watchdog: Fix Watchdog Reset while in U-Boot Prompt
PATCH 1/1 watchdog: Fix Watchdog Reset while in U-Boot Prompt
Hardware: CM-FX6 Module from Compulab
This patch fixes unwanted watchdog resets while the user enters a command at the U-Boot prompt.
As found on the CM-FX6 board from Compulab, when having enabled the watchdog, a missing WATCHDOG_RESET call in common/console.c causes this and alike boards to reset when the watchdog's timeout has elapsed while waiting at the U-Boot prompt.
Despite the user could press several keys within the watchdog timeout limit, the while loop in cli_readline.c, line 261, does only call WATCHDOG_RESET if first == 1, which gets set to 0 in the 1st loop iteration. This leads to a watchdog timeout no matter if the user presses keys or not.
Although, this affects other boards as well as it touches common/console.c, the macro WATCHDOG_RESET expands to {} if watchdog support isn't configured. Hence, there's no harm caused and no need to surround it by #ifdef in this case.
* Symptom:
U-Boot resets after watchdog times out when in commandline prompt and watchdog is enabled.
* Reasoning:
When U-Boot shows the commandline prompt, the following function call stack is executed while waiting for a keypress:
common/main.c:
main_loop => common/cli.c: cli_loop() =>
common/cli_hush.c:
parse_file_outer => parse_stream_outer =>
parse_stream => b_getch(i) =>
i->get(i) => file_get =>
get_user_input => cmdedit_read_input => uboot_cli_readline =>
common/cli_readline.c:
cli_readline => cli_readline_into_buffer =>
cread_line => getcmd_getch (== getc) =>
common/console.c:
fgetc => console_tstc
common/console.c:
(with CONFIG_CONSOLE_MUX is set)
- in console_tstc line 181:
If dev->tstc(dev) returns 0, the global tstcdev variable doesn't get set. This is the case if no character is in the serial buffer.
- in fgetc(int file), line 297:
Program flow keeps looping because tstcdev does not get set. Therefore WATCHDOG_RESET is not called, as mx_serial_tstc from drivers/serial/serial_mxc.c does not call it.
* Solution:
Add WATCHDOG_RESET into the loop of console_tstc.
Note: Macro expands to {} if not configured, so no #ifdef is needed.
* Comment:
---
common/console.c | 2 ++ 1 file changed, 2 insertions(+)
common/console.c +2 -0
@@ -16,6 +16,7 @@#include <stdio_dev.h> #include <exports.h> #include <environment.h> +#include <watchdog.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -294,6 +295,7 @@ int fgetc(int file)* Effectively poll for input wherever it may be available. */ for (;;) { +WATCHDOG_RESET ();/* * Upper layer may have already called tstc() so * check for that first.
Signature · 1 line
2.8.2
PATCH 1/1 watchdog: Fix Watchdog Reset while in U-Boot Prompt
Hi,
Quoted 58 lines · Andreas J. Reichel
Hardware: CM-FX6 Module from Compulab
This patch fixes unwanted watchdog resets while the user enters a command at the U-Boot prompt.
As found on the CM-FX6 board from Compulab, when having enabled the watchdog, a missing
WATCHDOG_RESETcall incommon/console.ccauses this and alike boards to reset when the watchdog's timeout has elapsed while waiting at the U-Boot prompt.Despite the user could press several keys within the watchdog timeout limit, the while loop in
cli_readline.c, line 261, does only callWATCHDOG_RESETif first == 1, which gets set to 0 in the 1st loop iteration. This leads to a watchdog timeout no matter if the user presses keys or not.Although, this affects other boards as well as it touches
common/console.c, the macroWATCHDOG_RESETexpands to {} if watchdog support isn't configured. Hence, there's no harm caused and no need to surround it by #ifdef in this case.* Symptom:
U-Boot resets after watchdog times out when in commandline prompt and watchdog is enabled.* Reasoning:
When U-Boot shows the commandline prompt, the following function call stack is executed while waiting for a keypress:
common/main.c:
main_loop=>common/cli.c:cli_loop()=>
common/cli_hush.c:parse_file_outer => parse_stream_outer => parse_stream => b_getch(i) => i->get(i) => file_get => get_user_input => cmdedit_read_input =>
uboot_cli_readline=>
common/cli_readline.c:
cli_readline=>cli_readline_into_buffer=>
cread_line=>getcmd_getch(== getc) =>
common/console.c:
fgetc =>console_tstc
common/console.c:
(withCONFIG_CONSOLE_MUXis set)- in
console_tstcline 181:
Ifdev->tstc(dev)returns 0, the global tstcdev variable doesn't get set. This is the case if no character is in the serial buffer.- in fgetc(int file), line 297:
Program flow keeps looping because tstcdev does not get set. ThereforeWATCHDOG_RESETis not called, asmx_serial_tstcfromdrivers/serial/serial_mxc.cdoes not call it.* Solution:
AddWATCHDOG_RESETinto the loop ofconsole_tstc.
Quoted 7 lines
Note: Macro expands to {} if not configured, so no #ifdef is needed.
* Comment:
Signed-off-by Christian Storm <[email protected]>Signed-off-by Jan Kiszka <[email protected]>Signed-off-by Andreas J. Reichel <[email protected]>
Thanks for the detailed info.
Would it be better to put this in _serial_tstc()?
Quoted 26 lines
---
common/console.c | 2 ++ 1 file changed, 2 insertions(+)common/console.c +2
-1@@ -16,6 +16,7 @@#include <stdio_dev.h> #include <exports.h> #include <environment.h> +#include <watchdog.h> DECLARE_GLOBAL_DATA_PTR ;@@ -294,6 +295,7 @@ int fgetc(int file)* Effectively poll for input wherever it may be available. */ for (;;) { +WATCHDOG_RESET ();/* * Upper layer may have already called tstc() so * check for that first. --
Quoted 2 lines
2.8.2
Regards,
Simon
PATCH v2 1/1 watchdog: Fix Watchdog Reset while in U-Boot Prompt
This patch fixes unwanted watchdog resets while the user enters a command at the U-Boot prompt.
As found on the CM-FX6 board from Compulab, when having enabled the watchdog, a missing WATCHDOG_RESET call in _serial_tstc() in (/drivers/serial/serial-uclass.c) causes this and alike boards to reset when the watchdog's timeout has elapsed while waiting at the U-Boot prompt.
Despite the user could press several keys within the watchdog timeout limit, the while loop in cli_readline.c, line 261, does only call WATCHDOG_RESET if first == 1, which gets set to 0 in the 1st loop iteration. This leads to a watchdog timeout no matter if the user presses keys or not.
The problem is solved with a call to WATCHDOG_RESET in _serial_tstc, defined in drivers/serial/serial-uclass.c.
Since the macro WATCHDOG_RESET expands to {} if watchdog support isn't configured, there's no need to surround it by #ifdef in this case.
* Symptom:
U-Boot resets after watchdog times out when in commandline prompt and watchdog is enabled.
* Reasoning:
When U-Boot shows the commandline prompt, the following function call stack is executed while waiting for a keypress:
common/main.c:
main_loop => common/cli.c: cli_loop() =>
common/cli_hush.c:
parse_file_outer => parse_stream_outer =>
parse_stream => b_getch(i) =>
i->get(i) => file_get =>
get_user_input => cmdedit_read_input => uboot_cli_readline =>
common/cli_readline.c:
cli_readline => cli_readline_into_buffer =>
cread_line => getcmd_getch (== getc) =>
commonn/console.c:
fgetc => console_tstc
- in console_tstc line 181:
If dev->tstc(dev) returns 0, the global tstcdev variable doesn't get set. This is the case if no character is in the serial buffer.
- in fgetc(int file), line 297:
Program flow keeps looping because tstcdev does not get set. Therefore WATCHDOG_RESET is not called, as mx_serial_tstc from drivers/serial/serial_mxc.c does not call it.
- Initialization calls drv_system_init in stdio.c, which sets dev.tstc = stdio_serial_tstc. Thus, dev->tstc(dev) calls serial_tstc() which in turn calls _serial_tstc().
Hence, _serial_tstc() needs to call WATCHDOG_RESET() to periodically reset the watchdog while cli_readline waits for user input.
---
Changes in v2:
- Move WATCHDOG_RESET() call from common/console.c to drivers/serial/serial-uclass.c.
drivers/serial/serial-uclass.c | 1 + 1 file changed, 1 insertion(+)
drivers/serial/serial-uclass.c +1 -0
@@ -155,6 +155,7 @@ static int _serial_tstc(struct udevice *dev) {struct dm_serial_ops *ops =serial_get_ops (dev); +WATCHDOG_RESET ();if (ops->pending)return ops->pending (dev, true);
Signature · 1 line
2.8.2
PATCH v2 1/1 watchdog: Fix Watchdog Reset while in U-Boot Prompt
+Tom, in case this should go into the release.
Quoted 77 lines · Andreas J. Reichel
This patch fixes unwanted watchdog resets while the user enters a command at the U-Boot prompt.
As found on the CM-FX6 board from Compulab, when having enabled the watchdog, a missing
WATCHDOG_RESETcall in_serial_tstc()in (/drivers/serial/serial-uclass.c) causes this and alike boards to reset when the watchdog's timeout has elapsed while waiting at the U-Boot prompt.Despite the user could press several keys within the watchdog timeout limit, the while loop in
cli_readline.c, line 261, does only callWATCHDOG_RESETif first == 1, which gets set to 0 in the 1st loop iteration. This leads to a watchdog timeout no matter if the user presses keys or not.The problem is solved with a call to
WATCHDOG_RESETin_serial_tstc, defined indrivers/serial/serial-uclass.c.Since the macro
WATCHDOG_RESETexpands to {} if watchdog support isn't configured, there's no need to surround it by #ifdef in this case.* Symptom:
U-Boot resets after watchdog times out when in commandline prompt and watchdog is enabled.* Reasoning:
When U-Boot shows the commandline prompt, the following function call stack is executed while waiting for a keypress:
common/main.c:
main_loop=>common/cli.c:cli_loop()=>
common/cli_hush.c:parse_file_outer => parse_stream_outer => parse_stream => b_getch(i) => i->get(i) => file_get => get_user_input => cmdedit_read_input =>
uboot_cli_readline=>
common/cli_readline.c:
cli_readline=>cli_readline_into_buffer=>
cread_line=>getcmd_getch(== getc) =>
commonn/console.c:
fgetc =>console_tstc- in
console_tstcline 181:
Ifdev->tstc(dev)returns 0, the global tstcdev variable doesn't get set. This is the case if no character is in the serial buffer.- in fgetc(int file), line 297:
Program flow keeps looping because tstcdev does not get set. ThereforeWATCHDOG_RESETis not called, asmx_serial_tstcfromdrivers/serial/serial_mxc.cdoes not call it.- Initialization calls
drv_system_initinstdio.c, which sets dev.tstc =stdio_serial_tstc. Thus,dev->tstc(dev)callsserial_tstc()which in turn calls_serial_tstc().Hence,
_serial_tstc()needs to callWATCHDOG_RESET()to periodically reset the watchdog whilecli_readlinewaits for user input.Signed-off-by Christian Storm <[email protected]>Signed-off-by Jan Kiszka <[email protected]>Signed-off-by Andreas J. Reichel <[email protected]>---
Changes in v2:
- MoveWATCHDOG_RESET()call fromcommon/console.ctodrivers/serial/serial-uclass.c.drivers/serial/serial-uclass.c | 1 + 1 file changed, 1 insertion(+)drivers/serial/serial-uclass.c +0
-0
drivers/serial/serial-uclass.c static int _serial_tstc(struct udevice *dev) · line 160
Quoted 6 lines
drivers/serial/serial-uclass.c +1
-0@@ -155,6 +155,7 @@ static int _serial_tstc(struct udevice *dev) {struct dm_serial_ops *ops =serial_get_ops (dev); +WATCHDOG_RESET ();if (ops->pending)return ops->pending (dev, true);
Great explanation, thank you.
Quoted 4 lines
drivers/serial/serial-uclass.c +0
-1--2.8.2
PATCH v2 1/1 watchdog: Fix Watchdog Reset while in U-Boot Prompt
Hi Tom,
is my patch going to be applied or is the problem resolved otherwhise?
Kind regards
Andreas
Quoted 96 lines · Simon Glass
+Tom, in case this should go into the release.
Quoted 77 lines · Andreas J. Reichel
This patch fixes unwanted watchdog resets while the user enters a command at the U-Boot prompt.
As found on the CM-FX6 board from Compulab, when having enabled the watchdog, a missing
WATCHDOG_RESETcall in_serial_tstc()in (/drivers/serial/serial-uclass.c) causes this and alike boards to reset when the watchdog's timeout has elapsed while waiting at the U-Boot prompt.Despite the user could press several keys within the watchdog timeout limit, the while loop in
cli_readline.c, line 261, does only callWATCHDOG_RESETif first == 1, which gets set to 0 in the 1st loop iteration. This leads to a watchdog timeout no matter if the user presses keys or not.The problem is solved with a call to
WATCHDOG_RESETin_serial_tstc, defined indrivers/serial/serial-uclass.c.Since the macro
WATCHDOG_RESETexpands to {} if watchdog support isn't configured, there's no need to surround it by #ifdef in this case.* Symptom:
U-Boot resets after watchdog times out when in commandline prompt and watchdog is enabled.* Reasoning:
When U-Boot shows the commandline prompt, the following function call stack is executed while waiting for a keypress:
common/main.c:
main_loop=>common/cli.c:cli_loop()=>
common/cli_hush.c:parse_file_outer => parse_stream_outer => parse_stream => b_getch(i) => i->get(i) => file_get => get_user_input => cmdedit_read_input =>
uboot_cli_readline=>
common/cli_readline.c:
cli_readline=>cli_readline_into_buffer=>
cread_line=>getcmd_getch(== getc) =>
commonn/console.c:
fgetc =>console_tstc- in
console_tstcline 181:
Ifdev->tstc(dev)returns 0, the global tstcdev variable doesn't get set. This is the case if no character is in the serial buffer.- in fgetc(int file), line 297:
Program flow keeps looping because tstcdev does not get set. ThereforeWATCHDOG_RESETis not called, asmx_serial_tstcfromdrivers/serial/serial_mxc.cdoes not call it.- Initialization calls
drv_system_initinstdio.c, which sets dev.tstc =stdio_serial_tstc. Thus,dev->tstc(dev)callsserial_tstc()which in turn calls_serial_tstc().Hence,
_serial_tstc()needs to callWATCHDOG_RESET()to periodically reset the watchdog whilecli_readlinewaits for user input.Signed-off-by Christian Storm <[email protected]>Signed-off-by Jan Kiszka <[email protected]>Signed-off-by Andreas J. Reichel <[email protected]>---
Changes in v2:
- MoveWATCHDOG_RESET()call fromcommon/console.ctodrivers/serial/serial-uclass.c.drivers/serial/serial-uclass.c | 1 + 1 file changed, 1 insertion(+)drivers/serial/serial-uclass.c +0
-0drivers/serial/serial-uclass.c static int _serial_tstc(struct udevice *dev) · line 160
Quoted 6 lines
drivers/serial/serial-uclass.c +1
-0@@ -155,6 +155,7 @@ static int _serial_tstc(struct udevice *dev) {struct dm_serial_ops *ops =serial_get_ops (dev); +WATCHDOG_RESET ();if (ops->pending)return ops->pending (dev, true);Great explanation, thank you.
Acked-by Simon Glass <[email protected]>Quoted 4 lines
drivers/serial/serial-uclass.c +0
-1--2.8.2
Signature · 10 lines
Andreas Reichel Dipl.-Phys. (Univ.) Software Consultant Andreas.Reichel at tngtech.com +49-174-3180074 TNG Technology Consulting GmbH, Betastr. 13a, 85774 Unterf?hring Gesch?ftsf?hrer: Henrik Klagges, Christoph Stock, Dr. Robert Dahlke Sitz: Unterf?hring * Amtsgericht M?nchen * HRB 135082
PATCH v2 1/1 watchdog: Fix Watchdog Reset while in U-Boot Prompt
Quoted 4 lines · Andreas Reichel
Hi Tom,
is my patch going to be applied or is the problem resolved otherwhise?
Sorry, lost in my patchwork queue. I'll pick this up soon now.
Quoted 113 lines
Kind regards
AndreasQuoted 96 lines · Simon Glass
+Tom, in case this should go into the release.
Quoted 77 lines · Andreas J. Reichel
This patch fixes unwanted watchdog resets while the user enters a command at the U-Boot prompt.
As found on the CM-FX6 board from Compulab, when having enabled the watchdog, a missing
WATCHDOG_RESETcall in_serial_tstc()in (/drivers/serial/serial-uclass.c) causes this and alike boards to reset when the watchdog's timeout has elapsed while waiting at the U-Boot prompt.Despite the user could press several keys within the watchdog timeout limit, the while loop in
cli_readline.c, line 261, does only callWATCHDOG_RESETif first == 1, which gets set to 0 in the 1st loop iteration. This leads to a watchdog timeout no matter if the user presses keys or not.The problem is solved with a call to
WATCHDOG_RESETin_serial_tstc, defined indrivers/serial/serial-uclass.c.Since the macro
WATCHDOG_RESETexpands to {} if watchdog support isn't configured, there's no need to surround it by #ifdef in this case.* Symptom:
U-Boot resets after watchdog times out when in commandline prompt and watchdog is enabled.* Reasoning:
When U-Boot shows the commandline prompt, the following function call stack is executed while waiting for a keypress:
common/main.c:
main_loop=>common/cli.c:cli_loop()=>
common/cli_hush.c:parse_file_outer => parse_stream_outer => parse_stream => b_getch(i) => i->get(i) => file_get => get_user_input => cmdedit_read_input =>
uboot_cli_readline=>
common/cli_readline.c:
cli_readline=>cli_readline_into_buffer=>
cread_line=>getcmd_getch(== getc) =>
commonn/console.c:
fgetc =>console_tstc- in
console_tstcline 181:
Ifdev->tstc(dev)returns 0, the global tstcdev variable doesn't get set. This is the case if no character is in the serial buffer.- in fgetc(int file), line 297:
Program flow keeps looping because tstcdev does not get set. ThereforeWATCHDOG_RESETis not called, asmx_serial_tstcfromdrivers/serial/serial_mxc.cdoes not call it.- Initialization calls
drv_system_initinstdio.c, which sets dev.tstc =stdio_serial_tstc. Thus,dev->tstc(dev)callsserial_tstc()which in turn calls_serial_tstc().Hence,
_serial_tstc()needs to callWATCHDOG_RESET()to periodically reset the watchdog whilecli_readlinewaits for user input.Signed-off-by Christian Storm <[email protected]>Signed-off-by Jan Kiszka <[email protected]>Signed-off-by Andreas J. Reichel <[email protected]>---
Changes in v2:
- MoveWATCHDOG_RESET()call fromcommon/console.ctodrivers/serial/serial-uclass.c.drivers/serial/serial-uclass.c | 1 + 1 file changed, 1 insertion(+)drivers/serial/serial-uclass.c +0
-0drivers/serial/serial-uclass.c static int _serial_tstc(struct udevice *dev) · line 160
Quoted 6 lines
drivers/serial/serial-uclass.c +1
-0@@ -155,6 +155,7 @@ static int _serial_tstc(struct udevice *dev) {struct dm_serial_ops *ops =serial_get_ops (dev); +WATCHDOG_RESET ();if (ops->pending)return ops->pending (dev, true);Great explanation, thank you.
Acked-by Simon Glass <[email protected]>Quoted 4 lines
drivers/serial/serial-uclass.c +0
-1--2.8.2
Signature · 10 lines
Andreas Reichel Dipl.-Phys. (Univ.) Software Consultant Andreas.Reichel at tngtech.com +49-174-3180074 TNG Technology Consulting GmbH, Betastr. 13a, 85774 Unterf?hring Gesch?ftsf?hrer: Henrik Klagges, Christoph Stock, Dr. Robert Dahlke Sitz: Unterf?hring * Amtsgericht M?nchen * HRB 135082
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20161014/76937bc6/attachment.sig>
v2 cover Fix U-Boot Prompt on CM-FX6 with enabled watchdog
In reply to Simon GlassThis patch fixes unwanted watchdog resets while the user enters a command at the U-Boot prompt.
As found on the CM-FX6 board from Compulab, when having enabled the watchdog, a missing WATCHDOG_RESET call in _serial_tstc() in (/drivers/serial/serial-uclass.c) causes this and alike boards to reset when the watchdog's timeout has elapsed while waiting at the U-Boot prompt.
Despite the user could press several keys within the watchdog timeout limit, the while loop in cli_readline.c, line 261, does only call WATCHDOG_RESET if first == 1, which gets set to 0 in the 1st loop iteration. This leads to a watchdog timeout no matter if the user presses keys or not.
The problem is solved with a call to WATCHDOG_RESET in _serial_tstc, defined in drivers/serial/serial-uclass.c.
Since the macro WATCHDOG_RESET expands to {} if watchdog support isn't configured, there's no need to surround it by #ifdef in this case.
Changes in v2:
- Move WATCHDOG_RESET() call from common/console.c to drivers/serial/serial-uclass.c.
Andreas J. Reichel (1):
watchdog: Fix Watchdog Reset while in U-Boot Prompt
drivers/serial/serial-uclass.c | 1 + 1 file changed, 1 insertion(+)
Signature · 1 line
2.8.2
PATCH 1/1 watchdog: Fix Watchdog Reset while in U-Boot Prompt
In reply to Andreas J. ReichelQuoted 58 lines · Andreas J. Reichel
Hardware: CM-FX6 Module from Compulab
This patch fixes unwanted watchdog resets while the user enters a command at the U-Boot prompt.
As found on the CM-FX6 board from Compulab, when having enabled the watchdog, a missing
WATCHDOG_RESETcall incommon/console.ccauses this and alike boards to reset when the watchdog's timeout has elapsed while waiting at the U-Boot prompt.Despite the user could press several keys within the watchdog timeout limit, the while loop in
cli_readline.c, line 261, does only callWATCHDOG_RESETif first == 1, which gets set to 0 in the 1st loop iteration. This leads to a watchdog timeout no matter if the user presses keys or not.Although, this affects other boards as well as it touches
common/console.c, the macroWATCHDOG_RESETexpands to {} if watchdog support isn't configured. Hence, there's no harm caused and no need to surround it by #ifdef in this case.* Symptom:
U-Boot resets after watchdog times out when in commandline prompt and watchdog is enabled.* Reasoning:
When U-Boot shows the commandline prompt, the following function call stack is executed while waiting for a keypress:
common/main.c:
main_loop=>common/cli.c:cli_loop()=>
common/cli_hush.c:parse_file_outer => parse_stream_outer => parse_stream => b_getch(i) => i->get(i) => file_get => get_user_input => cmdedit_read_input =>
uboot_cli_readline=>
common/cli_readline.c:
cli_readline=>cli_readline_into_buffer=>
cread_line=>getcmd_getch(== getc) =>
common/console.c:
fgetc =>console_tstc
common/console.c:
(withCONFIG_CONSOLE_MUXis set)- in
console_tstcline 181:
Ifdev->tstc(dev)returns 0, the global tstcdev variable doesn't get set. This is the case if no character is in the serial buffer.- in fgetc(int file), line 297:
Program flow keeps looping because tstcdev does not get set. ThereforeWATCHDOG_RESETis not called, asmx_serial_tstcfromdrivers/serial/serial_mxc.cdoes not call it.* Solution:
AddWATCHDOG_RESETinto the loop ofconsole_tstc.
Quoted 8 lines
Note: Macro expands to {} if not configured, so no #ifdef is needed.
* Comment:
Signed-off-by Christian Storm <[email protected]>Signed-off-by Jan Kiszka <[email protected]>Signed-off-by Andreas J. Reichel <[email protected]>Acked-by Simon Glass <[email protected]>
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: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20161018/abca43d0/attachment.sig>