scripts: Improve UI
[platform/kernel/u-boot.git] / scripts / tizen / sd_fusing_rpi4.sh
1 #!/bin/bash
2
3 declare FORMAT=""
4 declare DEVICE=""
5 declare SKIP=0
6 declare -i OLD_DD=0
7
8 # Binaires array for fusing
9 declare -a FUSING_BINARY_ARRAY
10 declare -i FUSING_BINARY_NUM=0
11
12 declare CONV_ASCII=""
13 declare -i FUS_ENTRY_NUM=0
14 declare -i ab_option=0
15
16 # binary name | part number | bs | label | fs type
17 declare -a PART_TABLE=(
18         "boot.img"                      1       4M      boot_a                  vfat
19         "rootfs.img"                    2       4M      rootfs_a                ext4
20         "system-data.img"               3       4M      system-data             ext4
21         "user.img"                      5       4M      user                    ext4
22         "modules.img"                   6       4M      module_a                ext4
23         "ramdisk.img"                   7       4M      ramdisk_a               ext4
24         "ramdisk-recovery.img"          8       4M      ramdisk-recovery_a      ext4
25         "hal.img"                       10      4M      hal_a                   ext4
26         "boot.img"                      11      4M      boot_b                  vfat
27         "rootfs.img"                    12      4M      rootfs_b                ext4
28         "modules.img"                   13      4M      module_b                ext4
29         "ramdisk.img"                   14      4M      ramdisk_b               ext4
30         "ramdisk-recovery.img"          15      4M      ramdisk-recovery_b      ext4
31         "hal.img"                       16      4M      hal_b                   ext4
32         )
33 declare -a PART_TABLE_B=(
34         "boot.img"                      11      4M      boot_b                  vfat
35         "rootfs.img"                    12      4M      rootfs_b                ext4
36         "modules.img"                   13      4M      module_b                ext4
37         "ramdisk.img"                   14      4M      ramdisk_b               ext4
38         "ramdisk-recovery.img"          15      4M      ramdisk-recovery_b      ext4
39         "hal.img"                       16      4M      hal_b                   ext4
40         )
41
42 declare -r -i PART_TABLE_COL=5
43 declare -r -i PART_TABLE_ROW=${#PART_TABLE[*]}/${PART_TABLE_COL}
44 declare -r -i PART_TABLE_ROW_B=${#PART_TABLE_B[*]}/${PART_TABLE_COL}
45
46 # partition table support
47 function get_index_use_name () {
48         local -r binary_name=$1
49
50         for ((idx=0;idx<$PART_TABLE_ROW;idx++)); do
51                 if [ ${PART_TABLE[idx * ${PART_TABLE_COL} + 0]} == "$binary_name" ]; then
52                         return $idx
53                 fi
54         done
55
56         # return out of bound index
57         return $idx
58 }
59
60 # partition table support
61 function get_index_use_name_to_b () {
62         local -r binary_name=$1
63
64         for ((idx=0;idx<$PART_TABLE_ROW_B;idx++)); do
65                 if [ ${PART_TABLE_B[idx * ${PART_TABLE_COL} + 0]} == "$binary_name" ]; then
66                         return $idx
67                 fi
68         done
69
70         # return out of bound index
71         return $idx
72 }
73
74 function print_message () {
75         local color=$1
76         local message=$2
77
78         tput setaf $color
79         tput bold
80         echo ""
81         echo $message
82         tput sgr 0
83 }
84
85 function check_ddversion () {
86         # NOTE
87         # before coreutils dd 8.24, dd doesn't support "status=progress"
88         # and the option causes fusing failure. For backward compatibility,
89         # do not use the option for old dd
90         local version=(`dd --version | head -1 | grep -o '[0-9]\+'`)
91         local major=${version[0]}
92         local minor=${version[1]}
93
94         if [ $major -lt 8 ];  then
95                 OLD_DD=1
96         elif [ $major -eq 8 -a $minor -lt 24 ];  then
97                 OLD_DD=1
98         fi
99 }
100
101 function fusing_image () {
102         if [ $ab_option == 2 ] ; then
103                 echo "Skip to update Partitoin A"
104                 return
105         fi
106         local -r fusing_img=$1
107
108         # get binary info using basename
109         get_index_use_name $(basename "$fusing_img")
110         local -r -i part_idx=$?
111
112         if [ $part_idx -ne $PART_TABLE_ROW ];then
113                 local -r num=${PART_TABLE[${part_idx} * ${PART_TABLE_COL} + 1]}
114                 if [ "${num}" == "" ]; then
115                         local -r blktype=disk
116                 else
117                         local -r blktype=part
118                 fi
119                 local -r device=/dev/`lsblk ${DEVICE} -o TYPE,KNAME | awk "/^${blktype}.*[a-z]${num}\$/ { print \\\$2 }"`
120                 local -r bs=${PART_TABLE[${part_idx} * ${PART_TABLE_COL} + 2]}
121         else
122                 echo "Unsupported binary: $fusing_img"
123                 return
124         fi
125
126         local -r input_size=`du -b $fusing_img | awk '{print $1}'`
127         local -r input_size_mb=`expr $input_size / 1024 / 1024`
128
129         print_message 2 "[Fusing $1 ($input_size_mb MiB)]"
130         if [ "$blktype" == "part" ]; then
131                 local MOUNT_PART=`mount | grep $device`
132                 if [ "$MOUNT_PART" != "" ]; then
133                         umount $device
134                 fi
135         fi
136         if [ $OLD_DD == 1 ]; then
137                 dd if=$fusing_img | pv -s $input_size | dd of=$device bs=$bs
138         else
139                 dd if=$fusing_img of=$device bs=$bs status=progress oflag=direct
140         fi
141 }
142
143 function fusing_image_to_b () {
144         if [ $ab_option == 0 ]  ; then
145                 echo "Skip to update Partitoin B"
146                 return
147         fi
148         local -r fusing_img=$1
149
150         # get binary info using basename
151         get_index_use_name_to_b $(basename "$fusing_img")
152
153         local -r -i part_idx=$?
154
155         if [ $part_idx -ne $PART_TABLE_ROW_B ];then
156                 local -r num=${PART_TABLE_B[${part_idx} * ${PART_TABLE_COL} + 1]}
157                 if [ "${num}" == "" ]; then
158                         local -r blktype=disk
159                 else
160                         local -r blktype=part
161                 fi
162                 local -r device=/dev/`lsblk ${DEVICE} -o TYPE,KNAME | awk "/^${blktype}.*[a-z]${num}\$/ { print \\\$2 }"`
163                 local -r bs=${PART_TABLE_B[${part_idx} * ${PART_TABLE_COL} + 2]}
164         else
165                 echo "Unsupported binary: $fusing_img"
166                 return
167         fi
168
169         local -r input_size=`du -b $fusing_img | awk '{print $1}'`
170         local -r input_size_mb=`expr $input_size / 1024 / 1024`
171
172         print_message 2 "[Fusing $1 ($input_size_mb MiB)]"
173         if [ "$blktype" == "part" ]; then
174                 local MOUNT_PART=`mount | grep $device`
175                 if [ "$MOUNT_PART" != "" ]; then
176                         umount $device
177                 fi
178         fi
179         if [ $OLD_DD == 1 ]; then
180                 dd if=$fusing_img | pv -s $input_size | dd of=$device bs=$bs
181         else
182                 dd if=$fusing_img of=$device bs=$bs status=progress oflag=direct
183         fi
184 }
185
186 function fuse_image_tarball () {
187         local -r filepath=$1
188         local -r temp_dir="tar_tmp"
189
190         mkdir -p $temp_dir
191         tar xvf $filepath -C $temp_dir
192         cd $temp_dir
193
194         for file in *
195         do
196                 fusing_image $file
197                 fusing_image_to_b $file
198         done
199
200         cd ..
201         rm -rf $temp_dir
202         eval sync
203 }
204
205 function initialize_parameter () {
206         # create "reboot-param.bin" file in inform partition for passing reboot parameter
207         # It should be done only once upon partition format.
208         local -r DISK=$DEVICE
209         local -r PART9=/dev/`lsblk ${DISK} -o TYPE,KNAME | grep part | awk '{ print $2 }' | grep -G "[a-z]9\$"`
210
211         if [ -d mnt_tmp ]; then
212                 echo "Remove the existing mnt_tmp directory!!"
213                 rm -rf mnt_tmp
214         fi
215         mkdir mnt_tmp
216         mount -t ext4 ${PART9} ./mnt_tmp
217         echo "norm" > ./mnt_tmp/reboot-param.bin
218         echo "norm" > ./mnt_tmp/reboot-param.info
219         echo "a" > ./mnt_tmp/partition-ab.info
220         echo "1" > ./mnt_tmp/partition-ab-cloned.info
221         echo "0" > ./mnt_tmp/upgrade-status.info
222
223         # To check the status of partition. (default "ok")
224         echo "ok" > ./mnt_tmp/partition-a-status.info
225         echo "ok" > ./mnt_tmp/partition-b-status.info
226
227         sync
228         umount ./mnt_tmp
229         rmdir mnt_tmp
230 }
231
232 function fuse_image () {
233
234         if [ "$FUSING_BINARY_NUM" == 0 ]; then
235                 return
236         fi
237
238         # Clear preivous values before flashing image
239         initialize_parameter
240
241         for ((fuse_idx = 0 ; fuse_idx < $FUSING_BINARY_NUM ; fuse_idx++))
242         do
243                 local filename=${FUSING_BINARY_ARRAY[fuse_idx]}
244
245                 case "$filename" in
246                     *.tar | *.tar.gz)
247                         fuse_image_tarball $filename
248                         ;;
249                     *)
250                         fusing_image $filename
251                         fusing_image_to_b $filename
252                         ;;
253                 esac
254         done
255         echo ""
256 }
257
258 # partition format
259 function mkpart_3 () {
260         # NOTE: if your sfdisk version is less than 2.26.0, then you should use following sfdisk command:
261         # sfdisk --in-order --Linux --unit M $DISK <<-__EOF__
262
263         # NOTE: sfdisk 2.26 doesn't support units other than sectors and marks --unit option as deprecated.
264         # The input data needs to contain multipliers (MiB) instead.
265         local version=(`sfdisk -v | grep -o '[0-9]\+'`)
266         local major=${version[0]}
267         local minor=${version[1]}
268         local sfdisk_new=0
269         local support_delete=0
270
271         if [ $major -gt 2 ];  then
272                 sfdisk_new=1
273                 if [ $major -eq 2 -a $minor -ge 28 ]; then
274                         support_delete=1
275                 fi
276         else
277                 if [ $major -eq 2 -a $minor -ge 26 ];  then
278                         sfdisk_new=1
279                 fi
280         fi
281
282         if [ $sfdisk_new == 0 ]; then
283                 echo "$(tput setaf 3)$(tput bold)NOTICE: Your sfdisk ${version[0]}.${version[1]}  version is too old. Update Latest sfdisk!"
284                 tput sgr 0
285                 exit -1
286         fi
287
288         local -r DISK=$DEVICE
289         local -r SIZE=`sfdisk -s $DISK`
290         local -r SIZE_MB=$((SIZE >> 10))
291
292         local -r BOOT_SZ=64
293         local -r ROOTFS_SZ=3072
294         local -r DATA_SZ=1344
295         local -r MODULE_SZ=32
296         local -r RAMDISK_SZ=32
297         local -r RAMDISK_RECOVERY_SZ=32
298         local -r INFORM_SZ=8
299         local -r HAL_SZ=256
300         local -r PARAM_SZ=4
301         local -r RESERVED1_SZ=64
302         local -r RESERVED2_SZ=125
303         local -r EXTEND_SZ=36
304
305         let "USER_SZ = $SIZE_MB - $BOOT_SZ * 2 - $ROOTFS_SZ * 2 - $DATA_SZ - $MODULE_SZ * 2 - $RAMDISK_SZ * 2 - $RAMDISK_RECOVERY_SZ * 2 - $INFORM_SZ - $EXTEND_SZ - $HAL_SZ * 2 - $RESERVED1_SZ - $RESERVED2_SZ - $PARAM_SZ"
306
307         local -r BOOT_A=${PART_TABLE[0 * ${PART_TABLE_COL} + 3]}
308         local -r ROOTFS_A=${PART_TABLE[1 * ${PART_TABLE_COL} + 3]}
309         local -r SYSTEMDATA=${PART_TABLE[2 * ${PART_TABLE_COL} + 3]}
310         local -r USER=${PART_TABLE[3 * ${PART_TABLE_COL} + 3]}
311         local -r MODULE_A=${PART_TABLE[4 * ${PART_TABLE_COL} + 3]}
312         local -r RAMDISK_A=${PART_TABLE[5 * ${PART_TABLE_COL} + 3]}
313         local -r RAMDISK_RECOVERY_A=${PART_TABLE[6 * ${PART_TABLE_COL} + 3]}
314         local -r INFORM=inform
315         local -r HAL_A=${PART_TABLE[7 * ${PART_TABLE_COL} + 3]}
316         local -r BOOT_B=${PART_TABLE[8 * ${PART_TABLE_COL} + 3]}
317         local -r ROOTFS_B=${PART_TABLE[9 * ${PART_TABLE_COL} + 3]}
318         local -r MODULE_B=${PART_TABLE[10 * ${PART_TABLE_COL} + 3]}
319         local -r RAMDISK_B=${PART_TABLE[11 * ${PART_TABLE_COL} + 3]}
320         local -r RAMDISK_RECOVERY_B=${PART_TABLE[12 * ${PART_TABLE_COL} + 3]}
321         local -r HAL_B=${PART_TABLE[13 * ${PART_TABLE_COL} + 3]}
322         local -r RESERVED0=reserved0
323         local -r RESERVED1=reserved1
324         local -r RESERVED2=reserved2
325
326         if [[ $USER_SZ -le 100 ]]
327         then
328                 echo "We recommend to use more than 8GB disk"
329                 exit 0
330         fi
331
332         echo "================================================"
333         echo "Label                     dev             size"
334         echo "================================================"
335         echo $BOOT_A"                   " $DISK"1       " $BOOT_SZ "MB"
336         echo $ROOTFS_A"                 " $DISK"2       " $ROOTFS_SZ "MB"
337         echo $SYSTEMDATA"               " $DISK"3       " $DATA_SZ "MB"
338         echo "[Extend]""                " $DISK"4"
339         echo " "$USER"                  " $DISK"5       " $USER_SZ "MB"
340         echo " "$MODULE_A"              " $DISK"6       " $MODULE_SZ "MB"
341         echo " "$RAMDISK_A"             " $DISK"7       " $RAMDISK_SZ "MB"
342         echo " "$RAMDISK_RECOVERY_A"    " $DISK"8       " $RAMDISK_RECOVERY_SZ "MB"
343         echo " "$INFORM"                " $DISK"9       " $INFORM_SZ "MB"
344         echo " "$HAL_A"                 " $DISK"10      " $HAL_SZ "MB"
345         echo " "$BOOT_B"                " $DISK"11      " $BOOT_SZ "MB"
346         echo " "$ROOTFS_B"              " $DISK"12      " $ROOTFS_SZ "MB"
347         echo " "$MODULE_B"              " $DISK"13      " $MODULE_SZ "MB"
348         echo " "$RAMDISK_B"             " $DISK"14      " $RAMDISK_SZ "MB"
349         echo " "$RAMDISK_RECOVERY_B"    " $DISK"15      " $RAMDISK_RECOVERY_SZ "MB"
350         echo " "$HAL_B"                 " $DISK"16      " $HAL_SZ "MB"
351         echo " "$RESERVED0"             " $DISK"17      " $PARAM_SZ "MB"
352         echo " "$RESERVED1"             " $DISK"18      " $RESERVED1_SZ "MB"
353         echo " "$RESERVED2"             " $DISK"19      " $RESERVED2_SZ "MB"
354
355         local MOUNT_LIST=`mount | grep $DISK | awk '{print $1}'`
356         for mnt in $MOUNT_LIST
357         do
358                 umount $mnt
359         done
360
361         echo "Remove partition table..."
362         dd if=/dev/zero of=$DISK bs=512 count=32 conv=notrunc
363
364         if [ $support_delete == 1 ]; then
365                 sfdisk --delete $DISK
366         fi
367
368         SCRIPT=""
369         for ((idx=0; idx < $PART_TABLE_ROW; idx++)); do
370                 NR=${PART_TABLE[idx * ${PART_TABLE_COL} + 1]}
371                 eval "PART_LABEL_NR_${NR}=${PART_TABLE[idx * ${PART_TABLE_COL} + 3]}"
372         done
373
374         sfdisk $DISK <<-__EOF__
375         label: gpt
376         start=4MiB, size=${BOOT_SZ}MiB, type= C12A7328-F81F-11D2-BA4B-00A0C93EC93B, name=${PART_LABEL_NR_1}
377         size=${ROOTFS_SZ}MiB, name=${PART_LABEL_NR_2}
378         size=${DATA_SZ}MiB, name=${PART_LABEL_NR_3}
379         size=${EXTEND_SZ}MiB, name=none
380         size=${USER_SZ}MiB, name=${PART_LABEL_NR_5}
381         size=${MODULE_SZ}MiB, name=${PART_LABEL_NR_6}
382         size=${RAMDISK_SZ}MiB, name=${PART_LABEL_NR_7}
383         size=${RAMDISK_RECOVERY_SZ}MiB, name=${PART_LABEL_NR_8}
384         size=${INFORM_SZ}MiB, name=inform
385         size=${HAL_SZ}MiB, name=${PART_LABEL_NR_10}
386         size=${BOOT_SZ}MiB, type= C12A7328-F81F-11D2-BA4B-00A0C93EC93B, name=${PART_LABEL_NR_11}
387         size=${ROOTFS_SZ}MiB, name=${PART_LABEL_NR_12}
388         size=${MODULE_SZ}MiB, name=${PART_LABEL_NR_13}
389         size=${RAMDISK_SZ}MiB, name=${PART_LABEL_NR_14}
390         size=${RAMDISK_RECOVERY_SZ}MiB, name=${PART_LABEL_NR_15}
391         size=${HAL_SZ}MiB, name=${PART_LABEL_NR_16}
392         size=${PARAM_SZ}MiB, name=reserved0
393         size=${RESERVED1_SZ}MiB, name=reserved1
394         size=${RESERVED2_SZ}MiB, name=reserved2
395         __EOF__
396
397
398         for ((idx=0;idx<$PART_TABLE_ROW;idx++)); do
399                 local PART=/dev/`lsblk ${DISK} -o TYPE,KNAME | awk "/^part.*[a-z]${PART_TABLE[$idx * ${PART_TABLE_COL} + 1]}\$/ { print \\\$2 }"`
400                 if [ "${PART_TABLE[$idx * ${PART_TABLE_COL} + 4]}" == "vfat" ]; then
401                         mkfs.vfat -F 16 ${PART} -n ${PART_TABLE[$idx * ${PART_TABLE_COL} + 3]}
402                         if [ $? -eq 1 ]; then
403                                 echo "Failed to format as FAT filesystem"
404                                 exit -1
405                         fi
406                 elif [ "${PART_TABLE[$idx * ${PART_TABLE_COL} + 4]}" == "ext4" ]; then
407                         mkfs.ext4 -q ${PART} -L ${PART_TABLE[$idx * ${PART_TABLE_COL} + 3]} -F
408                 else
409                         echo "Skip to format for unknown filesystem type ${PART_TABLE[$idx * ${PART_TABLE_COL} + 4]} for part$idx, ${PART_TABLE[$idx * ${PART_TABLE_COL} + 3]}"
410                 fi
411         done
412
413         local -r PART9=/dev/`lsblk ${DISK} -o TYPE,KNAME | grep part | awk '{ print $2 }' | grep -G "[a-z]9\$"`
414         mkfs.ext4 -q ${PART9} -L $INFORM -F -O ^metadata_csum
415
416         # initialize value of parameters
417         initialize_parameter
418
419         local -r PART17=/dev/`lsblk ${DISK} -o TYPE,KNAME | grep part | awk '{ print $2 }' | grep -G "[a-z]17\$"`
420         mkfs.ext4 -q ${PART17} -L $RESERVED0 -F
421
422         local -r PART18=/dev/`lsblk ${DISK} -o TYPE,KNAME | grep part | awk '{ print $2 }' | grep -G "[a-z]18\$"`
423         mkfs.ext4 -q ${PART18} -L $RESERVED1 -F
424
425         local -r PART19=/dev/`lsblk ${DISK} -o TYPE,KNAME | grep part | awk '{ print $2 }' | grep -G "[a-z]19\$"`
426         mkfs.ext4 -q ${PART19} -L $RESERVED2 -F
427 }
428
429 function skip_resize () {
430         if [ "${SKIP}" == "0" ]; then
431                 return 0;
432         fi
433
434         if [ ! -d mnt_tmp ] ; then
435                 mkdir mnt_tmp
436         fi
437
438         mount -t ext4 ${DEVICE}3 ./mnt_tmp
439         touch ./mnt_tmp/var/.resizefs_done
440
441         echo "Rootfs resize will be skipped..."
442         sync
443         umount ./mnt_tmp
444         rmdir mnt_tmp
445 }
446
447 function show_usage () {
448         echo "- Usage:"
449         echo "  sudo ./sd_fusing*.sh -d <device> [-b <path> <path> ..] [--format] [--update [b] ]"
450         echo "  -d  : device ndoe "
451         echo "  -b  : binary "
452         echo "  --update : If want to update Image about B Partition, use --update option with b"
453         echo "             Otherwise, it will be updated to both partition"
454 }
455
456 function check_partition_format () {
457         if [ "$FORMAT" != "2" ]; then
458                 echo "-----------------------"
459                 echo "Skip $DEVICE format"
460                 echo "-----------------------"
461                 return 0
462         fi
463
464         echo "-------------------------------"
465         echo "Start $DEVICE format"
466         echo ""
467         mkpart_3
468         echo "End $DEVICE format"
469         echo "-------------------------------"
470         echo ""
471 }
472
473 function check_args () {
474         if [ "$DEVICE" == "" ]; then
475                 echo "$(tput setaf 1)$(tput bold)- Device node is empty!"
476                 show_usage
477                 tput sgr 0
478                 exit 0
479         fi
480
481         if [ "$DEVICE" != "" ]; then
482                 echo "Device: $DEVICE"
483         fi
484
485         if [ "$FUSING_BINARY_NUM" != 0 ]; then
486                 echo "Fusing binary: "
487                 for ((bid = 0 ; bid < $FUSING_BINARY_NUM ; bid++))
488                 do
489                         echo "  ${FUSING_BINARY_ARRAY[bid]}"
490                 done
491                 echo ""
492         fi
493
494         if [ "$FORMAT" == "1" ]; then
495                 echo ""
496                 echo -n "$(tput setaf 3)$(tput bold)$DEVICE will be formatted, Is it OK? [y/<n>] "
497                 tput sgr 0
498                 read input
499                 if [ "$input" == "y" ] || [ "$input" == "Y" ]; then
500                         FORMAT=2
501                 else
502                         FORMAT=0
503                 fi
504         fi
505 }
506
507 function check_device () {
508         if [ ! -b "$DEVICE" ]; then
509                 echo "No such device: $DEVICE"
510                 exit 0
511         fi
512
513         DEVICE=/dev/`lsblk $DEVICE -o TYPE,KNAME | awk '/^(disk|loop)/ { print $2 }'`
514
515         local REMOVABLE=`lsblk $DEVICE -nd -o RM | grep 1 | wc -l`
516         if [ "$REMOVABLE" == "0" ]; then
517                 echo ""
518                 echo -n "$(tput setaf 3)$(tput bold)$DEVICE is not a removable disk, Is it OK? [y/<n>] "
519                 tput sgr 0
520                 read input
521                 if [ "$input" != "y" ] && [ "$input" != "Y" ]; then
522                         exit 0
523                 fi
524         fi
525
526         if [ ! -w "$DEVICE" ]; then
527                 echo "Write not permitted: $DEVICE"
528                 exit 0
529         fi
530 }
531
532 function print_logo () {
533         echo ""
534         echo "Raspberry Pi4 downloader, version 1.0.12"
535         echo "$(tput setaf 1)$(tput bold)NOTE: To use this script, it has to update to latest eeprom"
536         echo ""
537 }
538
539 print_logo
540
541 function add_fusing_binary() {
542         local declare binary_name=$1
543
544         if [ "$binary_name" != "" ]; then
545                 if [ -f "$binary_name" ]; then
546                         FUSING_BINARY_ARRAY[$FUSING_BINARY_NUM]=$binary_name
547
548                         FUSING_BINARY_NUM=$((FUSING_BINARY_NUM + 1))
549                 else
550                         echo "No such file: $binary_name"
551                 fi
552         fi
553 }
554
555
556 declare -i binary_option=0
557
558 while test $# -ne 0; do
559         option=$1
560         shift
561
562         case $option in
563         --f | --format)
564                 FORMAT="1"
565                 binary_option=0
566                 ;;
567         -d)
568                 DEVICE=$1
569                 binary_option=0
570                 shift
571                 ;;
572         -b)
573                 add_fusing_binary $1
574                 binary_option=1
575                 shift
576                 ;;
577         --update)
578                 if [ "$1" == "b" ] ; then
579                         ab_option=2
580                 else
581                         ab_option=1
582                 fi
583                 shift
584                 ;;
585         --skip-resize)
586                 SKIP=1
587                 shift
588                 ;;
589         *)
590                 if [ $binary_option == 1 ];then
591                         add_fusing_binary $option
592                 else
593                         echo "Unkown command: $option"
594                         exit
595                 fi
596                 ;;
597         esac
598 done
599
600 check_args
601 check_device
602 check_partition_format
603 check_ddversion
604 fuse_image
605 skip_resize