--------------------------------------------
以下由 @哇酷小管家 2021-12-16 添加:
用 buildroot 更方便,参考这两个链接
buildroot-tiny200 (F1C100/200s) 开发包近期更新内容 * 已支持DVP摄像头 *
https://whycan.com/t_5221.html
(V3s/V3x/S3/S3L/R11通吃)小智V3x开发板smallwitpi lite u-boot/linux/buildroot测试
https://whycan.com/t_7248.html#p69178
完毕
--------------------------------------------
pack.sh
#!/bin/bash
_UBOOT_SIZE=1
###第一个分区(FAT)大小,单位MiB##
_P1_SIZE=16
###TF卡镜像文件名称###
_IMG_FILE='f1c100s_tfcard_img.bin'
###TF卡镜像文件大小, 单位MiB###
_IMG_SIZE=120
temp_root_dir=$PWD
_UBOOT_FILE="${temp_root_dir}/data/u-boot-sunxi-with-spl.bin"
_SPLASH_BMP_FILE="${temp_root_dir}/data/splash.bmp"
_BOOT_SCR_FILE="${temp_root_dir}/data/boot.scr"
_KERNEL_IMAGE_FILE="${temp_root_dir}/data/zImage"
_DTB_FILE="${temp_root_dir}/data/dtb.bin"
_ROOTFS_TGZ_FILE="${temp_root_dir}/data/rootfs.tgz"
###初始化镜像文件###
dd if=/dev/zero of=$_IMG_FILE bs=1M count=$_IMG_SIZE
###判断镜像文件是否初始化成功###
if [ $? -ne 0 ]
then
echo "getting error in creating dd img!"
exit
fi
###获取一个循环设备###
_LOOP_DEV=$(sudo losetup -f)
#echo ${_LOOP_DEV}
##再次判断此设备是否存在###
if [ -z $_LOOP_DEV ]
then
echo "can not find a loop device!"
exit
fi
###把镜像文件和循环设备关联###
sudo losetup $_LOOP_DEV $_IMG_FILE
if [ $? -ne 0 ]
then
echo "dd img --> $_LOOP_DEV error!"
sudo losetup -d $_LOOP_DEV >/dev/null 2>&1 && exit
fi
echo "--->creating partitions for tf image ..."
#blockdev --rereadpt $_LOOP_DEV >/dev/null 2>&1
# size only can be integer
###分区###
cat <<EOT |sudo sfdisk ${_IMG_FILE}
${_UBOOT_SIZE}M,${_P1_SIZE}M,c
,,L
EOT
###格式化###
sleep 2
sudo partx -u $_LOOP_DEV
sudo mkfs.vfat ${_LOOP_DEV}p1 ||exit
sudo mkfs.ext4 ${_LOOP_DEV}p2 ||exit
if [ $? -ne 0 ]
then
echo "error in creating partitions"
sudo losetup -d $_LOOP_DEV >/dev/null 2>&1 && exit
#sudo partprobe $_LOOP_DEV >/dev/null 2>&1 && exit
fi
###u-boot写到TF卡8K偏移处###
#pack uboot
echo "--->writing u-boot-sunxi-with-spl to $_LOOP_DEV"
# sudo dd if=/dev/zero of=$_LOOP_DEV bs=1K seek=1 count=1023 # clear except mbr
sudo dd if=$_UBOOT_FILE of=$_LOOP_DEV bs=1024 seek=8
if [ $? -ne 0 ]
then
echo "writing u-boot error!"
sudo losetup -d $_LOOP_DEV >/dev/null 2>&1 && exit
#sudo partprobe $_LOOP_DEV >/dev/null 2>&1 && exit
fi
###新建 p1,p2 目录,并挂载TF卡两个分区###
sudo sync
mkdir -p ${temp_root_dir}/output/p1 >/dev/null 2>&1
mkdir -p ${temp_root_dir}/output/p2 > /dev/null 2>&1
sudo mount ${_LOOP_DEV}p1 ${temp_root_dir}/output/p1
sudo mount ${_LOOP_DEV}p2 ${temp_root_dir}/output/p2
echo "--->copy boot and rootfs files..."
sudo rm -rf ${temp_root_dir}/output/p1/* && sudo rm -rf ${temp_root_dir}/output/p2/*
###复制zImage, dtb, boot.scr, splash.bmp 等文件到第一分区 ###
sudo cp ${_KERNEL_IMAGE_FILE} ${temp_root_dir}/output/p1/zImage &&\
sudo cp ${_DTB_FILE} ${temp_root_dir}/output/p1/ &&\
sudo cp ${_BOOT_SCR_FILE} ${temp_root_dir}/output/p1/ &&\
sudo cp ${_SPLASH_BMP_FILE} ${temp_root_dir}/output/p1/ &&\
echo "--->p1 done~"
###解压 rootfs.tgz 到第二分区###
sudo tar xvf ${_ROOTFS_TGZ_FILE} -C ${temp_root_dir}/output/p2/ &&\
echo "--->p2 done~"
###同步, 等待, 卸载, 退出###
sudo sync
sleep 2
sudo umount ${temp_root_dir}/output/p1 ${temp_root_dir}/output/p2 && sudo losetup -d $_LOOP_DEV
if [ $? -ne 0 ]
then
echo "umount or losetup -d error!!"
exit
fi
目录结构:
.
..
pack.sh
data/
u-boot-sunxi-with-spl.bin
boot.scr
dtb.bin
rootfs.tgz
splash.bmp
zImage
以上脚本参考本站 @xiaohui 的打包脚本, 我加了部分注释, 把其他非打包脚本剥离开了。
离线