0
|
1 |
#!perl -w
|
|
2 |
#
|
|
3 |
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
# All rights reserved.
|
|
5 |
# This component and the accompanying materials are made available
|
|
6 |
# under the terms of the License "Eclipse Public License v1.0"
|
|
7 |
# which accompanies this distribution, and is available
|
|
8 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
9 |
#
|
|
10 |
# Initial Contributors:
|
|
11 |
# Nokia Corporation - initial contribution.
|
|
12 |
#
|
|
13 |
# Contributors:
|
|
14 |
#
|
|
15 |
# Description:
|
|
16 |
# This simple script makes a binary HCR data file from a text input file
|
|
17 |
#
|
|
18 |
use strict;
|
|
19 |
|
|
20 |
use HCRdat;
|
|
21 |
use HCRrec;
|
|
22 |
|
|
23 |
package mhd;
|
|
24 |
|
|
25 |
#
|
|
26 |
# Find out what file the user is interested in..
|
|
27 |
# Make sure it's specified and exists.
|
|
28 |
#
|
|
29 |
$mhd::trace = 0;
|
|
30 |
$mhd::otrace = 0;
|
|
31 |
|
|
32 |
if (@ARGV < 2 || @ARGV > 4) {
|
|
33 |
die "\nUsage: hcrmd.bat <source_textfile> <dest_datfile> [-i]\n";
|
|
34 |
}
|
|
35 |
|
|
36 |
my $textfile = shift @ARGV;
|
|
37 |
my $datfile = shift @ARGV;
|
|
38 |
|
|
39 |
my $do_create_image = 0;
|
|
40 |
my $opt_i = shift @ARGV;
|
|
41 |
#my $partid = 0x10000005;
|
|
42 |
if (defined($opt_i)) {
|
|
43 |
$do_create_image = 1 if ($opt_i eq "-i");
|
|
44 |
die "error: unknown command option\n" if ($opt_i ne "-i");
|
|
45 |
#my $i_no = shift @ARGV;
|
|
46 |
#$partid = hex($i_no) if (defined($i_no));
|
|
47 |
#printf("partitionid: 0x%x\n", $partid)
|
|
48 |
}
|
|
49 |
|
|
50 |
|
|
51 |
print "\n HCR Binary Data File Generator, version v0.1\n";
|
|
52 |
print " Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.\n\n";
|
|
53 |
print "-input: $textfile\n" if($mhd::trace);
|
|
54 |
print "-output: $datfile\n" if($mhd::trace);
|
|
55 |
|
|
56 |
die "error: Specifed source_textfile not found!" unless(-f $textfile);
|
|
57 |
#die "error: Specified dest_binfile '$datfile' already exists!" if(-e $datfile);
|
|
58 |
|
|
59 |
printf "\nReading input file... $textfile\n";
|
|
60 |
|
|
61 |
printf "-opening text file\n" if($mhd::trace);
|
|
62 |
my $tfh;
|
|
63 |
open($tfh, "<$textfile");
|
|
64 |
|
|
65 |
printf "-started conversion...\n" if($mhd::trace);
|
|
66 |
my $datobj = HCRdat->new();
|
|
67 |
my $inrec = 0;
|
|
68 |
my $ln = 0;
|
|
69 |
my $recobj;
|
|
70 |
|
|
71 |
while (<$tfh>)
|
|
72 |
{
|
|
73 |
$ln++;
|
|
74 |
if ($_ =~ '^\s*#') {
|
|
75 |
printf "-comment\n" if($mhd::trace);
|
|
76 |
}
|
|
77 |
elsif ($_ =~ '^@') {
|
|
78 |
die "error: Syntax error line $ln: New record started before previous one is closed" if($inrec > 0);
|
|
79 |
printf "-start\n" if($mhd::trace);
|
|
80 |
$inrec = 1;
|
|
81 |
$recobj = HCRrec->new();
|
|
82 |
}
|
|
83 |
elsif ($_ =~ '^\.') {
|
|
84 |
die "error: Syntax error line $ln: Record closed before a new record has been opened" if($inrec == 0);
|
|
85 |
printf "-end\n" if($mhd::trace);
|
|
86 |
if ($recobj->IsValid()) {
|
|
87 |
$datobj->AddSettingRecord($recobj);
|
|
88 |
}
|
|
89 |
else {
|
|
90 |
die "error: Record after record " . $datobj->NumRecords() . " completed but not valid, missing or has =0 fields?\n";
|
|
91 |
}
|
|
92 |
$inrec = 0;
|
|
93 |
}
|
|
94 |
elsif ($_ =~ '^\s*$') {
|
|
95 |
printf "-blank\n" if($mhd::trace);
|
|
96 |
}
|
|
97 |
elsif ($_ =~ '^\s*cuid:\s') {
|
|
98 |
print "--cuid " if($mhd::trace);
|
|
99 |
my @hwords = split(/\s+/,$_);
|
|
100 |
die "error: 'cuid:' line incorrectly formed" if (scalar(@hwords) != 2);
|
|
101 |
|
|
102 |
$recobj->CUID($hwords[1]);
|
|
103 |
printf("=0x%08x\n", $recobj->CUID()) if($mhd::trace);
|
|
104 |
}
|
|
105 |
elsif ($_ =~ '^\s*eid:\s') {
|
|
106 |
print "--eid " if($mhd::trace);
|
|
107 |
my @hwords = split(/\s+/,$_);
|
|
108 |
die "error: 'eid:' line incorrectly formed" if (scalar(@hwords) != 2);
|
|
109 |
|
|
110 |
$recobj->EID($hwords[1]);
|
|
111 |
print "=".($recobj->EID())."\n" if($mhd::trace);
|
|
112 |
}
|
|
113 |
elsif ($_ =~ '^\s*type:\s') {
|
|
114 |
print "--type " if($mhd::trace);
|
|
115 |
my @hwords = split(/\s+/,$_);
|
|
116 |
die "error: 'type:' line incorrectly formed" if (scalar(@hwords) != 2);
|
|
117 |
|
|
118 |
$recobj->Type($hwords[1]);
|
|
119 |
printf("=0x%08x (%s)\n", $recobj->Type(), $recobj->TypeName()) if($mhd::trace);
|
|
120 |
}
|
|
121 |
elsif ($_ =~ '^\s*flags:\s') {
|
|
122 |
print "--flags " if($mhd::trace);
|
|
123 |
my @hwords = split(/\s+/,$_);
|
|
124 |
die "error: 'flags:' line incorrectly formed" if (scalar(@hwords) != 2);
|
|
125 |
|
|
126 |
$recobj->Flags($hwords[1]);
|
|
127 |
printf ("=0x%x\n", $recobj->Flags()) if($mhd::trace);
|
|
128 |
printf ("warning: flag length value greater than 2-bytes\n") if ($recobj->Flags() > 0xffff);
|
|
129 |
}
|
|
130 |
elsif ($_ =~ '^\s*intval:\s') {
|
|
131 |
print "--intval " if($mhd::trace);
|
|
132 |
my @hwords = split(/\s+/,$_);
|
|
133 |
die "error: 'intval:' line incorrectly formed" if (scalar(@hwords) != 2);
|
|
134 |
|
|
135 |
$recobj->IntValue($hwords[1]);
|
|
136 |
printf("=%d (0x%x)\n", $recobj->IntValue(), $recobj->IntValue()) if($mhd::trace);
|
|
137 |
}
|
|
138 |
elsif ($_ =~ '^\s*hexval:\s') {
|
|
139 |
print "--hexval " if($mhd::trace);
|
|
140 |
my @hwords = split(/\s+/,$_);
|
|
141 |
die "error: 'hexval:' line incorrectly formed" if (scalar(@hwords) != 2);
|
|
142 |
|
|
143 |
$recobj->HexValue($hwords[1]);
|
|
144 |
printf("=%d (0x%x)\n", $recobj->IntValue(), $recobj->IntValue()) if($mhd::trace);
|
|
145 |
}
|
|
146 |
elsif ($_ =~ '^\s*arrval:\s') {
|
|
147 |
print "--arrval " if($mhd::trace);
|
|
148 |
my @hwords = split(/\s+/,$_);
|
|
149 |
die "error: 'arrval:' line incorrectly formed" if (scalar(@hwords) != 2);
|
|
150 |
|
|
151 |
print $hwords[1]."\n" if ($mhd::trace);
|
|
152 |
$recobj->ArrValue($hwords[1]);
|
|
153 |
}
|
|
154 |
elsif ($_ =~ '^\s*strval:\s') {
|
|
155 |
print "--strval " if($mhd::trace);
|
|
156 |
my @hwords = split(/\"/,$_);
|
|
157 |
die "error: 'strval:' line incorrectly formed" if (scalar(@hwords) != 3);
|
|
158 |
|
|
159 |
my $strval_size = $recobj->Length();
|
|
160 |
$recobj->StrValue($hwords[1]);
|
|
161 |
|
|
162 |
printf("=\"%s\"\n", substr($recobj->StrValue(), $strval_size)) if($mhd::trace);
|
|
163 |
}
|
|
164 |
elsif ($_ =~ '^\s*binval:\s') {
|
|
165 |
print "--binval " if($mhd::trace);
|
|
166 |
my @hwords = split(/:/,$_);
|
|
167 |
die "error: 'binval:' line incorrectly formed" if (scalar(@hwords) < 2);
|
|
168 |
|
|
169 |
my $binval_size = $recobj->Length();
|
|
170 |
$recobj->BinValue($hwords[1]);
|
|
171 |
|
|
172 |
my $binval_ref = $recobj->BinValue();
|
|
173 |
my @binval = @$binval_ref;
|
|
174 |
|
|
175 |
printf("(%d) =", $#binval+1) if($mhd::trace);
|
|
176 |
my $uint16 = $binval_size;
|
|
177 |
for (; $uint16 < @binval; $uint16++) {
|
|
178 |
printf("%02x ", $binval[$uint16]) if($mhd::trace);
|
|
179 |
}
|
|
180 |
|
|
181 |
print "\n" if($mhd::trace);
|
|
182 |
}
|
|
183 |
elsif ($_ =~ '') {
|
|
184 |
}
|
|
185 |
else {
|
|
186 |
die "error: unknown line type '$_'"
|
|
187 |
# print $_ if($mhd::trace);
|
|
188 |
}
|
|
189 |
}
|
|
190 |
|
|
191 |
close $tfh;
|
|
192 |
|
|
193 |
printf "\nGenerating output file... $datfile\n";
|
|
194 |
|
|
195 |
printf "-creating binary data file\n" if($mhd::otrace);
|
|
196 |
if ($datobj->WriteToFile($datfile.".tmp") != 0) {
|
|
197 |
die "error: failed to write to dest_binfile";
|
|
198 |
}
|
|
199 |
|
|
200 |
printf "-renaming file to temp file to $datfile\n" if($mhd::otrace);
|
|
201 |
rename ($datfile.".tmp", $datfile);
|
|
202 |
|
|
203 |
printf "-file header written:\n" if($mhd::otrace);
|
|
204 |
$datobj->ShowHeader() if($mhd::otrace);
|
|
205 |
|
|
206 |
if ($do_create_image) {
|
|
207 |
my $imgfile = $datfile . ".img";
|
|
208 |
print "\nGenerating partition image... ". $imgfile . "\n";
|
|
209 |
|
|
210 |
if ($datobj->WriteToImage($imgfile, $datfile) != 0) {
|
|
211 |
die "error: failed to write to image file $imgfile";
|
|
212 |
}
|
|
213 |
}
|
|
214 |
|
|
215 |
print "\nDone.\n";
|
|
216 |
exit 0;
|
|
217 |
|
|
218 |
|
|
219 |
|