⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 srecconv.pl

📁 MIPS下的boottloader yamon 的源代码
💻 PL
字号:
#! /usr/local/bin/perl -w
#########################################################################
#
#   srecconv.pl
#
#   Tool that converts from srecord format to :
#
#   1) File suitable for parallel download (.fl format)
#   2) Binary file suitable for EPROM programming devices (.bin format).
#
#
#   ######################################################################
#
#   Copyright (c) 1999-2000 MIPS Technologies, Inc. All rights reserved. 
#   
#   Unpublished rights reserved under the Copyright Laws of the United States of 
#   America. 
#   
#   This document contains information that is proprietary to MIPS Technologies, 
#   Inc. ("MIPS Technologies"). Any copying, modifying or use of this 
#   information (in whole or in part) which is not expressly permitted in 
#   writing by MIPS Technologies or a contractually-authorized third party is 
#   strictly prohibited. At a minimum, this information is protected under 
#   unfair competition laws and the expression of the information contained 
#   herein is protected under federal copyright laws. Violations thereof may 
#   result in criminal penalties and fines. 
#   MIPS Technologies or any contractually-authorized third party reserves the 
#   right to change the information contained in this document to improve 
#   function, design or otherwise. MIPS Technologies does not assume any 
#   liability arising out of the application or use of this information. Any 
#   license under patent rights or any other intellectual property rights owned 
#   by MIPS Technologies or third parties shall be conveyed by MIPS Technologies 
#   or any contractually-authorized third party in a separate license agreement 
#   between the parties. 
#   The information contained in this document constitutes one or more of the 
#   following: commercial computer software, commercial computer software 
#   documentation or other commercial items. If the user of this information, or 
#   any related documentation of any kind, including related technical data or 
#   manuals, is an agency, department, or other entity of the United States 
#   government ("Government"), the use, duplication, reproduction, release, 
#   modification, disclosure, or transfer of this information, or any related 
#   documentation of any kind, is restricted in accordance with Federal 
#   Acquisition Regulation 12.212 for civilian agencies and Defense Federal 
#   Acquisition Regulation Supplement 227.7202 for military agencies. The use of 
#   this information by the Government is further restricted in accordance with 
#   the terms of the license agreement(s) and/or applicable contract terms and 
#   conditions covering this information from MIPS Technologies or any 
#   contractually-authorized third party. 
#
#########################################################################

use Getopt::Long;

$srec_endian = "B";
$bin_endian  = "B";
$addr_bits   = 32;
$verbose     = 0;

$help = "
   Usage: $0 [-ES <endian>] [-EB <endian>] [-A <addr bits>] -v file

   The script reads the <file>.rec file which must be in SREC format,
   and generates two files:
   <file>.fl    : FLASH file for download to MIPS board.
   <file>.bin   : Binary file for EPROM on SEAD-1 board.

   The following options are available:

   -ES <endian> : Set the endianess of the SREC file. Valid options:
                  -ES L (little endian) or -ES B (big endian)

   -EB <endian> : Set the endianess of the binary file. Valid options:
                  -EB L (little endian) or -EB B (big endian)

   -A <addr bits> : Set number of address bits to include in FLASH file.

   -v           : Print verbose information

   Endianess for the SREC file can be changed on the fly by embedding the lines:
      !L
   or
      !B
   in the file.\n\n
";

GetOptions("ES:s"   => \$srec_endian,
           "EB:s"   => \$bin_endian,
	   "A:s"    => \$addr_bits,
	   "v"      => \$verbose);


if (!defined ($ARGV[0])) {
    print $help;
    exit -1;
}

$input_file      = "$ARGV[0]" . ".rec";
$output_file_fl  = "$ARGV[0]" . ".fl";
$output_file_bin = "$ARGV[0]" . ".bin";

open (IFILE, "<$input_file") ||
    die("Error: can't open file $input_file \n");

$addr_mask = 0xffffffff >> (32 - $addr_bits);
$addr_mask = $addr_mask & 0xfffffffc;
$addr_base = -1;

