From 65c6e51c203fd817b5d51654d5215076a2418016 Mon Sep 17 00:00:00 2001
From: guowenxue <guowenxue@gmail.com>
Date: Sun, 14 Nov 2021 00:40:21 +0800
Subject: [PATCH] update images build shell script
---
bsp/images/build.sh | 172 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 172 insertions(+), 0 deletions(-)
diff --git a/bsp/images/build.sh b/bsp/images/build.sh
index f345d53..8db2ddf 100755
--- a/bsp/images/build.sh
+++ b/bsp/images/build.sh
@@ -1,12 +1,184 @@
#!/bin/bash
+#
+# Reference: <<i.MX Linux® User's Guide.pdf>>
+#
+# SD Card partition layout: 1 Sector= 512B
+#
+# +-------------------------------+-----------------------+---------------------------------+
+# | Start Address | Size | Usage |
+# +-------------------------------+-----------------------+---------------------------------+
+# | 0x0 | 32 sectors(16K) | Reserved for partition table |
+# +-------------------------------+-----------------------+---------------------------------+
+# | 2 sector(1K, 0x400) | 20414 sectors(9M+) | i.MX6ULL u-boot image |
+# +-------------------------------+-----------------------+---------------------------------+
+# | 20480 sector(10M, 0xa00000) | 204800 sectors(100MB) | FAT32 Boot partition |
+# +-------------------------------+-----------------------+---------------------------------+
+# | 225280 sector(110M,0x6e00000) | Remaining Space | EXT4 filesystem for rootfs |
+# +-------------------------------+-----------------------+---------------------------------+
+#
PRJ_PATH=`pwd`
+IMAGE_PATH=${PRJ_PATH}/bin/
BOARD=imx6ull
# rootfs should be buildroot or stretch/buster/bullseye for debian system
ROOTFS=buildroot
+# linux kernel tarball path and branch
+TAR_PATH=/home/guowenxue/imx6ull/bsp/tarball
+
+BOOT=emmc
+
+IMAGE_NAME=linuxsys_${BOARD}_${ROOTFS}.img
+if [ $ROOTFS == buildroot ] ; then
+ IMAGE_SIZE=512
+else
+ IMAGE_SIZE=2048
+fi
+
+# 1 sector - for i.MX6 or i.MX7
+UBOOT_OFSET=1
+
+# BootRom(U-boot) Size 10MB: 20480 Sectors * 512B
+UBOOT_SIZE=10
+
+# vfat boot partition size
+BOOT_SIZE=100
+IMG_UBOOT=${IMAGE_PATH}/u-boot-imx6ull-emmc.imx
+IMG_KERNEL=${IMAGE_PATH}/Image
+IMG_DTB=${IMAGE_PATH}/imx6ull-emmc.dtb
+ROOTFS_TAR=${TAR_PATH}/rootfs_${ROOTFS}.tar.bz2
+
+MNT_POINT=./mnt
+LOOP_DEV=`losetup -f | cut -d/ -f3`
+
+set -u
+set -e
+
+if [ `id -u` != 0 ] ; then
+ echo "ERROR: This shell script must run as root"
+ exit 0;
+fi
+
+trap 'exit_handler' EXIT
+function exit_handler()
+{
+ echo "Shell script exit now, do some clean work"
+ echo ""
+
+ mountpoint $MNT_POINT > /dev/null 2>&1
+ if [ $? == 0 ] ; then
+ umount ${MNT_POINT}
+ fi
+
+ rm -rf ${MNT_POINT}
+
+ if [ -L /dev/mapper/${LOOP_DEV}p1 ] ; then
+ kpartx -dv /dev/${LOOP_DEV}
+ fi
+
+ losetup -a | grep "${LOOP_DEV}" > /dev/null 2>&1
+ if [ $? == 0 ] ; then
+ losetup -d /dev/${LOOP_DEV}
+ fi
+}
+
+STAGE=0
+function msg_banner()
+{
+ STAGE=`expr $STAGE + 1`
+
+ echo ""
+ echo "+---------------------------------------------+"
+ printf " Stage $STAGE: $1\n"
+ echo "+---------------------------------------------+"
+ echo ""
+}
+
+
+function generate_image()
+{
+ # system image block count by block=512k
+ BLOCK_CNT=`expr 2 \* ${IMAGE_SIZE}`
+
+ # FAT32 boot partition start/end address in MB
+ BOOT_START=${UBOOT_SIZE}
+ BOOT_END=`expr ${BOOT_START} + ${BOOT_SIZE}`
+
+ msg_banner " <${STAGE}> Generate system image "
+
+ dd if=/dev/zero of=${IMAGE_NAME} bs=512k count=${BLOCK_CNT} && sync
+ chmod a+x ${IMAGE_NAME}
+
+ msg_banner " <${STAGE}> Partition system image "
+
+ parted ${IMAGE_NAME} mklabel msdos
+ parted ${IMAGE_NAME} mkpart primary fat32 ${BOOT_START}M ${BOOT_END}M
+ parted ${IMAGE_NAME} mkpart primary ext4 ${BOOT_END}M 100%
+
+ sync
+}
+
+
+function format_partition()
+{
+ msg_banner " <${STAGE}> losetup image on $LOOP_DEV"
+
+ losetup /dev/${LOOP_DEV} ${IMAGE_NAME}
+ kpartx -av /dev/${LOOP_DEV}
+
+ msg_banner " <${STAGE}> Format system image partition"
+ mkfs.vfat /dev/mapper/${LOOP_DEV}p1
+ mkfs.ext4 /dev/mapper/${LOOP_DEV}p2
+ sync
+}
+
+function install_sysimg()
+{
+ msg_banner " <${STAGE}> Install u-boot image"
+ sudo dd if=${IMG_UBOOT} of=${IMAGE_NAME} bs=1k seek=${UBOOT_OFSET} conv=notrunc,sync
+
+ msg_banner " <${STAGE}> Install linux kernel image"
+
+ mkdir -p ${MNT_POINT}
+ mount -t vfat /dev/mapper/${LOOP_DEV}p1 ${MNT_POINT}
+
+ set -x
+ cp ${IMG_KERNEL} ${MNT_POINT}
+ cp ${IMG_DTB} ${MNT_POINT}
+ sync
+ set +x
+
+ umount ${MNT_POINT}
+}
+
+function install_rootfs()
+{
+ msg_banner " <${STAGE}> Install root filesystem "
+
+ if [ ! -f ${ROOTFS_TAR} ] ; then
+ echo "ERROR: rootfs tarball file '${ROOTFS_TAR}' not exist..."
+ exit ;
+ fi
+
+ mount -t ext4 /dev/mapper/${LOOP_DEV}p2 ${MNT_POINT}
+ tar -xjf ${ROOTFS_TAR} -C ${MNT_POINT} && sync
+
+ umount ${MNT_POINT}
+}
+
+mkdir -p ${MNT_POINT}
+
+generate_image
+
+format_partition
+
+install_sysimg
+
+install_rootfs
+
+rm -rf ${MNT_POINT}
--
Gitblit v1.9.1