spsdk icon indicating copy to clipboard operation
spsdk copied to clipboard

not helpful: spsdk.image.header.CorruptedException: Failed to parse command at position: 0x2c

Open saper opened this issue 4 years ago • 1 comments

While trying to read some imx image I get an exception:

Traceback (most recent call last):
  File "/tmp/spsdk/spsdk/image/commands.py", line 1362, in parse_command
    cmdtag = CmdTag.from_int(data[offset])
  File "/tmp/spsdk/spsdk/utils/easy_enum.py", line 158, in from_int
    raise ValueError(f'the following integer value is not defined within the enumeration: {str(value)}')
ValueError: the following integer value is not defined within the enumeration: 0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/tmp/spsdk/spsdk/image/segments.py", line 1162, in parse
    cmd_obj = parse_command(data, offset + index)
  File "/tmp/spsdk/spsdk/image/commands.py", line 1364, in parse_command
    raise ValueError("Unknown command at position: " + hex(offset))
ValueError: Unknown command at position: 0x2c

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/spsdk/spsdk/image/images.py", line 2232, in parse
    return BootImg2.parse(stream)
  File "/tmp/spsdk/spsdk/image/images.py", line 1036, in parse
    obj.csf = SegCSF.parse(read_raw_segment(stream, SegTag.CSF, csf_start))
  File "/tmp/spsdk/spsdk/image/segments.py", line 1165, in parse
    raise CorruptedException("Failed to parse command at position: " + hex(offset + index))
spsdk.image.header.CorruptedException: Failed to parse command at position: 0x2c

Regardless of the root cause of the exception, I think that Failed to parse command at position: 0x2c is unhelpful - csf_start is 0x50c00 in this particular image, but the error message does not show this.

Adding csf_start as an additional parameter to SegCSF.parse() does not help, either (it tries to seek beyond the file).

Any idea how to get offsets "right" in the exception messages?

(first post, and thanks for putting that up online!)

saper avatar Sep 03 '20 19:09 saper

Hello Saper, many thanks for submitting the issue. The problem with passing "csf_start" is the "read_raw_segment" which pre-parses the data, and the "parse" function gets the data without a need to any offset, (And as you correctly mentioned, adding offset may cause the "parse" function to go beyond the image file end.) How I see it, it would be possible to bypass the read_raw_segment and put necessary logic into the "parse" function. Those two functions are doing very similar stuff anyway, so I don't see any major problem with that. Could you please send me a sample image file you used? I assume you used the same i.MX 6/7 image as in issue #5 As i.MX application processors are not officially supported as of right now, I don't have much sample data right now. And having the sample image would allow me to kill two birds with one stone :) Many Thanks

mstarecek avatar Sep 07 '20 09:09 mstarecek