| | |
| | | # +-------------------------------+-----------------------+---------------------------------+ |
| | | # | Start Address | Size | Usage | |
| | | # +-------------------------------+-----------------------+---------------------------------+ |
| | | # | 0x0 | 32 sectors(16K) | Reserved for partition table | |
| | | # | 0x0 | 2 sectors(1K) | Reserved for partition table | |
| | | # +-------------------------------+-----------------------+---------------------------------+ |
| | | # | 2 sector(1K, 0x400) | 20414 sectors(9M+) | i.MX6ULL u-boot image | |
| | | # +-------------------------------+-----------------------+---------------------------------+ |
| | |
| | | # |
| | | |
| | | PRJ_PATH=`pwd` |
| | | IMAGE_PATH=${PRJ_PATH}/bin/ |
| | | PRJ_NAME=`basename ${PRJ_PATH}` |
| | | |
| | | IMAGE_PATH=${PRJ_PATH}/boot/ |
| | | |
| | | BOARD=imx6ull |
| | | |
| | | # rootfs should be buildroot or stretch/buster/bullseye for debian system |
| | | ROOTFS=buildroot |
| | | ROOTFS=buster |
| | | |
| | | # linux kernel tarball path and branch |
| | | TAR_PATH=${PRJ_PATH}/../tarball |
| | |
| | | IMAGE_SIZE=2048 |
| | | fi |
| | | |
| | | # 1 sector - for i.MX6 or i.MX7 |
| | | UBOOT_OFSET=1 |
| | | #i.MX6/i.MX7 read uboot from mmc start on sector #2 |
| | | UBOOT_OFSET=2 |
| | | MMC_SECSIZE=512 |
| | | |
| | | # BootRom(U-boot) Size 10MB: 20480 Sectors * 512B |
| | | # U-boot space Size 10MB |
| | | UBOOT_SIZE=10 |
| | | |
| | | # vfat boot partition size |
| | | # vfat boot partition 100MB |
| | | BOOT_SIZE=100 |
| | | |
| | | |
| | | IMG_UBOOT=${IMAGE_PATH}/u-boot-imx6ull-emmc.imx |
| | | IMG_KERNEL=${IMAGE_PATH}/Image |
| | | IMG_UBOOT=${PRJ_PATH}/u-boot-imx6ull-emmc.imx |
| | | IMG_KERNEL=${IMAGE_PATH}/zImage |
| | | IMG_DTB=${IMAGE_PATH}/imx6ull-emmc.dtb |
| | | ROOTFS_TAR=${TAR_PATH}/rootfs_${ROOTFS}.tar.bz2 |
| | | |
| | |
| | | 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" |
| | |
| | | |
| | | 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 |
| | | dd if=/dev/zero of=${IMAGE_NAME} bs=1024k count=${IMAGE_SIZE} && sync |
| | | chmod a+x ${IMAGE_NAME} |
| | | |
| | | msg_banner " <${STAGE}> Partition system image " |
| | |
| | | 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 |
| | | sudo dd if=${IMG_UBOOT} of=${IMAGE_NAME} bs=${MMC_SECSIZE} seek=${UBOOT_OFSET} conv=notrunc,sync |
| | | |
| | | msg_banner " <${STAGE}> Install linux kernel image" |
| | | |
| | |
| | | umount ${MNT_POINT} |
| | | } |
| | | |
| | | mkdir -p ${MNT_POINT} |
| | | function do_distclean() |
| | | { |
| | | printf "\n\n -- do distclean in `basename ${PRJ_PATH}` --\n\n" |
| | | |
| | | generate_image |
| | | rm -f *${BOARD}* |
| | | rm -rf boot/*Image* |
| | | rm -rf boot/overlays/ |
| | | rm -rf boot/*${BOARD}* |
| | | exit 0; |
| | | } |
| | | |
| | | format_partition |
| | | function do_image() |
| | | { |
| | | mkdir -p ${MNT_POINT} |
| | | |
| | | install_sysimg |
| | | generate_image |
| | | |
| | | install_rootfs |
| | | format_partition |
| | | |
| | | rm -rf ${MNT_POINT} |
| | | install_sysimg |
| | | |
| | | install_rootfs |
| | | |
| | | msg_banner " bzip2 compress system image " |
| | | bzip2 ${IMAGE_NAME} |
| | | |
| | | rm -rf ${MNT_POINT} |
| | | |
| | | printf "\n\n -- generate system image done --\n\n" |
| | | } |
| | | |
| | | |
| | | function do_root() |
| | | { |
| | | echo "" |
| | | if [[ $1 == "yes" ]] && [ `id -u` != 0 ] ; then |
| | | echo "ERROR: This action must run as root!" |
| | | echo "" |
| | | exit; |
| | | elif [[ $1 != "yes" ]] && [ `id -u` == 0 ] ; then |
| | | echo "ERROR: This action cannot run as root!" |
| | | echo "" |
| | | exit; |
| | | fi |
| | | } |
| | | |
| | | function do_usage() |
| | | { |
| | | echo "" |
| | | echo "Usage:" |
| | | echo " $0 [-b] [-c] [-h]" |
| | | echo " -b: download and build $PRJ_NAME" |
| | | echo " -c: clean all the source code" |
| | | echo " -h: show this help message" |
| | | echo "" |
| | | echo " WARNNING: This shell script must run as sudo" |
| | | echo "" |
| | | exit; |
| | | } |
| | | |
| | | trap 'exit_handler' EXIT |
| | | |
| | | while getopts "bch" OPTNAME |
| | | do |
| | | case "${OPTNAME}" in |
| | | "b") |
| | | break; |
| | | ;; |
| | | |
| | | "c") |
| | | do_root "yes" |
| | | do_distclean |
| | | ;; |
| | | |
| | | "*") |
| | | do_usage |
| | | ;; |
| | | esac |
| | | done |
| | | |
| | | do_root "yes" |
| | | do_image |
| | | |