From e6e8f5de6bc132e8fe38782841d1b7993e9ae0af Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Thu, 10 Feb 2022 17:48:20 -0800 Subject: [PATCH] soc/intel_adsp: cavstool: log out of bounds mmap offsets The winstream can become corrupted when the firmware hasn't booted or is in the bad state. Signed-off-by: Marc Herbert --- soc/xtensa/intel_adsp/tools/cavstool.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/soc/xtensa/intel_adsp/tools/cavstool.py b/soc/xtensa/intel_adsp/tools/cavstool.py index 46cf27031fe..795176c0ad7 100755 --- a/soc/xtensa/intel_adsp/tools/cavstool.py +++ b/soc/xtensa/intel_adsp/tools/cavstool.py @@ -276,8 +276,14 @@ def load_firmware(fw_file): # array seems to be unreliable on one of my machines (python 3.6.9 on # Ubuntu 18.04). Read out bytes individually. def win_read(start, length): - return b''.join(bar4_mmap[x + WINSTREAM_OFFSET].to_bytes(1, 'little') - for x in range(start, start + length)) + try: + return b''.join(bar4_mmap[WINSTREAM_OFFSET + x].to_bytes(1, 'little') + for x in range(start, start + length)) + except IndexError as ie: + # A FW in a bad state may cause winstream garbage + log.error("IndexError in bar4_mmap[%d + %d]", WINSTREAM_OFFSET, start) + log.error("bar4_mmap.size()=%d", bar4_mmap.size()) + raise ie def win_hdr(): return struct.unpack("