// SPDX-License-Identifier: GPL-2.0 #define pr_fmt(fmt) "[rootfs] " fmt #include #include #include #include "avm_mtd_helper.h" static const char *rootfs_names[] = { "rootfs_ram", "rootfs", "filesystem" }; static void rootfs_add_notifier(struct mtd_info *mtd) { static int found_rootfs_idx = -1; int i; int match = 0; if (!mtd->name) return; for (i = 0; !match && i < ARRAY_SIZE(rootfs_names); i++) if (!strcmp(rootfs_names[i], mtd->name)) match = 1; if (!match && strstarts(mtd->name, "filesystem")) { u8 expected_fs, fs; expected_fs = prom_get_linux_fs(); if (!kstrtou8(mtd->name + strlen("filesystem"), 10, &fs)) { pr_debug("mtd %s: fs=%d expected=%d\n", mtd->name, fs, expected_fs); match = (fs == expected_fs); i = ARRAY_SIZE(rootfs_names) + 1; } else pr_warn("mtd %s does not end with an valid number\n", mtd->name); } if (!match) { pr_debug("mtd %s: not a rootfs\n", mtd->name); return; } if (found_rootfs_idx != -1 && found_rootfs_idx < i) { pr_debug( "mtd %s: lower priority than existing root dev, ignoring\n.", mtd->name); return; } pr_notice("use mtd%d (%s) as root\n", mtd->index, mtd->name); found_rootfs_idx = i; /* * Setting ROOT_DEV only works when CONFIG_BLOCK and CONFIG_MTD_BLOCK * is enabled. (The latter has the former as dependency). * * For some reason the old code had a fallback to emulate a "root=" * cmdline option. CONFIG_MTD_BLOCK is set on all qca products, but to * avoid surprises we complain here if needed. */ BUILD_BUG_ON(!IS_ENABLED(CONFIG_MTD_BLOCK)); ROOT_DEV = MKDEV(MTD_BLOCK_MAJOR, mtd->index); } static void rootfs_rm_notifier(struct mtd_info *mtd) { } struct mtd_notifier avm_mtd_rootfs_notifier = { .add = rootfs_add_notifier, .remove = rootfs_rm_notifier, };