Skip to content

hi3518ev300: build the crypto modules into the kernel, off the rootfs - #2397

Merged
widgetii merged 1 commit into
masterfrom
hi3518ev300-modules-into-kernel
Sep 11, 2026
Merged

widgetii merged 1 commit into
masterfrom
hi3518ev300-modules-into-kernel

Conversation

@widgetii

Copy link
Copy Markdown
Member

Problem

hi3518ev300_lite has been red since the 2026-09-10 nightly (run 34508971947):

- rootfs.squashfs: [5128KB/5120KB]
-- size exceeded by: 8KB

It is the only board of 99 that fails, and nothing in this repository grew to
do it. Diffing every downloaded tarball between the last green nightly
(34383640663, 09-09) and the red one, exactly two inputs changed size:

input 09-09 09-10 delta
majestic.hi3516ev200.lite.master.tar.bz2 707,587 722,505 +14,918 B
majestic-webui-dist.tar.gz 294,421 299,309 +4,888 B

Both are unpinned moving refs — majestic.mk fetches …master.tar.bz2,
majestic-webui.mk pins VERSION = dist — so an upstream publish lands in the
next nightly with no pull request here to point at. The growth is uniform
across boards, confirmed by the headroom annotations: hi3518ev300_lite went
12KB free → 8KB over, and hi3519v101_lite went 28KB free → 8KB free. Both
exactly −20KB. The Sigmastar uImage headroom barely moved (25→24KB), so the
kernel did not change.

CI printed the warning a day early, exactly as CHECK_SIZE's 32KB band is
meant to:

::warning::hi3518ev300_lite: rootfs.squashfs has 12KB left of 5120KB

Why this board. It carries a USB-WiFi stack its hi3516ev300_lite sibling
does not — wpa_supplicant, wireless-tools, json-c, and
linux-firmware-openipc with MEDIATEK_MT7601U and RTL_8188EU.

Why not simply rebalance the partitions. The kernel partition has 184KB
idle (1864KB of 2048KB), but it cannot be lent to the rootfs. The 8MB map is
compiled into U-Boot and saved in every deployed camera's environment:

mtdparts=hi_sfc:256k(boot),64k(env),2048k(kernel),5120k(rootfs),-(rootfs_data)

rootfs starts at 0x250000 and is immediately followed by rootfs_data, the
owner's overlay. A squashfs over 5120k would run past the end of the rootfs MTD
and into it on every camera still on the old map. Code can move the other way,
though, and that is what this does.

Hardware tested on

Not run on a camera. There is no hi3518ev300 within reach — the change is
verified by local build only, and I have not ticked anything I did not observe.
Someone with the board should confirm it boots, streams, and still brings up an
MT7601U or RTL8188EU dongle before this is trusted in the field.

The evidence that does apply is below: two full local builds of
hi3518ev300_lite from this tree, the second differing only by this diff. The
baseline reproduces CI's numbers exactly (1864KB / 5128KB), which is what makes
the after-figures meaningful.

Evidence

Before:

- uImage: [1864KB/2048KB]
- rootfs.squashfs: [5128KB/5120KB]
-- size exceeded by: 8KB
make[1]: *** [Makefile:178: repack] Error 1

After:

- uImage: [1876KB/2048KB]
- rootfs.squashfs: [5104KB/5120KB]
-- headroom warning: rootfs.squashfs has 16KB left of 5120KB

The repack now completes and produces openipc.hi3518ev300-nor-lite.tgz
(7,129,032 B).

What moved. 11 .ko totalling 89,572 bytes leave /lib/modules; the
kernel grows 12KB. The trade works because most of a small .ko is ELF symbol
table, relocations and .modinfo, all of which disappear once the code is
linked in:

gcm.ko 16604   ccm.ko 12544   drbg.ko 11840   gf128mul.ko 9844
jitterentropy_rng.ko 9740   ctr.ko 6940   hmac.ko 5456   seqiv.ko 4640
echainiv.ko 4172   ghash-generic.ko 4020   crc32_generic.ko 3772

