* [PATCH v4 1/5] mtd: spi-nor: core: add manufacturer flags
2024-09-17 9:49 [PATCH v4 0/5] Add support for SPI-NOR Macronix OTP Erez Geva
@ 2024-09-17 9:49 ` Erez Geva
2024-09-17 9:49 ` [PATCH v4 2/5] mtd: spi-nor: core: add generic functions Erez Geva
` (3 subsequent siblings)
4 siblings, 0 replies; 20+ messages in thread
From: Erez Geva @ 2024-09-17 9:49 UTC (permalink / raw)
To: linux-mtd, Tudor Ambarus, Pratyush Yadav, Michael Walle
Cc: linux-kernel, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, devicetree, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Esben Haabendal, Erez Geva
From: Erez Geva <ErezGeva2@gmail.com>
Add flag for always trying reading SFDP:
Some vendors reuse all JEDEC IDs on manufacture table
with new chips that support SFDP.
Add flag for reading OTP parameters from device tree.
Some vendors reuse JEDEC IDs
with several chips with different OTP parameters.
Alternatively we read parameters from SFDP.
But the OTP parameters are absent from the SFDP.
So there is not other way but to add the OTP parameters in the device tree.
In this patch series we use the new flags with Macronix.
Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
---
drivers/mtd/spi-nor/core.c | 36 ++++++++++++++++++++++++++++++-----
drivers/mtd/spi-nor/core.h | 7 ++++++-
drivers/mtd/spi-nor/otp.c | 6 +++---
drivers/mtd/spi-nor/winbond.c | 2 +-
4 files changed, 41 insertions(+), 10 deletions(-)
diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index e0c4efc424f4..23e3d5720ec0 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2891,10 +2891,11 @@ static void spi_nor_init_params_deprecated(struct spi_nor *nor)
spi_nor_manufacturer_init_params(nor);
- if (nor->info->no_sfdp_flags & (SPI_NOR_DUAL_READ |
- SPI_NOR_QUAD_READ |
- SPI_NOR_OCTAL_READ |
- SPI_NOR_OCTAL_DTR_READ))
+ if ((nor->info->no_sfdp_flags & (SPI_NOR_DUAL_READ |
+ SPI_NOR_QUAD_READ |
+ SPI_NOR_OCTAL_READ |
+ SPI_NOR_OCTAL_DTR_READ)) ||
+ nor->manufacturer->flags & SPI_NOR_MANUFACT_TRY_SFDP)
spi_nor_sfdp_init_params_deprecated(nor);
}
@@ -2911,7 +2912,32 @@ static void spi_nor_init_default_params(struct spi_nor *nor)
struct device_node *np = spi_nor_get_flash_node(nor);
params->quad_enable = spi_nor_sr2_bit1_quad_enable;
- params->otp.org = info->otp;
+ memset(¶ms->otp.org, 0, sizeof(struct spi_nor_otp_organization));
+ if (info->otp) {
+ memcpy(¶ms->otp.org, info->otp, sizeof(struct spi_nor_otp_organization));
+ } else if (nor->manufacturer->flags & SPI_NOR_MANUFACT_DT_OTP) {
+ /* Check for OTP information on device tree */
+ u32 n_regions, len;
+
+ if (!of_property_read_u32(np, "opt_n_regions", &n_regions) &&
+ n_regions > 0 &&
+ !of_property_read_u32(np, "otp_len", &len) &&
+ len > 0) {
+ u32 base, offset = 0;
+
+ if (n_regions > 1) {
+ /* If offset is not defined use length as offset */
+ if (of_property_read_u32(np, "otp_offset", &offset))
+ offset = len;
+ }
+ if (of_property_read_u32(np, "otp_base", &base))
+ base = 0;
+ params->otp.org.n_regions = n_regions;
+ params->otp.org.offset = offset;
+ params->otp.org.base = base;
+ params->otp.org.len = len;
+ }
+ }
/* Default to 16-bit Write Status (01h) Command */
nor->flags |= SNOR_F_HAS_16BIT_SR;
diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index 1516b6d0dc37..c862e42c844f 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -326,7 +326,7 @@ struct spi_nor_otp_ops {
* @ops: OTP access ops
*/
struct spi_nor_otp {
- const struct spi_nor_otp_organization *org;
+ struct spi_nor_otp_organization org;
const struct spi_nor_otp_ops *ops;
};
@@ -560,12 +560,17 @@ struct flash_info {
* @parts: array of parts supported by this manufacturer
* @nparts: number of entries in the parts array
* @fixups: hooks called at various points in time during spi_nor_scan()
+ * @flags: manufacturer flags
*/
struct spi_nor_manufacturer {
const char *name;
const struct flash_info *parts;
unsigned int nparts;
const struct spi_nor_fixups *fixups;
+
+ u8 flags;
+#define SPI_NOR_MANUFACT_TRY_SFDP BIT(0)
+#define SPI_NOR_MANUFACT_DT_OTP BIT(0)
};
/**
diff --git a/drivers/mtd/spi-nor/otp.c b/drivers/mtd/spi-nor/otp.c
index 9a729aa3452d..ffb7ffeb9030 100644
--- a/drivers/mtd/spi-nor/otp.c
+++ b/drivers/mtd/spi-nor/otp.c
@@ -11,8 +11,8 @@
#include "core.h"
-#define spi_nor_otp_region_len(nor) ((nor)->params->otp.org->len)
-#define spi_nor_otp_n_regions(nor) ((nor)->params->otp.org->n_regions)
+#define spi_nor_otp_region_len(nor) ((nor)->params->otp.org.len)
+#define spi_nor_otp_n_regions(nor) ((nor)->params->otp.org.n_regions)
/**
* spi_nor_otp_read_secr() - read security register
@@ -222,7 +222,7 @@ int spi_nor_otp_is_locked_sr2(struct spi_nor *nor, unsigned int region)
static loff_t spi_nor_otp_region_start(const struct spi_nor *nor, unsigned int region)
{
- const struct spi_nor_otp_organization *org = nor->params->otp.org;
+ const struct spi_nor_otp_organization *org = &nor->params->otp.org;
return org->base + region * org->offset;
}
diff --git a/drivers/mtd/spi-nor/winbond.c b/drivers/mtd/spi-nor/winbond.c
index e065e4fd42a3..15af62aacc9a 100644
--- a/drivers/mtd/spi-nor/winbond.c
+++ b/drivers/mtd/spi-nor/winbond.c
@@ -307,7 +307,7 @@ static int winbond_nor_late_init(struct spi_nor *nor)
{
struct spi_nor_flash_parameter *params = nor->params;
- if (params->otp.org)
+ if (params->otp.org.n_regions)
params->otp.ops = &winbond_nor_otp_ops;
/*
--
2.39.5
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v4 2/5] mtd: spi-nor: core: add generic functions
2024-09-17 9:49 [PATCH v4 0/5] Add support for SPI-NOR Macronix OTP Erez Geva
2024-09-17 9:49 ` [PATCH v4 1/5] mtd: spi-nor: core: add manufacturer flags Erez Geva
@ 2024-09-17 9:49 ` Erez Geva
2024-09-17 9:49 ` [PATCH v4 3/5] dt-bindings: mtd: spi-nor: add OTP parameters Erez Geva
` (2 subsequent siblings)
4 siblings, 0 replies; 20+ messages in thread
From: Erez Geva @ 2024-09-17 9:49 UTC (permalink / raw)
To: linux-mtd, Tudor Ambarus, Pratyush Yadav, Michael Walle
Cc: linux-kernel, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, devicetree, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Esben Haabendal, Erez Geva
From: Erez Geva <ErezGeva2@gmail.com>
Create a new internal function, spi_nor_send_cmd_internal()
to reduce duplicate code.
Add generic functions for use by vendor callbacks.
The functions contain dispatching for using SPIMEM
or using an SPI controller.
It is better to leave this kind of dispatcher,
out side of vendor specific code.
In this patch series we use the new functions in
Macronix new OTP callbacks.
The new added functions:
- Send an opcode without address or data.
- Read a register value.
- Write a register value.
Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
---
drivers/mtd/spi-nor/core.c | 130 +++++++++++++++++++++++++++----------
drivers/mtd/spi-nor/core.h | 27 +-------
2 files changed, 99 insertions(+), 58 deletions(-)
diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 23e3d5720ec0..47d5d21d7291 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -354,53 +354,134 @@ int spi_nor_write_any_volatile_reg(struct spi_nor *nor, struct spi_mem_op *op,
}
/**
- * spi_nor_write_enable() - Set write enable latch with Write Enable command.
+ * spi_nor_send_cmd_internal() - Send instruction without address or data to the chip.
* @nor: pointer to 'struct spi_nor'.
+ * @opcode: Command to send
*
* Return: 0 on success, -errno otherwise.
*/
-int spi_nor_write_enable(struct spi_nor *nor)
+static inline int spi_nor_send_cmd_internal(struct spi_nor *nor, u8 opcode)
{
int ret;
if (nor->spimem) {
- struct spi_mem_op op = SPI_NOR_WREN_OP;
+ struct spi_mem_op op = SPI_MEM_OP(SPI_MEM_OP_CMD(opcode, 0),
+ SPI_MEM_OP_NO_ADDR,
+ SPI_MEM_OP_NO_DUMMY,
+ SPI_MEM_OP_NO_DATA);
spi_nor_spimem_setup_op(nor, &op, nor->reg_proto);
ret = spi_mem_exec_op(nor->spimem, &op);
} else {
- ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_WREN,
- NULL, 0);
+ ret = spi_nor_controller_ops_write_reg(nor, opcode, NULL, 0);
}
- if (ret)
- dev_dbg(nor->dev, "error %d on Write Enable\n", ret);
+ return ret;
+}
+
+/**
+ * spi_nor_send_cmd() - Send instruction without address or data to the chip.
+ * @nor: pointer to 'struct spi_nor'.
+ * @opcode: Command to send
+ *
+ * Return: 0 on success, -errno otherwise.
+ */
+int spi_nor_send_cmd(struct spi_nor *nor, u8 opcode)
+{
+ int ret;
+
+ ret = spi_nor_send_cmd_internal(nor, opcode);
return ret;
}
/**
- * spi_nor_write_disable() - Send Write Disable instruction to the chip.
+ * spi_nor_read_reg() - Send instruction without address or data to the chip.
* @nor: pointer to 'struct spi_nor'.
+ * @opcode: Command to send
+ * @len: register value length
*
* Return: 0 on success, -errno otherwise.
*/
-int spi_nor_write_disable(struct spi_nor *nor)
+int spi_nor_read_reg(struct spi_nor *nor, u8 opcode, size_t len)
{
int ret;
if (nor->spimem) {
- struct spi_mem_op op = SPI_NOR_WRDI_OP;
+ struct spi_mem_op op = SPI_MEM_OP(SPI_MEM_OP_CMD(opcode, 0),
+ SPI_MEM_OP_NO_ADDR,
+ SPI_MEM_OP_NO_DUMMY,
+ SPI_MEM_OP_DATA_IN(len, nor->bouncebuf, 0));
spi_nor_spimem_setup_op(nor, &op, nor->reg_proto);
ret = spi_mem_exec_op(nor->spimem, &op);
} else {
- ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_WRDI,
- NULL, 0);
+ ret = spi_nor_controller_ops_read_reg(nor, opcode, nor->bouncebuf, len);
}
+ return ret;
+}
+
+/*
+ * spi_nor_write_reg() - Send instruction without address or data to the chip.
+ * @nor: pointer to 'struct spi_nor'.
+ * @opcode: Command to send
+ * @len: register value length
+ *
+ * Return: 0 on success, -errno otherwise.
+ */
+int spi_nor_write_reg(struct spi_nor *nor, u8 opcode, size_t len)
+{
+ int ret;
+
+ if (nor->spimem) {
+ struct spi_mem_op op = SPI_MEM_OP(SPI_MEM_OP_CMD(opcode, 0),
+ SPI_MEM_OP_NO_ADDR,
+ SPI_MEM_OP_NO_DUMMY,
+ SPI_MEM_OP_DATA_OUT(len, nor->bouncebuf, 0));
+
+ spi_nor_spimem_setup_op(nor, &op, nor->reg_proto);
+
+ ret = spi_mem_exec_op(nor->spimem, &op);
+ } else {
+ ret = spi_nor_controller_ops_write_reg(nor, opcode, nor->bouncebuf, len);
+ }
+
+ return ret;
+}
+
+/**
+ * spi_nor_write_enable() - Set write enable latch with Write Enable command.
+ * @nor: pointer to 'struct spi_nor'.
+ *
+ * Return: 0 on success, -errno otherwise.
+ */
+int spi_nor_write_enable(struct spi_nor *nor)
+{
+ int ret;
+
+ ret = spi_nor_send_cmd_internal(nor, SPINOR_OP_WREN);
+
+ if (ret)
+ dev_dbg(nor->dev, "error %d on Write Enable\n", ret);
+
+ return ret;
+}
+
+/**
+ * spi_nor_write_disable() - Send Write Disable instruction to the chip.
+ * @nor: pointer to 'struct spi_nor'.
+ *
+ * Return: 0 on success, -errno otherwise.
+ */
+int spi_nor_write_disable(struct spi_nor *nor)
+{
+ int ret;
+
+ ret = spi_nor_send_cmd_internal(nor, SPINOR_OP_WRDI);
+
if (ret)
dev_dbg(nor->dev, "error %d on Write Disable\n", ret);
@@ -521,18 +602,8 @@ int spi_nor_set_4byte_addr_mode_en4b_ex4b(struct spi_nor *nor, bool enable)
{
int ret;
- if (nor->spimem) {
- struct spi_mem_op op = SPI_NOR_EN4B_EX4B_OP(enable);
-
- spi_nor_spimem_setup_op(nor, &op, nor->reg_proto);
-
- ret = spi_mem_exec_op(nor->spimem, &op);
- } else {
- ret = spi_nor_controller_ops_write_reg(nor,
- enable ? SPINOR_OP_EN4B :
- SPINOR_OP_EX4B,
- NULL, 0);
- }
+ ret = spi_nor_send_cmd_internal(nor, enable ? SPINOR_OP_EN4B :
+ SPINOR_OP_EX4B);
if (ret)
dev_dbg(nor->dev, "error %d setting 4-byte mode\n", ret);
@@ -765,16 +836,7 @@ int spi_nor_global_block_unlock(struct spi_nor *nor)
if (ret)
return ret;
- if (nor->spimem) {
- struct spi_mem_op op = SPI_NOR_GBULK_OP;
-
- spi_nor_spimem_setup_op(nor, &op, nor->reg_proto);
-
- ret = spi_mem_exec_op(nor->spimem, &op);
- } else {
- ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_GBULK,
- NULL, 0);
- }
+ ret = spi_nor_send_cmd_internal(nor, SPINOR_OP_GBULK);
if (ret) {
dev_dbg(nor->dev, "error %d on Global Block Unlock\n", ret);
diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index c862e42c844f..615c399dfb6e 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -25,18 +25,6 @@
SPI_MEM_OP_DUMMY(ndummy, 0), \
SPI_MEM_OP_DATA_IN(len, buf, 0))
-#define SPI_NOR_WREN_OP \
- SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_WREN, 0), \
- SPI_MEM_OP_NO_ADDR, \
- SPI_MEM_OP_NO_DUMMY, \
- SPI_MEM_OP_NO_DATA)
-
-#define SPI_NOR_WRDI_OP \
- SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_WRDI, 0), \
- SPI_MEM_OP_NO_ADDR, \
- SPI_MEM_OP_NO_DUMMY, \
- SPI_MEM_OP_NO_DATA)
-
#define SPI_NOR_RDSR_OP(buf) \
SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_RDSR, 0), \
SPI_MEM_OP_NO_ADDR, \
@@ -67,24 +55,12 @@
SPI_MEM_OP_NO_DUMMY, \
SPI_MEM_OP_DATA_IN(1, buf, 0))
-#define SPI_NOR_EN4B_EX4B_OP(enable) \
- SPI_MEM_OP(SPI_MEM_OP_CMD(enable ? SPINOR_OP_EN4B : SPINOR_OP_EX4B, 0), \
- SPI_MEM_OP_NO_ADDR, \
- SPI_MEM_OP_NO_DUMMY, \
- SPI_MEM_OP_NO_DATA)
-
#define SPI_NOR_BRWR_OP(buf) \
SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_BRWR, 0), \
SPI_MEM_OP_NO_ADDR, \
SPI_MEM_OP_NO_DUMMY, \
SPI_MEM_OP_DATA_OUT(1, buf, 0))
-#define SPI_NOR_GBULK_OP \
- SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_GBULK, 0), \
- SPI_MEM_OP_NO_ADDR, \
- SPI_MEM_OP_NO_DUMMY, \
- SPI_MEM_OP_NO_DATA)
-
#define SPI_NOR_DIE_ERASE_OP(opcode, addr_nbytes, addr, dice) \
SPI_MEM_OP(SPI_MEM_OP_CMD(opcode, 0), \
SPI_MEM_OP_ADDR(dice ? addr_nbytes : 0, addr, 0), \
@@ -604,6 +580,9 @@ extern const struct attribute_group *spi_nor_sysfs_groups[];
void spi_nor_spimem_setup_op(const struct spi_nor *nor,
struct spi_mem_op *op,
const enum spi_nor_protocol proto);
+int spi_nor_send_cmd(struct spi_nor *nor, u8 opcode);
+int spi_nor_read_reg(struct spi_nor *nor, u8 opcode, size_t len);
+int spi_nor_write_reg(struct spi_nor *nor, u8 opcode, size_t len);
int spi_nor_write_enable(struct spi_nor *nor);
int spi_nor_write_disable(struct spi_nor *nor);
int spi_nor_set_4byte_addr_mode_en4b_ex4b(struct spi_nor *nor, bool enable);
--
2.39.5
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH v4 3/5] dt-bindings: mtd: spi-nor: add OTP parameters
2024-09-17 9:49 [PATCH v4 0/5] Add support for SPI-NOR Macronix OTP Erez Geva
2024-09-17 9:49 ` [PATCH v4 1/5] mtd: spi-nor: core: add manufacturer flags Erez Geva
2024-09-17 9:49 ` [PATCH v4 2/5] mtd: spi-nor: core: add generic functions Erez Geva
@ 2024-09-17 9:49 ` Erez Geva
2024-09-17 10:17 ` Erez
2024-09-17 10:35 ` Krzysztof Kozlowski
2024-09-17 9:49 ` [PATCH v4 4/5] mtd: spi-nor: macronix: add support for OTP Erez Geva
2024-09-17 9:49 ` [PATCH v4 5/5] mtd: spi-nor: macronix: add manufacturer flags Erez Geva
4 siblings, 2 replies; 20+ messages in thread
From: Erez Geva @ 2024-09-17 9:49 UTC (permalink / raw)
To: linux-mtd, Tudor Ambarus, Pratyush Yadav, Michael Walle
Cc: linux-kernel, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, devicetree, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Esben Haabendal, Erez Geva
From: Erez Geva <ErezGeva2@gmail.com>
Some flash devices need OTP parameters in device tree.
As we can not deduce the parameters based on JEDEC ID or SFDP.
Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
---
.../bindings/mtd/jedec,spi-nor.yaml | 37 +++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml b/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml
index 6e3afb42926e..d502b7fab2ce 100644
--- a/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml
+++ b/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml
@@ -90,6 +90,43 @@ properties:
the SRWD bit while writing the status register. WP# signal hard strapped to GND
can be a valid use case.
+ opt_n_regions:
+ type: u32
+ description:
+ Some flash devices need OTP parameters in the device tree.
+ As we can not deduce the parameters based on JEDEC ID or SFDP.
+ This parameter indicates the number of OTP regions.
+ The value must be larger than 1 and mandatory for OTP.
+
+ otp_len:
+ type: u32
+ description:
+ Some flash devices need OTP parameters in the device tree.
+ As we can not deduce the parameters based on JEDEC ID or SFDP.
+ This parameter indicates the size (length) in bytes of an OTP region.
+ Currently the driver supports symmetric OTP,
+ which means all regions must use the same size.
+ The value must be positive and mandatory for OTP.
+
+ otp_offset:
+ type: u32
+ description:
+ Some flash devices need OTP parameters in the device tree.
+ As we can not deduce the parameters based on JEDEC ID or SFDP.
+ This parameter indicates the offset in bytes of
+ an OTP region relative to its previous.
+ User can omit it if the offset equals the length.
+ Or in case we have a single OTP region.
+
+ otp_base:
+ type: u32
+ description:
+ Some flash devices need OTP parameters in the device tree.
+ As we can not deduce the parameters based on JEDEC ID or SFDP.
+ This parameter indicates the base in bytes of the first OTP region.
+ User can omit it if the base is zero.
+ I.e. the address of the first OTP region starts from 0.
+
reset-gpios:
description:
A GPIO line connected to the RESET (active low) signal of the device.
--
2.39.5
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH v4 3/5] dt-bindings: mtd: spi-nor: add OTP parameters
2024-09-17 9:49 ` [PATCH v4 3/5] dt-bindings: mtd: spi-nor: add OTP parameters Erez Geva
@ 2024-09-17 10:17 ` Erez
2024-09-17 10:35 ` Krzysztof Kozlowski
1 sibling, 0 replies; 20+ messages in thread
From: Erez @ 2024-09-17 10:17 UTC (permalink / raw)
To: Erez Geva
Cc: linux-mtd, Tudor Ambarus, Pratyush Yadav, Michael Walle,
linux-kernel, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, devicetree, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Esben Haabendal
On Tue, 17 Sept 2024 at 11:50, Erez Geva <erezgeva@nwtime.org> wrote:
>
> From: Erez Geva <ErezGeva2@gmail.com>
>
> Some flash devices need OTP parameters in device tree.
> As we can not deduce the parameters based on JEDEC ID or SFDP.
>
> Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
> ---
> .../bindings/mtd/jedec,spi-nor.yaml | 37 +++++++++++++++++++
> 1 file changed, 37 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml b/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml
> index 6e3afb42926e..d502b7fab2ce 100644
> --- a/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml
> +++ b/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml
> @@ -90,6 +90,43 @@ properties:
> the SRWD bit while writing the status register. WP# signal hard strapped to GND
> can be a valid use case.
>
> + opt_n_regions:
> + type: u32
> + description:
> + Some flash devices need OTP parameters in the device tree.
> + As we can not deduce the parameters based on JEDEC ID or SFDP.
> + This parameter indicates the number of OTP regions.
> + The value must be larger than 1 and mandatory for OTP.
Sorry: "The value must be larger or equal to 1 and mandatory for OTP.
"
> +
> + otp_len:
> + type: u32
> + description:
> + Some flash devices need OTP parameters in the device tree.
> + As we can not deduce the parameters based on JEDEC ID or SFDP.
> + This parameter indicates the size (length) in bytes of an OTP region.
> + Currently the driver supports symmetric OTP,
> + which means all regions must use the same size.
> + The value must be positive and mandatory for OTP.
> +
> + otp_offset:
> + type: u32
> + description:
> + Some flash devices need OTP parameters in the device tree.
> + As we can not deduce the parameters based on JEDEC ID or SFDP.
> + This parameter indicates the offset in bytes of
> + an OTP region relative to its previous.
> + User can omit it if the offset equals the length.
> + Or in case we have a single OTP region.
> +
> + otp_base:
> + type: u32
> + description:
> + Some flash devices need OTP parameters in the device tree.
> + As we can not deduce the parameters based on JEDEC ID or SFDP.
> + This parameter indicates the base in bytes of the first OTP region.
> + User can omit it if the base is zero.
> + I.e. the address of the first OTP region starts from 0.
> +
> reset-gpios:
> description:
> A GPIO line connected to the RESET (active low) signal of the device.
> --
> 2.39.5
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v4 3/5] dt-bindings: mtd: spi-nor: add OTP parameters
2024-09-17 9:49 ` [PATCH v4 3/5] dt-bindings: mtd: spi-nor: add OTP parameters Erez Geva
2024-09-17 10:17 ` Erez
@ 2024-09-17 10:35 ` Krzysztof Kozlowski
2024-09-17 10:42 ` Erez
1 sibling, 1 reply; 20+ messages in thread
From: Krzysztof Kozlowski @ 2024-09-17 10:35 UTC (permalink / raw)
To: Erez Geva, linux-mtd, Tudor Ambarus, Pratyush Yadav,
Michael Walle
Cc: linux-kernel, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, devicetree, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Esben Haabendal, Erez Geva
On 17/09/2024 11:49, Erez Geva wrote:
> From: Erez Geva <ErezGeva2@gmail.com>
>
> Some flash devices need OTP parameters in device tree.
> As we can not deduce the parameters based on JEDEC ID or SFDP.
>
> Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
> ---
> .../bindings/mtd/jedec,spi-nor.yaml | 37 +++++++++++++++++++
> 1 file changed, 37 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml b/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml
> index 6e3afb42926e..d502b7fab2ce 100644
> --- a/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml
> +++ b/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml
> @@ -90,6 +90,43 @@ properties:
> the SRWD bit while writing the status register. WP# signal hard strapped to GND
> can be a valid use case.
>
> + opt_n_regions:
No underscores, but hyphens.
> + type: u32
It does not look like you tested the bindings, at least after quick
look. Please run `make dt_binding_check` (see
Documentation/devicetree/bindings/writing-schema.rst for instructions).
Maybe you need to update your dtschema and yamllint.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v4 3/5] dt-bindings: mtd: spi-nor: add OTP parameters
2024-09-17 10:35 ` Krzysztof Kozlowski
@ 2024-09-17 10:42 ` Erez
2024-09-17 17:00 ` Krzysztof Kozlowski
0 siblings, 1 reply; 20+ messages in thread
From: Erez @ 2024-09-17 10:42 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Erez Geva, linux-mtd, Tudor Ambarus, Pratyush Yadav,
Michael Walle, linux-kernel, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, devicetree, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Esben Haabendal
On Tue, 17 Sept 2024 at 12:36, Krzysztof Kozlowski <krzk@kernel.org> wrote:
>
> On 17/09/2024 11:49, Erez Geva wrote:
> > From: Erez Geva <ErezGeva2@gmail.com>
> >
> > Some flash devices need OTP parameters in device tree.
> > As we can not deduce the parameters based on JEDEC ID or SFDP.
> >
> > Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
> > ---
> > .../bindings/mtd/jedec,spi-nor.yaml | 37 +++++++++++++++++++
> > 1 file changed, 37 insertions(+)
> >
> > diff --git a/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml b/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml
> > index 6e3afb42926e..d502b7fab2ce 100644
> > --- a/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml
> > +++ b/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml
> > @@ -90,6 +90,43 @@ properties:
> > the SRWD bit while writing the status register. WP# signal hard strapped to GND
> > can be a valid use case.
> >
> > + opt_n_regions:
>
> No underscores, but hyphens.
I'll fix this.
>
> > + type: u32
>
> It does not look like you tested the bindings, at least after quick
> look. Please run `make dt_binding_check` (see
I run "make dt_binding_check" on kernel 6.6.
> Documentation/devicetree/bindings/writing-schema.rst for instructions).
> Maybe you need to update your dtschema and yamllint.
>
>
>
> Best regards,
> Krzysztof
>
Thanks for the feedback.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v4 3/5] dt-bindings: mtd: spi-nor: add OTP parameters
2024-09-17 10:42 ` Erez
@ 2024-09-17 17:00 ` Krzysztof Kozlowski
2024-09-17 17:11 ` Erez
0 siblings, 1 reply; 20+ messages in thread
From: Krzysztof Kozlowski @ 2024-09-17 17:00 UTC (permalink / raw)
To: Erez
Cc: Erez Geva, linux-mtd, Tudor Ambarus, Pratyush Yadav,
Michael Walle, linux-kernel, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, devicetree, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Esben Haabendal
On 17/09/2024 12:42, Erez wrote:
> On Tue, 17 Sept 2024 at 12:36, Krzysztof Kozlowski <krzk@kernel.org> wrote:
>>
>> On 17/09/2024 11:49, Erez Geva wrote:
>>> From: Erez Geva <ErezGeva2@gmail.com>
>>>
>>> Some flash devices need OTP parameters in device tree.
>>> As we can not deduce the parameters based on JEDEC ID or SFDP.
>>>
>>> Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
>>> ---
>>> .../bindings/mtd/jedec,spi-nor.yaml | 37 +++++++++++++++++++
>>> 1 file changed, 37 insertions(+)
>>>
>>> diff --git a/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml b/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml
>>> index 6e3afb42926e..d502b7fab2ce 100644
>>> --- a/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml
>>> +++ b/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml
>>> @@ -90,6 +90,43 @@ properties:
>>> the SRWD bit while writing the status register. WP# signal hard strapped to GND
>>> can be a valid use case.
>>>
>>> + opt_n_regions:
>>
>> No underscores, but hyphens.
>
> I'll fix this.
>
>>
>>> + type: u32
>>
>> It does not look like you tested the bindings, at least after quick
>> look. Please run `make dt_binding_check` (see
>
> I run "make dt_binding_check" on kernel 6.6.
Yeah, we are no on kernel 6.6. You can run it also on kernel v4.1 -
still does not matter.
Don't develop on ancient code because then you ask us to review same
broken stuff we already fixed.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v4 3/5] dt-bindings: mtd: spi-nor: add OTP parameters
2024-09-17 17:00 ` Krzysztof Kozlowski
@ 2024-09-17 17:11 ` Erez
2024-09-17 17:17 ` Krzysztof Kozlowski
0 siblings, 1 reply; 20+ messages in thread
From: Erez @ 2024-09-17 17:11 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Erez Geva, linux-mtd, Tudor Ambarus, Pratyush Yadav,
Michael Walle, linux-kernel, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, devicetree, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Esben Haabendal
On Tue, 17 Sept 2024 at 19:00, Krzysztof Kozlowski <krzk@kernel.org> wrote:
>
> On 17/09/2024 12:42, Erez wrote:
> > On Tue, 17 Sept 2024 at 12:36, Krzysztof Kozlowski <krzk@kernel.org> wrote:
> >>
> >> On 17/09/2024 11:49, Erez Geva wrote:
> >>> From: Erez Geva <ErezGeva2@gmail.com>
> >>>
> >>> Some flash devices need OTP parameters in device tree.
> >>> As we can not deduce the parameters based on JEDEC ID or SFDP.
> >>>
> >>> Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
> >>> ---
> >>> .../bindings/mtd/jedec,spi-nor.yaml | 37 +++++++++++++++++++
> >>> 1 file changed, 37 insertions(+)
> >>>
> >>> diff --git a/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml b/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml
> >>> index 6e3afb42926e..d502b7fab2ce 100644
> >>> --- a/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml
> >>> +++ b/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml
> >>> @@ -90,6 +90,43 @@ properties:
> >>> the SRWD bit while writing the status register. WP# signal hard strapped to GND
> >>> can be a valid use case.
> >>>
> >>> + opt_n_regions:
> >>
> >> No underscores, but hyphens.
> >
> > I'll fix this.
> >
> >>
> >>> + type: u32
> >>
> >> It does not look like you tested the bindings, at least after quick
> >> look. Please run `make dt_binding_check` (see
> >
> > I run "make dt_binding_check" on kernel 6.6.
>
> Yeah, we are no on kernel 6.6. You can run it also on kernel v4.1 -
> still does not matter.
>
> Don't develop on ancient code because then you ask us to review same
> broken stuff we already fixed.
I test with Beaglebone black for testing, it is difficult to run the
last vanille version.
I did backport the spi-nor driver.
As for "make dt_binding_check" on last kernel, it need to upgrade the tools,
and I did not think it could change that much.
The patches themself are based on vanile kernel
commit 6b0f8db921abf0520081d779876d3a41069dab95 (origin/master)
Merge: 6b4aa469f049 f50733b45d86
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date: Tue Aug 13 16:10:32 2024 -0700
Erez
>
> Best regards,
> Krzysztof
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v4 3/5] dt-bindings: mtd: spi-nor: add OTP parameters
2024-09-17 17:11 ` Erez
@ 2024-09-17 17:17 ` Krzysztof Kozlowski
2024-09-17 17:24 ` Erez
0 siblings, 1 reply; 20+ messages in thread
From: Krzysztof Kozlowski @ 2024-09-17 17:17 UTC (permalink / raw)
To: Erez
Cc: Erez Geva, linux-mtd, Tudor Ambarus, Pratyush Yadav,
Michael Walle, linux-kernel, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, devicetree, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Esben Haabendal
On 17/09/2024 19:11, Erez wrote:
> On Tue, 17 Sept 2024 at 19:00, Krzysztof Kozlowski <krzk@kernel.org> wrote:
>>
>> On 17/09/2024 12:42, Erez wrote:
>>> On Tue, 17 Sept 2024 at 12:36, Krzysztof Kozlowski <krzk@kernel.org> wrote:
>>>>
>>>> On 17/09/2024 11:49, Erez Geva wrote:
>>>>> From: Erez Geva <ErezGeva2@gmail.com>
>>>>>
>>>>> Some flash devices need OTP parameters in device tree.
>>>>> As we can not deduce the parameters based on JEDEC ID or SFDP.
>>>>>
>>>>> Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
>>>>> ---
>>>>> .../bindings/mtd/jedec,spi-nor.yaml | 37 +++++++++++++++++++
>>>>> 1 file changed, 37 insertions(+)
>>>>>
>>>>> diff --git a/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml b/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml
>>>>> index 6e3afb42926e..d502b7fab2ce 100644
>>>>> --- a/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml
>>>>> +++ b/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml
>>>>> @@ -90,6 +90,43 @@ properties:
>>>>> the SRWD bit while writing the status register. WP# signal hard strapped to GND
>>>>> can be a valid use case.
>>>>>
>>>>> + opt_n_regions:
>>>>
>>>> No underscores, but hyphens.
>>>
>>> I'll fix this.
>>>
>>>>
>>>>> + type: u32
>>>>
>>>> It does not look like you tested the bindings, at least after quick
>>>> look. Please run `make dt_binding_check` (see
>>>
>>> I run "make dt_binding_check" on kernel 6.6.
>>
>> Yeah, we are no on kernel 6.6. You can run it also on kernel v4.1 -
>> still does not matter.
>>
>> Don't develop on ancient code because then you ask us to review same
>> broken stuff we already fixed.
>
> I test with Beaglebone black for testing, it is difficult to run the
> last vanille version.
> I did backport the spi-nor driver.
> As for "make dt_binding_check" on last kernel, it need to upgrade the tools,
> and I did not think it could change that much.
>
Well, it is possible to build kernel on small embedded board, but that's
quite cumbersone, slow and inefficient, considering that it's just
easier to cross compile. But anyway, binding check does not even need
cross compilation.
Sorry, the code is obviously wrong, there is no such thing as u32, so
you did not test it. I provided link which explains how to test it. You
must do it on latest mainline kernel. Just like you must develop and
generate patches on latest mainline kernel, because this is where we
apply the patches. We do not apply them to v6.6.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v4 3/5] dt-bindings: mtd: spi-nor: add OTP parameters
2024-09-17 17:17 ` Krzysztof Kozlowski
@ 2024-09-17 17:24 ` Erez
2024-09-17 17:32 ` Krzysztof Kozlowski
0 siblings, 1 reply; 20+ messages in thread
From: Erez @ 2024-09-17 17:24 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Erez Geva, linux-mtd, Tudor Ambarus, Pratyush Yadav,
Michael Walle, linux-kernel, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, devicetree, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Esben Haabendal
On Tue, 17 Sept 2024 at 19:17, Krzysztof Kozlowski <krzk@kernel.org> wrote:
>
> On 17/09/2024 19:11, Erez wrote:
> > On Tue, 17 Sept 2024 at 19:00, Krzysztof Kozlowski <krzk@kernel.org> wrote:
> >>
> >> On 17/09/2024 12:42, Erez wrote:
> >>> On Tue, 17 Sept 2024 at 12:36, Krzysztof Kozlowski <krzk@kernel.org> wrote:
> >>>>
> >>>> On 17/09/2024 11:49, Erez Geva wrote:
> >>>>> From: Erez Geva <ErezGeva2@gmail.com>
> >>>>>
> >>>>> Some flash devices need OTP parameters in device tree.
> >>>>> As we can not deduce the parameters based on JEDEC ID or SFDP.
> >>>>>
> >>>>> Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
> >>>>> ---
> >>>>> .../bindings/mtd/jedec,spi-nor.yaml | 37 +++++++++++++++++++
> >>>>> 1 file changed, 37 insertions(+)
> >>>>>
> >>>>> diff --git a/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml b/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml
> >>>>> index 6e3afb42926e..d502b7fab2ce 100644
> >>>>> --- a/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml
> >>>>> +++ b/Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml
> >>>>> @@ -90,6 +90,43 @@ properties:
> >>>>> the SRWD bit while writing the status register. WP# signal hard strapped to GND
> >>>>> can be a valid use case.
> >>>>>
> >>>>> + opt_n_regions:
> >>>>
> >>>> No underscores, but hyphens.
> >>>
> >>> I'll fix this.
> >>>
> >>>>
> >>>>> + type: u32
> >>>>
> >>>> It does not look like you tested the bindings, at least after quick
> >>>> look. Please run `make dt_binding_check` (see
> >>>
> >>> I run "make dt_binding_check" on kernel 6.6.
> >>
> >> Yeah, we are no on kernel 6.6. You can run it also on kernel v4.1 -
> >> still does not matter.
> >>
> >> Don't develop on ancient code because then you ask us to review same
> >> broken stuff we already fixed.
> >
> > I test with Beaglebone black for testing, it is difficult to run the
> > last vanille version.
> > I did backport the spi-nor driver.
> > As for "make dt_binding_check" on last kernel, it need to upgrade the tools,
> > and I did not think it could change that much.
> >
>
> Well, it is possible to build kernel on small embedded board, but that's
> quite cumbersone, slow and inefficient, considering that it's just
> easier to cross compile. But anyway, binding check does not even need
> cross compilation.
>
> Sorry, the code is obviously wrong, there is no such thing as u32, so
> you did not test it. I provided link which explains how to test it. You
> must do it on latest mainline kernel. Just like you must develop and
> generate patches on latest mainline kernel, because this is where we
> apply the patches. We do not apply them to v6.6.
The patches are based on the lastest mainline kernel.
I do not understand why you think otherwise.
I will run the "make dt_binding_check" on the mainline kernel.
Thanks for your feedback.
Erez
>
> Best regards,
> Krzysztof
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v4 3/5] dt-bindings: mtd: spi-nor: add OTP parameters
2024-09-17 17:24 ` Erez
@ 2024-09-17 17:32 ` Krzysztof Kozlowski
2024-09-17 18:39 ` Erez
0 siblings, 1 reply; 20+ messages in thread
From: Krzysztof Kozlowski @ 2024-09-17 17:32 UTC (permalink / raw)
To: Erez
Cc: Erez Geva, linux-mtd, Tudor Ambarus, Pratyush Yadav,
Michael Walle, linux-kernel, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, devicetree, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Esben Haabendal
On 17/09/2024 19:24, Erez wrote:
>>>>>>
>>>>>> It does not look like you tested the bindings, at least after quick
>>>>>> look. Please run `make dt_binding_check` (see
>>>>>
>>>>> I run "make dt_binding_check" on kernel 6.6.
>>>>
>>>> Yeah, we are no on kernel 6.6. You can run it also on kernel v4.1 -
>>>> still does not matter.
>>>>
>>>> Don't develop on ancient code because then you ask us to review same
>>>> broken stuff we already fixed.
>>>
>>> I test with Beaglebone black for testing, it is difficult to run the
>>> last vanille version.
>>> I did backport the spi-nor driver.
>>> As for "make dt_binding_check" on last kernel, it need to upgrade the tools,
>>> and I did not think it could change that much.
>>>
>>
>> Well, it is possible to build kernel on small embedded board, but that's
>> quite cumbersone, slow and inefficient, considering that it's just
>> easier to cross compile. But anyway, binding check does not even need
>> cross compilation.
>>
>> Sorry, the code is obviously wrong, there is no such thing as u32, so
>> you did not test it. I provided link which explains how to test it. You
>> must do it on latest mainline kernel. Just like you must develop and
>> generate patches on latest mainline kernel, because this is where we
>> apply the patches. We do not apply them to v6.6.
>
> The patches are based on the lastest mainline kernel.
> I do not understand why you think otherwise.
Because you wrote:
"I run "make dt_binding_check" on kernel 6.6."
The command is either part of build process or final check process
(static analyzers etc). If you say you did this on v6.6, you got such
response.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v4 3/5] dt-bindings: mtd: spi-nor: add OTP parameters
2024-09-17 17:32 ` Krzysztof Kozlowski
@ 2024-09-17 18:39 ` Erez
2024-09-17 20:39 ` Conor Dooley
0 siblings, 1 reply; 20+ messages in thread
From: Erez @ 2024-09-17 18:39 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Erez Geva, linux-mtd, Tudor Ambarus, Pratyush Yadav,
Michael Walle, linux-kernel, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, devicetree, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Esben Haabendal
On Tue, 17 Sept 2024 at 19:32, Krzysztof Kozlowski <krzk@kernel.org> wrote:
>
> On 17/09/2024 19:24, Erez wrote:
> >>>>>>
> >>>>>> It does not look like you tested the bindings, at least after quick
> >>>>>> look. Please run `make dt_binding_check` (see
> >>>>>
> >>>>> I run "make dt_binding_check" on kernel 6.6.
> >>>>
> >>>> Yeah, we are no on kernel 6.6. You can run it also on kernel v4.1 -
> >>>> still does not matter.
> >>>>
> >>>> Don't develop on ancient code because then you ask us to review same
> >>>> broken stuff we already fixed.
> >>>
> >>> I test with Beaglebone black for testing, it is difficult to run the
> >>> last vanille version.
> >>> I did backport the spi-nor driver.
> >>> As for "make dt_binding_check" on last kernel, it need to upgrade the tools,
> >>> and I did not think it could change that much.
> >>>
> >>
> >> Well, it is possible to build kernel on small embedded board, but that's
> >> quite cumbersone, slow and inefficient, considering that it's just
> >> easier to cross compile. But anyway, binding check does not even need
> >> cross compilation.
> >>
> >> Sorry, the code is obviously wrong, there is no such thing as u32, so
> >> you did not test it. I provided link which explains how to test it. You
> >> must do it on latest mainline kernel. Just like you must develop and
> >> generate patches on latest mainline kernel, because this is where we
> >> apply the patches. We do not apply them to v6.6.
> >
> > The patches are based on the lastest mainline kernel.
> > I do not understand why you think otherwise.
>
> Because you wrote:
> "I run "make dt_binding_check" on kernel 6.6."
>
> The command is either part of build process or final check process
> (static analyzers etc). If you say you did this on v6.6, you got such
> response.
I know you are NOT a service.
The device tree is not the focus of my work.
It should not be broken like that.
I install dt-schema_2023.11-3_all.deb
with Debian trixie
I get:
l
SCHEMA Documentation/devicetree/bindings/processed-schema.json
Traceback (most recent call last):
File "/usr/bin/dt-mk-schema", line 8, in <module>
sys.exit(main())
^^^^^^
File "/usr/lib/python3/dist-packages/dtschema/mk_schema.py", line 28, in main
schemas = dtschema.DTValidator(args.schemas).schemas
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/dtschema/validator.py", line
363, in __init__
self.make_property_type_cache()
File "/usr/lib/python3/dist-packages/dtschema/validator.py", line
420, in make_property_type_cache
self.props, self.pat_props = get_prop_types(self.schemas)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/dtschema/validator.py", line
187, in get_prop_types
del props[r'^[a-z][a-z0-9\-]*$']
~~~~~^^^^^^^^^^^^^^^^^^^^^^^
KeyError: '^[a-z][a-z0-9\\-]*$'
make[2]: *** [Documentation/devicetree/bindings/Makefile:64:
Documentation/devicetree/bindings/processed-schema.json] Error 1
make[2]: *** Deleting file
'Documentation/devicetree/bindings/processed-schema.json'
make[1]: *** [/home/builder/kernel/Makefile:1435: dt_binding_schemas] Error 2
Erez
>
> Best regards,
> Krzysztof
>
^ permalink raw reply [flat|nested] 20+ messages in thread* Re: [PATCH v4 3/5] dt-bindings: mtd: spi-nor: add OTP parameters
2024-09-17 18:39 ` Erez
@ 2024-09-17 20:39 ` Conor Dooley
2024-09-17 21:29 ` Erez
0 siblings, 1 reply; 20+ messages in thread
From: Conor Dooley @ 2024-09-17 20:39 UTC (permalink / raw)
To: Erez
Cc: Krzysztof Kozlowski, Erez Geva, linux-mtd, Tudor Ambarus,
Pratyush Yadav, Michael Walle, linux-kernel, Miquel Raynal,
Richard Weinberger, Vignesh Raghavendra, devicetree, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Esben Haabendal
[-- Attachment #1: Type: text/plain, Size: 3552 bytes --]
On Tue, Sep 17, 2024 at 08:39:48PM +0200, Erez wrote:
> On Tue, 17 Sept 2024 at 19:32, Krzysztof Kozlowski <krzk@kernel.org> wrote:
> >
> > On 17/09/2024 19:24, Erez wrote:
> > >>>>>>
> > >>>>>> It does not look like you tested the bindings, at least after quick
> > >>>>>> look. Please run `make dt_binding_check` (see
> > >>>>>
> > >>>>> I run "make dt_binding_check" on kernel 6.6.
> > >>>>
> > >>>> Yeah, we are no on kernel 6.6. You can run it also on kernel v4.1 -
> > >>>> still does not matter.
> > >>>>
> > >>>> Don't develop on ancient code because then you ask us to review same
> > >>>> broken stuff we already fixed.
> > >>>
> > >>> I test with Beaglebone black for testing, it is difficult to run the
> > >>> last vanille version.
> > >>> I did backport the spi-nor driver.
> > >>> As for "make dt_binding_check" on last kernel, it need to upgrade the tools,
> > >>> and I did not think it could change that much.
> > >>>
> > >>
> > >> Well, it is possible to build kernel on small embedded board, but that's
> > >> quite cumbersone, slow and inefficient, considering that it's just
> > >> easier to cross compile. But anyway, binding check does not even need
> > >> cross compilation.
> > >>
> > >> Sorry, the code is obviously wrong, there is no such thing as u32, so
> > >> you did not test it. I provided link which explains how to test it. You
> > >> must do it on latest mainline kernel. Just like you must develop and
> > >> generate patches on latest mainline kernel, because this is where we
> > >> apply the patches. We do not apply them to v6.6.
> > >
> > > The patches are based on the lastest mainline kernel.
> > > I do not understand why you think otherwise.
> >
> > Because you wrote:
> > "I run "make dt_binding_check" on kernel 6.6."
> >
> > The command is either part of build process or final check process
> > (static analyzers etc). If you say you did this on v6.6, you got such
> > response.
>
> I know you are NOT a service.
> The device tree is not the focus of my work.
> It should not be broken like that.
>
> I install dt-schema_2023.11-3_all.deb
> with Debian trixie
> I get:
>
> l
> SCHEMA Documentation/devicetree/bindings/processed-schema.json
> Traceback (most recent call last):
> File "/usr/bin/dt-mk-schema", line 8, in <module>
> sys.exit(main())
> ^^^^^^
> File "/usr/lib/python3/dist-packages/dtschema/mk_schema.py", line 28, in main
> schemas = dtschema.DTValidator(args.schemas).schemas
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "/usr/lib/python3/dist-packages/dtschema/validator.py", line
> 363, in __init__
> self.make_property_type_cache()
> File "/usr/lib/python3/dist-packages/dtschema/validator.py", line
> 420, in make_property_type_cache
> self.props, self.pat_props = get_prop_types(self.schemas)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "/usr/lib/python3/dist-packages/dtschema/validator.py", line
> 187, in get_prop_types
> del props[r'^[a-z][a-z0-9\-]*$']
> ~~~~~^^^^^^^^^^^^^^^^^^^^^^^
> KeyError: '^[a-z][a-z0-9\\-]*$'
> make[2]: *** [Documentation/devicetree/bindings/Makefile:64:
> Documentation/devicetree/bindings/processed-schema.json] Error 1
> make[2]: *** Deleting file
> 'Documentation/devicetree/bindings/processed-schema.json'
> make[1]: *** [/home/builder/kernel/Makefile:1435: dt_binding_schemas] Error 2
Have you considered that this might be because of the invalid types you
used?
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v4 3/5] dt-bindings: mtd: spi-nor: add OTP parameters
2024-09-17 20:39 ` Conor Dooley
@ 2024-09-17 21:29 ` Erez
2024-09-18 8:23 ` Krzysztof Kozlowski
0 siblings, 1 reply; 20+ messages in thread
From: Erez @ 2024-09-17 21:29 UTC (permalink / raw)
To: Conor Dooley
Cc: Krzysztof Kozlowski, Erez Geva, linux-mtd, Tudor Ambarus,
Pratyush Yadav, Michael Walle, linux-kernel, Miquel Raynal,
Richard Weinberger, Vignesh Raghavendra, devicetree, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Esben Haabendal
On Tue, 17 Sept 2024 at 22:39, Conor Dooley <conor@kernel.org> wrote:
>
> On Tue, Sep 17, 2024 at 08:39:48PM +0200, Erez wrote:
> > On Tue, 17 Sept 2024 at 19:32, Krzysztof Kozlowski <krzk@kernel.org> wrote:
> > >
> > > On 17/09/2024 19:24, Erez wrote:
> > > >>>>>>
> > > >>>>>> It does not look like you tested the bindings, at least after quick
> > > >>>>>> look. Please run `make dt_binding_check` (see
> > > >>>>>
> > > >>>>> I run "make dt_binding_check" on kernel 6.6.
> > > >>>>
> > > >>>> Yeah, we are no on kernel 6.6. You can run it also on kernel v4.1 -
> > > >>>> still does not matter.
> > > >>>>
> > > >>>> Don't develop on ancient code because then you ask us to review same
> > > >>>> broken stuff we already fixed.
> > > >>>
> > > >>> I test with Beaglebone black for testing, it is difficult to run the
> > > >>> last vanille version.
> > > >>> I did backport the spi-nor driver.
> > > >>> As for "make dt_binding_check" on last kernel, it need to upgrade the tools,
> > > >>> and I did not think it could change that much.
> > > >>>
> > > >>
> > > >> Well, it is possible to build kernel on small embedded board, but that's
> > > >> quite cumbersone, slow and inefficient, considering that it's just
> > > >> easier to cross compile. But anyway, binding check does not even need
> > > >> cross compilation.
> > > >>
> > > >> Sorry, the code is obviously wrong, there is no such thing as u32, so
> > > >> you did not test it. I provided link which explains how to test it. You
> > > >> must do it on latest mainline kernel. Just like you must develop and
> > > >> generate patches on latest mainline kernel, because this is where we
> > > >> apply the patches. We do not apply them to v6.6.
> > > >
> > > > The patches are based on the lastest mainline kernel.
> > > > I do not understand why you think otherwise.
> > >
> > > Because you wrote:
> > > "I run "make dt_binding_check" on kernel 6.6."
> > >
> > > The command is either part of build process or final check process
> > > (static analyzers etc). If you say you did this on v6.6, you got such
> > > response.
> >
> > I know you are NOT a service.
> > The device tree is not the focus of my work.
> > It should not be broken like that.
> >
> > I install dt-schema_2023.11-3_all.deb
> > with Debian trixie
> > I get:
> >
> > l
> > SCHEMA Documentation/devicetree/bindings/processed-schema.json
> > Traceback (most recent call last):
> > File "/usr/bin/dt-mk-schema", line 8, in <module>
> > sys.exit(main())
> > ^^^^^^
> > File "/usr/lib/python3/dist-packages/dtschema/mk_schema.py", line 28, in main
> > schemas = dtschema.DTValidator(args.schemas).schemas
> > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > File "/usr/lib/python3/dist-packages/dtschema/validator.py", line
> > 363, in __init__
> > self.make_property_type_cache()
> > File "/usr/lib/python3/dist-packages/dtschema/validator.py", line
> > 420, in make_property_type_cache
> > self.props, self.pat_props = get_prop_types(self.schemas)
> > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > File "/usr/lib/python3/dist-packages/dtschema/validator.py", line
> > 187, in get_prop_types
> > del props[r'^[a-z][a-z0-9\-]*$']
> > ~~~~~^^^^^^^^^^^^^^^^^^^^^^^
> > KeyError: '^[a-z][a-z0-9\\-]*$'
> > make[2]: *** [Documentation/devicetree/bindings/Makefile:64:
> > Documentation/devicetree/bindings/processed-schema.json] Error 1
> > make[2]: *** Deleting file
> > 'Documentation/devicetree/bindings/processed-schema.json'
> > make[1]: *** [/home/builder/kernel/Makefile:1435: dt_binding_schemas] Error 2
>
> Have you considered that this might be because of the invalid types you
> used?
I remove the types.
Anyway, scripts should report on errors, not crash.
This is the purpose of syntax scripts, to help us, developers find out errors.
Erez :-)
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v4 3/5] dt-bindings: mtd: spi-nor: add OTP parameters
2024-09-17 21:29 ` Erez
@ 2024-09-18 8:23 ` Krzysztof Kozlowski
2024-09-18 9:46 ` Erez
0 siblings, 1 reply; 20+ messages in thread
From: Krzysztof Kozlowski @ 2024-09-18 8:23 UTC (permalink / raw)
To: Erez, Conor Dooley
Cc: Erez Geva, linux-mtd, Tudor Ambarus, Pratyush Yadav,
Michael Walle, linux-kernel, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, devicetree, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Esben Haabendal
On 17/09/2024 23:29, Erez wrote:
>>>
>>> I install dt-schema_2023.11-3_all.deb
>>> with Debian trixie
>>> I get:
>>>
>>> l
>>> SCHEMA Documentation/devicetree/bindings/processed-schema.json
>>> Traceback (most recent call last):
>>> File "/usr/bin/dt-mk-schema", line 8, in <module>
>>> sys.exit(main())
>>> ^^^^^^
>>> File "/usr/lib/python3/dist-packages/dtschema/mk_schema.py", line 28, in main
>>> schemas = dtschema.DTValidator(args.schemas).schemas
>>> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>> File "/usr/lib/python3/dist-packages/dtschema/validator.py", line
>>> 363, in __init__
>>> self.make_property_type_cache()
>>> File "/usr/lib/python3/dist-packages/dtschema/validator.py", line
>>> 420, in make_property_type_cache
>>> self.props, self.pat_props = get_prop_types(self.schemas)
>>> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>> File "/usr/lib/python3/dist-packages/dtschema/validator.py", line
>>> 187, in get_prop_types
>>> del props[r'^[a-z][a-z0-9\-]*$']
>>> ~~~~~^^^^^^^^^^^^^^^^^^^^^^^
>>> KeyError: '^[a-z][a-z0-9\\-]*$'
>>> make[2]: *** [Documentation/devicetree/bindings/Makefile:64:
>>> Documentation/devicetree/bindings/processed-schema.json] Error 1
>>> make[2]: *** Deleting file
>>> 'Documentation/devicetree/bindings/processed-schema.json'
>>> make[1]: *** [/home/builder/kernel/Makefile:1435: dt_binding_schemas] Error 2
>>
>> Have you considered that this might be because of the invalid types you
>> used?
>
> I remove the types.
> Anyway, scripts should report on errors, not crash.
> This is the purpose of syntax scripts, to help us, developers find out errors.
Yeah, things can be improved. Help in that is always welcomed.
The package you installed is very old (almost a year old!). I suggest
using pip or pipx (or virtualenv or whatever Python setup you have).
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v4 3/5] dt-bindings: mtd: spi-nor: add OTP parameters
2024-09-18 8:23 ` Krzysztof Kozlowski
@ 2024-09-18 9:46 ` Erez
0 siblings, 0 replies; 20+ messages in thread
From: Erez @ 2024-09-18 9:46 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Conor Dooley, Erez Geva, linux-mtd, Tudor Ambarus, Pratyush Yadav,
Michael Walle, linux-kernel, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, devicetree, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Esben Haabendal
On Wed, 18 Sept 2024 at 10:23, Krzysztof Kozlowski <krzk@kernel.org> wrote:
>
> On 17/09/2024 23:29, Erez wrote:
> >>>
> >>> I install dt-schema_2023.11-3_all.deb
> >>> with Debian trixie
> >>> I get:
> >>>
> >>> l
> >>> SCHEMA Documentation/devicetree/bindings/processed-schema.json
> >>> Traceback (most recent call last):
> >>> File "/usr/bin/dt-mk-schema", line 8, in <module>
> >>> sys.exit(main())
> >>> ^^^^^^
> >>> File "/usr/lib/python3/dist-packages/dtschema/mk_schema.py", line 28, in main
> >>> schemas = dtschema.DTValidator(args.schemas).schemas
> >>> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >>> File "/usr/lib/python3/dist-packages/dtschema/validator.py", line
> >>> 363, in __init__
> >>> self.make_property_type_cache()
> >>> File "/usr/lib/python3/dist-packages/dtschema/validator.py", line
> >>> 420, in make_property_type_cache
> >>> self.props, self.pat_props = get_prop_types(self.schemas)
> >>> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >>> File "/usr/lib/python3/dist-packages/dtschema/validator.py", line
> >>> 187, in get_prop_types
> >>> del props[r'^[a-z][a-z0-9\-]*$']
> >>> ~~~~~^^^^^^^^^^^^^^^^^^^^^^^
> >>> KeyError: '^[a-z][a-z0-9\\-]*$'
> >>> make[2]: *** [Documentation/devicetree/bindings/Makefile:64:
> >>> Documentation/devicetree/bindings/processed-schema.json] Error 1
> >>> make[2]: *** Deleting file
> >>> 'Documentation/devicetree/bindings/processed-schema.json'
> >>> make[1]: *** [/home/builder/kernel/Makefile:1435: dt_binding_schemas] Error 2
> >>
> >> Have you considered that this might be because of the invalid types you
> >> used?
> >
> > I remove the types.
> > Anyway, scripts should report on errors, not crash.
> > This is the purpose of syntax scripts, to help us, developers find out errors.
>
> Yeah, things can be improved. Help in that is always welcomed.
>
> The package you installed is very old (almost a year old!). I suggest
Debian tend to be old and stable (althguh this packages comes from sid).
> using pip or pipx (or virtualenv or whatever Python setup you have).
I'll try.
Though I am not a python developer. I usually do not use pip.
I did see a version checking:
$ make dt_binding_check
sort: -:2: disorder: 2022.08.2
ERROR: dtschema minimum version is v2023.9
Thanks
Erez
>
> Best regards,
> Krzysztof
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v4 4/5] mtd: spi-nor: macronix: add support for OTP
2024-09-17 9:49 [PATCH v4 0/5] Add support for SPI-NOR Macronix OTP Erez Geva
` (2 preceding siblings ...)
2024-09-17 9:49 ` [PATCH v4 3/5] dt-bindings: mtd: spi-nor: add OTP parameters Erez Geva
@ 2024-09-17 9:49 ` Erez Geva
2024-09-17 10:32 ` Erez
2024-09-17 9:49 ` [PATCH v4 5/5] mtd: spi-nor: macronix: add manufacturer flags Erez Geva
4 siblings, 1 reply; 20+ messages in thread
From: Erez Geva @ 2024-09-17 9:49 UTC (permalink / raw)
To: linux-mtd, Tudor Ambarus, Pratyush Yadav, Michael Walle
Cc: linux-kernel, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, devicetree, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Esben Haabendal, Erez Geva
From: Erez Geva <ErezGeva2@gmail.com>
Macronix SPI-NOR support OTP.
Add callbacks to read, write and lock the OTP.
Notice Macronix OTP do not support erase.
Every bit written with '0', can not be changed further.
Notice Macronix OTP do not support single region lock!
The locking include all regions at once!
Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
---
drivers/mtd/spi-nor/macronix.c | 167 +++++++++++++++++++++++++++++++++
include/linux/mtd/spi-nor.h | 9 ++
2 files changed, 176 insertions(+)
diff --git a/drivers/mtd/spi-nor/macronix.c b/drivers/mtd/spi-nor/macronix.c
index ea6be95e75a5..02aa844d641b 100644
--- a/drivers/mtd/spi-nor/macronix.c
+++ b/drivers/mtd/spi-nor/macronix.c
@@ -8,6 +8,162 @@
#include "core.h"
+/**
+ * macronix_nor_otp_enter() - Send Enter Secured OTP instruction to the chip.
+ * @nor: pointer to 'struct spi_nor'.
+ *
+ * Return: 0 on success, -errno otherwise.
+ */
+static int macronix_nor_otp_enter(struct spi_nor *nor)
+{
+ int error;
+
+ error = spi_nor_send_cmd(nor, SPINOR_OP_ENSO);
+ if (error)
+ dev_dbg(nor->dev, "error %d on Macronix Enter Secured OTP\n", error);
+
+ return error;
+}
+
+/**
+ * macronix_nor_otp_exit() - Send Exit Secured OTP instruction to the chip.
+ * @nor: pointer to 'struct spi_nor'.
+ *
+ * Return: 0 on success, -errno otherwise.
+ */
+static int macronix_nor_otp_exit(struct spi_nor *nor)
+{
+ int error;
+
+ error = spi_nor_send_cmd(nor, SPINOR_OP_EXSO);
+ if (error)
+ dev_dbg(nor->dev, "error %d on Macronix Exit Secured OTP\n", error);
+
+ return error;
+}
+
+/**
+ * macronix_nor_otp_read() - read security register
+ * @nor: pointer to 'struct spi_nor'
+ * @addr: offset to read from
+ * @len: number of bytes to read
+ * @buf: pointer to dst buffer
+ *
+ * Return: number of bytes read successfully, -errno otherwise
+ */
+static int macronix_nor_otp_read(struct spi_nor *nor, loff_t addr, size_t len, u8 *buf)
+{
+ int ret, error;
+
+ error = macronix_nor_otp_enter(nor);
+ if (error)
+ return error;
+
+ ret = spi_nor_read_data(nor, addr, len, buf);
+
+ error = macronix_nor_otp_exit(nor);
+
+ if (ret < 0)
+ dev_dbg(nor->dev, "error %d on Macronix read OTP data\n", ret);
+ else if (error)
+ return error;
+
+ return ret;
+}
+
+/**
+ * macronix_nor_otp_write() - write security register
+ * @nor: pointer to 'struct spi_nor'
+ * @addr: offset to write to
+ * @len: number of bytes to write
+ * @buf: pointer to src buffer
+ *
+ * Return: number of bytes written successfully, -errno otherwise
+ */
+static int macronix_nor_otp_write(struct spi_nor *nor, loff_t addr, size_t len, const u8 *buf)
+{
+ int error, ret = 0;
+
+ error = macronix_nor_otp_enter(nor);
+ if (error)
+ return error;
+
+ error = spi_nor_write_enable(nor);
+ if (error)
+ goto otp_write_err;
+
+ ret = spi_nor_write_data(nor, addr, len, buf);
+ if (ret < 0) {
+ dev_dbg(nor->dev, "error %d on Macronix write OTP data\n", ret);
+ goto otp_write_err;
+ }
+
+ error = spi_nor_wait_till_ready(nor);
+ if (error)
+ dev_dbg(nor->dev, "error %d on Macronix waiting write OTP finish\n", error);
+
+otp_write_err:
+
+ error = macronix_nor_otp_exit(nor);
+
+ return ret;
+}
+
+/**
+ * macronix_nor_otp_lock() - lock the OTP region
+ * @nor: pointer to 'struct spi_nor'
+ * @region: OTP region
+ *
+ * Return: 0 on success, -errno otherwise.
+ */
+static int macronix_nor_otp_lock(struct spi_nor *nor, unsigned int region)
+{
+ int error;
+ u8 *rdscur = nor->bouncebuf;
+
+ error = spi_nor_read_reg(nor, SPINOR_OP_RDSCUR, 1);
+ if (error) {
+ dev_dbg(nor->dev, "error %d on read security register\n", error);
+ return error;
+ }
+
+ if (rdscur[0] & SEC_REG_LDSO)
+ return 0;
+
+ error = spi_nor_write_enable(nor);
+ if (error) {
+ dev_dbg(nor->dev, "error %d on enable write before update security register\n",
+ error);
+ return error;
+ }
+
+ error = spi_nor_send_cmd(nor, SPINOR_OP_WRSCUR);
+ if (error)
+ dev_dbg(nor->dev, "error %d on update security register\n", error);
+
+ return error;
+}
+
+/**
+ * macronix_nor_otp_is_locked() - get the OTP region lock status
+ * @nor: pointer to 'struct spi_nor'
+ * @region: OTP region
+ *
+ * Return: 1 on lock, 0 on not locked, -errno otherwise.
+ */
+static int macronix_nor_otp_is_locked(struct spi_nor *nor, unsigned int region)
+{
+ int error;
+ u8 *rdscur = nor->bouncebuf;
+
+ error = spi_nor_read_reg(nor, SPINOR_OP_RDSCUR, 1);
+ if (error) {
+ dev_dbg(nor->dev, "error %d on read security register\n", error);
+ return error;
+ }
+ return rdscur[0] & SEC_REG_LDSO ? 1 : 0;
+}
+
static int
mx25l25635_post_bfpt_fixups(struct spi_nor *nor,
const struct sfdp_parameter_header *bfpt_header,
@@ -190,8 +346,19 @@ static void macronix_nor_default_init(struct spi_nor *nor)
nor->params->quad_enable = spi_nor_sr1_bit6_quad_enable;
}
+static const struct spi_nor_otp_ops macronix_nor_otp_ops = {
+ .read = macronix_nor_otp_read,
+ .write = macronix_nor_otp_write,
+ /* .erase = Macronix OTP do not support erase, */
+ .lock = macronix_nor_otp_lock,
+ .is_locked = macronix_nor_otp_is_locked,
+};
+
static int macronix_nor_late_init(struct spi_nor *nor)
{
+ if (nor->params->otp.org.n_regions)
+ nor->params->otp.ops = ¯onix_nor_otp_ops;
+
if (!nor->params->set_4byte_addr_mode)
nor->params->set_4byte_addr_mode = spi_nor_set_4byte_addr_mode_en4b_ex4b;
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index cdcfe0fd2e7d..ef834e7fc0ac 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -81,6 +81,15 @@
#define SPINOR_OP_BP 0x02 /* Byte program */
#define SPINOR_OP_AAI_WP 0xad /* Auto address increment word program */
+/* Macronix OTP registers. */
+#define SPINOR_OP_RDSCUR 0x2b /* read security register */
+#define SPINOR_OP_WRSCUR 0x2f /* write security register */
+#define SPINOR_OP_ENSO 0xb1 /* enter secured OTP */
+#define SPINOR_OP_EXSO 0xc1 /* exit secured OTP */
+
+/* Macronix security register values */
+#define SEC_REG_LDSO BIT(1) /* Lock-down Secured OTP */
+
/* Used for Macronix and Winbond flashes. */
#define SPINOR_OP_EN4B 0xb7 /* Enter 4-byte mode */
#define SPINOR_OP_EX4B 0xe9 /* Exit 4-byte mode */
--
2.39.5
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH v4 4/5] mtd: spi-nor: macronix: add support for OTP
2024-09-17 9:49 ` [PATCH v4 4/5] mtd: spi-nor: macronix: add support for OTP Erez Geva
@ 2024-09-17 10:32 ` Erez
0 siblings, 0 replies; 20+ messages in thread
From: Erez @ 2024-09-17 10:32 UTC (permalink / raw)
To: Erez Geva
Cc: linux-mtd, Tudor Ambarus, Pratyush Yadav, Michael Walle,
linux-kernel, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, devicetree, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Esben Haabendal
On Tue, 17 Sept 2024 at 11:50, Erez Geva <erezgeva@nwtime.org> wrote:
>
> From: Erez Geva <ErezGeva2@gmail.com>
>
> Macronix SPI-NOR support OTP.
> Add callbacks to read, write and lock the OTP.
>
> Notice Macronix OTP do not support erase.
> Every bit written with '0', can not be changed further.
>
> Notice Macronix OTP do not support single region lock!
> The locking includes all regions at once!
>
> Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
> ---
> drivers/mtd/spi-nor/macronix.c | 167 +++++++++++++++++++++++++++++++++
> include/linux/mtd/spi-nor.h | 9 ++
> 2 files changed, 176 insertions(+)
>
> diff --git a/drivers/mtd/spi-nor/macronix.c b/drivers/mtd/spi-nor/macronix.c
> index ea6be95e75a5..02aa844d641b 100644
> --- a/drivers/mtd/spi-nor/macronix.c
> +++ b/drivers/mtd/spi-nor/macronix.c
> @@ -8,6 +8,162 @@
>
> #include "core.h"
>
> +/**
> + * macronix_nor_otp_enter() - Send Enter Secured OTP instruction to the chip.
> + * @nor: pointer to 'struct spi_nor'.
> + *
> + * Return: 0 on success, -errno otherwise.
> + */
> +static int macronix_nor_otp_enter(struct spi_nor *nor)
> +{
> + int error;
> +
> + error = spi_nor_send_cmd(nor, SPINOR_OP_ENSO);
> + if (error)
> + dev_dbg(nor->dev, "error %d on Macronix Enter Secured OTP\n", error);
> +
> + return error;
> +}
> +
> +/**
> + * macronix_nor_otp_exit() - Send Exit Secured OTP instruction to the chip.
> + * @nor: pointer to 'struct spi_nor'.
> + *
> + * Return: 0 on success, -errno otherwise.
> + */
> +static int macronix_nor_otp_exit(struct spi_nor *nor)
> +{
> + int error;
> +
> + error = spi_nor_send_cmd(nor, SPINOR_OP_EXSO);
> + if (error)
> + dev_dbg(nor->dev, "error %d on Macronix Exit Secured OTP\n", error);
> +
> + return error;
> +}
> +
> +/**
> + * macronix_nor_otp_read() - read security register
Sorry, it should be "read OTP data".
> + * @nor: pointer to 'struct spi_nor'
> + * @addr: offset to read from
> + * @len: number of bytes to read
> + * @buf: pointer to dst buffer
> + *
> + * Return: number of bytes read successfully, -errno otherwise
> + */
> +static int macronix_nor_otp_read(struct spi_nor *nor, loff_t addr, size_t len, u8 *buf)
> +{
> + int ret, error;
> +
> + error = macronix_nor_otp_enter(nor);
> + if (error)
> + return error;
> +
> + ret = spi_nor_read_data(nor, addr, len, buf);
> +
> + error = macronix_nor_otp_exit(nor);
> +
> + if (ret < 0)
> + dev_dbg(nor->dev, "error %d on Macronix read OTP data\n", ret);
> + else if (error)
> + return error;
> +
> + return ret;
> +}
> +
> +/**
> + * macronix_nor_otp_write() - write security register
Sorry, it should be "write data to OTP".
> + * @nor: pointer to 'struct spi_nor'
> + * @addr: offset to write to
> + * @len: number of bytes to write
> + * @buf: pointer to src buffer
> + *
> + * Return: number of bytes written successfully, -errno otherwise
> + */
> +static int macronix_nor_otp_write(struct spi_nor *nor, loff_t addr, size_t len, const u8 *buf)
> +{
> + int error, ret = 0;
> +
> + error = macronix_nor_otp_enter(nor);
> + if (error)
> + return error;
> +
> + error = spi_nor_write_enable(nor);
> + if (error)
> + goto otp_write_err;
> +
> + ret = spi_nor_write_data(nor, addr, len, buf);
> + if (ret < 0) {
> + dev_dbg(nor->dev, "error %d on Macronix write OTP data\n", ret);
> + goto otp_write_err;
> + }
> +
> + error = spi_nor_wait_till_ready(nor);
> + if (error)
> + dev_dbg(nor->dev, "error %d on Macronix waiting write OTP finish\n", error);
> +
> +otp_write_err:
> +
> + error = macronix_nor_otp_exit(nor);
> +
> + return ret;
> +}
> +
> +/**
> + * macronix_nor_otp_lock() - lock the OTP region
> + * @nor: pointer to 'struct spi_nor'
> + * @region: OTP region
> + *
> + * Return: 0 on success, -errno otherwise.
> + */
> +static int macronix_nor_otp_lock(struct spi_nor *nor, unsigned int region)
> +{
> + int error;
> + u8 *rdscur = nor->bouncebuf;
> +
> + error = spi_nor_read_reg(nor, SPINOR_OP_RDSCUR, 1);
> + if (error) {
> + dev_dbg(nor->dev, "error %d on read security register\n", error);
> + return error;
> + }
> +
> + if (rdscur[0] & SEC_REG_LDSO)
> + return 0;
> +
> + error = spi_nor_write_enable(nor);
> + if (error) {
> + dev_dbg(nor->dev, "error %d on enable write before update security register\n",
> + error);
> + return error;
> + }
> +
> + error = spi_nor_send_cmd(nor, SPINOR_OP_WRSCUR);
> + if (error)
> + dev_dbg(nor->dev, "error %d on update security register\n", error);
> +
> + return error;
> +}
> +
> +/**
> + * macronix_nor_otp_is_locked() - get the OTP region lock status
> + * @nor: pointer to 'struct spi_nor'
> + * @region: OTP region
> + *
> + * Return: 1 on lock, 0 on not locked, -errno otherwise.
> + */
> +static int macronix_nor_otp_is_locked(struct spi_nor *nor, unsigned int region)
> +{
> + int error;
> + u8 *rdscur = nor->bouncebuf;
> +
> + error = spi_nor_read_reg(nor, SPINOR_OP_RDSCUR, 1);
> + if (error) {
> + dev_dbg(nor->dev, "error %d on read security register\n", error);
> + return error;
> + }
> + return rdscur[0] & SEC_REG_LDSO ? 1 : 0;
> +}
> +
> static int
> mx25l25635_post_bfpt_fixups(struct spi_nor *nor,
> const struct sfdp_parameter_header *bfpt_header,
> @@ -190,8 +346,19 @@ static void macronix_nor_default_init(struct spi_nor *nor)
> nor->params->quad_enable = spi_nor_sr1_bit6_quad_enable;
> }
>
> +static const struct spi_nor_otp_ops macronix_nor_otp_ops = {
> + .read = macronix_nor_otp_read,
> + .write = macronix_nor_otp_write,
> + /* .erase = Macronix OTP do not support erase, */
> + .lock = macronix_nor_otp_lock,
> + .is_locked = macronix_nor_otp_is_locked,
> +};
> +
> static int macronix_nor_late_init(struct spi_nor *nor)
> {
> + if (nor->params->otp.org.n_regions)
> + nor->params->otp.ops = ¯onix_nor_otp_ops;
> +
> if (!nor->params->set_4byte_addr_mode)
> nor->params->set_4byte_addr_mode = spi_nor_set_4byte_addr_mode_en4b_ex4b;
>
> diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
> index cdcfe0fd2e7d..ef834e7fc0ac 100644
> --- a/include/linux/mtd/spi-nor.h
> +++ b/include/linux/mtd/spi-nor.h
> @@ -81,6 +81,15 @@
> #define SPINOR_OP_BP 0x02 /* Byte program */
> #define SPINOR_OP_AAI_WP 0xad /* Auto address increment word program */
>
> +/* Macronix OTP registers. */
> +#define SPINOR_OP_RDSCUR 0x2b /* read security register */
> +#define SPINOR_OP_WRSCUR 0x2f /* write security register */
> +#define SPINOR_OP_ENSO 0xb1 /* enter secured OTP */
> +#define SPINOR_OP_EXSO 0xc1 /* exit secured OTP */
> +
> +/* Macronix security register values */
> +#define SEC_REG_LDSO BIT(1) /* Lock-down Secured OTP */
> +
> /* Used for Macronix and Winbond flashes. */
> #define SPINOR_OP_EN4B 0xb7 /* Enter 4-byte mode */
> #define SPINOR_OP_EX4B 0xe9 /* Exit 4-byte mode */
> --
> 2.39.5
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v4 5/5] mtd: spi-nor: macronix: add manufacturer flags
2024-09-17 9:49 [PATCH v4 0/5] Add support for SPI-NOR Macronix OTP Erez Geva
` (3 preceding siblings ...)
2024-09-17 9:49 ` [PATCH v4 4/5] mtd: spi-nor: macronix: add support for OTP Erez Geva
@ 2024-09-17 9:49 ` Erez Geva
4 siblings, 0 replies; 20+ messages in thread
From: Erez Geva @ 2024-09-17 9:49 UTC (permalink / raw)
To: linux-mtd, Tudor Ambarus, Pratyush Yadav, Michael Walle
Cc: linux-kernel, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, devicetree, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Esben Haabendal, Erez Geva
From: Erez Geva <ErezGeva2@gmail.com>
Add flag for always trying reading SFDP:
All new chips from Macronix support SFDP.
All old chips in the IDs table were reused by new chips.
Add flag for reading OTP parameters from device tree.
As Macronix reuse JEDEC IDs, there is no way to determine OTP parameters.
Allow users to define the OTP parameters in device tree.
Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
---
Notes:
* My initial Macronix OTP code was tested with MX25l12833F.
* As I no longer have that hardware.
* I now testing with MX25L3233F connected to my BeagleBone Black
* through an 8-PIN SOP (200mil).
* The BeagleBone Black runs with Debian GNU/Linux 12.
* And use Kernel 6.6.32-ti-arm32-r5 build with
* arm-linux-gnueabihf-gcc gcc version 12.2.0 (Debian 12.2.0-14).
$ cat /sys/bus/spi/devices/spi0.0/spi-nor/jedec_id
c22016
$ cat /sys/bus/spi/devices/spi0.0/spi-nor/manufacturer
macronix
$ cat /sys/bus/spi/devices/spi0.0/spi-nor/partname
mx25l3205d
$ xxd -p /sys/bus/spi/devices/spi0.0/spi-nor/sfdp
53464450000101ff00000109300000ffc2000104600000ffffffffffffff
ffffffffffffffffffffffffffffffffffffe520f1ffffffff0144eb086b
083b04bbeeffffffffff00ffffff00ff0c200f5210d800ffffffffffffff
ffffffffffff003650269ef97764fecfffffffffffff
$ sha256sum /sys/bus/spi/devices/spi0.0/spi-nor/sfdp
22d5d34af77c3628300056a0fc4bfbeafa027f544998852cf27f7cebf7881196 /sys/bus/spi/devices/spi0.0/spi-nor/sfdp
$ cat /sys/kernel/debug/spi-nor/spi0.0/capabilities
Supported read modes by the flash
1S-1S-1S
opcode 0x03
mode cycles 0
dummy cycles 0
1S-1S-2S
opcode 0x3b
mode cycles 0
dummy cycles 8
1S-2S-2S
opcode 0xbb
mode cycles 0
dummy cycles 4
1S-1S-4S
opcode 0x6b
mode cycles 0
dummy cycles 8
1S-4S-4S
opcode 0xeb
mode cycles 2
dummy cycles 4
Supported page program modes by the flash
1S-1S-1S
opcode 0x02
$ cat /sys/kernel/debug/spi-nor/spi0.0/params
name mx25l3205d
id c2 20 16 c2 20 16
size 4.00 MiB
write size 1
page size 256
address nbytes 3
flags HAS_16BIT_SR
opcodes
read 0x03
dummy cycles 0
erase 0x20
program 0x02
8D extension none
protocols
read 1S-1S-1S
write 1S-1S-1S
register 1S-1S-1S
erase commands
20 (4.00 KiB) [1]
52 (32.0 KiB) [2]
d8 (64.0 KiB) [3]
c7 (4.00 MiB)
sector map
region (in hex) | erase mask | flags
------------------+------------+----------
00000000-003fffff | [ 123] |
# mtd_debug info /dev/mtd0
mtd.type = MTD_NORFLASH
mtd.flags = MTD_CAP_NORFLASH
mtd.size = 4194304 (4M)
mtd.erasesize = 4096 (4K)
mtd.writesize = 1
mtd.oobsize = 0
regions = 0
* The BeagleBone Black SPI is very slow, Tests are slow.
# dd if=/dev/urandom of=./spi_test bs=1M count=2
2+0 records in
2+0 records out
2097152 bytes (2.1 MB, 2.0 MiB) copied, 0.0682607 s, 30.7 MB/s
# time mtd_debug erase /dev/mtd0 0 2097152
Erased 2097152 bytes from address 0x00000000 in flash
real 0m12.703s
user 0m0.000s
sys 0m12.692s
# time mtd_debug read /dev/mtd0 0 2097152 spi_read
Copied 2097152 bytes from address 0x00000000 in flash to spi_read
real 0m1.942s
user 0m0.000s
sys 0m0.053s
# hexdump spi_read
0000000 ffff ffff ffff ffff ffff ffff ffff ffff
*
0200000
# sha256sum spi_read
4bda3a28f4ffe603c0ec1258c0034d65a1a0d35ab7bd523a834608adabf03cc5 spi_read
# time mtd_debug write /dev/mtd0 0 2097152 spi_test
Copied 2097152 bytes from spi_test to address 0x00000000 in flash
real 0m5.883s
user 0m0.006s
sys 0m3.970s
# time mtd_debug read /dev/mtd0 0 2097152 spi_read
Copied 2097152 bytes from address 0x00000000 in flash to spi_read
real 0m2.208s
user 0m0.003s
sys 0m0.063s
# sha256sum spi*
f4f5d1d0a4fef487037cdb3f1be0f9aab68ca32f2dbe8782c927f03adf623ec3 spi_read
f4f5d1d0a4fef487037cdb3f1be0f9aab68ca32f2dbe8782c927f03adf623ec3 spi_test
# time mtd_debug erase /dev/mtd0 0 2097152
Erased 2097152 bytes from address 0x00000000 in flash
real 0m12.126s
user 0m0.001s
sys 0m12.115s
# time mtd_debug read /dev/mtd0 0 2097152 spi_read
Copied 2097152 bytes from address 0x00000000 in flash to spi_read
real 0m2.611s
user 0m0.000s
sys 0m0.064s
# sha256sum spi*
4bda3a28f4ffe603c0ec1258c0034d65a1a0d35ab7bd523a834608adabf03cc5 spi_read
f4f5d1d0a4fef487037cdb3f1be0f9aab68ca32f2dbe8782c927f03adf623ec3 spi_test
* MX25L3233F OTP uses 1 region of size of 4096 bits
$ git diff -U1
diff --git a/arch/arm/boot/dts/ti/omap/BB-SPINOR-00A0.dtso b/arch/arm/boot/dts/ti/omap/BB-SPINOR-00A0.dtso
index 333a6b9556ed..adaddfaa8091 100644
--- a/arch/arm/boot/dts/ti/omap/BB-SPINOR-00A0.dtso
+++ b/arch/arm/boot/dts/ti/omap/BB-SPINOR-00A0.dtso
@@ -63,6 +63,8 @@ channel@0 {
compatible = "jedec,spi-nor";
+ otp_len = <512>;
+ opt_n_regions = <1>;
# flash_otp_info -u /dev/mtd0
Number of OTP user blocks on /dev/mtd0: 1
block 0: offset = 0x0000 size = 512 bytes [unlocked]
# flash_otp_dump -u /dev/mtd0
OTP user data for /dev/mtd0
0x0000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x0010: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x0020: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x0030: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x0040: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x0050: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x0060: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x0070: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x0080: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x0090: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x00a0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x00b0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x00c0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x00d0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x00e0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x00f0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x0100: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x0110: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x0120: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x0130: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x0140: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x0150: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x0160: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x0170: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x0180: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x0190: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x01a0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x01b0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x01c0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x01d0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x01e0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0x01f0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
* Macronix OTP does not support erase!
* flash_otp_erase
# printf '\xde\xad%.0s' {1..256} | flash_otp_write -u /dev/mtd0 0
Writing OTP user data on /dev/mtd0 at offset 0x0
Wrote 512 bytes of OTP user data
# flash_otp_dump -u /dev/mtd0
OTP user data for /dev/mtd0
0x0000: de ad de ad de ad de ad de ad de ad de ad de ad
0x0010: de ad de ad de ad de ad de ad de ad de ad de ad
0x0020: de ad de ad de ad de ad de ad de ad de ad de ad
0x0030: de ad de ad de ad de ad de ad de ad de ad de ad
0x0040: de ad de ad de ad de ad de ad de ad de ad de ad
0x0050: de ad de ad de ad de ad de ad de ad de ad de ad
0x0060: de ad de ad de ad de ad de ad de ad de ad de ad
0x0070: de ad de ad de ad de ad de ad de ad de ad de ad
0x0080: de ad de ad de ad de ad de ad de ad de ad de ad
0x0090: de ad de ad de ad de ad de ad de ad de ad de ad
0x00a0: de ad de ad de ad de ad de ad de ad de ad de ad
0x00b0: de ad de ad de ad de ad de ad de ad de ad de ad
0x00c0: de ad de ad de ad de ad de ad de ad de ad de ad
0x00d0: de ad de ad de ad de ad de ad de ad de ad de ad
0x00e0: de ad de ad de ad de ad de ad de ad de ad de ad
0x00f0: de ad de ad de ad de ad de ad de ad de ad de ad
0x0100: de ad de ad de ad de ad de ad de ad de ad de ad
0x0110: de ad de ad de ad de ad de ad de ad de ad de ad
0x0120: de ad de ad de ad de ad de ad de ad de ad de ad
0x0130: de ad de ad de ad de ad de ad de ad de ad de ad
0x0140: de ad de ad de ad de ad de ad de ad de ad de ad
0x0150: de ad de ad de ad de ad de ad de ad de ad de ad
0x0160: de ad de ad de ad de ad de ad de ad de ad de ad
0x0170: de ad de ad de ad de ad de ad de ad de ad de ad
0x0180: de ad de ad de ad de ad de ad de ad de ad de ad
0x0190: de ad de ad de ad de ad de ad de ad de ad de ad
0x01a0: de ad de ad de ad de ad de ad de ad de ad de ad
0x01b0: de ad de ad de ad de ad de ad de ad de ad de ad
0x01c0: de ad de ad de ad de ad de ad de ad de ad de ad
0x01d0: de ad de ad de ad de ad de ad de ad de ad de ad
0x01e0: de ad de ad de ad de ad de ad de ad de ad de ad
0x01f0: de ad de ad de ad de ad de ad de ad de ad de ad
# flash_otp_info -u /dev/mtd0
Number of OTP user blocks on /dev/mtd0: 1
block 0: offset = 0x0000 size = 512 bytes [unlocked]
# printf '\xff\xff%.0s' {1..256} | flash_otp_write -u /dev/mtd0 0
Writing OTP user data on /dev/mtd0 at offset 0x0
Wrote 512 bytes of OTP user data
# We cannot overwrite '0' with '1'!
# flash_otp_dump -u /dev/mtd0
OTP user data for /dev/mtd0
0x0000: de ad de ad de ad de ad de ad de ad de ad de ad
0x0010: de ad de ad de ad de ad de ad de ad de ad de ad
0x0020: de ad de ad de ad de ad de ad de ad de ad de ad
0x0030: de ad de ad de ad de ad de ad de ad de ad de ad
0x0040: de ad de ad de ad de ad de ad de ad de ad de ad
0x0050: de ad de ad de ad de ad de ad de ad de ad de ad
0x0060: de ad de ad de ad de ad de ad de ad de ad de ad
0x0070: de ad de ad de ad de ad de ad de ad de ad de ad
0x0080: de ad de ad de ad de ad de ad de ad de ad de ad
0x0090: de ad de ad de ad de ad de ad de ad de ad de ad
0x00a0: de ad de ad de ad de ad de ad de ad de ad de ad
0x00b0: de ad de ad de ad de ad de ad de ad de ad de ad
0x00c0: de ad de ad de ad de ad de ad de ad de ad de ad
0x00d0: de ad de ad de ad de ad de ad de ad de ad de ad
0x00e0: de ad de ad de ad de ad de ad de ad de ad de ad
0x00f0: de ad de ad de ad de ad de ad de ad de ad de ad
0x0100: de ad de ad de ad de ad de ad de ad de ad de ad
0x0110: de ad de ad de ad de ad de ad de ad de ad de ad
0x0120: de ad de ad de ad de ad de ad de ad de ad de ad
0x0130: de ad de ad de ad de ad de ad de ad de ad de ad
0x0140: de ad de ad de ad de ad de ad de ad de ad de ad
0x0150: de ad de ad de ad de ad de ad de ad de ad de ad
0x0160: de ad de ad de ad de ad de ad de ad de ad de ad
0x0170: de ad de ad de ad de ad de ad de ad de ad de ad
0x0180: de ad de ad de ad de ad de ad de ad de ad de ad
0x0190: de ad de ad de ad de ad de ad de ad de ad de ad
0x01a0: de ad de ad de ad de ad de ad de ad de ad de ad
0x01b0: de ad de ad de ad de ad de ad de ad de ad de ad
0x01c0: de ad de ad de ad de ad de ad de ad de ad de ad
0x01d0: de ad de ad de ad de ad de ad de ad de ad de ad
0x01e0: de ad de ad de ad de ad de ad de ad de ad de ad
0x01f0: de ad de ad de ad de ad de ad de ad de ad de ad
# flash_otp_lock -u /dev/mtd0 0 512
About to lock OTP user data on /dev/mtd0 from 0x0 to 0x200
flash_otp_lock: Are you sure? (y/N) y
Done.
# flash_otp_info -u /dev/mtd0
Number of OTP user blocks on /dev/mtd0: 1
block 0: offset = 0x0000 size = 512 bytes [locked]
# printf '\x00\x00%.0s' {1..256} | flash_otp_write -u /dev/mtd0 0
Writing OTP user data on /dev/mtd0 at offset 0x0
write(): Read-only file system
# flash_otp_dump -u /dev/mtd0
OTP user data for /dev/mtd0
0x0000: de ad de ad de ad de ad de ad de ad de ad de ad
0x0010: de ad de ad de ad de ad de ad de ad de ad de ad
0x0020: de ad de ad de ad de ad de ad de ad de ad de ad
0x0030: de ad de ad de ad de ad de ad de ad de ad de ad
0x0040: de ad de ad de ad de ad de ad de ad de ad de ad
0x0050: de ad de ad de ad de ad de ad de ad de ad de ad
0x0060: de ad de ad de ad de ad de ad de ad de ad de ad
0x0070: de ad de ad de ad de ad de ad de ad de ad de ad
0x0080: de ad de ad de ad de ad de ad de ad de ad de ad
0x0090: de ad de ad de ad de ad de ad de ad de ad de ad
0x00a0: de ad de ad de ad de ad de ad de ad de ad de ad
0x00b0: de ad de ad de ad de ad de ad de ad de ad de ad
0x00c0: de ad de ad de ad de ad de ad de ad de ad de ad
0x00d0: de ad de ad de ad de ad de ad de ad de ad de ad
0x00e0: de ad de ad de ad de ad de ad de ad de ad de ad
0x00f0: de ad de ad de ad de ad de ad de ad de ad de ad
0x0100: de ad de ad de ad de ad de ad de ad de ad de ad
0x0110: de ad de ad de ad de ad de ad de ad de ad de ad
0x0120: de ad de ad de ad de ad de ad de ad de ad de ad
0x0130: de ad de ad de ad de ad de ad de ad de ad de ad
0x0140: de ad de ad de ad de ad de ad de ad de ad de ad
0x0150: de ad de ad de ad de ad de ad de ad de ad de ad
0x0160: de ad de ad de ad de ad de ad de ad de ad de ad
0x0170: de ad de ad de ad de ad de ad de ad de ad de ad
0x0180: de ad de ad de ad de ad de ad de ad de ad de ad
0x0190: de ad de ad de ad de ad de ad de ad de ad de ad
0x01a0: de ad de ad de ad de ad de ad de ad de ad de ad
0x01b0: de ad de ad de ad de ad de ad de ad de ad de ad
0x01c0: de ad de ad de ad de ad de ad de ad de ad de ad
0x01d0: de ad de ad de ad de ad de ad de ad de ad de ad
0x01e0: de ad de ad de ad de ad de ad de ad de ad de ad
0x01f0: de ad de ad de ad de ad de ad de ad de ad de ad
* Test that mimic old Macronix chip lack SFDP.
* In order to check how will the driver cope with an old Macronix chip.
* As we do not posses such an old chip, we will change RDSFDP to an unused opcode.
$ git diff -U0
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index 4ebc527aadc1..784cba9b2d0d 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -47 +47 @@
-#define SPINOR_OP_RDSFDP 0x5a /* Read SFDP */
+#define SPINOR_OP_RDSFDP 0x57 /* Read SFDP */
# dmesg | grep spi
[ 42.436974] spi-nor spi0.0: mx25l3205d (4096 Kbytes)
* No error in kernel log!
# ls /sys/bus/spi/devices/spi0.0/spi-nor/
jedec_id manufacturer partname
* No SFDP, as expected!
$ cat /sys/kernel/debug/spi-nor/spi0.0/capabilities
Supported read modes by the flash
1S-1S-1S
opcode 0x03
mode cycles 0
dummy cycles 0
Supported page program modes by the flash
1S-1S-1S
opcode 0x02
$ cat /sys/kernel/debug/spi-nor/spi0.0/params
name mx25l3205d
id c2 20 16 c2 20 16
size 4.00 MiB
write size 1
page size 256
address nbytes 3
flags HAS_16BIT_SR
opcodes
read 0x03
dummy cycles 0
erase 0x20
program 0x02
8D extension none
protocols
read 1S-1S-1S
write 1S-1S-1S
register 1S-1S-1S
erase commands
20 (4.00 KiB) [0]
d8 (64.0 KiB) [1]
c7 (4.00 MiB)
sector map
region (in hex) | erase mask | flags
------------------+------------+----------
00000000-003fffff | [01 ] |
drivers/mtd/spi-nor/macronix.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/mtd/spi-nor/macronix.c b/drivers/mtd/spi-nor/macronix.c
index 02aa844d641b..f79033e9efa5 100644
--- a/drivers/mtd/spi-nor/macronix.c
+++ b/drivers/mtd/spi-nor/macronix.c
@@ -375,4 +375,5 @@ const struct spi_nor_manufacturer spi_nor_macronix = {
.parts = macronix_nor_parts,
.nparts = ARRAY_SIZE(macronix_nor_parts),
.fixups = ¯onix_nor_fixups,
+ .flags = SPI_NOR_MANUFACT_TRY_SFDP | SPI_NOR_MANUFACT_DT_OTP,
};
--
2.39.5
^ permalink raw reply related [flat|nested] 20+ messages in thread