Last Reboot detection on PhyCORE-AM335x-PD13.1.2 Linux 3.2

809 views Asked by At

In an embedded system using BSP linux 3.2 on the sitara AM3359, at application startup, I want to detect what caused the last reboot and save this status in one of two counters: a Watchdog reset and a Power-on reset.

  1. Usually in a MCU, I test the watchdog by reserving spot in the ram and write special key on the first boot and reset using the watchdog. If not there when reboot it's power on if it's there it's a watchdog reset.

    My first question is, how to save the key variables on RAM that would survive a reboot or a watchdog reset ?

    It's seem something clean the ram at boot...can I disable that?

  2. There usually a register with that information. On AM335x there is the PRM_RSTST register with the bit (WDT1_RST), I am using ioctl() with WDIOC_GETBOOTSTATUS to Check if the last boot is caused by watchdog or it's power-on-reset. This call doesn't return me something I can understand. Can somebody explain it ? How can I get this register...

    Power ON:
    test1: 1076092848
    test2: 1076113328
    test3: 1075589040
    test4: 1076203440
    watchdog:
    test5: 1076481968
    test6: 1075732400
    test7: 1075965872
    

    code use:

    /* Check if last boot is caused by watchdog */
    if (ioctl(fd, WDIOC_GETBOOTSTATUS, &bootstatus) == 0) {
       fprintf(stdout, "Last boot is caused by : %s, bootstatus= %d\n",
          (bootstatus != 0) ? "Watchdog" : "Power-On-Reset", bootstatus);
    } else {
       fprintf(stderr, "Error: Cannot read watchdog status\n");
       exit(EXIT_FAILURE);
    }
    
  3. Is there another way to get this information (mmap, write driver, sys, etc)?

2

There are 2 answers

0
Phil On BEST ANSWER

I start by using terminal command devmem 0x44E00F08 (busybox) to see if reading the physical memory will work then I use mmap() to read the PRM_RSTST register and know if the last reset was watchdog reset.

1
tuppi-ovh On

I would propose you to use your bootloader to see processor register values (for u-boot I beleive the command is reginfo). The same way (but another command) for the memory where you stock watchdog keys. Once debugged with your bootloader you can think about passing them to the kernel.