fix(H4): bound boot NTP + core-0 watchdog with core-1 heartbeat + non-blocking latch - #14
Open
d33mobile wants to merge 2 commits into
Open
fix(H4): bound boot NTP + core-0 watchdog with core-1 heartbeat + non-blocking latch#14d33mobile wants to merge 2 commits into
d33mobile wants to merge 2 commits into
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
d33mobile
force-pushed
the
fix/h4-boot-watchdog
branch
from
August 4, 2026 17:39
a1568e8 to
123346f
Compare
…ompiles Rebasing onto current master pulled in a latent build break: cmd_status declares `keys` inside the `if (commands_is_admin())` block but scrubs it via `secure_wipe(keys, sizeof(keys))` at function scope, so `keys` is undeclared there. asan_commands links serial/commands.c (not commands_system.c) so it never compiled this TU, but `make -C test coverage` compiles the whole first-party surface and fails here (`keys undeclared`) -- as does the real firmware build. Restore `keys` to function scope, matching the scrub's intent of always clearing the key DB from BSS (incl. the non-admin path where it stays zero-initialised). Same fix as PR hakierspejs#15 (M1). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ISSUES.md H4 (High)
This PR implements all three remediations. It touches core / hardware / network wiring that cannot be exercised on the host (no RP2040 here) — see the verify-on-hardware note at the end.
The three sub-fixes
1. Bound the boot NTP sync, then degrade instead of hanging (
main.c,network/ntp.c)boot_network()no longer loops forever onntp_sync(). It triesBOOT_NTP_MAX_ATTEMPTS(3) times, then boots anyway into a degraded "time-not-set" state:console_init()runs and the service loop starts.ntp_task()previously early-returned when!synced, so the first sync was only attempted by the boot loop. It now retries the first sync in the degraded state on a spacedNTP_DEGRADED_RETRY_S(30 s) cadence, so the device recovers once NTP is reachable again — without a blocking sync every tick starving the console.totp_verify()returns false whenclock_get_unix_time()reports "unset". No behavioural change was needed there; it is consistent with M1's intent and is called out in the code comment.2. Feed the watchdog from core 0, gated on a core-1 heartbeat (
core1.c,core1.h,main.c)volatile uint32_t core1_heartbeat, bumped by core 1 on every keypad-loop iteration and while it waits on a door verdict. Core 1 no longer callswatchdog_update()directly.watchdog_feed_core0()(core-0 only) pets the watchdog only if the heartbeat advanced since the last call. It is called from the service loop and from thentp_sync()poll loop. Result: a wedge on either core stops the watchdog being fed and resets the board.watchdog_enable()is moved from the very start of boot to just before the service loop. The boot path has legitimately long single-core blocking (recovery beeps, WiFi association, the bounded NTP sync) that no single core can pet within the RP2040's ~8 s watchdog ceiling; boot is already bounded on every path, so the watchdog now guards steady state where the heartbeat scheme applies.ntp_sync()'s poll loop (a core-0 wait of up toNTP_TIMEOUT_S= 15 s, over the 8 s window) now callswatchdog_feed_core0(), so a reachable-but-slow server no longer trips a reset while a genuinely wedged core still does.network/wifi.c: the blockingcyw43_arch_wifi_connect_timeout_msis reduced 15 s → 6 s. With core 0 now feeding the watchdog, a 15 s blocking connect on thewifi_task()reconnect path would trip a reset mid-attempt and reboot-loop while the AP is slow/unreachable. A failed attempt is retried on the nextwifi_task()tick.3. Non-blocking
latch_open()(hardware/latch.c)add_alarm_in_ms(LATCH_OPEN_DELAY, ...), and returns immediately instead ofsleep_ms(5000). This removes the thin watchdog margin on the door-open path (previously the 5.2 s grant path left only ~2.8 s under the 8 s limit).core1.cdrops thebuzzer_on()/buzzer_off()that bracketed the old blocking call (thebuzzer_play_door_open()cue still sounds).cmd_test(commands_system.c) benefits too — it no longer blocks the console for 5 s.Host tests (CI gates) — all green
make -C test asan→ 0make -C test valgrind→ 0make -C test coverage→ 0./ci --action=check(clang-format + shellcheck) → 0hardware/latch.cis compiled (compile-only) by the coverage gate, so a terse host stub for the timer-alarm API (alarm_id_t,add_alarm_in_ms,cancel_alarm) was added totest/stub/pico/time.h. The libFuzzerfuzz_*.charnesses are out of scope and untouched.None of this runs on the host. Please confirm on a real RP2040:
flash_safe_execute(which locks out core 1) completes well under 8 s so it does not self-reset.LATCH_OPEN_DELAYand de-energises exactly once; two grants within the window keep it open for a fresh full delay.ntp_task()recovers and the door works.