2018-06-01 15:38:12 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0+
|
|
|
|
# Copyright (c) 2018 Google, Inc
|
|
|
|
# Written by Simon Glass <sjg@chromium.org>
|
|
|
|
#
|
|
|
|
# Base class for sections (collections of entries)
|
|
|
|
#
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
from collections import OrderedDict
|
2018-09-14 10:57:22 +00:00
|
|
|
from sets import Set
|
2018-06-01 15:38:12 +00:00
|
|
|
import sys
|
|
|
|
|
|
|
|
import fdt_util
|
|
|
|
import re
|
2018-09-14 10:57:21 +00:00
|
|
|
import state
|
2018-06-01 15:38:12 +00:00
|
|
|
import tools
|
|
|
|
|
|
|
|
class Section(object):
|
|
|
|
"""A section which contains multiple entries
|
|
|
|
|
|
|
|
A section represents a collection of entries. There must be one or more
|
|
|
|
sections in an image. Sections are used to group entries together.
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
_node: Node object that contains the section definition in device tree
|
2018-09-14 10:57:33 +00:00
|
|
|
_parent_section: Parent Section object which created this Section
|
2018-06-01 15:38:12 +00:00
|
|
|
_size: Section size in bytes, or None if not known yet
|
|
|
|
_align_size: Section size alignment, or None
|
|
|
|
_pad_before: Number of bytes before the first entry starts. This
|
2018-08-01 21:22:37 +00:00
|
|
|
effectively changes the place where entry offset 0 starts
|
2018-06-01 15:38:12 +00:00
|
|
|
_pad_after: Number of bytes after the last entry ends. The last
|
|
|
|
entry will finish on or before this boundary
|
|
|
|
_pad_byte: Byte to use to pad the section where there is no entry
|
2018-08-01 21:22:37 +00:00
|
|
|
_sort: True if entries should be sorted by offset, False if they
|
2018-06-01 15:38:12 +00:00
|
|
|
must be in-order in the device tree description
|
|
|
|
_skip_at_start: Number of bytes before the first entry starts. These
|
2018-08-01 21:22:37 +00:00
|
|
|
effectively adjust the starting offset of entries. For example,
|
2018-06-01 15:38:12 +00:00
|
|
|
if _pad_before is 16, then the first entry would start at 16.
|
2018-08-01 21:22:37 +00:00
|
|
|
An entry with offset = 20 would in fact be written at offset 4
|
2018-06-01 15:38:12 +00:00
|
|
|
in the image file.
|
|
|
|
_end_4gb: Indicates that the section ends at the 4GB boundary. This is
|
2018-08-01 21:22:37 +00:00
|
|
|
used for x86 images, which want to use offsets such that a memory
|
|
|
|
address (like 0xff800000) is the first entry offset. This causes
|
|
|
|
_skip_at_start to be set to the starting memory address.
|
2018-06-01 15:38:21 +00:00
|
|
|
_name_prefix: Prefix to add to the name of all entries within this
|
|
|
|
section
|
2018-06-01 15:38:12 +00:00
|
|
|
_entries: OrderedDict() of entries
|
|
|
|
"""
|
2018-09-14 10:57:33 +00:00
|
|
|
def __init__(self, name, parent_section, node, image, test=False):
|
2018-06-01 15:38:12 +00:00
|
|
|
global entry
|
|
|
|
global Entry
|
|
|
|
import entry
|
|
|
|
from entry import Entry
|
|
|
|
|
2018-09-14 10:57:33 +00:00
|
|
|
self._parent_section = parent_section
|
2018-07-17 19:25:28 +00:00
|
|
|
self._name = name
|
2018-06-01 15:38:12 +00:00
|
|
|
self._node = node
|
2018-09-14 10:57:33 +00:00
|
|
|
self._image = image
|
2019-04-26 03:58:39 +00:00
|
|
|
self._offset = None
|
2018-06-01 15:38:12 +00:00
|
|
|
self._size = None
|
|
|
|
self._align_size = None
|
|
|
|
self._pad_before = 0
|
|
|
|
self._pad_after = 0
|
|
|
|
self._pad_byte = 0
|
|
|
|
self._sort = False
|
2018-09-03 16:05:07 +00:00
|
|
|
self._skip_at_start = None
|
2018-06-01 15:38:12 +00:00
|
|
|
self._end_4gb = False
|
2018-06-01 15:38:21 +00:00
|
|
|
self._name_prefix = ''
|
2018-06-01 15:38:12 +00:00
|
|
|
self._entries = OrderedDict()
|
2018-09-14 10:57:34 +00:00
|
|
|
self._image_pos = None
|
2018-06-01 15:38:12 +00:00
|
|
|
if not test:
|
|
|
|
self._ReadNode()
|
|
|
|
self._ReadEntries()
|
|
|
|
|
|
|
|
def _ReadNode(self):
|
|
|
|
"""Read properties from the section node"""
|
2019-04-26 03:58:39 +00:00
|
|
|
self._offset = fdt_util.GetInt(self._node, 'offset')
|
2018-06-01 15:38:12 +00:00
|
|
|
self._size = fdt_util.GetInt(self._node, 'size')
|
|
|
|
self._align_size = fdt_util.GetInt(self._node, 'align-size')
|
|
|
|
if tools.NotPowerOfTwo(self._align_size):
|
|
|
|
self._Raise("Alignment size %s must be a power of two" %
|
|
|
|
self._align_size)
|
|
|
|
self._pad_before = fdt_util.GetInt(self._node, 'pad-before', 0)
|
|
|
|
self._pad_after = fdt_util.GetInt(self._node, 'pad-after', 0)
|
|
|
|
self._pad_byte = fdt_util.GetInt(self._node, 'pad-byte', 0)
|
2018-08-01 21:22:37 +00:00
|
|
|
self._sort = fdt_util.GetBool(self._node, 'sort-by-offset')
|
2018-06-01 15:38:12 +00:00
|
|
|
self._end_4gb = fdt_util.GetBool(self._node, 'end-at-4gb')
|
2018-09-03 16:05:07 +00:00
|
|
|
self._skip_at_start = fdt_util.GetInt(self._node, 'skip-at-start')
|
2018-06-01 15:38:12 +00:00
|
|
|
if self._end_4gb:
|
2018-09-03 16:05:07 +00:00
|
|
|
if not self._size:
|
|
|
|
self._Raise("Section size must be provided when using end-at-4gb")
|
|
|
|
if self._skip_at_start is not None:
|
|
|
|
self._Raise("Provide either 'end-at-4gb' or 'skip-at-start'")
|
|
|
|
else:
|
|
|
|
self._skip_at_start = 0x100000000 - self._size
|
|
|
|
else:
|
|
|
|
if self._skip_at_start is None:
|
|
|
|
self._skip_at_start = 0
|
2018-06-01 15:38:21 +00:00
|
|
|
self._name_prefix = fdt_util.GetString(self._node, 'name-prefix')
|
2018-06-01 15:38:12 +00:00
|
|
|
|
|
|
|
def _ReadEntries(self):
|
|
|
|
for node in self._node.subnodes:
|
2018-09-14 10:57:31 +00:00
|
|
|
if node.name == 'hash':
|
|
|
|
continue
|
2018-06-01 15:38:21 +00:00
|
|
|
entry = Entry.Create(self, node)
|
|
|
|
entry.SetPrefix(self._name_prefix)
|
|
|
|
self._entries[node.name] = entry
|
2018-06-01 15:38:12 +00:00
|
|
|
|
2018-09-14 10:57:22 +00:00
|
|
|
def GetFdtSet(self):
|
|
|
|
"""Get the set of device tree files used by this image"""
|
|
|
|
fdt_set = Set()
|
|
|
|
for entry in self._entries.values():
|
|
|
|
fdt_set.update(entry.GetFdtSet())
|
|
|
|
return fdt_set
|
|
|
|
|
2018-07-17 19:25:28 +00:00
|
|
|
def SetOffset(self, offset):
|
|
|
|
self._offset = offset
|
|
|
|
|
2018-09-14 10:57:28 +00:00
|
|
|
def ExpandEntries(self):
|
|
|
|
for entry in self._entries.values():
|
|
|
|
entry.ExpandEntries()
|
|
|
|
|
2018-07-06 16:27:41 +00:00
|
|
|
def AddMissingProperties(self):
|
2018-07-17 19:25:28 +00:00
|
|
|
"""Add new properties to the device tree as needed for this entry"""
|
2018-08-01 21:22:42 +00:00
|
|
|
for prop in ['offset', 'size', 'image-pos']:
|
2018-07-17 19:25:28 +00:00
|
|
|
if not prop in self._node.props:
|
2018-09-14 10:57:21 +00:00
|
|
|
state.AddZeroProp(self._node, prop)
|
2018-09-14 10:57:31 +00:00
|
|
|
state.CheckAddHashProp(self._node)
|
2018-07-06 16:27:41 +00:00
|
|
|
for entry in self._entries.values():
|
|
|
|
entry.AddMissingProperties()
|
|
|
|
|
|
|
|
def SetCalculatedProperties(self):
|
2019-04-26 03:58:39 +00:00
|
|
|
state.SetInt(self._node, 'offset', self._offset or 0)
|
2018-09-14 10:57:21 +00:00
|
|
|
state.SetInt(self._node, 'size', self._size)
|
2018-09-14 10:57:34 +00:00
|
|
|
image_pos = self._image_pos
|
|
|
|
if self._parent_section:
|
|
|
|
image_pos -= self._parent_section.GetRootSkipAtStart()
|
|
|
|
state.SetInt(self._node, 'image-pos', image_pos)
|
2018-07-06 16:27:41 +00:00
|
|
|
for entry in self._entries.values():
|
|
|
|
entry.SetCalculatedProperties()
|
|
|
|
|
2018-07-06 16:27:40 +00:00
|
|
|
def ProcessFdt(self, fdt):
|
|
|
|
todo = self._entries.values()
|
|
|
|
for passnum in range(3):
|
|
|
|
next_todo = []
|
|
|
|
for entry in todo:
|
|
|
|
if not entry.ProcessFdt(fdt):
|
|
|
|
next_todo.append(entry)
|
|
|
|
todo = next_todo
|
|
|
|
if not todo:
|
|
|
|
break
|
|
|
|
if todo:
|
|
|
|
self._Raise('Internal error: Could not complete processing of Fdt: '
|
|
|
|
'remaining %s' % todo)
|
|
|
|
return True
|
|
|
|
|
2018-06-01 15:38:12 +00:00
|
|
|
def CheckSize(self):
|
|
|
|
"""Check that the section contents does not exceed its size, etc."""
|
|
|
|
contents_size = 0
|
|
|
|
for entry in self._entries.values():
|
2018-08-01 21:22:37 +00:00
|
|
|
contents_size = max(contents_size, entry.offset + entry.size)
|
2018-06-01 15:38:12 +00:00
|
|
|
|
|
|
|
contents_size -= self._skip_at_start
|
|
|
|
|
|
|
|
size = self._size
|
|
|
|
if not size:
|
|
|
|
size = self._pad_before + contents_size + self._pad_after
|
|
|
|
size = tools.Align(size, self._align_size)
|
|
|
|
|
|
|
|
if self._size and contents_size > self._size:
|
|
|
|
self._Raise("contents size %#x (%d) exceeds section size %#x (%d)" %
|
|
|
|
(contents_size, contents_size, self._size, self._size))
|
|
|
|
if not self._size:
|
|
|
|
self._size = size
|
|
|
|
if self._size != tools.Align(self._size, self._align_size):
|
|
|
|
self._Raise("Size %#x (%d) does not match align-size %#x (%d)" %
|
|
|
|
(self._size, self._size, self._align_size, self._align_size))
|
|
|
|
return size
|
|
|
|
|
|
|
|
def _Raise(self, msg):
|
|
|
|
"""Raises an error for this section
|
|
|
|
|
|
|
|
Args:
|
|
|
|
msg: Error message to use in the raise string
|
|
|
|
Raises:
|
|
|
|
ValueError()
|
|
|
|
"""
|
|
|
|
raise ValueError("Section '%s': %s" % (self._node.path, msg))
|
|
|
|
|
|
|
|
def GetPath(self):
|
|
|
|
"""Get the path of an image (in the FDT)
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Full path of the node for this image
|
|
|
|
"""
|
|
|
|
return self._node.path
|
|
|
|
|
|
|
|
def FindEntryType(self, etype):
|
|
|
|
"""Find an entry type in the section
|
|
|
|
|
|
|
|
Args:
|
|
|
|
etype: Entry type to find
|
|
|
|
Returns:
|
|
|
|
entry matching that type, or None if not found
|
|
|
|
"""
|
|
|
|
for entry in self._entries.values():
|
|
|
|
if entry.etype == etype:
|
|
|
|
return entry
|
|
|
|
return None
|
|
|
|
|
|
|
|
def GetEntryContents(self):
|
|
|
|
"""Call ObtainContents() for each entry
|
|
|
|
|
|
|
|
This calls each entry's ObtainContents() a few times until they all
|
|
|
|
return True. We stop calling an entry's function once it returns
|
|
|
|
True. This allows the contents of one entry to depend on another.
|
|
|
|
|
|
|
|
After 3 rounds we give up since it's likely an error.
|
|
|
|
"""
|
|
|
|
todo = self._entries.values()
|
|
|
|
for passnum in range(3):
|
|
|
|
next_todo = []
|
|
|
|
for entry in todo:
|
|
|
|
if not entry.ObtainContents():
|
|
|
|
next_todo.append(entry)
|
|
|
|
todo = next_todo
|
|
|
|
if not todo:
|
|
|
|
break
|
2018-07-06 16:27:17 +00:00
|
|
|
if todo:
|
|
|
|
self._Raise('Internal error: Could not complete processing of '
|
|
|
|
'contents: remaining %s' % todo)
|
|
|
|
return True
|
2018-06-01 15:38:12 +00:00
|
|
|
|
2018-08-01 21:22:37 +00:00
|
|
|
def _SetEntryOffsetSize(self, name, offset, size):
|
|
|
|
"""Set the offset and size of an entry
|
2018-06-01 15:38:12 +00:00
|
|
|
|
|
|
|
Args:
|
|
|
|
name: Entry name to update
|
2018-08-01 21:22:37 +00:00
|
|
|
offset: New offset
|
2018-06-01 15:38:12 +00:00
|
|
|
size: New size
|
|
|
|
"""
|
|
|
|
entry = self._entries.get(name)
|
|
|
|
if not entry:
|
2018-08-01 21:22:37 +00:00
|
|
|
self._Raise("Unable to set offset/size for unknown entry '%s'" %
|
|
|
|
name)
|
|
|
|
entry.SetOffsetSize(self._skip_at_start + offset, size)
|
2018-06-01 15:38:12 +00:00
|
|
|
|
2018-08-01 21:22:37 +00:00
|
|
|
def GetEntryOffsets(self):
|
|
|
|
"""Handle entries that want to set the offset/size of other entries
|
2018-06-01 15:38:12 +00:00
|
|
|
|
2018-08-01 21:22:37 +00:00
|
|
|
This calls each entry's GetOffsets() method. If it returns a list
|
2018-06-01 15:38:12 +00:00
|
|
|
of entries to update, it updates them.
|
|
|
|
"""
|
|
|
|
for entry in self._entries.values():
|
2018-08-01 21:22:37 +00:00
|
|
|
offset_dict = entry.GetOffsets()
|
|
|
|
for name, info in offset_dict.iteritems():
|
|
|
|
self._SetEntryOffsetSize(name, *info)
|
2018-06-01 15:38:12 +00:00
|
|
|
|
|
|
|
def PackEntries(self):
|
|
|
|
"""Pack all entries into the section"""
|
2018-08-01 21:22:37 +00:00
|
|
|
offset = self._skip_at_start
|
2018-06-01 15:38:12 +00:00
|
|
|
for entry in self._entries.values():
|
2018-08-01 21:22:37 +00:00
|
|
|
offset = entry.Pack(offset)
|
|
|
|
self._size = self.CheckSize()
|
2018-06-01 15:38:12 +00:00
|
|
|
|
|
|
|
def _SortEntries(self):
|
2018-08-01 21:22:37 +00:00
|
|
|
"""Sort entries by offset"""
|
|
|
|
entries = sorted(self._entries.values(), key=lambda entry: entry.offset)
|
2018-06-01 15:38:12 +00:00
|
|
|
self._entries.clear()
|
|
|
|
for entry in entries:
|
|
|
|
self._entries[entry._node.name] = entry
|
|
|
|
|
2018-09-14 10:57:29 +00:00
|
|
|
def _ExpandEntries(self):
|
|
|
|
"""Expand any entries that are permitted to"""
|
|
|
|
exp_entry = None
|
|
|
|
for entry in self._entries.values():
|
|
|
|
if exp_entry:
|
|
|
|
exp_entry.ExpandToLimit(entry.offset)
|
|
|
|
exp_entry = None
|
|
|
|
if entry.expand_size:
|
|
|
|
exp_entry = entry
|
|
|
|
if exp_entry:
|
|
|
|
exp_entry.ExpandToLimit(self._size)
|
|
|
|
|
2018-06-01 15:38:12 +00:00
|
|
|
def CheckEntries(self):
|
2018-09-14 10:57:29 +00:00
|
|
|
"""Check that entries do not overlap or extend outside the section
|
|
|
|
|
|
|
|
This also sorts entries, if needed and expands
|
|
|
|
"""
|
2018-06-01 15:38:12 +00:00
|
|
|
if self._sort:
|
|
|
|
self._SortEntries()
|
2018-09-14 10:57:29 +00:00
|
|
|
self._ExpandEntries()
|
2018-08-01 21:22:37 +00:00
|
|
|
offset = 0
|
2018-06-01 15:38:12 +00:00
|
|
|
prev_name = 'None'
|
|
|
|
for entry in self._entries.values():
|
2018-08-01 21:22:37 +00:00
|
|
|
entry.CheckOffset()
|
|
|
|
if (entry.offset < self._skip_at_start or
|
2018-09-14 10:57:27 +00:00
|
|
|
entry.offset + entry.size > self._skip_at_start + self._size):
|
2018-08-01 21:22:37 +00:00
|
|
|
entry.Raise("Offset %#x (%d) is outside the section starting "
|
2018-06-01 15:38:12 +00:00
|
|
|
"at %#x (%d)" %
|
2018-08-01 21:22:37 +00:00
|
|
|
(entry.offset, entry.offset, self._skip_at_start,
|
2018-06-01 15:38:12 +00:00
|
|
|
self._skip_at_start))
|
2018-08-01 21:22:37 +00:00
|
|
|
if entry.offset < offset:
|
|
|
|
entry.Raise("Offset %#x (%d) overlaps with previous entry '%s' "
|
2018-06-01 15:38:12 +00:00
|
|
|
"ending at %#x (%d)" %
|
2018-08-01 21:22:37 +00:00
|
|
|
(entry.offset, entry.offset, prev_name, offset, offset))
|
|
|
|
offset = entry.offset + entry.size
|
2018-06-01 15:38:12 +00:00
|
|
|
prev_name = entry.GetPath()
|
|
|
|
|
2018-08-01 21:22:42 +00:00
|
|
|
def SetImagePos(self, image_pos):
|
|
|
|
self._image_pos = image_pos
|
|
|
|
for entry in self._entries.values():
|
|
|
|
entry.SetImagePos(image_pos)
|
|
|
|
|
2018-06-01 15:38:12 +00:00
|
|
|
def ProcessEntryContents(self):
|
|
|
|
"""Call the ProcessContents() method for each entry
|
|
|
|
|
|
|
|
This is intended to adjust the contents as needed by the entry type.
|
|
|
|
"""
|
|
|
|
for entry in self._entries.values():
|
|
|
|
entry.ProcessContents()
|
|
|
|
|
|
|
|
def WriteSymbols(self):
|
|
|
|
"""Write symbol values into binary files for access at run time"""
|
|
|
|
for entry in self._entries.values():
|
|
|
|
entry.WriteSymbols(self)
|
|
|
|
|
2018-08-01 21:22:37 +00:00
|
|
|
def BuildSection(self, fd, base_offset):
|
2018-06-01 15:38:12 +00:00
|
|
|
"""Write the section to a file"""
|
2018-08-01 21:22:37 +00:00
|
|
|
fd.seek(base_offset)
|
2018-06-01 15:38:12 +00:00
|
|
|
fd.write(self.GetData())
|
|
|
|
|
|
|
|
def GetData(self):
|
2018-07-17 19:25:28 +00:00
|
|
|
"""Get the contents of the section"""
|
2018-06-01 15:38:12 +00:00
|
|
|
section_data = chr(self._pad_byte) * self._size
|
|
|
|
|
|
|
|
for entry in self._entries.values():
|
|
|
|
data = entry.GetData()
|
2018-08-01 21:22:37 +00:00
|
|
|
base = self._pad_before + entry.offset - self._skip_at_start
|
2018-06-01 15:38:12 +00:00
|
|
|
section_data = (section_data[:base] + data +
|
|
|
|
section_data[base + len(data):])
|
|
|
|
return section_data
|
|
|
|
|
|
|
|
def LookupSymbol(self, sym_name, optional, msg):
|
|
|
|
"""Look up a symbol in an ELF file
|
|
|
|
|
|
|
|
Looks up a symbol in an ELF file. Only entry types which come from an
|
|
|
|
ELF image can be used by this function.
|
|
|
|
|
2018-08-01 21:22:37 +00:00
|
|
|
At present the only entry property supported is offset.
|
2018-06-01 15:38:12 +00:00
|
|
|
|
|
|
|
Args:
|
|
|
|
sym_name: Symbol name in the ELF file to look up in the format
|
|
|
|
_binman_<entry>_prop_<property> where <entry> is the name of
|
|
|
|
the entry and <property> is the property to find (e.g.
|
2018-08-01 21:22:37 +00:00
|
|
|
_binman_u_boot_prop_offset). As a special case, you can append
|
2018-06-01 15:38:12 +00:00
|
|
|
_any to <entry> to have it search for any matching entry. E.g.
|
2018-08-01 21:22:37 +00:00
|
|
|
_binman_u_boot_any_prop_offset will match entries called u-boot,
|
2018-06-01 15:38:12 +00:00
|
|
|
u-boot-img and u-boot-nodtb)
|
|
|
|
optional: True if the symbol is optional. If False this function
|
|
|
|
will raise if the symbol is not found
|
|
|
|
msg: Message to display if an error occurs
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Value that should be assigned to that symbol, or None if it was
|
|
|
|
optional and not found
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
ValueError if the symbol is invalid or not found, or references a
|
|
|
|
property which is not supported
|
|
|
|
"""
|
|
|
|
m = re.match(r'^_binman_(\w+)_prop_(\w+)$', sym_name)
|
|
|
|
if not m:
|
|
|
|
raise ValueError("%s: Symbol '%s' has invalid format" %
|
|
|
|
(msg, sym_name))
|
|
|
|
entry_name, prop_name = m.groups()
|
|
|
|
entry_name = entry_name.replace('_', '-')
|
|
|
|
entry = self._entries.get(entry_name)
|
|
|
|
if not entry:
|
|
|
|
if entry_name.endswith('-any'):
|
|
|
|
root = entry_name[:-4]
|
|
|
|
for name in self._entries:
|
|
|
|
if name.startswith(root):
|
|
|
|
rest = name[len(root):]
|
|
|
|
if rest in ['', '-img', '-nodtb']:
|
|
|
|
entry = self._entries[name]
|
|
|
|
if not entry:
|
|
|
|
err = ("%s: Entry '%s' not found in list (%s)" %
|
|
|
|
(msg, entry_name, ','.join(self._entries.keys())))
|
|
|
|
if optional:
|
|
|
|
print('Warning: %s' % err, file=sys.stderr)
|
|
|
|
return None
|
|
|
|
raise ValueError(err)
|
2018-08-01 21:22:37 +00:00
|
|
|
if prop_name == 'offset':
|
|
|
|
return entry.offset
|
2018-08-01 21:22:42 +00:00
|
|
|
elif prop_name == 'image_pos':
|
|
|
|
return entry.image_pos
|
2018-06-01 15:38:12 +00:00
|
|
|
else:
|
|
|
|
raise ValueError("%s: No such property '%s'" % (msg, prop_name))
|
|
|
|
|
|
|
|
def GetEntries(self):
|
2018-07-17 19:25:28 +00:00
|
|
|
"""Get the number of entries in a section
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Number of entries in a section
|
|
|
|
"""
|
2018-06-01 15:38:12 +00:00
|
|
|
return self._entries
|
2018-06-01 15:38:20 +00:00
|
|
|
|
2018-07-17 19:25:28 +00:00
|
|
|
def GetSize(self):
|
|
|
|
"""Get the size of a section in bytes
|
|
|
|
|
|
|
|
This is only meaningful if the section has a pre-defined size, or the
|
|
|
|
entries within it have been packed, so that the size has been
|
|
|
|
calculated.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Entry size in bytes
|
|
|
|
"""
|
|
|
|
return self._size
|
|
|
|
|
2018-06-01 15:38:20 +00:00
|
|
|
def WriteMap(self, fd, indent):
|
|
|
|
"""Write a map of the section to a .map file
|
|
|
|
|
|
|
|
Args:
|
|
|
|
fd: File to write the map to
|
|
|
|
"""
|
2019-04-26 03:58:39 +00:00
|
|
|
Entry.WriteMapLine(fd, indent, self._name, self._offset or 0,
|
|
|
|
self._size, self._image_pos)
|
2018-06-01 15:38:20 +00:00
|
|
|
for entry in self._entries.values():
|
2018-07-17 19:25:28 +00:00
|
|
|
entry.WriteMap(fd, indent + 1)
|
2018-07-17 19:25:47 +00:00
|
|
|
|
|
|
|
def GetContentsByPhandle(self, phandle, source_entry):
|
|
|
|
"""Get the data contents of an entry specified by a phandle
|
|
|
|
|
|
|
|
This uses a phandle to look up a node and and find the entry
|
|
|
|
associated with it. Then it returnst he contents of that entry.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
phandle: Phandle to look up (integer)
|
|
|
|
source_entry: Entry containing that phandle (used for error
|
|
|
|
reporting)
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
data from associated entry (as a string), or None if not found
|
|
|
|
"""
|
|
|
|
node = self._node.GetFdt().LookupPhandle(phandle)
|
|
|
|
if not node:
|
|
|
|
source_entry.Raise("Cannot find node for phandle %d" % phandle)
|
|
|
|
for entry in self._entries.values():
|
|
|
|
if entry._node == node:
|
2018-09-14 10:57:34 +00:00
|
|
|
return entry.GetData()
|
2018-07-17 19:25:47 +00:00
|
|
|
source_entry.Raise("Cannot find entry for node '%s'" % node.name)
|
2018-09-14 10:57:29 +00:00
|
|
|
|
|
|
|
def ExpandSize(self, size):
|
|
|
|
if size != self._size:
|
|
|
|
self._size = size
|
2018-09-14 10:57:34 +00:00
|
|
|
|
|
|
|
def GetRootSkipAtStart(self):
|
|
|
|
if self._parent_section:
|
|
|
|
return self._parent_section.GetRootSkipAtStart()
|
|
|
|
return self._skip_at_start
|
|
|
|
|
|
|
|
def GetImageSize(self):
|
|
|
|
return self._image._size
|