mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-10 23:24:38 +00:00
binman: Add a bit of logging in entries when packing
Use the new logging feature to log information about progress with packing. This is useful to see how binman is figuring things out. Also update elf.py to use the same feature. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
fd07336211
commit
9f297b09c0
6 changed files with 53 additions and 16 deletions
|
@ -17,6 +17,7 @@ import struct
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
import tools
|
import tools
|
||||||
|
import tout
|
||||||
|
|
||||||
ELF_TOOLS = True
|
ELF_TOOLS = True
|
||||||
try:
|
try:
|
||||||
|
@ -25,9 +26,6 @@ try:
|
||||||
except: # pragma: no cover
|
except: # pragma: no cover
|
||||||
ELF_TOOLS = False
|
ELF_TOOLS = False
|
||||||
|
|
||||||
# This is enabled from control.py
|
|
||||||
debug = False
|
|
||||||
|
|
||||||
Symbol = namedtuple('Symbol', ['section', 'address', 'size', 'weak'])
|
Symbol = namedtuple('Symbol', ['section', 'address', 'size', 'weak'])
|
||||||
|
|
||||||
# Information about an ELF file:
|
# Information about an ELF file:
|
||||||
|
@ -143,9 +141,8 @@ def LookupAndWriteSymbols(elf_fname, entry, section):
|
||||||
value = -1
|
value = -1
|
||||||
pack_string = pack_string.lower()
|
pack_string = pack_string.lower()
|
||||||
value_bytes = struct.pack(pack_string, value)
|
value_bytes = struct.pack(pack_string, value)
|
||||||
if debug:
|
tout.Debug('%s:\n insert %s, offset %x, value %x, length %d' %
|
||||||
print('%s:\n insert %s, offset %x, value %x, length %d' %
|
(msg, name, offset, value, len(value_bytes)))
|
||||||
(msg, name, offset, value, len(value_bytes)))
|
|
||||||
entry.data = (entry.data[:offset] + value_bytes +
|
entry.data = (entry.data[:offset] + value_bytes +
|
||||||
entry.data[offset + sym.size:])
|
entry.data[offset + sym.size:])
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ import command
|
||||||
import elf
|
import elf
|
||||||
import test_util
|
import test_util
|
||||||
import tools
|
import tools
|
||||||
|
import tout
|
||||||
|
|
||||||
binman_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
|
binman_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
|
||||||
|
|
||||||
|
@ -130,14 +131,16 @@ class TestElf(unittest.TestCase):
|
||||||
|
|
||||||
def testDebug(self):
|
def testDebug(self):
|
||||||
"""Check that enabling debug in the elf module produced debug output"""
|
"""Check that enabling debug in the elf module produced debug output"""
|
||||||
elf.debug = True
|
try:
|
||||||
entry = FakeEntry(20)
|
tout.Init(tout.DEBUG)
|
||||||
section = FakeSection()
|
entry = FakeEntry(20)
|
||||||
elf_fname = os.path.join(binman_dir, 'test', 'u_boot_binman_syms')
|
section = FakeSection()
|
||||||
with test_util.capture_sys_output() as (stdout, stderr):
|
elf_fname = os.path.join(binman_dir, 'test', 'u_boot_binman_syms')
|
||||||
syms = elf.LookupAndWriteSymbols(elf_fname, entry, section)
|
with test_util.capture_sys_output() as (stdout, stderr):
|
||||||
elf.debug = False
|
syms = elf.LookupAndWriteSymbols(elf_fname, entry, section)
|
||||||
self.assertTrue(len(stdout.getvalue()) > 0)
|
self.assertTrue(len(stdout.getvalue()) > 0)
|
||||||
|
finally:
|
||||||
|
tout.Init(tout.WARNING)
|
||||||
|
|
||||||
def testMakeElf(self):
|
def testMakeElf(self):
|
||||||
"""Test for the MakeElf function"""
|
"""Test for the MakeElf function"""
|
||||||
|
|
|
@ -23,6 +23,7 @@ import sys
|
||||||
import fdt_util
|
import fdt_util
|
||||||
import state
|
import state
|
||||||
import tools
|
import tools
|
||||||
|
from tools import ToHex, ToHexSize
|
||||||
import tout
|
import tout
|
||||||
|
|
||||||
modules = {}
|
modules = {}
|
||||||
|
@ -272,8 +273,9 @@ class Entry(object):
|
||||||
new_size = len(data)
|
new_size = len(data)
|
||||||
if state.AllowEntryExpansion():
|
if state.AllowEntryExpansion():
|
||||||
if new_size > self.contents_size:
|
if new_size > self.contents_size:
|
||||||
tout.Debug("Entry '%s' size change from %#x to %#x" % (
|
tout.Debug("Entry '%s' size change from %s to %s" % (
|
||||||
self._node.path, self.contents_size, new_size))
|
self._node.path, ToHex(self.contents_size),
|
||||||
|
ToHex(new_size)))
|
||||||
# self.data will indicate the new size needed
|
# self.data will indicate the new size needed
|
||||||
size_ok = False
|
size_ok = False
|
||||||
elif new_size != self.contents_size:
|
elif new_size != self.contents_size:
|
||||||
|
@ -294,6 +296,9 @@ class Entry(object):
|
||||||
|
|
||||||
def ResetForPack(self):
|
def ResetForPack(self):
|
||||||
"""Reset offset/size fields so that packing can be done again"""
|
"""Reset offset/size fields so that packing can be done again"""
|
||||||
|
self.Detail('ResetForPack: offset %s->%s, size %s->%s' %
|
||||||
|
(ToHex(self.offset), ToHex(self.orig_offset),
|
||||||
|
ToHex(self.size), ToHex(self.orig_size)))
|
||||||
self.offset = self.orig_offset
|
self.offset = self.orig_offset
|
||||||
self.size = self.orig_size
|
self.size = self.orig_size
|
||||||
|
|
||||||
|
@ -315,6 +320,9 @@ class Entry(object):
|
||||||
Returns:
|
Returns:
|
||||||
New section offset pointer (after this entry)
|
New section offset pointer (after this entry)
|
||||||
"""
|
"""
|
||||||
|
self.Detail('Packing: offset=%s, size=%s, content_size=%x' %
|
||||||
|
(ToHex(self.offset), ToHex(self.size),
|
||||||
|
self.contents_size))
|
||||||
if self.offset is None:
|
if self.offset is None:
|
||||||
if self.offset_unset:
|
if self.offset_unset:
|
||||||
self.Raise('No offset set with offset-unset: should another '
|
self.Raise('No offset set with offset-unset: should another '
|
||||||
|
@ -346,6 +354,8 @@ class Entry(object):
|
||||||
if self.offset != tools.Align(self.offset, self.align):
|
if self.offset != tools.Align(self.offset, self.align):
|
||||||
self.Raise("Offset %#x (%d) does not match align %#x (%d)" %
|
self.Raise("Offset %#x (%d) does not match align %#x (%d)" %
|
||||||
(self.offset, self.offset, self.align, self.align))
|
(self.offset, self.offset, self.align, self.align))
|
||||||
|
self.Detail(' - packed: offset=%#x, size=%#x, content_size=%#x, next_offset=%x' %
|
||||||
|
(self.offset, self.size, self.contents_size, new_offset))
|
||||||
|
|
||||||
return new_offset
|
return new_offset
|
||||||
|
|
||||||
|
@ -353,6 +363,11 @@ class Entry(object):
|
||||||
"""Convenience function to raise an error referencing a node"""
|
"""Convenience function to raise an error referencing a node"""
|
||||||
raise ValueError("Node '%s': %s" % (self._node.path, msg))
|
raise ValueError("Node '%s': %s" % (self._node.path, msg))
|
||||||
|
|
||||||
|
def Detail(self, msg):
|
||||||
|
"""Convenience function to log detail referencing a node"""
|
||||||
|
tag = "Node '%s'" % self._node.path
|
||||||
|
tout.Detail('%30s: %s' % (tag, msg))
|
||||||
|
|
||||||
def GetEntryArgsOrProps(self, props, required=False):
|
def GetEntryArgsOrProps(self, props, required=False):
|
||||||
"""Return the values of a set of properties
|
"""Return the values of a set of properties
|
||||||
|
|
||||||
|
@ -389,6 +404,7 @@ class Entry(object):
|
||||||
return self._node.path
|
return self._node.path
|
||||||
|
|
||||||
def GetData(self):
|
def GetData(self):
|
||||||
|
self.Detail('GetData: size %s' % ToHexSize(self.data))
|
||||||
return self.data
|
return self.data
|
||||||
|
|
||||||
def GetOffsets(self):
|
def GetOffsets(self):
|
||||||
|
|
|
@ -14,6 +14,7 @@ from entry import Entry
|
||||||
from fdt import Fdt
|
from fdt import Fdt
|
||||||
import state
|
import state
|
||||||
import tools
|
import tools
|
||||||
|
import tout
|
||||||
|
|
||||||
FDTMAP_MAGIC = b'_FDTMAP_'
|
FDTMAP_MAGIC = b'_FDTMAP_'
|
||||||
FDTMAP_HDR_LEN = 16
|
FDTMAP_HDR_LEN = 16
|
||||||
|
@ -98,6 +99,8 @@ class Entry_fdtmap(Entry):
|
||||||
|
|
||||||
# Find the node for the image containing the Fdt-map entry
|
# Find the node for the image containing the Fdt-map entry
|
||||||
path = self.section.GetPath()
|
path = self.section.GetPath()
|
||||||
|
self.Detail("Fdtmap: Using section '%s' (path '%s')" %
|
||||||
|
(self.section.name, path))
|
||||||
node = infdt.GetNode(path)
|
node = infdt.GetNode(path)
|
||||||
if not node:
|
if not node:
|
||||||
self.Raise("Internal error: Cannot locate node for path '%s'" %
|
self.Raise("Internal error: Cannot locate node for path '%s'" %
|
||||||
|
|
|
@ -149,6 +149,8 @@ class Entry_section(Entry):
|
||||||
base = self.pad_before + entry.offset - self._skip_at_start
|
base = self.pad_before + entry.offset - self._skip_at_start
|
||||||
section_data = (section_data[:base] + data +
|
section_data = (section_data[:base] + data +
|
||||||
section_data[base + len(data):])
|
section_data[base + len(data):])
|
||||||
|
self.Detail('GetData: %d entries, total size %#x' %
|
||||||
|
(len(self._entries), len(section_data)))
|
||||||
return section_data
|
return section_data
|
||||||
|
|
||||||
def GetOffsets(self):
|
def GetOffsets(self):
|
||||||
|
|
|
@ -473,3 +473,19 @@ def RunIfwiTool(ifwi_file, cmd, fname=None, subpart=None, entry_name=None):
|
||||||
if entry_name:
|
if entry_name:
|
||||||
args += ['-d', '-e', entry_name]
|
args += ['-d', '-e', entry_name]
|
||||||
Run(*args)
|
Run(*args)
|
||||||
|
|
||||||
|
def ToHex(val):
|
||||||
|
"""Convert an integer value (or None) to a string
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
hex value, or 'None' if the value is None
|
||||||
|
"""
|
||||||
|
return 'None' if val is None else '%#x' % val
|
||||||
|
|
||||||
|
def ToHexSize(val):
|
||||||
|
"""Return the size of an object in hex
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
hex value of size, or 'None' if the value is None
|
||||||
|
"""
|
||||||
|
return 'None' if val is None else '%#x' % len(val)
|
||||||
|
|
Loading…
Reference in a new issue