blob: f675039304195dfb2330c6925ff3831913cefe65 [file] [log] [blame]
developerefca97c2022-05-30 16:22:40 +08001#!/bin/sh
2set +e
3
4export PATH=/sbin:/bin:/usr/sbin:/usr/bin
5MOUNT="/bin/mount"
6UMOUNT="/bin/umount"
7INIT="/lib/systemd/systemd"
8
developer8f0d3442022-07-12 17:38:07 +08009
10nand_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
26mkdir -p /proc
27mkdir -p /sys
28mkdir -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
34data_ubivol="$( nand_find_volume ubi0 rootfs_data )"
35
36[ -z "$CONSOLE" ] && CONSOLE="/dev/console"
37mkdir -p /mnt
38
39$MOUNT -n -t ubifs /dev/$data_ubivol -o rw,noatime /overlay
40
developer1b68abb2022-09-08 14:09:13 +080041if [ -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
48fi
developer8f0d3442022-07-12 17:38:07 +080049
developerefca97c2022-05-30 16:22:40 +080050[ ! -d "/overlay/upper" ] && mkdir /overlay/upper
51[ ! -d "/overlay/work" ] && mkdir /overlay/work
developer8f0d3442022-07-12 17:38:07 +080052
developerefca97c2022-05-30 16:22:40 +080053$MOUNT -n -t overlay overlayfs:/overlay -o rw,noatime,lowerdir=/,upperdir=/overlay/upper,workdir=/overlay/work /mnt
developer8f0d3442022-07-12 17:38:07 +080054$MOUNT -n /proc -o noatime --move /mnt/proc
developerefca97c2022-05-30 16:22:40 +080055pivot_root /mnt /mnt/rom
developer8f0d3442022-07-12 17:38:07 +080056
57
58$MOUNT -n /rom/sys -o noatime --move /sys
developerefca97c2022-05-30 16:22:40 +080059$MOUNT -n /rom/dev -o noatime --move /dev
developer8f0d3442022-07-12 17:38:07 +080060$MOUNT -n /rom/rdklogs -o noatime --move /rdklogs
developerefca97c2022-05-30 16:22:40 +080061$MOUNT -n /rom/overlay -o noatime --move /overlay
62
63
developer8f0d3442022-07-12 17:38:07 +080064
65
developerefca97c2022-05-30 16:22:40 +080066exec $INIT