Skip to contentSkip to conversation

x530: Enable watchdog

PATCH Superseded Chris Packham 2 participants 9 messages Feb 15, 2019

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover x530: Enable watchdog

We've seen some issues with the x530 under extreme conditions where the DDR gets into a bad state. Generally this results in an application crash, kernel panic then a lock-up in u-boot (generally just as the SPL hands off to u-boot proper).

Enabling the watchdog prevents the lock up and will let the DDR training have another go. Sometimes this recovers but even a reboot loop is better than a complete lockup.

Chris Packham (2):
watchdog: orion_wdt: support SPL usage
arm: mvebu: x530: Enable watchdog in SPL and U-Boot

 arch/arm/dts/armada-385-atl-x530-u-boot.dtsi |  4 ++
 board/alliedtelesis/x530/x530.c              | 48 ++++++++++++++++++++
 configs/x530_defconfig                       |  5 ++
 drivers/watchdog/orion_wdt.c                 |  4 +-
 4 files changed, 58 insertions(+), 3 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/2 watchdog: orion_wdt: support SPL usage

When run from the SPL the mvebu targets are using the hardware default offset for the SoC peripherals. devfdt_get_addr_size_index() understands how to deal with this via dm_get_translation_offset() so use this instead of fdtdec_get_addr_size_auto_noparent().

---

 drivers/watchdog/orion_wdt.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/watchdog/orion_wdt.c +1 -3
