diff options
author | Madhavan Srinivasan <maddy@linux.vnet.ibm.com> | 2016-11-03 23:52:43 +0530 |
---|---|---|
committer | Rajarshi Das <drajarshi@in.ibm.com> | 2017-01-12 02:35:31 -0600 |
commit | 1e9910e7e36e7d93cfbe5da652d2b00bf16f8e1d (patch) | |
tree | 17f13ceb15f79d574c8f9a5745b1a5d4e82590d0 | |
parent | 70d4e1979b08df8c3685e05f717fd2e44dcd6988 (diff) | |
download | ima-catalog-1e9910e7e36e7d93cfbe5da652d2b00bf16f8e1d.tar.gz ima-catalog-1e9910e7e36e7d93cfbe5da652d2b00bf16f8e1d.zip |
openpower/ima-catalog: build script for ima-catalog.bin
Initial commit for the ima-catalog.bin build script
-rwxr-xr-x | build.sh | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..c260be4 --- /dev/null +++ b/build.sh @@ -0,0 +1,120 @@ +#!/bin/bash +# +# Based on "openpower/capp-ucode" build.sh script. + +# +# #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]; +# }; + +# +# Two parameters are passed to this script +# 1)Path to host-tools +# 2)Platform to build +# + +declare -a ima_arr +declare -a ima_pvr +declare -a ima_file + +#Catalog files to pickup for a given platform +declare -a POWER8=('81E00610.4D0100.dts' '81E00610.4D0200.dts') +declare -a POWER8_PVR=(0x4d0100 0x4d0200) +declare -a POWER8_FILENAME=(0x4d0100.bin 0x4d0200.bin) + +align() { + echo $(( (($1 + ($alignment - 1))) & ~($alignment - 1) )) +} + +if [ "$2" == "POWER8" ]; then + ima_arr=("${POWER8[@]}") + ima_pvr=("${POWER8_PVR[@]}") + ima_file=("${POWER8_FILENAME[@]}") +fi + +entries=$((${#ima_arr[@]})) +debug=true +if [ -n "$DEBUG" ] ; then + debug=echo +fi + +#Generate the Device Tree Binary (DTB) files from DTS (text) +if [ $entries -gt 0 ]; then + for i in $(seq 0 $(($entries - 1)) ) ; do + $1/dtc -O dtb -I dts -o ${ima_file[${i}]} ${ima_arr[${i}]} + $1/xz -9 -C crc32 ${ima_file[${i}]} + mv ${ima_file[${i}]}.xz ${ima_file[${i}]} + + size=$( stat -c %s ${ima_file[${i}]} ) + pad=$(( 8000 - $(($size)))) + dd if=/dev/zero count=$pad bs=1 >> ${ima_file[${i}]} + done +fi + +#Create a tmp file for manipulation +TMPFILE=$(mktemp) + +EYECATCHER=$(( 0x494D4143 )) # ascii 'IMAC' +VERSION=1 +NUMBEROFTOCENTRIES=$entries + +printf "0: %.8x" $EYECATCHER | xxd -r -g0 >> $TMPFILE +printf "0: %.8x" $VERSION | xxd -r -g0 >> $TMPFILE + +sections=0 +alignment=$(( 0x1000 )) +offset=$alignment + + +for i in $(seq 0 $(($NUMBEROFTOCENTRIES - 1 ))) ; do + # Work out if we added this file already + matched=0 + for s in $(seq $sections); do + if cmp -s ${ima_file[$i]} ${sectionfile[$s]} ; then + $debug matched ${ima_file[$i]} ${sectionfile[$s]} + matched=1 + section=$s + break 1 + fi + done + if [ $matched == 0 ] ; then + sections=$(( $sections + 1 )) + sectionfile[$sections]=${ima_file[$i]} + sectionsize[$sections]=$( stat -c %s ${sectionfile[$sections]} ) + sectionoffset[$sections]=$(align $offset) + offset=$(( $offset + ${sectionsize[$sections]} )) + $debug Adding section ${ima_file[$i]} size: ${sectionsize[$sections]} offset: ${sectionoffset[$sections]} + section=$sections + fi + + # Add TOC entry for every PHB3 to + printf "0: %.8x" ${ima_pvr[$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 ima_catalog.bin +rm -rf $TMPFILE + |