--- zzzz-none-000/linux-4.9.276/drivers/mtd/ubi/gluebi.c 2021-07-20 14:21:16.000000000 +0000 +++ falcon-5530-750/linux-4.9.276/drivers/mtd/ubi/gluebi.c 2023-04-05 08:19:01.000000000 +0000 @@ -38,6 +38,9 @@ #include #include #include +#ifdef CONFIG_MTD_UBI_GLUEBI_ROOTFS_DEV +#include +#endif #include "ubi-media.h" #define err_msg(fmt, ...) \ @@ -66,6 +69,27 @@ static LIST_HEAD(gluebi_devices); static DEFINE_MUTEX(devices_mutex); +#ifdef CONFIG_MTD_UBI_GLUEBI_ROOTFS_DEV +/* Buffers to read kernel command line */ +extern char *saved_command_line; +char *rootfsmtd_ptr; +char command_line_buf[64]; +#define ROOTFS_CMDLINE "rootfsname=" + +/* + * gluebi_read_cmdline - read kernel command line and get value of 'rootfsname' + * return: 0 + */ +static void __init gluebi_read_cmdline(void) +{ + rootfsmtd_ptr = strstr(saved_command_line, ROOTFS_CMDLINE); + if (rootfsmtd_ptr) { + sscanf(rootfsmtd_ptr, ROOTFS_CMDLINE "%s", command_line_buf); + printk("Gluebi: Found kernel commandline option 'rootfsname=%s'\n", command_line_buf); + } +} +#endif + /** * find_gluebi_nolock - find a gluebi device. * @ubi_num: UBI device number @@ -347,6 +371,16 @@ return -ENFILE; } +#ifdef CONFIG_MTD_UBI_GLUEBI_ROOTFS_DEV + if (rootfsmtd_ptr) { + if (!strcmp(mtd->name, command_line_buf)) { + ROOT_DEV = MKDEV(MTD_BLOCK_MAJOR, mtd->index); + printk("Gluebi: mtd '%s' set to be root filesystem\n", mtd->name); + printk("rootdev: 0x%08x, mtd block: %08x, mtd index: %08x\n", ROOT_DEV, MTD_BLOCK_MAJOR, mtd->index); + } + } +#endif + mutex_lock(&devices_mutex); list_add_tail(&gluebi->list, &gluebi_devices); mutex_unlock(&devices_mutex); @@ -487,6 +521,9 @@ static int __init ubi_gluebi_init(void) { +#ifdef CONFIG_MTD_UBI_GLUEBI_ROOTFS_DEV + gluebi_read_cmdline(); +#endif return ubi_register_volume_notifier(&gluebi_notifier, 0); }