@@ -26,6 +26,12 @@ VENUS_ENC_MOD="venus_enc"
2626# Session-only blocks live under /run/modprobe.d
2727RUNTIME_BLOCK_DIR=" /run/modprobe.d"
2828
29+ # Optional custom module sources (set by run.sh only when user opts in)
30+ # NOTE: Leaving these unset keeps the exact existing behavior.
31+ KO_DIRS=" ${KO_DIRS:- } " # colon-separated dirs containing .ko files
32+ KO_TREE=" ${KO_TREE:- } " # alt root containing lib/modules/$(uname -r)
33+ KO_PREFER_CUSTOM=" ${KO_PREFER_CUSTOM:- 0} " # 1 = prefer KO_DIRS before system tree
34+
2935# Firmware path for Kodiak downstream blob
3036FW_PATH_KODIAK=" /lib/firmware/qcom/vpu/vpu20_p1_gen2.mbn"
3137: " ${FW_BACKUP_DIR:=/ opt} "
@@ -132,12 +138,21 @@ video_insmod_with_deps() {
132138 if ! " $MODPROBE " -q " $d " 2> /dev/null; then
133139 dpath=" $( video_find_module_file " $d " ) " || dpath=" "
134140 if [ -n " $dpath " ] && [ -f " $dpath " ]; then
135- insmod " $dpath " 2> /dev/null || true
141+ if insmod " $dpath " 2> /dev/null; then
142+ video_log_load_success " $d " dep-insmod " $dpath "
143+ else
144+ log_warn " dep insmod failed for $dpath "
145+ fi
146+ else
147+ log_warn " dep resolve failed for $d "
136148 fi
149+ else
150+ video_log_load_success " $d " dep-modprobe
137151 fi
138152 done
139153
140154 if insmod " $path " 2> /dev/null; then
155+ video_log_load_success " $m " insmod " $path "
141156 return 0
142157 fi
143158
@@ -171,6 +186,9 @@ video_list_runtime_blocks() {
171186 fi
172187}
173188
189+ # -------------------------------------------------------------------------
190+ # Path resolution & load logging helpers
191+ # -------------------------------------------------------------------------
174192video_dump_stack_state () {
175193 when=" $1 " # pre|post
176194
@@ -188,44 +206,149 @@ video_dump_stack_state() {
188206 video_list_runtime_blocks
189207}
190208
209+ video_log_resolve () {
210+ # usage: video_log_resolve <module> <how> <path>
211+ # how: modinfo | system-tree | updates-tree | altroot-tree | ko-dir
212+ m=" $1 " ; how=" $2 " ; p=" $3 "
213+ case " $how " in
214+ modinfo)
215+ log_info " resolve-path: $m via modinfo -n => $p "
216+ ;;
217+ system-tree)
218+ log_info " resolve-path: $m via /lib/modules => $p "
219+ ;;
220+ updates-tree)
221+ log_info " resolve-path: $m via /lib/modules/*/updates => $p "
222+ ;;
223+ altroot-tree)
224+ log_info " resolve-path: $m via KO_TREE => $p "
225+ ;;
226+ ko-dir)
227+ log_info " resolve-path: $m via KO_DIRS => $p "
228+ ;;
229+ esac
230+ }
231+
232+ video_log_load_success () {
233+ # usage: video_log_load_success <module> <how> [extra]
234+ # how: modprobe-system | modprobe-altroot | insmod | dep-modprobe | dep-insmod
235+ m=" $1 " ; how=" $2 " ; extra=" $3 "
236+ case " $how " in
237+ modprobe-system)
238+ log_info " load-path: modprobe(system): $m "
239+ ;;
240+ modprobe-altroot)
241+ log_info " load-path: modprobe(altroot=$KO_TREE ): $m "
242+ ;;
243+ insmod)
244+ # extra = path
245+ log_info " load-path: insmod: $extra "
246+ ;;
247+ dep-modprobe)
248+ log_info " load-path(dep): modprobe(system): $m "
249+ ;;
250+ dep-insmod)
251+ # extra = path
252+ log_info " load-path(dep): insmod: $extra "
253+ ;;
254+ esac
255+ }
256+
191257video_find_module_file () {
192258 # Resolve a module file path for a logical mod name (handles _ vs -).
193259 # Prefers: modinfo -n, then .../updates/, then general search.
194260 m=" $1 "
195261 kr=" $( uname -r 2> /dev/null) "
196-
262+
197263 if [ -z " $kr " ]; then
198264 kr=" $( find /lib/modules -mindepth 1 -maxdepth 1 -type d -printf ' %f\n' 2> /dev/null | head -n1) "
199265 fi
200-
266+
201267 if video_exist_cmd modinfo; then
202268 p=" $( modinfo -n " $m " 2> /dev/null) "
203269 if [ -n " $p " ] && [ -f " $p " ]; then
270+ video_log_resolve " $m " modinfo " $p "
204271 printf ' %s\n' " $p "
205272 return 0
206273 fi
207274 fi
208-
275+
209276 m_us=" $m "
210277 m_hy=" $( printf ' %s' " $m " | tr ' _' ' -' ) "
211278 m_alt=" $( printf ' %s' " $m " | tr ' -' ' _' ) "
212-
279+
280+ # Helper to scan KO_DIRS (bounded search)
281+ scan_ko_dirs () {
282+ modbase=" $1 " # without .ko*
283+ if [ -z " $KO_DIRS " ]; then
284+ return 1
285+ fi
286+ OLD_IFS=" $IFS "
287+ IFS=' :'
288+ for d in $KO_DIRS ; do
289+ IFS=" $OLD_IFS "
290+ if [ -z " $d " ] || [ ! -d " $d " ]; then
291+ continue
292+ fi
293+ p=" $( find " $d " -maxdepth 3 -type f -name " ${modbase} .ko*" -print -quit 2> /dev/null) "
294+ if [ -n " $p " ]; then
295+ video_log_resolve " $m " ko-dir " $p "
296+ printf ' %s\n' " $p "
297+ return 0
298+ fi
299+ done
300+ IFS=" $OLD_IFS "
301+ return 1
302+ }
303+
304+ # Optional order: prefer KO_DIRS first if requested
305+ if [ " $KO_PREFER_CUSTOM " -eq 1 ] 2> /dev/null; then
306+ for pat in " $m_us " " $m_hy " " $m_alt " ; do
307+ if scan_ko_dirs " $pat " ; then
308+ return 0
309+ fi
310+ done
311+ fi
312+
313+ # Optional altroot tree (KO_TREE) first, if provided
314+ if [ -n " $KO_TREE " ] && [ -d " $KO_TREE " ]; then
315+ for pat in " $m_us " " $m_hy " " $m_alt " ; do
316+ p=" $( find " $KO_TREE /lib/modules/$kr " -type f -name " ${pat} .ko*" -print -quit 2> /dev/null) "
317+ if [ -n " $p " ]; then
318+ video_log_resolve " $m " altroot-tree " $p "
319+ printf ' %s\n' " $p "
320+ return 0
321+ fi
322+ done
323+ fi
324+
213325 for pat in " $m_us " " $m_hy " " $m_alt " ; do
214326 p=" $( find " /lib/modules/$kr /updates" -type f -name " ${pat} .ko*" 2> /dev/null | head -n 1) "
215327 if [ -n " $p " ]; then
328+ video_log_resolve " $m " updates-tree " $p "
216329 printf ' %s\n' " $p "
217330 return 0
218331 fi
219332 done
220-
333+
221334 for pat in " $m_us " " $m_hy " " $m_alt " ; do
222335 p=" $( find " /lib/modules/$kr " -type f -name " ${pat} .ko*" 2> /dev/null | head -n 1) "
223336 if [ -n " $p " ]; then
337+ video_log_resolve " $m " system-tree " $p "
224338 printf ' %s\n' " $p "
225339 return 0
226340 fi
227341 done
228-
342+
343+ # If not preferred-first, still try KO_DIRS at the end
344+ if [ " $KO_PREFER_CUSTOM " -ne 1 ] 2> /dev/null; then
345+ for pat in " $m_us " " $m_hy " " $m_alt " ; do
346+ if scan_ko_dirs " $pat " ; then
347+ return 0
348+ fi
349+ done
350+ fi
351+
229352 return 1
230353}
231354
@@ -359,16 +482,24 @@ video_retry_modprobe() {
359482
360483 while [ " $i " -lt " $n " ]; do
361484 i=$(( i+ 1 ))
362- log_info " modprobe attempt $i /$n : $m "
363485
364486 if video_has_module_loaded " $m " ; then
365487 log_info " module became present before attempt $i : $m "
366488 return 0
367489 fi
368490
369- if " $MODPROBE " " $m " 2> /dev/null; then
370- log_info " modprobe succeeded on attempt $i : $m "
371- return 0
491+ if [ -n " $KO_TREE " ] && [ -d " $KO_TREE " ]; then
492+ log_info " modprobe attempt $i /$n (altroot=$KO_TREE ): $m "
493+ if " $MODPROBE " -d " $KO_TREE " " $m " 2> /dev/null; then
494+ video_log_load_success " $m " modprobe-altroot
495+ return 0
496+ fi
497+ else
498+ log_info " modprobe attempt $i /$n (system): $m "
499+ if " $MODPROBE " " $m " 2> /dev/null; then
500+ video_log_load_success " $m " modprobe-system
501+ return 0
502+ fi
372503 fi
373504
374505 video_usleep " ${MOD_RETRY_SLEEP} "
@@ -602,8 +733,8 @@ video_stack_status() {
602733 case " $plat " in
603734 lemans|monaco)
604735 # Upstream accepted if:
605- # - pure upstream build: qcom_iris present and iris_vpu absent
606- # - base+overlay build: qcom_iris and iris_vpu both present
736+ # - pure upstream build: qcom_iris present and iris_vpu absent
737+ # - base+overlay build: qcom_iris and iris_vpu both present
607738 if video_has_module_loaded qcom_iris && ! video_has_module_loaded iris_vpu; then
608739 printf ' %s\n' " upstream"
609740 return 0
@@ -623,8 +754,8 @@ video_stack_status() {
623754
624755 kodiak)
625756 # Upstream accepted if:
626- # - Venus trio present (canonical upstream on Kodiak), OR
627- # - pure upstream build: qcom_iris present and iris_vpu absent
757+ # - Venus trio present (canonical upstream on Kodiak), OR
758+ # - pure upstream build: qcom_iris present and iris_vpu absent
628759 if video_has_module_loaded venus_core && video_has_module_loaded venus_dec && video_has_module_loaded venus_enc; then
629760 printf ' %s\n' " upstream"
630761 return 0
@@ -787,7 +918,7 @@ video_hot_switch_modules() {
787918# Entry point: ensure desired stack
788919# -----------------------------------------------------------------------------
789920video_ensure_stack () {
790- want_raw=" $1 " # upstream|downstream|auto|base|overlay|up|down
921+ want_raw=" $1 " # upstream|downstream|auto|base|overlay|up|down
791922 plat=" $2 "
792923
793924 if [ -z " $plat " ]; then
@@ -814,9 +945,9 @@ video_ensure_stack() {
814945 # ----------------------------------------------------------------------
815946 # Early no-op: if current state already equals desired, do NOT hot switch.
816947 # This covers:
817- # - Build #1 (pure upstream: qcom_iris only) on lemans/monaco/kodiak
818- # - Build #2 (base+overlay: qcom_iris + iris_vpu) when upstream is requested
819- # - Downstream already active (e.g., iris_vpu only on lemans/monaco, or kodiak downstream)
948+ # - Build #1 (pure upstream: qcom_iris only) on lemans/monaco/kodiak
949+ # - Build #2 (base+overlay: qcom_iris + iris_vpu) when upstream is requested
950+ # - Downstream already active (e.g., iris_vpu only on lemans/monaco, or kodiak downstream)
820951 # Still allow Kodiak downstream FW swap without touching modules.
821952 # ----------------------------------------------------------------------
822953 cur_state=" $( video_stack_status " $plat " ) "
0 commit comments