summaryrefslogtreecommitdiffstats
path: root/meta/recipes-bsp/orinoco/spectrum-fw/parse_symbol_fw
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-bsp/orinoco/spectrum-fw/parse_symbol_fw')
-rwxr-xr-xmeta/recipes-bsp/orinoco/spectrum-fw/parse_symbol_fw129
1 files changed, 129 insertions, 0 deletions
diff --git a/meta/recipes-bsp/orinoco/spectrum-fw/parse_symbol_fw b/meta/recipes-bsp/orinoco/spectrum-fw/parse_symbol_fw
new file mode 100755
index 0000000000..7fe0ea57c4
--- /dev/null
+++ b/meta/recipes-bsp/orinoco/spectrum-fw/parse_symbol_fw
@@ -0,0 +1,129 @@
1#!/usr/bin/perl -w
2
3# Extract Symbol firmware and convert is to a header file and two binary
4# files.
5
6# Copyright (C) 2004 Pavel Roskin <proski@gnu.org>
7
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
11
12# Usage:
13# parse_symbol_fw infile header binfile1 binfile2
14
15use strict;
16
17# Print message and exit (like "die", but without raising an exception).
18# Newline is added at the end.
19sub error
20{
21 printf STDERR "ERROR: ";
22 printf STDERR @_;
23 printf STDERR "\n";
24 exit 1;
25}
26
27sub readnum_ba ()
28{
29 my $byte_a;
30 read INFILE,$byte_a,1;
31 my $byte_b;
32 read INFILE,$byte_b,1;
33 return (ord($byte_b) << 8) + ord($byte_a);
34}
35
36
37if ($#ARGV != 3) {
38 error ("Usage: parse_symbol_fw infile header binfile1 binfile2");
39}
40
41unless (open (INFILE, "< $ARGV[0]")) {
42 error ("couldn't open $ARGV[0] for reading: $!");
43}
44
45unless (open (OUTFILE, "> $ARGV[1]")) {
46 error ("couldn't open $ARGV[1] for writing: $!");
47}
48
49# Process one array, either for primary or for secondary firmware
50sub process_one_array($$) {
51 my $arrname = shift(@_);
52 my $binfile = shift(@_);
53 my $offset = -1;
54 my $str_offset = 0;
55
56 # Skip to the beginning of firmware
57 $/ = "\x00";
58 while (<INFILE>) {
59 if (m{FILE: }g) {
60 $offset = $str_offset + pos() - 6;
61 last;
62 }
63 $str_offset = tell(INFILE);
64 }
65
66 if ($offset == -1) {
67 error("Cannot find FILE: marker");
68 }
69
70 my @fwdata = split;
71 print $fwdata[1] . "\n";
72 seek(INFILE, $offset, 0);
73
74 my $blknum = $fwdata[3];
75 my $pdrlen = $fwdata[4];
76 my $crclen = $fwdata[5];
77 my $compatlen = $fwdata[6];
78
79 while (!eof(INFILE)) {
80 my $byte;
81 read INFILE, $byte, 1;
82 last if (ord($byte) == 0x1a);
83 }
84
85 # Walk all blocks
86 my $block = $blknum;
87 while ($block-- > 0) {
88 seek(INFILE, 4, 1);
89 my $len = readnum_ba();
90 seek(INFILE, $len, 1);
91 }
92
93 my $img_len = tell(INFILE) - $offset + $pdrlen + $crclen + $compatlen + 2;
94 seek(INFILE, $offset, 0);
95
96 # Write binary file for the section
97 unless (open (BINFILE, "> $binfile")) {
98 error ("couldn't open $binfile for writing: $!");
99 }
100
101 # Output the array
102 printf OUTFILE "/* %s %s */\n", $fwdata[1], $fwdata[2];
103 printf OUTFILE "static u8 %s[] = {\n", $arrname;
104
105 my $count = 0;
106 while ($count++ < $img_len) {
107 my $byte;
108 read INFILE, $byte, 1;
109 $byte = ord($byte);
110 printf OUTFILE "0x%02x,", $byte;
111 printf BINFILE "%c", $byte;
112 if ($count % 16 == 0) {
113 printf OUTFILE "\n";
114 }
115 }
116
117 if ($img_len % 16) {
118 printf OUTFILE "\n";
119 }
120
121 print OUTFILE "};\n";
122 close(BINFILE);
123}
124
125process_one_array("primsym", $ARGV[2]);
126process_one_array("secsym", $ARGV[3]);
127
128close(INFILE);
129close(OUTFILE);