forked from open-power/pnor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_image.pl
executable file
·174 lines (147 loc) · 8.36 KB
/
update_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
#!/usr/bin/perl
use strict;
use File::Basename;
#my $ecc_tool_dir = "/opt/mcp/shared/fr_FLD8-1-20140528/opt/fsp/usr/bin"; #wh_todo
my $op_target_dir = "";
my $hb_image_dir = "";
my $scratch_dir = "";
my $hb_binary_dir = "";
my $targeting_binary_filename = "";
my $targeting_binary_source = "";
my $sbe_binary_filename = "";
my $sbec_binary_filename = "";
my $occ_binary_filename = "";
while (@ARGV > 0){
$_ = $ARGV[0];
chomp($_);
$_ = &trim_string($_);
if (/^-h$/i || /^-help$/i || /^--help$/i){
usage(); #print help content
exit 0;
}
elsif (/^-op_target_dir/i){
$op_target_dir = $ARGV[1] or die "Bad command line arg given: expecting a config type.\n";
shift;
}
elsif (/^-hb_image_dir/i){
$hb_image_dir = $ARGV[1] or die "Bad command line arg given: expecting a config type.\n";
shift;
}
elsif (/^-scratch_dir/i){
$scratch_dir = $ARGV[1] or die "Bad command line arg given: expecting a config type.\n";
shift;
}
elsif (/^-hb_binary_dir/i){
$hb_binary_dir = $ARGV[1] or die "Bad command line arg given: expecting a config type.\n";
shift;
}
elsif (/^-targeting_binary_filename/i){
$targeting_binary_filename = $ARGV[1] or die "Bad command line arg given: expecting a config type.\n";
shift;
}
elsif (/^-targeting_binary_source/i){
$targeting_binary_source = $ARGV[1] or die "Bad command line arg given: expecting a config type.\n";
shift;
}
elsif (/^-sbe_binary_filename/i){
$sbe_binary_filename = $ARGV[1] or die "Bad command line arg given: expecting a config type.\n";
shift;
}
elsif (/^-sbec_binary_filename/i){
$sbec_binary_filename = $ARGV[1] or die "Bad command line arg given: expecting a config type.\n";
shift;
}
elsif (/^-occ_binary_filename/i){
$occ_binary_filename = $ARGV[1] or die "Bad command line arg given: expecting a config type.\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;
}
# Pad Targeting binary to 4k page size, then add ECC data
###
### To calculate the pad, ibs=(<partition size>/9)*8
###
run_command("dd if=$op_target_dir/$targeting_binary_source of=$scratch_dir/$targeting_binary_source ibs=4k conv=sync");
run_command("ecc --inject $scratch_dir/$targeting_binary_source --output $scratch_dir/$targeting_binary_filename --p8");
run_command("echo \"00000000001800000000000008000000000000000007EF80\" | xxd -r -ps - $scratch_dir/sbe.header");
run_command("echo -en VERSION\\\\0 > $scratch_dir/hostboot.sha.bin");
run_command("sha512sum $hb_image_dir/img/hostboot.bin | awk \'{print \$1}\' | xxd -pr -r >> $scratch_dir/hostboot.sha.bin");
run_command("dd if=$scratch_dir/hostboot.sha.bin of=$scratch_dir/secureboot.header ibs=4k conv=sync");
run_command("dd if=/dev/zero of=$scratch_dir/hbb.footer count=1 bs=128K");
run_command("cat $scratch_dir/sbe.header $scratch_dir/secureboot.header $hb_image_dir/img/hostboot.bin $scratch_dir/hbb.footer > $scratch_dir/hostboot.stage.bin");
run_command("head -c 524288 $scratch_dir/hostboot.stage.bin > $scratch_dir/hostboot.header.bin");
run_command("ecc --inject $hb_image_dir/img/hostboot.bin --output $scratch_dir/hostboot.bin.ecc --p8");
run_command("ecc --inject $scratch_dir/hostboot.header.bin --output $scratch_dir/hostboot.header.bin.ecc --p8");
run_command("dd if=$hb_image_dir/img/hostboot_extended.bin of=$scratch_dir/hostboot_extended.bin.pad ibs=4k count=1280 conv=sync");
run_command("ecc --inject $scratch_dir/hostboot_extended.bin.pad --output $scratch_dir/hostboot_extended.bin.ecc --p8");
run_command("echo -en VERSION\\\\0 > $scratch_dir/hostboot_runtime.sha.bin");
run_command("sha512sum $hb_image_dir/img/hostboot_runtime.bin | awk \'{print \$1}\' | xxd -pr -r >> $scratch_dir/hostboot_runtime.sha.bin");
run_command("dd if=$scratch_dir/hostboot_runtime.sha.bin of=$scratch_dir/hostboot.temp.bin ibs=4k conv=sync");
run_command("cat $hb_image_dir/img/hostboot_runtime.bin >> $scratch_dir/hostboot.temp.bin");
run_command("dd if=$scratch_dir/hostboot.temp.bin of=$scratch_dir/hostboot_runtime.header.bin ibs=2048K conv=sync");
run_command("ecc --inject $scratch_dir/hostboot_runtime.header.bin --output $scratch_dir/hostboot_runtime.header.bin.ecc --p8");
run_command("echo -en VERSION\\\\0 > $scratch_dir/hostboot_extended.sha.bin");
run_command("sha512sum $hb_image_dir/img/hostboot_extended.bin | awk \'{print \$1}\' | xxd -pr -r >> $scratch_dir/hostboot_extended.sha.bin");
run_command("dd if=$scratch_dir/hostboot_extended.sha.bin of=$scratch_dir/hostboot.temp.bin ibs=4k conv=sync");
run_command("cat $hb_image_dir/img/hostboot_extended.bin >> $scratch_dir/hostboot.temp.bin");
run_command("dd if=$scratch_dir/hostboot.temp.bin of=$scratch_dir/hostboot_extended.header.bin ibs=5120k conv=sync");
run_command("ecc --inject $scratch_dir/hostboot_extended.header.bin --output $scratch_dir/hostboot_extended.header.bin.ecc --p8");
#Create blank binary file for HB Errorlogs (HBEL) Partition
run_command("dd if=/dev/zero bs=128K count=1 | tr \"\\000\" \"\\377\" > $scratch_dir/hostboot.temp.bin");
run_command("ecc --inject $scratch_dir/hostboot.temp.bin --output $scratch_dir/hbel.bin.ecc --p8");\
#Create blank binary file for GUARD Data (GUARD) Partition
run_command("dd if=/dev/zero bs=16K count=1 | tr \"\\000\" \"\\377\" > $scratch_dir/hostboot.temp.bin");
run_command("ecc --inject $scratch_dir/hostboot.temp.bin --output $scratch_dir/guard.bin.ecc --p8");
#Create blank binary file for NVRAM Data (NVRAM) Partition
run_command("dd if=/dev/zero bs=512K count=1 | tr \"\\000\" \"\\377\" > $scratch_dir/hostboot.temp.bin");
run_command("ecc --inject $scratch_dir/hostboot.temp.bin --output $scratch_dir/nvram.bin.ecc --p8");
#Create blank binary file for MVPD Partition
run_command("dd if=/dev/zero bs=512K count=1 | tr \"\\000\" \"\\377\" > $scratch_dir/hostboot.temp.bin");
run_command("ecc --inject $scratch_dir/hostboot.temp.bin --output $scratch_dir/mvpd_fill.bin.ecc --p8");
#Create blank binary file for DJVPD Partition
run_command("dd if=/dev/zero bs=256K count=1 | tr \"\\000\" \"\\377\" > $scratch_dir/hostboot.temp.bin");
run_command("ecc --inject $scratch_dir/hostboot.temp.bin --output $scratch_dir/djvpd_fill.bin.ecc --p8");
#Add ECC Data to CVPD Data (CVPD) Partition
run_command("ecc --inject $hb_binary_dir/cvpd.bin --output $scratch_dir/cvpd.bin.ecc --p8");
#Create blank binary file for ATTR_TMP Partition
run_command("dd if=/dev/zero bs=28K count=1 | tr \"\\000\" \"\\377\" > $scratch_dir/hostboot.temp.bin");
run_command("ecc --inject $scratch_dir/hostboot.temp.bin --output $scratch_dir/attr_tmp.bin.ecc --p8");
#Create blank binary file for ATTR_PERM Partition
run_command("dd if=/dev/zero bs=28K count=1 | tr \"\\000\" \"\\377\" > $scratch_dir/hostboot.temp.bin");
run_command("ecc --inject $scratch_dir/hostboot.temp.bin --output $scratch_dir/attr_perm.bin.ecc --p8");
#Create blank binary file for OCC Partition
run_command("dd if=$occ_binary_filename of=$scratch_dir/hostboot.temp.bin ibs=1M conv=sync");
run_command("ecc --inject $scratch_dir/hostboot.temp.bin --output $occ_binary_filename.ecc --p8");
#Create blank binary file for FIRDATA Partition
run_command("dd if=/dev/zero bs=8K count=1 | tr \"\\000\" \"\\377\" > $scratch_dir/hostboot.temp.bin");
run_command("ecc --inject $scratch_dir/hostboot.temp.bin --output $scratch_dir/firdata.bin.ecc --p8");
#Copy Binary Data files for consistency
run_command("cp $hb_binary_dir/$sbec_binary_filename $scratch_dir/");
run_command("cp $hb_binary_dir/$sbe_binary_filename $scratch_dir/");
run_command("cp $hb_binary_dir/p8.ref_image.hdr.bin.ecc $scratch_dir/");
#END MAIN
#-------------------------------------------------------------------------
############# HELPER FUNCTIONS #################################################
# Function to first print, and then run a system command, erroring out if the
# command does not complete successfully
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 remove leading and trailing whitespeace before returning that string
sub trim_string {
my $str = shift;
$str =~ s/^\s+//;
$str =~ s/\s+$//;
return $str;
}