[PATCH 0/4] Add WATCHDOG_RESET() in MTD framework and STM32 QSPI driver

In case of large area read/write/erase on spi nor and spi nand, watchdog may occurs depending on watchdog timeout and MTD device size. Some of these use-cases has been reproduced with stm32mp157-ev1 board.
To prevent this situation, WATHDOG_RESET() are added at several location: - Add WATCHDOG_RESET() in spi_nor_erase() and spi_nor_write() - Add WATCHDOG_RESET() in _stm32_qspi_read_fifo() - Add WATCHDOG_RESET() in nanddev_mtd_erase() - Add WATCHDOG_RESET() in spinand_mtd_read() and spinand_mtd_erase()
Patrice Chotard (4): mtd: spi-nor: Add WATCHDOG_RESET() in spi_nor_core callbacks spi: stm32_qspi: Add WATCHDOG_RESET in _stm32_qspi_read_fifo() mtd: nand: Add WATCHDOG_RESET() in nanddev_mtd_erase() mtd: spinand: Add WATCHDOG_RESET() in spinand_mtd_read/write()
drivers/mtd/nand/core.c | 2 ++ drivers/mtd/nand/spi/core.c | 3 +++ drivers/mtd/spi/spi-nor-core.c | 3 +++ drivers/spi/stm32_qspi.c | 2 ++ 4 files changed, 10 insertions(+)