while ($line = <IFILE>)
{

    if ($line =~ /^S3(.{2})(.{8})(.*)/)
    {
	$count = hex($1)-4-1;
	$addr  = hex($2);
	$data  = $3;


	for ($i = 0; $i < $count; $i++)
	{

	    $addr32 = $addr & $addr_mask;
	    $addr01 = $addr & 0x3;

	    if ($addr_base < 0)
	    {
		$addr_base = $addr32;
	    }

	    $addr32 = $addr32 - $addr_base;
	    $data =~ /(.{2})/g;

	    $val = hex($1);

	    if ($srec_endian eq "L")
	    {
		$val = $val << (8*$addr01);
	    }
	    else
	    {
		$val = $val << (8*(3-$addr01));
	    }

	    if (defined($data_array[$addr32]))
	    {
		$data_array[$addr32] = $data_array[$addr32] | $val;
	    }
	    else
	    {
		$data_array[$addr32] = $val;
	    }

	    $addr = $addr + 1;
	}

    }
    elsif ($line =~ /^!B/)
    {
	vprint ("Changing SREC endianess to big endian\n");
	$srec_endian = "B";
    }
    elsif ($line =~ /^!L/)
    {
	vprint ("Changing SREC endianess to little endian\n");
	$srec_endian = "L";
    }




}
close(IFILE);


#------------------------------------------------------------
# Create the FLASH file
#------------------------------------------------------------
open (OFILE, ">$output_file_fl") ||
    die("Error: can't open file $output_file_fl \n");

# Initialize download
print(OFILE "# Reset the loader state machine.\n!R\n");

$prev_addr = -256;
$block16   = 0;

for ($addr=0; $addr < @data_array; $addr=$addr+4)
{

    next if (!defined($data_array[$addr]));

    if ($addr !=  $prev_addr+4)
    {
	$hole    = ($addr-$prev_addr)/4 - 1;
	$missing = (16 - $block16) % 16;

	$count = $hole > $missing ? $missing : $hole;

	while ($count)
	{
	    printf(OFILE "%.8x\n",0xf111c0de);
	    $block16 = ($block16+1) % 16;
	    $count--;
	}

	if ($hole > $missing)
	{
	    printf(OFILE "@%.8x\n",$addr+$addr_base);
	    printf(OFILE ">%.8x\n",$addr+$addr_base);
	}

    }

    $prev_addr = $addr;

    printf(OFILE "%.8X\n",$data_array[$addr]);
    $block16 = ($block16+1) % 16;
}

while ($block16 < 16)
{
    printf(OFILE "%.8x\n",0xf111c0de);
    $block16++;
}
printf(OFILE ">#DL_DONE\n");
close(OFILE);

#------------------------------------------------------------
# Create the binary file
#------------------------------------------------------------
open (OFILE, ">$output_file_bin") ||
    die("Error: can't open file $output_file_bin \n");

$prev_addr = -256;

for ($addr=0; $addr < @data_array; $addr=$addr+4)
{
    next if (!defined($data_array[$addr]));

    if (($addr !=  $prev_addr+4) && $prev_addr > 0)
    {
	$hole    = ($addr-$prev_addr)/4 - 1;
	while ($hole)
	{
	    $ostream = pack("C4", 0,0,0,0);
	    print (OFILE $ostream);
	    $hole--;
	}

    }

    $prev_addr = $addr;

    if ($bin_endian eq "L")
    {
	$istream[0] = ($data_array[$addr]>>0)  & 0xff;
	$istream[1] = ($data_array[$addr]>>8)  & 0xff;
	$istream[2] = ($data_array[$addr]>>16) & 0xff;
	$istream[3] = ($data_array[$addr]>>24) & 0xff;
    }
    else
    {
	$istream[3] = ($data_array[$addr]>>0)  & 0xff;
	$istream[2] = ($data_array[$addr]>>8)  & 0xff;
	$istream[1] = ($data_array[$addr]>>16) & 0xff;
	$istream[0] = ($data_array[$addr]>>24) & 0xff;
    }

    $ostream = pack("C4", @istream);
    print (OFILE $ostream);
}

close (OFILE);

sub vprint {
    my $string = $_[0];
    if($verbose) {
	print($string);
    }
}

exit 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -