Root/target/linux/cns3xxx/base-files/lib/upgrade/platform.sh

1. /lib/cns3xxx.sh
2
3RAMFS_COPY_DATA="/lib/cns3xxx.sh"
4
5CI_BLKSZ=65536
6
7platform_find_partitions() {
8    local first dev size erasesize name
9    while read dev size erasesize name; do
10        name=${name#'"'}; name=${name%'"'}
11        case "$name" in
12            vmlinux.bin.l7|kernel|linux|rootfs)
13                if [ -z "$first" ]; then
14                    first="$name"
15                else
16                    echo "$erasesize:$first:$name"
17                    break
18                fi
19            ;;
20        esac
21    done < /proc/mtd
22}
23
24platform_find_kernelpart() {
25    local part
26    for part in "${1%:*}" "${1#*:}"; do
27        case "$part" in
28            vmlinux.bin.l7|kernel|linux)
29                echo "$part"
30                break
31            ;;
32        esac
33    done
34}
35
36platform_do_upgrade_combined() {
37    local partitions=$(platform_find_partitions)
38    local kernelpart=$(platform_find_kernelpart "${partitions#*:}")
39    local erase_size=$((0x${partitions%%:*})); partitions="${partitions#*:}"
40    local kern_length=0x$(dd if="$1" bs=2 skip=1 count=4 2>/dev/null)
41    local kern_blocks=$(($kern_length / $CI_BLKSZ))
42    local root_blocks=$((0x$(dd if="$1" bs=2 skip=5 count=4 2>/dev/null) / $CI_BLKSZ))
43
44    v "platform_do_upgrade_combined"
45    v "partitions=$partitions"
46    v "kernelpart=$kernelpart"
47    v "erase_size=$erase_size"
48    v "kern_blocks=$kern_blocks"
49    v "root_blocks=$root_blocks"
50
51    if [ -n "$partitions" ] && [ -n "$kernelpart" ] && \
52       [ ${kern_blocks:-0} -gt 0 ] && \
53       [ ${root_blocks:-0} -gt 0 ] && \
54       [ ${erase_size:-0} -gt 0 ];
55    then
56        local append=""
57        [ -f "$CONF_TAR" -a "$SAVE_CONFIG" -eq 1 ] && append="-j $CONF_TAR"
58
59        dd if="$1" bs=$CI_BLKSZ skip=1 count=$kern_blocks 2>/dev/null | mtd write - kernel
60        dd if="$1" bs=$CI_BLKSZ skip=$((1+$kern_blocks)) count=$root_blocks 2>/dev/null | \
61                 mtd -r $append write - rootfs
62    else
63        echo "invalid image"
64    fi
65}
66
67platform_check_image() {
68    local board=$(cns3xxx_board_name)
69    local magic="$(get_magic_word "$1")"
70    local magic_long="$(get_magic_long "$1")"
71
72    [ "$ARGC" -gt 1 ] && return 1
73
74    case "$board" in
75    laguna)
76        [ "$magic" != "4349" ] && {
77            echo "Invalid image. Use *-sysupgrade.bin files on this board"
78            return 1
79        }
80
81        local md5_img=$(dd if="$1" bs=2 skip=9 count=16 2>/dev/null)
82        local md5_chk=$(dd if="$1" bs=$CI_BLKSZ skip=1 2>/dev/null | md5sum -); md5_chk="${md5_chk%% *}"
83
84        if [ -n "$md5_img" -a -n "$md5_chk" ] && [ "$md5_img" = "$md5_chk" ]; then
85            return 0
86        else
87            echo "Invalid image. Contents do not match checksum (image:$md5_img calculated:$md5_chk)"
88            return 1
89        fi
90        return 0
91        ;;
92    esac
93
94    echo "Sysupgrade is not yet supported on $board."
95    return 1
96}
97
98platform_do_upgrade() {
99    local board=$(cns3xxx_board_name)
100
101    v "board=$board"
102    case "$board" in
103    laguna)
104        platform_do_upgrade_combined "$ARGV"
105        ;;
106    *)
107        default_do_upgrade "$ARGV"
108        ;;
109    esac
110}
111
112disable_watchdog() {
113    v "killing watchdog"
114    killall watchdog
115    ( ps | grep -v 'grep' | grep '/dev/watchdog' ) && {
116        echo 'Could not disable watchdog'
117        return 1
118    }
119}
120
121# CONFIG_WATCHDOG_NOWAYOUT=y - can't kill watchdog unless kernel cmdline has a mpcore_wdt.nowayout=0
122#append sysupgrade_pre_upgrade disable_watchdog
123

Archive Download this file



interactive