diff mbox

[U-Boot] stm32: stm32_flash: add memory barrier during flash write

Message ID 1459813747-15189-1-git-send-email-vikas.manocha@st.com
State Accepted
Commit 9082517a85930740f59966fcf13293c38792afe8
Delegated to: Tom Rini
Headers show

Commit Message

Vikas MANOCHA April 4, 2016, 11:49 p.m. UTC
After writing data to flash space, next instruction is checking if flash
controller is busy writing to the flash memory. Memory barrier is required here
to avoid transaction re-ordering for data write and busy status check.

Signed-off-by: Vikas Manocha <vikas.manocha@st.com>
---
 drivers/mtd/stm32_flash.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Tom Rini April 12, 2016, 2:29 a.m. UTC | #1
On Mon, Apr 04, 2016 at 04:49:02PM -0700, Vikas Manocha wrote:

> After writing data to flash space, next instruction is checking if flash
> controller is busy writing to the flash memory. Memory barrier is required here
> to avoid transaction re-ordering for data write and busy status check.
> 
> Signed-off-by: Vikas Manocha <vikas.manocha@st.com>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/drivers/mtd/stm32_flash.c b/drivers/mtd/stm32_flash.c
index 71f4854..e16b6cd 100644
--- a/drivers/mtd/stm32_flash.c
+++ b/drivers/mtd/stm32_flash.c
@@ -137,6 +137,10 @@  int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt)
 	/* To make things simple use byte writes only */
 	for (i = 0; i < cnt; i++) {
 		*(uchar *)(addr + i) = src[i];
+		/*  avoid re-ordering flash data write and busy status
+		 *  check as flash memory space attributes are generally Normal
+		 */
+		mb();
 		while (readl(&STM32_FLASH->sr) & STM32_FLASH_SR_BSY)
 			;
 	}