Skip to contentSkip to conversation

board_r: move initr_watchdog to be called after initr_serial

PATCH New Weijie Gao 5 participants 9 messages May 16, 2019 – Jul 8, 2019

lore
Share & tools
lore

Weijie Gao

author
#0 lore raw

PATCH v2 1/3 board_r: move initr_watchdog to be called after initr_serial

The initr_watchdog is currently placed before initr_serial. The initr_watchdog calls printf and printf finally calls ops->putc of a serial driver.

However, gd->cur_serial_dev points to a udevice allocated in board_f. The gd->cur_serial_dev->driver->ops->putc points the the code region before relocation.

Some serial drivers call WATCHDOG_RESET() in ops->putc. When DM is enabled for watchdog, watchdog_reset() is called. watchdog_reset() calls get_timer to get current timer.

On some platforms the timer driver is also a DM driver. initr_watchdog is placed right after initr_dm, which means the timer driver hasn't been initialized. So dm_timer_init() is called. To create a new udevice, calloc is called.

However start from ops->putc, u-boot execution flow is redirected into the memory region before relocation (board_f). In board_f, dlmalloc hasn't been initialized. The call to calloc will fail, and this will cause DM to print out an error message, and it will call printf again, causing recursive error outputs.

This patch places initr_watchdog after initr_serial to solve this issue.

---
Changes since v1: move initr_watchdog instead of initr_serial

---
 common/board_r.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
