File: bcm_hex2bin

package info (click to toggle)
bluez-firmware 1.2-13
  • links: PTS, VCS
  • area: non-free-firmware
  • in suites: forky, sid, trixie
  • size: 1,140 kB
  • sloc: sh: 517; perl: 305; makefile: 36; xml: 14
file content (120 lines) | stat: -rwxr-xr-x 2,142 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/perl
#
# This is a tool to convert three banked intel hex format files 
# into a single intel hex format file. The common portion of the
# code will be removed.
#

@Bank0;

$BANK_LIMIT = "8000";

$bcm2039 = "BCM2039";

#@type;
$count;

$outFile="";
$filename="";

if(( @ARGV == 0 ) || ( @ARGV == 1 ))
{
    print "Usage: IHex2Bin.pl inputFile.hex outputFile.bin\n";

}
else
{

   $count=114688;

   @Image[$count];

    for( $i = 0 ; $i < $count; $i += 1 )
    {
        $Image[$i] = 0xff;
    }

    ParseOneFile( \@Bank0, shift ARGV );
    
    $outfile = shift ARGV;

    open (hdl, ">", $outfile ) || die "Can't open $outfile\n"; 
    binmode hdl, ':raw';

    foreach $item (@Bank0)
    {
        $baseAddr = hex $item->{"addr"};

        if($item->{"type"} == 2)
        {   
            $baseAddr += 0x8000;
        }

        if($item->{"type"} == 3)
        {   
            $baseAddr += 0x10000;
        }

        $str = $item->{"data"} ;
        for($i = 0; $i < length($str ) ; $i +=2 )
        {
            # cut the whole ascii string into two
            # characters each and convert them into 
            # hex number.
            $tmp = hex( substr( $str , $i, 2 ) );

            # figure out the offset

            $Image[$baseAddr ] = $tmp;

            #increase the base address by one for next 
            # byte
            $baseAddr += 1;
        }
    }

    for( $i = 0 ; $i < $count; $i += 1 )
    {
       $val = sprintf("%02X", $Image[$i]); 
       $len = length($val);
       $value = pack("H$len", $val);
       print hdl $value;
    }

    close hdl;
}

exit 0;



sub ParseOneFile()
{
    local ( $image ) = shift @_;
    $filename        = shift @_;
    local ($line);


    open( file, $filename ) || die "Can't open $filename\n";

    binmode($filename);

    while( $line = <file> )
    {
        $record = {};

        $line =~ /:(\w\w)(\w{4})(\w\w)(.*)(\w\w)/;

        $record->{"len"} = $1;
        $record->{"addr"} = $2;
        $record->{"type"} = $3;
        $record->{"data"} = $4;
        $record->{"checksum"} = $5;

        push @$image, $record;
    }

    close(file);


}