Skip to content

hi3516cv200: OSAL shim layer for kernel version independence #46

@widgetii

Description

@widgetii

Problem

hi3516cv200 (V2 generation) is the only platform where binary blobs call kernel APIs directly — all other platforms (V3/V3.5/V4) go through OSAL, which can be recompiled for any kernel version.

Currently CV200 is locked to kernel 4.9.37. Bumping beyond ~4.19 will break blob modules because removed kernel APIs (ioremap_nocache, do_gettimeofday, init_timer, set_fs, etc.) are called directly from the 18 blob .o files in kernel/obj/hi3516cv200/.

PR #45 landed the foundation — all open_ modules load and stream on real hi3518ev200 hardware. This issue tracks the next step: kernel version independence.

Proposed approach

Create a CV200 OSAL shim module (open_osal.ko) that exports old kernel API names, forwarding to current kernel implementations. This mirrors how V3/V4 OSAL works but targeted at the specific APIs the V2 blobs import.

Step 1: Catalog blob dependencies

for f in kernel/obj/hi3516cv200/*.o; do
    echo "=== $(basename $f) ==="
    nm --undefined-only $f | grep -v "^$"
done

Categorize undefined symbols into:

  • Kernel APIs (need shims when kernel changes)
  • Cross-module (provided by other open_ modules — already working)
  • Compiler builtins (__aeabi_* — stable)

Step 2: Build shim module

Reuse patterns from existing OSAL implementations:

  • kernel/osal/hi3516cv500/ — V3.5 OSAL (closest reference)
  • kernel/osal/linux/kernel/ — V4 shared OSAL

The CV200 shim only needs to cover kernel APIs that the blobs actually call and that changed between 4.9 and the target kernel. It does NOT need the full OSAL abstraction layer.

Step 3: Incremental kernel testing

Target Expected effort
4.19 LTS Likely works with zero or minimal shims
5.4 LTS access_ok, do_gettimeofday shims
5.10 LTS Above + set_fs/get_fs (hardest)
5.15 LTS Above + ioremap_nocache
6.1+ LTS Above + proc_ops, strlcpy, sysctl changes

Known hard problems

  • set_fs()/get_fs() removal (5.10+): Blobs use these for kernel↔user copies. Restoring addr_limit in thread_info requires a kernel patch, not just a module shim. The V4 OSAL solved this by wrapping all user access behind osal_copy_from_user().

  • Struct layout changes: If blobs embed struct file_operations, struct timer_list, or struct proc_dir_entry by value, field offset changes will cause silent corruption. Each blob needs verification via objdump -d to check struct access patterns.

References

  • PR fix: resolve hi3516cv200 module issues for hardware deployment #45 — CV200 module fixes for real hardware (merged baseline)
  • kernel/compat/kernel_compat.h — existing compat shims for source modules (3.0–7.0)
  • kernel/osal/hi3516cv500/ — V3.5 OSAL reference implementation
  • Hi3518E SDK V1.0.5.0 — vendor SDK this platform is based on

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions