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