Skip to content

hisilicon-opensdk: build sc2315e for hi3516ev200 from source, dropping the binary - #2881

Merged
openipc-ai merged 1 commit into
masterfrom
hisilicon/sc2315e-from-source
Nov 17, 2026
Merged

openipc-ai merged 1 commit into
masterfrom
hisilicon/sc2315e-from-source

Conversation

@openipc-ai

Copy link
Copy Markdown
Collaborator

Problem

hi3516ev200-family cameras with an SC2315E sensor can lose the streamer when the video pipeline restarts (a reload with a changed setting): it stops with SIGILL in musl's free(), freeing the sensor driver's state. Reported from the field to openipc.org's crash collection; whether a given streamer build is hit depends only on heap layout, so it comes and goes with unrelated changes.

The cause is libsns_sc2315e.so, which hisilicon-osdrv-hi3516ev200 carried as a binary with no source here. It allocates a 2156-byte ISP_SNS_STATE_S and, on every frame-rate set, writes two words ~490 bytes past it (pstSnsState[1]..., lines carried over from a disassembly of a vendor build with a larger state struct). Its source is now in openhisilicon (libraries/sensor/hi3516ev200/smart_sc2315e), with the overrun fixed: OpenIPC/openhisilicon#306.

This bumps the opensdk pin to that merge (the only change between the two pins), builds the driver for the hi3516ev200 family, and removes the binary so the two cannot overwrite each other in either install order. It is added per family rather than to HISILICON_OPENSDK_SENSORS_hi3516ev200 itself, because gk7205v200 takes that list whole and installs from its own sensor tree, which has no sc2315e.

Hardware tested on

hi3516ev200 + SC2315E lab camera, stock OpenIPC lite firmware (Lite HiSilicon (hi3516ev200), master+8d76d3e), with the libsns_sc2315e.so taken from a hi3516ev200_lite build of this branch (output/target/usr/lib/sensors/) bind-mounted over the installed one. I did not flash a full image from this branch: locally the build stopped at post-image-split.sh on the kernel config (a stale kernel tarball in the download cache I reused), after the rootfs was built.

To make the overrun visible regardless of heap layout, the streamer was run with a test-only LD_PRELOAD shim that places any 2156-byte allocation flush against a PROT_NONE page, and with /proc/sys/kernel/print-fatal-signals set to 1. Neither is part of this change. The "after" run used a current streamer build (it restarts the pipeline only when a setting changes, so video0.fps was changed before each reload).

Evidence

Before (installed binary, md5 c945192b496632a12f5004a3a17f0367), on start:

majestic exit status 139
11:17:43 INFO  <majestic> [sc2315e_cmos.c] sensor_driver@1144: SC2315E Universal driver © openipc.org Jan  1 2022 19:12:29
GUARD malloc(2156) = 0xb6a8c794, guard page at 0xb6a8d000, caller 0xb6a8f61c
potentially unexpected fatal signal 11.
PC is at 0xb6a8f050
pc : [<b6a8f050>]    lr : [<00000046>]    psr: 80000010
r3 : b6a8c794  r2 : b6f0b518  r1 : 00000a8c  r0 : 00000a88

