forked from open-power/capp-ucode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·102 lines (83 loc) · 2.56 KB
/
build.sh
File metadata and controls
executable file
·102 lines (83 loc) · 2.56 KB
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
#!/bin/bash
# #define PNOR_SUBPART_HEADER_SIZE 0x1000
# struct pnor_hostboot_toc {
# be32 ec;
# be32 offset; /* from start of header. 4K aligned */
# be32 size; /* */
# };
# #define PNOR_HOSTBOOT_TOC_MAX_ENTRIES ((PNOR_SUBPART_HEADER_SIZE - 8)/sizeof(struct pnor_hostboot_toc))
# struct pnor_hostboot_header {
# char eyecatcher[4];
# be32 version;
# struct pnor_hostboot_toc toc[PNOR_HOSTBOOT_TOC_MAX_ENTRIES];
# };
align() {
echo $(( (($1 + ($alignment - 1))) & ~($alignment - 1) ))
}
phb3=0
phb3=$(( $phb3 + 1))
phb3id[$phb3]=$(( 0x100ea ))
phb3file[$phb3]="CAPPUC_T0V10.bin"
phb3=$(( $phb3 + 1))
phb3id[$phb3]=$(( 0x200ea ))
phb3file[$phb3]="CAPPUC_T0V20.bin"
phb3=$(( $phb3 + 1))
phb3id[$phb3]=$(( 0x200ef ))
phb3file[$phb3]="CAPPUC_T0M20.bin"
phb3=$(( $phb3 + 1))
phb3id[$phb3]=$(( 0x201ef ))
phb3file[$phb3]="CAPPUC_T0M21.bin"
phb3=$(( $phb3 + 1))
phb3id[$phb3]=$(( 0x100d3 ))
phb3file[$phb3]="CAPPUC_T0N10.bin"
debug=true
if [ -n "$DEBUG" ] ; then
debug=echo
fi
TMPFILE=$(mktemp)
EYECATCHER=$(( 0x43415050 )) # ascii 'CAPP'
VERSION=1
NUMBEROFTOCENTRIES=$phb3
printf "0: %.8x" $EYECATCHER | xxd -r -g0 >> $TMPFILE
printf "0: %.8x" $VERSION | xxd -r -g0 >> $TMPFILE
sections=0
alignment=$(( 0x1000 ))
offset=$alignment
# Add IDs
for i in $(seq $NUMBEROFTOCENTRIES) ; do
# Work out if we added this file already
matched=0
for s in $(seq $sections); do
if cmp -s ${phb3file[$i]} ${sectionfile[$s]} ; then
$debug matched ${phb3file[$i]} ${sectionfile[$s]}
matched=1
section=$s
break 1
fi
done
if [ $matched == 0 ] ; then
sections=$(( $sections + 1 ))
sectionfile[$sections]=${phb3file[$i]}
sectionsize[$sections]=$( stat -c %s ${sectionfile[$sections]} )
sectionoffset[$sections]=$(align $offset)
offset=$(( $offset + ${sectionsize[$sections]} ))
$debug Adding section ${phb3file[$i]} size: ${sectionsize[$sections]} offset: ${sectionoffset[$sections]}
section=$sections
fi
# Add TOC entry for every PHB3 to
printf "0: %.8x" ${phb3id[$i]} | xxd -r -g0 >> $TMPFILE
printf "0: %.8x" ${sectionoffset[$section]} | xxd -r -g0 >> $TMPFILE
printf "0: %.8x" ${sectionsize[$section]} | xxd -r -g0 >> $TMPFILE
done
# write zeros to alignment
bytes=$(( $alignment - 8 - ($NUMBEROFTOCENTRIES * 12) ))
dd if=/dev/zero count=$bytes bs=1 >> $TMPFILE
# Add file sections
for i in $(seq $sections) ; do
cat ${sectionfile[$i]} >> $TMPFILE
# write zeros to alignment
bytes=$(( $(align ${sectionsize[$i]}) - ${sectionsize[$i]} ))
dd if=/dev/zero count=$bytes bs=1 >> $TMPFILE
done
mv $TMPFILE cappucode.bin
rm -rf $TMPFILE