kernel/hi3516cv300: fix cv300_lite (kernel 3.18) build regression from #148#150
Merged
Conversation
…#148 PR #148 brought cv300 OSAL/peripherals up to Linux 7.0 and was verified end-to-end on kernel 7.0 under QEMU, but it broke the cv300_lite 3.18 path that ships in production firmware. Two distinct root causes, both caught while building hi3516cv300_lite from firmware PR #2103: 1. mmz/media-mem.c called p4d_offset() unconditionally. The symbol was added in 4.11 (5-level paging prep). On 3.18 it doesn't exist: error: implicit declaration of function 'p4d_offset'; did you mean 'pmd_offset'? Gate it with LINUX_VERSION_CODE >= 4.11 and fall back to pud_offset(pgd, virt) on older kernels — same pattern already used by hi3516cv500/mmz/media_mem.c and osal/linux/kernel/mmz/ media-mem.c. (CLAUDE.md prefers shims in kernel_compat.h, but pud_offset's first-arg type also differs across the cutover so a clean macro shim isn't possible — matching the existing cv500 pattern is the right local minimum.) 2. wdt/hi_wdt.c, ir/hiir.c, pwm/pwm.c, rtc/hi_rtc.c gained `MODULE_LICENSE("GPL")` lines in #148 but none of them include <linux/module.h> directly. On 7.0 the include chain via hi_osal.h transitively pulls in module.h and the macro resolves. On 3.18 the chain is shorter, the macro is undefined, and the C preprocessor leaves the call as a bare function-like token: error: expected declaration specifiers or '...' before string constant 583 | MODULE_LICENSE("GPL"); Add the explicit `#include <linux/module.h>` to each affected file — what the existing cv300 init/*.c files already do, and what the macro's contract requires. Verified by building hi3516cv300_lite from firmware feat/cv300-neo with this openhisilicon pinned in, and diffing the resulting rootfs against the latest nightly: - file list: 674 = 674, diff empty - hisilicon .ko set: identical - QEMU -M hi3516cv300: * login prompt reached * lsmod identical (5 modules) * dmesg identical except: build host, build time, +/-4K rounding in `Memory: ... available`, BogoMIPS scheduling jitter, random MAC (no DT MAC → seeded from RNG) * no Oops/panic/BUG/Trace
Two more regressions from #148, caught on this branch's CI matrix across the cv500_lite / cv200_lite (kernel 4.9) and ev300_neo / av300_neo (kernel 6.6 / 6.18 / 7.0) rows: 1. print_symbol shim was gated `>= 4.0.0`, but the kernel function is still declared in <linux/kallsyms.h> on 4.x and 5.0-5.14. Defining it as a `do { ... } while (0)` macro collides with the existing function prototype: error: expected identifier or '(' before 'do' 189 | do { \ It was actually removed in 5.15 (commit f74cd6432cb6). Bump the gate to KERNEL_VERSION(5, 15, 0) — the macro now only kicks in on kernels that no longer declare the function. 2. DEFINE_SEMAPHORE shim did `#undef` + redefine as a 1-arg macro on >= 6.4. cv500 and osal/linux mmz code call DEFINE_SEMAPHORE with the modern 2-arg form via compat_DEFINE_SEMAPHORE; my redefinition broke that: error: macro "DEFINE_SEMAPHORE" passed 2 arguments, but takes just 1 Drop the `#undef` — leave the kernel macro alone. Keep only the compat_DEFINE_SEMAPHORE helper that maps the 1-arg legacy call to the 2-arg modern form. Update cv300 osal mmz/media-mem.c to use compat_DEFINE_SEMAPHORE (matches the pattern cv500 mmz already uses). Verified by rebuilding hi3516cv300_lite again with these fixes: rootfs file list still 674 = 674 vs nightly, hisilicon .ko set unchanged.
Member
Author
|
Additional fixes pushed: PR #148 also broke cv500_lite / cv200_lite (kernel 4.9, `print_symbol` collision) and ev300_neo / av300_neo (kernel 6.4+, `DEFINE_SEMAPHORE` collision). Surfaced by the CI matrix run on this branch.
Locally verified: cv300_lite still byte-equivalent to nightly (rootfs file list 674 = 674, hisilicon .ko set unchanged) and the other shim-affected platforms should now compile. |
widgetii
added a commit
to OpenIPC/firmware
that referenced
this pull request
May 17, 2026
…ion fix) The previous bump to b405551 inadvertently broke cv300_lite (kernel 3.18), cv500_lite / cv200_lite (kernel 4.9), and ev300_neo / av300_neo (kernel 6.4+) builds. Pulled in via OpenIPC/openhisilicon#150: - mmz/media-mem.c gated p4d_offset() on >= 4.11 (didn't exist on 3.18, was added in 4.11 as 5-level paging prep) - wdt/ir/pwm/rtc/hi3516cv300 .c files: explicit <linux/module.h> include so MODULE_LICENSE() expands on 3.18 (the chain via hi_osal.h only pulled it transitively on 7.0) - kernel_compat.h: print_symbol shim gated >= 5.15 not >= 4.0 (function is still declared in <linux/kallsyms.h> through 5.14; macro do { ... } while (0) collides with the prototype on 4.9) - kernel_compat.h: DEFINE_SEMAPHORE shim dropped the #undef + 1-arg redefinition; kept only compat_DEFINE_SEMAPHORE helper. cv300 osal/mmz/media-mem.c updated to use the helper (matches cv500 mmz pattern). Locally verified: hi3516cv300_lite build from this branch produces a rootfs byte-equivalent to nightly (674 = 674 files, hisilicon .ko set unchanged, QEMU lsmod + scrubbed dmesg identical).
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.
Summary
#148 brought cv300 OSAL/peripherals up to Linux 7.0 and was verified end-to-end on kernel 7.0 under QEMU — but it broke the cv300_lite 3.18 path that ships in production firmware. Two distinct root causes, both surfaced while building `hi3516cv300_lite` from OpenIPC/firmware#2103:
`mmz/media-mem.c` called `p4d_offset()` unconditionally. The symbol was added in 4.11; on 3.18 it doesn't exist. Gate it with `LINUX_VERSION_CODE >= 4.11` and fall back to `pud_offset(pgd, virt)` on older kernels — same pattern `hi3516cv500/mmz/media_mem.c` and `osal/linux/kernel/mmz/media-mem.c` already use.
`wdt/hi_wdt.c`, `ir/hiir.c`, `pwm/pwm.c`, `rtc/hi_rtc.c` got `MODULE_LICENSE("GPL")` lines in kernel/hi3516cv300: bring up V3 OSAL against Linux 7.0 + ci matrix row (issue #60) #148 without an explicit `#include <linux/module.h>`. On 7.0 the include chain via `hi_osal.h` transitively pulls module.h; on 3.18 it doesn't, the macro is undefined, and the C preprocessor leaves a bare string-literal call. Add the explicit include — matching what the cv300 init/*.c files that already have `MODULE_LICENSE` do.
Test plan
Built `hi3516cv300_lite` from OpenIPC/firmware feat/cv300-neo with this fix pinned in, diffed against today's nightly:
No behavioural change to the 7.0 (neo) path either — the fix is conditional (`#if LINUX_VERSION_CODE` for p4d; bare include addition for module.h). Both kernel versions take the same compiled paths after this change.
🤖 Generated with Claude Code