binman: Rename ExpandToLimit to extend_to_limit

The word 'expand' is used for entries which generate subentries. It is
also used for entries that can have an '_expanded' version which is used
to break out its contents.

Rather than talking about expanding an entry's size, use the term
'extending'. It is slightly more precise and avoids the above conflicts.

This change renders the old 'expand-size' property invalid, so add an
error check for that.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
This commit is contained in:
Simon Glass 2022-03-05 20:18:59 -07:00
parent 6d427c4bcb
commit 80a66ae646
10 changed files with 51 additions and 31 deletions

View File

@ -480,8 +480,8 @@ image-pos:
for each entry. This makes it easy to find out exactly where the entry for each entry. This makes it easy to find out exactly where the entry
ended up in the image, regardless of parent sections, etc. ended up in the image, regardless of parent sections, etc.
expand-size: extend-size:
Expand the size of this entry to fit available space. This space is only Extend the size of this entry to fit available space. This space is only
limited by the size of the image/section and the position of the next limited by the size of the image/section and the position of the next
entry. entry.

View File

@ -106,7 +106,7 @@ class Entry(object):
self.pad_after = 0 self.pad_after = 0
self.offset_unset = False self.offset_unset = False
self.image_pos = None self.image_pos = None
self.expand_size = False self.extend_size = False
self.compress = 'none' self.compress = 'none'
self.missing = False self.missing = False
self.faked = False self.faked = False
@ -235,6 +235,8 @@ class Entry(object):
""" """
if 'pos' in self._node.props: if 'pos' in self._node.props:
self.Raise("Please use 'offset' instead of 'pos'") self.Raise("Please use 'offset' instead of 'pos'")
if 'expand-size' in self._node.props:
self.Raise("Please use 'extend-size' instead of 'expand-size'")
self.offset = fdt_util.GetInt(self._node, 'offset') self.offset = fdt_util.GetInt(self._node, 'offset')
self.size = fdt_util.GetInt(self._node, 'size') self.size = fdt_util.GetInt(self._node, 'size')
self.orig_offset = fdt_util.GetInt(self._node, 'orig-offset') self.orig_offset = fdt_util.GetInt(self._node, 'orig-offset')
@ -262,7 +264,7 @@ class Entry(object):
self.align_size) self.align_size)
self.align_end = fdt_util.GetInt(self._node, 'align-end') self.align_end = fdt_util.GetInt(self._node, 'align-end')
self.offset_unset = fdt_util.GetBool(self._node, 'offset-unset') self.offset_unset = fdt_util.GetBool(self._node, 'offset-unset')
self.expand_size = fdt_util.GetBool(self._node, 'expand-size') self.extend_size = fdt_util.GetBool(self._node, 'extend-size')
self.missing_msg = fdt_util.GetString(self._node, 'missing-msg') self.missing_msg = fdt_util.GetString(self._node, 'missing-msg')
# This is only supported by blobs and sections at present # This is only supported by blobs and sections at present
@ -774,8 +776,8 @@ features to produce new behaviours.
name = '%s.%s' % (node.name, name) name = '%s.%s' % (node.name, name)
return name return name
def ExpandToLimit(self, limit): def extend_to_limit(self, limit):
"""Expand an entry so that it ends at the given offset limit""" """Extend an entry so that it ends at the given offset limit"""
if self.offset + self.size < limit: if self.offset + self.size < limit:
self.size = limit - self.offset self.size = limit - self.offset
# Request the contents again, since changing the size requires that # Request the contents again, since changing the size requires that

View File

@ -386,7 +386,7 @@ class Entry_section(Entry):
self._PackEntries() self._PackEntries()
if self._sort: if self._sort:
self._SortEntries() self._SortEntries()
self._ExpandEntries() self._extend_entries()
data = self.BuildSectionData(True) data = self.BuildSectionData(True)
self.SetContents(data) self.SetContents(data)
@ -404,17 +404,17 @@ class Entry_section(Entry):
offset = entry.Pack(offset) offset = entry.Pack(offset)
return offset return offset
def _ExpandEntries(self): def _extend_entries(self):
"""Expand any entries that are permitted to""" """Extend any entries that are permitted to"""
exp_entry = None exp_entry = None
for entry in self._entries.values(): for entry in self._entries.values():
if exp_entry: if exp_entry:
exp_entry.ExpandToLimit(entry.offset) exp_entry.extend_to_limit(entry.offset)
exp_entry = None exp_entry = None
if entry.expand_size: if entry.extend_size:
exp_entry = entry exp_entry = entry
if exp_entry: if exp_entry:
exp_entry.ExpandToLimit(self.size) exp_entry.extend_to_limit(self.size)
def _SortEntries(self): def _SortEntries(self):
"""Sort entries by offset""" """Sort entries by offset"""

View File

