-
Notifications
You must be signed in to change notification settings - Fork 48
/
create_pnor_image.pl
executable file
·295 lines (259 loc) · 10.1 KB
/
create_pnor_image.pl
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#!/usr/bin/perl
use strict;
use File::Basename;
use XML::Simple;
my $program_name = File::Basename::basename $0;
my $release = "";
my $outdir = "";
my $scratch_dir = "";
my $pnor_data_dir = "";
my $pnor_filename = "";
my $payload = "";
my $bootkernel = "";
my $hb_image_dir = "";
my $xml_layout_file = "";
my $targeting_binary_filename = "";
my $targeting_RO_binary_filename = "";
my $targeting_RW_binary_filename = "";
my $sbec_binary_filename = "";
my $sbe_binary_filename = "";
my $wink_binary_filename = "";
my $occ_binary_filename = "";
my $openpower_version_filename = "";
my $wofdata_binary_filename = "";
my $memddata_binary_filename = "";
my $hdat_binary_filename = "";
my $ocmbfw_binary_filename = "";
while (@ARGV > 0){
$_ = $ARGV[0];
chomp($_);
$_ = &trim_string($_);
if (/^-h$/i || /^-help$/i || /^--help$/i){
#print help content
usage();
exit 0;
}
elsif (/^-release/i){
$release = $ARGV[1] or die "Bad command line arg given: expecting a release input.\n";
shift;
}
elsif (/^-scratch_dir/i){
$scratch_dir = $ARGV[1] or die "Bad command line arg given: expecting a scratch dir path.\n";
shift;
}
elsif (/^-outdir/i){
$outdir = $ARGV[1] or die "Bad command line arg given: expecting a directory for output data.\n";
shift;
}
elsif (/^-pnor_data_dir/i){
$pnor_data_dir = $ARGV[1] or die "Bad command line arg given: expecting a directory containing pnor data.\n";
shift;
}
elsif (/^-pnor_filename/i){
$pnor_filename = $ARGV[1] or die "Bad command line arg given: expecting a pnor filename.\n";
shift;
}
elsif (/^-hb_image_dir/i){
$hb_image_dir = $ARGV[1] or die "Bad command line arg given: expecting an hb image dir path.\n";
shift;
}
elsif (/^-xml_layout_file/i){
$xml_layout_file = $ARGV[1] or die "Bad command line arg given: expecting an xml layout file.\n";
shift;
}
elsif (/^-payload/i){
$payload = $ARGV[1] or die "Bad command line arg given: expecting a filepath to payload binary file.\n";
shift;
}
elsif (/^-bootkernel/i){
$bootkernel = $ARGV[1] or die "Bad command line arg given: expecting a filepath to bootloader kernel image.\n";
shift;
}
elsif (/^-targeting_binary_filename/i){
$targeting_binary_filename = $ARGV[1] or die "Bad command line arg given: expecting a targeting binary filename.\n";
shift;
}
elsif (/^-targeting_RO_binary_filename/i){
$targeting_RO_binary_filename = $ARGV[1] or die "Bad command line arg given: expecting a targeting RW binary filename.\n";
shift;
}
elsif (/^-targeting_RW_binary_filename/i){
$targeting_RW_binary_filename = $ARGV[1] or die "Bad command line arg given: expecting a targeting RW binary filename.\n";
shift;
}
elsif (/^-sbe_binary_filename/i){
$sbe_binary_filename = $ARGV[1] or die "Bad command line arg given: expecting an sbe binary filename.\n";
shift;
}
elsif (/^-sbec_binary_filename/i){
$sbec_binary_filename = $ARGV[1] or die "Bad command line arg given: expecting an sbec binary filename.\n";
shift;
}
elsif (/^-wink_binary_filename/i){
$wink_binary_filename = $ARGV[1] or die "Bad command line arg given: expecting an wink binary filename.\n";
shift;
}
elsif (/^-occ_binary_filename/i){
$occ_binary_filename = $ARGV[1] or die "Bad command line arg given: expecting an occ binary filename.\n";
shift;
}
elsif (/^-openpower_version_filename/i){
$openpower_version_filename = $ARGV[1] or die "Bad command line arg given: expecting openpower version filename.\n";
shift;
}
elsif (/^-wofdata_binary_filename/i){
$wofdata_binary_filename = $ARGV[1] or die "Bad command line arg given: expecting a wofdata binary filename.\n";
shift;
}
elsif (/^-memddata_binary_filename/i){
$memddata_binary_filename = $ARGV[1] or die "Bad command line arg given: expecting a memddata binary filename.\n";
shift;
}
elsif (/^-hdat_binary_filename/i){
$hdat_binary_filename = $ARGV[1] or die "Bad command line arg given: expecting an hdat binary filename.\n";
shift;
}
elsif (/^-ocmbfw_binary_filename/i){
$ocmbfw_binary_filename = $ARGV[1] or die "Bad command line arg given: expecting an ocmbfw binary filename.\n";
shift;
}
else {
print "Unrecognized command line arg: $_ \n";
print "To view all the options and help text run \'$program_name -h\' \n";
exit 1;
}
shift;
}
if ($outdir eq "") {
die "-outdir <path_to_directory_for_output_files> is a required command line variable. Please run again with this parameter.\n";
}
if ($release eq "") {
die "-release <p8 or p9> is a required command line variable. Please run again with this parameter.\n";
}
# Verify that pnor_layout file exists and parse it
if ( ! -e "$xml_layout_file")
{
die "$xml_layout_file does not exist\n";
}
my $xs = new XML::Simple(keyattr=>[], forcearray => 1);
my $parsed_pnor_layout = $xs->XMLin($xml_layout_file);
print "release = $release\n";
print "scratch_dir = $scratch_dir\n";
print "pnor_data_dir = $pnor_data_dir\n";
my $build_pnor_command = "$hb_image_dir/buildpnor.pl";
$build_pnor_command .= " --pnorOutBin $pnor_filename --pnorLayout $xml_layout_file --editedLayoutLocation $hb_image_dir";
# Process HBD section and possibly HBD_RW section
if (checkForPnorPartition("HBD_RW", $parsed_pnor_layout))
{
$build_pnor_command .= " --binFile_HBD $scratch_dir/$targeting_RO_binary_filename";
$build_pnor_command .= " --binFile_HBD_RW $scratch_dir/$targeting_RW_binary_filename";
}
else
{
$build_pnor_command .= " --binFile_HBD $scratch_dir/$targeting_binary_filename";
}
$build_pnor_command .= " --binFile_SBE $scratch_dir/$sbe_binary_filename";
$build_pnor_command .= " --binFile_HBB $scratch_dir/hostboot.header.bin.ecc";
$build_pnor_command .= " --binFile_HBI $scratch_dir/hostboot_extended.header.bin.ecc";
$build_pnor_command .= " --binFile_HBRT $scratch_dir/hostboot_runtime.header.bin.ecc";
$build_pnor_command .= " --binFile_HBEL $scratch_dir/hbel.bin.ecc";
$build_pnor_command .= " --binFile_GUARD $scratch_dir/guard.bin.ecc";
$build_pnor_command .= " --binFile_PAYLOAD $payload";
$build_pnor_command .= " --binFile_BOOTKERNEL $bootkernel";
$build_pnor_command .= " --binFile_NVRAM $scratch_dir/nvram.bin";
$build_pnor_command .= " --binFile_ATTR_TMP $scratch_dir/attr_tmp.bin.ecc";
$build_pnor_command .= " --binFile_OCC $occ_binary_filename.ecc";
$build_pnor_command .= " --binFile_ATTR_PERM $scratch_dir/attr_perm.bin.ecc";
$build_pnor_command .= " --binFile_FIRDATA $scratch_dir/firdata.bin.ecc";
$build_pnor_command .= " --binFile_CAPP $scratch_dir/cappucode.bin.ecc";
$build_pnor_command .= " --binFile_SECBOOT $scratch_dir/secboot.bin.ecc";
$build_pnor_command .= " --binFile_VERSION $scratch_dir/openpower_pnor_version.bin";
$build_pnor_command .= " --binFile_IMA_CATALOG $scratch_dir/ima_catalog.bin.ecc";
# These are optional sections not tied to a specific processor family type
if (checkForPnorPartition("DJVPD", $parsed_pnor_layout))
{
$build_pnor_command .= " --binFile_DJVPD $scratch_dir/djvpd_fill.bin.ecc";
}
if (checkForPnorPartition("CVPD", $parsed_pnor_layout))
{
$build_pnor_command .= " --binFile_CVPD $scratch_dir/cvpd.bin.ecc";
}
if (checkForPnorPartition("MVPD", $parsed_pnor_layout))
{
$build_pnor_command .= " --binFile_MVPD $scratch_dir/mvpd_fill.bin.ecc";
}
if (checkForPnorPartition("EECACHE", $parsed_pnor_layout))
{
$build_pnor_command .= " --binFile_EECACHE $scratch_dir/eecache_fill.bin.ecc";
}
if (checkForPnorPartition("OCMBFW", $parsed_pnor_layout))
{
$build_pnor_command .= " --binFile_OCMBFW $ocmbfw_binary_filename";
}
# Add sections based on processor family type
if ($release eq "p9"){
$build_pnor_command .= " --binFile_WOFDATA $wofdata_binary_filename" if -e $wofdata_binary_filename;
if (checkForPnorPartition("MEMD", $parsed_pnor_layout))
{
$build_pnor_command .= " --binFile_MEMD $memddata_binary_filename" if -e $memddata_binary_filename;
}
$build_pnor_command .= " --binFile_HDAT $hdat_binary_filename" if -e $hdat_binary_filename;
}
if ($release eq "p8"){
$build_pnor_command .= " --binFile_SBEC $scratch_dir/$sbec_binary_filename";
$build_pnor_command .= " --binFile_WINK $scratch_dir/$wink_binary_filename";
} else {
$build_pnor_command .= " --binFile_SBKT $scratch_dir/SBKT.bin";
$build_pnor_command .= " --binFile_HCODE $scratch_dir/$wink_binary_filename";
$build_pnor_command .= " --binFile_HBBL $scratch_dir/hbbl.bin.ecc";
$build_pnor_command .= " --binFile_RINGOVD $scratch_dir/ringOvd.bin";
$build_pnor_command .= " --binFile_HB_VOLATILE $scratch_dir/guard.bin.ecc";
}
$build_pnor_command .= " --fpartCmd \"fpart\"";
$build_pnor_command .= " --fcpCmd \"fcp\"";
print "###############################";
run_command("$build_pnor_command");
#END MAIN
#-------------------------------------------------------------------------
sub usage {
print <<"ENDUSAGE";
ENDUSAGE
;
}
sub parse_config_file {
}
#trim_string takes one string as input, trims leading and trailing whitespace
# before returning that string
sub trim_string {
my $str = shift;
$str =~ s/^\s+//;
$str =~ s/\s+$//;
return $str;
}
sub run_command {
my $command = shift;
print "$command\n";
my $rc = system($command);
if ($rc !=0 ){
die "Error running command: $command. Nonzero return code of ($rc) returned.\n";
}
return $rc;
}
# Function to check if a partition exists in the PNOR XML Layout File
sub checkForPnorPartition {
my $section = shift;
my $parsed_layout = shift;
# default the return as 0 (aka 'false') - partition does NOT exist
my $does_section_exist = 0;
#Iterate over the <section> elements.
foreach my $sectionEl (@{$parsed_layout->{section}})
{
my $eyeCatch = $sectionEl->{eyeCatch}[0];
if($eyeCatch eq $section)
{
$does_section_exist = 1;
last;
}
}
return $does_section_exist;
}