diff mbox series

[v2] ubivol_handler: keep ubi volume ids stable on resize

Message ID VE1P194MB0830DF5C72C53DC3B1469AF2D7882@VE1P194MB0830.EURP194.PROD.OUTLOOK.COM
State Accepted
Headers show
Series [v2] ubivol_handler: keep ubi volume ids stable on resize | expand

Commit Message

Hannes Weisbach Aug. 23, 2024, 12:39 p.m. UTC
UBI volume resizing is implemented by deleting and (re-)creating a volume. If the volume previously existed, its type (static or dynamic) is copied over, however its volume ID is lost.
This can be a problem in case a block device is required for an UBI volume, for example when using squashfs. In case of squashfs first a block device has to be created with the kernel commandline parameter ubi.block=<ubi-device>,<volume name>. Then root=/dev/ubiblock<x>_<y> has to be set with UBI device ID as x and UBI volume ID as y. The root=<ubi device>:<volume-name>-syntax as used by ubifs cannot be used.
Changing volume IDs in turn require the bootloader to potentially modify the kernel command line after each rootfs update/resize.

Signed-off-by: Hannes Weisbach <weisbach@neosat.de>
---
 handlers/ubivol_handler.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/handlers/ubivol_handler.c b/handlers/ubivol_handler.c
index bf1ec00a..7ea4a6f9 100644
--- a/handlers/ubivol_handler.c
+++ b/handlers/ubivol_handler.c
@@ -310,6 +310,7 @@  static int resize_volume(struct img_type *cfg, long long size)
 	struct ubi_mkvol_request req;
 	struct mtd_ubi_info *mtd_info;
 	int mtdnum, req_vol_type;
+	int req_vol_id = UBI_VOL_NUM_AUTO;
 	char node[64];
 	int err;
 	struct flash_description *flash = get_flash_info();
@@ -371,6 +372,7 @@  static int resize_volume(struct img_type *cfg, long long size)
 		}
 
 		snprintf(node, sizeof(node), "/dev/ubi%d", ubivol->vol_info.dev_num);
+		req_vol_id = ubivol->vol_info.vol_id;
 		err = ubi_rmvol(nandubi->libubi, node, ubivol->vol_info.vol_id);
 		if (err) {
 			ERROR("Volume %s cannot be dropped", ubivol->vol_info.name);
@@ -392,7 +394,7 @@  static int resize_volume(struct img_type *cfg, long long size)
 		 */
 		memset(&req, 0, sizeof(req));
 		req.vol_type = req_vol_type;
-		req.vol_id = UBI_VOL_NUM_AUTO;
+		req.vol_id = req_vol_id;
 		req.alignment = 1;
 		req.bytes = size;
 		req.name = cfg->volname;