6 local cfgpart
=$
(find_mmc_part
"0:BOOTCONFIG")
9 if [ -z "$cfgpart" ]; then
10 echo "failed to get the partition: \"0:BOOTCONFIG\""
14 cur_index
=$
(dd if=${cfgpart} bs
=1 count
=1 skip
=$offset 2> /dev
/null |
hexdump -e '"%d"')
15 if [ ${index} != ${cur_index} ]; then
16 echo "updating \"0:BOOTCONFIG\""
17 echo -en "\x0${index}" | \
18 dd of
=${cfgpart} bs
=1 count
=1 seek
=$offset conv
=notrunc
2>/dev
/null
21 # also update 0:BOOTCONFIG1 if exists
22 cfgpart
=$
(find_mmc_part
"0:BOOTCONFIG1")
23 [ -z "$cfgpart" ] && return
25 cur_index
=$
(dd if=${cfgpart} bs
=1 count
=1 skip
=$offset 2> /dev
/null |
hexdump -e '"%d"')
26 if [ ${index} != ${cur_index} ]; then
27 echo "updating \"0:BOOTCONFIG1\""
28 echo -en "\x0${index}" | \
29 dd of
=${cfgpart} bs
=1 count
=1 seek
=$offset conv
=notrunc
2>/dev
/null
34 # After the commit bad1835f27ec31dbc30060b03cc714212275168a in fstools,
35 # p17 (label: "rootfs_data") is mounted as a rootfs_data on boot instead
36 # of the loop device labeled as "rootfs_data" in p15 (label: "rootfs").
38 # cmdline flag is added to avoid mount "rootfs_data" partition by the
39 # commit 964d1e3af0e111bad6d393f8a3be702e334c2398 in fstools, but
40 # NCP-HG100 doesn't use it because it has a large (abount 1.6GB)
41 # "rootfs_data" partition and the advantage is larger than the
42 # disadvantages, such as overwriting the stock data in "rootfs_data"
44 sony_emmc_do_upgrade
() {
50 kernel_dev
=$
(find_mmc_part
"0:HLOS")
51 rootfs_dev
=$
(find_mmc_part
"rootfs")
52 rootfs_data_dev
=$
(find_mmc_part
"rootfs_data")
54 if [ -z "$kernel_dev" ] ||
[ -z "$rootfs_dev" ] ||
[ -z "$rootfs_data_dev" ]; then
55 echo "The partition name for kernel or rootfs or rootfs_data is not specified or failed to get the mmc device."
59 # use first partitions of kernel/rootfs for NCP-HG100
60 # - offset 88 (0x58): 0:HLOS (kernel)
61 # - offset 108 (0x6c): rootfs
62 update_bootconfig
88 0 ||
exit 1
63 update_bootconfig
108 0 ||
exit 1
65 board_dir
=$
(tar tf
$tar_file |
grep -m 1 '^sysupgrade-.*/$')
66 board_dir
=${board_dir%/}
68 echo "Flashing kernel to ${kernel_dev}"
69 tar xf
$tar_file ${board_dir}/kernel
-O > $kernel_dev
71 echo "Flashing rootfs to ${rootfs_dev}"
72 tar xf
$tar_file ${board_dir}/root
-O > $rootfs_dev
74 echo "Format new rootfs_data"
75 mkfs.ext4
-F -L rootfs_data
$rootfs_data_dev
77 if [ -e "$UPGRADE_BACKUP" ]; then
79 mount
-t ext4
$rootfs_data_dev /tmp
/new_root
&& {
80 echo "Saving configurations to rootfs_data"
81 cp "$UPGRADE_BACKUP" "/tmp/new_root/$BACKUP_FILE"
86 echo "sysupgrade successful"