From: Piotr Dymacz Date: Tue, 13 Jun 2017 20:53:04 +0000 (+0200) Subject: Add new custom command 'rstbywdt' for last reset reason check X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=007e4341621933d4ac78ecf760b9952129753b40;p=oweals%2Fu-boot_mod.git Add new custom command 'rstbywdt' for last reset reason check Add a small helper command 'rstbywdt' which returns true if the last system reset was caused by the SOC watchdog. It can be used for example to boot different kernel in case of reset caused by watchdog: if rstbywdt; then bootm 0x9FE80000; else bootm 0x9F050000; fi Also, show a warning at boot if last reset was caused by watchodg. --- diff --git a/u-boot/board/ar7240/common/common.c b/u-boot/board/ar7240/common/common.c index d69af94..1d20173 100644 --- a/u-boot/board/ar7240/common/common.c +++ b/u-boot/board/ar7240/common/common.c @@ -76,6 +76,22 @@ void qca_soc_name_rev(char *buf) } } +/* + * Returns last reset reason: + * 1 -> reset by watchdog + * 0 -> normal reset + */ +int last_reset_wdt() +{ + u32 reg; + + reg = qca_soc_reg_read(QCA_RST_WATCHDOG_TIMER_CTRL_REG); + if (reg & QCA_RST_WATCHDOG_TIMER_CTRL_LAST_MASK) + return 1; + + return 0; +} + /* * Prints available information about the board */ @@ -89,6 +105,10 @@ void print_board_info(void) bd_t *bd = gd->bd; char buffer[24]; + /* Show warning if last reboot was caused by SOC watchdog */ + if (last_reset_wdt()) + puts("** Warning: reset caused by watchdog!\n\n"); + /* Board name */ printf("%" ALIGN_SIZE "s %s\n", "BOARD:", MK_STR(CONFIG_BOARD_CUSTOM_STRING)); diff --git a/u-boot/common/cmd_custom.c b/u-boot/common/cmd_custom.c index cfefe1a..d74f0f4 100644 --- a/u-boot/common/cmd_custom.c +++ b/u-boot/common/cmd_custom.c @@ -311,3 +311,15 @@ int do_ledoff(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) U_BOOT_CMD(ledon, 1, 1, do_ledon, "turn LED/s on\n", NULL); U_BOOT_CMD(ledoff, 1, 1, do_ledoff, "turn LED/s off\n", NULL); #endif /* CONFIG_CMD_LED */ + +/* + * Checks if last reset was caused by watchdog + */ +#if defined(CONFIG_CMD_RSTBYWDT) +int do_rstbywdt(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) +{ + return !last_reset_wdt(); +} + +U_BOOT_CMD(rstbywdt, 1, 1, do_rstbywdt, "check if last reset was caused by watchdog\n", NULL); +#endif /* CONFIG_CMD_RSTBYWDT */ diff --git a/u-boot/include/common.h b/u-boot/include/common.h index a52548e..cc32b91 100644 --- a/u-boot/include/common.h +++ b/u-boot/include/common.h @@ -191,6 +191,7 @@ int checkboard(void); int checkflash(void); int checkdram(void); int last_stage_init(void); +int last_reset_wdt(void); int reset_button_status(void); extern ulong monitor_flash_len; diff --git a/u-boot/include/configs/qca9k_common.h b/u-boot/include/configs/qca9k_common.h index 360c676..4cd3505 100644 --- a/u-boot/include/configs/qca9k_common.h +++ b/u-boot/include/configs/qca9k_common.h @@ -114,6 +114,7 @@ #define CONFIG_CMD_MEMORY #define CONFIG_CMD_NET #define CONFIG_CMD_PING +#define CONFIG_CMD_RSTBYWDT #define CONFIG_CMD_RUN #define CONFIG_CMD_SETEXPR #define CONFIG_CMD_SLEEP