Skip to content

Commit 2c252d3

Browse files
sjg20trini
authored andcommitted
binman: Honour the skip-at-start property more faithfully
A discussion on the mailing list about dealing with block offsets and binman symbols made me think that something is wrong with how Binman deals with the skip-at-start property. The feature was originally designed to handle x86 ROMs, which are mapped at the top of the address space. That seemed too specific, whereas skipping some space at the start seemed more generally useful. It has proved useful. For example, rockchip images start at block 64, so a skip-at-start of 0x8000 deals with this. But it doesn't actually work correctly, since the image_pos value does not give the actual position on the media. Fix this and update the documentation, moving it into the 'section' section. Signed-off-by: Simon Glass <[email protected]>
1 parent 91fa9d9 commit 2c252d3

File tree

5 files changed

+46
-36
lines changed

5 files changed

+46
-36
lines changed

tools/binman/binman.rst

+29-18
Original file line numberDiff line numberDiff line change
@@ -823,24 +823,6 @@ multiple-images:
823823
};
824824
};
825825

826-
end-at-4gb:
827-
For x86 machines the ROM offsets start just before 4GB and extend
828-
up so that the image finished at the 4GB boundary. This boolean
829-
option can be enabled to support this. The image size must be
830-
provided so that binman knows when the image should start. For an
831-
8MB ROM, the offset of the first entry would be 0xfff80000 with
832-
this option, instead of 0 without this option.
833-
834-
skip-at-start:
835-
This property specifies the entry offset of the first entry.
836-
837-
For PowerPC mpc85xx based CPU, CONFIG_TEXT_BASE is the entry
838-
offset of the first entry. It can be 0xeff40000 or 0xfff40000 for
839-
nor flash boot, 0x201000 for sd boot etc.
840-
841-
'end-at-4gb' property is not applicable where CONFIG_TEXT_BASE +
842-
Image size != 4gb.
843-
844826
align-default:
845827
Specifies the default alignment for entries in this section if they do
846828
not specify an alignment. Note that this only applies to top-level entries
@@ -957,6 +939,35 @@ filename:
957939
section in different image, since there is currently no way to share data
958940
between images other than through files.
959941

942+
end-at-4gb:
943+
For x86 machines the ROM offsets start just before 4GB and extend
944+
up so that the image finished at the 4GB boundary. This boolean
945+
option can be enabled to support this. The image size must be
946+
provided so that binman knows when the image should start. For an
947+
8MB ROM, the offset of the first entry would be 0xfff80000 with
948+
this option, instead of 0 without this option.
949+
950+
skip-at-start:
951+
This property specifies the entry offset of the first entry in the section.
952+
It is useful when the Binman image is written to a particular offset in the
953+
media. It allows the offset of the first entry to be the media offset, even
954+
though it is at the start of the image. It effectively creates a hole at the
955+
start of the image, an implied, empty area.
956+
957+
For example, if the image is written to offset 4K on the media, set
958+
skip-at-start to 0x1000. At runtime, the Binman image will assume that it
959+
has be written at offset 4K and all symbols and offsets will take account of
960+
that. The image-pos values will also be adjusted. The effect is similar to
961+
adding an empty 4K region at the start, except that Binman does not actually
962+
output it.
963+
964+
For PowerPC mpc85xx based CPU, CONFIG_TEXT_BASE is the entry
965+
offset of the first entry. It can be 0xeff40000 or 0xfff40000 for
966+
nor flash boot, 0x201000 for sd boot etc.
967+
968+
'end-at-4gb' property is not applicable where CONFIG_TEXT_BASE +
969+
Image size != 4gb.
970+
960971
Image Properties
961972
----------------
962973

tools/binman/entry.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,8 @@ def SetCalculatedProperties(self):
392392
"""Set the value of device-tree properties calculated by binman"""
393393
state.SetInt(self._node, 'offset', self.offset)
394394
state.SetInt(self._node, 'size', self.size)
395-
base = self.section.GetRootSkipAtStart() if self.section else 0
396395
if self.image_pos is not None:
397-
state.SetInt(self._node, 'image-pos', self.image_pos - base)
396+
state.SetInt(self._node, 'image-pos', self.image_pos)
398397
if self.GetImage().allow_repack:
399398
if self.orig_offset is not None:
400399
state.SetInt(self._node, 'orig-offset', self.orig_offset, True)

tools/binman/etype/fmap.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def _AddEntries(areas, entry):
6565
if entry.image_pos is None:
6666
pos = 0
6767
else:
68-
pos = entry.image_pos - entry.GetRootSkipAtStart()
68+
pos = entry.image_pos
6969

7070
# Drop @ symbols in name
7171
name = entry.name.replace('@', '')
@@ -75,8 +75,6 @@ def _AddEntries(areas, entry):
7575
_AddEntries(areas, subentry)
7676
else:
7777
pos = entry.image_pos
78-
if pos is not None:
79-
pos -= entry.section.GetRootSkipAtStart()
8078
areas.append(fmap_util.FmapArea(pos or 0, entry.size or 0,
8179
entry.name, flags))
8280

