scripts: tizen: sd_fusing_rpi3: Check dd version for backward compatibility
authorSeung-Woo Kim <sw0312.kim@samsung.com>
Thu, 14 May 2020 08:19:36 +0000 (17:19 +0900)
committerJaehoon Chung <jh80.chung@samsung.com>
Tue, 17 Oct 2023 04:19:20 +0000 (13:19 +0900)
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 <sw0312.kim@samsung.com>
scripts/tizen/sd_fusing_rpi3.sh

index 6e3c52b..085bf1f 100755 (executable)
@@ -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