Skip to contentSkip to conversation

sf: bar: Clean BA24 Bank Address Register bit after read/write/erase operation

PATCH New Lukasz Majewski 3 participants 6 messages Sep 13, 2017 – Sep 25, 2017 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sf: bar: Clean BA24 Bank Address Register bit after read/write/erase operation

The content of Bank Address Register (BAR) is volatile. It is cleared after power cycle or reset command (RESET F0h).

Some memories (like e.g. s25fl256s) use it to access memory larger than 0x1000000 (16 MiB).

The problem shows up when one:

1. Reads/writes/erases memory > 16 MiB
2. Calls "reset" u-boot command (which is not causing BAR to be cleared)

In the above scenario, the SoC ROM sends 0x000000 address to read SPL. Unfortunately, the BA24 bit is still set and hence it receives content from 0x1000000 memory address.
As a result the SoC aborts and we hang. Only power cycle can take the SoC out of this state.

How to reproduce/test:

sf probe; sf erase 0x1200000 0x800000; reset
sf probe; sf erase 0x1200000 0x800000; sf write 0x11000000 0x1200000 0x800000; reset sf probe; sf read 0x11000000 0x1200000 0x800000; reset

---
 drivers/mtd/spi/spi_flash.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
drivers/mtd/spi/spi_flash.c +33 -0
index 34f6888..d19d64a 100644
@@ -113,6 +113,27 @@ static int write_cr(struct spi_flash *flash, u8 wc)
 #endif
 
 #ifdef CONFIG_SPI_FLASH_BAR
+/*
+ * This "cleanup" is necessary in a situation when one was accessing
+ * spi flash memory > 16 MiB by using Bank Address Register's BA24 bit.
+ *
+ * After it the BA24 bit shall be cleared to allow access to correct
+ * memory region after SW reset (by calling "reset" command).
+ *
+ * Otherwise, the BA24 bit may be left set and then after reset, the
+ * ROM would seek for SPL from 0x1000000, not 0x0.
+ */
+static int cleanup_bar(struct spi_flash *flash)
+{
+	u8 cmd, bank_sel = 0;
+
+	if (flash->bank_curr == 0)
+		return 0;
+	cmd = flash->bank_write_cmd;
+
+	return spi_flash_write_common(flash, &cmd, 1, &bank_sel, 1);
+}
+
 static int write_bar(struct spi_flash *flash, u32 offset)
 {
 	u8 cmd, bank_sel;
@@ -339,6 +360,10 @@ int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len)
 		len -= erase_size;
 	}
 
+#ifdef CONFIG_SPI_FLASH_BAR
+	ret = cleanup_bar(flash);
+#endif
+
 	return ret;
 }
 
@@ -397,6 +422,10 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
 		offset += chunk_len;
 	}
 
+#ifdef CONFIG_SPI_FLASH_BAR
+	ret = cleanup_bar(flash);
+#endif
+
 	return ret;
 }
 
@@ -500,6 +529,10 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
 		data += read_len;
 	}
 
+#ifdef CONFIG_SPI_FLASH_BAR
+	ret = cleanup_bar(flash);
+#endif
+
 	free(cmd);
 	return ret;
 }
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/1 sf: bar: Clean BA24 Bank Address Register bit after read/write/erase operation

Hi Lukasz,

Quoted 12 lines · Lukasz Majewski

#ifdef CONFIG_SPI_FLASH_BAR

drivers/mtd/spi/spi_flash.c +11 -0
+/*
+ * This "cleanup" is necessary in a situation when one was accessing
+ * spi flash memory > 16 MiB by using Bank Address Register's BA24 bit.
+ *
+ * After it the BA24 bit shall be cleared to allow access to correct
+ * memory region after SW reset (by calling "reset" command).
+ *
+ * Otherwise, the BA24 bit may be left set and then after reset, the
+ * ROM would seek for SPL from 0x1000000, not 0x0.
+ */
+static int cleanup_bar(struct spi_flash *flash)

drivers/mtd/spi/spi_flash.c static int write_cr(struct spi_flash *flash, u8 wc) · line 136

Quoted 10 lines
drivers/mtd/spi/spi_flash.c +10 -0
+{
+       u8 cmd, bank_sel = 0;
+
+       if (flash->bank_curr == 0)
+               return 0;
+       cmd = flash->bank_write_cmd;
+
+       return spi_flash_write_common(flash, &cmd, 1, &bank_sel, 1);
+}
+

What about defining an empty stub for this function when CONFIG_SPI_FLASH_BAR is not defined?

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len) · line 365

Quoted 10 lines

static int write_bar(struct spi_flash *flash, u32 offset)

 {
        u8 cmd, bank_sel;
drivers/mtd/spi/spi_flash.c +3 -0
@@ -339,6 +360,10 @@ int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len)
                len -= erase_size;
        }
 
+#ifdef CONFIG_SPI_FLASH_BAR
+       ret = cleanup_bar(flash);
+#endif

