3 # Extract Symbol firmware and convert is to a header file and two binary
6 # Copyright (C) 2004 Pavel Roskin <proski@gnu.org>
8 # This script is Free Software, and it can be copied, distributed and
9 # modified as defined in the GNU General Public License. A copy of
10 # its license can be downloaded from http://www.gnu.org/copyleft/gpl.html
13 # parse_symbol_fw infile header binfile1 binfile2
17 # Print message and exit (like "die", but without raising an exception).
18 # Newline is added at the end.
21 printf STDERR "ERROR: ";
30 read INFILE,$byte_a,1;
32 read INFILE,$byte_b,1;
33 return (ord($byte_b) << 8) + ord($byte_a);
38 error ("Usage: parse_symbol_fw infile header binfile1 binfile2");
41 unless (open (INFILE, "< $ARGV[0]")) {
42 error ("couldn't open $ARGV[0] for reading: $!");
45 unless (open (OUTFILE, "> $ARGV[1]")) {
46 error ("couldn't open $ARGV[1] for writing: $!");
49 # Process one array, either for primary or for secondary firmware
50 sub process_one_array($$) {
51 my $arrname = shift(@_);
52 my $binfile = shift(@_);
56 # Skip to the beginning of firmware
60 $offset = $str_offset + pos() - 6;
63 $str_offset = tell(INFILE);
67 error("Cannot find FILE: marker");
71 print $fwdata[1] . "\n";
72 seek(INFILE, $offset, 0);
74 my $blknum = $fwdata[3];
75 my $pdrlen = $fwdata[4];
76 my $crclen = $fwdata[5];
77 my $compatlen = $fwdata[6];
79 while (!eof(INFILE)) {
81 read INFILE, $byte, 1;
82 last if (ord($byte) == 0x1a);
87 while ($block-- > 0) {
89 my $len = readnum_ba();
90 seek(INFILE, $len, 1);
93 my $img_len = tell(INFILE) - $offset + $pdrlen + $crclen + $compatlen + 2;
94 seek(INFILE, $offset, 0);
96 # Write binary file for the section
97 unless (open (BINFILE, "> $binfile")) {
98 error ("couldn't open $binfile for writing: $!");
102 printf OUTFILE "/* %s %s */\n", $fwdata[1], $fwdata[2];
103 printf OUTFILE "static u8 %s[] = {\n", $arrname;
106 while ($count++ < $img_len) {
108 read INFILE, $byte, 1;
110 printf OUTFILE "0x%02x,", $byte;
111 printf BINFILE "%c", $byte;
112 if ($count % 16 == 0) {
121 print OUTFILE "};\n";
125 process_one_array("primsym", $ARGV[2]);
126 process_one_array("secsym", $ARGV[3]);