[PATCH] base-files: pad root.squashfs to 64KiB in ubi volumes

Christian Lamparter chunkeey at gmail.com
Sat Aug 24 06:55:40 EDT 2019


SquashFS's HOWTO states in the section "Using mksquashfs"
<https://elinux.org/Squash_FS_Howto#Using_mksquashfs>
that a padding is necessary "for the filesystem to be used
on block devices."

OpenWrt's mksquashfs for the rootfs (which is usually
squashfs) is instructed to skip the padding via the nopad
option because the rootfs will be padded by functions like
pad-rootfs to the eraseblocksize which is usually much
bigger at somewhere 64KiB.

But this is a problem for squashfs as rootfs in ubi
partitions. Currently no explicit padding is being
set and it currently works for the most time because
ubi volumes are always aligned to LEBs which could
be close enough for 4KiB paddings...

Digging down deeper revealed that squashfs excepts blocks
to be up to PAGE_SIZE. This is explained in this bug report
that states that the 4k padding for ARCHs with 64KiB pages
resulted in "attempt access beyond end of device" errors:
<https://sourceforge.net/p/squashfs/mailman/message/28307755/>

This patch changes sysupgrade to follow fstools with its
ROOTDEV_OVERLAY_ALIGN (=64KiB) and aligns squashfs rootfs
filesystem to the same amount, while also changing the
ubinize script to apply the alignment in the same manner.
(More additions would be welcome. Note: ubinize and
ubimkvol don't support alignment values that are bigger
than a LEB!)

Reported-by: Russell Senior <russell at personaltelco.net>
Signed-off-by: Christian Lamparter <chunkeey at gmail.com>
---
 package/base-files/files/lib/upgrade/nand.sh | 12 +++++++++---
 scripts/ubinize-image.sh                     | 12 +++++++++++-
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/package/base-files/files/lib/upgrade/nand.sh b/package/base-files/files/lib/upgrade/nand.sh
index fbc2b5c19a..7eb9632a06 100644
--- a/package/base-files/files/lib/upgrade/nand.sh
+++ b/package/base-files/files/lib/upgrade/nand.sh
@@ -174,11 +174,17 @@ nand_upgrade_prepare_ubi() {
 
 	# update rootfs
 	local root_size_param
-	if [ "$rootfs_type" = "ubifs" ]; then
+	case "$rootfs_type" in
+	"squashfs")
+		root_size_param="-s $(( ($rootfs_length + 65535) & ~65535))"
+		;;
+	"ubifs")
 		root_size_param="-m"
-	else
+		;;
+	*)
 		root_size_param="-s $rootfs_length"
-	fi
+		;;
+	esac
 	if ! ubimkvol /dev/$ubidev -N $CI_ROOTPART $root_size_param; then
 		echo "cannot create rootfs volume"
 		return 1;
diff --git a/scripts/ubinize-image.sh b/scripts/ubinize-image.sh
index a18d6dc428..06f4a3b995 100755
--- a/scripts/ubinize-image.sh
+++ b/scripts/ubinize-image.sh
@@ -18,6 +18,12 @@ is_ubifs() {
 	fi
 }
 
+is_squashfs() {
+	if [ "$( get_magic_word "$1" )" = "6873" ]; then
+		echo "1"
+	fi
+}
+
 ubivol() {
 	volid=$1
 	name=$2
@@ -69,7 +75,11 @@ ubilayout() {
 		ubivol $vol_id kernel "$3"
 		vol_id=$(( $vol_id + 1 ))
 	fi
-	ubivol $vol_id rootfs "$2" $root_is_ubifs
+	size=""
+	if [ -n "$( is_squashfs "$2" )" ]; then
+		size=$(( ($(wc -c < "$2") + 65535) & ~65535))
+	fi
+	ubivol $vol_id rootfs "$2" "$root_is_ubifs" "$size"
 	vol_id=$(( $vol_id + 1 ))
 	[ "$root_is_ubifs" ] || ubivol $vol_id rootfs_data "" 1
 }
-- 
2.23.0




---




_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list