I've decided to investigate the watchdog functionality of my pcDuino3 as a fail safe mechanism that if something goes wrong with a driver / or the kernel panics - at least the board will reboot automatically.
After reading few posts on the internet related to A10 / A13 watchdog I've decided to see if it works for A20 also. The kernel that I'm using (sources from 30 April) does not contain the watchdog compiled (neither within the kernel nor as a module). These were the steps:
Assuming that the kernel sources are in /usr/local/src/a20-kernel
1. edit the file /usr/local/src/a20-kernel/patch/linux-sunxi/arch/arm/configs/sun7i_defconfig by locating the section below and adding the last line CONFIG_SUNXI_WDT=y to it:
CONFIG_WATCHDOG=y CONFIG_WATCHDOG_CORE=y CONFIG_WATCHDOG_NOWAYOUT=y # # Watchdog Device Drivers # # CONFIG_SOFT_WATCHDOG is not set # CONFIG_ARM_SP805_WATCHDOG is not set # CONFIG_DW_WATCHDOG is not set # CONFIG_MPCORE_WATCHDOG is not set # CONFIG_MAX63XX_WATCHDOG is not set CONFIG_SUNXI_WDT=y
This would build the watchdog into the kernel directly (or put =m to have it built as a module, however, I haven't tried as a module).
The change is not enough, since unfortunately, in the Kconfig file from the main kernel, the SUNXI_WDT config depends either on the ARCH_SUN4I or ARCH_SUN5I, but it is not the case on pcDuino3 - the config is ignored. Thus it has to also depend on ARCH_SUN7I. I had to do make menuconfig and wonder why I still don't see the option (I thought I was modifying the wrong file in the patch folder). So to fix this, few more steps are needed:
2. copy file /usr/local/src/a20-kernel/linux-sunxi/drivers/watchdog/Kconfig to /usr/local/src/a20-kernel/patch/linux-sunxi/drivers/watchdog/Kconfig
2. edit the copy such as you add the " || ARCH_SUN7I" to the "depends on ..." line:
config SUNXI_WDT tristate "Allwinner A10/A13/A20 Watchdog" depends on ARCH_SUN4I || ARCH_SUN5I || ARCH_SUN7I help This is the driver for the hardware watchdog on the Allwinner A10/A13/A20 processors.
I also modified a bit the comments so that they reflect the A20 is also working.
Now, it is just a matter of building the kernel. To verify that everything is in, you need to:
ubuntu@ubuntu:/usr/local/src/a20-kernel/build/sun7i_defconfig-linux$ grep sunxi_wdt modules.builtin kernel/drivers/watchdog/sunxi_wdt.ko ubuntu@ubuntu:/usr/local/src/a20-kernel/build/sun7i_defconfig-linux$
After deploying the new kernel, the following will be visible into /var/log/syslog:
Aug 3 12:08:40 ubuntu kernel: [ 5.641127] sunxi_wdt: sunxi WatchDog Timer Driver v1.0 Aug 3 12:08:40 ubuntu kernel: [ 5.648690] sunxi_wdt: initialized (timeout=23s, nowayout=1)
To generate a kernel panic and verify that the watchdog works:
echo "c" > /proc/sysrq-trigger
The board will freeze and should restart in about 23 seconds.
Obs: if the freeze is due to a power supply issue (such as not providing the 2A, not using the capacitor method or not using the latest kernel that is supposed to fix the power consumption issues) then most probably the watchdog will not work to reboot the board.