Skip to contentSkip to conversation

ARM: Fix reset in SPL if SYSRESET is not used

PATCH New Harald Seiler 3 participants 13 messages Mar 4, 2020 – May 1, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover ARM: Fix reset in SPL if SYSRESET is not used

Hello,

continuing on the discussion around Claudius' patch for fixing reset in SPL [1] we have taken a closer look at the issue. To quickly summarize the situation:

The original patch was to enable the generic ARM implementation of do_reset if CONFIG_SYSRESET is not enabled in SPL. This would break compilation for some boards which define their own do_reset in board/*/spl.c.

To be more specific, the following 4 boards have this custom do_reset:

- toradex/verdin-imx8mm
- freescale/imx8mn_evk
- freescale/imx8mm_evk
- freescale/imx8mp_evk

I hope we can all agree that do_reset is not at all meant to be implemented in board files. From looking at the related code for imx8m, it feels like this was just a workaround hack to archieve the same thing which Claudius has fixed. So this patch series reverts the addition of do_reset implementations in imx8m board files and instead switches to using the proper fix provided by Claudius.

Additionally, the custom do_reset implementations were passing an address (WDOG1_BASE_ADDR) to reset_cpu() instead of 0. This is the only place in the entire U-Boot tree where this happens. Instead, all other implementations simply ignore the parameter and 0 is passed by callers. It looks a lot like this is a legacy left-over which makes me think that using it for a (hard-coded) watchdog address is not a good idea as it breaks convention with the rest of U-Boot.

[1]: https://patchwork.ozlabs.org/patch/1201959

Claudius Heine (3):
ARM: reset: use do_reset in SPL/TPL if SYSRESET was not enabled for
them
imx: imx8m*: Remove do_reset from board files
imx: imx8m: Don't use the addr parameter of reset_cpu

 arch/arm/lib/Makefile             | 2 +-
 arch/arm/mach-imx/imx8m/soc.c     | 5 +----
 board/freescale/imx8mm_evk/spl.c  | 9 ---------
 board/freescale/imx8mn_evk/spl.c  | 9 ---------
 board/freescale/imx8mp_evk/spl.c  | 9 ---------
 board/toradex/verdin-imx8mm/spl.c | 9 ---------
 6 files changed, 2 insertions(+), 41 deletions(-)
Signature · 5 lines
Harald

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

PATCH 1/3 ARM: reset: use do_reset in SPL/TPL if SYSRESET was not enabled for them

From: Claudius Heine <[email protected]>

In case CONFIG_SYSRESET is set, do_reset from reset.c will not be available anywere, even if SYSRESET is disabled for SPL/TPL.

'do_reset' is called from SPL for instance from the panic handler and PANIC_HANG is not set

---
 arch/arm/lib/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/lib/Makefile +1 -1
index 8482f5446c5c..b839aa7a5096 100644
@@ -57,7 +57,7 @@ obj-y	+= interrupts_64.o
 else
 obj-y	+= interrupts.o
 endif
-ifndef CONFIG_SYSRESET
+ifndef CONFIG_$(SPL_TPL_)SYSRESET
 obj-y	+= reset.o
 endif
 
Signature · 1 line
2.24.1
#2 lore raw

PATCH 1/3 ARM: reset: use do_reset in SPL/TPL if SYSRESET was not enabled for them

Quoted 9 lines · Harald Seiler

From: Claudius Heine <[email protected]>

In case CONFIG_SYSRESET is set, do_reset from reset.c will not be available anywere, even if SYSRESET is disabled for SPL/TPL.

'do_reset' is called from SPL for instance from the panic handler and PANIC_HANG is not set

#3 lore raw

PATCH 1/3 ARM: reset: use do_reset in SPL/TPL if SYSRESET was not enabled for them

In reply to Harald Seiler
Quoted 7 lines

From: Claudius Heine <[email protected]>
In case CONFIG_SYSRESET is set, do_reset from reset.c will not be available anywere, even if SYSRESET is disabled for SPL/TPL.
'do_reset' is called from SPL for instance from the panic handler and PANIC_HANG is not set

Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================
#4 lore raw

PATCH 2/3 imx: imx8m*: Remove do_reset from board files

In reply to Harald Seiler

From: Claudius Heine <[email protected]>

Use the do_reset implementation of arch/arm/lib/reset.c in SPL instead. It is very close to what is done here, anyway, and plays more nicely with the rest of U-Boot than adding a custom do_reset implementation into board files.

do_reset from arch/arm/lib/reset.c calls reset_cpu with 0 as the addr parameter while the boards are passing WDOG1_BASE_ADDR. This is ok because the reset_cpu implementation uses WDOG1_BASE_ADDR by default if 0 is passed in.

---
 board/freescale/imx8mm_evk/spl.c  | 9 ---------
 board/freescale/imx8mn_evk/spl.c  | 9 ---------
 board/freescale/imx8mp_evk/spl.c  | 9 ---------
 board/toradex/verdin-imx8mm/spl.c | 9 ---------
 4 files changed, 36 deletions(-)
board/freescale/imx8mm_evk/spl.c +0 -9
index 5d17f397cb68..4d34622465b3 100644
@@ -161,12 +161,3 @@ void board_init_f(ulong dummy)
 
 	board_init_r(NULL, 0);
 }
-
-int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-	puts ("resetting ...\n");
-
-	reset_cpu(WDOG1_BASE_ADDR);
-
-	return 0;
-}
board/freescale/imx8mn_evk/spl.c +0 -9
index 7aed14c52b68..45417b24464d 100644
@@ -114,12 +114,3 @@ void board_init_f(ulong dummy)
 
 	board_init_r(NULL, 0);
 }
-
-int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-	puts("resetting ...\n");
-
-	reset_cpu(WDOG1_BASE_ADDR);
-
-	return 0;
-}
board/freescale/imx8mp_evk/spl.c +0 -9
index 0b20668e2b30..39c1dae684ac 100644
@@ -149,12 +149,3 @@ void board_init_f(ulong dummy)
 
 	board_init_r(NULL, 0);
 }
-
-int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-	puts("resetting ...\n");
-
-	reset_cpu(WDOG1_BASE_ADDR);
-
-	return 0;
-}
board/toradex/verdin-imx8mm/spl.c +0 -9
index a5dc54082054..dc5bd84f332e 100644
@@ -169,12 +169,3 @@ void board_init_f(ulong dummy)
 
 	board_init_r(NULL, 0);
 }
-
-int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-	puts("resetting ...\n");
-
-	reset_cpu(WDOG1_BASE_ADDR);
-
-	return 0;
-}
Signature · 1 line
2.24.1
#5 lore raw

PATCH 2/3 imx: imx8m*: Remove do_reset from board files

Quoted 15 lines · Harald Seiler

From: Claudius Heine <[email protected]>

Use the do_reset implementation of arch/arm/lib/reset.c in SPL instead. It is very close to what is done here, anyway, and plays more nicely with the rest of U-Boot than adding a custom do_reset implementation into board files.

do_reset from arch/arm/lib/reset.c calls reset_cpu with 0 as the addr parameter while the boards are passing WDOG1_BASE_ADDR. This is ok because the reset_cpu implementation uses WDOG1_BASE_ADDR by default if 0 is passed in.

Quoted 6 lines
---
 board/freescale/imx8mm_evk/spl.c  | 9 ---------
 board/freescale/imx8mn_evk/spl.c  | 9 ---------
 board/freescale/imx8mp_evk/spl.c  | 9 ---------
 board/toradex/verdin-imx8mm/spl.c | 9 ---------
 4 files changed, 36 deletions(-)
#6 lore raw

PATCH 2/3 imx: imx8m*: Remove do_reset from board files

In reply to Harald Seiler
Quoted 9 lines

From: Claudius Heine <[email protected]>
Use the do_reset implementation of arch/arm/lib/reset.c in SPL instead. It is very close to what is done here, anyway, and plays more nicely with the rest of U-Boot than adding a custom do_reset implementation into board files.
do_reset from arch/arm/lib/reset.c calls reset_cpu with 0 as the addr parameter while the boards are passing WDOG1_BASE_ADDR. This is ok because the reset_cpu implementation uses WDOG1_BASE_ADDR by default if 0 is passed in.

Quoted 4 lines

Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================
#7 lore raw

PATCH 3/3 imx: imx8m: Don't use the addr parameter of reset_cpu

In reply to Harald Seiler

From: Claudius Heine <[email protected]>

imx8m has the only implementation of reset_cpu which does not ignore the addr parameter and instead gives it some meaning as the base address of watchdog registers. This breaks convention with the rest of U-Boot where the parameter is ignored and callers are passing in 0.

Fixes d2041725e84b ("imx8m: restrict reset_cpu")
---
 arch/arm/mach-imx/imx8m/soc.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
arch/arm/mach-imx/imx8m/soc.c +1 -4
index 7fcbd53f3020..2d3afc61a452 100644
@@ -385,10 +385,7 @@ int ft_system_setup(void *blob, bd_t *bd)
 #if defined(CONFIG_SPL_BUILD) || !defined(CONFIG_SYSRESET)
 void reset_cpu(ulong addr)
 {
-       struct watchdog_regs *wdog = (struct watchdog_regs *)addr;
-
-       if (!addr)
-	       wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
+       struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
 
        /* Clear WDA to trigger WDOG_B immediately */
        writew((WCR_WDE | WCR_SRS), &wdog->wcr);