After the rebuild: 0 crypto .ko under /lib/modules, 32 crypto entries in
modules.builtin.

Nothing is dropped. mt7601u.ko, r8188eu.ko, mac80211.ko and
wireguard.ko all still ship, so both USB WiFi dongles behave as before. The
load path is unaffected: busybox modprobe reads modules.builtin
(modutils/modprobe.c:631) and answers module ... is builtin rather than
not found in modules.dep, and general/overlay/etc/wireless/usb does
modprobe mt7601u; exit 0, ignoring the exit status.

Shared config. hi3518ev300.generic.config is used by
hi3518ev300_lite and hi3518ev300_ultimate. The ultimate's kernel cap is
4096KB, so it absorbs the 12KB without coming close.

Selector and self-tests, run from the repo root:

$ git diff --name-only origin/master | python3 .github/scripts/ci-matrix.py --stdin
  hi3518ev300_lite
  hi3518ev300_ultimate
needs-build=true
reason=narrowed to the affected boards

$ python3 .github/scripts/ci-matrix.py --self-test
ci-matrix: self-test ok (99 boards, 135 packages, 56 cases)

$ python3 general/scripts/tests/test_kconfig_graph.py
Ran 2 tests — OK

$ STRICT=1 bash .github/scripts/test_shell_parse.sh
checked 141 shell script(s) — all parsed clean under busybox ash

$ STRICT=1 bash .github/scripts/test_strip_shell_comments.sh
All strip-shell-comments checks passed.

Known limitations

  • 16KB of margin is thin. Majestic has been growing roughly 20KB a bump, so
    this buys one bump, not a year. The durable fix is upstream size discipline
    or a pin; this stops the bleeding without dropping a feature.
  • The kernel and rootfs are a matched pair for this board from here on. A
    camera updated with sysupgrade -r alone would have the modules gone from
    the rootfs and not yet built into its kernel, and would lose WiFi until it
    also takes the kernel. The combined-image path writes both.
  • hi3519v101_lite is the next domino, now at 8KB free of 5120KB. It is
    untouched here.

Scope

  • No kernel patches under general/package/all-patches/linux/ (those go to OpenIPC/linux)
  • No files specific to a single retail camera model (those go to OpenIPC/builder)
  • No probing or bring-up tooling (that goes to OpenIPC/ipctool)
  • Nothing under general/overlay/ or in a shared load_<vendor> script hardcodes a value specific to my board
  • Package sources come from an OpenIPC repository, and any version bump keeps at least the specificity of the pin it replaces (a new package should pin a full 40-character SHA)
  • No LD_PRELOAD, and no binaries that cannot be rebuilt from source
  • New code is selected by a defconfig, so CI actually builds it

hi3518ev300_lite went red in the 2026-09-10 nightly at 5128KB against its
5120KB squashfs cap. Nothing in this repository grew to do it: between the
09-09 and 09-10 runs majestic's master tarball gained 14,918 bytes and
majestic-webui's dist gained 4,888, and both are unpinned moving refs, so
every board's rootfs grew ~20KB with no pull request to point at. This board
had 12KB of headroom and CI had printed the warning a day earlier.

The slack that does exist is in the kernel partition -- 1864KB used of 2048KB
-- and it cannot be lent to the rootfs. The 8MB map is compiled into U-Boot
and saved in every deployed camera's environment
(...,2048k(kernel),5120k(rootfs),-(rootfs_data)), so a squashfs over 5120k
would run past the end of the rootfs MTD and into the owner's overlay. Code
can move the other way, though.

Building the 17 crypto symbols in rather than shipping them as modules takes
11 .ko out of /lib/modules for 12KB of kernel. The trade works because most
of a small .ko is ELF symbol table, relocations and .modinfo, all of which
disappear once the code is linked in -- 89,572 bytes of .ko become 12KB of
uImage.

  before   uImage 1864KB/2048KB   rootfs.squashfs 5128KB/5120KB   8KB over
  after    uImage 1876KB/2048KB   rootfs.squashfs 5104KB/5120KB   16KB free

