forked from Ivasoft/openwrt
1. Create "rootfs_data" dynamicaly U-Boot firmware images can contain only 2 UBI volumes: bootfs (container with U-Boot + kernel + DTBs) and rootfs (e.g. squashfs). There is no way to include "rootfs_data" UBI volume or make firmware file tell U-Boot to create one. For that reason "rootfs_data" needs to be created dynamically. Use preinit script to handle that. Fire it right before "mount_root" one. 2. Relate "rootfs_data" to flashed firmware As already explained flashing new firmware with U-Boot will do nothing to the "rootfs_data". It could result in new firmware reusing old "rootfs_data" overlay UBI volume and its file. Users expect a clean state after flashing firmware (even if flashing the same one). Solve that by reading flash counter of running firmware and storing it in "rootfs_data" UBI volume. Every mismatch will result in wiping old data. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
36 lines
916 B
Plaintext
36 lines
916 B
Plaintext
# SPDX-License-Identifier: GPL-2.0-or-later OR BSD-2-Clause
|
|
|
|
. /lib/functions/bcm4908.sh
|
|
|
|
rootfs_create() {
|
|
local blocks
|
|
|
|
blocks=$(cat /sys/class/ubi/ubi0/avail_eraseblocks)
|
|
[ -z "$blocks" ] && {
|
|
echo "Failed to read amount of available erase blocks" >&2
|
|
return
|
|
}
|
|
|
|
# Use 80% of remaining flash size for "rootfs_data"
|
|
ubimkvol /dev/ubi0 -n 20 -N rootfs_data --lebs $((blocks / 100 * 80))
|
|
mknod -m 0600 /dev/ubi0_20 c 252 21
|
|
|
|
bcm4908_verify_rootfs_data ubi0_20
|
|
}
|
|
|
|
rootfs_prepare() {
|
|
# Do nothing on CFE devices
|
|
ubinfo /dev/ubi0 -N metadata1 > /dev/null 2>&1 || exit 0
|
|
|
|
# Find UBI volume device (e.g. ubi0_123)
|
|
local ubivol="$(grep rootfs_data /sys/devices/virtual/ubi/ubi*/ubi*/name | sed -n 's/.*\(ubi\d*_\d*\).*/\1/p')"
|
|
if [ -n "$ubivol" ]; then
|
|
bcm4908_verify_rootfs_data $ubivol
|
|
else
|
|
echo "Creating \"rootfs_data\" UBI volume"
|
|
rootfs_create
|
|
fi
|
|
}
|
|
|
|
boot_hook_add preinit_main rootfs_prepare
|