developer | efca97c | 2022-05-30 16:22:40 +0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | set +e |
| 3 | |
| 4 | export PATH=/sbin:/bin:/usr/sbin:/usr/bin |
| 5 | MOUNT="/bin/mount" |
| 6 | UMOUNT="/bin/umount" |
| 7 | INIT="/lib/systemd/systemd" |
| 8 | |
developer | 8f0d344 | 2022-07-12 17:38:07 +0800 | [diff] [blame] | 9 | |
| 10 | nand_find_volume() { |
| 11 | local ubidevdir ubivoldir |
| 12 | ubidevdir="/sys/devices/virtual/ubi/$1" |
| 13 | [ ! -d "$ubidevdir" ] && return 1 |
| 14 | for ubivoldir in $ubidevdir/${1}_*; do |
| 15 | [ ! -d "$ubivoldir" ] && continue |
| 16 | if [ "$( cat $ubivoldir/name )" = "$2" ]; then |
| 17 | basename $ubivoldir |
| 18 | return 0 |
| 19 | fi |
| 20 | done |
| 21 | } |
| 22 | |
| 23 | |
| 24 | $MOUNT -o remount,rw / |
| 25 | |
| 26 | mkdir -p /proc |
| 27 | mkdir -p /sys |
| 28 | mkdir -p /rdklogs |
| 29 | |
| 30 | $MOUNT -t proc proc -o rw,nosuid,nodev,noexec,noatime /proc |
| 31 | $MOUNT -t sysfs sysfs -o rw,nosuid,nodev,noexec,noatime /sys |
| 32 | $MOUNT -n -t tmpfs tmpfs -o rw,nosuid,nodev,noexec,noatime /rdklogs |
| 33 | |
| 34 | data_ubivol="$( nand_find_volume ubi0 rootfs_data )" |
| 35 | |
| 36 | [ -z "$CONSOLE" ] && CONSOLE="/dev/console" |
| 37 | mkdir -p /mnt |
| 38 | |
| 39 | $MOUNT -n -t ubifs /dev/$data_ubivol -o rw,noatime /overlay |
| 40 | |
developer | 1b68abb | 2022-09-08 14:09:13 +0800 | [diff] [blame] | 41 | if [ -f "/overlay/upper/reset-default" ]; then |
| 42 | v "Proceed with reset to default" |
| 43 | $UMOUNT /overlay |
| 44 | rootfs_data_length=$(cat /sys/class/ubi/$data_ubivol/data_bytes) |
| 45 | ubirmvol /dev/ubi0 -N rootfs_data |
| 46 | ubimkvol /dev/ubi0 -N rootfs_data -s $rootfs_data_length |
| 47 | $MOUNT -n -t ubifs /dev/$data_ubivol -o rw,noatime /overlay |
| 48 | fi |
developer | 8f0d344 | 2022-07-12 17:38:07 +0800 | [diff] [blame] | 49 | |
developer | efca97c | 2022-05-30 16:22:40 +0800 | [diff] [blame] | 50 | [ ! -d "/overlay/upper" ] && mkdir /overlay/upper |
| 51 | [ ! -d "/overlay/work" ] && mkdir /overlay/work |
developer | 8f0d344 | 2022-07-12 17:38:07 +0800 | [diff] [blame] | 52 | |
developer | efca97c | 2022-05-30 16:22:40 +0800 | [diff] [blame] | 53 | $MOUNT -n -t overlay overlayfs:/overlay -o rw,noatime,lowerdir=/,upperdir=/overlay/upper,workdir=/overlay/work /mnt |
developer | 8f0d344 | 2022-07-12 17:38:07 +0800 | [diff] [blame] | 54 | $MOUNT -n /proc -o noatime --move /mnt/proc |
developer | efca97c | 2022-05-30 16:22:40 +0800 | [diff] [blame] | 55 | pivot_root /mnt /mnt/rom |
developer | 8f0d344 | 2022-07-12 17:38:07 +0800 | [diff] [blame] | 56 | |
| 57 | |
| 58 | $MOUNT -n /rom/sys -o noatime --move /sys |
developer | efca97c | 2022-05-30 16:22:40 +0800 | [diff] [blame] | 59 | $MOUNT -n /rom/dev -o noatime --move /dev |
developer | 8f0d344 | 2022-07-12 17:38:07 +0800 | [diff] [blame] | 60 | $MOUNT -n /rom/rdklogs -o noatime --move /rdklogs |
developer | efca97c | 2022-05-30 16:22:40 +0800 | [diff] [blame] | 61 | $MOUNT -n /rom/overlay -o noatime --move /overlay |
| 62 | |
| 63 | |
developer | 8f0d344 | 2022-07-12 17:38:07 +0800 | [diff] [blame] | 64 | |
| 65 | |
developer | efca97c | 2022-05-30 16:22:40 +0800 | [diff] [blame] | 66 | exec $INIT |