Nothing is dropped. mt7601u.ko, r8188eu.ko, mac80211.ko and wireguard.ko all
still ship, so both USB WiFi dongles behave exactly as before. busybox
modprobe reads modules.builtin and answers "module ... is builtin" for a
built-in name, and /etc/wireless/usb ignores modprobe's exit status, so the
load path is unaffected.

The config is shared with hi3518ev300_ultimate, whose 4096KB kernel cap
absorbs the 12KB without coming close.

One consequence worth knowing: the kernel and rootfs are a matched pair for
this board from here on. A camera updated with `sysupgrade -r` alone would
have the modules gone from the rootfs and not yet built into its kernel; the
combined-image path writes both.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Build hi3518ev300 crypto modules into the kernel

🐞 Bug fix ⚙️ Configuration changes 🕐 10-20 Minutes

Grey Divider

AI Description

• Builds 17 crypto options into hi3518ev300 kernels instead of loadable modules.
• Frees 24KB of rootfs space while consuming 12KB of kernel headroom.
• Preserves deployed flash partition layouts and existing WiFi functionality.
Diagram

graph TD
  C["Kernel config"] --> K["Built-in crypto"] --> U["uImage"] --> F["Firmware bundle"]
  C -->|"excludes crypto modules"| P["Module packaging"] --> R["Root filesystem"] --> F
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Pin upstream application artifacts
  • ➕ Prevents unreviewed nightly size changes
  • ➕ Makes firmware builds reproducible
  • ➕ Retains kernel and rootfs contents unchanged
  • ➖ May hold back upstream fixes and features
  • ➖ Requires selecting and maintaining stable revisions
  • ➖ Does not accommodate future intentional application growth
2. Resize flash partitions
  • ➕ Provides substantially more rootfs headroom
  • ➕ Avoids relocating functionality between artifacts
  • ➖ Conflicts with deployed U-Boot environments
  • ➖ Can overwrite existing rootfs_data overlays
  • ➖ Requires a coordinated and risky migration path
3. Remove optional rootfs features
  • ➕ Creates immediate rootfs headroom
  • ➕ Avoids increasing the kernel image
  • ➖ Regresses supported WiFi or application functionality
  • ➖ Changes board capabilities to address a packaging constraint

Recommendation: The proposed module-to-built-in conversion is the best immediate fix because it preserves functionality and the deployed flash map while using available kernel headroom efficiently. Follow up by pinning or otherwise controlling the moving Majestic artifacts, and require hardware validation of boot, streaming, and both supported USB-WiFi drivers before field deployment.

Files changed (1) +17 / -17

Other (1) +17 / -17
hi3518ev300.generic.configLink required crypto algorithms into hi3518ev300 kernels +17/-17

Link required crypto algorithms into hi3518ev300 kernels

• Changes 17 crypto framework, cipher, hash, and random-number options from loadable modules to built-ins. This removes 11 crypto '.ko' files from the rootfs while retaining their functionality in kernels shared by the lite and ultimate variants.

br-ext-chip-hisilicon/board/hi3516ev200/hi3518ev300.generic.config

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

qodo-free-for-open-source-projects Bot commented Sep 11, 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. Camera behavior lacks hardware proof 📘 Rule violation ☼ Reliability
Description
hi3518ev300.generic.config changes CONFIG_CRYPTO_AEAD and related crypto settings from loadable
modules to built-ins, but the resulting kernel was not tested on a real camera and its crypto
self-tests are disabled. The shared configuration reaches both lite and ultimate images, changing
initialization and module-loading behavior used by boot, streaming, WireGuard, and MT7601U or
RTL8188EU USB Wi-Fi paths without runtime validation.
Code

br-ext-chip-hisilicon/board/hi3516ev200/hi3518ev300.generic.config[2594]

