summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Kołtun2026-10-28 19:57:20 +0000
committerDaniel Golle2026-11-28 18:36:31 +0000
commitb5f65a44b78bb0e7af8819d0f1ebacb2137fce3c (patch)
tree06ad0de50762def7c6330374df2840517eb50d84
parent5e371ecfa7f6289db816b6ce07da5a039fb0a5c8 (diff)
block: skip probing UBI-backed NANDHEADmaster
When an MTD NAND device is already attached to UBI, probing it through mtdblock triggers a kernel warning recommending UBI block devices instead. Check /sys/class/ubi/ubiN/mtd_num to detect MTD devices managed by UBI and skip the mtdblock probe for those devices. Keep the existing rootfs and rootfs_data handling for NAND devices not attached to UBI, preserving compatibility with legacy layouts. Signed-off-by: Piotr Kołtun <pkoltun@op.pl>
-rw-r--r--block.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/block.c b/block.c
index e2e5c69..42e423f 100644
--- a/block.c
+++ b/block.c
@@ -609,6 +609,55 @@ static int config_load(char *cfg)
return 0;
}
+static bool mtd_is_attached_to_ubi(const char *mtdnum)
+{
+ DIR *dir;
+ struct dirent *entry;
+ char path[128];
+ char buf[32];
+ FILE *fp;
+ size_t i;
+ bool attached = false;
+
+ dir = opendir("/sys/class/ubi");
+ if (!dir)
+ return false;
+
+ while ((entry = readdir(dir)) != NULL) {
+ if (strncmp(entry->d_name, "ubi", 3) ||
+ !entry->d_name[3])
+ continue;
+
+ /* Accept ubiN device entries, but not ubiN_M volume entries. */
+ for (i = 3; entry->d_name[i]; i++) {
+ if (entry->d_name[i] < '0' ||
+ entry->d_name[i] > '9')
+ break;
+ }
+ if (entry->d_name[i])
+ continue;
+
+ snprintf(path, sizeof(path), "/sys/class/ubi/%s/mtd_num",
+ entry->d_name);
+ fp = fopen(path, "r");
+ if (!fp)
+ continue;
+
+ if (fgets(buf, sizeof(buf), fp)) {
+ buf[strcspn(buf, "\r\n")] = '\0';
+ if (!strcmp(buf, mtdnum))
+ attached = true;
+ }
+ fclose(fp);
+
+ if (attached)
+ break;
+ }
+
+ closedir(dir);
+ return attached;
+}
+
static bool mtdblock_is_nand(char *mtdnum)
{
char tmppath[64];
@@ -631,6 +680,10 @@ static bool mtdblock_is_nand(char *mtdnum)
if (strcmp(buf, "nand"))
return false;
+ /* Avoid probing NAND already managed by UBI. */
+ if (mtd_is_attached_to_ubi(mtdnum))
+ return true;
+
/*
* --- CUT HERE ---
* Keep probing rootfs and rootfs_data in the meantime to not break