From 5c7f25e3df1c4b06f0620e75833fd01f1c763163 Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Thu, 14 May 2020 17:19:36 +0900 Subject: [PATCH] scripts: tizen: sd_fusing_rpi3: Check dd version for backward compatibility Before dd version 8.24, "status=progress" option is not supported. For backward compatibility, check dd version and use the option only when it is possible. Change-Id: Ia90668e9cd22bf2906b4b0ecd574bb45ad14fd95 Signed-off-by: Seung-Woo Kim --- scripts/tizen/sd_fusing_rpi3.sh | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/scripts/tizen/sd_fusing_rpi3.sh b/scripts/tizen/sd_fusing_rpi3.sh index 6e3c52b..085bf1f 100755 --- a/scripts/tizen/sd_fusing_rpi3.sh +++ b/scripts/tizen/sd_fusing_rpi3.sh @@ -2,6 +2,7 @@ declare FORMAT="" declare DEVICE="" +declare -i OLD_DD=0 # Binaires array for fusing declare -a FUSING_BINARY_ARRAY @@ -50,6 +51,23 @@ function print_message () { tput sgr 0 } +function check_ddversion () { + # NOTE + # before coreutils dd 8.24, dd doesn't support "status=progress" + # and the option causes fusing failure. For backward compatibility, + # do not use the option for old dd + local version=`dd --version | head -1 | awk '{print $3}'` + local major=${version%%.*} + local version=${version:`expr index $version .`} + local minor=${version%%.*} + + if [ $major -lt 8 ]; then + OLD_DD=1 + elif [ $major -eq 8 -a $minor -lt 24 ]; then + OLD_DD=1 + fi +} + function fusing_image () { local -r fusing_img=$1 @@ -65,12 +83,16 @@ function fusing_image () { return fi - local input_size=`du -b $fusing_img | awk '{print $1}'` - input_size=`expr $input_size / 1024 / 1024` + local -r input_size=`du -b $fusing_img | awk '{print $1}'` + local -r input_size_mb=`expr $input_size / 1024 / 1024` - print_message 2 "[Fusing $1 ($input_size MiB)]" + print_message 2 "[Fusing $1 ($input_size_mb MiB)]" umount $device - dd if=$fusing_img of=$device bs=$bs status=progress oflag=direct + if [ $OLD_DD == 1 ]; then + dd if=$fusing_img | pv -s $input_size | dd of=$device bs=$bs + else + dd if=$fusing_img of=$device bs=$bs status=progress oflag=direct + fi local -r fstype=`blkid -o value -s TYPE $device` if [[ "$fstype" =~ "ext" ]]; then @@ -378,4 +400,5 @@ done check_args check_device check_partition_format +check_ddversion fuse_image -- 2.7.4