Skip to contentSkip to conversation

Meson: R/W support for pages used by boot ROM

PATCH Superseded Arseniy Krasnov 3 participants 7 messages Apr 8, 2024 – Apr 9, 2024

Subsystems (5)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 cover Meson: R/W support for pages used by boot ROM

Amlogic's boot ROM code needs that some pages on NAND must be written in special "short" ECC mode with scrambling enabled. Such pages:
1) Contain some metadata about hardware.
2) Located with some interval starting from 0 offset, until some specified offset. Interval and second offset are set in the device tree.

This patchset adds R/W support for such pages. To enable it we can setup it in dts:

    nand-is-boot-medium;
    amlogic,boot-page-last = <1024>;
    amlogic,boot-page-step = <128>;

It means that each 128th page in range 0 to 1024 pages will be accessed in special mode ("short" ECC + scrambling). In practice this feature is needed when we want to update first block of NAND - driver will enable required mode by itself using value from device tree.

Changelog:
v1 -> v2:
* Rename 'meson,boot-page-XXX' -> 'amlogic,boot-page-XXX'.
* Add words that 'amlogic,boot-page-step' is measured in pages.
* Remove words that 'amlogic,boot-page-XXX' depends on 'nand-is-boot-medium'.
* Make both 'amlogic,boot-page-XXX' depend on each other also, in addition to 'nand-is-boot-medium' dependency.

Arseniy Krasnov (2):
dt-bindings: mtd: amlogic,meson-nand: support fields for boot ROM code
mtd: rawnand: meson: support R/W mode for boot ROM

 .../bindings/mtd/amlogic,meson-nand.yaml      | 14 +++
 drivers/mtd/nand/raw/meson_nand.c             | 88 +++++++++++++------
 2 files changed, 73 insertions(+), 29 deletions(-)
Signature · 1 line
2.35.0
#1 lore raw

PATCH v2 1/2 dt-bindings: mtd: amlogic,meson-nand: support fields for boot ROM code

Boot ROM code on Meson requires that some pages on NAND must be written in special mode: "short" ECC mode where each block is 384 bytes and scrambling mode is on. Such pages located with the specified interval within specified offset. Both interval and offset are located in the device tree and used by driver if 'nand-is-boot-medium' is set for NAND chip.

---
 .../bindings/mtd/amlogic,meson-nand.yaml           | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
Documentation/devicetree/bindings/mtd/amlogic,meson-nand.yaml +14 -0
index 57b6957c8415..80ba5003ca70 100644
@@ -64,11 +64,25 @@ patternProperties:
         items:
           maximum: 0
 
+      amlogic,boot-page-last:
+        $ref: /schemas/types.yaml#/definitions/uint32
+        description:
+          The NFC driver needs this information to select ECC
+          algorithms supported by the boot ROM.
+
+      amlogic,boot-page-step:
+        $ref: /schemas/types.yaml#/definitions/uint32
+        description:
+          The NFC driver needs this information to select ECC
+          algorithms supported by the boot ROM (in pages).
+
     unevaluatedProperties: false
 
     dependencies:
       nand-ecc-strength: [nand-ecc-step-size]
       nand-ecc-step-size: [nand-ecc-strength]
+      amlogic,boot-page-last: [nand-is-boot-medium, amlogic,boot-page-step]
+      amlogic,boot-page-step: [nand-is-boot-medium, amlogic,boot-page-last]
 
 
 required:
Signature · 1 line
2.35.0
#2 lore raw

Re: [PATCH v2 1/2] dt-bindings: mtd: amlogic,meson-nand: support fields for boot ROM code

kernel test robot noticed the following build warnings:

Hi Arseniy,

kernel test robot noticed the following build warnings:

