Skip to content

Instantly share code, notes, and snippets.

@naseef
Created February 6, 2026 06:26
Show Gist options
  • Select an option

  • Save naseef/aa6890b30e48fb02adc8884f8447f6b3 to your computer and use it in GitHub Desktop.

Select an option

Save naseef/aa6890b30e48fb02adc8884f8447f6b3 to your computer and use it in GitHub Desktop.
422-mtd-nand-realtek-ecc-support-oob-size-override.patch
mtd: nand: realtek-ecc: support OOB size override from device tree
Some NAND chips have a physical OOB size larger than what vendor
firmware actually uses for its ECC layout. For example the Macronix
MX35LF1G24AD found in Netlink HG323DAC has 128 byte OOB but vendor
firmware only uses the first 64 bytes for the BCH6 ECC layout. The
Realtek ECC engine strictly validates flash geometry against its
supported configuration which causes probe failure on these chips.
Add support for a "realtek,ecc-oob-size" device tree property on the
NAND flash node. When present, the ECC engine uses this value instead
of the flash-reported OOB size for its geometry validation. This
allows per-device opt-in after the OOB layout has been verified
against vendor firmware, without weakening the check for unverified
chips.
Signed-off-by: Ahmed Naseef <naseefkm@gmail.com>
--- a/drivers/mtd/nand/ecc-realtek.c
+++ b/drivers/mtd/nand/ecc-realtek.c
@@ -7,6 +7,7 @@
#include <linux/dma-mapping.h>
#include <linux/mtd/nand.h>
#include <linux/mutex.h>
+#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/regmap.h>
@@ -309,8 +310,23 @@ static int rtl_ecc_check_support(struct
{
struct mtd_info *mtd = nanddev_to_mtd(nand);
struct device *dev = nand->ecc.engine->dev;
+ struct device_node *np = mtd->dev.parent->of_node;
+ int oobsize = mtd->oobsize;
+ u32 val;
- if (mtd->oobsize != RTL_ECC_ALLOWED_OOB_SIZE ||
+ /*
+ * Allow per-device override of the OOB size used for the geometry
+ * check. Some NAND chips have a physical OOB size larger than what
+ * the vendor firmware actually uses for its ECC layout. For example
+ * the Macronix MX35LF1G24AD has 128 byte OOB but vendor firmware
+ * only uses the first 64 bytes for the BCH6 ECC layout. This
+ * property should only be set after verifying the actual on-flash
+ * ECC layout matches the engine's expectations.
+ */
+ if (np && !of_property_read_u32(np, "realtek,ecc-oob-size", &val))
+ oobsize = val;
+
+ if (oobsize != RTL_ECC_ALLOWED_OOB_SIZE ||
mtd->writesize != RTL_ECC_ALLOWED_PAGE_SIZE) {
dev_err(dev, "only flash geometry data=%d, oob=%d supported\n",
RTL_ECC_ALLOWED_PAGE_SIZE, RTL_ECC_ALLOWED_OOB_SIZE);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment