Skip to content

Commit 296abc9

Browse files
authored
Merge pull request qualcomm-linux#206 from smuppand/video-fix
Video: custom .ko install + quieter logs, ShellCheck fixes & CI tweak
2 parents 7915fd1 + 91f5f42 commit 296abc9

File tree

3 files changed

+187
-36
lines changed

3 files changed

+187
-36
lines changed

Runner/plans/video_pre-merge.yaml

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,48 @@ run:
1818
RPATH="$REPO_ROOT/suites/Multimedia/Video/Video_V4L2_Runner/run.sh"
1919
RESFILE="$REPO_ROOT/suites/Multimedia/Video/Video_V4L2_Runner/Video_V4L2_Runner.res"
2020
21-
# Custom media bundle (local) paths
21+
# Custom media bundle (local) path
2222
CLIPS_TAR="/data/vendor/iris_test_app/video_clips_iris.tar.gz"
23-
CLIPS_DEST="/data/vendor/iris_test_app/clips"
2423
2524
# Custom downstream module location (directory containing iris_vpu.ko)
2625
KO_DIR="/data/vendor/iris_test_app"
2726
2827
# Optional: downstream firmware needed on Kodiak overlay
29-
DS_FW="/data/vendor/iris_test_app/vpu20_p1_gen2.mbn"
28+
DS_FW="/data/vendor/iris_test_app/vpu20_1v.mbn"
29+
30+
# Prefer explicit TARGET; otherwise derive from LAVA device-type
31+
if [ -n "${TARGET:-}" ]; then
32+
TL="$(printf '%s' "$TARGET" | tr '[:upper:]' '[:lower:]')"
33+
else
34+
DEVTYPE_RAW="${DEVICE_TYPE:-${LAVA_DEVICE_TYPE:-${LAVA_DEVICE_TYPE_NAME:-${DEVICE_TYPE_NAME:-}}}}"
35+
DEVTYPE="$(printf '%s' "$DEVTYPE_RAW" | tr '[:upper:]' '[:lower:]')"
36+
case "$DEVTYPE" in
37+
# monaco
38+
qcs8300-ride|qcs8300-ride-sx|iq-8275-evk) TL="monaco" ;;
39+
# lemans
40+
qcs9100-ride-r3|sa8775p-ride|iq-9075-evk|qcs9075-rb8|qcs9100-ride-sx) TL="lemans" ;;
41+
# kodiak
42+
qcs6490-rb3gen2|rb3gen2|qcs6490-rb3gen2-core-kit) TL="kodiak" ;;
43+
# fallback to autodetect in run.sh
44+
*) TL="" ;;
45+
esac
46+
fi
3047
31-
# Normalize/derive platform flag
32-
TL="$(printf '%s' "${TARGET:-}" | tr '[:upper:]' '[:lower:]')"
3348
case "$TL" in
3449
kodiak|lemans|monaco) PLAT="--platform $TL" ;;
3550
*) PLAT="" ;; # autodetect
3651
esac
3752
38-
# Common args (clips local, no Wi-Fi or TAR_URL needed)
39-
ARGS_COMMON="--clips-tar $CLIPS_TAR --clips-dest $CLIPS_DEST --app /data/vendor/iris_test_app/iris_v4l2_test $PLAT --retry-on-fail 2 --loglevel 15"
53+
echo "DEBUG: TARGET='${TARGET:-}' DEVTYPE='${DEVTYPE:-}' -> TL='$TL' PLAT='$PLAT'"
54+
55+
# Common args (local clips; no Wi-Fi/TAR_URL needed)
56+
ARGS_COMMON="--clips-tar $CLIPS_TAR --app /data/vendor/iris_test_app/iris_v4l2_test $PLAT --retry-on-fail 2 --loglevel 15"
4057
4158
# --- BASE (upstream): NO ko args here ---
4259
ARGS_BASE="--stack base $ARGS_COMMON"
4360
44-
# --- OVERLAY (downstream): add ko args; on kodiak also add downstream FW ---
45-
ARGS_OVERLAY="--stack overlay $ARGS_COMMON --ko-dir $KO_DIR --ko-prefer-custom"
61+
# --- OVERLAY (downstream): add ko args; only add FW on kodiak ---
62+
ARGS_OVERLAY="--stack overlay $ARGS_COMMON"
4663
if [ "$TL" = "kodiak" ]; then
4764
ARGS_OVERLAY="$ARGS_OVERLAY --downstream-fw $DS_FW"
4865
fi