[auto build test WARNING on mtd/mtd/next]
[also build test WARNING on mtd/mtd/fixes mtd/nand/next robh/for-next linus/master v6.9-rc3 next-20240408] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Arseniy-Krasnov/dt-bindings-mtd-amlogic-meson-nand-support-fields-for-boot-ROM-code/20240408-171119
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next
patch link:    https://lore.kernel.org/r/20240408085931.456337-2-avkrasnov%40salutedevices.com
patch subject: [PATCH v2 1/2] dt-bindings: mtd: amlogic,meson-nand: support fields for boot ROM code
compiler: loongarch64-linux-gcc (GCC) 13.2.0
reproduce: (https://download.01.org/0day-ci/archive/20240409/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

dtcheck warnings: (new ones prefixed by >>)

>> Documentation/devicetree/bindings/mtd/amlogic,meson-nand.yaml:84:61: [warning] too few spaces after comma (commas)

Documentation/devicetree/bindings/mtd/amlogic,meson-nand.yaml:85:61: [warning] too few spaces after comma (commas)

vim +84 Documentation/devicetree/bindings/mtd/amlogic,meson-nand.yaml

     8	
     9	allOf:
    10	  - $ref: nand-controller.yaml
    11	
    12	maintainers:
    13	  - [email protected]
    14	
    15	properties:
    16	  compatible:
    17	    enum:
    18	      - amlogic,meson-gxl-nfc
    19	      - amlogic,meson-axg-nfc
    20	
    21	  reg:
    22	    maxItems: 2
    23	
    24	  reg-names:
    25	    items:
    26	      - const: nfc
    27	      - const: emmc
    28	
    29	  interrupts:
    30	    maxItems: 1
    31	
    32	  clocks:
    33	    minItems: 2
    34	
    35	  clock-names:
    36	    items:
    37	      - const: core
    38	      - const: device
    39	
    40	patternProperties:
    41	  "^nand@[0-7]$":
    42	    type: object
    43	    $ref: raw-nand-chip.yaml
    44	    properties:
    45	      reg:
    46	        minimum: 0
    47	        maximum: 1
    48	
    49	      nand-ecc-mode:
    50	        const: hw
    51	
    52	      nand-ecc-step-size:
    53	        enum: [512, 1024]
    54	
    55	      nand-ecc-strength:
    56	        enum: [8, 16, 24, 30, 40, 50, 60]
    57	        description: |
    58	          The ECC configurations that can be supported are as follows.
    59	            meson-gxl-nfc 8, 16, 24, 30, 40, 50, 60
    60	            meson-axg-nfc 8
    61	
    62	      nand-rb:
    63	        maxItems: 1
    64	        items:
    65	          maximum: 0
    66	
    67	      amlogic,boot-page-last:
    68	        $ref: /schemas/types.yaml#/definitions/uint32
    69	        description:
    70	          The NFC driver needs this information to select ECC
    71	          algorithms supported by the boot ROM.
    72	
    73	      amlogic,boot-page-step:
    74	        $ref: /schemas/types.yaml#/definitions/uint32
    75	        description:
    76	          The NFC driver needs this information to select ECC
    77	          algorithms supported by the boot ROM (in pages).
    78	
    79	    unevaluatedProperties: false
    80	
    81	    dependencies:
    82	      nand-ecc-strength: [nand-ecc-step-size]
    83	      nand-ecc-step-size: [nand-ecc-strength]
  > 84	      amlogic,boot-page-last: [nand-is-boot-medium, amlogic,boot-page-step]
    85	      amlogic,boot-page-step: [nand-is-boot-medium, amlogic,boot-page-last]
    86	
    87	
    88	required:
    89	  - compatible
    90	  - reg
    91	  - interrupts
    92	  - clocks
    93	  - clock-names
    94	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
maintainer
#3 lore raw

Re: [PATCH v2 1/2] dt-bindings: mtd: amlogic,meson-nand: support fields for boot ROM code

In reply to Arseniy Krasnov
Quoted 7 lines · Arseniy Krasnov

Boot ROM code on Meson requires that some pages on NAND must be written in special mode: "short" ECC mode where each block is 384 bytes and scrambling mode is on. Such pages located with the specified interval within specified offset. Both interval and offset are located in the device tree and used by driver if 'nand-is-boot-medium' is set for NAND chip.

Quoted 5 lines
---
 .../bindings/mtd/amlogic,meson-nand.yaml           | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:
./Documentation/devicetree/bindings/mtd/amlogic,meson-nand.yaml:84:61: [warning] too few spaces after comma (commas) ./Documentation/devicetree/bindings/mtd/amlogic,meson-nand.yaml:85:61: [warning] too few spaces after comma (commas)

dtschema/dtc warnings/errors:

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]