tools/binman/etype/section.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ def _SetEntryOffsetSize(self, name, offset, size):
801801
if not entry:
802802
self._Raise("Unable to set offset/size for unknown entry '%s'" %
803803
name)
804-
entry.SetOffsetSize(self._skip_at_start + offset if offset is not None
804+
entry.SetOffsetSize(offset + self._skip_at_start if offset is not None
805805
else None, size)
806806

807807
def GetEntryOffsets(self):

tools/binman/ftest.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -2297,16 +2297,17 @@ def testFmapX86(self):
22972297
fhdr, fentries = fmap_util.DecodeFmap(data[32:])
22982298

22992299
self.assertEqual(0x100, fhdr.image_size)
2300+
base = (1 << 32) - 0x100
23002301

2301-
self.assertEqual(0, fentries[0].offset)
2302+
self.assertEqual(base, fentries[0].offset)
23022303
self.assertEqual(4, fentries[0].size)
23032304
self.assertEqual(b'U_BOOT', fentries[0].name)
23042305

2305-
self.assertEqual(4, fentries[1].offset)
2306+
self.assertEqual(base + 4, fentries[1].offset)
23062307
self.assertEqual(3, fentries[1].size)
23072308
self.assertEqual(b'INTEL_MRC', fentries[1].name)
23082309

2309-
self.assertEqual(32, fentries[2].offset)
2310+
self.assertEqual(base + 32, fentries[2].offset)
23102311
self.assertEqual(fmap_util.FMAP_HEADER_LEN +
23112312
fmap_util.FMAP_AREA_LEN * 3, fentries[2].size)
23122313
self.assertEqual(b'FMAP', fentries[2].name)
@@ -2319,27 +2320,28 @@ def testFmapX86Section(self):
23192320
fhdr, fentries = fmap_util.DecodeFmap(data[36:])
23202321

23212322
self.assertEqual(0x180, fhdr.image_size)
2323+
base = (1 << 32) - 0x180
23222324
expect_size = fmap_util.FMAP_HEADER_LEN + fmap_util.FMAP_AREA_LEN * 4
23232325
fiter = iter(fentries)
23242326

23252327
fentry = next(fiter)
23262328
self.assertEqual(b'U_BOOT', fentry.name)
2327-
self.assertEqual(0, fentry.offset)
2329+
self.assertEqual(base, fentry.offset)
23282330
self.assertEqual(4, fentry.size)
23292331

23302332
fentry = next(fiter)
23312333
self.assertEqual(b'SECTION', fentry.name)
2332-
self.assertEqual(4, fentry.offset)
2334+
self.assertEqual(base + 4, fentry.offset)
23332335
self.assertEqual(0x20 + expect_size, fentry.size)
23342336

23352337
fentry = next(fiter)
23362338
self.assertEqual(b'INTEL_MRC', fentry.name)
2337-
self.assertEqual(4, fentry.offset)
2339+
self.assertEqual(base + 4, fentry.offset)
23382340
self.assertEqual(3, fentry.size)
23392341

23402342
fentry = next(fiter)
23412343
self.assertEqual(b'FMAP', fentry.name)
2342-
self.assertEqual(36, fentry.offset)
2344+
self.assertEqual(base + 36, fentry.offset)
23432345
self.assertEqual(expect_size, fentry.size)
23442346

23452347
def testElf(self):
@@ -3535,8 +3537,8 @@ def testDescriptorOffset(self):
35353537
image = control.images['image']
35363538
entries = image.GetEntries()
35373539
desc = entries['intel-descriptor']
3538-
self.assertEqual(0xff800000, desc.offset);
3539-
self.assertEqual(0xff800000, desc.image_pos);
3540+
self.assertEqual(0xff800000, desc.offset)
3541+
self.assertEqual(0xff800000, desc.image_pos)
35403542

35413543
def testReplaceCbfs(self):
35423544
"""Test replacing a single file in CBFS without changing the size"""
@@ -3778,8 +3780,8 @@ def testPackIntelFit(self):
37783780

37793781
image = control.images['image']
37803782
entries = image.GetEntries()
3781-
expected_ptr = entries['intel-fit'].image_pos - (1 << 32)
3782-
self.assertEqual(expected_ptr, ptr)
3783+
expected_ptr = entries['intel-fit'].image_pos #- (1 << 32)
3784+
self.assertEqual(expected_ptr, ptr + (1 << 32))
37833785

37843786
def testPackIntelFitMissing(self):
37853787
"""Test detection of a FIT pointer with not FIT region"""
@@ -4773,7 +4775,7 @@ def testReadImageSkip(self):
47734775
entry = image.GetEntries()['fdtmap']
47744776
self.assertEqual(orig_entry.offset, entry.offset)
47754777
self.assertEqual(orig_entry.size, entry.size)
4776-
self.assertEqual(16, entry.image_pos)
4778+
self.assertEqual((1 << 32) - 0x400 + 16, entry.image_pos)
47774779

47784780
u_boot = image.GetEntries()['section'].GetEntries()['u-boot']
47794781

0 commit comments

Comments
 (0)