Then you don't need to add the ifdefs when calling cleanup_bar().

#2 lore raw

PATCH 1/1 sf: bar: Clean BA24 Bank Address Register bit after read/write/erase operation

Hi Fabio,

Quoted 37 lines

Hi Lukasz,

Quoted 12 lines · Lukasz Majewski
  #ifdef CONFIG_SPI_FLASH_BAR
drivers/mtd/spi/spi_flash.c +11 -0
+/*
+ * This "cleanup" is necessary in a situation when one was accessing
+ * spi flash memory > 16 MiB by using Bank Address Register's BA24 bit.
+ *
+ * After it the BA24 bit shall be cleared to allow access to correct
+ * memory region after SW reset (by calling "reset" command).
+ *
+ * Otherwise, the BA24 bit may be left set and then after reset, the
+ * ROM would seek for SPL from 0x1000000, not 0x0.
+ */
+static int cleanup_bar(struct spi_flash *flash)

drivers/mtd/spi/spi_flash.c static int write_cr(struct spi_flash *flash, u8 wc) · line 136

Quoted 10 lines
drivers/mtd/spi/spi_flash.c +10 -0
+{
+       u8 cmd, bank_sel = 0;
+
+       if (flash->bank_curr == 0)
+               return 0;
+       cmd = flash->bank_write_cmd;
+
+       return spi_flash_write_common(flash, &cmd, 1, &bank_sel, 1);
+}
+

What about defining an empty stub for this function when CONFIG_SPI_FLASH_BAR is not defined?

Quoted 7 lines
  static int write_bar(struct spi_flash *flash, u32 offset)
  {
         u8 cmd, bank_sel;
drivers/mtd/spi/spi_flash.c +0 -0
@@ -339,6 +360,10 @@ int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len)
                 len -= erase_size;
         }
 
Quoted 5 lines

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len) · line 365

Quoted 3 lines
drivers/mtd/spi/spi_flash.c +3 -0
+#ifdef CONFIG_SPI_FLASH_BAR
+       ret = cleanup_bar(flash);
+#endif

Then you don't need to add the ifdefs when calling cleanup_bar().

I took the approach already used in this file, so I would prefer to leave it is in this patch (to be in sync with the rest).

Quoted 1 line
Signature · 9 lines
Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
#3 lore raw

PATCH 1/1 sf: bar: Clean BA24 Bank Address Register bit after read/write/erase operation

In reply to Fabio Estevam

Hi Fabio, Jagan,

Quoted 37 lines

Hi Lukasz,

Quoted 12 lines · Lukasz Majewski
  #ifdef CONFIG_SPI_FLASH_BAR
drivers/mtd/spi/spi_flash.c +11 -0
+/*
+ * This "cleanup" is necessary in a situation when one was accessing
+ * spi flash memory > 16 MiB by using Bank Address Register's BA24 bit.
+ *
+ * After it the BA24 bit shall be cleared to allow access to correct
+ * memory region after SW reset (by calling "reset" command).
+ *
+ * Otherwise, the BA24 bit may be left set and then after reset, the
+ * ROM would seek for SPL from 0x1000000, not 0x0.
+ */
+static int cleanup_bar(struct spi_flash *flash)

drivers/mtd/spi/spi_flash.c static int write_cr(struct spi_flash *flash, u8 wc) · line 136

Quoted 10 lines
drivers/mtd/spi/spi_flash.c +10 -0
+{
+       u8 cmd, bank_sel = 0;
+
+       if (flash->bank_curr == 0)
+               return 0;
+       cmd = flash->bank_write_cmd;
+
+       return spi_flash_write_common(flash, &cmd, 1, &bank_sel, 1);
+}
+

What about defining an empty stub for this function when CONFIG_SPI_FLASH_BAR is not defined?

Quoted 7 lines
  static int write_bar(struct spi_flash *flash, u32 offset)
  {
         u8 cmd, bank_sel;
drivers/mtd/spi/spi_flash.c +0 -0
@@ -339,6 +360,10 @@ int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len)
                 len -= erase_size;
         }
 
Quoted 6 lines

drivers/mtd/spi/spi_flash.c int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len) · line 365

Quoted 3 lines
drivers/mtd/spi/spi_flash.c +3 -0
+#ifdef CONFIG_SPI_FLASH_BAR
+       ret = cleanup_bar(flash);
+#endif

Then you don't need to add the ifdefs when calling cleanup_bar().

Jagan, could you look into this patch?

I would prefer to keep the coding style similar to the one already present in this file.

Signature · 9 lines
Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
#4 lore raw

PATCH 1/1 sf: bar: Clean BA24 Bank Address Register bit after read/write/erase operation

In reply to Lukasz Majewski
Quoted 35 lines · Lukasz Majewski

The content of Bank Address Register (BAR) is volatile. It is cleared after power cycle or reset command (RESET F0h).

Some memories (like e.g. s25fl256s) use it to access memory larger than 0x1000000 (16 MiB).