The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.

maintainer
#4 lore raw

Re: [PATCH v2 1/2] dt-bindings: mtd: amlogic,meson-nand: support fields for boot ROM code

In reply to Arseniy Krasnov
Quoted 29 lines · Arseniy Krasnov

Boot ROM code on Meson requires that some pages on NAND must be written in special mode: "short" ECC mode where each block is 384 bytes and scrambling mode is on. Such pages located with the specified interval within specified offset. Both interval and offset are located in the device tree and used by driver if 'nand-is-boot-medium' is set for NAND chip.

---
 .../bindings/mtd/amlogic,meson-nand.yaml           | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
Documentation/devicetree/bindings/mtd/amlogic,meson-nand.yaml +9 -0
index 57b6957c8415..80ba5003ca70 100644
@@ -64,11 +64,25 @@ patternProperties:
         items:
           maximum: 0
 
+      amlogic,boot-page-last:
+        $ref: /schemas/types.yaml#/definitions/uint32
+        description:
+          The NFC driver needs this information to select ECC
+          algorithms supported by the boot ROM.
+
+      amlogic,boot-page-step:
+        $ref: /schemas/types.yaml#/definitions/uint32
+        description:

Documentation/devicetree/bindings/mtd/amlogic,meson-nand.yaml patternProperties: · line 85

Quoted 10 lines
Documentation/devicetree/bindings/mtd/amlogic,meson-nand.yaml +5 -0
+          The NFC driver needs this information to select ECC
+          algorithms supported by the boot ROM (in pages).
+
     unevaluatedProperties: false
 
     dependencies:
       nand-ecc-strength: [nand-ecc-step-size]
       nand-ecc-step-size: [nand-ecc-strength]
+      amlogic,boot-page-last: [nand-is-boot-medium, amlogic,boot-page-step]
+      amlogic,boot-page-step: [nand-is-boot-medium, amlogic,boot-page-last]

You need quotes if using the inline syntax.

Rob

#5 lore raw

Re: [PATCH v2 1/2] dt-bindings: mtd: amlogic,meson-nand: support fields for boot ROM code

Quoted 35 lines · Rob Herring
Quoted 34 lines · Arseniy Krasnov

Boot ROM code on Meson requires that some pages on NAND must be written in special mode: "short" ECC mode where each block is 384 bytes and scrambling mode is on. Such pages located with the specified interval within specified offset. Both interval and offset are located in the device tree and used by driver if 'nand-is-boot-medium' is set for NAND chip.

---
 .../bindings/mtd/amlogic,meson-nand.yaml           | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
Documentation/devicetree/bindings/mtd/amlogic,meson-nand.yaml +12 -0
index 57b6957c8415..80ba5003ca70 100644
@@ -64,11 +64,25 @@ patternProperties:
         items:
           maximum: 0
 
+      amlogic,boot-page-last:
+        $ref: /schemas/types.yaml#/definitions/uint32
+        description:
+          The NFC driver needs this information to select ECC
+          algorithms supported by the boot ROM.
+
+      amlogic,boot-page-step:
+        $ref: /schemas/types.yaml#/definitions/uint32
+        description:
+          The NFC driver needs this information to select ECC
+          algorithms supported by the boot ROM (in pages).
+
     unevaluatedProperties: false
 
Quoted 7 lines

Documentation/devicetree/bindings/mtd/amlogic,meson-nand.yaml patternProperties: · line 85

Quoted 5 lines
Documentation/devicetree/bindings/mtd/amlogic,meson-nand.yaml +2 -0
     dependencies:
       nand-ecc-strength: [nand-ecc-step-size]
       nand-ecc-step-size: [nand-ecc-strength]
