Skip to contentSkip to conversation

mtd: nand: raw: rockchip_nfc: fix ecc setup

PATCH Superseded Johan Jonker 3 participants 3 messages Jul 12 – Jul 13

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: nand: raw: rockchip_nfc: fix ecc setup

The Rockchip boot ROM only checks for nand chip 0 and with reduced ecc strength. Currently only the read page functions have a condition check added. Fix by adding the same condition to all read and write page functions.

The NAND_IS_BOOT_MEDIUM option was introduced more recently then this driver. Use it to behave identical with the Linux driver.

Fixes b12dc5d6fa76 ("mtd: nand: NFC drivers for RK3308, RK2928 and others")
---
 drivers/mtd/nand/raw/rockchip_nfc.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/mtd/nand/raw/rockchip_nfc.c +8 -6
index ea8e67d1a23e..e788fda22a95 100644
@@ -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 ((chip->options & NAND_IS_BOOT_MEDIUM) &&
+	    (page < (pages_per_blk * rknand->boot_blks))) {
 		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 ((chip->options & NAND_IS_BOOT_MEDIUM) &&
+	    (page < (pages_per_blk * rknand->boot_blks))) {
 		boot_rom_mode = 1;
 		if (rknand->boot_ecc != ecc->strength)
 			rk_nfc_hw_ecc_setup(chip, rknand->boot_ecc);
Signature · 1 line
2.39.5
Tested-by on v1 1/1
#1 lore raw

Hi Johan,

Thanks for the patch.

This also fixes the bug, where you have an UBI layout spanning multiple chips. First scan after the creation will work fine, but after the device restart it ubi wont work anymore because the 2nd chip's first n boot blocks are written in different layout.

example nand config with 2 chip selects

nand@0 {
	reg = <0>, <2>;
	label = "rk-nand-0";
	nand-bus-width = <8>;
	nand-ecc-mode = "hw";
	nand-ecc-step-size = <1024>;
	nand-ecc-strength = <40>;
	nand-is-boot-medium;
	rockchip,boot-blks = <8>;
	rockchip,boot-ecc-strength = <24>;
}
Quoted 61 lines · Johan Jonker

The Rockchip boot ROM only checks for nand chip 0 and with reduced ecc strength. Currently only the read page functions have a condition check added. Fix by adding the same condition to all read and write page functions.

The NAND_IS_BOOT_MEDIUM option was introduced more recently then this driver. Use it to behave identical with the Linux driver.

Fixes b12dc5d6fa76 ("mtd: nand: NFC drivers for RK3308, RK2928 and others")
---
  drivers/mtd/nand/raw/rockchip_nfc.c | 14 ++++++++------
  1 file changed, 8 insertions(+), 6 deletions(-)
drivers/mtd/nand/raw/rockchip_nfc.c +8 -6
index ea8e67d1a23e..e788fda22a95 100644
@@ -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 ((chip->options & NAND_IS_BOOT_MEDIUM) &&
+	    (page < (pages_per_blk * rknand->boot_blks))) {
  		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 ((chip->options & NAND_IS_BOOT_MEDIUM) &&
+	    (page < (pages_per_blk * rknand->boot_blks))) {
  		boot_rom_mode = 1;
  		if (rknand->boot_ecc != ecc->strength)
  			rk_nfc_hw_ecc_setup(chip, rknand->boot_ecc);
Reviewed-by on v1 1/1
#2 lore raw
In reply to Johan Jonker

Hi Johan,

Quoted 15 lines · Johan Jonker

mtd: nand: raw: rockchip_nfc: fix ecc setup

The Rockchip boot ROM only checks for nand chip 0 and with reduced ecc strength. Currently only the read page functions have a condition check added. Fix by adding the same condition to all read and write page functions.

The NAND_IS_BOOT_MEDIUM option was introduced more recently then this driver. Use it to behave identical with the Linux driver.

Fixes b12dc5d6fa76 ("mtd: nand: NFC drivers for RK3308, RK2928 and others")
Quoted 6 lines

drivers/mtd/nand/raw/rockchip_nfc.c | 14 ++++++++------

 1 file changed, 8 insertions(+), 6 deletions(-)

The NAND_IS_BOOT_MEDIUM option was introduced more recently then this driver. Use it to behave identical with the Linux driver.

Typos: 'then' should be 'than', and 'identical' should be 'identically to'.

drivers/mtd/nand/raw/rockchip_nfc.c static int rk_nfc_read_page_raw(struct mtd_info *mtd, · line 627

Quoted 6 lines
drivers/mtd/nand/raw/rockchip_nfc.c +2 -2
@@ -624,8 +626,8 @@ static int rk_nfc_read_page_raw(struct mtd_info *mtd,
-     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)) &&

The commit message only mentions adding the condition to all read and write page functions, but this patch also drops the existing selected_bank == 0 check from both read functions, so chip-selects other than 0 on a boot-medium chip now get the boot ROM layout too. I suspect that is intentional (reads and writes must use the same layout), but it sits oddly with the first sentence, which stresses that the boot ROM only checks chip 0. Please can you mention this in the commit message and explain why it is correct?

These are just wording changes, so:

Regards,
Simon