From 40cd6bd6fbec9ecd242eb591a2fe137b2f8537db Mon Sep 17 00:00:00 2001 From: Junghoon Kim Date: Tue, 11 Jul 2017 09:58:24 +0900 Subject: [PATCH] scripts: odroid-xu4: support new version of sfdisk In 2.26.0 and later versions of sfdisk, the input data needs to contain multipliers (MiB) instead of "--unit" option. For this, This patch fixes sfdisk command to support all versions. Change-Id: I08e0e02c528d281dafc1a474a839cd4e3baf66e4 Signed-off-by: Joonyoung Shim Signed-off-by: Junghoon Kim --- scripts/sd_fusing_xu4.sh | 53 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/scripts/sd_fusing_xu4.sh b/scripts/sd_fusing_xu4.sh index 41ece38..36cdaec 100755 --- a/scripts/sd_fusing_xu4.sh +++ b/scripts/sd_fusing_xu4.sh @@ -193,6 +193,25 @@ function fuse_image () { # partition format function mkpart_3 () { + # NOTE: if your sfdisk version is less than 2.26.0, then you should use following sfdisk command: + # sfdisk --in-order --Linux --unit M $DISK <<-__EOF__ + + # NOTE: sfdisk 2.26 doesn't support units other than sectors and marks --unit option as deprecated. + # The input data needs to contain multipliers (MiB) instead. + local version=`sfdisk -v | awk '{print $4}'` + local major=${version%%.*} + local version=${version:`expr index $version .`} + local minor=${version%%.*} + local sfdisk_new=0 + + if [ $major -gt 2 ]; then + sfdisk_new=1 + else + if [ $major -eq 2 -a $minor -ge 26 ]; then + sfdisk_new=1 + fi + fi + local -r DISK=$DEVICE local -r SIZE=`sfdisk -s $DISK` local -r SIZE_MB=$((SIZE >> 10)) @@ -201,8 +220,13 @@ function mkpart_3 () { local -r ROOTFS_SZ=3072 local -r DATA_SZ=512 local -r MODULE_SZ=20 + if [ $sfdisk_new == 1 ]; then + local -r EXTEND_SZ=8 + else + local -r EXTEND_SZ=4 + fi - let "USER_SZ = $SIZE_MB - $BOOT_SZ - $ROOTFS_SZ - $DATA_SZ - $MODULE_SZ - 4" + let "USER_SZ = $SIZE_MB - $BOOT_SZ - $ROOTFS_SZ - $DATA_SZ - $MODULE_SZ - $EXTEND_SZ" local -r BOOT=boot local -r ROOTFS=rootfs @@ -235,14 +259,25 @@ function mkpart_3 () { echo "Remove partition table..." dd if=/dev/zero of=$DISK bs=512 count=16 conv=notrunc - sfdisk --in-order --Linux --unit M $DISK <<-__EOF__ - 4,$BOOT_SZ,0xE,* - ,$ROOTFS_SZ,,- - ,$DATA_SZ,,- - ,,E,- - ,$USER_SZ,,- - ,$MODULE_SZ,,- - __EOF__ + if [ $sfdisk_new == 1 ]; then + sfdisk $DISK <<-__EOF__ + 4MiB,${BOOT_SZ}MiB,0xE,* + 8MiB,${ROOTFS_SZ}MiB,,- + 8MiB,${DATA_SZ}MiB,,- + 8MiB,,E,- + ,${USER_SZ}MiB,,- + ,${MODULE_SZ}MiB,,- + __EOF__ + else + sfdisk --in-order --Linux --unit M $DISK <<-__EOF__ + 4,$BOOT_SZ,0xE,* + ,$ROOTFS_SZ,,- + ,$DATA_SZ,,- + ,,E,- + ,$USER_SZ,,- + ,$MODULE_SZ,,- + __EOF__ + fi mkfs.vfat -F 16 ${DISK}1 -n $BOOT mkfs.ext4 -q ${DISK}2 -L $ROOTFS -F -- 2.7.4