1 # Copyright (C) 2021 OpenWrt.org
8 [ "$CI_KERNPART" -a -z "$EMMC_KERN_DEV" ] && export EMMC_KERN_DEV
="$(find_mmc_part $CI_KERNPART $CI_ROOTDEV)"
9 [ "$CI_ROOTPART" -a -z "$EMMC_ROOT_DEV" ] && export EMMC_ROOT_DEV
="$(find_mmc_part $CI_ROOTPART $CI_ROOTDEV)"
10 [ "$CI_DATAPART" -a -z "$EMMC_DATA_DEV" ] && export EMMC_DATA_DEV
="$(find_mmc_part $CI_DATAPART $CI_ROOTDEV)"
13 local board_dir
=$
(tar tf
"$tar_file" |
grep -m 1 '^sysupgrade-.*/$')
14 board_dir
=${board_dir%/}
16 tar tf
"$tar_file" ${board_dir}/kernel
1>/dev
/null
2>/dev
/null
&& has_kernel
=1
17 tar tf
"$tar_file" ${board_dir}/root
1>/dev
/null
2>/dev
/null
&& has_rootfs
=1
19 [ "$has_kernel" = 1 -a "$EMMC_KERN_DEV" ] &&
20 export EMMC_KERNEL_BLOCKS
=$
(($
(tar xf
"$tar_file" ${board_dir}/kernel
-O |
dd of
="$EMMC_KERN_DEV" bs
=512 2>&1 |
grep "records out" | cut
-d' ' -f1)))
22 [ "$has_rootfs" = 1 -a "$EMMC_ROOT_DEV" ] &&
23 export EMMC_ROOTFS_BLOCKS
=$
(($
(tar xf
"$tar_file" ${board_dir}/root
-O |
dd of
="$EMMC_ROOT_DEV" bs
=512 2>&1 |
grep "records out" | cut
-d' ' -f1)))
25 if [ -z "$UPGRADE_BACKUP" ]; then
26 if [ "$EMMC_DATA_DEV" ]; then
27 dd if=/dev
/zero of
="$EMMC_DATA_DEV" bs
=512 count
=8
28 elif [ "$EMMC_ROOTFS_BLOCKS" ]; then
29 dd if=/dev
/zero of
="$EMMC_ROOT_DEV" bs
=512 seek
=$EMMC_ROOTFS_BLOCKS count
=8
30 elif [ "$EMMC_KERNEL_BLOCKS" ]; then
31 dd if=/dev
/zero of
="$EMMC_KERN_DEV" bs
=512 seek
=$EMMC_KERNEL_BLOCKS count
=8
38 [ "$CI_KERNPART" -a -z "$EMMC_KERN_DEV" ] && export EMMC_KERN_DEV
="$(find_mmc_part $CI_KERNPART $CI_ROOTDEV)"
40 if [ "$EMMC_KERN_DEV" ]; then
41 export EMMC_KERNEL_BLOCKS
=$
(($
(get_image
"$fit_file" | fwtool
-i /dev
/null
-T - |
dd of
="$EMMC_KERN_DEV" bs
=512 2>&1 |
grep "records out" | cut
-d' ' -f1)))
43 [ -z "$UPGRADE_BACKUP" ] && dd if=/dev
/zero of
="$EMMC_KERN_DEV" bs
=512 seek
=$EMMC_KERNEL_BLOCKS count
=8
48 if [ "$EMMC_DATA_DEV" ]; then
49 dd if="$UPGRADE_BACKUP" of
="$EMMC_DATA_DEV" bs
=512
50 elif [ "$EMMC_ROOTFS_BLOCKS" ]; then
51 dd if="$UPGRADE_BACKUP" of
="$EMMC_ROOT_DEV" bs
=512 seek
=$EMMC_ROOTFS_BLOCKS
52 elif [ "$EMMC_KERNEL_BLOCKS" ]; then
53 dd if="$UPGRADE_BACKUP" of
="$EMMC_KERN_DEV" bs
=512 seek
=$EMMC_KERNEL_BLOCKS
58 local file_type
=$
(identify
$1)
61 "fit") emmc_upgrade_fit
$1;;
62 *) emmc_upgrade_tar
$1;;