Skip to content

Commit d3b7b08

Browse files
committed
u-boot: Fix the SPI and eMMC hang issue
This backports 3738645 from master branch. Original commit message: Refer to 1 and 2, the root cause is the wrong data type of the timer value. Thanks [email protected] for the patches. 1. https://lists.denx.de/pipermail/u-boot/2024-December/574817.html 2. https://lists.denx.de/pipermail/u-boot/2024-December/574818.html Signed-off-by: Baocheng Su <[email protected]>
1 parent d403490 commit d3b7b08

File tree

4 files changed

+124
-0
lines changed

4 files changed

+124
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Jan Kiszka <[email protected]>
3+
Date: Mon, 30 Oct 2023 17:20:29 +0100
4+
Subject: [PATCH] spi: cadence-quadspi: Fix error message on stuck busy state
5+
6+
We are not iterating CQSPI_REG_RETRY, we are waiting 'timeout' ms, since
7+
day 1.
8+
9+
Signed-off-by: Jan Kiszka <[email protected]>
10+
Reviewed-by: Stefan Roese <[email protected]>
11+
Reviewed-by: Jagan Teki <[email protected]>
12+
---
13+
drivers/spi/cadence_qspi_apb.c | 3 +--
14+
1 file changed, 1 insertion(+), 2 deletions(-)
15+
16+
diff --git a/drivers/spi/cadence_qspi_apb.c b/drivers/spi/cadence_qspi_apb.c
17+
index 9ce2c0f254f3..d033184aa466 100644
18+
--- a/drivers/spi/cadence_qspi_apb.c
19+
+++ b/drivers/spi/cadence_qspi_apb.c
20+
@@ -171,8 +171,7 @@ static unsigned int cadence_qspi_wait_idle(void *reg_base)
21+
}
22+
23+
/* Timeout, still in busy mode. */
24+
- printf("QSPI: QSPI is still busy after poll for %d times.\n",
25+
- CQSPI_REG_RETRY);
26+
+ printf("QSPI: QSPI is still busy after poll for %d ms.\n", timeout);
27+
return 0;
28+
}
29+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Ronald Wahl <[email protected]>
3+
Date: Wed, 11 Dec 2024 21:51:04 +0100
4+
Subject: [PATCH] spi: cadence-quadspi: fix potential malfunction after ~49
5+
days uptime
6+
7+
The get_timer function returns an unsigned long which may be calculated
8+
from the ARM system counter. This counter is reset only on a cold reset.
9+
U-boot divides this counter down to a 1000 Hz counter that will cross
10+
the 32bit barrier after a bit more than 49 days. Assigning the value to
11+
an unsigned int will truncate it on 64bit systems.
12+
Passing this truncated value back to the get_timer function will return
13+
a very large value that is certainly larger than the timeout and so will
14+
go down the error path and besides stopping U-Boot will lead to messages
15+
like
16+
17+
"SPI: QSPI is still busy after poll for 5000 ms."
18+
19+
Signed-off-by: Ronald Wahl <[email protected]>
20+
Cc: Vignesh R <[email protected]>
21+
Cc: Pratyush Yadav <[email protected]>
22+
---
23+
drivers/spi/cadence_qspi_apb.c | 6 +++---
24+
1 file changed, 3 insertions(+), 3 deletions(-)
25+
26+
diff --git a/drivers/spi/cadence_qspi_apb.c b/drivers/spi/cadence_qspi_apb.c
27+
index d033184aa466..ecbd6f9d147d 100644
28+
--- a/drivers/spi/cadence_qspi_apb.c
29+
+++ b/drivers/spi/cadence_qspi_apb.c
30+
@@ -152,9 +152,9 @@ static int cadence_qspi_set_protocol(struct cadence_spi_priv *priv,
31+
/* Return 1 if idle, otherwise return 0 (busy). */
32+
static unsigned int cadence_qspi_wait_idle(void *reg_base)
33+
{
34+
- unsigned int start, count = 0;
35+
+ unsigned long start, count = 0;
36+
/* timeout in unit of ms */
37+
- unsigned int timeout = 5000;
38+
+ unsigned long timeout = 5000;
39+
40+
start = get_timer(0);
41+
for ( ; get_timer(start) < timeout ; ) {
42+
@@ -171,7 +171,7 @@ static unsigned int cadence_qspi_wait_idle(void *reg_base)
43+
}
44+
45+
/* Timeout, still in busy mode. */
46+
- printf("QSPI: QSPI is still busy after poll for %d ms.\n", timeout);
47+
+ printf("QSPI: QSPI is still busy after poll for %lu ms.\n", timeout);
48+
return 0;
49+
}
50+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Ronald Wahl <[email protected]>
3+
Date: Wed, 11 Dec 2024 21:52:00 +0100
4+
Subject: [PATCH] mmc: Fix potential timer value truncation
5+
6+
On 64bit systems the timer value might be truncated to a 32bit value
7+
causing malfunctions. For example on ARM the timer might start from 0
8+
again only after a cold reset. The 32bit overflow occurs after a bit
9+
more than 49 days (1000 Hz counter) so booting after that time may lead
10+
to a surprise because the board might become stuck requiring a cold
11+
reset.
12+
13+
Signed-off-by: Ronald Wahl <[email protected]>
14+
Cc: Peng Fan <[email protected]>
15+
Cc: Jaehoon Chung <[email protected]>
16+
---
17+
drivers/mmc/mmc.c | 5 +++--
18+
1 file changed, 3 insertions(+), 2 deletions(-)
19+
20+
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
21+
index 31cfda288587..2779302b843e 100644
22+
--- a/drivers/mmc/mmc.c
23+
+++ b/drivers/mmc/mmc.c
24+
@@ -713,7 +713,7 @@ static int mmc_send_op_cond(struct mmc *mmc)
25+
{
26+
int err, i;
27+
int timeout = 1000;
28+
- uint start;
29+
+ ulong start;
30+
31+
/* Some cards seem to need this */
32+
mmc_go_idle(mmc);
33+
@@ -808,7 +808,8 @@ int mmc_send_ext_csd(struct mmc *mmc, u8 *ext_csd)
34+
static int __mmc_switch(struct mmc *mmc, u8 set, u8 index, u8 value,
35+
bool send_status)
36+
{
37+
- unsigned int status, start;
38+
+ ulong start;
39+
+ unsigned int status;
40+
struct mmc_cmd cmd;
41+
int timeout_ms = DEFAULT_CMD6_TIMEOUT_MS;
42+
bool is_part_switch = (set == EXT_CSD_CMD_SET_NORMAL) &&

recipes-bsp/u-boot/u-boot-iot2050_2023.10.bb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ SRC_URI += " \
2323
file://0009-dts-iot2050-Sync-kernel-dts-to-u-boot.patch \
2424
file://0010-dts-iot2050-Support-new-IOT2050-SM-variant.patch \
2525
file://0011-arm-dts-iot2050-Disable-lock-step-mode-for-all-iot20.patch \
26+
file://0012-spi-cadence-quadspi-Fix-error-message-on-stuck-busy-.patch \
27+
file://0013-spi-cadence-quadspi-fix-potential-malfunction-after-.patch \
28+
file://0014-mmc-Fix-potential-timer-value-truncation.patch \
2629
"
2730

2831
SRC_URI[sha256sum] = "e00e6c6f014e046101739d08d06f328811cebcf5ae101348f409cbbd55ce6900"

0 commit comments

Comments
 (0)