The driver is mapped at 0xb6a8e000 (the malloc call returns to +0x161c), so the fault is at +0x1050: str r1, [r3, #2648] with r3 the 2156-byte state.

After (this branch's build, md5 b5a5b19441aa8f3ef8e86df0a99cc4c1), eight pipeline rebuilds:

11:11:06 INFO  <majestic.master> [sc2315e_cmos.c] sensor_driver@1157: SC2315E Universal driver © openipc.org Nov 17 2026 11:09:37
GUARD malloc(2156) = 0xb69ed794, guard page at 0xb69ee000, caller 0xb69f0c29
rebuild1 video0.fps=25 pid=2911 isp: IntGapT=40019us IntRat=26 venc FrameRate=25
rebuild2 video0.fps=20 pid=2911 isp: IntGapT=40034us IntRat=26 venc FrameRate=20
rebuild3 video0.fps=15 pid=2911 isp: IntGapT=39996us IntRat=26 venc FrameRate=15
rebuild4 video0.fps=25 pid=2911 isp: IntGapT=40001us IntRat=26 venc FrameRate=25
rebuild5 video0.fps=20 pid=2911 isp: IntGapT=40016us IntRat=25 venc FrameRate=20
rebuild6 video0.fps=15 pid=2911 isp: IntGapT=39985us IntRat=26 venc FrameRate=15
rebuild7 video0.fps=25 pid=2911 isp: IntGapT=40018us IntRat=26 venc FrameRate=25
rebuild8 video0.fps=20 pid=2911 isp: IntGapT=40017us IntRat=26 venc FrameRate=20
guarded state allocated 9 times, freed 8 times
0 fatal signals

Sensor timing (/proc/umap/isp interrupt gap, 40 ms) and encoder rates match the installed binary's under the same settings; snapshots from both looked the same.

Size: the driver built from source is 31320 bytes against the binary's 35360, so the image shrinks by ~4 KB. Local hi3516ev200_lite rootfs: Filesystem size 5214.91 Kbytes.

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

…g the binary

hisilicon-osdrv-hi3516ev200 carried libsns_sc2315e.so as a binary with no
source here. It wrote two words ~490 bytes past its 2156-byte sensor state
on every frame-rate set, and musl's allocator could stop the streamer with
SIGILL in free() when the pipeline restarted -- reported from the field on
hi3516ev200 + SC2315E cameras. Its source is now in openhisilicon
(smart_sc2315e, OpenIPC/openhisilicon#306) with the overrun fixed.

Bump the opensdk pin to that merge and build the driver for the
hi3516ev200 family only: gk7205v200 takes the family's sensor list whole
and installs from its own sensor tree, which has no sc2315e. The binary
goes, so the two cannot overwrite each other in either install order.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Build hi3516ev200 SC2315E driver from fixed upstream source

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

Grey Divider

AI Description

• Pin openhisilicon to the SC2315E fix for a sensor-state buffer overrun.
Diagram

graph TD
  A["Openhisilicon source"] --> B["SDK build"] --> C["SC2315E driver"] --> D["Firmware sensors"] --> E["Streamer pipeline"]
  F["hi3516ev200 selection"] --> D
Loading
High-Level Assessment

Use the fixed upstream source and select its library only for hi3516ev200. Adding it to the shared sensor list would also select it for gk7205v200, whose sensor tree lacks SC2315E; retaining the old binary would leave install-order ambiguity.

Files changed (1) +12 / -1

Bug fix (1) +12 / -1
hisilicon-opensdk.mkPin fixed SDK and select SC2315E for hi3516ev200 +12/-1

Pin fixed SDK and select SC2315E for hi3516ev200

• Advances the openhisilicon commit pin to the version with the SC2315E overrun fix. Adds the source-built driver to the install list only for hi3516ev200, avoiding the gk7205v200 family that reuses the base list.

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

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

qodo-free-for-open-source-projects Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Remediation recommended

1. Standalone builds lose the sensor driver 🐞 Bug ≡ Correctness
Description
libsns_sc2315e.so is now supplied by the OpenSDK sensor list, but the Hi3516EV200 osdrv package
can still be selected without OpenSDK. In a configuration selecting only osdrv, its SC2315E profile
remains installed while the library it names is no longer installed.
Code

general/package/hisilicon-opensdk/hisilicon-opensdk.mk[R331-333]

+ifeq ($(OPENIPC_SOC_FAMILY),hi3516ev200)
+HISILICON_OPENSDK_SENSORS += smart_sc2315e/libsns_sc2315e
+endif
Evidence
The osdrv symbol has no OpenSDK dependency or selection, whereas the new library is installed only
by OpenSDK. The existing SC2315E profile explicitly requests that library.

general/package/hisilicon-osdrv-hi3516ev200/Config.in[1-7]
general/package/hisilicon-opensdk/Config.in[1-7]
general/package/hisilicon-opensdk/hisilicon-opensdk.mk[331-333]
general/package/hisilicon-opensdk/hisilicon-opensdk.mk[789-793]
general/package/hisilicon-osdrv-hi3516ev200/files/sensor/config/sc2315e_i2c_1080p.ini[1-4]

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 SC2315E library has moved from osdrv to OpenSDK, but osdrv remains independently selectable. An osdrv-only configuration retains the sensor profile without its library.
## Fix Focus Areas
- general/package/hisilicon-osdrv-hi3516ev200/Config.in[1-7]
- general/package/hisilicon-opensdk/hisilicon-opensdk.mk[331-333]
## Recommended Fix
Make the osdrv package select OpenSDK, accounting for OpenSDK's Linux-kernel dependency, so every configuration that installs the SC2315E profile also builds and installs its library.

ⓘ 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 enable the Remediation agent and Qodo fixes findings in a dedicated fix PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@openipc-ai

Copy link
Copy Markdown
Collaborator Author

Qodo finding 1 (standalone builds lose the sensor driver): left as is. Every defconfig that enables BR2_PACKAGE_HISILICON_OSDRV_HI3516EV200 (hi3516ev200, hi3516ev300, hi3518ev300 and hi3516dv200, all variants) also enables BR2_PACKAGE_HISILICON_OPENSDK, and an osdrv-only configuration is already in this state for most of the family's sensors: osdrv installs the profiles for imx307, imx335, gc2053, sc2235, sc3335, sp2305 and others, whose libraries only opensdk builds. sc2315e now joins them. Making osdrv select opensdk (and with it the kernel) would change the package graph for the whole family, which is a separate decision from this fix.

@openipc-ai
openipc-ai merged commit 526fb53 into master Nov 17, 2026
82 of 83 checks passed
@openipc-ai
openipc-ai deleted the hisilicon/sc2315e-from-source branch November 17, 2026 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant