soc/intel_adsp: cavstool: minor error handling fixes

Don't "crash" when passing no argument at all.

Log exceptions, adding for instance the second line:

ERROR:cavs-fw:Could not map device in sysfs; run as root?
ERROR:cavs-fw:[Errno 13] Permission denied: \
             '/sys/bus/pci/devices/0000:00:0e.0/power/control'

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
This commit is contained in:
Marc Herbert 2022-01-25 22:52:50 -08:00 committed by Anas Nashif
commit 40b38d5e48

View file

@ -173,8 +173,9 @@ def runx(cmd):
def load_firmware(fw_file):
try:
fw_bytes = open(fw_file, "rb").read()
except Exception:
except Exception as e:
log.error(f"Could not read firmware file: `{fw_file}'")
log.error(e)
sys.exit(1)
(magic, sz) = struct.unpack("4sI", fw_bytes[0:8])
@ -302,13 +303,18 @@ async def main():
global hda, sd, dsp, hda_ostream_id
try:
(hda, sd, dsp, hda_ostream_id) = map_regs()
except Exception:
log.error("Could not map device in sysfs; run as root.")
except Exception as e:
log.error("Could not map device in sysfs; run as root?")
log.error(e)
sys.exit(1)
log.info(f"Detected cAVS {'1.5' if cavs15 else '1.8+'} hardware")
if not args.log_only:
if not args.fw_file:
log.error("Firmware file argument missing")
sys.exit(1)
load_firmware(args.fw_file)
time.sleep(0.1)
if not args.quiet: