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

Tudor Ambarus tudor.ambarus at linaro.org
Wed Nov 1 10:27:37 PDT 2023



On 11/1/23 16:17, Fabio Estevam wrote:
> Hi Tudor,
> 

Hi!

> On 01/11/2023 13:04, Tudor Ambarus wrote:
> 
>> this is wrong, it should have been
>>     bool multi_die = nor->mtd.size != die_size;
> 
> 
> I applied the following changes on top of v2:
> 
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -1067,12 +1067,17 @@ 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));
> +       dev_info(nor->dev, " %lldKiB\n", (long long)(die_size >> 10));
> 
>         if (nor->spimem) {
> +               dev_info(nor->dev, "***** nor->params->die_erase_opcode:
> 0x%x\n", nor->params->die_erase_opcode);
> +               dev_info(nor->dev, "***** nor->addr_nbytes: %d\n",
> nor->addr_nbytes);
> +               dev_info(nor->dev, "***** addr 0x%llx\n", addr);
> +               dev_info(nor->dev, "***** multi_die: %d\n", multi_die);
> +
>                 struct spi_mem_op op =
>                         SPI_NOR_DIE_ERASE_OP(nor->params->die_erase_opcode,
>                                              nor->addr_nbytes, addr,
> multi_die);

cool!

> , but erase is still not working:
>>
> ~# time flash_erase /dev/mtd0 0 0
> Erasing 131072 Kibyte @ 0 --  0 [   14.733446] spi-nor spi0.0:  65536KiB
> % complete [   14.739932] spi-nor spi0.0: *****
> nor->params->die_erase_opcode: 0xc4
> [   14.747311] spi-nor spi0.0: ***** nor->addr_nbytes: 4
> [   14.752402] spi-nor spi0.0: ***** addr 0x0
> [   14.756524] spi-nor spi0.0: ***** multi_die: 1
> [   14.761121] spi-nor spi0.0:  65536KiB
> [   14.764807] spi-nor spi0.0: ***** nor->params->die_erase_opcode: 0xc4
> [   14.771289] spi-nor spi0.0: ***** nor->addr_nbytes: 4
> [   14.776369] spi-nor spi0.0: ***** addr 0x4000000
> [   14.781004] spi-nor spi0.0: ***** multi_die: 1
> Erasing 131072 Kibyte @ 0 -- 100 % complete
> 
> real    0m0.061s
> user    0m0.006s
> sys    0m0.053s
> 
> ~# hexdump -C /dev/mtd0
> 00000000  d4 a1 8c 16 ad 4d b2 df  3d 2a af c2 ae 0a 8a c1 
> |.....M..=*......|
> 00000010  5f 2d 7a 17 9f c3 a4 46  cd f9 80 b8 1e 33 43 25 
> |_-z....F.....3C%|
> ....

Thanks, Fabio. I can't tell what's happening and it's getting late here.
Die erase does not execute if either of the status register BP bits are
set to 1 (some sectors are locked), but that shouldn't be the case I
guess as you could erase the entire flash before. So maybe dump SR/FSR
before and after the chip erase op. Other idea is to dump the spi_mem_op
fields, after spi_nor_spimem_setup_op() is called, maybe I got something
wrong there, but on a short look it seems fine.

I'll re-read this tomorrow. Cheers,
ta



More information about the linux-arm-kernel mailing list