Runner/suites/Multimedia/Video/Video_V4L2_Runner/run.sh

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,12 @@ export INTER_TEST_SLEEP
293293
# --- EARLY dependency check (bail out fast) ---
294294

295295
# Ensure the app is executable if a path was provided but lacks +x
296+
if [ -n "$VIDEO_APP" ] && [ -f "$VIDEO_APP" ] && [ ! -x "$VIDEO_APP" ]; then
297+
chmod +x "$VIDEO_APP" 2>/dev/null || true
298+
if [ ! -x "$VIDEO_APP" ]; then
299+
log_warn "App $VIDEO_APP is not executable and chmod failed; attempting to run anyway."
300+
fi
301+
fi
296302

297303
# --- Optional: unpack a custom module tarball **once** (no env exports) ---
298304
KVER="$(uname -r 2>/dev/null || printf '%s' unknown)"
@@ -308,16 +314,13 @@ if [ -n "$KO_TARBALL" ] && [ -f "$KO_TARBALL" ]; then
308314
fi
309315
;;
310316
*)
311-
# not a tar? treat as a directory if user passed one by mistake
312317
:
313318
;;
314319
esac
315320
fi
316-
# decide whether the tar contained a full tree or loose .ko’s
317321
if [ -d "$DEST/lib/modules/$KVER" ]; then
318322
KO_TREE="$DEST"
319323
else
320-
# find first dir that has at least one .ko (bounded depth)
321324
first_ko_dir="$(find "$DEST" -type f -name '*.ko*' -maxdepth 3 2>/dev/null | head -n1 | xargs -r dirname)"
322325
if [ -n "$first_ko_dir" ]; then
323326
if [ -n "$KO_DIRS" ]; then
@@ -327,7 +330,6 @@ if [ -n "$KO_TARBALL" ] && [ -f "$KO_TARBALL" ]; then
327330
fi
328331
fi
329332
fi
330-
# quiet summary (only if user opted-in)
331333
log_info "Custom module source prepared (tree='${KO_TREE:-none}', dirs='${KO_DIRS:-none}', prefer_custom=$KO_PREFER_CUSTOM)"
332334
fi
333335

@@ -689,7 +691,7 @@ if [ "${VIDEO_STACK}" = "both" ]; then
689691
overlay_reason="missing --downstream-fw"
690692
fi
691693

692-
if [ "$rc_base" -eq 0 ] && [ "$rc_overlay" -eq 0 ]; then
694+
if [ "$rc_base" -eq 0 ] && [ "$rc_overlay" -eq 0 ] ; then
693695
if [ "$base_status" = "PASS" ] && [ "$overlay_status" = "SKIP" ]; then
694696
if [ -n "$overlay_reason" ]; then
695697
log_info "[both] upstream/base executed and PASS; downstream/overlay SKIP ($overlay_reason). Overall PASS."
@@ -720,7 +722,6 @@ if [ -n "$VIDEO_FW_DS" ]; then
720722
log_info "Downstream FW override: $VIDEO_FW_DS"
721723
fi
722724
if [ -n "$KO_TREE$KO_DIRS$KO_TARBALL" ]; then
723-
# print only when user actually provided custom sources
724725
if [ -n "$KO_TREE" ]; then
725726
log_info "Custom module tree (modprobe -d): $KO_TREE"
726727
fi
@@ -776,6 +777,33 @@ fi
776777
# --- Optional cleanup: robust capture + normalization of post-stack value ---
777778
video_dump_stack_state "pre"
778779

