Skip to content

vigil: hardware watchdog on the HiSilicon NVR images (S95vigil, hi3536dv100, hi3520dv200) - #3029

Open
dimerr wants to merge 5 commits into
OpenIPC:masterfrom
dimerr:vigil-watchdog
Open

dimerr wants to merge 5 commits into
OpenIPC:masterfrom
dimerr:vigil-watchdog

Conversation

@dimerr

@dimerr dimerr commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

vigil's vigild can now feed the board's hardware watchdog while its threads keep running (watchdog in /etc/vigil.yaml, on by default). On the HiSilicon NVR images there was no usable /dev/watchdog yet; this PR adds one and makes the init script safe around it.

S95vigil (general/package/vigil/files/S95vigil). vigild arms the watchdog itself and keeps /var/run/vigild.watchdog while it is armed; a stop it asked for disarms it with the magic close. A vigild that crashed or was killed leaves the dog counting on drivers that have the magic close (the HiSilicon ones), and the supervisor's waits before a restart (5, 30, 120 s) can be longer than the timeout. So while the mark is there the supervisor:

  • feeds the dog through the wait, on its own descriptor, which the next vigild takes over;
  • disarms it (open, V, close) when it gives up after a crash loop, when vigild ends without a crash, and when it is stopped. A board that reboots forever is no easier to reach, and a stop under sysupgrade must not reset the board mid-flash.

Without the mark it opens nothing, so it never arms a watchdog nobody asked for.

hi3536dv100. load_hisilicon loaded open_wdt and removed it again at once. On a vigil image (/usr/bin/vigild present) it now stays; the driver's kernel thread feeds the dog until vigild opens the device. Other images are unchanged. The driver itself is fixed in openhisilicon (OpenIPC/openhisilicon#320: the magic close was inverted, and the timeout was doubled). Master's hisilicon-opensdk pin (d115067) already includes it, so hi3536dv100 needs no package change here.

hi3520dv200. The vendor osdrv ships no watchdog module. hisilicon-opensdk builds openhisilicon's (already the fixed driver) but did not install it. On vigil images it is now installed as wdt.ko and load_hisilicon loads it when it is there. Other hi3520dv200 images are unchanged.

Tested:

  • hi3536dv100_lite and hi3520dv200_lite build. After the bump, hi3536dv100_lite's open_wdt.ko is the fixed driver (@Hi3536v100).
  • In qemu-bench's hi3536dv100 machine (no watchdog model there, so only the driver's messages):
    • vigild arms it; a clean stop logs "Watchdog is disabled!";
    • a crash logs "Unexpected close, watchdog left running!", and the supervisor feeds it through the restart wait;
    • a stop during that wait disarms it.

Needs a board: an actual reset after the timeout, on hi3536dv100 and hi3520dv200.

Until vigil main has the watchdog: vigil's watchdog support is on its integration branch now, not yet in main, which these images build. Until it reaches main, vigild never creates the mark, so S95vigil changes nothing on a running image. On hi3536dv100 the driver's kernel thread then keeps feeding open_wdt, which is now left loaded.

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

vigil: hardware watchdog support for HiSilicon NVR images

✨ Enhancement ⚙️ Configuration changes 🕐 40+ Minutes

Grey Divider

AI Description

• Adds a hardware watchdog path for vigil on hi3536dv100 and hi3520dv200 NVR images, bumping
 openhisilicon to the fixed driver.
• S95vigil feeds the watchdog across crash-restart waits while vigild's mark exists, and disarms it
 on give-up, clean exit, or stop.
• load_hisilicon keeps the watchdog driver loaded on vigil images only; other images behave as
 before.
Merge Risk 🔴 High

Blast radius 🔴 High 💥 2 capabilities

  • 2 affected capabilities span independent functional scopes: firmware upgrade, vigil NVR operation.
  • The changed supervisor, watchdog driver loading and daemon lifecycle all serve the single vigil NVR behavior: keeping vigild running or safely stopping it.
  • The driver and init script are implementation hops in that behavior, not independent capabilities.
  • Firmware upgrade is an independent end-to-end system operation: sysupgrade stops vigil before writing and explicitly refuses to proceed when an armed watchdog cannot be disarmed.
  • It is therefore a distinct functional scope from vigil recording, despite sharing the runtime watchdog boundary.
  • This parsing change affects the supervisor identity check used by the same vigil start/stop lifecycle; it does not create a separate user-facing capability or independent functional scope.
