0
0
mirror of https://git.openwrt.org/openwrt/openwrt.git synced 2025-05-22 14:17:55 +00:00
Files
openwrt/target/linux/generic/pending-6.12/490-ubi-auto-attach-mtd-device-named-ubi-or-data-on-boot.patch
Mieczyslaw Nalewaj be6753dda0 generic: 6.12: manually rebuild pending patches
Manually rebuild pending patches:
 - 103-kbuild-export-SUBARCH.patch
 - 141-jffs2-add-RENAME_EXCHANGE-support.patch
 - 200-ARM-9404-1-arm32-fix-boot-hang-with-HAVE_LD_DEAD_COD.patch
 - 203-kallsyms_uncompressed.patch
 - 270-platform-mikrotik-build-bits.patch
 - 308-mips32r2_tune.patch
 - 330-MIPS-kexec-Accept-command-line-parameters-from-users.patch
 - 402-mtd-spi-nor-write-support-for-minor-aligned-partitions.patch
 - 451-block-partitions-populate-fwnode.patch
 - 476-mtd-spi-nor-add-eon-en25q128.patch
 - 477-mtd-spi-nor-add-eon-en25qx128a.patch
 - 479-mtd-spi-nor-add-xtx-xt25f128b.patch
 - 481-mtd-spi-nor-add-support-for-Gigadevice-GD25D05.patch
 - 482-mtd-spi-nor-add-gd25q512.patch
 - 484-mtd-spi-nor-add-esmt-f25l16pa.patch
 - 485-mtd-spi-nor-add-xmc-xm25qh128c.patch
 - 488-mtd-spi-nor-add-xmc-xm25qh64c.patch
 - 490-ubi-auto-attach-mtd-device-named-ubi-or-data-on-boot.patch
 - 497-mtd-mtdconcat-add-dt-driver-for-concat-devices.patch
 - 498-mtd-spi-nor-locking-support-for-MX25L6405D.patch
 - 510-block-add-uImage.FIT-subimage-block-driver.patch
 - 530-jffs2_make_lzma_available.patch
 - 630-packet_socket_type.patch
 - 666-Add-support-for-MAP-E-FMRs-mesh-mode.patch
 - 681-net-remove-NETIF_F_GSO_FRAGLIST-from-NETIF_F_GSO_SOF.patch
 - 700-netfilter-nft_flow_offload-handle-netdevice-events-f.patch
 - 702-net-ethernet-mtk_eth_soc-enable-threaded-NAPI.patch
 - 706-net-phy-populate-host_interfaces-when-attaching-PHY.patch
 - 711-03-net-dsa-qca8k-add-support-for-port_change_master.patch
 - 734-net-ethernet-mediatek-enlarge-DMA-reserve-buffer.patch
 - 736-03-net-ethernet-mtk_eth_soc-improve-keeping-track-of-of.patch
 - 737-net-ethernet-mtk_eth_soc-add-paths-and-SerDes-modes-.patch
 - 739-03-net-pcs-pcs-mtk-lynxi-add-platform-driver-for-MT7988.patch
 - 801-gpio-gpio-cascade-add-generic-GPIO-cascade.patch
 - 809-01-nvmem-core-generalize-mac-base-cells-handling.patch
 - 811-pci_disable_usb_common_quirks.patch
 - 834-ledtrig-libata.patch
 - 892-leds-Add-LED1202-I2C-driver.patch
 - 920-mangle_bootargs.patch

Co-authored-by: Aditya Nugraha <vortexilation@gmail.com>
Signed-off-by: Mieczyslaw Nalewaj <namiltd@yahoo.com>
[ improve commit title + minor fixes ]
Link: https://github.com/openwrt/openwrt/pull/16547
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
2025-04-30 16:26:31 +02:00

105 lines
2.6 KiB
Diff

From: Daniel Golle <daniel@makrotopia.org>
Subject: ubi: auto-attach mtd device named "ubi" or "data" on boot
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
drivers/mtd/ubi/build.c | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -1263,6 +1263,80 @@ static struct mtd_notifier ubi_mtd_notif
.remove = ubi_notify_remove,
};
+
+/*
+ * This function tries attaching mtd partitions named either "ubi" or "data"
+ * during boot.
+ */
+static void __init ubi_auto_attach(void)
+{
+ int err;
+ struct mtd_info *mtd;
+ struct device_node *np;
+ loff_t offset = 0;
+ size_t len;
+ char magic[4];
+
+ /* try attaching mtd device named "ubi" or "data" */
+ mtd = open_mtd_device("ubi");
+ if (IS_ERR(mtd))
+ mtd = open_mtd_device("data");
+
+ if (IS_ERR(mtd))
+ return;
+
+ /* skip "linux,ubi" mtd as it has already been attached */
+ np = mtd_get_of_node(mtd);
+ if (of_device_is_compatible(np, "linux,ubi"))
+ goto cleanup;
+
+ /* get the first not bad block */
+ if (mtd_can_have_bb(mtd))
+ while (mtd_block_isbad(mtd, offset)) {
+ offset += mtd->erasesize;
+
+ if (offset > mtd->size) {
+ pr_err("UBI error: Failed to find a non-bad "
+ "block on mtd%d\n", mtd->index);
+ goto cleanup;
+ }
+ }
+
+ /* check if the read from flash was successful */
+ err = mtd_read(mtd, offset, 4, &len, (void *) magic);
+ if ((err && !mtd_is_bitflip(err)) || len != 4) {
+ pr_err("UBI error: unable to read from mtd%d\n", mtd->index);
+ goto cleanup;
+ }
+
+ /* check for a valid ubi magic */
+ if (strncmp(magic, "UBI#", 4)) {
+ pr_err("UBI error: no valid UBI magic found inside mtd%d\n", mtd->index);
+ goto cleanup;
+ }
+
+ /* don't auto-add media types where UBI doesn't makes sense */
+ if (mtd->type != MTD_NANDFLASH &&
+ mtd->type != MTD_NORFLASH &&
+ mtd->type != MTD_DATAFLASH &&
+ mtd->type != MTD_MLCNANDFLASH)
+ goto cleanup;
+
+ mutex_lock(&ubi_devices_mutex);
+ pr_notice("UBI: auto-attach mtd%d\n", mtd->index);
+ err = ubi_attach_mtd_dev(mtd, UBI_DEV_NUM_AUTO, 0, 0, false, false);
+ mutex_unlock(&ubi_devices_mutex);
+ if (err < 0) {
+ pr_err("UBI error: cannot attach mtd%d\n", mtd->index);
+ goto cleanup;
+ }
+
+ return;
+
+cleanup:
+ put_mtd_device(mtd);
+}
+
static int __init ubi_init_attach(void)
{
int err, i, k;
@@ -1314,6 +1388,12 @@ static int __init ubi_init_attach(void)
}
}
+ /* auto-attach mtd devices only if built-in to the kernel and no ubi.mtd
+ * parameter was given */
+ if (IS_ENABLED(CONFIG_MTD_ROOTFS_ROOT_DEV) &&
+ !ubi_is_module() && !mtd_devs)
+ ubi_auto_attach();
+
return 0;
out_detach: