blob: e24e244ff1250cabd6e2690634fce1ebc5ea67c9 [file] [log] [blame]
developer15a43312022-04-12 11:23:23 +08001#!/bin/bash
2
3if [ $1 ] ; then
4 echo "Usage '/lib/rdk/FwUgrade.sh'"
5 echo "Note: New images should be downloaded in /tmp directory"
6 exit 1
7fi
8
9check ()
10{
11 if [ $? != 0 ]; then
12 echo $*
13 exit 1
14 fi
15}
16
17ls /tmp/zImage* >/dev/null
18check "No new image present in /tmp directory"
19
20BootPartition="/dev/mmcblk0p1"
21NewTurrisModel=1
22
23ActiveRootPartition=`mount | grep "/" -w | cut -d' ' -f1`
24if [ $ActiveRootPartition == "/dev/mmcblk0p2" ]; then
25 TargetRootPartition="/dev/mmcblk0p3"
26elif [ $ActiveRootPartition == "/dev/mmcblk0p3" ]; then
27 TargetRootPartition="/dev/mmcblk0p2"
28elif [ $ActiveRootPartition == "/dev/mmcblk0p5" ]; then
29 TargetRootPartition="/dev/mmcblk0p7"
30 BootPartition="/dev/mmcblk0p3"
31 NewTurrisModel=0
32else ##if $ActiveRootPartition is "/dev/mmcblk0p7"
33 TargetRootPartition="/dev/mmcblk0p5"
34 BootPartition="/dev/mmcblk0p3"
35 NewTurrisMode=0
36fi
37echo "ActiveRootPartition: $ActiveRootPartition"
38echo "TargetRootPartition: $TargetRootPartition"
39echo "BootPartition: $BootPartition"
40
41umount /mnt 2>/dev/null
42echo y | mkfs.ext2 $TargetRootPartition
43check "Error in formatting $TargetRootPartition"
44
45mount $TargetRootPartition /mnt
46check "Error in mounting $TargetRootPartition"
47
48tar -xzf /tmp/*.tar.gz -C /mnt
49check "Error in unpacking new rootfs"
50
51umount /mnt
52check "Error in unmounting"
53echo "New rootfs is loaded in $TargetRootPartition"
54
55mount $BootPartition /mnt/
56check "Error in mounting $BootPartition"
57
58mv /mnt/zImage /zImage_old
59cp /tmp/zImage* /mnt/zImage
60if [ $? != 0 ]; then
61echo "Error in copying zImage. Falling back."
62mv /zImage_old /mnt/zImage
63exit 1
64fi
65
66if [ $NewTurrisModel -eq 1 ]; then
67 if [ $TargetRootPartition == "/dev/mmcblk0p2" ]; then
68 cp /boot-main.scr /mnt/boot.scr
69 else
70 cp /boot-alt.scr /mnt/boot.scr
71 fi
72else
73 fw_setenv yocto_bootargs earlyprintk console=ttyS0,115200 root=$TargetRootPartition rootfstype=ext2 rw rootwait
74fi