+      amlogic,boot-page-last: [nand-is-boot-medium, amlogic,boot-page-step]
+      amlogic,boot-page-step: [nand-is-boot-medium, amlogic,boot-page-last]

You need quotes if using the inline syntax.

IIUC it must look like this:

amlogic,boot-page-last: [nand-is-boot-medium, "amlogic,boot-page-step"]

etc.

Quoted 2 lines

Rob

#6 lore raw

PATCH v2 2/2 mtd: rawnand: meson: support R/W mode for boot ROM

In reply to Arseniy Krasnov

Boot ROM code on Meson requires that some pages on NAND must be written in special mode: "short" ECC mode where each block is 384 bytes and scrambling mode is on. Such pages located with the specified interval within specified offset. Both interval and offset are located in the device tree and used by driver if 'nand-is-boot-medium' is set for NAND chip.

---
 drivers/mtd/nand/raw/meson_nand.c | 88 +++++++++++++++++++++----------
 1 file changed, 59 insertions(+), 29 deletions(-)
drivers/mtd/nand/raw/meson_nand.c +59 -29
index 00ce0e5bb970..b68aac24af16 100644
@@ -35,6 +35,7 @@
 #define NFC_CMD_RB		BIT(20)
 #define NFC_CMD_SCRAMBLER_ENABLE	BIT(19)
 #define NFC_CMD_SCRAMBLER_DISABLE	0
+#define NFC_CMD_SHORTMODE_ENABLE	1
 #define NFC_CMD_SHORTMODE_DISABLE	0
 #define NFC_CMD_RB_INT		BIT(14)
 #define NFC_CMD_RB_INT_NO_PIN	((0xb << 10) | BIT(18) | BIT(16))
@@ -78,6 +79,8 @@
 #define DMA_DIR(dir)		((dir) ? NFC_CMD_N2M : NFC_CMD_M2N)
 #define DMA_ADDR_ALIGN		8
 
+#define NFC_SHORT_MODE_ECC_SZ	384
+
 #define ECC_CHECK_RETURN_FF	(-1)
 
 #define NAND_CE0		(0xe << 10)
@@ -125,6 +128,8 @@ struct meson_nfc_nand_chip {
 	u32 twb;
 	u32 tadl;
 	u32 tbers_max;
+	u32 boot_page_last;
+	u32 boot_page_step;
 
 	u32 bch_mode;
 	u8 *data_buf;
@@ -298,28 +303,49 @@ static void meson_nfc_cmd_seed(struct meson_nfc *nfc, u32 seed)
 	       nfc->reg_base + NFC_REG_CMD);
 }
 
-static void meson_nfc_cmd_access(struct nand_chip *nand, int raw, bool dir,
-				 int scrambler)
+static int meson_nfc_page_is_boot(struct nand_chip *nand, int page)
+{
+	const struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand);
+
+	return (nand->options & NAND_IS_BOOT_MEDIUM) &&
+	       !(page % meson_chip->boot_page_step) &&
+	       (page < meson_chip->boot_page_last);
+}
+
+static void meson_nfc_cmd_access(struct nand_chip *nand, bool raw, bool dir, int page)
 {
+	const struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand);
 	struct mtd_info *mtd = nand_to_mtd(nand);
 	struct meson_nfc *nfc = nand_get_controller_data(mtd_to_nand(mtd));
-	struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand);
-	u32 bch = meson_chip->bch_mode, cmd;
 	int len = mtd->writesize, pagesize, pages;
+	int scrambler;
+	u32 cmd;
 
