同樣是壓箱底的老腳本,用來編譯並燒錄 uboot,其中最後一段應該不是我親手寫的,一併收錄進來。
#!/bin/sh #build.sh set -e CPU_NUM=$(grep processor /proc/cpuinfo | awk '{field=$NF};END{print field+1}') ROOT_DIR=$PWD U_BOOT_DIR=$ROOT_DIR/u-boot-2013.01 SEC_DIR=$ROOT_DIR/CodeSign4SecureBoot SDQ_DIR=$ROOT_DIR/sdfuse_q export ARCH=arm export CROSS_COMPILE=/opt/arm-linux-gcc-4.6.4/bin/arm-linux- cd $U_BOOT_DIR case "$1" in clean) echo make clean make mrproper rm -rf $U_BOOT_DIR/CodeSign4SecureBoot rm -rf $U_BOOT_DIR/sdfuse_q ;; tags) echo $PWD ctags -R * ;; config) if [ ! -d $SEC_DIR ] ; then echo "**********************************************" echo "[ERR]please get the CodeSign4SecureBoot first" echo "**********************************************" exit 0 elif [ ! -d $SDQ_DIR ] ; then echo "**********************************************" echo "[ERR]please get the sdfuse_q first" echo "**********************************************" exit 0 fi cp -a $SEC_DIR $U_BOOT_DIR cp -a $SDQ_DIR $U_BOOT_DIR make origen_config ;; *) make -j$CPU_NUM split -b 14336 u-boot.bin bl2 make -C $U_BOOT_DIR/sdfuse_q $U_BOOT_DIR/sdfuse_q/chksum $U_BOOT_DIR/sdfuse_q/add_padding rm bl2a* if [ ! -f checksum_bl2_14k.bin ] then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "There are some error(s) while building uboot, please use command make to check." echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" exit 0 fi cp -rf checksum_bl2_14k.bin $U_BOOT_DIR/CodeSign4SecureBoot cp -rf u-boot.bin $U_BOOT_DIR/CodeSign4SecureBoot rm checksum_bl2_14k.bin cd $U_BOOT_DIR/CodeSign4SecureBoot cat E4412_N.bl1.SCP2G.bin bl2.bin all00_padding.bin u-boot.bin tzsw_SMDK4412_SCP_2GB.bin > u-boot-4412.bin cp -a u-boot-4412.bin /home/tftpdir mv u-boot-4412.bin $ROOT_DIR/mk_sdboot rm checksum_bl2_14k.bin rm u-boot.bin echo echo ;; esac
第一段 build.sh 用 case 分支把常用操作都收攏了:clean 清理產物、tags 生成 ctags 索引、config 檢查安全啟動相關目錄並拷貝配置,其餘情況則走完整的編譯、加簽、填充、拼接流程,最終把 u-boot-4412.bin 分別送往 TFTP 目錄與 mk_sdboot。
#!/bin/bash # # This script will create a u-boot binary for movinand/mmc boot # #mkuboot.sh echo "Fuse 4412 trustzone uboot file into SD card" if [ -z $1 ] then ./sd_fusing_exynos4x12.sh /dev/sdb u-boot-4412.bin else ./sd_fusing_exynos4x12.sh $1 u-boot-4412.bin fi
第二段 mkuboot.sh 是個語法糖,專門負責把上一步產生的鏡像燒進 SD 卡,沒帶參數時默認寫入 /dev/sdb。
#!/bin/sh # # Copyright (C) 2010 Samsung Electronics Co., Ltd. # https://www.samsung.com/ # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # #################################### #sd_fuse_exynos4x12.sh reader_type1="/dev/sd" reader_type2="/dev/mmcblk0" if [ -z $2 ] then echo "usage: ./sd_fusing.sh <SD Reader's device file> <filename>" exit 0 fi param1=`echo "$1" | awk '{print substr($1,1,7)}'` if [ "$param1" = "$reader_type1" ] then partition=$1"1" elif [ "$1" = "$reader_type2" ] then partition=$1"p1" else echo "Unsupported SD reader" exit 0 fi if [ -b $1 ] then echo "$1 reader is identified." else echo "$1 is NOT identified." exit 0 fi #################################### echo "----------------------------------" echo $partition echo "----------------------------------" # format umount $partition 2> /dev/null echo "$2 fusing..." dd iflag=dsync oflag=dsync if=./$2 of=$1 seek=1 && \ echo "$2 image has been fused successfully." #################################### #<Message Display> echo "Eject SD card"
第三段是三星官方的 sd_fusing_exynos4x12.sh,負責辨識讀卡器設備、換算分區名,再用 dd 以 seek=1 的方式把鏡像精確寫入 SD 卡對應位置。三段腳本串起來,就是「編譯 → 加簽拼接 → 燒卡」的一條完整流水線。