[PATCH v2 2/6] mtd: spi-nor: add erase die (chip) capability

Tudor Ambarus tudor.ambarus at linaro.org
Thu Nov 2 11:21:14 PDT 2023



On 11/2/23 18:01, Fabio Estevam wrote:
> On 02/11/2023 14:59, Tudor Ambarus wrote:
>> On 11/2/23 17:54, Tudor Ambarus wrote:
>>> Does this help?
>>>
>>
>> I guess not, because you used the full flash erase in the first place,
>> but still a bug. Ok, I'll add some prints.
> 
> Yes, it did not help:


Let's see what gets to the SPI controller. Which SPI controller do you use?

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index af8f3fc30256..5584bf9cbfd1 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -1067,7 +1067,7 @@ static int spi_nor_read_sr2(struct spi_nor *nor,
u8 *sr2)
  */
 static int spi_nor_erase_die(struct spi_nor *nor, loff_t addr, size_t
die_size)
 {
-       bool multi_die = nor->mtd.size == die_size;
+       bool multi_die = nor->mtd.size != die_size;
        int ret;

        dev_dbg(nor->dev, " %lldKiB\n", (long long)(die_size >> 10));
@@ -1079,6 +1079,23 @@ static int spi_nor_erase_die(struct spi_nor *nor,
loff_t addr, size_t die_size)

                spi_nor_spimem_setup_op(nor, &op, nor->reg_proto);

+               dev_info(nor->dev, "***** nor->reg_proto = 0x%08x \n",
nor->reg_proto);
+               dev_info(nor->dev, "*****\n");
+               dev_info(nor->dev, "***** op.cmd.nbytes = 0x%02x \n",
op.cmd.nbytes);
+               dev_info(nor->dev, "***** op.cmd.buswidth = 0x%02x \n",
op.cmd.buswidth);
+               dev_info(nor->dev, "***** op.cmd.opcode = 0x%02x \n",
(u8) op.cmd.opcode);
+               dev_info(nor->dev, "*****\n");
+               dev_info(nor->dev, "***** op.addr.nbytes = 0x%02x \n",
op.addr.nbytes);
+               dev_info(nor->dev, "***** op.addr.buswidth = 0x%02x \n",
op.addr.buswidth);
+               dev_info(nor->dev, "***** op.addr.buswidth = 0x%llx \n",
op.addr.val);
+               dev_info(nor->dev, "*****\n");
+               dev_info(nor->dev, "***** op.dummy.nbytes = 0x%02x \n",
op.dummy.nbytes);
+               dev_info(nor->dev, "***** op.dummy.buswidth = 0x%02x
\n", op.dummy.buswidth);
+               dev_info(nor->dev, "*****\n");
+               dev_info(nor->dev, "***** op.data.buswidth = 0x%02x \n",
op.data.buswidth);
+               dev_info(nor->dev, "***** op.data.nbytes = %d \n",
op.data.nbytes);
+
+
                ret = spi_mem_exec_op(nor->spimem, &op);
        } else {
                if (multi_die)
@@ -1870,7 +1887,7 @@ static int spi_nor_erase(struct mtd_info *mtd,
struct erase_info *instr)

        if (n_dice) {
                die_size = div_u64(mtd->size, n_dice);
-               if (len == die_size && (addr & (die_size - 1)))
+               if (!(len & (die_size - 1)) && !(addr & (die_size - 1)))
                        multi_die_erase = true;
        } else {
                die_size = mtd->size;



More information about the linux-mtd mailing list