]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
mtd: nand: raw: rockchip_nfc: fix ecc setup
authorJohan Jonker <jbx6244@gmail.com>
Thu, 23 Jul 2026 15:22:59 +0000 (17:22 +0200)
committerQuentin Schulz <u-boot@0leil.net>
Thu, 23 Jul 2026 15:43:33 +0000 (17:43 +0200)
A Rockchip NAND Flash Controller (NFC) supports multiple
flash devices. The SoC boot ROM only checks for NAND chip 0
and with reduced ECC strength. Currently only the read page
functions have this condition check added in the U-Boot
driver.

In single- and multi-chip nodes with rockchip,boot-blks and
rockchip,boot-ecc-strength set, the chips that aren't chip 0
will thus have an ECC mismatch when writing and reading.

Fix by adding the same condition to all read and write page
functions by dropping the existing 'selected_bank == 0' check
and use the NAND_IS_BOOT_MEDIUM option that was introduced to
U-Boot more recently than this driver to behave
identically to the Linux driver.

NAND_IS_BOOT_MEDIUM is automatically set when nand-is-boot-medium
property is set in the Device Tree, which is a requirement for
rockchip,boot-blks and rockchip,boot-ecc-strength and will thus
apply to all chips in single- and multi-chips nodes, regardless
of the CS.

Fixes: b12dc5d6fa76 ("mtd: nand: NFC drivers for RK3308, RK2928 and others")
Signed-off-by: Johan Jonker <jbx6244@gmail.com>
Tested-by: Hüseyin BIYIK <boogiepop@gmx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Quentin Schulz <quentin.schulz@cherry.de>
Link: https://patch.msgid.link/5690db1e-4de5-44bc-a9c0-58ad23662753@gmail.com
Signed-off-by: Quentin Schulz <u-boot@0leil.net>
drivers/mtd/nand/raw/rockchip_nfc.c

index ea8e67d1a23ef1a85072ec6dd837fb25f8830559..d23a651f369226c8e7ee67c16544377be4118367 100644 (file)
@@ -440,7 +440,8 @@ static int rk_nfc_write_page_raw(struct mtd_info *mtd,
        int i, pages_per_blk;
 
        pages_per_blk = mtd->erasesize / mtd->writesize;
-       if ((page < (pages_per_blk * rknand->boot_blks)) &&
+       if ((chip->options & NAND_IS_BOOT_MEDIUM) &&
+           (page < (pages_per_blk * rknand->boot_blks)) &&
            rknand->boot_ecc != ecc->strength) {
                /*
                 * There's currently no method to notify the MTD framework that
@@ -560,7 +561,8 @@ static int rk_nfc_write_page_hwecc(struct mtd_info *mtd,
         *
         * Configure the ECC algorithm supported by the boot ROM.
         */
-       if (page < (pages_per_blk * rknand->boot_blks)) {
+       if ((page < (pages_per_blk * rknand->boot_blks)) &&
+           (chip->options & NAND_IS_BOOT_MEDIUM)) {
                boot_rom_mode = 1;
                if (rknand->boot_ecc != ecc->strength)
                        rk_nfc_hw_ecc_setup(chip, rknand->boot_ecc);
@@ -624,8 +626,8 @@ static int rk_nfc_read_page_raw(struct mtd_info *mtd,
        int i, pages_per_blk;
 
        pages_per_blk = mtd->erasesize / mtd->writesize;
-       if ((page < (pages_per_blk * rknand->boot_blks)) &&
-           nfc->selected_bank == 0 &&
+       if ((chip->options & NAND_IS_BOOT_MEDIUM) &&
+           (page < (pages_per_blk * rknand->boot_blks)) &&
            rknand->boot_ecc != ecc->strength) {
                /*
                 * There's currently no method to notify the MTD framework that
@@ -700,8 +702,8 @@ static int rk_nfc_read_page_hwecc(struct mtd_info *mtd,
         * are used by the boot ROM.
         * Configure the ECC algorithm supported by the boot ROM.
         */
-       if (page < (pages_per_blk * rknand->boot_blks) &&
-           nfc->selected_bank == 0) {
+       if ((page < (pages_per_blk * rknand->boot_blks)) &&
+           (chip->options & NAND_IS_BOOT_MEDIUM)) {
                boot_rom_mode = 1;
                if (rknand->boot_ecc != ecc->strength)
                        rk_nfc_hw_ecc_setup(chip, rknand->boot_ecc);