-	pagesize = nand->ecc.size;
+	if (nand->options & NAND_NEED_SCRAMBLING)
+		scrambler = NFC_CMD_SCRAMBLER_ENABLE;
+	else
+		scrambler = NFC_CMD_SCRAMBLER_DISABLE;
 
 	if (raw) {
 		len = mtd->writesize + mtd->oobsize;
 		cmd = len | scrambler | DMA_DIR(dir);
-		writel(cmd, nfc->reg_base + NFC_REG_CMD);
-		return;
-	}
+	} else if (meson_nfc_page_is_boot(nand, page)) {
+		pagesize = NFC_SHORT_MODE_ECC_SZ >> 3;
+		pages = mtd->writesize / 512;
+
+		scrambler = NFC_CMD_SCRAMBLER_ENABLE;
+		cmd = CMDRWGEN(DMA_DIR(dir), scrambler, NFC_ECC_BCH8_1K,
+			       NFC_CMD_SHORTMODE_ENABLE, pagesize, pages);
+	} else {
+		pagesize = nand->ecc.size >> 3;
+		pages = len / nand->ecc.size;
 
-	pages = len / nand->ecc.size;
+		cmd = CMDRWGEN(DMA_DIR(dir), scrambler, meson_chip->bch_mode,
+			       NFC_CMD_SHORTMODE_DISABLE, pagesize, pages);
+	}
 
-	cmd = CMDRWGEN(DMA_DIR(dir), scrambler, bch,
-		       NFC_CMD_SHORTMODE_DISABLE, pagesize, pages);
+	if (scrambler == NFC_CMD_SCRAMBLER_ENABLE)
+		meson_nfc_cmd_seed(nfc, page);
 
 	writel(cmd, nfc->reg_base + NFC_REG_CMD);
 }
@@ -743,15 +769,7 @@ static int meson_nfc_write_page_sub(struct nand_chip *nand,
 	if (ret)
 		return ret;
 
-	if (nand->options & NAND_NEED_SCRAMBLING) {
-		meson_nfc_cmd_seed(nfc, page);
-		meson_nfc_cmd_access(nand, raw, DIRWRITE,
-				     NFC_CMD_SCRAMBLER_ENABLE);
-	} else {
-		meson_nfc_cmd_access(nand, raw, DIRWRITE,
-				     NFC_CMD_SCRAMBLER_DISABLE);
-	}
-
+	meson_nfc_cmd_access(nand, raw, DIRWRITE, page);
 	cmd = nfc->param.chip_select | NFC_CMD_CLE | NAND_CMD_PAGEPROG;
 	writel(cmd, nfc->reg_base + NFC_REG_CMD);
 	meson_nfc_queue_rb(nand, PSEC_TO_MSEC(sdr->tPROG_max), false);
@@ -829,15 +847,7 @@ static int meson_nfc_read_page_sub(struct nand_chip *nand,
 	if (ret)
 		return ret;
 
-	if (nand->options & NAND_NEED_SCRAMBLING) {
-		meson_nfc_cmd_seed(nfc, page);
-		meson_nfc_cmd_access(nand, raw, DIRREAD,
-				     NFC_CMD_SCRAMBLER_ENABLE);
-	} else {
-		meson_nfc_cmd_access(nand, raw, DIRREAD,
-				     NFC_CMD_SCRAMBLER_DISABLE);
-	}
-
+	meson_nfc_cmd_access(nand, raw, DIRREAD, page);
 	ret = meson_nfc_wait_dma_finish(nfc);
 	meson_nfc_check_ecc_pages_valid(nfc, nand, raw);
 
@@ -1436,6 +1446,26 @@ meson_nfc_nand_chip_init(struct device *dev,
 	if (ret)
 		return ret;
 
+	if (nand->options & NAND_IS_BOOT_MEDIUM) {
+		ret = of_property_read_u32(np, "amlogic,boot-page-last",
+					   &meson_chip->boot_page_last);
+		if (ret) {
+			dev_err(dev, "could not retrieve 'amlogic,boot-page-last' property: %d",
+				ret);
+			nand_cleanup(nand);
+			return ret;
+		}
+
+		ret = of_property_read_u32(np, "amlogic,boot-page-step",
+					   &meson_chip->boot_page_step);
+		if (ret) {
+			dev_err(dev, "could not retrieve 'amlogic,boot-page-step' property: %d",
+				ret);
+			nand_cleanup(nand);
+			return ret;
+		}
+	}
+
 	ret = mtd_device_register(mtd, NULL, 0);
 	if (ret) {
 		dev_err(dev, "failed to register MTD device: %d\n", ret);
Signature · 1 line
2.35.0