| #!/bin/bash |
| #set -x |
| #set -e |
| |
| inFile=${1?need input file} |
| #outFile=${2:-block1_layout.bin} |
| outFile=${2:-"out"} |
| if [ ! -f $inFile ]; then echo "$inFile does not exist"; exit 1; fi |
| |
| # BLOCK1_IMAGE_TYPE_MASK = 0x000000FF; |
| # BLOCK1_IMAGE_TYPE_LAYOUT = 0x00; |
| # BLOCK1_IMAGE_TYPE_EROM = 0x01; |
| # BLOCK1_IMAGE_TYPE_IMAGE2 = 0x02; |
| # BLOCK1_IMAGE_TYPE_LOADER = 0x03; |
| # BLOCK1_IMAGE_TYPE_TZ = 0x04; |
| # BLOCK1_IMAGE_TYPE_DATA = 0x10; |
| # |
| # BLOCK1_IMAGE_DESTINATION_TYPE_MASK = 0x000F0000; |
| # BLOCK1_IMAGE_DESTINATION_IN_SOC = 0x00000; |
| # BLOCK1_IMAGE_DESTINATION_IN_BCM = 0x10000; |
| # BLOCK1_IMAGE_DESTINATION_NA = 0x20000; |
| # |
| # BLOCK1_IMAGE_SIGNING_OPTIONS_MASK = 0x0F0000000; |
| # BLOCK1_IMAGE_IS_SIGNED = 0x00000000; |
| # BLOCK1_IMAGE_NOT_SIGNED = 0x10000000; |
| # |
| # BLOCK1_IMAGE_HANDSHAKE_MASK = 0xF0000000; |
| # BLOCK1_IMAGE_HANDSHAKE_ACK = 0x80000000; |
| |
| |
| #image1/release/bcm_erom.bin |
| #image1/release/bcm_erom.info |
| #image2/release/samsung_image2.bin |
| #image2/release/samsung_image2.info |
| |
| # type START SIZE entry |
| #echo 0x00010001 0x00000 0x01400 0x0002c000 bcm erom |
| ##echo 0x01000000 0x01400 0x00080 0xf7a40004 this |
| #echo 0x00000002 0x01400 0x04C00 0xf7a40000 sysinit or drm-erom |
| #echo 0x00000003 0x06000 0x56000 0x00680000 bootloader |
| #echo |
| |
| function endian |
| { |
| # revert_endian for xxd |
| local VAL=${1?need value} |
| local HEX="$(printf %08x $VAL)" |
| local HEX1=`echo $HEX|cut -b 7-8` |
| local HEX2=`echo $HEX|cut -b 5-6` |
| local HEX3=`echo $HEX|cut -b 3-4` |
| local HEX4=`echo $HEX|cut -b 1-2` |
| |
| echo "0x$HEX1$HEX2$HEX3$HEX4" |
| } |
| |
| function gen_layout_item |
| { |
| #generate "$TYPE $FROM $SIZE $ENTRY" for a layout item |
| local TYPE=${1:-0} |
| local FROM=${2:-0} |
| local NAME=${3?need file name} |
| |
| # get "Entry point address: 0x2c001" string |
| local TXT=$(cat $NAME.info|grep "Entry point") |
| |
| # remve till ':' char and revert the endian |
| local ENTRY="$(endian $(printf %d ${TXT#*:}))" |
| |
| # get file size and revert the endian |
| local SIZE="$(endian $(stat -c %s $NAME.bin))" |
| |
| # revert the endian |
| let TYPE="$(endian $(printf %d $TYPE))" |
| let FROM="$(endian $(printf %d $FROM))" |
| |
| echo "$TYPE $FROM $SIZE $ENTRY" |
| } |
| |
| function output_layout_item |
| { |
| declare -a entry_l=("${!1}") |
| declare -i nItems=${#entry_l[@]} |
| local str |
| |
| [ $nItems -eq 4 ] || (echo "nItems($nItems) != 4"; exit 1); |
| for k in $(seq 0 $((${#entry_l[@]} - 1))); do |
| printf %08x ${entry_l[$k]} | xxd -r -p >>$outFile |
| str="$str $(printf "0x%08x" $(endian ${entry_l[$k]}))" |
| done |
| echo "output item: $str" |
| } |
| |
| echo "inFile is $inFile" |
| numImg=0 |
| declare -a entry |
| declare -a nameList |
| declare -a typeList |
| while read line; do |
| entry=($line) |
| nameList[$numImg]=${entry[0]} |
| typeList[$numImg]=${entry[1]} |
| let "numImg += 1" |
| #echo "line $numImg:${entry[0]} ${entry[1]}" |
| done < "$inFile" |
| |
| #echo "names: ${nameList[@]}" |
| #echo "types: ${typeList[@]}" |
| #exit 0 |
| |
| #numArg=$# |
| #image1=${1:-image1/release/bcm_erom} |
| #image2=${2:-image2/release/samsung_image2} |
| #image3=${3:-bootloader/release/nand_bootloader} |
| #nameList=($image1 $image2 $image3) |
| #nameList=($image1 $image2) |
| #nameList=($@) |
| #typeList=(0x10001 2 3) |
| |
| |
| sizeofItem=16 |
| ALIGN=1024 |
| START=0 |
| |
| # the element index of the layout item |
| iTYPE=0 |
| iSTART=1 |
| iSIZE=2 |
| iENTRY=3 |
| |
| |
| rm $outFile |
| #MV_Block1_Head; |
| #unsigned int HeaderVersion; |
| #unsigned short MagicNumber; |
| #unsigned short OffsetSignature; |
| #unsigned char NumItems; |
| #unsigned char RootAesKey; |
| #unsigned char SubKeyIndex; |
| #unsigned char SubKeyParam; |
| |
| let numImg="(${#nameList[@]} + 1)" |
| let uint_1="$(printf %d 0xda7a)" |
| let uint_1="(($numImg + 1) * $sizeofItem) * 65536 + $uint_1" |
| entry=($(endian 1) $(endian $uint_1) $(endian $numImg) 0) |
| output_layout_item entry[@] |
| |
| let sizeLayout="(($numImg + 1) * 16)" |
| entry=(0 $(endian 512) $(endian $sizeLayout) $(endian 0xf7a60010)) |
| output_layout_item entry[@] |
| |
| for i in $(seq 0 $((${#nameList[@]} - 1))); do |
| # TYPE START SIZE ENTRY |
| entry=($(gen_layout_item ${typeList[$i]} $START ${nameList[$i]})) |
| let SIZE="$(printf %d $(endian ${entry[$iSIZE]}))" |
| let START="($START + $SIZE + $ALIGN - 1) / $ALIGN * $ALIGN" |
| #echo "img $i: ${entry[*]}" |
| #echo "start=$(printf 0x%08x ${entry[iSTART]}); size=$(printf 0x%08x ${entry[iSIZE]})" |
| |
| output_layout_item entry[@] |
| #for k in $(seq 0 $((${#entry[@]} - 1))); do |
| #printf %08x ${entry[$k]} | xxd -r -p >>$outFile |
| #done |
| done |
| |
| xxd -g1 $outFile |