--- zzzz-none-000/linux-5.4.213/init/do_mounts.c 2022-09-15 10:04:56.000000000 +0000 +++ miami-7690-761/linux-5.4.213/init/do_mounts.c 2024-05-29 11:20:02.000000000 +0000 @@ -313,7 +313,9 @@ } EXPORT_SYMBOL_GPL(name_to_dev_t); -static int __init root_dev_setup(char *line) +/* this isn't static anymore, as we need to have this function available for + * mtdram1= param parsing in our mtd code -PHU*/ +int __init root_dev_setup(char *line) { strlcpy(saved_root_name, line, sizeof(saved_root_name)); return 1; @@ -460,7 +462,30 @@ out: put_page(page); } - + +#ifdef CONFIG_MTD_ROOTFS_ROOT_DEV +static int __init mount_ubi_rootfs(void) +{ + int flags = MS_SILENT; + int err, tried = 0; + + while (tried < 2) { + err = do_mount_root("ubi0:rootfs", "ubifs", flags, \ + root_mount_data); + switch (err) { + case -EACCES: + flags |= MS_RDONLY; + tried++; + break; + default: + return err; + } + } + + return -EINVAL; +} +#endif + #ifdef CONFIG_ROOT_NFS #define NFSROOT_TIMEOUT_MIN 5 @@ -554,6 +579,10 @@ change_floppy("root floppy"); } #endif +#ifdef CONFIG_MTD_ROOTFS_ROOT_DEV + if (!mount_ubi_rootfs()) + return; +#endif #ifdef CONFIG_BLOCK { int err = create_dev("/dev/root", ROOT_DEV); @@ -605,12 +634,31 @@ goto out; /* wait for any asynchronous scanning to complete */ - if ((ROOT_DEV == 0) && root_wait) { + if ((ROOT_DEV == 0) && root_wait && saved_root_name[0]) { printk(KERN_INFO "Waiting for root device %s...\n", saved_root_name); while (driver_probe_done() != 0 || (ROOT_DEV = name_to_dev_t(saved_root_name)) == 0) msleep(5); + + async_synchronize_full(); + } else if (IS_ENABLED(CONFIG_MTD_ROOTFS_ROOT_DEV) && + (ROOT_DEV == 0) && root_wait) { + pr_info(KERN_INFO "Waiting for root device ...\n"); + /* + * Though MMC devices get detected before kernel + * reaches here, GPT partition table parsing happens + * later. Since we assume the GPT partition "rootfs", + * as the device to mount the Root FS from, the + * "root=xxx" command line option might not be + * present resulting in 'saved_root_name' being NULL. + * Hence, don't try to do 'name_to_dev_t' on it. + * Eventually, ROOT_DEV will get updated by the GPT + * parsing code and we will break out of this loop. + */ + while (driver_probe_done() != 0 || ROOT_DEV == 0) + msleep(100); + async_synchronize_full(); }