@ -2028,9 +2028,9 @@ class TestFunctional(unittest.TestCase):
self.assertIn("Node '/binman/files': Missing 'pattern' property", self.assertIn("Node '/binman/files': Missing 'pattern' property",
str(e.exception)) str(e.exception))
def testExpandSize(self): def testExtendSize(self):
"""Test an expanding entry""" """Test an extending entry"""
data, _, map_data, _ = self._DoReadFileDtb('088_expand_size.dts', data, _, map_data, _ = self._DoReadFileDtb('088_extend_size.dts',
map=True) map=True)
expect = (tools.get_bytes(ord('a'), 8) + U_BOOT_DATA + expect = (tools.get_bytes(ord('a'), 8) + U_BOOT_DATA +
MRC_DATA + tools.get_bytes(ord('b'), 1) + U_BOOT_DATA + MRC_DATA + tools.get_bytes(ord('b'), 1) + U_BOOT_DATA +
@ -2050,11 +2050,11 @@ class TestFunctional(unittest.TestCase):
00000020 00000020 00000008 fill2 00000020 00000020 00000008 fill2
''', map_data) ''', map_data)
def testExpandSizeBad(self): def testExtendSizeBad(self):
"""Test an expanding entry which fails to provide contents""" """Test an extending entry which fails to provide contents"""
with test_util.capture_sys_output() as (stdout, stderr): with test_util.capture_sys_output() as (stdout, stderr):
with self.assertRaises(ValueError) as e: with self.assertRaises(ValueError) as e:
self._DoReadFileDtb('089_expand_size_bad.dts', map=True) self._DoReadFileDtb('089_extend_size_bad.dts', map=True)
self.assertIn("Node '/binman/_testing': Cannot obtain contents when " self.assertIn("Node '/binman/_testing': Cannot obtain contents when "
'expanding entry', str(e.exception)) 'expanding entry', str(e.exception))
@ -2487,22 +2487,22 @@ class TestFunctional(unittest.TestCase):
str(e.exception)) str(e.exception))
def testEntryExpand(self): def testEntryExpand(self):
"""Test expanding an entry after it is packed""" """Test extending an entry after it is packed"""
data = self._DoReadFile('121_entry_expand.dts') data = self._DoReadFile('121_entry_extend.dts')
self.assertEqual(b'aaa', data[:3]) self.assertEqual(b'aaa', data[:3])
self.assertEqual(U_BOOT_DATA, data[3:3 + len(U_BOOT_DATA)]) self.assertEqual(U_BOOT_DATA, data[3:3 + len(U_BOOT_DATA)])
self.assertEqual(b'aaa', data[-3:]) self.assertEqual(b'aaa', data[-3:])
def testEntryExpandBad(self): def testEntryExtendBad(self):
"""Test expanding an entry after it is packed, twice""" """Test extending an entry after it is packed, twice"""
with self.assertRaises(ValueError) as e: with self.assertRaises(ValueError) as e:
self._DoReadFile('122_entry_expand_twice.dts') self._DoReadFile('122_entry_extend_twice.dts')
self.assertIn("Image '/binman': Entries changed size after packing", self.assertIn("Image '/binman': Entries changed size after packing",
str(e.exception)) str(e.exception))
def testEntryExpandSection(self): def testEntryExtendSection(self):
"""Test expanding an entry within a section after it is packed""" """Test extending an entry within a section after it is packed"""
data = self._DoReadFile('123_entry_expand_section.dts') data = self._DoReadFile('123_entry_extend_section.dts')
self.assertEqual(b'aaa', data[:3]) self.assertEqual(b'aaa', data[:3])
self.assertEqual(U_BOOT_DATA, data[3:3 + len(U_BOOT_DATA)]) self.assertEqual(U_BOOT_DATA, data[3:3 + len(U_BOOT_DATA)])
self.assertEqual(b'aaa', data[-3:]) self.assertEqual(b'aaa', data[-3:])
@ -5305,6 +5305,14 @@ fdt fdtmap Extract the devicetree blob from the fdtmap
self.assertIn("Node '/binman/fit': Unknown operation 'unknown'", self.assertIn("Node '/binman/fit': Unknown operation 'unknown'",
str(exc.exception)) str(exc.exception))
def test_uses_expand_size(self):
"""Test that the 'expand-size' property cannot be used anymore"""
with self.assertRaises(ValueError) as e:
data = self._DoReadFile('225_expand_size_bad.dts')
self.assertIn(
"Node '/binman/u-boot': Please use 'extend-size' instead of 'expand-size'",
str(e.exception))
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()

View File

@ -5,7 +5,7 @@
binman { binman {
size = <40>; size = <40>;
fill { fill {
expand-size; extend-size;
fill-byte = [61]; fill-byte = [61];
size = <0>; size = <0>;
}; };
@ -13,7 +13,7 @@
offset = <8>; offset = <8>;
}; };
section { section {
expand-size; extend-size;
pad-byte = <0x62>; pad-byte = <0x62>;
intel-mrc { intel-mrc {
}; };
@ -25,7 +25,7 @@
section2 { section2 {
type = "section"; type = "section";
fill { fill {
expand-size; extend-size;
fill-byte = [63]; fill-byte = [63];
size = <0>; size = <0>;
}; };
@ -35,7 +35,7 @@
}; };
fill2 { fill2 {
type = "fill"; type = "fill";
expand-size; extend-size;
fill-byte = [64]; fill-byte = [64];
size = <0>; size = <0>;
}; };

View File

@ -4,7 +4,7 @@
/ { / {
binman { binman {
_testing { _testing {
expand-size; extend-size;
return-contents-once; return-contents-once;
}; };
u-boot { u-boot {

View File

@ -0,0 +1,10 @@
// SPDX-License-Identifier: GPL-2.0+
/dts-v1/;
/ {
binman {
u-boot {
expand-size;
};
};
};