BL1对应的文件是 E4412_N.bl1.bin文件。
BL2是根据我们提供的程序来制作的,此工具的源码是V310-EVT1-mkbl2.c,存放在/work/4412/tools 目录下,可用以下命令生成可执行程序 mkbl2:
gcc -o my_mkbl2 V310-EVT1-mkbl2.c
mkbl2的作用是截取用户提供的bin文件的前(14K-4)字节数据,算出4字节的较验码,然后这两部
分数据组合成14KB的文件bl2.bin,它就是BL2。
对于SD卡,我们只需要把E4412_N.bl1.bin烧在偏移地址512字节处,把bl2.bin烧在偏移地址(512+8K)字节处。
如果用户提供的bin大于(14K-4)字节,还需要把它烧写在SD卡其他位置,这由用户决定。 我们的大部
分程序没超过(14K-4)字节,所以这种情况暂时不理会。
对于SD卡,烧写过程总结如下:
- 把E4412_N.bl1.bin烧在偏移地址512字节处;
- 使用mkb12命令,把用户提供的bin文件制作出bl2.bin,命令如下(修改 bin 文件名leds.bin):
-
mkbl2 leds.bin bl2.bin 14336
把 bl2.bin 烧在偏移地址(512+8K)字节处;
为简单化操作,我们把这些命令写入sd_fusing.sh文件中,使用时只要执行以下命令即可(假设SD卡的
设备节点为/dev/sdb,用户bin文件为 leds.bin):
sd_fusing.sh /dev/sdc leds.bin
注意:把SD卡接到PC后执行以下命令,一般最后一个“不带数字的”设备节点就是SD卡的设备名:
$ ls /dev/sd*
输出示例:
/dev/sda /dev/sda1 /dev/sda2 /dev/sda5 /dev/sdb /dev/sdb1 /dev/sdc /dev/sdc1
在上面的输出示例中, /dev/sdb就是该卡的设备名。
sd_fusing.sh 的源码如下(注释很完善,不用再讲解):
#
# Copyright (C) 2013 100ask
# http://www.100ask.net/
####################################
if [ -z $1 ] #判断参数1的字符串是否为空,如果为空,则打印出帮助信息
then
echo "usage: sd_fusing.sh <SD Reader's device file> <Source file>"
exit 0;
fi
if [ -z $2 ] #判断参数2的字符串是否为空,如果为空,则打印出帮助信息
then
echo "usage: sd_fusing.sh <SD Reader's device file> <Source file>"
exit 0;
fi
if [ -b $1 ] #判断参数1所指向的设备节点是否存在
then
echo "$1 reader is identified."
else
echo "$1 is NOT identified."
exit -1;
fi
####################################
#<verify device>
BDEV_NAME=`basename $1`
BDEV_SIZE=`cat /sys/block/${BDEV_NAME}/size`
#如果卡的容量小于0,则打印失败信息,并退出
if [ ${BDEV_SIZE} -le 0 ]; then
echo "Error: NO media found in card reader."
exit 1;
fi
#如果卡的容量大于32000000,则打印失败信息,并退出
if [ ${BDEV_SIZE} -gt 32000000 ]; then
echo "Error: Block device size (${BDEV_SIZE}) is too large"
exit 1;
fi
####################################
# check files
SOURCE_FILE=$2
MKBL2=mkbl2
#检查source file是否存在
if [ ! -f ${SOURCE_FILE} ]; then
echo "Error: $2 NOT found, please build it & try again."
exit -1;
fi
#<make bl2>
#使用mkbl2工具来处理传入的bin,从而生成bl2.bin
./${MKBL2} ${SOURCE_FILE} bl2.bin 14336
####################################
# fusing images
signed_bl1_position=1 #bl1的镜像烧写到sd卡的第1个扇区
bl2_position=17 #bl2的镜像烧写到sd卡的第17个扇区
#<BL1 fusing>
echo "---------------------------------------"
echo "BL1 fusing"
# 烧写bl1到SD卡512字节处
dd iflag=dsync oflag=dsync if=/work/tiny4412/sd_fuse/tiny4412/E4412_N.bl1.bin of=$1 seek=$signed_bl1_position
# 如果失败则退出
if [ $? -ne 0 ]
then
echo Write BL1 Error!
exit -1;
fi
#<BL2 fusing>
echo "---------------------------------------"
echo "BL2 fusing"
# 烧写bl2到SD卡(512+8K)字节处, 512+8K=17x512,即第17个block
dd iflag=dsync oflag=dsync if=./bl2.bin of=$1 seek=$bl2_position
# 如果失败则退出
if [ $? -ne 0 ]
then
echo Write BL2 Error!
exit -1;
fi
#<flush to disk>
# 同步文件
sync
rm bl2.bin
####################################
#<Message Display>
echo "---------------------------------------"
echo "source file image is fused successfully."
echo "Eject SD card and insert it to Exynos 4412 board again.";