780+
# --- Custom .ko staging (only if user provided --ko-dir) ---
781+
if [ -n "${KO_DIRS:-}" ]; then
782+
case "$(video_normalize_stack "$VIDEO_STACK")" in
783+
downstream|overlay|down)
784+
KVER="$(uname -r 2>/dev/null || printf '%s' unknown)"
785+
786+
if command -v video_find_module_file >/dev/null 2>&1; then
787+
modpath="$(video_find_module_file iris_vpu "$KO_DIRS" 2>/dev/null | tail -n1 | tr -d '\r')"
788+
else
789+
modpath=""
790+
fi
791+
792+
if [ -n "$modpath" ] && [ -f "$modpath" ]; then
793+
log_info "Using custom iris_vpu candidate: $modpath"
794+
if command -v video_ensure_moddir_install >/dev/null 2>&1; then
795+
video_ensure_moddir_install "$modpath" "$KVER" >/dev/null 2>&1 || true
796+
fi
797+
if command -v depmod >/dev/null 2>&1; then
798+
depmod -a "$KVER" >/dev/null 2>&1 || true
799+
fi
800+
else
801+
log_warn "KO_DIRS set, but iris_vpu.ko not found under: $KO_DIRS"
802+
fi
803+
;;
804+
esac
805+
fi
806+
779807
video_step "" "Apply desired stack = $VIDEO_STACK"
780808

781809
stack_tmp="$LOG_DIR/.ensure_stack.$$.out"
@@ -804,6 +832,28 @@ log_info "Video stack (post): $post_stack"
804832

805833
video_dump_stack_state "post"
806834

835+
# --- Custom .ko load assist (only if user provided --ko-dir) ---
836+
if [ -n "${KO_DIRS:-}" ]; then
837+
case "$(video_normalize_stack "$VIDEO_STACK")" in
838+
downstream|overlay|down)
839+
if ! video_has_module_loaded iris_vpu 2>/dev/null; then
840+
if command -v video_find_module_file >/dev/null 2>&1; then
841+
modpath2="$(video_find_module_file iris_vpu "$KO_DIRS" 2>/dev/null | tail -n1 | tr -d '\r')"
842+
else
843+
modpath2=""
844+
fi
845+
846+
if [ "$KO_PREFER_CUSTOM" = "1" ] && [ -n "$modpath2" ] && [ -f "$modpath2" ]; then
847+
if command -v video_insmod_with_deps >/dev/null 2>&1; then
848+
log_info "Prefer custom: insmod with deps: $modpath2"
849+
video_insmod_with_deps "$modpath2" >/dev/null 2>&1 || true
850+
fi
851+
fi
852+
fi
853+
;;
854+
esac
855+
fi
856+
807857
# Always refresh/prune device nodes (even if no switch occurred)
808858
video_step "" "Refresh V4L device nodes (udev trigger + prune stale)"
809859
video_clean_and_refresh_v4l || true
@@ -1193,7 +1243,6 @@ while IFS= read -r cfg; do
11931243
r=1
11941244
log_info "[$id] RETRY_ON_FAIL: up to $RETRY_ON_FAIL additional attempt(s)"
11951245
while [ "$r" -le "$RETRY_ON_FAIL" ]; do
1196-
# optional delay between retries, reuse REPEAT_DELAY for consistency
11971246
if [ "$REPEAT_DELAY" -gt 0 ] 2>/dev/null; then
11981247
sleep "$REPEAT_DELAY"
11991248
fi
@@ -1205,7 +1254,6 @@ while IFS= read -r cfg; do
12051254
log_pass "[$id] RETRY succeeded — marking PASS"
12061255
break
12071256
else
1208-
# capture latest rc marker for visibility
12091257
rc_val="$(awk -F'=' '/^END-RUN rc=/{print $2}' "$logf" 2>/dev/null | tail -n1 | tr -d ' ')"
12101258
if [ -n "$rc_val" ]; then
12111259
case "$rc_val" in
@@ -1253,7 +1301,6 @@ while IFS= read -r cfg; do
12531301
fi
12541302
fi
12551303

1256-
# (6) Post-test settle sleep
12571304
case "$POST_TEST_SLEEP" in
12581305
''|*[!0-9]* )
12591306
:

Runner/utils/lib_video.sh

Lines changed: 105 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,58 +105,144 @@ video_log_fw_hint() {
105105
fi
106106
}
107107

