4 platform_find_partitions() {
5 local first dev size erasesize name
6 while read dev size erasesize name; do
7 name=${name#'"'}; name=${name%'"'}
9 vmlinux.bin.l7|kernel|linux|rootfs)
10 if [ -z "$first" ]; then
13 echo "$erasesize:$first:$name"
21 platform_find_kernelpart() {
23 for part in "${1%:*}" "${1#*:}"; do
25 vmlinux.bin.l7|kernel|linux)
33 platform_check_image() {
34 [ "$#" -gt 1 ] && return 1
36 case "$(get_magic_word "$1")" in
39 local md5_img=$(dd if="$1" bs=2 skip=9 count=16 2>/dev/null)
40 local md5_chk=$(dd if="$1" bs=$CI_BLKSZ skip=1 2>/dev/null | md5sum -); md5_chk="${md5_chk%% *}"
42 if [ -n "$md5_img" -a -n "$md5_chk" ] && [ "$md5_img" = "$md5_chk" ]; then
45 echo "Invalid image. Contents do not match checksum (image:$md5_img calculated:$md5_chk)"
50 echo "Invalid image. Use combined .img files on this platform"
56 platform_do_upgrade() {
57 local partitions=$(platform_find_partitions)
58 local kernelpart=$(platform_find_kernelpart "${partitions#*:}")
59 local erase_size=$((0x${partitions%%:*})); partitions="${partitions#*:}"
60 local kern_length=0x$(dd if="$1" bs=2 skip=1 count=4 2>/dev/null)
61 local kern_blocks=$(($kern_length / $CI_BLKSZ))
62 local root_blocks=$((0x$(dd if="$1" bs=2 skip=5 count=4 2>/dev/null) / $CI_BLKSZ))
64 if [ -n "$partitions" ] && [ -n "$kernelpart" ] && \
65 [ ${kern_blocks:-0} -gt 0 ] && \
66 [ ${root_blocks:-0} -gt ${kern_blocks:-0} ] && \
67 [ ${erase_size:-0} -gt 0 ];
70 [ -f "$CONF_TAR" -a "$SAVE_CONFIG" -eq 1 ] && append="-j $CONF_TAR"
72 ( dd if="$1" bs=$CI_BLKSZ skip=1 count=$kern_blocks 2>/dev/null; \
73 dd if="$1" bs=$CI_BLKSZ skip=$((1+$kern_blocks)) count=$root_blocks 2>/dev/null ) | \
74 mtd -r $append -F$kernelpart:$kern_length:$CI_LDADR,rootfs write - $partitions