uboot分析:SD卡镜像制作脚本分析

1. sd_fusing文件夹基本介绍

sd_fusing文件中的sd_fushing.sh脚本文件用于制作U-Boot的SD卡镜像,即将u-boot.bin镜像烧录进SD卡中,以便于开发板从SD卡中启动U-Boot。

sd_fusing文件夹下各文件介绍

sd_fusing.sh SD卡镜像制作脚本
sd_fusing2.sh SD卡镜像制作脚本2,一般用第一个
sd_fdisk.c 用于生成sd_fdisk
sd_fdisk 用于SD卡分区
C110-EVT1-mkbl1.c 用于生成mkbl1
mkbl1 用于计算U-Boot校验和
c110.signedBL1_bin 将U-Boot的BL1分离出来(前8K)
Makefile 编译文件

P.S.:sd_fisk.c生成了sd_fdisk可执行文件。sd_fusing.sh中调用sd_fdisk对mmc设备进行分区,具体的分区信息已经包含在sd_fdisk文件中。分区完成后,会将分区信息(MBR)存储在mmc的第0扇区。内核在初始化mmc时,直接读取MBR即可得知mmc的分区信息。

使用方法如下:

  1)进入/uboot/sd_fusing目录下;

  2)运行命令:make  clean (清除之前编译的文件);

  3)运行命令:make (编译生成烧录工具);

  4)运行命令:./sd_fusing.sh  /dev/sdb(将u_boot.bin镜像烧录进SD卡)。

2. sd_fusing.sh脚本文件分析

sd_fusing.sh脚本的主要作用是在SD卡内创建一个fat32分区,然后将U-Boot的BL1和整个U-Boot烧录进SD卡中。

//定义SD卡设备,应该根据实际的设备信息进行修改
reader_type1="/dev/sdb"
reader_type2="/dev/mmcblk0"
//如果没有参数,则显示帮助信息
if [ -z $1 ]
then
    echo "usage: ./sd_fusing.sh <SD Reader's device file>"
    exit 0
fi

//判断SD卡的设备类型,然后定义四个分区
if [ $1 = $reader_type1 ]
then 
    partition1="$11"
    partition2="$12"
    partition3="$13"
    partition4="$14"

elif [ $1 = $reader_type2 ]
then 
    partition1="$1p1"
    partition2="$1p2"
    partition3="$1p3"
    partition4="$1p4"

else   //不能识别SD卡设备
    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

//开始进行SD卡分区
# make partition
echo "make sd card partition"
echo "./sd_fdisk $1" 
./sd_fdisk $1 
dd iflag=dsync oflag=dsync if=sd_mbr.dat of=$1 
rm sd_mbr.dat
 
# format
umount $partition1 2> /dev/null
umount $partition2 2> /dev/null
umount $partition3 2> /dev/null
umount $partition4 2> /dev/null

echo "mkfs.vfat -F 32 $partition1"  //建立一个fat32分区
mkfs.vfat -F 32 $partition1

//定义U-Boot的扇区位置
#<BL1 fusing>
bl1_position=1
uboot_position=49

//将U-Boot的BL1(前8K)和U-Boot的校验和(uboot的前16字节)烧录进SD卡的bl1_position=1扇区

echo "BL1 fusing"
./mkbl1 ../uboot_inand.bin SD-bl1-8k.bin 8192                           //计算uboot的校验和
dd iflag=dsync oflag=dsync if=SD-bl1-8k.bin of=$1 seek=$bl1_position    //烧录
rm SD-bl1-8k.bin

//将整个U-Boot烧录进SD卡的uboot_position=49扇区
#<u-boot fusing>
echo "u-boot fusing"
dd iflag=dsync oflag=dsync if=../uboot_inand.bin of=$1 seek=$uboot_position

//烧录成功信息提示
#<Message Display>
echo "U-boot image is fused successfully."
echo "Eject SD card and insert it again."
原文地址:https://www.cnblogs.com/linfeng-learning/p/9285533.html