+CONFIG_CRYPTO_AEAD=y
Evidence
The cited kernel configuration changes crypto support from a module to a built-in, while the PR
description explicitly says that no camera testing was performed. Both deployable hi3518ev300
variants select this shared configuration and package WPA/WireGuard functionality and the affected
USB Wi-Fi firmware; because crypto manager self-tests and the crypto test module are disabled,
successful build and size checks provide no repository-side runtime validation of booting,
streaming, or wireless operation.

Rule 1: Hardware evidence is present and honest
br-ext-chip-hisilicon/board/hi3516ev200/hi3518ev300.generic.config[2594-2594]
br-ext-chip-hisilicon/configs/hi3518ev300_lite_defconfig[18-24]
br-ext-chip-hisilicon/configs/hi3518ev300_lite_defconfig[32-37]
br-ext-chip-hisilicon/configs/hi3518ev300_lite_defconfig[61-63]
br-ext-chip-hisilicon/configs/hi3518ev300_ultimate_defconfig[18-24]
br-ext-chip-hisilicon/configs/hi3518ev300_ultimate_defconfig[33-38]
br-ext-chip-hisilicon/board/hi3516ev200/hi3518ev300.generic.config[2611-2619]

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 shared hi3518ev300 kernel configuration changes crypto components from loadable modules to built-ins and affects both lite and ultimate images, but neither resulting image has been exercised on real hardware. Build and size checks cannot establish that the rebuilt kernel boots or that streaming, USB Wi-Fi, and WireGuard still operate, particularly because kernel crypto self-tests are disabled.
## Fix Focus Areas
- br-ext-chip-hisilicon/board/hi3516ev200/hi3518ev300.generic.config[2594-2594]
- br-ext-chip-hisilicon/configs/hi3518ev300_lite_defconfig[18-24]
- br-ext-chip-hisilicon/configs/hi3518ev300_ultimate_defconfig[18-24]
## Recommended Fix
Build the before-and-after lite and ultimate images and test them on affected hi3518ev300 hardware. Update the PR evidence with observed successful boot and streaming results, then exercise WireGuard and the supported MT7601U and RTL8188EU USB Wi-Fi paths where the hardware is available before merging.

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


Grey Divider

Tip of the day
💡 Did you know, you can switch off images and animations for a plain-text comment

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@widgetii
widgetii merged commit 26e5ccd into master Sep 11, 2026
32 of 37 checks passed
@widgetii
widgetii deleted the hi3518ev300-modules-into-kernel branch September 11, 2026 13:13
widgetii added a commit that referenced this pull request Sep 15, 2026
…nnot load

Six boards were over or at their squashfs cap. All of them ship kernel modules
that no code path on the image can load; this removes those, at no cost to the
kernel partition and with nothing dropped that anything uses.

  gk7205v300_lite   5140 -> 5080KB/5120   (was 20KB over)
  gk7205v200_lite   5132 -> 5072KB/5120   (was 12KB over)
  gk7605v100_lite   5124 -> 5068KB/5120   (was  4KB over)
  gk7202v300_lite   5120 -> 5088KB/5120   (was  0KB free)
  hi3516ev300_lite  5124 -> 5060KB/5120   (was  4KB over)
  hi3516av300_neo   8208 -> 6688KB/8192   (was 16KB over)

WHY THEY WENT OVER. Nothing in this repository grew to do it. Between the last
green nightly (34771958692) and the red one (34874636710), every board carrying
majestic-webui grew 12-44KB, and the only three at +0KB are exactly the three
that ship neither majestic nor the webui. Both are unpinned moving refs by
design. Full analysis, and the levers not spent here, in #2420.

THE USB GADGET STACK HAS NO CONSUMER (goke x4, hi3516ev300). libcomposite,
configfs, usb_f_acm/ecm/rndis/mass_storage, u_ether and u_serial exist on these
images only for usb-dual-role -- selected by zero defconfigs and listed in
ci-matrix.py's NOT_BUILT. There is no USB hotplug modprobe either: mdev.conf
carries no $MODALIAS rule and S40network dispatches only on the `wlandev`
U-Boot variable, so a module is loadable if and only if a script names it.
Nothing names these. br_netfilter and i2c-tiny-usb go too -- no consumer
anywhere in the tree.