In case of big area write/erase on spi nor, watchdog timeout may occurs. Issue reproduced on stm32mp157c-ev1 with following commands:
sf write 0xC0000000 0 0x3000000 or sf erase 0 0x1000000
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com ---
drivers/mtd/spi/spi-nor-core.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c index eb49a6c11c..51e0613d4c 100644 --- a/drivers/mtd/spi/spi-nor-core.c +++ b/drivers/mtd/spi/spi-nor-core.c @@ -10,6 +10,7 @@ */
#include <common.h> +#include <watchdog.h> #include <linux/err.h> #include <linux/errno.h> #include <linux/log2.h> @@ -557,6 +558,7 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr) len = instr->len;
while (len) { + WATCHDOG_RESET(); #ifdef CONFIG_SPI_FLASH_BAR ret = write_bar(nor, addr); if (ret < 0) @@ -1235,6 +1237,7 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len, for (i = 0; i < len; ) { ssize_t written; loff_t addr = to + i; + WATCHDOG_RESET();
/* * If page_size is a power of two, the offset can be quickly

Hi Patrice,
On 1/20/21 2:42 PM, Patrice Chotard wrote:
In case of big area write/erase on spi nor, watchdog timeout may occurs. Issue reproduced on stm32mp157c-ev1 with following commands:
sf write 0xC0000000 0 0x3000000 or sf erase 0 0x1000000
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com
drivers/mtd/spi/spi-nor-core.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c index eb49a6c11c..51e0613d4c 100644 --- a/drivers/mtd/spi/spi-nor-core.c +++ b/drivers/mtd/spi/spi-nor-core.c @@ -10,6 +10,7 @@ */
#include <common.h> +#include <watchdog.h> #include <linux/err.h> #include <linux/errno.h> #include <linux/log2.h> @@ -557,6 +558,7 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr) len = instr->len;
while (len) {
#ifdef CONFIG_SPI_FLASH_BAR ret = write_bar(nor, addr); if (ret < 0)WATCHDOG_RESET();
@@ -1235,6 +1237,7 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len, for (i = 0; i < len; ) { ssize_t written; loff_t addr = to + i;
WATCHDOG_RESET();
/*
- If page_size is a power of two, the offset can be quickly
Reviewed-by: Patrick Delaunay patrick.delaunay@foss.st.com
Thanks
Patrick

Hi
On 1/27/21 4:14 PM, Patrick DELAUNAY wrote:
Hi Patrice,
On 1/20/21 2:42 PM, Patrice Chotard wrote:
In case of big area write/erase on spi nor, watchdog timeout may occurs. Issue reproduced on stm32mp157c-ev1 with following commands:
sf write 0xC0000000 0 0x3000000 or sf erase 0 0x1000000
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com
drivers/mtd/spi/spi-nor-core.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c index eb49a6c11c..51e0613d4c 100644 --- a/drivers/mtd/spi/spi-nor-core.c +++ b/drivers/mtd/spi/spi-nor-core.c @@ -10,6 +10,7 @@ */ #include <common.h> +#include <watchdog.h> #include <linux/err.h> #include <linux/errno.h> #include <linux/log2.h> @@ -557,6 +558,7 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr) len = instr->len; while (len) { + WATCHDOG_RESET(); #ifdef CONFIG_SPI_FLASH_BAR ret = write_bar(nor, addr); if (ret < 0) @@ -1235,6 +1237,7 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len, for (i = 0; i < len; ) { ssize_t written; loff_t addr = to + i; + WATCHDOG_RESET(); /* * If page_size is a power of two, the offset can be quickly
Reviewed-by: Patrick Delaunay patrick.delaunay@foss.st.com
Thanks
Patrick
Applied to u-boot-stm/next
Thanks
Patrice

In case of reading large area and memory-map mode is misconfigured (memory-map size declared lower than the real size of the memory chip) watchdog can be triggered.
Add WATCHDOG_RESET() in _stm32_qspi_read_fifo to fix it.
Issue reproduced with stm32mp157c-ev1 board and memory map size set to 1, with following command: sf read 0xC0000000 0 0x4000000
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com ---
drivers/spi/stm32_qspi.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/drivers/spi/stm32_qspi.c b/drivers/spi/stm32_qspi.c index 958c394a1a..c3da17f991 100644 --- a/drivers/spi/stm32_qspi.c +++ b/drivers/spi/stm32_qspi.c @@ -11,6 +11,7 @@ #include <clk.h> #include <reset.h> #include <spi-mem.h> +#include <watchdog.h> #include <linux/iopoll.h> #include <linux/ioport.h> #include <linux/sizes.h> @@ -163,6 +164,7 @@ static int _stm32_qspi_wait_cmd(struct stm32_qspi_priv *priv, static void _stm32_qspi_read_fifo(u8 *val, void __iomem *addr) { *val = readb(addr); + WATCHDOG_RESET(); }
static void _stm32_qspi_write_fifo(u8 *val, void __iomem *addr)

Hi Patrice
On 1/20/21 2:42 PM, Patrice Chotard wrote:
In case of reading large area and memory-map mode is misconfigured (memory-map size declared lower than the real size of the memory chip) watchdog can be triggered.
Add WATCHDOG_RESET() in _stm32_qspi_read_fifo to fix it.
Issue reproduced with stm32mp157c-ev1 board and memory map size set to 1, with following command: sf read 0xC0000000 0 0x4000000
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com
drivers/spi/stm32_qspi.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/drivers/spi/stm32_qspi.c b/drivers/spi/stm32_qspi.c index 958c394a1a..c3da17f991 100644 --- a/drivers/spi/stm32_qspi.c +++ b/drivers/spi/stm32_qspi.c @@ -11,6 +11,7 @@ #include <clk.h> #include <reset.h> #include <spi-mem.h> +#include <watchdog.h> #include <linux/iopoll.h> #include <linux/ioport.h> #include <linux/sizes.h> @@ -163,6 +164,7 @@ static int _stm32_qspi_wait_cmd(struct stm32_qspi_priv *priv, static void _stm32_qspi_read_fifo(u8 *val, void __iomem *addr) { *val = readb(addr);
WATCHDOG_RESET(); }
static void _stm32_qspi_write_fifo(u8 *val, void __iomem *addr)
Reviewed-by: Patrick Delaunay patrick.delaunay@foss.st.com
Thanks
Patrick

Hi
On 1/27/21 4:15 PM, Patrick DELAUNAY wrote:
Hi Patrice
On 1/20/21 2:42 PM, Patrice Chotard wrote:
In case of reading large area and memory-map mode is misconfigured (memory-map size declared lower than the real size of the memory chip) watchdog can be triggered.
Add WATCHDOG_RESET() in _stm32_qspi_read_fifo to fix it.
Issue reproduced with stm32mp157c-ev1 board and memory map size set to 1, with following command: sf read 0xC0000000 0 0x4000000
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com
drivers/spi/stm32_qspi.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/drivers/spi/stm32_qspi.c b/drivers/spi/stm32_qspi.c index 958c394a1a..c3da17f991 100644 --- a/drivers/spi/stm32_qspi.c +++ b/drivers/spi/stm32_qspi.c @@ -11,6 +11,7 @@ #include <clk.h> #include <reset.h> #include <spi-mem.h> +#include <watchdog.h> #include <linux/iopoll.h> #include <linux/ioport.h> #include <linux/sizes.h> @@ -163,6 +164,7 @@ static int _stm32_qspi_wait_cmd(struct stm32_qspi_priv *priv, static void _stm32_qspi_read_fifo(u8 *val, void __iomem *addr) { *val = readb(addr); + WATCHDOG_RESET(); } static void _stm32_qspi_write_fifo(u8 *val, void __iomem *addr)
Reviewed-by: Patrick Delaunay patrick.delaunay@foss.st.com
Thanks
Patrick
Applied to u-boot-stm/next
Thanks
Patrice

In case of big area erased on nand, watchdog timeout may occurs. To fix that, add WATCHDOG_RESET() in nanddev_mtd_erase() to ensure that watchdog is reset.
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com ---
drivers/mtd/nand/core.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/drivers/mtd/nand/core.c b/drivers/mtd/nand/core.c index 3abaef23c5..ec11bf44f8 100644 --- a/drivers/mtd/nand/core.c +++ b/drivers/mtd/nand/core.c @@ -10,6 +10,7 @@ #define pr_fmt(fmt) "nand: " fmt
#include <common.h> +#include <watchdog.h> #ifndef __UBOOT__ #include <linux/module.h> #endif @@ -162,6 +163,7 @@ int nanddev_mtd_erase(struct mtd_info *mtd, struct erase_info *einfo) nanddev_offs_to_pos(nand, einfo->addr, &pos); nanddev_offs_to_pos(nand, einfo->addr + einfo->len - 1, &last); while (nanddev_pos_cmp(&pos, &last) <= 0) { + WATCHDOG_RESET(); ret = nanddev_erase(nand, &pos); if (ret) { einfo->fail_addr = nanddev_pos_to_offs(nand, &pos);

Hi Patrice,
On 1/20/21 2:42 PM, Patrice Chotard wrote:
In case of big area erased on nand, watchdog timeout may occurs. To fix that, add WATCHDOG_RESET() in nanddev_mtd_erase() to ensure that watchdog is reset.
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com
drivers/mtd/nand/core.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/drivers/mtd/nand/core.c b/drivers/mtd/nand/core.c index 3abaef23c5..ec11bf44f8 100644 --- a/drivers/mtd/nand/core.c +++ b/drivers/mtd/nand/core.c @@ -10,6 +10,7 @@ #define pr_fmt(fmt) "nand: " fmt
#include <common.h> +#include <watchdog.h> #ifndef __UBOOT__ #include <linux/module.h> #endif @@ -162,6 +163,7 @@ int nanddev_mtd_erase(struct mtd_info *mtd, struct erase_info *einfo) nanddev_offs_to_pos(nand, einfo->addr, &pos); nanddev_offs_to_pos(nand, einfo->addr + einfo->len - 1, &last); while (nanddev_pos_cmp(&pos, &last) <= 0) {
ret = nanddev_erase(nand, &pos); if (ret) { einfo->fail_addr = nanddev_pos_to_offs(nand, &pos);WATCHDOG_RESET();
Reviewed-by: Patrick Delaunay patrick.delaunay@foss.st.com
Thanks
Patrick

Hi
On 1/27/21 4:15 PM, Patrick DELAUNAY wrote:
Hi Patrice,
On 1/20/21 2:42 PM, Patrice Chotard wrote:
In case of big area erased on nand, watchdog timeout may occurs. To fix that, add WATCHDOG_RESET() in nanddev_mtd_erase() to ensure that watchdog is reset.
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com
drivers/mtd/nand/core.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/drivers/mtd/nand/core.c b/drivers/mtd/nand/core.c index 3abaef23c5..ec11bf44f8 100644 --- a/drivers/mtd/nand/core.c +++ b/drivers/mtd/nand/core.c @@ -10,6 +10,7 @@ #define pr_fmt(fmt) "nand: " fmt #include <common.h> +#include <watchdog.h> #ifndef __UBOOT__ #include <linux/module.h> #endif @@ -162,6 +163,7 @@ int nanddev_mtd_erase(struct mtd_info *mtd, struct erase_info *einfo) nanddev_offs_to_pos(nand, einfo->addr, &pos); nanddev_offs_to_pos(nand, einfo->addr + einfo->len - 1, &last); while (nanddev_pos_cmp(&pos, &last) <= 0) { + WATCHDOG_RESET(); ret = nanddev_erase(nand, &pos); if (ret) { einfo->fail_addr = nanddev_pos_to_offs(nand, &pos);
Reviewed-by: Patrick Delaunay patrick.delaunay@foss.st.com
Thanks
Patrick
Applied to u-boot-stm/next
Thanks
Patrice

In case of big area read/write on spi nand, watchdog timeout may occurs. To fix that, add WATCHDOG_RESET() in spinand_mtd_read() and spinand_mtd_write() to ensure that watchdog is reset.
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com
---
drivers/mtd/nand/spi/core.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c index cb8ffa3fa9..7f54422c93 100644 --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c @@ -24,6 +24,7 @@ #include <errno.h> #include <spi.h> #include <spi-mem.h> +#include <watchdog.h> #include <linux/mtd/spinand.h> #endif
@@ -574,6 +575,7 @@ static int spinand_mtd_read(struct mtd_info *mtd, loff_t from, #endif
nanddev_io_for_each_page(nand, from, ops, &iter) { + WATCHDOG_RESET(); ret = spinand_select_target(spinand, iter.req.pos.target); if (ret) break; @@ -625,6 +627,7 @@ static int spinand_mtd_write(struct mtd_info *mtd, loff_t to, #endif
nanddev_io_for_each_page(nand, to, ops, &iter) { + WATCHDOG_RESET(); ret = spinand_select_target(spinand, iter.req.pos.target); if (ret) break;

Hi,
On 1/20/21 2:42 PM, Patrice Chotard wrote:
In case of big area read/write on spi nand, watchdog timeout may occurs. To fix that, add WATCHDOG_RESET() in spinand_mtd_read() and spinand_mtd_write() to ensure that watchdog is reset.
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com
drivers/mtd/nand/spi/core.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c index cb8ffa3fa9..7f54422c93 100644 --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c @@ -24,6 +24,7 @@ #include <errno.h> #include <spi.h> #include <spi-mem.h> +#include <watchdog.h> #include <linux/mtd/spinand.h> #endif
@@ -574,6 +575,7 @@ static int spinand_mtd_read(struct mtd_info *mtd, loff_t from, #endif
nanddev_io_for_each_page(nand, from, ops, &iter) {
ret = spinand_select_target(spinand, iter.req.pos.target); if (ret) break;WATCHDOG_RESET();
@@ -625,6 +627,7 @@ static int spinand_mtd_write(struct mtd_info *mtd, loff_t to, #endif
nanddev_io_for_each_page(nand, to, ops, &iter) {
ret = spinand_select_target(spinand, iter.req.pos.target); if (ret) break;WATCHDOG_RESET();
Reviewed-by: Patrick Delaunay patrick.delaunay@foss.st.com
Thanks
Patrick

Hi
On 1/27/21 4:19 PM, Patrick DELAUNAY wrote:
Hi,
On 1/20/21 2:42 PM, Patrice Chotard wrote:
In case of big area read/write on spi nand, watchdog timeout may occurs. To fix that, add WATCHDOG_RESET() in spinand_mtd_read() and spinand_mtd_write() to ensure that watchdog is reset.
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com
drivers/mtd/nand/spi/core.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c index cb8ffa3fa9..7f54422c93 100644 --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c @@ -24,6 +24,7 @@ #include <errno.h> #include <spi.h> #include <spi-mem.h> +#include <watchdog.h> #include <linux/mtd/spinand.h> #endif @@ -574,6 +575,7 @@ static int spinand_mtd_read(struct mtd_info *mtd, loff_t from, #endif nanddev_io_for_each_page(nand, from, ops, &iter) { + WATCHDOG_RESET(); ret = spinand_select_target(spinand, iter.req.pos.target); if (ret) break; @@ -625,6 +627,7 @@ static int spinand_mtd_write(struct mtd_info *mtd, loff_t to, #endif nanddev_io_for_each_page(nand, to, ops, &iter) { + WATCHDOG_RESET(); ret = spinand_select_target(spinand, iter.req.pos.target); if (ret) break;
Reviewed-by: Patrick Delaunay patrick.delaunay@foss.st.com
Thanks
Patrick
Applied to u-boot-stm/next
Thanks
Patrice
participants (3)
-
Patrice CHOTARD
-
Patrice Chotard
-
Patrick DELAUNAY