diff options
author | Simon Glass | 2021-01-06 21:35:19 -0700 |
---|---|---|
committer | Simon Glass | 2021-01-30 14:25:41 -0700 |
commit | 5c6ba71bbe1285cfd323574dca88b8484a38aecd (patch) | |
tree | 89ce129ceb7af90ef1e7a721c3333f5eb482f24e | |
parent | 6eb9932668fa6bd8c659484b2d18d8a73713208c (diff) |
binman: Allow for skip_at_start when reading entries
The offset of an entry needs to be adjusted by its skip-at-start value.
This is currently missing when reading entry data. Fix it.
Signed-off-by: Simon Glass <sjg@chromium.org>
-rw-r--r-- | tools/binman/etype/section.py | 10 | ||||
-rw-r--r-- | tools/binman/ftest.py | 19 | ||||
-rw-r--r-- | tools/binman/test/191_read_image_skip.dts | 23 |
3 files changed, 48 insertions, 4 deletions
diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py index 28a888776af..1ceadef13f3 100644 --- a/tools/binman/etype/section.py +++ b/tools/binman/etype/section.py @@ -605,10 +605,12 @@ class Entry_section(Entry): def ReadData(self, decomp=True): tout.Info("ReadData path='%s'" % self.GetPath()) parent_data = self.section.ReadData(True) - tout.Info('%s: Reading data from offset %#x-%#x, size %#x' % - (self.GetPath(), self.offset, self.offset + self.size, - self.size)) - data = parent_data[self.offset:self.offset + self.size] + offset = self.offset - self.section._skip_at_start + data = parent_data[offset:offset + self.size] + tout.Info( + '%s: Reading data from offset %#x-%#x (real %#x), size %#x, got %#x' % + (self.GetPath(), self.offset, self.offset + self.size, offset, + self.size, len(data))) return data def ReadChildData(self, child, decomp=True): diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index b31a7305a33..814e91d42e9 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -4226,6 +4226,25 @@ class TestFunctional(unittest.TestCase): expect = FILES_DATA[:15] + b'\0' + FILES_DATA[15:] self.assertEqual(expect, data) + def testReadImageSkip(self): + """Test reading an image and accessing its FDT map""" + data = self.data = self._DoReadFileRealDtb('191_read_image_skip.dts') + image_fname = tools.GetOutputFilename('image.bin') + orig_image = control.images['image'] + image = Image.FromFile(image_fname) + self.assertEqual(orig_image.GetEntries().keys(), + image.GetEntries().keys()) + + orig_entry = orig_image.GetEntries()['fdtmap'] + entry = image.GetEntries()['fdtmap'] + self.assertEqual(orig_entry.offset, entry.offset) + self.assertEqual(orig_entry.size, entry.size) + self.assertEqual(16, entry.image_pos) + + u_boot = image.GetEntries()['section'].GetEntries()['u-boot'] + + self.assertEquals(U_BOOT_DATA, u_boot.ReadData()) + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/test/191_read_image_skip.dts b/tools/binman/test/191_read_image_skip.dts new file mode 100644 index 00000000000..31df518fae6 --- /dev/null +++ b/tools/binman/test/191_read_image_skip.dts @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + end-at-4gb; + size = <0x400>; + section { + size = <0x10>; + u-boot { + }; + }; + fdtmap { + }; + image-header { + location = "end"; + }; + }; +}; |