Behavioral complexity 🔴 High 🧩 Interacting branches, Concurrent ordering

  • Before: crash recovery used an ordinary sleep and service stop handled daemon and supervisor state without coordinating an armed watchdog.
  • After: restart waits feed a watchdog, stop and upgrade paths release it, and background feeding must be interrupted in the correct order.
  • The new correctness condition is that every armed-watchdog state remains fed until vigild retakes it or is successfully disarmed, while stop and flash operations cannot race that state.
Potential damage 🔴 High 🩹 Integrity

  • If an armed watchdog resets the board during flash writing, the installed firmware can be incomplete or unbootable.
  • A normal code revert cannot restore an interrupted write; recovery may require a bootloader, recovery image or physical reflash.
  • The changed stop path is intended to prevent this by failing before the write when release fails, but a missed or falsely cleared watchdog state would require platform-specific recovery and possibly manual reflashing.
Assessed commit 8866e5c
Diagram

graph TD
  D["load_hisilicon"] --> E["wdt.ko driver"] --> B[("/dev/watchdog")]
  A["vigild"] --> B
  C["S95vigil supervisor"] --> B
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. vigild disarms itself via exit handler / atexit
  • ➕ Keeps watchdog logic inside vigild, with no shell-side feeding loop
  • ➕ Simpler init script
  • ➖ Does not run on SIGKILL or OOM kill, which is the case that matters
  • ➖ A crash loop still resets the board unless the supervisor also intervenes
2. Rely on the driver kernel thread alone, with no supervisor feeding
  • ➕ No shell feeding loop; minimal S95vigil change
  • ➖ Driver thread stops feeding once vigild opens the device, so a crashed vigild leaves the dog counting through the restart waits
  • ➖ Waits of 30 to 120 s can exceed the timeout and reset the board mid-restart

Recommendation: The PR's approach is reasonable: the supervisor holds the dog across the restart wait and releases it on every non-crash exit, so a board is not left armed without an owner. The main weakness is that a SIGKILL or OOM-killed vigild cannot run its own cleanup, so the supervisor has to do the disarm. Keeping the disarm in the supervisor, gated on a mark file, is the only option that covers those cases.

Files changed (4) +78 / -3

Enhancement (1) +57 / -1
S95vigilFeed the watchdog across restart waits; disarm on give-up, exit, or stop +57/-1

Feed the watchdog across restart waits; disarm on give-up, exit, or stop

• Adds wdog_feed, wdog_wait, and wdog_release. While vigild's mark file exists, the supervisor feeds /dev/watchdog on fd 9 during the 5/30/120 s restart waits, and disarms it (open, V, close) when giving up, on clean exit outside sysupgrade, or on stop. Without the mark, nothing is opened, so no watchdog is armed unasked.

general/package/vigil/files/S95vigil

Other (3) +21 / -2
hisilicon-opensdk.mkBump openhisilicon to fixed driver; install wdt.ko on vigil hi3520dv200 +12/-1

Bump openhisilicon to fixed driver; install wdt.ko on vigil hi3520dv200

• Pins HISILICON_OPENSDK_VERSION to d122dae, which fixes the inverted magic close and doubled timeout in open_wdt. On vigil images, installs open_wdt.ko as wdt.ko into the kernel module directory; other images are unchanged.

general/package/hisilicon-opensdk/hisilicon-opensdk.mk

load_hisiliconLoad wdt.ko on vigil hi3520dv200 images +5/-0

Load wdt.ko on vigil hi3520dv200 images

• insert_ko loads wdt.ko when present, which only vigil images ship. remove_ko unloads wdt. Other images do not have the file and see no change.

general/package/hisilicon-osdrv-hi3520dv200/files/script/load_hisilicon

load_hisiliconKeep open_wdt loaded on vigil hi3536dv100 images +4/-1

Keep open_wdt loaded on vigil hi3536dv100 images

• Skips remove_wdt when /usr/bin/vigild exists, so the driver's kernel thread keeps feeding the dog until vigild opens it. Non-vigil images still load and remove the module as before.

