| #!/bin/bash |
| |
| NAND=${1:-micron} |
| #NAND=${1:-powerchip} |
| NAND=${1:-toshiba} |
| MV88DE3100_SDK=$(readlink -f ../..) |
| WORKING_DIR=$(readlink -f .) |
| |
| [ "$FLASH_TYPE" = "" -o "$CUST_SELFKEY_IMAGE" = "" ] && { |
| source $MV88DE3100_SDK/Customization_Data/config |
| if [ -z $CPUPLL ];then |
| CPUPLL=1000 |
| fi |
| if [ -z $MEMPLL ];then |
| MEMPLL=1600 |
| fi |
| if [ -z $SYSPLL ];then |
| SYSPLL=800 |
| fi |
| |
| export PLATFORM |
| export CPUPLL |
| export PV_COMP |
| export NFCECCCLK |
| export LINUX_ON_CPU1 |
| export CPU_TYPE |
| export CPU_PLL |
| export MEMPLL |
| export SYSPLL |
| export SYSTEM_CONFIGURATION_PATH |
| export PLATFORM_INFO |
| export BUILD_GOOGLETV |
| export BOOT_TYPE |
| export RANDOMIZER |
| export CONFIG_NAND_READ_RETRY |
| export CONFIG_ENHANCED_SLC |
| export CONFIG_SLC |
| export SM_IMAGE_ACTIVE |
| export SM_IMAGE_PATH |
| export SM_IMAGE_FORMAT |
| export CPU0_START_ADDR |
| export CONFIG_GPT |
| export DISABLE_CRASH_COUNTER |
| export BERLIN_CHIP |
| top_data_dir=$MV88DE3100_SDK/Customization_Data/ |
| export top_data_dir |
| } |
| pagesize=`echo $FLASH_TYPE | cut -d _ -f1` |
| page_per_block=`echo $FLASH_TYPE | cut -d _ -f3` |
| block_size=`expr $pagesize \* $page_per_block` |
| block_size_kB=`expr $block_size / 1024` |
| echo "pagesize=$pagesize , page_per_block=$page_per_block" |
| echo "block_size_kB=$block_size_kB" |
| |
| #WORKING_DIR=`pwd` |
| #yunsen ADDHEADER_TOOL="../Scripts/addheader.sh" |
| ADDHEADER_TOOL="$MV88DE3100_SDK/tool/addheader.sh" |
| LOCAL_CUST_SELFKEY_PATH=$MV88DE3100_SDK/Customization_Data/${CUST_SELFKEY_IMAGE} |
| SYSTEM_INIT_FILE_LOCAL=SI_part1.bin |
| SI_CUST_FIGO_IMAGE_LOCAL=SI_cust_figo.bin |
| SM_PATH=$MV88DE3100_SDK/Customization_Data/$SM_IMAGE_PATH |
| if [ $BOOT_TYPE = "NAND_BOOT" ]; then |
| BOOT_DEV=nand |
| else |
| BOOT_DEV=emmc |
| fi |
| |
| # copy the linux parameters (bootargs) |
| if [ ! -f ../.temp/linux_param.h ]; then |
| echo run \"make linux_param\" under MV88DE3100_Tools/ first |
| exit 1 |
| fi |
| cp -f ../.temp/linux_param.h . |
| |
| # check platform info |
| if [ \( ! -f $top_data_dir/$PLATFORM_INFO \) -a \( ! -L $top_data_dir/$PLATFORM_INFO \) ]; then |
| echo "Error: Pin setting file $top_data_dir/$PLATFORM_INFO does not exist." |
| exit 1 |
| fi |
| cp -f $top_data_dir/$PLATFORM_INFO pin_settings.h ||exit 1 |
| |
| # copy SM |
| if [ "$SM_IMAGE_FORMAT" = "binary" ]; then |
| echo "SM image is a binary file" |
| else |
| echo "SM image is a $SM_IMAGE_FORMAT file" do not support now |
| exit 1 |
| fi |
| cp -f $SM_PATH sm.bin |
| |
| if [ $BERLIN_CHIP = "BG2CD" ]; then |
| SYS_INIT_DIR=../sys_init_bg2cd |
| else |
| if [ $CPU_TYPE = "Z1" -o $CPU_TYPE = "Z2" ];then |
| SYS_INIT_DIR=../sys_init_Zx |
| else |
| SYS_INIT_DIR=../sys_init |
| fi |
| fi |
| |
| #yunsen SYS_INIT_BIN_FILE=sys_init_${BOOT_DEV}_secure_CPU"$CPUPLL"_MEM"$MEMPLL"_SYS"$SYSPLL"_$CPU_TYPE.bin |
| |
| #yunsen [ $# = 1 ] && VT_PATH=$1 || VT_PATH=../.temp/version_table |
| VT_PATH=../.temp/version_table |
| |
| #if [ "$ROM_KEY_DISABLE" = "0" ]; then |
| # cp diag_jtag_switch_figo_romkey.bin figo_image.bin |
| #else |
| # cp diag_jtag_switch_figo_distkey.bin figo_image.bin |
| #fi |
| |
| if [ "$PRODUCTION_CHIP" = "0" ]; then |
| echo "Generating bootloader for engineer chip" |
| if [ ! -f ../DRM_Image/customer_keystore_figo.bin_ROM_Key ]; then |
| echo "../DRM_Image/customer_keystore_figo.bin_ROM_Key not found" |
| exit 1 |
| fi |
| DRM_IMAGE_FILE=../DRM_Image/customer_keystore_figo.bin_ROM_Key |
| #yunsen if [ "is$PLATFORM" != "is" -a -d $SYS_INIT_DIR/$PLATFORM ]; then |
| #yunsen SYS_INIT_BIN_DIR=$SYS_INIT_DIR/$PLATFORM/${BOOT_DEV}_secure_romkey |
| #yunsen else |
| #yunsen SYS_INIT_BIN_DIR=$SYS_INIT_DIR/default/${BOOT_DEV}_secure_romkey |
| #yunsen fi |
| else |
| echo "Generating bootloader for production chip" |
| if [ ! -f ../DRM_Image/customer_keystore_figo.bin_Dist_Key ]; then |
| echo "../DRM_Image/customer_keystore_figo.bin_Dist_Key not found" |
| exit 1 |
| fi |
| DRM_IMAGE_FILE=../DRM_Image/customer_keystore_figo.bin_Dist_Key |
| #yunsen if [ "is$PLATFORM" != "is" -a -d $SYS_INIT_DIR/$PLATFORM ]; then |
| #yunsen SYS_INIT_BIN_DIR=$SYS_INIT_DIR/$PLATFORM/${BOOT_DEV}_secure_distkey |
| #yunsen else |
| #yunsen SYS_INIT_BIN_DIR=$SYS_INIT_DIR/default/${BOOT_DEV}_secure_distkey |
| #yunsen fi |
| fi |
| |
| # Copy system init part1 image and cust figo image to local |
| cp $DRM_IMAGE_FILE $SI_CUST_FIGO_IMAGE_LOCAL |
| |
| SYS_INIT_BIN_DIR=$MV88DE3100_SDK/image2/release #yunsen |
| SYS_INIT_BIN_FILE=${NAND}_sysinit.bin #yunsen |
| echo "sys_init binary file: $SYS_INIT_BIN_DIR/$SYS_INIT_BIN_FILE" |
| #yunsen cp $SYS_INIT_BIN_DIR/$SYS_INIT_BIN_FILE $SYSTEM_INIT_FILE_LOCAL || exit 1 |
| cp $MV88DE3100_SDK/image1/release/bcm_erom.bin init_erom.bin || exit 1 |
| cp $MV88DE3100_SDK/image2/release/${NAND}_sysinit.bin init_boot.bin || exit 1 |
| cat init_erom.bin init_boot.bin >$SYSTEM_INIT_FILE_LOCAL |
| |
| if [ ! -f $VT_PATH ];then |
| echo "please generate $VT_PATH first." |
| exit 1 |
| fi |
| |
| # Generate Customer Key Store in C style |
| if [ "x$CUST_KEY_IMAGE_2ND" != "x" ]; then |
| cat $MV88DE3100_SDK/Customization_Data/${CUST_KEY_IMAGE_2ND} | xxd -i > customer_key_store.h |
| else |
| echo > customer_key_store.h |
| fi |
| |
| make clean &&\ |
| make configure ASIC=BG2CDP CPU_TYPE=$CPU_TYPE CPUPLL=$CPUPLL BOX_PRODUCT_RELEASE=$BOX_PRODUCT_RELEASE BOOT_TYPE=$BOOT_TYPE RANDOMIZER=$RANDOMIZER &&\ |
| make >/dev/null && \ |
| rm -f pin_settings.h #|| exit 1 |
| |
| |
| echo cust_self_key=$CUST_SELFKEY_IMAGE |
| ls -l $MV88DE3100_SDK/Customization_Data/$CUST_SELFKEY_IMAGE |
| |
| #yunsen $ADDHEADER_TOOL bootloader.elf bootloader_en.bin && \ |
| #yunsen cp -f ../enc_tool . && \ |
| #yunsen cp -f ../Common/tools/encryption.sh ./ |
| #yunsen cp -f ../Common/tools/encrypt ./ |
| #yunsen if [ "$CPU_IMAGE_ENCRYPT" = "y" ];then |
| #yunsen cp -f $LOCAL_CUST_SELFKEY_PATH ./ |
| #yunsen fi |
| #yunsen ./encryption.sh bootloader_en.bin bootloader_en.bin || { |
| ENC_TOOL=$MV88DE3100_SDK/tool/bin/cdp_sign0 |
| $ENC_TOOL -C3 -B1 -i bootloader.bin -O bootloader_en.bin > bootloder.log || { |
| echo fail to generate bootloader_en.bin |
| exit 1 |
| } |
| |
| if [ "$ROM_KEY_DISABLE" = "" ];then |
| echo "ROM_KEY_DISABLE is not set in config file, please update your config file" |
| exit 1 |
| fi |
| |
| if [ "$ROM_KEY_DISABLE" = "1" ]; then |
| echo " ****************** ROM key has been disabled ************" |
| |
| if [ "$OTP_RSA_KEY_FILE_NAME" = "" ]; then |
| echo "ROM KEY has been disabled, but OTP_RSA_KEY_FILE_NAME is not defined" |
| exit 1 |
| fi |
| |
| if [ ! -f $MV88DE3100_SDK/Customization_Data/${OTP_RSA_KEY_FILE_NAME} ];then |
| echo " Can not find User RSA key file: $MV88DE3100_SDK/Customization_Data/${OTP_RSA_KEY_FILE_NAME} " |
| exit 1 |
| fi |
| cp $MV88DE3100_SDK/Customization_Data/${OTP_RSA_KEY_FILE_NAME} ./ |
| #cp ../SPI_Secure_Uboot_Releases_Prod_Chip/ChangeSign ./ |
| cp ../kms_release_bg2_32/seclab/bin/ChangeSign ./ |
| if [ ! -f ./ChangeSign ];then |
| echo "ChangeSign doesn't exist" |
| exit 1 |
| fi |
| |
| echo " resign system init..." |
| ./ChangeSign $SYSTEM_INIT_FILE_LOCAL 0 |
| echo " resign cust figo image..." |
| ./ChangeSign $SI_CUST_FIGO_IMAGE_LOCAL 0 |
| fi |
| |
| cp $SYSTEM_INIT_FILE_LOCAL ../IMAGE/Key_Injection/SI_part1 |
| cp $SI_CUST_FIGO_IMAGE_LOCAL ../IMAGE/Key_Injection/SI_figo_image |
| cp $MV88DE3100_SDK/Customization_Data/${CUST_KEY_IMAGE} ../IMAGE/Key_Injection/SI_cust_key |
| #cp bootloader_en.bin ../IMAGE/Key_Injection/SI_part2 |
| cp bootloader_en.bin ../IMAGE/Key_Injection/SI_part2 |
| |
| cp -vf $SYSTEM_INIT_FILE_LOCAL image2_init.bin &&\ |
| $ADDHEADER_TOOL $SI_CUST_FIGO_IMAGE_LOCAL figo.img &&\ |
| $ADDHEADER_TOOL $MV88DE3100_SDK/Customization_Data/${CUST_KEY_IMAGE} key.img || exit 1 |
| |
| echo -------------------- |
| echo begin padding |
| echo -------------------- |
| dd if=$VT_PATH of=version conv=notrunc && \ |
| SIZE=`stat -c %s version` && \ |
| dd if=/dev/urandom of=version bs=1 seek=$SIZE count=`expr 4096 - $SIZE` conv=notrunc && \ |
| SIZE=`stat -c %s figo.img` && \ |
| dd if=/dev/urandom of=figo.img bs=1 seek=$SIZE count=`expr 4096 - $SIZE` conv=notrunc && \ |
| SIZE=`stat -c %s key.img` && \ |
| dd if=/dev/urandom of=key.img bs=1 seek=$SIZE count=`expr 4096 - $SIZE` conv=notrunc && \ |
| |
| #create filler.bin |
| rm filler.bin |
| #touch filler.bin |
| #SIZE="stat -c %s image2_init.bin" && \ |
| #dd if=/dev/urandom of=filler.bin bs=1 seek=0 count=`expr 53248 - $SIZE` conv=notrunc |
| SIZE=$(stat -c %s image2_init.bin) && \ |
| head -c `expr 53248 - $SIZE` /dev/urandom >filler.bin |
| echo " Entry point address: 0x000000" >filler.info |
| |
| cat version figo.img key.img > version.bin || exit 1 |
| echo " Entry point address: 0x600000" >version.info |
| readelf -h bootloader.elf | grep "Entry point" >bootloader_en.info |
| #echo " Entry point address: 0x680000" >bootloader.info |
| |
| GEN_LAYOUT=$MV88DE3100_SDK/tool/gen_layout.sh # tool to generate block1 layout data |
| SET_LAYOUT=$MV88DE3100_SDK/tool/set_layout.sh # tool to inject block1 layout |
| echo "$MV88DE3100_SDK/image1/release/bcm_erom 0x10001" >layout.seq |
| echo "$MV88DE3100_SDK/image2/release/${NAND}_sysinit 2" >>layout.seq |
| echo "$WORKING_DIR/filler 0x100200ff" >>layout.seq |
| echo "$WORKING_DIR/version 0x10020008" >>layout.seq |
| echo "$WORKING_DIR/bootloader_en 3" >>layout.seq |
| $GEN_LAYOUT layout.seq layout.bin |
| $SET_LAYOUT layout.bin $SYSTEM_INIT_FILE_LOCAL image2_init.bin |
| |
| |
| #cat image2_init.bin version figo.img key.img bootloader_en.bin> init_loader.img || exit 1 |
| #cat image2_init.bin filler.bin version.bin bootloader_en.bin> init_loader.img || exit 1 #baowei |
| cat image2_init.bin filler.bin version.bin > init_loader.img || exit 1 |
| cat bootloader_en.bin > post-init_loader.img || exit 1 |
| |
| if [ $BOOT_TYPE = "EMMC_BOOT" ]; then |
| INIT_LOADER_FINAL_SIZE=`stat -c %s init_loader.img` |
| if [ $INIT_LOADER_FINAL_SIZE -ge 524288 ]; then |
| echo "Error: bootloader partition image size is greater than 512K." |
| exit 1; |
| fi |
| dd if=/dev/zero of=init_loader.img bs=1 count=1 seek=524287 conv=notrunc || exit 1 |
| else |
| INIT_LOADER_FINAL_SIZE=`stat -c %s init_loader.img` |
| if [ $INIT_LOADER_FINAL_SIZE -ge $block_size ]; then |
| echo "Error: bootloader partition image size is greater than block size." |
| exit 1; |
| fi |
| SIZE=`stat -c %s init_loader.img` && \ |
| |
| dd if=/dev/urandom of=init_loader.img bs=1 seek=$SIZE count=`expr $block_size - $SIZE` conv=notrunc || exit 1 |
| SIZE=`stat -c %s post-init_loader.img` && \ |
| dd if=/dev/urandom of=post-init_loader.img bs=1 seek=$SIZE count=`expr 1048576 - $SIZE` conv=notrunc || exit 1 |
| fi |