Signature · 1 line
2.24.1
#8 lore raw

PATCH 3/3 imx: imx8m: Don't use the addr parameter of reset_cpu

Quoted 21 lines · Harald Seiler

From: Claudius Heine <[email protected]>

imx8m has the only implementation of reset_cpu which does not ignore the addr parameter and instead gives it some meaning as the base address of watchdog registers. This breaks convention with the rest of U-Boot where the parameter is ignored and callers are passing in 0.

Fixes d2041725e84b ("imx8m: restrict reset_cpu")
---
 arch/arm/mach-imx/imx8m/soc.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
arch/arm/mach-imx/imx8m/soc.c +0 -0
index 7fcbd53f3020..2d3afc61a452 100644
@@ -385,10 +385,7 @@ int ft_system_setup(void *blob, bd_t *bd)
 #if defined(CONFIG_SPL_BUILD) || !defined(CONFIG_SYSRESET)

arch/arm/mach-imx/imx8m/soc.c int ft_system_setup(void *blob, bd_t *bd) · line 391

Quoted 10 lines
arch/arm/mach-imx/imx8m/soc.c +1 -4
 void reset_cpu(ulong addr)
 {
-       struct watchdog_regs *wdog = (struct watchdog_regs *)addr;
-
-       if (!addr)
-	       wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
+       struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
 
        /* Clear WDA to trigger WDOG_B immediately */
        writew((WCR_WDE | WCR_SRS), &wdog->wcr);

Can't we remove the param altogether ?

Otherwise

#9 lore raw

PATCH 3/3 imx: imx8m: Don't use the addr parameter of reset_cpu

Hello Marek,

Quoted 30 lines · Marek Vasut
Quoted 29 lines · Harald Seiler

From: Claudius Heine <[email protected]>

imx8m has the only implementation of reset_cpu which does not ignore the addr parameter and instead gives it some meaning as the base address of watchdog registers. This breaks convention with the rest of U-Boot where the parameter is ignored and callers are passing in 0.

Fixes d2041725e84b ("imx8m: restrict reset_cpu")
---
 arch/arm/mach-imx/imx8m/soc.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
arch/arm/mach-imx/imx8m/soc.c +1 -4
index 7fcbd53f3020..2d3afc61a452 100644
@@ -385,10 +385,7 @@ int ft_system_setup(void *blob, bd_t *bd)
 #if defined(CONFIG_SPL_BUILD) || !defined(CONFIG_SYSRESET)
 void reset_cpu(ulong addr)
 {
-       struct watchdog_regs *wdog = (struct watchdog_regs *)addr;
-
-       if (!addr)
-	       wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
+       struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
 
Quoted 4 lines

arch/arm/mach-imx/imx8m/soc.c int ft_system_setup(void *blob, bd_t *bd) · line 391

Quoted 2 lines
arch/arm/mach-imx/imx8m/soc.c +0 -0
        /* Clear WDA to trigger WDOG_B immediately */
        writew((WCR_WDE | WCR_SRS), &wdog->wcr);

Can't we remove the param altogether ?

Yes, that is what I would suggest as well. Although I'd do that as a separate follow up because it is not ARM nor i.MX specific.

Quoted 2 lines

Otherwise

Signature · 1 line
Harald
#10 lore raw

PATCH 3/3 imx: imx8m: Don't use the addr parameter of reset_cpu

In reply to Harald Seiler
Quoted 10 lines

From: Claudius Heine <[email protected]>
imx8m has the only implementation of reset_cpu which does not ignore the addr parameter and instead gives it some meaning as the base address of watchdog registers. This breaks convention with the rest of U-Boot where the parameter is ignored and callers are passing in 0.

Fixes d2041725e84b ("imx8m: restrict reset_cpu")

Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================
#11 lore raw

cover ARM: Fix reset in SPL if SYSRESET is not used

In reply to Harald Seiler

Hello,

Quoted 41 lines · Harald Seiler

Hello,

continuing on the discussion around Claudius' patch for fixing reset in SPL [1] we have taken a closer look at the issue. To quickly summarize the situation:

The original patch was to enable the generic ARM implementation of do_reset if CONFIG_SYSRESET is not enabled in SPL. This would break compilation for some boards which define their own do_reset in board/*/spl.c.

To be more specific, the following 4 boards have this custom do_reset:

- toradex/verdin-imx8mm
- freescale/imx8mn_evk
- freescale/imx8mm_evk
- freescale/imx8mp_evk

I hope we can all agree that do_reset is not at all meant to be implemented in board files. From looking at the related code for imx8m, it feels like this was just a workaround hack to archieve the same thing which Claudius has fixed. So this patch series reverts the addition of do_reset implementations in imx8m board files and instead switches to using the proper fix provided by Claudius.

Additionally, the custom do_reset implementations were passing an address (WDOG1_BASE_ADDR) to reset_cpu() instead of 0. This is the only place in the entire U-Boot tree where this happens. Instead, all other implementations simply ignore the parameter and 0 is passed by callers. It looks a lot like this is a legacy left-over which makes me think that using it for a (hard-coded) watchdog address is not a good idea as it breaks convention with the rest of U-Boot.

[1]: https://patchwork.ozlabs.org/patch/1201959

Claudius Heine (3):
ARM: reset: use do_reset in SPL/TPL if SYSRESET was not enabled for
them
imx: imx8m*: Remove do_reset from board files
imx: imx8m: Don't use the addr parameter of reset_cpu

Quoted 8 lines
 arch/arm/lib/Makefile             | 2 +-
 arch/arm/mach-imx/imx8m/soc.c     | 5 +----
 board/freescale/imx8mm_evk/spl.c  | 9 ---------
 board/freescale/imx8mn_evk/spl.c  | 9 ---------
 board/freescale/imx8mp_evk/spl.c  | 9 ---------
 board/toradex/verdin-imx8mm/spl.c | 9 ---------
 6 files changed, 2 insertions(+), 41 deletions(-)

Quick question, what is the situation with this series? Is there anything which needs to be addressed?

Without it, CONFIG_SPL_USB_SDP_SUPPORT is broken on the imx6q hardware I am working with and I guess the same issue might exist on many other boards as well (The USB stack needs a do_reset() implementation in SPL).

Regards,

Signature · 1 line
Harald
#12 lore raw

cover ARM: Fix reset in SPL if SYSRESET is not used

Quoted 53 lines · Harald Seiler

Hello,

Quoted 41 lines · Harald Seiler

Hello,

continuing on the discussion around Claudius' patch for fixing reset in SPL [1] we have taken a closer look at the issue. To quickly summarize the situation:

The original patch was to enable the generic ARM implementation of do_reset if CONFIG_SYSRESET is not enabled in SPL. This would break compilation for some boards which define their own do_reset in board/*/spl.c.

To be more specific, the following 4 boards have this custom do_reset:

- toradex/verdin-imx8mm
- freescale/imx8mn_evk
- freescale/imx8mm_evk
- freescale/imx8mp_evk

I hope we can all agree that do_reset is not at all meant to be implemented in board files. From looking at the related code for imx8m, it feels like this was just a workaround hack to archieve the same thing which Claudius has fixed. So this patch series reverts the addition of do_reset implementations in imx8m board files and instead switches to using the proper fix provided by Claudius.

Additionally, the custom do_reset implementations were passing an address (WDOG1_BASE_ADDR) to reset_cpu() instead of 0. This is the only place in the entire U-Boot tree where this happens. Instead, all other implementations simply ignore the parameter and 0 is passed by callers. It looks a lot like this is a legacy left-over which makes me think that using it for a (hard-coded) watchdog address is not a good idea as it breaks convention with the rest of U-Boot.

[1]: https://patchwork.ozlabs.org/patch/1201959

Claudius Heine (3):
ARM: reset: use do_reset in SPL/TPL if SYSRESET was not enabled for
them
imx: imx8m*: Remove do_reset from board files
imx: imx8m: Don't use the addr parameter of reset_cpu

Quoted 8 lines
 arch/arm/lib/Makefile             | 2 +-
 arch/arm/mach-imx/imx8m/soc.c     | 5 +----
 board/freescale/imx8mm_evk/spl.c  | 9 ---------
 board/freescale/imx8mn_evk/spl.c  | 9 ---------
 board/freescale/imx8mp_evk/spl.c  | 9 ---------
 board/toradex/verdin-imx8mm/spl.c | 9 ---------
 6 files changed, 2 insertions(+), 41 deletions(-)
Quoted 2 lines

Quick question, what is the situation with this series? Is there anything which needs to be addressed?

Patches are fine IMHO - I will merge them soon.

Stefano

Quoted 7 lines

Without it, CONFIG_SPL_USB_SDP_SUPPORT is broken on the imx6q hardware I am working with and I guess the same issue might exist on many other boards as well (The USB stack needs a do_reset() implementation in SPL).

Regards,

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================