common/board_r.c +3 -3
index 150e8cd424..df24021f2c 100644
@@ -678,9 +678,6 @@ static init_fnc_t init_sequence_r[] = {
 #ifdef CONFIG_DM
 	initr_dm,
 #endif
-#if defined(CONFIG_WDT)
-	initr_watchdog,
-#endif
 #if defined(CONFIG_ARM) || defined(CONFIG_NDS32) || defined(CONFIG_RISCV) || \
 	defined(CONFIG_SANDBOX)
 	board_init,	/* Setup chipselects */
@@ -700,6 +697,9 @@ static init_fnc_t init_sequence_r[] = {
 	stdio_init_tables,
 	initr_serial,
 	initr_announce,
+#if defined(CONFIG_WDT)
+	initr_watchdog,
+#endif
 	INIT_FUNC_WATCHDOG_RESET
 #ifdef CONFIG_NEEDS_MANUAL_RELOC
 	initr_manual_reloc_cmdtable,
Signature · 1 line
2.18.0
#1 lore raw

PATCH v2 1/3 board_r: move initr_watchdog to be called, after initr_serial

Hi,

May I know if this patch is still under review ?

I have converted OMAP3 watchdog driver into driver model for TI AM33XX based SOC and tested corresponding patches on BeagleBone Black board.

Build was successful but board goes into a loop when turned on/runtime, problem identified and is in sync with Weijie Gao's explanation and his patch for such behaviour (please follow this thread for explanation).

When initr_watchdog is moved/placed just after initr_serial, board is behaving normal. Tested on BeagleBone Black.

Please suggest if there are any workarounds for this problem.

Regards

Signature · 6 lines
Suniel Mahesh
Embedded Linux, Kernel & U-Boot engineer
https://github.com/sunielmahesh
www.tuxtrons.com
https://github.com/techveda
Hyderabad, India
#2 lore raw

PATCH v2 1/3 board_r: move initr_watchdog to be called after initr_serial

In reply to Weijie Gao

Cc'ing a few people

Quoted 49 lines · Weijie Gao

The initr_watchdog is currently placed before initr_serial. The initr_watchdog calls printf and printf finally calls ops->putc of a serial driver.

However, gd->cur_serial_dev points to a udevice allocated in board_f. The gd->cur_serial_dev->driver->ops->putc points the the code region before relocation.

Some serial drivers call WATCHDOG_RESET() in ops->putc. When DM is enabled for watchdog, watchdog_reset() is called. watchdog_reset() calls get_timer to get current timer.

On some platforms the timer driver is also a DM driver. initr_watchdog is placed right after initr_dm, which means the timer driver hasn't been initialized. So dm_timer_init() is called. To create a new udevice, calloc is called.

However start from ops->putc, u-boot execution flow is redirected into the memory region before relocation (board_f). In board_f, dlmalloc hasn't been initialized. The call to calloc will fail, and this will cause DM to print out an error message, and it will call printf again, causing recursive error outputs.

This patch places initr_watchdog after initr_serial to solve this issue.

---
Changes since v1: move initr_watchdog instead of initr_serial

---
  common/board_r.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
common/board_r.c +0 -3
index 150e8cd424..df24021f2c 100644
@@ -678,9 +678,6 @@ static init_fnc_t init_sequence_r[] = {
  #ifdef CONFIG_DM
  	initr_dm,
  #endif
-#if defined(CONFIG_WDT)
-	initr_watchdog,
-#endif
  #if defined(CONFIG_ARM) || defined(CONFIG_NDS32) || defined(CONFIG_RISCV) || \
  	defined(CONFIG_SANDBOX)
  	board_init,	/* Setup chipselects */

common/board_r.c static init_fnc_t init_sequence_r[] = { · line 705

Quoted 9 lines
common/board_r.c +3 -0
@@ -700,6 +697,9 @@ static init_fnc_t init_sequence_r[] = {
  	stdio_init_tables,
  	initr_serial,
  	initr_announce,
+#if defined(CONFIG_WDT)
+	initr_watchdog,
+#endif
  	INIT_FUNC_WATCHDOG_RESET
  #ifdef CONFIG_NEEDS_MANUAL_RELOC
  	initr_manual_reloc_cmdtable,

Frank, does this patch fix the watchdog issue on your board as well?

Tom, could you please apply this patch to the upcoming release?

Thanks,
Stefan

#3 lore raw

PATCH v2 1/3 board_r: move initr_watchdog to be called after initr_serial

Hi Stefan/Tom

this Patch in combination with https://patchwork.ozlabs.org/patch/1113120/ seem to fix issues on bananapi-r2 /mt7623 (bootloop/hang on WDT servicing) if CONFIG_WATCHDOG is not set to "n" (else it will be set to y because of new "imply WATCHDOG" inside of "config WDT").

@tom can you please include this 2 Patches in master?

regards Frank

#5 lore raw

PATCH v2 1/3 board_r: move initr_watchdog to be called after initr_serial

Hi

It looks this fix is not yet merged. Tom can you add it before release? Without it bpi-r2 and maybe other boards are broken.

Regards Frank

#7 lore raw

PATCH v2 1/3 board_r: move initr_watchdog to be called after initr_serial

Agreed with frank. My patches for watchdog DM conversion depends on this change set.

tested on AM335x based Beaglebone Black

Regards

Signature · 6 lines
Suniel Mahesh
Embedded Linux, Kernel & U-Boot engineer
https://github.com/sunielmahesh
www.tuxtrons.com
https://github.com/techveda
Hyderabad, India
#8 lore raw

PATCH v2 1/3 board_r: move initr_watchdog to be called after initr_serial

In reply to Weijie Gao
Quoted 23 lines · Weijie Gao

The initr_watchdog is currently placed before initr_serial. The initr_watchdog calls printf and printf finally calls ops->putc of a serial driver.

However, gd->cur_serial_dev points to a udevice allocated in board_f. The gd->cur_serial_dev->driver->ops->putc points the the code region before relocation.

Some serial drivers call WATCHDOG_RESET() in ops->putc. When DM is enabled for watchdog, watchdog_reset() is called. watchdog_reset() calls get_timer to get current timer.

On some platforms the timer driver is also a DM driver. initr_watchdog is placed right after initr_dm, which means the timer driver hasn't been initialized. So dm_timer_init() is called. To create a new udevice, calloc is called.

However start from ops->putc, u-boot execution flow is redirected into the memory region before relocation (board_f). In board_f, dlmalloc hasn't been initialized. The call to calloc will fail, and this will cause DM to print out an error message, and it will call printf again, causing recursive error outputs.

Quoted 8 lines

This patch places initr_watchdog after initr_serial to solve this issue.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190707/e9beaa2b/attachment.sig>