Browse Source

Merge branch 'CR_1604_sdcrad_img_515_Andy.Hu' into 'jh7110-devel'

CR_1604: sdcard.img: generate sdcard image file

See merge request sdk/freelight-u-sdk!91
Jason Zhou 1 year ago
parent
commit
0bec29ae1d
3 changed files with 112 additions and 0 deletions
  1. 24 0
      README.md
  2. 35 0
      conf/genimage.cfg
  3. 53 0
      genimage.sh

+ 24 - 0
README.md

@@ -187,6 +187,30 @@ $ make buildroot_rootfs -jx
 $ make DISK=/dev/sdX format-rootfs-image && sync
 ```
 
+## Generate SDCard Image file
+
+We could generate a sdcard image file by the below command. The sdcard image file could be burned into sdcard or tf card through `dd` command, or `rpi-imager` or `balenaEtcher` tool
+
+```
+$ make -jx
+$ make buildroot_rootfs -jx
+$ ./build_soft_3rdpart.sh rootfs
+$ rm work/buildroot_rootfs/images/rootfs.ext*
+$ make buildroot_rootfs -jx
+$ ./genimage.sh
+```
+
+Then the output file `work/sdcard.img`  will be generated.  Then It can been burn into tf card, e.g. through `dd` command
+
+```
+$ sudo dd if=work/sdcard.img of=/dev/sdX bs=4096
+$ sync
+$ sudo growpart /dev/sdc 4  # extend partition 4
+$ sudo e2fsck -f /dev/sdc4
+$ sudo resize2fs /dev/sdc4  # extend filesystem
+$ sudo fsck.ext4 /dev/sdc4
+```
+
 ## Using DTB Overlay Dynamically
 
 The system support load dtb overlay dynamically when the board is running. The detail process to use the dtbo please reference to the dtbo documents.

+ 35 - 0
conf/genimage.cfg

@@ -0,0 +1,35 @@
+image sdcard.img {
+	hdimage {
+		gpt = true
+	}
+
+	partition spl {
+		# image = "u-boot-spl.bin.normal.out"
+		partition-type-uuid = 5B193300-FC78-40CD-8002-E86C45580B47
+		offset = 1M
+		size = 2M
+	}
+
+	partition uboot {
+		image = "work/evb_fw_payload.img"
+		partition-type-uuid = 2E54B353-1271-4842-806F-E436D6AF6985
+		offset = 3M
+		size = 5M
+	}
+
+	partition image {
+		# partition-type = 0xC
+		partition-type-uuid = EBD0A0A2-B9E5-4433-87C0-68B6B72699C7
+		image = "work/starfive-evb-vfat.part"
+		offset = 8M
+		size = 292M
+	}
+
+	partition root {
+		# partition-type = 0x83
+		partition-type-uuid = 0FC63DAF-8483-4772-8E79-3D69D8477DE4
+		image = "work/buildroot_rootfs/images/rootfs.ext4"
+		offset = 300M
+		bootable = true
+	}
+}

+ 53 - 0
genimage.sh

@@ -0,0 +1,53 @@
+#!/bin/bash
+##################################################################
+##                                                              ##
+##      SPDX-License-Identifier: GPL-2.0-or-later               ##
+##                                                              ##
+##      Copyright (C) 2018-2022   Starfive Technology           ##
+##                                                              ##
+##  Author: Andy Hu <andy.hu@starfivetech.com>                  ##
+##  Date:   2022-07-27                                          ##
+##  Description: This script used to generate img file          ##
+##    which could be burned to tf card through dd or            ##
+##    rpi-imager or balenaEtcher tool.                          ##
+##    Run it after the usdk initramfs and rootfs had been built ##
+##                                                              ##
+##################################################################
+COLOR_NORMAL="\033[0m"
+COLOR_GREEN="\033[1;32m"
+COLOR_YELLOW="\033[1;33m"
+COLOR_RED="\033[1;31m"
+COLOR_GREY="\033[1;30m"
+
+TOPDIR=`dirname $0`
+BUILD_DIR=$TOPDIR/work
+INPUT_DIR=$TOPDIR
+OUTPUT_DIR=$TOPDIR/work
+GENIMAGE_CFG=$TOPDIR/conf/genimage.cfg
+GENIMAGE=$TOPDIR/work/buildroot_initramfs/host/bin/genimage
+
+if [ ! -f $GENIMAGE ]; then
+    printf $COLOR_RED
+    echo "Error: $GENIMAGE not found. need building the usdk first"
+    printf $COLOR_NORMAL
+    exit 1
+fi
+
+GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp"
+
+# Pass an empty rootpath. genimage makes a full copy of the given rootpath to
+# ${GENIMAGE_TMP}/root so passing TARGET_DIR would be a waste of time and disk
+# space. We don't rely on genimage to build the rootfs image, just to insert a
+# pre-built one in the disk image.
+
+trap 'rm -rf "${ROOTPATH_TMP}"' EXIT
+ROOTPATH_TMP="$(mktemp -d)"
+
+rm -rf "${GENIMAGE_TMP}"
+
+$GENIMAGE \
+	--rootpath "${ROOTPATH_TMP}"     \
+	--tmppath "${GENIMAGE_TMP}"    \
+	--inputpath "${INPUT_DIR}"  \
+	--outputpath "${OUTPUT_DIR}" \
+	--config "${GENIMAGE_CFG}"