22# SPDX-License-Identifier: MIT
33# Copyright (c) 2024-2025 Linaro Ltd.
44
5- import os , re , sys
5+ import os , re , sys , yaml
66
77def empty_data ():
88 return {'dirs' : {}}
@@ -175,6 +175,60 @@ def list_git():
175175 if git .close ():
176176 sys .stderr .write ("WHENCE: skipped contents validation, git file listing failed\n " )
177177
178+ def load_machine_dsp_paths ():
179+ """Load and parse 00-hexagon-dsp-binaries.yaml to get valid DSP library paths."""
180+ try :
181+ with open ("00-hexagon-dsp-binaries.yaml" , encoding = "utf-8" ) as file :
182+ data = yaml .safe_load (file )
183+ if not data or 'machines' not in data :
184+ return set ()
185+
186+ # Extract base paths (without /dsp suffix) from DSP_LIBRARY_PATH
187+ paths = set ()
188+ for machine_name , machine_data in data ['machines' ].items ():
189+ if 'DSP_LIBRARY_PATH' in machine_data :
190+ dsp_path = machine_data ['DSP_LIBRARY_PATH' ]
191+ # Remove /dsp suffix to get base path
192+ if dsp_path .endswith ('/dsp' ):
193+ base_path = dsp_path [:- 4 ]
194+ paths .add (base_path )
195+ return paths
196+ except FileNotFoundError :
197+ sys .stderr .write ("Warning: 00-hexagon-dsp-binaries.yaml not found, skipping path consistency check\n " )
198+ return None
199+ except Exception as e :
200+ sys .stderr .write ("Error loading 00-hexagon-dsp-binaries.yaml: %s\n " % e )
201+ return None
202+
203+ def check_config_against_machine_paths (config_data , machine_paths ):
204+ """Check that config.txt paths are consistent with 00-hexagon-dsp-binaries.yaml."""
205+ if machine_paths is None :
206+ return True
207+
208+ ret = True
209+ reported_paths = set () # Track paths we've already reported as missing
210+
211+ for data in config_data :
212+ if data [0 ] == "install" :
213+ (lineno , path , dsp , subdir ) = data [1 :]
214+ if path not in machine_paths and path not in reported_paths :
215+ sys .stderr .write ("config.txt: %d: Install path '%s' not found in 00-hexagon-dsp-binaries.yaml\n " % (lineno , path ))
216+ reported_paths .add (path )
217+ ret = False
218+ elif data [0 ] == "link" :
219+ (lineno , src_path , dst_path ) = data [1 :]
220+ # Extract base path from link target (dst_path)
221+ # Link format: path/to/device/dsp/dsptype
222+ parts = dst_path .split ('/' )
223+ if len (parts ) >= 2 and parts [- 2 ] == 'dsp' :
224+ base_path = '/' .join (parts [:- 2 ])
225+ if base_path not in machine_paths and base_path not in reported_paths :
226+ sys .stderr .write ("config.txt: %d: Link target base path '%s' not found in 00-hexagon-dsp-binaries.yaml\n " % (lineno , base_path ))
227+ reported_paths .add (base_path )
228+ ret = False
229+
230+ return ret
231+
178232def check_dir (subdir ):
179233 pattern_shell = re .compile ("^fastrpc_shell(_unsigned)?_[0-9]$" )
180234 pattern_library = re .compile ("^[-_+0-9a-zA-Z]*\\ .so(\\ .[0-9]*)?$" )
@@ -212,7 +266,7 @@ def main():
212266 if 'licence' in data :
213267 licences [data ['licence' ][0 ]] = None
214268
215- known_files = ['config.txt' , 'Makefile' , 'TODO' , 'README.md' , 'WHENCE' ]
269+ known_files = ['config.txt' , 'Makefile' , 'TODO' , 'README.md' , 'WHENCE' , '00-hexagon-dsp-binaries.yaml' ]
216270
217271 for file in list_git ():
218272 if os .path .dirname (file ) in dirs :
@@ -233,15 +287,25 @@ def main():
233287 sys .stderr .write ("WHENCE: file %s is not under a listed directory\n " % file )
234288 okay = False
235289
290+ # Load 00-hexagon-dsp-binaries.yaml for consistency checking
291+ machine_paths = load_machine_dsp_paths ()
292+
293+ # Collect config data for consistency check
294+ config_data = []
236295 try :
237296 for data in load_config ():
297+ config_data .append (data )
238298 if not check_config (data , dirs ):
239299 okay = False
240300
241301 except Exception as e :
242302 sys .stderr .write ("%s\n " % e )
243303 okay = False
244304
305+ # Check config.txt paths against 00-hexagon-dsp-binaries.yaml
306+ if not check_config_against_machine_paths (config_data , machine_paths ):
307+ okay = False
308+
245309 for entry in dirs .keys ():
246310 if not check_dir (entry ):
247311 sys .stderr .write ("WHENCE: subdir %s failed the checks\n " % entry )
0 commit comments