index a0df02d10382..c1add3e7c121 100644
@@ -114,9 +114,7 @@ static inline bool save_reg_from_ofdata(struct udevice *dev, int index,
 	fdt_addr_t addr;
 	fdt_size_t off;
 
-	addr = fdtdec_get_addr_size_auto_noparent(
-		gd->fdt_blob, dev_of_offset(dev), "reg", index, &off, true);
-
+	addr = devfdt_get_addr_size_index(dev, index, &off);
 	if (addr == FDT_ADDR_T_NONE)
 		return false;
 
Signature · 1 line
2.20.1
#2 lore raw

PATCH 1/2 watchdog: orion_wdt: support SPL usage

Quoted 6 lines · Chris Packham

When run from the SPL the mvebu targets are using the hardware default offset for the SoC peripherals. devfdt_get_addr_size_index() understands how to deal with this via dm_get_translation_offset() so use this instead of fdtdec_get_addr_size_auto_noparent().

Thanks,
Stefan

#3 lore raw

PATCH 2/2 arm: mvebu: x530: Enable watchdog in SPL and U-Boot

In reply to Chris Packham

Enable the hardware watchdog to guard against system lock ups when running in the SPL or U-Boot. Stop the watchdog just before booting so that the OS.

---

 arch/arm/dts/armada-385-atl-x530-u-boot.dtsi |  4 ++
 board/alliedtelesis/x530/x530.c              | 48 ++++++++++++++++++++
 configs/x530_defconfig                       |  5 ++
 3 files changed, 57 insertions(+)
arch/arm/dts/armada-385-atl-x530-u-boot.dtsi +4 -0
index 7074a73537fa..79b694cb84bc 100644
@@ -11,3 +11,7 @@
 &uart0 {
 	u-boot,dm-pre-reloc;
 };
+
+&watchdog {
+	u-boot,dm-pre-reloc;
+};
board/alliedtelesis/x530/x530.c +48 -0

81 lines not on this page · raw message

configs/x530_defconfig +5 -0
index 25b9e885d8e6..3bc37b9bee11 100644
@@ -19,6 +19,8 @@ CONFIG_SILENT_CONSOLE=y
 CONFIG_SILENT_U_BOOT_ONLY=y
 CONFIG_SILENT_CONSOLE_UPDATE_ON_RELOC=y
 CONFIG_MISC_INIT_R=y
+CONFIG_SPL_BOARD_INIT=y
+CONFIG_SPL_WATCHDOG_SUPPORT=y
 CONFIG_CMD_MEMINFO=y
 # CONFIG_CMD_FLASH is not set
 CONFIG_CMD_GPIO=y
@@ -70,3 +72,6 @@ CONFIG_USB_STORAGE=y
 CONFIG_USB_HOST_ETHER=y
 CONFIG_USB_ETHER_ASIX=y
 CONFIG_USB_ETHER_ASIX88179=y
+CONFIG_WATCHDOG=y
+CONFIG_WDT=y
+CONFIG_WDT_ORION=y
Signature · 1 line
2.20.1
#4 lore raw

PATCH 2/2 arm: mvebu: x530: Enable watchdog in SPL and U-Boot

Quoted 4 lines · Chris Packham

Enable the hardware watchdog to guard against system lock ups when running in the SPL or U-Boot. Stop the watchdog just before booting so that the OS.

D'oh managed to cut off the sentence.

so that the OS can re-enable it if needed.

Quoted 134 lines

---

 arch/arm/dts/armada-385-atl-x530-u-boot.dtsi |  4 ++
 board/alliedtelesis/x530/x530.c              | 48 ++++++++++++++++++++
 configs/x530_defconfig                       |  5 ++
 3 files changed, 57 insertions(+)
arch/arm/dts/armada-385-atl-x530-u-boot.dtsi +4 -0
index 7074a73537fa..79b694cb84bc 100644
@@ -11,3 +11,7 @@
 &uart0 {
        u-boot,dm-pre-reloc;
 };
+
+&watchdog {
+       u-boot,dm-pre-reloc;
+};
board/alliedtelesis/x530/x530.c +48 -0
index d7d1942fe686..1b22b6307cd2 100644
@@ -7,6 +7,7 @@
 #include <command.h>
 #include <dm.h>
 #include <i2c.h>
+#include <wdt.h>
 #include <asm/gpio.h>
 #include <linux/mbus.h>
 #include <linux/io.h>
@@ -24,6 +25,10 @@ DECLARE_GLOBAL_DATA_PTR;
 #define CONFIG_NVS_LOCATION            0xf4800000
 #define CONFIG_NVS_SIZE                        (512 << 10)
 
+#ifdef CONFIG_WATCHDOG
+static struct udevice *watchdog_dev;
+#endif
+
 static struct serdes_map board_serdes_map[] = {
        {PEX0, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0},
        {DEFAULT_SERDES, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0},
@@ -75,6 +80,10 @@ struct mv_ddr_topology_map *mv_ddr_topology_map_get(void)
 
 int board_early_init_f(void)
 {
+#ifdef CONFIG_WATCHDOG
+       watchdog_dev = NULL;
+#endif
+
        /* Configure MPP */
        writel(0x00001111, MVEBU_MPP_BASE + 0x00);
        writel(0x00000000, MVEBU_MPP_BASE + 0x04);
@@ -88,6 +97,17 @@ int board_early_init_f(void)
        return 0;
 }
 
+void spl_board_init(void)
+{
+#ifdef CONFIG_WATCHDOG
+       int ret;
+
+       ret = uclass_get_device(UCLASS_WDT, 0, &watchdog_dev);
+       if (!ret)
+               wdt_start(watchdog_dev, 25000000ULL * 120, 0);
+#endif
+}
+
 int board_init(void)
 {
        /* address of boot parameters */
@@ -100,9 +120,37 @@ int board_init(void)
        /* DEV_READYn is not needed for NVS, ignore it when accessing CS1 */
        writel(0x00004001, MVEBU_DEV_BUS_BASE + 0xc8);
 
+       spl_board_init();
+
        return 0;
 }
 
+void arch_preboot_os(void)
+{
+#ifdef CONFIG_WATCHDOG
+       wdt_stop(watchdog_dev);
+#endif
+}
+
+#ifdef CONFIG_WATCHDOG
+void watchdog_reset(void)
+{
+       static ulong next_reset = 0;
+       ulong now;
+
+       if (!watchdog_dev)
+               return;
+
+       now = timer_get_us();
+
+       /* Do not reset the watchdog too often */
+       if (now > next_reset) {
+               wdt_reset(watchdog_dev);
+               next_reset = now + 1000;
+       }
+}
+#endif
+
 static int led_7seg_init(unsigned int segments)
 {
        int node;
configs/x530_defconfig +5 -1
index 25b9e885d8e6..3bc37b9bee11 100644
@@ -19,6 +19,8 @@ CONFIG_SILENT_CONSOLE=y
 CONFIG_SILENT_U_BOOT_ONLY=y
 CONFIG_SILENT_CONSOLE_UPDATE_ON_RELOC=y
 CONFIG_MISC_INIT_R=y
+CONFIG_SPL_BOARD_INIT=y
+CONFIG_SPL_WATCHDOG_SUPPORT=y
 CONFIG_CMD_MEMINFO=y
 # CONFIG_CMD_FLASH is not set
 CONFIG_CMD_GPIO=y
@@ -70,3 +72,6 @@ CONFIG_USB_STORAGE=y
 CONFIG_USB_HOST_ETHER=y
 CONFIG_USB_ETHER_ASIX=y
 CONFIG_USB_ETHER_ASIX88179=y
+CONFIG_WATCHDOG=y
+CONFIG_WDT=y
+CONFIG_WDT_ORION=y
--

2.20.1

#5 lore raw

PATCH 2/2 arm: mvebu: x530: Enable watchdog in SPL and U-Boot

In reply to Chris Packham

Hi Chris,

Quoted 60 lines · Chris Packham

Enable the hardware watchdog to guard against system lock ups when running in the SPL or U-Boot. Stop the watchdog just before booting so that the OS.

---

  arch/arm/dts/armada-385-atl-x530-u-boot.dtsi |  4 ++
  board/alliedtelesis/x530/x530.c              | 48 ++++++++++++++++++++
  configs/x530_defconfig                       |  5 ++
  3 files changed, 57 insertions(+)
arch/arm/dts/armada-385-atl-x530-u-boot.dtsi +4 -0
index 7074a73537fa..79b694cb84bc 100644
@@ -11,3 +11,7 @@
  &uart0 {
  	u-boot,dm-pre-reloc;
  };
+
+&watchdog {
+	u-boot,dm-pre-reloc;
+};
board/alliedtelesis/x530/x530.c +9 -0
index d7d1942fe686..1b22b6307cd2 100644
@@ -7,6 +7,7 @@
  #include <command.h>
  #include <dm.h>
  #include <i2c.h>
+#include <wdt.h>
  #include <asm/gpio.h>
  #include <linux/mbus.h>
  #include <linux/io.h>
@@ -24,6 +25,10 @@ DECLARE_GLOBAL_DATA_PTR;
  #define CONFIG_NVS_LOCATION		0xf4800000
  #define CONFIG_NVS_SIZE			(512 << 10)
 
+#ifdef CONFIG_WATCHDOG
+static struct udevice *watchdog_dev;
+#endif
+
  static struct serdes_map board_serdes_map[] = {
  	{PEX0, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0},
  	{DEFAULT_SERDES, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0},
@@ -75,6 +80,10 @@ struct mv_ddr_topology_map *mv_ddr_topology_map_get(void)
 
  int board_early_init_f(void)
  {
+#ifdef CONFIG_WATCHDOG
+	watchdog_dev = NULL;
+#endif
+
  	/* Configure MPP */
  	writel(0x00001111, MVEBU_MPP_BASE + 0x00);
  	writel(0x00000000, MVEBU_MPP_BASE + 0x04);
@@ -88,6 +97,17 @@ int board_early_init_f(void)
  	return 0;

board/alliedtelesis/x530/x530.c int board_early_init_f(void) · line 107

Quoted 10 lines
board/alliedtelesis/x530/x530.c +8 -0
  }
 
+void spl_board_init(void)
+{
+#ifdef CONFIG_WATCHDOG
+	int ret;
+
+	ret = uclass_get_device(UCLASS_WDT, 0, &watchdog_dev);
+	if (!ret)
+		wdt_start(watchdog_dev, 25000000ULL * 120, 0);

This is CONFIG_SYS_TCLK? Would it make sense to use this macro instead here?

Quoted 11 lines
board/alliedtelesis/x530/x530.c +4 -0
+#endif
+}
+
  int board_init(void)
  {
  	/* address of boot parameters */
@@ -100,9 +120,37 @@ int board_init(void)
  	/* DEV_READYn is not needed for NVS, ignore it when accessing CS1 */
  	writel(0x00004001, MVEBU_DEV_BUS_BASE + 0xc8);
 
+	spl_board_init();

board/alliedtelesis/x530/x530.c int board_init(void) · line 133

Quoted 10 lines
board/alliedtelesis/x530/x530.c +7 -0
+
  	return 0;
  }
 
+void arch_preboot_os(void)
+{
+#ifdef CONFIG_WATCHDOG
+	wdt_stop(watchdog_dev);
+#endif
+}

So you are not using the WDT in the OS (Linux)?

Quoted 9 lines
board/alliedtelesis/x530/x530.c +9 -0
+
+#ifdef CONFIG_WATCHDOG
+void watchdog_reset(void)
+{
+	static ulong next_reset = 0;
+	ulong now;
+
+	if (!watchdog_dev)
+		return;

board/alliedtelesis/x530/x530.c int board_init(void) · line 152

Quoted 10 lines
board/alliedtelesis/x530/x530.c +10 -0
+
+	now = timer_get_us();
+
+	/* Do not reset the watchdog too often */
+	if (now > next_reset) {
+		wdt_reset(watchdog_dev);
+		next_reset = now + 1000;
+	}
+}
+#endif

When I recently implemented the watchdog support the MT7688, I wondered why there is so much code necessary, that each board and platform needs to copy to get this real watchdog working. We should definitely rework this at some time, so make this more generic with less board specific code that could be shared.

You don't need to change this here. I just wanted to express my thoughts, as I'm stumbling over this code again.

Other than this (and your commit text change):

Thanks,
Stefan

#6 lore raw

PATCH 2/2 arm: mvebu: x530: Enable watchdog in SPL and U-Boot

Quoted 68 lines · On Fri, 15 Feb 2019 21:46 Stefan Roese <[email protected] wrote:

Hi Chris,

Quoted 5 lines · Chris Packham

Enable the hardware watchdog to guard against system lock ups when running in the SPL or U-Boot. Stop the watchdog just before booting so that the OS.

Review

Quoted 8 lines

---

  arch/arm/dts/armada-385-atl-x530-u-boot.dtsi |  4 ++
  board/alliedtelesis/x530/x530.c              | 48 ++++++++++++++++++++
  configs/x530_defconfig                       |  5 ++
  3 files changed, 57 insertions(+)
(quoted diff) +0 -0

b/arch/arm/dts/armada-385-atl-x530-u-boot.dtsi

Review

Quoted 12 lines

index 7074a73537fa..79b694cb84bc 100644

arch/arm/dts/armada-385-atl-x530-u-boot.dtsi +4 -0
@@ -11,3 +11,7 @@
  &uart0 {
      u-boot,dm-pre-reloc;
  };
+
+&watchdog {
+     u-boot,dm-pre-reloc;
+};
(quoted diff) +0 -0

b/board/alliedtelesis/x530/x530.c

board/alliedtelesis/x530/x530.c struct mv_ddr_topology_map

Quoted 23 lines

index d7d1942fe686..1b22b6307cd2 100644

board/alliedtelesis/x530/x530.c +5 -0
@@ -7,6 +7,7 @@
  #include <command.h>
  #include <dm.h>
  #include <i2c.h>
+#include <wdt.h>
  #include <asm/gpio.h>
  #include <linux/mbus.h>
  #include <linux/io.h>
@@ -24,6 +25,10 @@ DECLARE_GLOBAL_DATA_PTR;
  #define CONFIG_NVS_LOCATION         0xf4800000
  #define CONFIG_NVS_SIZE                     (512 << 10)
 
+#ifdef CONFIG_WATCHDOG
+static struct udevice *watchdog_dev;
+#endif
+
  static struct serdes_map board_serdes_map[] = {
      {PEX0, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0},
      {DEFAULT_SERDES, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0},
@@ -75,6 +80,10 @@ struct mv_ddr_topology_map

*mv_ddr_topology_map_get(void)

Quoted 14 lines
board/alliedtelesis/x530/x530.c +4 -0
  int board_early_init_f(void)
  {
+#ifdef CONFIG_WATCHDOG
+     watchdog_dev = NULL;
+#endif
+
      /* Configure MPP */
      writel(0x00001111, MVEBU_MPP_BASE + 0x00);
      writel(0x00000000, MVEBU_MPP_BASE + 0x04);
@@ -88,6 +97,17 @@ int board_early_init_f(void)
      return 0;
  }
 
Quoted 12 lines

board/alliedtelesis/x530/x530.c int board_early_init_f(void) · line 107

Quoted 8 lines
board/alliedtelesis/x530/x530.c +8 -0
+void spl_board_init(void)
+{
+#ifdef CONFIG_WATCHDOG
+     int ret;
+
+     ret = uclass_get_device(UCLASS_WDT, 0, &watchdog_dev);
+     if (!ret)
+             wdt_start(watchdog_dev, 25000000ULL * 120, 0);

This is CONFIG_SYS_TCLK? Would it make sense to use this macro instead here?

Yes it would. I'll send a v2 with this change.

Ideally I'd specify the value in ms and have orion_wdt deal with the details of SYS_TCLK.

Quoted 61 lines

board/alliedtelesis/x530/x530.c int board_init(void) · line 120

Quoted 8 lines
board/alliedtelesis/x530/x530.c +3 -0
+#endif
+}
+
  int board_init(void)
  {
      /* address of boot parameters */
@@ -100,9 +120,37 @@ int board_init(void)
      /* DEV_READYn is not needed for NVS, ignore it when accessing CS1

*/

board/alliedtelesis/x530/x530.c int board_init(void) · line 133

Quoted 13 lines
board/alliedtelesis/x530/x530.c +8 -0
      writel(0x00004001, MVEBU_DEV_BUS_BASE + 0xc8);
 
+     spl_board_init();
+
      return 0;
  }
 
+void arch_preboot_os(void)
+{
+#ifdef CONFIG_WATCHDOG
+     wdt_stop(watchdog_dev);
+#endif
+}

So you are not using the WDT in the OS (Linux)?

Quoted 9 lines
board/alliedtelesis/x530/x530.c +9 -0
+
+#ifdef CONFIG_WATCHDOG
+void watchdog_reset(void)
+{
+     static ulong next_reset = 0;
+     ulong now;
+
+     if (!watchdog_dev)
+             return;

board/alliedtelesis/x530/x530.c int board_init(void) · line 152

Quoted 10 lines
board/alliedtelesis/x530/x530.c +10 -0
+
+     now = timer_get_us();
+
+     /* Do not reset the watchdog too often */
+     if (now > next_reset) {
+             wdt_reset(watchdog_dev);
+             next_reset = now + 1000;
+     }
+}
+#endif

When I recently implemented the watchdog support the MT7688, I wondered why there is so much code necessary, that each board and platform needs to copy to get this real watchdog working. We should definitely rework this at some time, so make this more generic with less board specific code that could be shared.

You don't need to change this here. I just wanted to express my thoughts, as I'm stumbling over this code again.

Other than this (and your commit text change):

Thanks,
Stefan

#7 lore raw

PATCH 2/2 arm: mvebu: x530: Enable watchdog in SPL and U-Boot

Quoted 82 lines · Chris Packham
Quoted 66 lines · On Fri, 15 Feb 2019 21:46 Stefan Roese <[email protected] wrote:

Hi Chris,

Quoted 62 lines · Chris Packham

Enable the hardware watchdog to guard against system lock ups when running in the SPL or U-Boot. Stop the watchdog just before booting so that the OS.

---

  arch/arm/dts/armada-385-atl-x530-u-boot.dtsi |  4 ++
  board/alliedtelesis/x530/x530.c              | 48 ++++++++++++++++++++
  configs/x530_defconfig                       |  5 ++
  3 files changed, 57 insertions(+)
arch/arm/dts/armada-385-atl-x530-u-boot.dtsi +4 -0
index 7074a73537fa..79b694cb84bc 100644
@@ -11,3 +11,7 @@
  &uart0 {
      u-boot,dm-pre-reloc;
  };
+
+&watchdog {
+     u-boot,dm-pre-reloc;
+};
board/alliedtelesis/x530/x530.c +9 -0
index d7d1942fe686..1b22b6307cd2 100644
@@ -7,6 +7,7 @@
  #include <command.h>
  #include <dm.h>
  #include <i2c.h>
+#include <wdt.h>
  #include <asm/gpio.h>
  #include <linux/mbus.h>
  #include <linux/io.h>
@@ -24,6 +25,10 @@ DECLARE_GLOBAL_DATA_PTR;
  #define CONFIG_NVS_LOCATION         0xf4800000
  #define CONFIG_NVS_SIZE                     (512 << 10)
 
+#ifdef CONFIG_WATCHDOG
+static struct udevice *watchdog_dev;
+#endif
+
  static struct serdes_map board_serdes_map[] = {
      {PEX0, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0},
      {DEFAULT_SERDES, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0},
@@ -75,6 +80,10 @@ struct mv_ddr_topology_map *mv_ddr_topology_map_get(void)
 
  int board_early_init_f(void)
  {
+#ifdef CONFIG_WATCHDOG
+     watchdog_dev = NULL;
+#endif
+
      /* Configure MPP */
      writel(0x00001111, MVEBU_MPP_BASE + 0x00);
      writel(0x00000000, MVEBU_MPP_BASE + 0x04);
@@ -88,6 +97,17 @@ int board_early_init_f(void)
      return 0;
  }
 
Quoted 11 lines

board/alliedtelesis/x530/x530.c int board_early_init_f(void) · line 107

Quoted 8 lines
board/alliedtelesis/x530/x530.c +8 -0
+void spl_board_init(void)
+{
+#ifdef CONFIG_WATCHDOG
+     int ret;
+
+     ret = uclass_get_device(UCLASS_WDT, 0, &watchdog_dev);
+     if (!ret)
+             wdt_start(watchdog_dev, 25000000ULL * 120, 0);

This is CONFIG_SYS_TCLK? Would it make sense to use this macro instead here?

Quoted 2 lines

Yes it would. I'll send a v2 with this change.

Spoke too soon. It's not SYS_TCLK but numerically it happens to be SYS_TCLK / 10. I'd like to keep this as-is (I'll still send v2 with the updated commit message).

Quoted 2 lines

Ideally I'd specify the value in ms and have orion_wdt deal with the details of SYS_TCLK.

I think this is actually what's needed. Right now orion_wdt justs casts timeout_ms to u32 and uses it directly. It should figure out how many timer ticks are needed (which will be a function of CONFIG_SYS_TCLK) and figure out the value appropriately.

Quoted 60 lines
Quoted 60 lines
Quoted 12 lines
board/alliedtelesis/x530/x530.c +4 -0
+#endif
+}
+
  int board_init(void)
  {
      /* address of boot parameters */
@@ -100,9 +120,37 @@ int board_init(void)
      /* DEV_READYn is not needed for NVS, ignore it when accessing CS1 */
      writel(0x00004001, MVEBU_DEV_BUS_BASE + 0xc8);
 
+     spl_board_init();

board/alliedtelesis/x530/x530.c int board_init(void) · line 133

Quoted 10 lines
board/alliedtelesis/x530/x530.c +7 -0
+
      return 0;
  }
 
+void arch_preboot_os(void)
+{
+#ifdef CONFIG_WATCHDOG
+     wdt_stop(watchdog_dev);
+#endif
+}

So you are not using the WDT in the OS (Linux)?

Quoted 9 lines
board/alliedtelesis/x530/x530.c +9 -0
+
+#ifdef CONFIG_WATCHDOG
+void watchdog_reset(void)
+{
+     static ulong next_reset = 0;
+     ulong now;
+
+     if (!watchdog_dev)
+             return;

board/alliedtelesis/x530/x530.c int board_init(void) · line 152

Quoted 10 lines
board/alliedtelesis/x530/x530.c +10 -0
+
+     now = timer_get_us();
+
+     /* Do not reset the watchdog too often */
+     if (now > next_reset) {
+             wdt_reset(watchdog_dev);
+             next_reset = now + 1000;
+     }
+}
+#endif

When I recently implemented the watchdog support the MT7688, I wondered why there is so much code necessary, that each board and platform needs to copy to get this real watchdog working. We should definitely rework this at some time, so make this more generic with less board specific code that could be shared.

You don't need to change this here. I just wanted to express my thoughts, as I'm stumbling over this code again.

Other than this (and your commit text change):

Thanks,
Stefan

#8 lore raw

PATCH 2/2 arm: mvebu: x530: Enable watchdog in SPL and U-Boot

In reply to Stefan Roese
Quoted 96 lines · On Fri, 15 Feb 2019, 9:46 PM Stefan Roese <[email protected] wrote:

Hi Chris,

Quoted 5 lines · Chris Packham

Enable the hardware watchdog to guard against system lock ups when running in the SPL or U-Boot. Stop the watchdog just before booting so that the OS.

Review

Quoted 8 lines

---

  arch/arm/dts/armada-385-atl-x530-u-boot.dtsi |  4 ++
  board/alliedtelesis/x530/x530.c              | 48 ++++++++++++++++++++
  configs/x530_defconfig                       |  5 ++
  3 files changed, 57 insertions(+)
(quoted diff) +0 -0

b/arch/arm/dts/armada-385-atl-x530-u-boot.dtsi

Review

Quoted 12 lines

index 7074a73537fa..79b694cb84bc 100644

arch/arm/dts/armada-385-atl-x530-u-boot.dtsi +4 -0
@@ -11,3 +11,7 @@
  &uart0 {
      u-boot,dm-pre-reloc;
  };
+
+&watchdog {
+     u-boot,dm-pre-reloc;
+};
(quoted diff) +0 -0

b/board/alliedtelesis/x530/x530.c

board/alliedtelesis/x530/x530.c struct mv_ddr_topology_map

Quoted 23 lines

index d7d1942fe686..1b22b6307cd2 100644

board/alliedtelesis/x530/x530.c +5 -0
@@ -7,6 +7,7 @@
  #include <command.h>
  #include <dm.h>
  #include <i2c.h>
+#include <wdt.h>
  #include <asm/gpio.h>
  #include <linux/mbus.h>
  #include <linux/io.h>
@@ -24,6 +25,10 @@ DECLARE_GLOBAL_DATA_PTR;
  #define CONFIG_NVS_LOCATION         0xf4800000
  #define CONFIG_NVS_SIZE                     (512 << 10)
 
+#ifdef CONFIG_WATCHDOG
+static struct udevice *watchdog_dev;
+#endif
+
  static struct serdes_map board_serdes_map[] = {
      {PEX0, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0},
      {DEFAULT_SERDES, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0},
@@ -75,6 +80,10 @@ struct mv_ddr_topology_map

*mv_ddr_topology_map_get(void)

Quoted 12 lines
board/alliedtelesis/x530/x530.c +4 -0
  int board_early_init_f(void)
  {
+#ifdef CONFIG_WATCHDOG
+     watchdog_dev = NULL;
+#endif
+
      /* Configure MPP */
      writel(0x00001111, MVEBU_MPP_BASE + 0x00);
      writel(0x00000000, MVEBU_MPP_BASE + 0x04);
@@ -88,6 +97,17 @@ int board_early_init_f(void)
      return 0;

board/alliedtelesis/x530/x530.c int board_early_init_f(void) · line 107

Quoted 10 lines
board/alliedtelesis/x530/x530.c +8 -0
  }
 
+void spl_board_init(void)
+{
+#ifdef CONFIG_WATCHDOG
+     int ret;
+
+     ret = uclass_get_device(UCLASS_WDT, 0, &watchdog_dev);
+     if (!ret)
+             wdt_start(watchdog_dev, 25000000ULL * 120, 0);

This is CONFIG_SYS_TCLK? Would it make sense to use this macro instead here?

board/alliedtelesis/x530/x530.c int board_init(void) · line 120

Quoted 8 lines
board/alliedtelesis/x530/x530.c +3 -0
+#endif
+}
+
  int board_init(void)
  {
      /* address of boot parameters */
@@ -100,9 +120,37 @@ int board_init(void)
      /* DEV_READYn is not needed for NVS, ignore it when accessing CS1

*/

Quoted 7 lines
board/alliedtelesis/x530/x530.c +2 -0
      writel(0x00004001, MVEBU_DEV_BUS_BASE + 0xc8);
 
+     spl_board_init();
+
      return 0;
  }
 
Quoted 9 lines

board/alliedtelesis/x530/x530.c int board_init(void) · line 133

Quoted 6 lines
board/alliedtelesis/x530/x530.c +6 -0
+void arch_preboot_os(void)
+{
+#ifdef CONFIG_WATCHDOG
+     wdt_stop(watchdog_dev);
+#endif
+}

So you are not using the WDT in the OS (Linux)?

In our production systems we are. But I wanted to allow a kernel built without the driver to boot and not have it reset on me (e.g. if I'm using a debugger).

Quoted 26 lines
Quoted 9 lines
board/alliedtelesis/x530/x530.c +9 -0
+
+#ifdef CONFIG_WATCHDOG
+void watchdog_reset(void)
+{
+     static ulong next_reset = 0;
+     ulong now;
+
+     if (!watchdog_dev)
+             return;

board/alliedtelesis/x530/x530.c int board_init(void) · line 152

Quoted 10 lines
board/alliedtelesis/x530/x530.c +10 -0
+
+     now = timer_get_us();
+
+     /* Do not reset the watchdog too often */
+     if (now > next_reset) {
+             wdt_reset(watchdog_dev);
+             next_reset = now + 1000;
+     }
+}
+#endif

When I recently implemented the watchdog support the MT7688, I wondered why there is so much code necessary, that each board and platform needs to copy to get this real watchdog working. We should definitely rework this at some time, so make this more generic with less board specific code that could be shared.

Quoted 3 lines

You don't need to change this here. I just wanted to express my thoughts, as I'm stumbling over this code again.

Yes it's no coincidence that this looks a lot like the code from one of the turris boards. I was kind of surprised i needed to get the device and start it but it kind of makes sense as I've decided that my board needs to do it in the spl where as others might want to use it only to ensure that their os boots succesfully.

Implementing watchdog_reset was a surprise but again generic code would need to iterate over all instantiated UCLASS_WDT devices.

May be there's some middle ground with some mvebu specific code that can't be completely generic but can avoid the repetition.

Quoted 7 lines

Other than this (and your commit text change):

Thanks,
Stefan