general/package/hisilicon-osdrv-hi3536dv100/files/script/load_hisilicon

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (1) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Untested watchdog reaches NVR images 📘 Rule violation ☼ Reliability
Description
The hi3520dv200 watchdog install is gated on BR2_PACKAGE_VIGIL, so on every vigil image wdt.ko
is installed and load_hisilicon loads it, arming a hardware watchdog that can reset the board. The
PR description says the reset itself is only verified on a board ("Needs a board: an actual reset
after the timeout, on hi3536dv100 and hi3520dv200") and that hi3520dv200 was only built, not run.
Because the change alters camera behaviour, the stated lack of hardware testing matches the failure
criterion; the gap also reaches the supervisor's feed/disarm logic in S95vigil, which is not
exercised on this board either.
Code

general/package/hisilicon-opensdk/hisilicon-opensdk.mk[R783-786]

+ifeq ($(BR2_PACKAGE_VIGIL),y)
+define HISILICON_OPENSDK_HI3520DV200_WDT
+	$(INSTALL) -m 644 $(@D)/kernel/open_wdt.ko $(HISILICON_OPENSDK_KMOD_DST)/wdt.ko
+endef
Evidence
The PR description states the reset behaviour needs a board and the hi3520dv200 change is built but
not run, while the diff installs wdt.ko into every vigil image and load_hisilicon loads it.

Rule 3: Hardware evidence is present and honest
general/package/hisilicon-opensdk/hisilicon-opensdk.mk[783-786]
general/package/hisilicon-osdrv-hi3520dv200/files/script/load_hisilicon[209-212]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The PR adds a hardware watchdog to vigil images (hi3520dv200 `wdt.ko` install and load, hi3536dv100 kept-loaded `open_wdt`, and the S95vigil feed/disarm logic). Its description states the reset behaviour has not been verified on a board and that hi3520dv200 was only built, not run. The change alters camera behaviour, so the PR needs hardware evidence.
## Fix Focus Areas
- general/package/hisilicon-opensdk/hisilicon-opensdk.mk[783-787]
- general/package/hisilicon-osdrv-hi3520dv200/files/script/load_hisilicon[209-212]
- general/package/hisilicon-osdrv-hi3536dv100/files/script/load_hisilicon[99-106]
- general/package/vigil/files/S95vigil[153-187]
## Recommended Fix
Run the image on an actual hi3520dv200 and hi3536dv100 board. Capture dmesg and log output for: a clean vigild stop ("Watchdog is disabled!"), a crash ("Unexpected close, watchdog left running!"), a stop during the restart wait, and an actual reset after the timeout. Put this output in the PR description, with the affected board named. If hardware cannot be reached, say so plainly in the description and keep the watchdog gated off the shipped images until it is verified.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. An upgrade can reset during flash ✓ Resolved Bug Reliability
Description
supervise skips wdog_release when the upgrade lock exists, including when vigild exits and
leaves the watchdog armed. If vigild dies after an upgrade has created the lock but before its
delayed stop_vigil call, that call can skip the init script because neither vigild nor its
supervisor remains; an in-place flash then has no watchdog keeper.

3. A failed disarm still allows flashing ✓ Resolved Bug Reliability
Description
wdog_release logs a failed watchdog open or magic-close write, then removes vigild.watchdog and
returns success anyway. When stop calls it before sysupgrade, the init script reports a successful
stop despite an armed watchdog that can expire during the flash.


Remediation recommended

4. A feed error can reset a restarting NVR ✓ Resolved Bug Reliability
Description
wdog_wait handles any wdog_feed failure by sleeping for the entire original backoff, even if the
feed loop had already run for part of it. If a watchdog write fails after the descriptor opens,
closing it leaves the HiSilicon watchdog counting while the supervisor waits up to 120 seconds
without another feed or disarm attempt.

Grey Divider

Tip of the day
💡 Did you know, you can pick a display mode instead of tweaking every Display option by hand

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

dimerr pushed a commit to dimerr/firmware that referenced this pull request Dec 1, 2026
…iled disarm is not a stop

From the review of OpenIPC#3029:
- The supervisor broke out under sysupgrade's lock without disarming a
  watchdog the last vigild left armed, and stop_vigil skipped the stop
  when neither vigild nor the supervisor was left: the flash had a dog
  counting under it. Each break now disarms it, and stop_vigil runs the
  stop while /var/run/vigild.watchdog is there.
- wdog_release removed the mark and reported success when the disarm
  failed. It keeps the mark and fails; the stop says FAIL, and sysupgrade
  refuses the upgrade before writing anything rather than flash under it.
- A feed that failed during the restart wait fell back to sleeping the
  whole wait unfed. It now disarms the dog and sleeps only what is left.
- supervising(): a pidfile naming a killed supervisor no longer prints
  "can't open /proc/<pid>/cmdline" (the failed redirection escaped its
  2>/dev/null).

Checked in qemu-bench's hi3536dv100 with vigil nvr-dev: a crash under the
lock disarms ("upgrade: ... disarmed", HiDog "Watchdog is disabled!");
a crash, the fed wait, then a stop disarms; with vigild and the
supervisor killed and the device held elsewhere the stop fails and keeps
the mark, and once it is free a stop disarms it. The functions alone
under busybox ash with /dev/full: a failed feed disarms and sleeps the
rest.
dimerr and others added 5 commits December 1, 2026 17:10
vigild now arms /dev/watchdog (watchdog in /etc/vigil.yaml), feeds it
while its threads turn, and keeps /var/run/vigild.watchdog while it is
armed; a stop it did not ask for disarms it with the magic close. A
vigild that crashed or was killed leaves the dog counting where the
driver has the magic close (the HiSilicon ones), and the supervisor's
waits before a restart (5, 30, 120 s) can outlast its timeout.

So when the mark is there the supervisor feeds the dog through the wait,
on a descriptor of its own that the next vigild takes over; it disarms
it (open, 'V', close) when it gives up after a crash loop -- a board that
rebooted forever would be no easier to reach -- when vigild ends without
a crash, and when it is stopped: a vigild it had to kill under
sysupgrade must not leave a dog that resets the board mid-flash. Without
the mark nothing is opened: that would arm a dog nobody asked for.

Checked in qemu-bench's hi3536dv100 machine (no watchdog model: the
driver's messages): a crash leaves it running and the supervisor holds
it through the wait; a stop during that wait disarms it ("Watchdog is
disabled!"); the feeding and the release on the image's busybox ash.
vigil's vigild feeds the hardware watchdog while its threads turn, but
load_hisilicon loads open_wdt and removes it again at once, so there is
no /dev/watchdog. On a vigil image (/usr/bin/vigild there) it now stays;
its kernel thread feeds the dog until vigild opens the device. Other
images load and remove it as before.

openhisilicon's hi3536dv100 hi_wdt.c is still the vendor's: a "V"
before the close leaves the dog armed and unfed, while a plain close
hands it back to the kernel thread -- the magic close inverted, so
vigild's clean stop would reset the board and a crash would never -- and
the counter is loaded with a whole margin, which the SP805 runs twice.
The hi3520dv200 copy in the same tree has those fixed (as hi3516cv200's
and cv100's), for the same SP805 and clock gate; vigil images build it
at hi3536dv100's addresses (0x12070000, 0x12050000), with a check that
the substitution took. The fix belongs in openhisilicon, after which
this hook goes.

Built (hi3536dv100_lite, kernel 4.9.37) and loaded in qemu-bench's
hi3536dv100 machine: /dev/watchdog, vigild arms it with the magic close
supported; a clean stop says "Watchdog is disabled!", a crash
"Unexpected close, watchdog left running!". The machine has no watchdog
model, so no reset was seen; that needs a board.
vigil's vigild feeds the hardware watchdog while its threads turn, and
hi3520dv200 has none: the vendor osdrv ships no wdt module and
hisilicon-opensdk builds openhisilicon's (the fixed driver: a real magic
close, a real timeout, the kernel thread feeding only until the first
open) but does not install it. On vigil images it is installed as
wdt.ko, and load_hisilicon loads it when it is there (and removes it
with the rest); other hi3520dv200 images are unchanged.

Built (hi3520dv200_lite): wdt.ko is the fixed driver (3.0.8) and
load_hisilicon loads it. Not run: qemu-bench's hi3520dv200 machine has
no watchdog model, and no board was at hand.
…con, not a sed at build

The vigil images built hi3520dv200's fixed hi_wdt.c at hi3536dv100's
addresses with a sed over the source at patch time. The same file is
now proposed for openhisilicon itself (OpenIPC/openhisilicon#320); with
it merged, the package's pin carries the fix for every hi3536dv100 image
and this hook goes.
…iled disarm is not a stop

From the review of OpenIPC#3029:
- The supervisor broke out under sysupgrade's lock without disarming a
  watchdog the last vigild left armed, and stop_vigil skipped the stop
  when neither vigild nor the supervisor was left: the flash had a dog
  counting under it. Each break now disarms it, and stop_vigil runs the
  stop while /var/run/vigild.watchdog is there.
- wdog_release removed the mark and reported success when the disarm
  failed. It keeps the mark and fails; the stop says FAIL, and sysupgrade
  refuses the upgrade before writing anything rather than flash under it.
- A feed that failed during the restart wait fell back to sleeping the
  whole wait unfed. It now disarms the dog and sleeps only what is left.
- supervising(): a pidfile naming a killed supervisor no longer prints
  "can't open /proc/<pid>/cmdline" (the failed redirection escaped its
  2>/dev/null).

Checked in qemu-bench's hi3536dv100 with vigil nvr-dev: a crash under the
lock disarms ("upgrade: ... disarmed", HiDog "Watchdog is disabled!");
a crash, the fed wait, then a stop disarms; with vigild and the
supervisor killed and the device held elsewhere the stop fails and keeps
the mark, and once it is free a stop disarms it. The functions alone
under busybox ash with /dev/full: a failed feed disarms and sleeps the
rest.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants