siemens / meta-iot2050

SIMATIC IOT2050 Isar/Debian Board Support Package
MIT License
129 stars 76 forks source link

iot2050:watchdog: Add support for WDIOF_CARDRESET #474

Closed huaqianli closed 10 months ago

huaqianli commented 11 months ago

This patch adds the WDIOF_CARDRESET support for the TI AM65x platform watchdog, to know if the board reboot is due to a watchdog reset.

This is done via reserved memory(RAM), which indicates if specific info saved in k3-rti-wdt, triggering the watchdog reset in last boot.

jan-kiszka commented 11 months ago

Just to note this clearly: This will also need the k3-wdt firmware patch - or an update of upstream once the needed changes are accepted there.

huaqianli commented 10 months ago

Yes, I didn't add it because I don't know which commit id will be used. Once the k3-wdt firmware is merged, I will update it.

jan-kiszka commented 10 months ago

Quick question: How do I obtain the status from the kernel driver easiest?

huaqianli commented 10 months ago

Quick question: How do I obtain the status from the kernel driver easiest?

From my perspective, waiting for an email from community is the easiest way. You and @BaochengSu have more experience on upstreaming, maybe you know better.

jan-kiszka commented 10 months ago

Misunderstanding: I meant how to read back the reset status on the device if this patch here is applied?

huaqianli commented 10 months ago

Misunderstanding: I meant how to read back the reset status on the device if this patch here is applied?

Here is an example:

void foo(void)
{
    if ((fd = open("/dev/watchdog", O_RDWR)) < 0) {
        printf("Failed to open watchdog\n");
        return;
    }

    if (ioctl(fd, WDIOC_GETBOOTSTATUS, &status) < 0) {
        printf("Failed to get boot status!");
    }

    if (WDIOF_CARDRESET & status) {
        // WDIOF_CARDRESET is detected, do what you want to do
    }
}
jan-kiszka commented 10 months ago

Ah, found it myself: cat /sys/class/watchdog/watchdog0/bootstatus