summaryrefslogtreecommitdiff
path: root/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-firmware-upgrade
blob: a377309cb5dbc754e3762df045332e8e2edd791b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
dofile=/var/volatile/do_flash_upgrade

if [ $# != 1 ]; then
    echo "Usage: $0 upgrade.bin"
    exit 1
fi

set -e
upgrade=$1

mkdir -p /var/volatile
cd /var/volatile

# make sure firmware is for this device
hw_version=$(cat /sys/devices/platform/mts-io/hw-version)
firmware_model=$(tar -xO -f $upgrade model)
shopt -s nocasematch
if [[ ! "$hw_version" =~ ^$firmware_model- ]]; then
    logger -s -t firmware_upgrade "Wrong firmware for this hardware"
    logger -s -t firmware_upgrade "hw version: $hw_version"
    logger -s -t firmware_upgrade "firmware model: $firmware_model"
    exit 1
fi

files=(bstrap.bin uboot.bin uImage.bin config.jffs2 oem.jffs2 rootfs.jffs2 install.sh)

tobeflashed=0
# verify all MD5 sums
for (( i = 0; i < ${#files[@]}; i++ )); do
    file=${files[i]}
    # if the file is in the tar, md5sum it
    if tar -t -f $upgrade | grep -F -q "$file"; then
        logger -s -t firmware_upgrade "Checking MD5 for $file..."
        if ! tar -x -f $upgrade $file.md5; then
            logger -s -t firmware_upgrade "MD5 is not found for the $file, upgrade aborted"
            exit 1
        fi
        if ! tar -xO -f $upgrade $file | md5sum -c $file.md5; then
            logger -s -t firmware_upgrade "MD5 check failed, upgrade aborted"
            exit 1
        fi
        tobeflashed=1
    fi
done

if (( $tobeflashed )); then
    mkdir -p /var/volatile/flash-upgrade
    mv -f $upgrade /var/volatile/flash-upgrade/upgrade.bin
    touch "${dofile}"
    chown "root:root" "${dofile}" || true
    uid=$(stat -c %u "${dofile}") || true
    result=$?
    if ((result != 0)) ; then
        logger -s -t firmware_upgrade "Cannot create ${dofile}"
        exit 1
    fi
    if ((uid != 0)) ; then
        logger -s -t firmware_upgrade "Cannot set ownership of ${dofile} to root"
        exit 1
    fi
    logger -s -t firmware_upgrade "Rebooting"
    sleep 1
    reboot
    exit 0
else
    logger -s -t firmware_upgrade "Nothing to be flashed!"
    exit 1
fi