108-
# -----------------------------------------------------------------------------
109-
# Shared module introspection helpers (kept; used by dump)
110-
# -----------------------------------------------------------------------------
108+
# Install a module file into /lib/modules/$(uname -r)/updates and run depmod.
109+
# Usage: video_ensure_moddir_install <module_path> <logical_name>
110+
video_ensure_moddir_install() {
111+
mp="$1" # source path to .ko
112+
mname="$2" # logical module name for logging
113+
kr="$(uname -r 2>/dev/null)"
114+
[ -z "$kr" ] && kr="$(find /lib/modules -mindepth 1 -maxdepth 1 -type d -printf '%f\n' 2>/dev/null | head -n 1)"
115+
116+
if [ -z "$mp" ] || [ ! -f "$mp" ]; then
117+
log_warn "install-ko: invalid module path: $mp"
118+
return 1
119+
fi
120+
121+
updates="/lib/modules/$kr/updates"
122+
if [ ! -d "$updates" ]; then
123+
if ! mkdir -p "$updates" 2>/dev/null; then
124+
log_warn "install-ko: cannot create $updates (read-only FS?)"
125+
return 1
126+
fi
127+
fi
128+
129+
base="$(basename "$mp")"
130+
dst="$updates/$base"
131+
132+
do_copy=1
133+
if [ -f "$dst" ]; then
134+
if command -v md5sum >/dev/null 2>&1; then
135+
src_md5="$(md5sum "$mp" 2>/dev/null | awk '{print $1}')"
136+
dst_md5="$(md5sum "$dst" 2>/dev/null | awk '{print $1}')"
137+
[ -n "$src_md5" ] && [ "$src_md5" = "$dst_md5" ] && do_copy=0
138+
else
139+
if cmp -s "$mp" "$dst" 2>/dev/null; then
140+
do_copy=0
141+
fi
142+
fi
143+
fi
144+
145+
if [ "$do_copy" -eq 1 ]; then
146+
if ! cp -f "$mp" "$dst" 2>/dev/null; then
147+
log_warn "install-ko: failed to copy $mp -> $dst"
148+
return 1
149+
fi
150+
chmod 0644 "$dst" 2>/dev/null || true
151+
sync 2>/dev/null || true
152+
log_info "install-ko: copied $(basename "$mp") to $dst"
153+
else
154+
log_info "install-ko: up-to-date at $dst"
155+
fi
156+
157+
if command -v depmod >/dev/null 2>&1; then
158+
if depmod -a "$kr" >/dev/null 2>&1; then
159+
log_info "install-ko: depmod -a $kr done"
160+
else
161+
log_warn "install-ko: depmod -a $kr failed (continuing)"
162+
fi
163+
else
164+
log_warn "install-ko: depmod not found; modprobe may fail to resolve deps"
165+
fi
166+
167+
[ -n "$mname" ] && video_log_resolve "$mname" updates-tree "$dst"
168+
printf '%s\n' "$dst"
169+
return 0
170+
}
171+
172+
# Takes a logical module name (e.g. iris_vpu), resolves/copies into updates/, depmods, then loads deps+module.
111173
video_insmod_with_deps() {
112-
# Takes a logical module name (e.g. qcom_iris), resolves the path, then insmods deps+module
113174
m="$1"
175+
[ -z "$m" ] && { log_warn "insmod-with-deps: empty module name"; return 1; }
176+
177+
[ -z "$MODPROBE" ] && MODPROBE="modprobe"
114178

115179
if video_has_module_loaded "$m"; then
116-
log_info "module already loaded (insmod path skipped): $m"
180+
log_info "module already loaded (skip): $m"
117181
return 0
118182
fi
119183

120-
path="$(video_find_module_file "$m")" || path=""
121-
if [ -z "$path" ] || [ ! -f "$path" ]; then
184+
mp="$(video_find_module_file "$m")" || mp=""
185+
if [ -z "$mp" ] || [ ! -f "$mp" ]; then
122186
log_warn "insmod fallback: could not locate module file for $m"
123187
return 1
124188
fi
189+
log_info "resolve: $m -> $mp"
190+
191+
case "$mp" in
192+
/lib/modules/*) staged="$mp" ;;
193+
*)
194+
staged="$(video_ensure_moddir_install "$mp" "$m")" || staged=""
195+
if [ -z "$staged" ]; then
196+
log_warn "insmod-with-deps: staging into updates/ failed for $m"
197+
return 1
198+
fi
199+
;;
200+
esac
201+
202+
if "$MODPROBE" -q "$m" 2>/dev/null; then
203+
video_log_load_success "$m" modprobe "$staged"
204+
return 0
205+
fi
206+
log_warn "modprobe failed: $m (attempting direct insmod)"
125207

126208
deps=""
127209
if video_exist_cmd modinfo; then
128-
deps="$(modinfo -F depends "$path" 2>/dev/null | tr ',' ' ' | tr -s ' ')"
210+
deps="$(modinfo -F depends "$staged" 2>/dev/null | tr ',' ' ' | tr -s ' ')"
129211
fi
130212

131213
for d in $deps; do
132-
if [ -z "$d" ]; then
133-
continue
134-
fi
214+
[ -z "$d" ] && continue
135215
if video_has_module_loaded "$d"; then
136216
continue
137217
fi
138218
if ! "$MODPROBE" -q "$d" 2>/dev/null; then
139219
dpath="$(video_find_module_file "$d")" || dpath=""
220+
if [ -z "$dpath" ] || [ ! -f "$dpath" ]; then
221+
kr="$(uname -r 2>/dev/null)"
222+
[ -z "$kr" ] && kr="$(find /lib/modules -mindepth 1 -maxdepth 1 -type d -printf '%f\n' 2>/dev/null | head -n 1)"
223+
cand="/lib/modules/$kr/updates/${d}.ko"
224+
[ -f "$cand" ] && dpath="$cand"
225+
fi
140226
if [ -n "$dpath" ] && [ -f "$dpath" ]; then
141227
if insmod "$dpath" 2>/dev/null; then
142228
video_log_load_success "$d" dep-insmod "$dpath"
143229
else
144-
log_warn "dep insmod failed for $dpath"
230+
log_warn "dep insmod failed: $d ($dpath)"
145231
fi
146232
else
147-
log_warn "dep resolve failed for $d"
233+
log_warn "dep resolve failed: $d"
148234
fi
149235
else
150236
video_log_load_success "$d" dep-modprobe
151237
fi
152238
done
153239

154-
if insmod "$path" 2>/dev/null; then
155-
video_log_load_success "$m" insmod "$path"
240+
if insmod "$staged" 2>/dev/null; then
241+
video_log_load_success "$m" insmod "$staged"
156242
return 0
157243
fi
158244

159-
log_warn "insmod failed for $path"
245+
log_warn "insmod failed for $staged"
160246
return 1
161247
}
162248

@@ -256,12 +342,12 @@ video_log_load_success() {
256342

257343
video_find_module_file() {
258344
# Resolve a module file path for a logical mod name (handles _ vs -).
259-
# Prefers: modinfo -n, then .../updates/, then general search.
345+
# Prefers: modinfo -n, then .../updates/, then general search (and KO_DIRS/KO_TREE if provided).
260346
m="$1"
261347
kr="$(uname -r 2>/dev/null)"
262348

263349
if [ -z "$kr" ]; then
264-
kr="$(find /lib/modules -mindepth 1 -maxdepth 1 -type d -printf '%f\n' 2>/dev/null | head -n1)"
350+
kr="$(find /lib/modules -mindepth 1 -maxdepth 1 -type d -printf '%f\n' 2>/dev/null | head -n 1)"
265351
fi
266352

267353
if video_exist_cmd modinfo; then
@@ -287,6 +373,7 @@ video_find_module_file() {
287373
IFS=':'
288374
for d in $KO_DIRS; do
289375
IFS="$OLD_IFS"
376+
# SC2015 fix: avoid `[ -n "$d" ] && [ -d "$d" ] || continue`
290377
if [ -z "$d" ] || [ ! -d "$d" ]; then
291378
continue
292379
fi

0 commit comments

Comments
 (0)