MCUboot and watchdog behavior on the nrf5340, ncs v3.1.1

Hi,

I'm looking at the watchdog behavior in mcuboot during DFU. Here are the watchdog-related configs I've set:

CONFIG_BOOT_WATCHDOG_FEED=y
CONFIG_WATCHDOG=y

and here are a few things I've noticed:

- Even though the watchdog is fed by the macro `FEED_WDT_INST(id)` in mcuboot_config.h, the watchdog doesn't seem to be started in the first place. This can be checked by calling `nrf_wdt_started_check()` in `mcuboot/boot/zephyr/main.c`, which returns false. This means that the feeding of the watchdog doesn't really do anything.

- The reload value in the CRV registers appears to always be set to 0xFFFFFFFF when mcuboot runs and there doesn't seem to be any way to set it to another value.

Could you have a look at the mcuboot code and check if these are expected behaviors?

Thank you (:

Parents Reply Children
  • Thanks for the quick reply Vidar.

    I've just checked the application and it indeed does call `wdt_install_timeout()` as well as `wdt_setup()` via Zephyr's task watchdog API.


    I read out the value of the CRV register and it was indeed updated. I also called `nrf_wdt_started_check()` in the app's main.c to check if the watchdog has actually been started, and the function call did return true.

    However, when I called `nrf_wdt_started_check()` in `mcuboot/boot/zephyr/main.c`, it returned false. I also got 0xFFFFFFFF when trying to read out the value of the CRV register in mcuboot's main.c.

    Maybe I'm just not using the watchdog API correctly? I'm building the firmware using sysbuild, just FYI.

  • The WDT will be active during bootloader execution only if the application has previously run wdt_setup() and the device was reset by a soft reset, not by a pin reset or another reset source that resets the WDT.

  • <if the application has previously run wdt_setup() and the device was reset by a soft reset>

    I believe that's the case for my application and my board, yes.

  • While reading the WDT state from the bootloader, please also check the RESETREAS to confirm the reset source (Note: this register is retained across all resets but POR/BOR).

  • So I've injected some code into mcuboot's main.c to read out RESETREAS. Throughout DFU, there were 3 reboots in total (not sure why).

    - 1st reboot, reset reason: watchdog and software

    - 2nd reboot, reset reason: software

    - 3rd reboot, (after which the app starts to run): reset reason: power-on reset

    16:14:08.303: dfu_target_mcuboot: MCUBoot image-0 upgrade scheduled. Reset device to apply
    16:14:08.308: dfu_target_mcuboot: MCUBoot image-1 upgrade scheduled. Reset device to apply
    16:14:09.215: Serial error: [Errno 5] Input/output error
    16:14:10.334: Reopened serial port
    16:14:10.645: *** Delaying boot by 2000ms... ***
    16:14:11.974: *** Booting mcuboot v2.1.0-dev-2b69d93e75bc ***
    16:14:11.988: *** Using nRF Connect SDK v3.1.0-6c6e5b32496e ***
    16:14:11.992: *** Using Zephyr OS v4.1.99-1612683d4010 ***
    16:14:11.997: W: Reset reason: watchdog | software, raw: 0xa
    16:14:12.014: W: watchdog at 0x50018000, CRV: 0xffffffff or 131071999 ms, TASKS_STOP: 0x0, TASKS_START: 0x0, RREN: 0x1, TSEN: 0x0, CONFIG: 0x1, EVENTS_STOPPED: 0x0, started: 0
    16:14:12.023: I: Starting bootloader
    16:14:12.028: D: context_boot_go
    16:14:12.033: I: Line 476, Image index: 0, Swap type: test
    16:14:12.037: D: boot_validate_slot: slot 1, expected_swap_type 2
    16:14:12.042: D: bootutil_img_validate: flash area 0xffa4
    16:14:12.047: D: bootutil_img_hash
    16:14:12.681: D: bootutil_tlv_iter_begin: type 65535, prot == 0
    16:14:12.690: D: bootutil_img_validate: TLV off 362368, end 362515
    16:14:12.694: D: bootutil_tlv_iter_next: searching for 65535 (65535 is any) starting at 362368 ending at 362515
    16:14:12.699: D: bootutil_tlv_iter_next: TLV 16 found at 362372 (size 32)
    16:14:12.704: D: bootutil_img_validate: EXPECTED_HASH_TLV == 16
    16:14:12.709: D: bootutil_tlv_iter_next: searching for 65535 (65535 is any) starting at 362404 ending at 362515
    16:14:12.713: D: bootutil_tlv_iter_next: TLV 1 found at 362408 (size 32)
    16:14:12.718: D: bootutil_img_validate: EXPECTED_KEY_TLV == 1
    16:14:12.723: D: bootutil_find_key
    16:14:12.727: D: bootutil_tlv_iter_next: searching for 65535 (65535 is any) starting at 362440 ending at 362515
    16:14:12.732: D: bootutil_tlv_iter_next: TLV 34 found at 362444 (size 71)
    16:14:12.737: D: bootutil_img_validate: EXPECTED_SIG_TLV == 34
    16:14:13.154: D: bootutil_tlv_iter_next: searching for 65535 (65535 is any) starting at 362515 ending at 362515
    16:14:13.159: D: bootutil_tlv_iter_next: TLV 65535 not found
    16:14:13.163: I: Line 476, Image index: 1, Swap type: test
    16:14:13.168: D: boot_validate_slot: slot 1, expected_swap_type 2
    16:14:13.173: D: bootutil_img_validate: flash area 0xffb4
    16:14:13.178: D: bootutil_img_hash
    16:14:13.183: D: bootutil_tlv_iter_begin: type 65535, prot == 0
    16:14:13.187: D: bootutil_img_validate: TLV off 36316, end 36461
    16:14:13.192: D: bootutil_tlv_iter_next: searching for 65535 (65535 is any) starting at 36316 ending at 36461
    16:14:13.197: D: bootutil_tlv_iter_next: TLV 16 found at 36320 (size 32)
    16:14:13.202: D: bootutil_img_validate: EXPECTED_HASH_TLV == 16
    16:14:13.206: D: bootutil_tlv_iter_next: searching for 65535 (65535 is any) starting at 36352 ending at 36461
    16:14:13.211: D: bootutil_tlv_iter_next: TLV 1 found at 36356 (size 32)
    16:14:13.216: D: bootutil_img_validate: EXPECTED_KEY_TLV == 1
    16:14:13.220: D: bootutil_find_key
    16:14:13.225: D: bootutil_tlv_iter_next: searching for 65535 (65535 is any) starting at 36388 ending at 36461
    16:14:13.230: D: bootutil_tlv_iter_next: TLV 34 found at 36392 (size 69)
    16:14:13.234: D: bootutil_img_validate: EXPECTED_SIG_TLV == 34
    16:14:21.378: D: bootutil_tlv_iter_next: searching for 65535 (65535 is any) starting at 36461 ending at 36461
    16:14:21.383: D: bootutil_tlv_iter_next: TLV 65535 not found
    16:14:21.388: D: boot_verify_slot_dependencies
    16:14:21.393: D: bootutil_tlv_iter_begin: type 64, prot == 1
    16:14:21.398: D: bootutil_tlv_iter_next: searching for 64 (65535 is any) starting at 362368 ending at 362515
    16:14:21.403: D: bootutil_tlv_iter_next: protected TLV 64 not found
    16:14:21.408: D: boot_verify_slot_dependencies
    16:14:21.414: D: bootutil_tlv_iter_begin: type 64, prot == 1
    16:14:21.419: D: bootutil_tlv_iter_next: searching for 64 (65535 is any) starting at 36316 ending at 36461
    16:14:21.425: D: bootutil_tlv_iter_next: protected TLV 64 not found
    16:14:21.431: I: Image 0 upgrade secondary slot -> primary slot
    16:14:21.437: I: Erasing the primary slot
    ///////////// D: [Lots of boot_erase_region s]
    16:14:22.511: I: Image 0 copying the secondary slot to the primary slot: 0x58814 bytes
    16:14:25.594: D: boot_write_magic: fa_id=6 off=0xc5ff0 (0xd9ff0)
    16:14:25.602: D: erasing secondary header
    16:14:25.607: D: boot_scramble_region: 0xffa4 0 4096 0
    16:14:25.612: D: boot_erase_region: flash_area 0xffa4, offset 0, size 4096, backwards == 0
    16:14:25.616: D: boot_erase_region: device with erase
    16:14:25.621: D: erasing secondary trailer
    16:14:25.626: D: boot_scramble_region: 0xffa4 806912 4096 0
    16:14:25.631: D: boot_erase_region: flash_area 0xffa4, offset 806912, size 4096, backwards == 0
    16:14:25.636: D: boot_erase_region: device with erase
    16:14:25.640: I: Image 1 upgrade secondary slot -> primary slot
    16:14:25.645: I: Erasing the primary slot
    ////////////: D: [A few boot_erase_region s]
    16:14:25.766: I: Image 1 copying the secondary slot to the primary slot: 0x8e70 bytes
    16:14:25.771: D: boot_write_magic: fa_id=1 off=0x3fff0 (0x3fff0)
    16:14:25.776: I: Turned on network core
    16:14:28.700: I: Turned off network core
    16:14:28.711: D: erasing secondary header
    16:14:28.716: D: boot_scramble_region: 0xffb4 0 4096 0
    16:14:28.721: D: boot_erase_region: flash_area 0xffb4, offset 0, size 4096, backwards == 0
    16:14:28.726: D: boot_erase_region: device with erase
    16:14:28.730: D: erasing secondary trailer
    16:14:28.735: D: boot_scramble_region: 0xffb4 258048 4096 0
    16:14:28.740: D: boot_erase_region: flash_area 0xffb4, offset 258048, size 4096, backwards == 0
    16:14:28.744: D: boot_erase_region: device with erase
    16:14:28.763: D: boot_validate_slot: slot 0, expected_swap_type 0
    16:14:28.770: D: bootutil_img_validate: flash area 0xfeb4
    16:14:28.774: D: bootutil_img_hash
    16:14:29.362: D: bootutil_tlv_iter_begin: type 65535, prot == 0
    16:14:29.374: D: bootutil_img_validate: TLV off 362368, end 362515
    16:14:29.382: D: bootutil_tlv_iter_next: searching for 65535 (65535 is any) starting at 362368 ending at 362515
    16:14:29.388: D: bootutil_tlv_iter_next: TLV 16 found at 362372 (size 32)
    16:14:29.393: D: bootutil_img_validate: EXPECTED_HASH_TLV == 16
    16:14:29.397: D: bootutil_tlv_iter_next: searching for 65535 (65535 is any) starting at 362404 ending at 362515
    16:14:29.404: D: bootutil_tlv_iter_next: TLV 1 found at 362408 (size 32)
    16:14:29.409: D: bootutil_img_validate: EXPECTED_KEY_TLV == 1
    16:14:29.413: D: bootutil_find_key
    16:14:29.419: D: bootutil_tlv_iter_next: searching for 65535 (65535 is any) starting at 362440 ending at 362515
    16:14:29.424: D: bootutil_tlv_iter_next: TLV 34 found at 362444 (size 71)
    16:14:29.429: D: bootutil_img_validate: EXPECTED_SIG_TLV == 34
    16:14:29.755: D: bootutil_tlv_iter_next: searching for 65535 (65535 is any) starting at 362515 ending at 362515
    16:14:29.770: D: bootutil_tlv_iter_next: TLV 65535 not found
    16:14:29.775: D: boot_validate_slot: slot 0, expected_swap_type 0
    16:14:29.780: D: Left boot_go with success == 1
    16:14:29.785: I: Bootloader chainload address offset: 0x14000
    16:14:29.795: I: Image version: v0.0.0
    16:14:29.805: I: Jumping to the first image slot
    16:14:29.809: W: watchdog at 0x50018000, CRV: 0xffffffff or 131071999 ms, TASKS_STOP: 0x0, TASKS_START: 0x0, RREN: 0x1, TSEN: 0x0, CONFIG: 0x41, EVENTS_STOPPED: 0x1, started: 0
    16:14:31.750: Serial error: [Errno 5] Input/output error
    16:14:38.798: Reopened serial port
    16:14:39.104: *** Delaying boot by 2000ms... ***
    16:14:40.468: *** Booting mcuboot v2.1.0-dev-2b69d93e75bc ***
    16:14:40.475: *** Using nRF Connect SDK v3.1.0-6c6e5b32496e ***
    16:14:40.481: *** Using Zephyr OS v4.1.99-1612683d4010 ***
    16:14:40.486: W: Reset reason: software, raw: 0x8
    16:14:40.491: W: watchdog at 0x50018000, CRV: 0xffffffff or 131071999 ms, TASKS_STOP: 0x0, TASKS_START: 0x0, RREN: 0x1, TSEN: 0x0, CONFIG: 0x1, EVENTS_STOPPED: 0x0, started: 0
    16:14:40.500: I: Starting bootloader
    16:14:40.505: D: context_boot_go
    16:14:40.510: I: Line 490, Image index: 0, Swap type: none
    16:14:40.515: I: Line 490, Image index: 1, Swap type: none
    16:14:40.530: D: boot_validate_slot: slot 0, expected_swap_type 0
    16:14:40.534: D: bootutil_img_validate: flash area 0xfeb4
    16:14:40.539: D: bootutil_img_hash
    16:14:41.128: D: bootutil_tlv_iter_begin: type 65535, prot == 0
    16:14:41.142: D: bootutil_img_validate: TLV off 362368, end 362515
    16:14:41.146: D: bootutil_tlv_iter_next: searching for 65535 (65535 is any) starting at 362368 ending at 362515
    16:14:41.151: D: bootutil_tlv_iter_next: TLV 16 found at 362372 (size 32)
    16:14:41.156: D: bootutil_img_validate: EXPECTED_HASH_TLV == 16
    16:14:41.160: D: bootutil_tlv_iter_next: searching for 65535 (65535 is any) starting at 362404 ending at 362515
    16:14:41.165: D: bootutil_tlv_iter_next: TLV 1 found at 362408 (size 32)
    16:14:41.170: D: bootutil_img_validate: EXPECTED_KEY_TLV == 1
    16:14:41.176: D: bootutil_find_key
    16:14:41.183: D: bootutil_tlv_iter_next: searching for 65535 (65535 is any) starting at 362440 ending at 362515
    16:14:41.188: D: bootutil_tlv_iter_next: TLV 34 found at 362444 (size 71)
    16:14:41.193: D: bootutil_img_validate: EXPECTED_SIG_TLV == 34
    16:14:41.513: D: bootutil_tlv_iter_next: searching for 65535 (65535 is any) starting at 362515 ending at 362515
    16:14:41.529: D: bootutil_tlv_iter_next: TLV 65535 not found
    16:14:41.542: D: boot_validate_slot: slot 0, expected_swap_type 0
    16:14:41.549: D: Left boot_go with success == 1
    16:14:41.553: I: Bootloader chainload address offset: 0x14000
    16:14:41.563: I: Image version: v0.0.0
    16:14:41.572: I: Jumping to the first image slot
    16:14:41.577: W: watchdog at 0x50018000, CRV: 0xffffffff or 131071999 ms, TASKS_STOP: 0x0, TASKS_START: 0x0, RREN: 0x1, TSEN: 0x0, CONFIG: 0x41, EVENTS_STOPPED: 0x1, started: 0
    16:14:43.506: Serial error: [Errno 5] Input/output error
    16:14:50.047: Reopened serial port
    16:14:50.278: *** Booting nRF Connect SDK v3.1.0-6c6e5b32496e ***
    16:14:50.283: *** Using Zephyr OS v4.1.99-1612683d4010 ***
    16:14:50.288: NRFX_WDT: Function: nrfx_wdt_channel_alloc, error code: NRFX_SUCCESS.
    16:14:50.298: task_wdt: hw_wdt timeout installed, wdt_config.window.max: 210
    16:14:50.511: main: App Version: 0.0.7-1
    16:14:50.523: main: Reset reason: power-on reset
    16:14:50.537: NRFX_WDT: Reconfigured watchdog at 0x50018000 with reload value of 210 ms, behavior 65, int prio 0
    16:14:50.542: NRFX_WDT: Enabled.
    16:16:21.810: main: watchdog at 0x50018000, CRV: 0x1ae1 or 209 ms, TASKS_STOP: 0x0, TASKS_START: 0x0, RREN: 0x1, started: 1
    

Related