Magellan Linux

Contents of /trunk/linterm_tools/fw_builder/bundle-tools/extract_head.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 658 - (show annotations) (download)
Mon Jan 14 16:57:24 2008 UTC (16 years, 3 months ago) by niro
File MIME type: text/plain
File size: 2511 byte(s)
initial import

1 #!/usr/bin/perl
2 #
3 # This script extracts the header bytes of an original format, needed by fwpack
4 # Copyright (C) 2005 Wilmer van der Gaast <wilmer@gaast.net>
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the second version of the GNU
8 # General Public License as published by the Free Software
9 # Foundation.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #
20
21 @imgs = <*.WYE *.CPQ *.wye *.cpq>;
22 if( scalar( @ARGV ) >= 1 )
23 {
24 $fn = $ARGV[0];
25 }
26 elsif( scalar( @imgs ) == 0 )
27 {
28 print( 'Hmm, can\'t find any possible firmware bundle file. Please pass one as an' . "\n" .
29 'argument or copy it to this directory.' . "\n" );
30 exit( 1 );
31 }
32 elsif( scalar( @imgs ) > 1 )
33 {
34 print( 'Found the following firmware bundles:' . "\n" .
35 join( ' ', @imgs ) . "\n" .
36 'Which one should be used to copy the headers?' . "\n" );
37 chomp( $fn = <STDIN> );
38 }
39 else
40 {
41 $fn = $imgs[0];
42 }
43
44 open( IMG, '<', $fn ) or die( 'Can\'t open input file ' . $fn );
45 $n = sysread( IMG, $head, 0x59 );
46 close( IMG );
47
48 if( substr( $head, 3, 4 ) ne 'BndL' )
49 {
50 print( STDERR 'Hmm, that doesn\'t look like a bundle file!' . "\n" );
51 }
52
53 if( ord( substr( $head, 0xf, 1 ) ) == 0 )
54 {
55 print( STDERR 'Hmm, that looks like an add-on bundle file!' . "\n" );
56 }
57
58 ## Let's just set these to something bogus, fwpack is supposed to fill them in.
59 substr( $head, 0x13, 4 ) = pack( 'cccc', 0xaa, 0xaa, 0xaa, 0xaa );
60 substr( $head, 0x37, 8 ) = pack( 'cccccccc', 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa );
61 @head = split( '', $head );
62
63 open( FWHEAD, '>', 'fwhead.h' ) or die( 'Can\'t open output file fwhead.h' );
64 print( FWHEAD '/* Auto-generated from ' . $fn . ' */' . "\n" );
65 print( FWHEAD 'u_int8_t fhead[0x59] = { ' );
66 for $i ( 0 .. ( scalar( @head ) - 1 ) )
67 {
68 printf( FWHEAD '0x%02x', ord $head[$i] );
69 if( $i < ( scalar( @head ) - 1 ) )
70 {
71 print( FWHEAD ',' );
72 }
73 if( ( $i % 16 ) == 15 )
74 {
75 $n = 0;
76 print( FWHEAD "\n" . ( ' ' x 25 ) );
77 }
78 else
79 {
80 print( FWHEAD ' ' );
81 }
82 }
83 print( FWHEAD '};' . "\n" );
84 close( FWHEAD );
85
86 print( 'fwhead.h successfully created' . "\n" );

Properties

Name Value
svn:executable *