The problem shows up when one:

1. Reads/writes/erases memory > 16 MiB
2. Calls "reset" u-boot command (which is not causing BAR to be cleared)

In the above scenario, the SoC ROM sends 0x000000 address to read SPL. Unfortunately, the BA24 bit is still set and hence it receives content from 0x1000000 memory address.
As a result the SoC aborts and we hang. Only power cycle can take the SoC out of this state.

How to reproduce/test:

sf probe; sf erase 0x1200000 0x800000; reset
sf probe; sf erase 0x1200000 0x800000; sf write 0x11000000 0x1200000 0x800000; reset sf probe; sf read 0x11000000 0x1200000 0x800000; reset

---
 drivers/mtd/spi/spi_flash.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
drivers/mtd/spi/spi_flash.c +0 -0
index 34f6888..d19d64a 100644
@@ -113,6 +113,27 @@ static int write_cr(struct spi_flash *flash, u8 wc)
 #endif
 

drivers/mtd/spi/spi_flash.c static int write_cr(struct spi_flash *flash, u8 wc) · line 124

Quoted 10 lines
drivers/mtd/spi/spi_flash.c +9 -0
 #ifdef CONFIG_SPI_FLASH_BAR
+/*
+ * This "cleanup" is necessary in a situation when one was accessing
+ * spi flash memory > 16 MiB by using Bank Address Register's BA24 bit.
+ *
+ * After it the BA24 bit shall be cleared to allow access to correct
+ * memory region after SW reset (by calling "reset" command).
+ *
+ * Otherwise, the BA24 bit may be left set and then after reset, the
+ * ROM would seek for SPL from 0x1000000, not 0x0.

This need to change, SPL will look 16 MiB * bank_sel

drivers/mtd/spi/spi_flash.c static int write_cr(struct spi_flash *flash, u8 wc) · line 126

Quoted 2 lines
drivers/mtd/spi/spi_flash.c +2 -0
+ */
+static int cleanup_bar(struct spi_flash *flash)

what about clear_bar?

thanks!

Signature · 4 lines
Jagan Teki
Free Software Engineer | www.openedev.com
U-Boot, Linux | Upstream Maintainer
Hyderabad, India.
#5 lore raw

PATCH 1/1 sf: bar: Clean BA24 Bank Address Register bit after read/write/erase operation

Hi Jagan,

Quoted 36 lines · Lukasz Majewski
Quoted 35 lines

The content of Bank Address Register (BAR) is volatile. It is cleared after power cycle or reset command (RESET F0h).

Some memories (like e.g. s25fl256s) use it to access memory larger than 0x1000000 (16 MiB).

The problem shows up when one:

1. Reads/writes/erases memory > 16 MiB
2. Calls "reset" u-boot command (which is not causing BAR to be cleared)

In the above scenario, the SoC ROM sends 0x000000 address to read SPL. Unfortunately, the BA24 bit is still set and hence it receives content from 0x1000000 memory address.
As a result the SoC aborts and we hang. Only power cycle can take the SoC out of this state.

How to reproduce/test:

sf probe; sf erase 0x1200000 0x800000; reset
sf probe; sf erase 0x1200000 0x800000; sf write 0x11000000 0x1200000 0x800000; reset sf probe; sf read 0x11000000 0x1200000 0x800000; reset

---
  drivers/mtd/spi/spi_flash.c | 33 +++++++++++++++++++++++++++++++++
  1 file changed, 33 insertions(+)
drivers/mtd/spi/spi_flash.c +0 -0
index 34f6888..d19d64a 100644
@@ -113,6 +113,27 @@ static int write_cr(struct spi_flash *flash, u8 wc)
  #endif
 
Quoted 12 lines

drivers/mtd/spi/spi_flash.c static int write_cr(struct spi_flash *flash, u8 wc) · line 124

Quoted 10 lines
drivers/mtd/spi/spi_flash.c +9 -0
  #ifdef CONFIG_SPI_FLASH_BAR
+/*
+ * This "cleanup" is necessary in a situation when one was accessing
+ * spi flash memory > 16 MiB by using Bank Address Register's BA24 bit.
+ *
+ * After it the BA24 bit shall be cleared to allow access to correct
+ * memory region after SW reset (by calling "reset" command).
+ *
+ * Otherwise, the BA24 bit may be left set and then after reset, the
+ * ROM would seek for SPL from 0x1000000, not 0x0.

This need to change, SPL will look 16 MiB * bank_sel

Ok. I will update the description.

Quoted 5 lines

drivers/mtd/spi/spi_flash.c static int write_cr(struct spi_flash *flash, u8 wc) · line 126

Quoted 3 lines
drivers/mtd/spi/spi_flash.c +2 -0
+ */
+static int cleanup_bar(struct spi_flash *flash)

what about clear_bar?

Ok. I will change the name.

Quoted 3 lines

thanks!

Signature · 9 lines
Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de