@@ -249,9 +249,9 @@ def parse_rpu_sys_fw_stats(self, blob_data: bytes, endianness: str = '<'):
249249 logging .debug (f" Match: { '✓' if total_expected == len (blob_data ) else '✗' } " )
250250
251251def main ():
252- parser = argparse .ArgumentParser (description = 'Parse rpu_sys_fw_stats from hex blob using header file' )
252+ parser = argparse .ArgumentParser (description = 'Parse rpu_sys_fw_stats from hex blob or binary file using header file' )
253253 parser .add_argument ('header_file' , help = 'Path to header file containing struct definitions' )
254- parser .add_argument ('hex_blob' , help = 'Hex blob data to parse ' )
254+ parser .add_argument ('hex_blob' , help = 'Hex blob data string or path to binary file ' )
255255 parser .add_argument ('-d' , '--debug' , action = 'store_true' , help = 'Enable debug output' )
256256
257257 args = parser .parse_args ()
@@ -266,8 +266,25 @@ def main():
266266 print (f"Error: Header file '{ args .header_file } ' not found" )
267267 sys .exit (1 )
268268
269- # Convert hex string to binary
270- blob_data = bytes .fromhex (args .hex_blob .replace (' ' , '' ))
269+ # Check if blob is a file
270+ if os .path .isfile (args .blob ):
271+ try :
272+ with open (args .blob , 'rb' ) as f :
273+ blob_data = f .read ()
274+ logging .debug (f"Read { len (blob_data )} bytes from file '{ args .blob } '" )
275+ except Exception as e :
276+ print (f"Error reading file '{ args .blob } ': { e } " )
277+ sys .exit (1 )
278+ else :
279+ # Assume it's a hex string
280+ try :
281+ # Remove potential whitespace and 0x prefix
282+ clean_hex = args .blob .replace (' ' , '' ).replace ('0x' , '' ).replace ('\n ' , '' )
283+ blob_data = bytes .fromhex (clean_hex )
284+ logging .debug (f"Parsed { len (blob_data )} bytes from hex string" )
285+ except ValueError :
286+ print (f"Error: Argument '{ args .blob } ' is neither a valid file path nor a valid hex string." )
287+ sys .exit (1 )
271288
272289 # Parse using header file
273290 struct_parser = StructParser (args .header_file , debug = args .debug )
0 commit comments