brcm2708: implement sysupgrade image check
[librecmc/librecmc.git] / target / linux / brcm2708 / base-files / lib / upgrade / platform.sh
1 get_magic_at() {
2         local file="$1"
3         local pos="$2"
4         get_image "$file" | dd bs=1 count=2 skip="$pos" 2>/dev/null | hexdump -v -n 2 -e '1/1 "%02x"'
5 }
6
7 platform_check_image() {
8         local file="$1"
9         local magic
10
11         magic=$(get_magic_at "$file" 510)
12         [ "$magic" != "55aa" ] && {
13                 echo "Failed to verify MBR boot signature."
14                 return 1
15         }
16
17         return 0;
18 }
19
20 platform_do_upgrade() {
21         sync
22         get_image "$1" | dd of=/dev/mmcblk0 bs=2M conv=fsync
23         sleep 1
24 }
25
26 platform_copy_config() {
27         mkdir -p /boot
28         [ -f /boot/kernel.img ] || mount -t vfat -o rw,noatime /dev/mmcblk0p1 /boot
29         cp -af "$CONF_TAR" /boot/
30         sync
31         umount /boot
32 }