diff options
author | Daniel Golle <daniel@makrotopia.org> | 2021-02-17 15:17:49 +0000 |
---|---|---|
committer | Daniel Golle <daniel@makrotopia.org> | 2021-02-24 01:35:20 +0000 |
commit | 5c10f26c28031c0d7e72b672623727adb5df7b2d (patch) | |
tree | 2362cacb0e64046c32ae10261475b63912a49cc8 /package/base-files/files | |
parent | 330bd380e8b691833c8dcc9b579b51851cbd4b0f (diff) | |
download | upstream-5c10f26c28031c0d7e72b672623727adb5df7b2d.tar.gz upstream-5c10f26c28031c0d7e72b672623727adb5df7b2d.tar.bz2 upstream-5c10f26c28031c0d7e72b672623727adb5df7b2d.zip |
sysupgrade-nand: allow limiting rootfs_data by setting env variable
Check if firmware environment variable 'rootfs_data_max' exists and is
set to a numerical value greater than 0. If so, limit rootfs_data
volume to that size instead of using the maximum available size.
This is useful on devices with lots of flash where users may want to
have eg. a volume for persistent logs and statistics or for external
applications/containers. Persistence on rootfs overlay is limited by
the size of memory available during the sysugprade process as that
data needs to be copied to RAM while the volume is being recreated
during sysupgrade. Hence it is unsuitable for keeping larger amounts
of data accross upgrade which makes additional volume(s) for
application data desirable.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Diffstat (limited to 'package/base-files/files')
-rw-r--r-- | package/base-files/files/lib/upgrade/nand.sh | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/package/base-files/files/lib/upgrade/nand.sh b/package/base-files/files/lib/upgrade/nand.sh index 7cf95c0139..2b766480d7 100644 --- a/package/base-files/files/lib/upgrade/nand.sh +++ b/package/base-files/files/lib/upgrade/nand.sh @@ -117,6 +117,9 @@ nand_restore_config() { nand_upgrade_prepare_ubi() { local rootfs_length="$1" local rootfs_type="$2" + local rootfs_data_max="$(fw_printenv -n rootfs_data_max 2>/dev/null)" + [ -n "$rootfs_data_max" ] && rootfs_data_max=$(($rootfs_data_max)) + local kernel_length="$3" local has_env="${4:-0}" @@ -176,11 +179,11 @@ nand_upgrade_prepare_ubi() { # update rootfs if [ -n "$rootfs_length" ]; then - local root_size_param + local rootfs_size_param if [ "$rootfs_type" = "ubifs" ]; then - root_size_param="-m" + rootfs_size_param="-m" else - root_size_param="-s $rootfs_length" + rootfs_size_param="-s $rootfs_length" fi if ! ubimkvol /dev/$ubidev -N $CI_ROOTPART $rootfs_size_param; then echo "cannot create rootfs volume" @@ -190,7 +193,16 @@ nand_upgrade_prepare_ubi() { # create rootfs_data for non-ubifs rootfs if [ "$rootfs_type" != "ubifs" ]; then - if ! ubimkvol /dev/$ubidev -N rootfs_data -m; then + local availeb=$(cat /sys/devices/virtual/ubi/$ubidev/avail_eraseblocks) + local ebsize=$(cat /sys/devices/virtual/ubi/$ubidev/eraseblock_size) + local avail_size=$(( $availeb * $ebsize )) + local rootfs_data_size_param="-m" + if [ -n "$rootfs_data_max" ] && + [ "$rootfs_data_max" != "0" ] && + [ "$rootfs_data_max" -le "$avail_size" ]; then + rootfs_data_size_param="-s $rootfs_data_max" + fi + if ! ubimkvol /dev/$ubidev -N rootfs_data $rootfs_data_size_param; then echo "cannot initialize rootfs_data volume" return 1 fi |