USB_GADGET itself stays =y. USB_DWC3_DUAL_ROLE depends on it, so turning the
subsystem off would drop the controller out of dual-role and take USB host --
and the Wi-Fi dongle -- with it. Only the functions go.

Not touched, having checked: usbnet, cdc_ether, mii, usb_wwan and
usb-serial-simple are dependency-loaded by option/usbserial/rndis_host, which
/etc/wireless/modem does modprobe; every crypto .ko is loaded by the kernel
crypto API's own request_module(), which is why #2397 built those in rather
than deleting them; tun is live via vtund-openipc/files/tunnel:24.

THE cv500 NEO SHIPPED EVERY VENDOR MODULE TWICE. The neo variants build the 7.x
upstream-patches kernel, where buildroot's kernel-module install lands the .ko
in updates/ rather than the extra/ that hisilicon-opensdk's finalize hook
clears, and INSTALL_TARGET_CMDS then copies the same open_*.ko set into
hisilicon/. kmod searches "updates" first, so that is the copy modprobe
resolves and depmod indexes; hisilicon/ is unreachable. On hi3516av300_neo that
is 45 modules and 5.4MB -- 1520KB of squashfs. Verified against the nightly's
own published image: the hisilicon/ names are a pure subset of updates/,
modules.dep names updates/ 156 times and hisilicon/ never, and the two copies
of a module are the same object differing only in that updates/ is stripped.

Scoped to cv500+neo deliberately, because the same duplication has the opposite
answer next door: hi3516cv300_neo renames its modules to hi3516cv300_*/hi_* in
hisilicon/, names that exist nowhere in updates/ and that its load_hisilicon
insmods by filename. The 4.9 boards have no updates/ directory at all. The
remaining neo boards are tracked in #2420.

usb-dual-role NOW BRINGS ITS OWN KERNEL SYMBOLS, through the same
LINUX_CONFIG_FIXUPS mechanism linux-patcher uses, so disabling them per board
cannot strand it. The audit behind that is worth recording: usb-mode modprobes
exactly configfs, libcomposite and usb_f_uvc -- it never composes ACM, ECM,
RNDIS or mass_storage, which are precisely the four functions these boards were
shipping -- while USB_CONFIGFS_F_UVC, the one function it does load, was absent
from those configs entirely. The previous state could not have worked. Verified
by selecting the package on gk7205v300_lite and rebuilding: USB_GADGET,
CONFIGFS_FS, USB_CONFIGFS and USB_LIBCOMPOSITE come back. F_UVC does not,
because it also needs VIDEO_V4L2 and VIDEO_DEV; the request stays in the fixup
and the limit is written into both the .mk and the Config.in help.

MEASURED, full clean builds (make clean, so no stale per-package module trees),
before and after taken from the same build:

  gk7205v300_lite   5,263,360 -> 5,201,920 B   uImage [1810KB/2048KB] unchanged
  hi3516ev300_lite  [5124KB]  -> [5056KB]      uImage [2005KB/2048KB] unchanged

No kernel cost anywhere, which matters for hi3516ev300 -- it has the
second-tightest kernel partition in the tree and could not have paid for a
build-in trade. Verified in the built rootfs: the removed .ko are gone and
mac80211, cfg80211, mt7601u, wireguard, tun, option, usbserial, rndis_host,
usbnet and mii all still ship, with modules.dep still resolving
mt7601u -> mac80211 -> cfg80211. SCSI is deliberately left alone on
hi3516ev300; #2410 dropped it from hi3518ev300 after establishing that board
had no transport, and scsi_mod/sd_mod here need that determination separately.

NOT TESTED ON A CAMERA -- I have none of these boards. Someone with a goke
camera should confirm an MT7601U dongle still associates and USB host still
enumerates; someone with an hi3516av300 neo should confirm it still boots and
streams. hi3516av300_neo was not built locally either (it needs the 7.x kernel
tree); its evidence is the published image above, and CI builds it.

Refs #2420
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.

1 participant