binman: Add CBFS support
v2 cover binman: Add CBFS support
CBFS (Coreboot Filesystem) is a simple ROM-based filesystem used for locating data needed during booting. It has particular features for x86 such as defining a boot block at the top of the ROM image. At run-time, boot loaders can locate files in the ROM by searching for a header and magic strings in the ROM.
It is common to have multiple, separate CBFSs in the ROM.
Binman provides its own way of locating data, typically with a device tree built into the image, or linker symbols when space is short. But it is useful to be able to create images containing CBFSs with binman, since it allows all image structure to defined in one place, rather than spread out over multiple cbfstool invocations, etc.
The approach taken here is to directly create the CBFS in binman rather than calling out to cbfstool. The latter is quite slow for multiple invocations and the tool itself has no tests.
Also included is ifwitool lifted from coreboot, which is needed to package images for Intel apollo lake SoCs. This seems easier than implementing this functionality in binman.
Tests are provided for new binman functionality, although ifwitool has no tests and is tested only by invocation from binman.
This series does not support all CBFS features, just raw binaries and Elf files (called 'stages' in CBFS).
Changes in v2:
- Deal with travis's old lz4 version by skipping tests as necessary
- Install lzma tool in travis
- Skip use of cbfstool in tests if it is not available
Simon Glass (37):
x86: Add ifwitool for Intel Integrated Firmware Image
cbfs: Add an enum and comment for the magic number
cbfs: Rename checksum to attributes_offset
tools: Drop duplicate raise_on_error argument
binman: Fix comment in bsection.GetEntries()
binman: Correct two typos in function names in ftest
binman: Add coverage tools info for Python 3
patman: Add a way to set the search path for tools
binman: Add a --toolpath option to set the tool search path
binman: Add missing comments to bsection
binman: Add missing comments toentry
binman: Tidy up help for --indir
binman: Use a better error for missing Intel descriptor
binman: Detect skipped tests
binman: Add a function to create a sample ELF file
binman: Add a function to decode an ELF file
binman: Ensure that coverage has access to site packages
binman: Assume Intel descriptor is at the start of the image
binman: Don't assume there is an ME region
binman: Update entry.SetOffsetSize to be optional
binman: Allow text directly in the node
patman: Add functions to compress and decompress data
binman: Use the tools.Decompress method
binman: Drop unnecessary debug handling
binman: Use tools compression function for blob handling
binman: Correct comment in u_boot_spl_elf
binman: Support ELF files for TPL
binman: Fix up the _DoTestFile() function -u argument
binman: Allow verbosity control when running tests
binman: Allow preserving test directories
binman: Pass the toolpath to tests
patman: Add a function to write ifwitool
binman: Add a utility library for coreboot CBFS
binman: Add support for CBFS entries
binman: Add support for Intel IFWI entries
binman: Pad empty areas of the CBFS with files
binman: Add support for fixed-offset files in CBFS
.travis.yml | 3 +- fs/cbfs/cbfs.c | 4 +- include/cbfs.h | 16 +- test/run | 9 +- tools/Makefile | 3 + tools/binman/README | 25 +- tools/binman/README.entries | 204 +- tools/binman/binman.py | 52 +- tools/binman/bsection.py | 42 +- tools/binman/cbfs_util.py | 861 ++++++ tools/binman/cbfs_util_test.py | 625 +++++ tools/binman/cmdline.py | 8 +- tools/binman/control.py | 3 + tools/binman/elf.py | 174 ++ tools/binman/elf_test.py | 41 + tools/binman/entry.py | 38 +- tools/binman/etype/blob.py | 16 +- tools/binman/etype/cbfs.py | 205 ++ tools/binman/etype/intel_descriptor.py | 16 +- tools/binman/etype/intel_ifwi.py | 100 + tools/binman/etype/intel_me.py | 2 + tools/binman/etype/text.py | 23 +- tools/binman/etype/u_boot_spl_elf.py | 2 +- tools/binman/etype/u_boot_tpl_elf.py | 24 + tools/binman/ftest.py | 266 +- tools/binman/test/066_text.dts | 5 + tools/binman/test/096_elf.dts | 2 + tools/binman/test/102_cbfs_raw.dts | 20 + tools/binman/test/103_cbfs_raw_ppc.dts | 21 + tools/binman/test/104_cbfs_stage.dts | 19 + tools/binman/test/105_cbfs_raw_compress.dts | 26 + tools/binman/test/106_cbfs_bad_arch.dts | 15 + tools/binman/test/107_cbfs_no_size.dts | 13 + tools/binman/test/108_cbfs_no_contents.dts | 17 + tools/binman/test/109_cbfs_bad_compress.dts | 18 + tools/binman/test/110_cbfs_name.dts | 24 + tools/binman/test/111_x86-rom-ifwi.dts | 29 + tools/binman/test/112_x86-rom-ifwi-nodesc.dts | 28 + tools/binman/test/113_x86-rom-ifwi-nodata.dts | 29 + tools/binman/test/114_cbfs_offset.dts | 26 + tools/binman/test/fitimage.bin.gz | Bin 0 -> 8418 bytes tools/binman/test/ifwi.bin.gz | Bin 0 -> 1884 bytes tools/ifwitool.c | 2314 +++++++++++++++++ tools/patman/command.py | 4 +- tools/patman/tools.py | 141 +- 45 files changed, 5434 insertions(+), 79 deletions(-) create mode 100644 tools/binman/cbfs_util.py create mode 100755 tools/binman/cbfs_util_test.py create mode 100644 tools/binman/etype/cbfs.py create mode 100644 tools/binman/etype/intel_ifwi.py create mode 100644 tools/binman/etype/u_boot_tpl_elf.py create mode 100644 tools/binman/test/102_cbfs_raw.dts create mode 100644 tools/binman/test/103_cbfs_raw_ppc.dts create mode 100644 tools/binman/test/104_cbfs_stage.dts create mode 100644 tools/binman/test/105_cbfs_raw_compress.dts create mode 100644 tools/binman/test/106_cbfs_bad_arch.dts create mode 100644 tools/binman/test/107_cbfs_no_size.dts create mode 100644 tools/binman/test/108_cbfs_no_contents.dts create mode 100644 tools/binman/test/109_cbfs_bad_compress.dts create mode 100644 tools/binman/test/110_cbfs_name.dts create mode 100644 tools/binman/test/111_x86-rom-ifwi.dts create mode 100644 tools/binman/test/112_x86-rom-ifwi-nodesc.dts create mode 100644 tools/binman/test/113_x86-rom-ifwi-nodata.dts create mode 100644 tools/binman/test/114_cbfs_offset.dts create mode 100644 tools/binman/test/fitimage.bin.gz create mode 100644 tools/binman/test/ifwi.bin.gz create mode 100644 tools/ifwitool.c
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 1/37 x86: Add ifwitool for Intel Integrated Firmware Image
Some Intel SoCs from about 2016 boot using an internal microcontroller via an 'IFWI' image. This is a special format which can hold firmware images. In U-Boot's case it holds u-boot-tpl.bin.
Add this tool, taken from coreboot, so that we can build bootable images on apollolake SoCs.
This tool itself has no tests. Some amount of coverage will be provided by the binman tests that use it, so enable building the tool on sandbox.
---
Changes in v2: None
tools/Makefile | 3 + tools/ifwitool.c | 2314 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 2317 insertions(+) create mode 100644 tools/ifwitool.c
tools/Makefile +3 -0
@@ -175,6 +175,9 @@ HOSTCFLAGS_mkexynosspl.o := -pedantic ifdtool-objs := $(LIBFDT_OBJS) ifdtool.o hostprogs-$(CONFIG_X86) += ifdtool +ifwitool-objs := ifwitool.o +hostprogs-$(CONFIG_X86)$(CONFIG_SANDBOX) += ifwitool + hostprogs-$(CONFIG_MX23) += mxsboot hostprogs-$(CONFIG_MX28) += mxsboot HOSTCFLAGS_mxsboot.o := -pedantic
tools/ifwitool.c new file +2314 -0
2,314 lines not on this page · raw message
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 2/37 cbfs: Add an enum and comment for the magic number
In reply to Simon GlassThis field is not commented in the original file. Add a comment.
---
Changes in v2: None
include/cbfs.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
include/cbfs.h +11 -0
@@ -40,6 +40,17 @@ enum cbfs_filetype {CBFS_TYPE_CMOS_LAYOUT =0x01aa }; +enum { +CBFS_HEADER_MAGIC =0x4f524243 , +}; + +/** +* struct cbfs_header - header at the start of a CBFS region +* +* All fields use big-endian format. +* +* @magic: Magic number (CBFS_HEADER_MAGIC) +*/ struct cbfs_header {u32 magic;u32 version;
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 3/37 cbfs: Rename checksum to attributes_offset
In reply to Simon GlassIt seems that this field has been renamed in later version of coreboot. Update it.
---
Changes in v2: None
fs/cbfs/cbfs.c | 4 ++-- include/cbfs.h | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-)
fs/cbfs/cbfs.c +2 -2
@@ -55,7 +55,7 @@ static void swap_file_header(struct cbfs_fileheader *dest,memcpy (&dest->magic, &src->magic,sizeof (dest->magic)); dest->len =be32_to_cpu (src->len); dest->type =be32_to_cpu (src->type); - dest->checksum =be32_to_cpu (src->checksum); + dest->attributes_offset =be32_to_cpu (src->attributes_offset); dest->offset =be32_to_cpu (src->offset); }
@@ -108,7 +108,7 @@ static int file_cbfs_next_file(u8 *start, u32 size, u32 align, newNode->name = (char *)fileHeader +sizeof (struct cbfs_fileheader ); newNode->name_length = name_len; - newNode->checksum = header.checksum; + newNode->attributes_offset = header.attributes_offset; step = header.len;if (step % align)
include/cbfs.h +3 -2
@@ -65,7 +65,8 @@ struct cbfs_fileheader {u8 magic[8 ];u32 len;u32 type; -u32 checksum; +/* offset to struct cbfs_file_attribute or 0 */ +u32 attributes_offset;u32 offset; } __packed;
@@ -76,7 +77,7 @@ struct cbfs_cachenode {u32 data_length;char *name;u32 name_length; -u32 checksum; +u32 attributes_offset; } __packed;extern enum cbfs_result file_cbfs_result;
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 4/37 tools: Drop duplicate raise_on_error argument
In reply to Simon GlassIf kwargs contains raise_on_error then this function generates an error due to a duplicate argument. Fix this.
---
Changes in v2: None
tools/patman/command.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/patman/command.py +2 -2
@@ -108,8 +108,8 @@ def RunPipe(pipe_list, infile=None, outfile=None, return result def Output(*cmd, **kwargs): - raise_on_error = kwargs.get('raise_on_error', True) - return RunPipe([cmd], capture=True, raise_on_error=raise_on_error).stdout + kwargs['raise_on_error'] = kwargs.get('raise_on_error', True) + return RunPipe([cmd], capture=True, **kwargs).stdout def OutputOneLine(*cmd, **kwargs): raise_on_error = kwargs.pop('raise_on_error', True)
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 5/37 binman: Fix comment in bsection.GetEntries()
In reply to Simon GlassThis comment is out of date as it does not correctly describe the return value. Fix it.
---
Changes in v2: None
tools/binman/bsection.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/binman/bsection.py +2 -2
@@ -399,10 +399,10 @@ class Section(object): raise ValueError("%s: No such property '%s'" % (msg, prop_name)) def GetEntries(self): - """Get the number of entries in a section + """Get the dict of entries in a section Returns: - Number of entries in a section + OrderedDict of entries in a section """ return self._entries
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 6/37 binman: Correct two typos in function names in ftest
In reply to Simon GlassTwo functions have incorrect names. Fix them.
---
Changes in v2: None
tools/binman/ftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/binman/ftest.py +2 -2
@@ -1758,7 +1758,7 @@ class TestFunctional(unittest.TestCase): TestFunctional._MakeInputFile('-boot', fd.read()) data = self._DoReadFile('096_elf.dts') - def testElfStripg(self): + def testElfStrip(self): """Basic test of ELF entries""" self._SetupSplElf() with open(self.TestFile('bss_data'), 'rb') as fd:
@@ -1784,7 +1784,7 @@ class TestFunctional(unittest.TestCase): <none> 00000003 00000004 u-boot-align ''', map_data) - def testPacRefCode(self): + def testPackRefCode(self): """Test that an image with an Intel Reference code binary works""" data = self._DoReadFile('100_intel_refcode.dts') self.assertEqual(REFCODE_DATA, data[:len(REFCODE_DATA)])
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 7/37 binman: Add coverage tools info for Python 3
In reply to Simon GlassTest coverage with Python 3 requires a new package. Add details about this.
---
Changes in v2: None
tools/binman/README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/binman/README +1 -1
@@ -699,7 +699,7 @@ implementations target 100% test coverage. Run 'binman -T' to check this. To enable Python test coverage on Debian-type distributions (e.g. Ubuntu): - $ sudo apt-get install python-coverage python-pytest + $ sudo apt-get install python-coverage python3-coverage python-pytest Concurrent tests
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 8/37 patman: Add a way to set the search path for tools
In reply to Simon GlassSometimes tools can be located by looking in other locations. Add a way to direct the search.
---
Changes in v2: None
tools/patman/tools.py | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-)
tools/patman/tools.py +37 -5
@@ -24,6 +24,8 @@ chroot_path = None # Search paths to use for Filename(), used to find files search_paths = [] +tool_search_paths = [] + # Tools and the packages that contain them, on debian packages = { 'lz4': 'liblz4-tool',
@@ -154,26 +156,56 @@ def Align(pos, align): def NotPowerOfTwo(num): return num and (num & (num - 1)) -def PathHasFile(fname): +def SetToolPaths(toolpaths): + """Set the path to search for tools + + Args: + toolpaths: List of paths to search for tools executed by Run() + """ + global tool_search_paths + + tool_search_paths = toolpaths + +def PathHasFile(path_spec, fname): """Check if a given filename is in the PATH Args: + path_spec: Value of PATH variable to check fname: Filename to check Returns: True if found, False if not """ - for dir in os.environ['PATH'].split(':'): + for dir in path_spec.split(':'): if os.path.exists(os.path.join(dir, fname)): return True return False def Run(name, *args, **kwargs): + """Run a tool with some arguments + + This runs a 'tool', which is a program used by binman to process files and + perhaps produce some output. Tools can be located on the PATH or in a + search path. + + Args: + name: Command name to run + args: Arguments to the tool + kwargs: Options to pass to command.run() + + Returns: + CommandResult object + """ try: - return command.Run(name, *args, cwd=outdir, capture=True, **kwargs) + env = None + if tool_search_paths: + env = dict(os.environ) + env['PATH'] = ':'.join(tool_search_paths) + ':' + env['PATH'] + return command.Run(name, *args, capture=True, + capture_stderr=True, env=env, **kwargs) except: - if not PathHasFile(name): - msg = "Plesae install tool '%s'" % name + if env and not PathHasFile(env['PATH'], name): + msg = "Please install tool '%s'" % name package = packages.get(name) if package: msg += " (e.g. from package '%s')" % package
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 9/37 binman: Add a --toolpath option to set the tool search path
In reply to Simon GlassSometimes tools used by binman may not be in the normal PATH search path, such as when the tool is built by the U-Boot build itself (e.g. mkimage). Provide a way to specify an additional search path for tools. The flag can be used multiple times.
Update the help to describe this option.
---
Changes in v2: None
tools/binman/README | 10 ++++++++++ tools/binman/cmdline.py | 2 ++ tools/binman/control.py | 1 + 3 files changed, 13 insertions(+)
tools/binman/README +10 -0
@@ -691,6 +691,16 @@ Not all properties can be provided this way. Only some entries support it, typically for filenames. +External tools +-------------- + +Binman can make use of external command-line tools to handle processing of +entry contents or to generate entry contents. These tools are executed using +the 'tools' module's Run() method. The tools generally must exist on the PATH, +but the --toolpath option can be used to specify additional search paths to +use. This option can be specified multiple times to add more than one path. + + Code coverage -------------
tools/binman/cmdline.py +2 -0
@@ -52,6 +52,8 @@ def ParseArgs(argv): default=False, help='run tests') parser.add_option('-T', '--test-coverage', action='store_true', default=False, help='run tests and check for 100% coverage') + parser.add_option('--toolpath', type='string', action='append', + help='Add a path to the directories containing tools') parser.add_option('-u', '--update-fdt', action='store_true', default=False, help='Update the binman node with offset/size info') parser.add_option('-v', '--verbosity', default=1,
tools/binman/control.py +1 -0
@@ -112,6 +112,7 @@ def Binman(options, args): try: tools.SetInputDirs(options.indir) tools.PrepareOutputDir(options.outdir, options.preserve) + tools.SetToolPaths(options.toolpath) state.SetEntryArgs(options.entry_arg) # Get the device tree ready by compiling it and copying the compiled
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 10/37 binman: Add missing comments to bsection
In reply to Simon GlassSome functions lack comments in this file. Add comments to cover this functionality.
---
Changes in v2: None
tools/binman/bsection.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
tools/binman/bsection.py +23 -0
@@ -452,13 +452,36 @@ class Section(object): source_entry.Raise("Cannot find entry for node '%s'" % node.name) def ExpandSize(self, size): + """Change the size of an entry + + Args: + size: New size for entry + """ if size != self._size: self._size = size def GetRootSkipAtStart(self): + """Get the skip-at-start value for the top-level section + + This is used to find out the starting offset for root section that + contains this section. If this is a top-level section then it returns + the skip-at-start offset for this section. + + This is used to get the absolute position of section within the image. + + Returns: + Integer skip-at-start value for the root section containing this + section + """ if self._parent_section: return self._parent_section.GetRootSkipAtStart() return self._skip_at_start def GetImageSize(self): + """Get the size of the image containing this section + + Returns: + Image size as an integer number of bytes, which may be None if the + image size is dynamic and its sections have not yet been packed + """ return self._image._size
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 11/37 binman: Add missing comments toentry
In reply to Simon GlassAt present GetOffsets() lacks a function comment. Add one.
---
Changes in v2: None
tools/binman/entry.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
tools/binman/entry.py +15 -0
@@ -355,6 +355,21 @@ class Entry(object): return self.data def GetOffsets(self): + """Get the offsets for siblings + + Some entry types can contain information about the position or size of + other entries. An example of this is the Intel Flash Descriptor, which + knows where the Intel Management Engine section should go. + + If this entry knows about the position of other entries, it can specify + this by returning values here + + Returns: + Dict: + key: Entry type + value: List containing position and size of the given entry + type. + """ return {} def SetOffsetSize(self, pos, size):
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 11/37 binman: Add missing comments toentry
At present GetOffsets() lacks a function comment. Add one.
---
Changes in v2: None
tools/binman/entry.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
Applied to u-boot-dm, thanks!
PATCH v2 12/37 binman: Tidy up help for --indir
In reply to Simon GlassThe current help is confusing. Adjust it to indicate what the flag actually does.
---
Changes in v2: None
tools/binman/cmdline.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/binman/cmdline.py +1 -1
@@ -35,7 +35,7 @@ def ParseArgs(argv): parser.add_option('-i', '--image', type='string', action='append', help='Image filename to build (if not specified, build all)') parser.add_option('-I', '--indir', action='append', - help='Add a path to a directory to use for input files') + help='Add a path to the list of directories to use for input files') parser.add_option('-H', '--full-help', action='store_true', default=False, help='Display the README file') parser.add_option('-m', '--map', action='store_true',
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 12/37 binman: Tidy up help for --indir
The current help is confusing. Adjust it to indicate what the flag actually does.
---
Changes in v2: None
tools/binman/cmdline.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied to u-boot-dm, thanks!
PATCH v2 13/37 binman: Use a better error for missing Intel descriptor
In reply to Simon GlassFD is a bit confusing so write this out in full. Also avoid splitting the string so that people can grep for the error message more easily.
---
Changes in v2: None
tools/binman/etype/intel_descriptor.py | 2 +- tools/binman/ftest.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
tools/binman/etype/intel_descriptor.py +1 -1
@@ -51,7 +51,7 @@ class Entry_intel_descriptor(Entry_blob): def GetOffsets(self): offset = self.data.find(FD_SIGNATURE) if offset == -1: - self.Raise('Cannot find FD signature') + self.Raise('Cannot find Intel Flash Descriptor (FD) signature') flvalsig, flmap0, flmap1, flmap2 = struct.unpack('<LLLL', self.data[offset:offset + 16]) frba = ((flmap0 >> 16) & 0xff) << 4
tools/binman/ftest.py +2 -2
@@ -806,8 +806,8 @@ class TestFunctional(unittest.TestCase): TestFunctional._MakeInputFile('descriptor.bin', b'') with self.assertRaises(ValueError) as e: self._DoTestFile('031_x86-rom-me.dts') - self.assertIn("Node '/binman/intel-descriptor': Cannot find FD " - "signature", str(e.exception)) + self.assertIn("Node '/binman/intel-descriptor': Cannot find Intel Flash Descriptor (FD) signature", + str(e.exception)) def testPackX86RomBadDesc(self): """Test that the Intel requires a descriptor entry"""
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 13/37 binman: Use a better error for missing Intel descriptor
FD is a bit confusing so write this out in full. Also avoid splitting the string so that people can grep for the error message more easily.
---
Changes in v2: None
tools/binman/etype/intel_descriptor.py | 2 +- tools/binman/ftest.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
Applied to u-boot-dm, thanks!
PATCH v2 14/37 binman: Detect skipped tests
In reply to Simon GlassIf tests are skipped we should ideally exit with an error, since there may be a missing dependency. However at present this is not desirable since it breaks travis tests. For now, just report the skips.
---
Changes in v2: None
tools/binman/binman.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
tools/binman/binman.py +7 -2
@@ -104,9 +104,14 @@ def RunTests(debug, processes, args): print(test.id(), err) for test, err in result.failures: print(err, result.failures) + if result.skipped: + print('%d binman test%s SKIPPED:' % + (len(result.skipped), 's' if len(result.skipped) > 1 else '')) + for skip_info in result.skipped: + print('%s: %s' % (skip_info[0], skip_info[1])) if result.errors or result.failures: - print('binman tests FAILED') - return 1 + print('binman tests FAILED') + return 1 return 0 def GetEntryModules(include_testing=True):
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 14/37 binman: Detect skipped tests
If tests are skipped we should ideally exit with an error, since there may be a missing dependency. However at present this is not desirable since it breaks travis tests. For now, just report the skips.
---
Changes in v2: None
tools/binman/binman.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
Applied to u-boot-dm, thanks!
PATCH v2 15/37 binman: Add a function to create a sample ELF file
In reply to Simon GlassIt is useful to create an ELF file for testing purposes, with just the right attributes used by the test. Add a function to handle this, along with a test that it works correctly.
---
Changes in v2: None
tools/binman/elf.py | 98 ++++++++++++++++++++++++++++++++++++++++ tools/binman/elf_test.py | 20 ++++++++ 2 files changed, 118 insertions(+)
tools/binman/elf.py +98 -0
@@ -5,11 +5,15 @@ # Handle various things related to ELF images # +from __future__ import print_function + from collections import namedtuple, OrderedDict import command import os import re +import shutil import struct +import tempfile import tools
@@ -128,3 +132,97 @@ def LookupAndWriteSymbols(elf_fname, entry, section): (msg, name, offset, value, len(value_bytes))) entry.data = (entry.data[:offset] + value_bytes + entry.data[offset + sym.size:]) + +def MakeElf(elf_fname, text, data): + """Make an elf file with the given data in a single section + + The output file has a several section including '.text' and '.data', + containing the info provided in arguments. + + Args: + elf_fname: Output filename + text: Text (code) to put in the file's .text section + data: Data to put in the file's .data section + """ + outdir = tempfile.mkdtemp(prefix='binman.elf.') + s_file = os.path.join(outdir, 'elf.S') + + # Spilt the text into two parts so that we can make the entry point two + # bytes after the start of the text section + text_bytes1 = ['\t.byte\t%#x' % tools.ToByte(byte) for byte in text[:2]] + text_bytes2 = ['\t.byte\t%#x' % tools.ToByte(byte) for byte in text[2:]] + data_bytes = ['\t.byte\t%#x' % tools.ToByte(byte) for byte in data] + with open(s_file, 'w') as fd: + print('''/* Auto-generated C program to produce an ELF file for testing */ + +.section .text +.code32 +.globl _start +.type _start, @function +%s +_start: +%s +.ident "comment" + +.comm fred,8,4 + +.section .empty +.globl _empty +_empty: +.byte 1 + +.globl ernie +.data +.type ernie, @object +.size ernie, 4 +ernie: +%s +''' % ('\n'.join(text_bytes1), '\n'.join(text_bytes2), '\n'.join(data_bytes)), + file=fd) + lds_file = os.path.join(outdir, 'elf.lds') + + # Use a linker script to set the alignment and text address. + with open(lds_file, 'w') as fd: + print('''/* Auto-generated linker script to produce an ELF file for testing */ + +PHDRS +{ + text PT_LOAD ; + data PT_LOAD ; + empty PT_LOAD FLAGS ( 6 ) ; + note PT_NOTE ; +} + +SECTIONS +{ + . = 0xfef20000; + ENTRY(_start) + .text . : SUBALIGN(0) + { + *(.text) + } :text + .data : { + *(.data) + } :data + _bss_start = .; + .empty : { + *(.empty) + } :empty + .note : { + *(.comment) + } :note + .bss _bss_start (OVERLAY) : { + *(.bss) + } +} +''', file=fd) + # -static: Avoid requiring any shared libraries + # -nostdlib: Don't link with C library + # -Wl,--build-id=none: Don't generate a build ID, so that we just get the + # text section at the start + # -m32: Build for 32-bit x86 + # -T...: Specifies the link script, which sets the start address + stdout = command.Output('cc', '-static', '-nostdlib', '-Wl,--build-id=none', + '-m32','-T', lds_file, '-o', elf_fname, s_file) + shutil.rmtree(outdir) +
tools/binman/elf_test.py +20 -0
@@ -5,9 +5,12 @@ # Test for the elf module import os +import shutil import sys +import tempfile import unittest +import command import elf import test_util import tools
@@ -136,6 +139,23 @@ class TestElf(unittest.TestCase): elf.debug = False self.assertTrue(len(stdout.getvalue()) > 0) + def testMakeElf(self): + """Test for the MakeElf function""" + outdir = tempfile.mkdtemp(prefix='elf.') + expected_text = b'1234' + expected_data = b'wxyz' + elf_fname = os.path.join(outdir, 'elf') + bin_fname = os.path.join(outdir, 'elf') + + # Make an Elf file and then convert it to a fkat binary file. This + # should produce the original data. + elf.MakeElf(elf_fname, expected_text, expected_data) + stdout = command.Output('objcopy', '-O', 'binary', elf_fname, bin_fname) + with open(bin_fname, 'rb') as fd: + data = fd.read() + self.assertEqual(expected_text + expected_data, data) + shutil.rmtree(outdir) + if __name__ == '__main__': unittest.main()
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 15/37 binman: Add a function to create a sample ELF file
It is useful to create an ELF file for testing purposes, with just the right attributes used by the test. Add a function to handle this, along with a test that it works correctly.
---
Changes in v2: None
tools/binman/elf.py | 98 ++++++++++++++++++++++++++++++++++++++++ tools/binman/elf_test.py | 20 ++++++++ 2 files changed, 118 insertions(+)
Applied to u-boot-dm, thanks!
PATCH v2 16/37 binman: Add a function to decode an ELF file
In reply to Simon GlassAdd a function which decodes an ELF file, working out where in memory each part of the data should be written.
---
Changes in v2: None
tools/binman/README | 4 +++ tools/binman/elf.py | 76 ++++++++++++++++++++++++++++++++++++++++ tools/binman/elf_test.py | 21 +++++++++++ 3 files changed, 101 insertions(+)
tools/binman/README +4 -0
@@ -181,6 +181,10 @@ the configuration of the Intel-format descriptor. Running binman -------------- +First install prerequisites, e.g. + + sudo apt-get install python-pyelftools python3-pyelftools + Type: binman -b <board_name>
tools/binman/elf.py +76 -0
96 lines not on this page · raw message
tools/binman/elf_test.py +21 -0
@@ -156,6 +156,27 @@ class TestElf(unittest.TestCase): self.assertEqual(expected_text + expected_data, data) shutil.rmtree(outdir) + def testDecodeElf(self): + """Test for the MakeElf function""" + if not elf.ELF_TOOLS: + self.skipTest('Python elftools not available') + outdir = tempfile.mkdtemp(prefix='elf.') + expected_text = b'1234' + expected_data = b'wxyz' + elf_fname = os.path.join(outdir, 'elf') + elf.MakeElf(elf_fname, expected_text, expected_data) + data = tools.ReadFile(elf_fname) + + load = 0xfef20000 + entry = load + 2 + expected = expected_text + expected_data + self.assertEqual(elf.ElfInfo(expected, load, entry, len(expected)), + elf.DecodeElf(data, 0)) + self.assertEqual(elf.ElfInfo(b'\0\0' + expected[2:], + load, entry, len(expected)), + elf.DecodeElf(data, load + 2)) + #shutil.rmtree(outdir) + if __name__ == '__main__': unittest.main()
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 16/37 binman: Add a function to decode an ELF file
Add a function which decodes an ELF file, working out where in memory each part of the data should be written.
---
Changes in v2: None
tools/binman/README | 4 +++ tools/binman/elf.py | 76 ++++++++++++++++++++++++++++++++++++++++ tools/binman/elf_test.py | 21 +++++++++++ 3 files changed, 101 insertions(+)
Applied to u-boot-dm, thanks!
PATCH v2 17/37 binman: Ensure that coverage has access to site packages
In reply to Simon GlassCode coverage tests fail on binman due to dist-packages being dropped from the python path on Ubuntu 16.04. Add them in so that we can find the elffile module, which is required by binman.
---
Changes in v2: None
tools/binman/binman.py | 8 ++++++++ 1 file changed, 8 insertions(+)
tools/binman/binman.py +8 -0
@@ -11,9 +11,11 @@ from __future__ import print_function +from distutils.sysconfig import get_python_lib import glob import multiprocessing import os +import site import sys import traceback import unittest
@@ -28,6 +30,12 @@ sys.path.insert(0, 'scripts/dtc/pylibfdt') sys.path.insert(0, os.path.join(our_path, '../../build-sandbox_spl/scripts/dtc/pylibfdt')) +# When running under python-coverage on Ubuntu 16.04, the dist-packages +# directories are dropped from the python path. Add them in so that we can find +# the elffile module. We could use site.getsitepackages() here but unfortunately +# that is not available in a virtualenv. +sys.path.append(get_python_lib()) + import cmdline import command use_concurrent = True
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 17/37 binman: Ensure that coverage has access to site packages
Code coverage tests fail on binman due to dist-packages being dropped from the python path on Ubuntu 16.04. Add them in so that we can find the elffile module, which is required by binman.
---
Changes in v2: None
tools/binman/binman.py | 8 ++++++++ 1 file changed, 8 insertions(+)
Applied to u-boot-dm, thanks!
PATCH v2 18/37 binman: Assume Intel descriptor is at the start of the image
In reply to Simon GlassAt present binman requires that the Intel descriptor has an explicit offset. Generally this is 0 since the descriptor is at the start of the image. Add a default to handle this, so users don't need to specify the offset.
---
Changes in v2: None
tools/binman/bsection.py | 8 ++++++++ tools/binman/etype/intel_descriptor.py | 2 ++ 2 files changed, 10 insertions(+)
tools/binman/bsection.py +8 -0
@@ -477,6 +477,14 @@ class Section(object): return self._parent_section.GetRootSkipAtStart() return self._skip_at_start + def GetStartOffset(self): + """Get the start offset for this section + + Returns: + The first available offset in this section (typically 0) + """ + return self._skip_at_start + def GetImageSize(self): """Get the size of the image containing this section
tools/binman/etype/intel_descriptor.py +2 -0
@@ -47,6 +47,8 @@ class Entry_intel_descriptor(Entry_blob): def __init__(self, section, etype, node): Entry_blob.__init__(self, section, etype, node) self._regions = [] + if self.offset is None: + self.offset = self.section.GetStartOffset() def GetOffsets(self): offset = self.data.find(FD_SIGNATURE)
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 18/37 binman: Assume Intel descriptor is at the start of the image
At present binman requires that the Intel descriptor has an explicit offset. Generally this is 0 since the descriptor is at the start of the image. Add a default to handle this, so users don't need to specify the offset.
---
Changes in v2: None
tools/binman/bsection.py | 8 ++++++++ tools/binman/etype/intel_descriptor.py | 2 ++ 2 files changed, 10 insertions(+)
Applied to u-boot-dm, thanks!
PATCH v2 19/37 binman: Don't assume there is an ME region
In reply to Simon GlassAt present having a descriptor means that there is an ME (Intel Management Engine) entry as well. The descriptor provides the ME location and assumes that it is present.
For some SoCs this is not true. Before providing the location of a potentially non-existent entry, check if it is present.
Update the comment in the ME entry also.
---
Changes in v2: None
tools/binman/README.entries | 2 ++ tools/binman/entry.py | 9 +++++++++ tools/binman/etype/intel_descriptor.py | 10 +++++++--- tools/binman/etype/intel_me.py | 2 ++ 4 files changed, 20 insertions(+), 3 deletions(-)
tools/binman/README.entries +2 -0
@@ -206,6 +206,8 @@ does not directly execute code in the ME binary. A typical filename is 'me.bin'. +The position of this entry is generally set by the intel-descriptor entry. + See README.x86 for information about x86 binary blobs.
tools/binman/entry.py +9 -0
@@ -544,3 +544,12 @@ features to produce new behaviours. # the data grows. This should not fail, but check it to be sure. if not self.ObtainContents(): self.Raise('Cannot obtain contents when expanding entry') + + def HasSibling(self, name): + """Check if there is a sibling of a given name + + Returns: + True if there is an entry with this name in the the same section, + else False + """ + return name in self.section.GetEntries()
tools/binman/etype/intel_descriptor.py +7 -3
@@ -60,6 +60,10 @@ class Entry_intel_descriptor(Entry_blob): for i in range(MAX_REGIONS): self._regions.append(Region(self.data, frba, i)) - # Set the offset for ME only, for now, since the others are not used - return {'intel-me': [self._regions[REGION_ME].base, - self._regions[REGION_ME].size]} + # Set the offset for ME (Management Engine) only, for now, since the + # others are not used + info = {} + if self.HasSibling('intel-me'): + info['intel-me'] = [self._regions[REGION_ME].base, + self._regions[REGION_ME].size] + return info
tools/binman/etype/intel_me.py +2 -0
@@ -22,6 +22,8 @@ class Entry_intel_me(Entry_blob): A typical filename is 'me.bin'. + The position of this entry is generally set by the intel-descriptor entry. + See README.x86 for information about x86 binary blobs. """ def __init__(self, section, etype, node):
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 19/37 binman: Don't assume there is an ME region
At present having a descriptor means that there is an ME (Intel Management Engine) entry as well. The descriptor provides the ME location and assumes that it is present.
For some SoCs this is not true. Before providing the location of a potentially non-existent entry, check if it is present.
Update the comment in the ME entry also.
---
Changes in v2: None
tools/binman/README.entries | 2 ++ tools/binman/entry.py | 9 +++++++++ tools/binman/etype/intel_descriptor.py | 10 +++++++--- tools/binman/etype/intel_me.py | 2 ++ 4 files changed, 20 insertions(+), 3 deletions(-)
Applied to u-boot-dm, thanks!
PATCH v2 20/37 binman: Update entry.SetOffsetSize to be optional
In reply to Simon GlassAt present this function always sets both the offset and the size of entries. But in some cases we want to set only one or the other, for example with the forthcoming ifwi entry, where we only set the offset. Update the function to handle this.
---
Changes in v2: None
tools/binman/bsection.py | 7 ++++--- tools/binman/entry.py | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-)
tools/binman/bsection.py +4 -3
@@ -236,14 +236,15 @@ class Section(object): Args: name: Entry name to update - offset: New offset - size: New size + offset: New offset, or None to leave alone + size: New size, or None to leave alone """ entry = self._entries.get(name) if not entry: self._Raise("Unable to set offset/size for unknown entry '%s'" % name) - entry.SetOffsetSize(self._skip_at_start + offset, size) + entry.SetOffsetSize(self._skip_at_start + offset if offset else None, + size) def GetEntryOffsets(self): """Handle entries that want to set the offset/size of other entries
tools/binman/entry.py +12 -4
@@ -368,13 +368,21 @@ class Entry(object): Dict: key: Entry type value: List containing position and size of the given entry - type. + type. Either can be None if not known """ return {} - def SetOffsetSize(self, pos, size): - self.offset = pos - self.size = size + def SetOffsetSize(self, offset, size): + """Set the offset and/or size of an entry + + Args: + offset: New offset, or None to leave alone + size: New size, or None to leave alone + """ + if offset is not None: + self.offset = offset + if size is not None: + self.size = size def SetImagePos(self, image_pos): """Set the position in the image
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 20/37 binman: Update entry.SetOffsetSize to be optional
At present this function always sets both the offset and the size of entries. But in some cases we want to set only one or the other, for example with the forthcoming ifwi entry, where we only set the offset. Update the function to handle this.
---
Changes in v2: None
tools/binman/bsection.py | 7 ++++--- tools/binman/entry.py | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-)
Applied to u-boot-dm, thanks!
PATCH v2 21/37 binman: Allow text directly in the node
In reply to Simon GlassAt present text entries use an indirect method to specify the text to use, with a label pointing to the text itself.
Allow the text to be directly written into the node. This is more convenient in cases where the text is constant.
---
Changes in v2: None
tools/binman/README.entries | 9 +++++++++ tools/binman/etype/text.py | 23 +++++++++++++++++++---- tools/binman/ftest.py | 2 +- tools/binman/test/066_text.dts | 5 +++++ 4 files changed, 34 insertions(+), 5 deletions(-)
tools/binman/README.entries +9 -0
@@ -312,6 +312,8 @@ Properties / Entry arguments: that contains the string to place in the entry <xxx> (actual name is the value of text-label): contains the string to place in the entry. + <text>: The text to place in the entry (overrides the above mechanism). + This is useful when the text is constant. Example node:
@@ -334,6 +336,13 @@ It is also possible to put the string directly in the node: message = "a message directly in the node" }; +or just: + + text { + size = <8>; + text = "some text directly in the node" + }; + The text is not itself nul-terminated. This can be achieved, if required, by setting the size of the entry to something larger than the text.
tools/binman/etype/text.py +19 -4
@@ -22,6 +22,8 @@ class Entry_text(Entry): that contains the string to place in the entry <xxx> (actual name is the value of text-label): contains the string to place in the entry. + <text>: The text to place in the entry (overrides the above mechanism). + This is useful when the text is constant. Example node:
@@ -44,15 +46,28 @@ class Entry_text(Entry): message = "a message directly in the node" }; + or just: + + text { + size = <8>; + text = "some text directly in the node" + }; + The text is not itself nul-terminated. This can be achieved, if required, by setting the size of the entry to something larger than the text. """ def __init__(self, section, etype, node): Entry.__init__(self, section, etype, node) - label, = self.GetEntryArgsOrProps([EntryArg('text-label', str)]) - self.text_label = tools.ToStr(label) if type(label) != str else label - value, = self.GetEntryArgsOrProps([EntryArg(self.text_label, str)]) - value = tools.ToBytes(value) if value is not None else value + value = fdt_util.GetString(self._node, 'text') + if value: + value = tools.ToBytes(value) + else: + label, = self.GetEntryArgsOrProps([EntryArg('text-label', str)]) + self.text_label = label + if self.text_label: + value, = self.GetEntryArgsOrProps([EntryArg(self.text_label, + str)]) + value = tools.ToBytes(value) if value is not None else value self.value = value def ObtainContents(self):
tools/binman/ftest.py +1 -1
@@ -1286,7 +1286,7 @@ class TestFunctional(unittest.TestCase): expected = (tools.ToBytes(TEXT_DATA) + tools.GetBytes(0, 8 - len(TEXT_DATA)) + tools.ToBytes(TEXT_DATA2) + tools.ToBytes(TEXT_DATA3) + - b'some text') + b'some text' + b'more text') self.assertEqual(expected, data) def testEntryDocs(self):
tools/binman/test/066_text.dts +5 -0
@@ -24,5 +24,10 @@ text-label = "test-id4"; test-id4 = "some text"; }; + /* Put text directly in the node */ + text5 { + type = "text"; + text = "more text"; + }; }; };
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 21/37 binman: Allow text directly in the node
At present text entries use an indirect method to specify the text to use, with a label pointing to the text itself.
Allow the text to be directly written into the node. This is more convenient in cases where the text is constant.
---
Changes in v2: None
tools/binman/README.entries | 9 +++++++++ tools/binman/etype/text.py | 23 +++++++++++++++++++---- tools/binman/ftest.py | 2 +- tools/binman/test/066_text.dts | 5 +++++ 4 files changed, 34 insertions(+), 5 deletions(-)
Applied to u-boot-dm, thanks!
PATCH v2 22/37 patman: Add functions to compress and decompress data
In reply to Simon GlassAdd utility functions to compress and decompress using lz4 and lzma algorithms. In the latter case these use the legacy lzma support favoured by coreboot's CBFS.
No tests are provided as these functions will be tested by the CBFS tests in a separate patch.
---
Changes in v2: None
tools/binman/README | 3 +- tools/patman/tools.py | 66 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-)
tools/binman/README +2 -1
@@ -183,7 +183,8 @@ Running binman First install prerequisites, e.g. - sudo apt-get install python-pyelftools python3-pyelftools + sudo apt-get install python-pyelftools python3-pyelftools lzma-alone \ + liblz4-tool Type:
tools/patman/tools.py +66 -0
69 lines not on this page · raw message
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 22/37 patman: Add functions to compress and decompress data
Add utility functions to compress and decompress using lz4 and lzma algorithms. In the latter case these use the legacy lzma support favoured by coreboot's CBFS.
No tests are provided as these functions will be tested by the CBFS tests in a separate patch.
---
Changes in v2: None
tools/binman/README | 3 +- tools/patman/tools.py | 66 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-)
Applied to u-boot-dm, thanks!
PATCH v2 23/37 binman: Use the tools.Decompress method
In reply to Simon GlassUpdate the compression test to use the tools module to decompress the output data.
---
Changes in v2: None
tools/binman/ftest.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)
tools/binman/ftest.py +2 -11
@@ -59,7 +59,7 @@ BMPBLK_DATA = b'bmp' VBLOCK_DATA = b'vblk' FILES_DATA = (b"sorry I'm late\nOh, don't bother apologising, I'm " + b"sorry you're alive\n") -COMPRESS_DATA = b'data to compress' +COMPRESS_DATA = b'compress xxxxxxxxxxxxxxxxxxxxxx data' REFCODE_DATA = b'refcode'
@@ -1560,16 +1560,7 @@ class TestFunctional(unittest.TestCase): self._ResetDtbs() def _decompress(self, data): - out = os.path.join(self._indir, 'lz4.tmp') - with open(out, 'wb') as fd: - fd.write(data) - return tools.Run('lz4', '-dc', out, binary=True) - ''' - try: - orig = lz4.frame.decompress(data) - except AttributeError: - orig = lz4.decompress(data) - ''' + return tools.Decompress(data, 'lz4') def testCompress(self): """Test compression of blobs"""
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 23/37 binman: Use the tools.Decompress method
Update the compression test to use the tools module to decompress the output data.
---
Changes in v2: None
tools/binman/ftest.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)
Applied to u-boot-dm, thanks!
PATCH v2 24/37 binman: Drop unnecessary debug handling
In reply to Simon GlassThe -D option enables debug mode, but we only need to add -D to the command line once. Drop the duplicate code. Also drop the comment about enabling debugging since this can be done with -D.
---
Changes in v2: None
tools/binman/binman.py | 5 ----- 1 file changed, 5 deletions(-)
tools/binman/binman.py +0 -5
@@ -71,8 +71,6 @@ def RunTests(debug, processes, args): sys.argv = [sys.argv[0]] if debug: sys.argv.append('-D') - if debug: - sys.argv.append('-D') # Run the entry tests first ,since these need to be the first to import the # 'entry' module.
@@ -151,9 +149,6 @@ def RunBinman(options, args): """ ret_code = 0 - # For testing: This enables full exception traces. - #options.debug = True - if not options.debug: sys.tracebacklimit = 0
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 24/37 binman: Drop unnecessary debug handling
The -D option enables debug mode, but we only need to add -D to the command line once. Drop the duplicate code. Also drop the comment about enabling debugging since this can be done with -D.
---
Changes in v2: None
tools/binman/binman.py | 5 ----- 1 file changed, 5 deletions(-)
Applied to u-boot-dm, thanks!
PATCH v2 25/37 binman: Use tools compression function for blob handling
In reply to Simon GlassAvoid duplicate code here by using the new compression function in the tools module.
---
Changes in v2: None
tools/binman/etype/blob.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
tools/binman/etype/blob.py +4 -12
@@ -49,18 +49,10 @@ class Entry_blob(Entry): # new Entry method which can read in chunks. Then we could copy # the data in chunks and avoid reading it all at once. For now # this seems like an unnecessary complication. - data = tools.ReadFile(self._pathname) - if self._compress == 'lz4': - self._uncompressed_size = len(data) - ''' - import lz4 # Import this only if needed (python-lz4 dependency) - - try: - data = lz4.frame.compress(data) - except AttributeError: - data = lz4.compress(data) - ''' - data = tools.Run('lz4', '-c', self._pathname, binary=True) + indata = tools.ReadFile(self._pathname) + if self._compress != 'none': + self._uncompressed_size = len(indata) + data = tools.Compress(indata, self._compress) self.SetContents(data) return True
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 25/37 binman: Use tools compression function for blob handling
Avoid duplicate code here by using the new compression function in the tools module.
---
Changes in v2: None
tools/binman/etype/blob.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
Applied to u-boot-dm, thanks!
PATCH v2 26/37 binman: Correct comment in u_boot_spl_elf
In reply to Simon GlassThis comment mentions the wrong default filename. Fix it.
---
Changes in v2: None
tools/binman/README.entries | 2 +- tools/binman/etype/u_boot_spl_elf.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tools/binman/README.entries +1 -1
@@ -496,7 +496,7 @@ Entry: u-boot-spl-elf: U-Boot SPL ELF image ------------------------------------------- Properties / Entry arguments: - - filename: Filename of SPL u-boot (default 'spl/u-boot') + - filename: Filename of SPL u-boot (default 'spl/u-boot-spl') This is the U-Boot SPL ELF image. It does not include a device tree but can be relocated to any address for execution.
tools/binman/etype/u_boot_spl_elf.py +1 -1
@@ -12,7 +12,7 @@ class Entry_u_boot_spl_elf(Entry_blob): """U-Boot SPL ELF image Properties / Entry arguments: - - filename: Filename of SPL u-boot (default 'spl/u-boot') + - filename: Filename of SPL u-boot (default 'spl/u-boot-spl') This is the U-Boot SPL ELF image. It does not include a device tree but can be relocated to any address for execution.
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 26/37 binman: Correct comment in u_boot_spl_elf
This comment mentions the wrong default filename. Fix it.
---
Changes in v2: None
tools/binman/README.entries | 2 +- tools/binman/etype/u_boot_spl_elf.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Applied to u-boot-dm, thanks!
PATCH v2 27/37 binman: Support ELF files for TPL
In reply to Simon GlassWe currenty support using the ELF file in U-Boot proper and SPL, but not TPL. Add this as it is useful both with sandbox and for CBFS to allow adding TPL as a 'stage'.
---
Changes in v2: None
tools/binman/README.entries | 11 +++++++++++ tools/binman/etype/u_boot_tpl_elf.py | 24 ++++++++++++++++++++++++ tools/binman/ftest.py | 2 ++ tools/binman/test/096_elf.dts | 2 ++ 4 files changed, 39 insertions(+) create mode 100644 tools/binman/etype/u_boot_tpl_elf.py
tools/binman/README.entries +11 -0
@@ -574,6 +574,17 @@ process. +Entry: u-boot-tpl-elf: U-Boot TPL ELF image +------------------------------------------- + +Properties / Entry arguments: + - filename: Filename of TPL u-boot (default 'tpl/u-boot-tpl') + +This is the U-Boot TPL ELF image. It does not include a device tree but can +be relocated to any address for execution. + + + Entry: u-boot-tpl-with-ucode-ptr: U-Boot TPL with embedded microcode pointer ----------------------------------------------------------------------------
tools/binman/etype/u_boot_tpl_elf.py new file +24 -0
@@ -0,0 +1,24 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2018 Google, Inc +# Written by Simon Glass <[email protected]> +# +# Entry-type module for U-Boot TPL ELF image +# + +from entry import Entry +from blob import Entry_blob + +class Entry_u_boot_tpl_elf(Entry_blob): + """U-Boot TPL ELF image + + Properties / Entry arguments: + - filename: Filename of TPL u-boot (default 'tpl/u-boot-tpl') + + This is the U-Boot TPL ELF image. It does not include a device tree but can + be relocated to any address for execution. + """ + def __init__(self, section, etype, node): + Entry_blob.__init__(self, section, etype, node) + + def GetDefaultFilename(self): + return 'tpl/u-boot-tpl'
tools/binman/ftest.py +2 -0
@@ -1745,6 +1745,8 @@ class TestFunctional(unittest.TestCase): def testElf(self): """Basic test of ELF entries""" self._SetupSplElf() + with open(self.TestFile('bss_data'), 'rb') as fd: + TestFunctional._MakeInputFile('tpl/u-boot-tpl', fd.read()) with open(self.TestFile('bss_data'), 'rb') as fd: TestFunctional._MakeInputFile('-boot', fd.read()) data = self._DoReadFile('096_elf.dts')
tools/binman/test/096_elf.dts +2 -0
@@ -10,5 +10,7 @@ }; u-boot-spl-elf { }; + u-boot-tpl-elf { + }; }; };
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 27/37 binman: Support ELF files for TPL
We currenty support using the ELF file in U-Boot proper and SPL, but not TPL. Add this as it is useful both with sandbox and for CBFS to allow adding TPL as a 'stage'.
---
Changes in v2: None
tools/binman/README.entries | 11 +++++++++++ tools/binman/etype/u_boot_tpl_elf.py | 24 ++++++++++++++++++++++++ tools/binman/ftest.py | 2 ++ tools/binman/test/096_elf.dts | 2 ++ 4 files changed, 39 insertions(+) create mode 100644 tools/binman/etype/u_boot_tpl_elf.py
Applied to u-boot-dm, thanks!
PATCH v2 28/37 binman: Fix up the _DoTestFile() function -u argument
In reply to Simon GlassThis should be -u, not -up, since we don't need to preserve the output directory in this case.
---
Changes in v2: None
tools/binman/ftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/binman/ftest.py +1 -1
@@ -208,7 +208,7 @@ class TestFunctional(unittest.TestCase): if map: args.append('-m') if update_dtb: - args.append('-up') + args.append('-u') if not use_real_dtb: args.append('--fake-dtb') if verbosity is not None:
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 28/37 binman: Fix up the _DoTestFile() function -u argument
This should be -u, not -up, since we don't need to preserve the output directory in this case.
---
Changes in v2: None
tools/binman/ftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied to u-boot-dm, thanks!
PATCH v2 29/37 binman: Allow verbosity control when running tests
In reply to Simon GlassAt present the -v flag is ignored with tests, so that (for example) -v2 does not have any effect. Update binman to pass this flag through to tests so that they work just like running binman normally, except in a few special cases where we are actually testing behaviour with different levels of verbosity.
---
Changes in v2: None
tools/binman/binman.py | 8 ++++++-- tools/binman/ftest.py | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-)
tools/binman/binman.py +6 -2
@@ -46,11 +46,12 @@ except: import control import test_util -def RunTests(debug, processes, args): +def RunTests(debug, verbosity, processes, args): """Run the functional tests and any embedded doctests Args: debug: True to enable debugging, which shows a full stack trace on error + verbosity: Verbosity level to use args: List of positional args provided to binman. This can hold a test name to execute (as in 'binman -t testSections', for example) processes: Number of processes to use to run tests (None=same as #CPUs)
@@ -71,6 +72,8 @@ def RunTests(debug, processes, args): sys.argv = [sys.argv[0]] if debug: sys.argv.append('-D') + if verbosity: + sys.argv.append('-v%d' % verbosity) # Run the entry tests first ,since these need to be the first to import the # 'entry' module.
@@ -153,7 +156,8 @@ def RunBinman(options, args): sys.tracebacklimit = 0 if options.test: - ret_code = RunTests(options.debug, options.processes, args[1:]) + ret_code = RunTests(options.debug, options.verbosity, options.processes, + args[1:]) elif options.test_coverage: RunTestCoverage()
tools/binman/ftest.py +16 -1
@@ -153,6 +153,19 @@ class TestFunctional(unittest.TestCase): TestFunctional._MakeInputFile('spl/u-boot-spl.dtb', U_BOOT_SPL_DTB_DATA) TestFunctional._MakeInputFile('tpl/u-boot-tpl.dtb', U_BOOT_TPL_DTB_DATA) + def _GetVerbosity(self): + """Check if verbosity should be enabled + + Returns: + list containing either: + - Verbosity flag (e.g. '-v2') if it is present on the cmd line + - nothing if the flag is not present + """ + for arg in sys.argv[1:]: + if arg.startswith('-v'): + return [arg] + return [] + def _RunBinman(self, *args, **kwargs): """Run binman using the command line
@@ -213,6 +226,8 @@ class TestFunctional(unittest.TestCase): args.append('--fake-dtb') if verbosity is not None: args.append('-v%d' % verbosity) + else: + args += self._GetVerbosity() if entry_args: for arg, value in entry_args.items(): args.append('-a%s=%s' % (arg, value))
@@ -1471,7 +1486,7 @@ class TestFunctional(unittest.TestCase): expected = 'Skipping images: image1' # We should only get the expected message in verbose mode - for verbosity in (None, 2): + for verbosity in (0, 2): with test_util.capture_sys_output() as (stdout, stderr): retcode = self._DoTestFile('006_dual_image.dts', verbosity=verbosity,
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 29/37 binman: Allow verbosity control when running tests
At present the -v flag is ignored with tests, so that (for example) -v2 does not have any effect. Update binman to pass this flag through to tests so that they work just like running binman normally, except in a few special cases where we are actually testing behaviour with different levels of verbosity.
---
Changes in v2: None
tools/binman/binman.py | 8 ++++++-- tools/binman/ftest.py | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-)
Applied to u-boot-dm, thanks!
PATCH v2 30/37 binman: Allow preserving test directories
In reply to Simon GlassSometimes when debugging tests it is useful to keep the input and output directories so they can be examined later. Add an option for this and update the binman tests to support it. This affects both the test class and the tearDown() function called after each test.
---
Changes in v2: None
tools/binman/README | 8 ++++++++ tools/binman/binman.py | 16 +++++++++++++--- tools/binman/cmdline.py | 4 ++++ tools/binman/ftest.py | 28 +++++++++++++++++++++++++--- 4 files changed, 50 insertions(+), 6 deletions(-)
tools/binman/README +8 -0
@@ -731,6 +731,14 @@ Use '-P 1' to disable this. It is automatically disabled when code coverage is being used (-T) since they are incompatible. +Debugging tests +--------------- + +Sometimes when debugging tests it is useful to keep the input and output +directories so they can be examined later. Use -X or --test-preserve-dirs for +this. + + Advanced Features / Technical docs ----------------------------------
tools/binman/binman.py +13 -3
@@ -46,15 +46,20 @@ except: import control import test_util -def RunTests(debug, verbosity, processes, args): +def RunTests(debug, verbosity, processes, test_preserve_dirs, args): """Run the functional tests and any embedded doctests Args: debug: True to enable debugging, which shows a full stack trace on error verbosity: Verbosity level to use + test_preserve_dirs: True to preserve the input directory used by tests + so that it can be examined afterwards (only useful for debugging + tests). If a single test is selected (in args[0]) it also preserves + the output directory for this test. Both directories are displayed + on the command line. + processes: Number of processes to use to run tests (None=same as #CPUs) args: List of positional args provided to binman. This can hold a test name to execute (as in 'binman -t testSections', for example) - processes: Number of processes to use to run tests (None=same as #CPUs) """ import elf_test import entry_test
@@ -82,6 +87,11 @@ def RunTests(debug, verbosity, processes, args): loader = unittest.TestLoader() for module in (entry_test.TestEntry, ftest.TestFunctional, fdt_test.TestFdt, elf_test.TestElf, image_test.TestImage): + # Test the test module about our arguments, if it is interested + if hasattr(module, 'setup_test_args'): + setup_test_args = getattr(module, 'setup_test_args') + setup_test_args(preserve_indir=test_preserve_dirs, + preserve_outdirs=test_preserve_dirs and test_name is not None) if test_name: try: suite.addTests(loader.loadTestsFromName(test_name, module))
@@ -157,7 +167,7 @@ def RunBinman(options, args): if options.test: ret_code = RunTests(options.debug, options.verbosity, options.processes, - args[1:]) + options.test_preserve_dirs, args[1:]) elif options.test_coverage: RunTestCoverage()
tools/binman/cmdline.py +4 -0
@@ -59,6 +59,10 @@ def ParseArgs(argv): parser.add_option('-v', '--verbosity', default=1, type='int', help='Control verbosity: 0=silent, 1=progress, 3=full, ' '4=debug') + parser.add_option('-X', '--test-preserve-dirs', action='store_true', + help='Preserve and display test-created input directories; also ' + 'preserve the output directory if a single test is run (pass test ' + 'name at the end of the command line') parser.usage += """
tools/binman/ftest.py +25 -3
@@ -6,6 +6,8 @@ # # python -m unittest func_test.TestFunctional.testHelp +from __future__ import print_function + import hashlib from optparse import OptionParser import os
@@ -134,10 +136,27 @@ class TestFunctional(unittest.TestCase): @classmethod def tearDownClass(self): """Remove the temporary input directory and its contents""" - if self._indir: - shutil.rmtree(self._indir) + if self.preserve_indir: + print('Preserving input dir: %s' % self._indir) + else: + if self._indir: + shutil.rmtree(self._indir) self._indir = None + @classmethod + def setup_test_args(cls, preserve_indir=False, preserve_outdirs=False): + """Accept arguments controlling test execution + + Args: + preserve_indir: Preserve the shared input directory used by all + tests in this class. + preserve_outdir: Preserve the output directories used by tests. Each + test has its own, so this is normally only useful when running a + single test. + """ + cls.preserve_indir = preserve_indir + cls.preserve_outdirs = preserve_outdirs + def setUp(self): # Enable this to turn on debugging output # tout.Init(tout.DEBUG)
@@ -145,7 +164,10 @@ class TestFunctional(unittest.TestCase): def tearDown(self): """Remove the temporary output directory""" - tools._FinaliseForTest() + if self.preserve_outdirs: + print('Preserving output dir: %s' % tools.outdir) + else: + tools._FinaliseForTest() @classmethod def _ResetDtbs(self):
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 30/37 binman: Allow preserving test directories
Sometimes when debugging tests it is useful to keep the input and output directories so they can be examined later. Add an option for this and update the binman tests to support it. This affects both the test class and the tearDown() function called after each test.
---
Changes in v2: None
tools/binman/README | 8 ++++++++ tools/binman/binman.py | 16 +++++++++++++--- tools/binman/cmdline.py | 4 ++++ tools/binman/ftest.py | 28 +++++++++++++++++++++++++--- 4 files changed, 50 insertions(+), 6 deletions(-)
Applied to u-boot-dm, thanks!
PATCH v2 31/37 binman: Pass the toolpath to tests
In reply to Simon GlassTools like ifwitool may not be available in the PATH, but are available in the build. These tools may be needed by tests, so allow tests to use the --toolpath flag.
Also use this flag with travis.
---
Changes in v2: None
.travis.yml | 2 +- test/run | 9 ++++++--- tools/binman/binman.py | 12 +++++++++--- tools/binman/ftest.py | 8 +++++++- 4 files changed, 23 insertions(+), 8 deletions(-)
.travis.yml +1 -1
@@ -146,7 +146,7 @@ script: if [[ -n "${TEST_PY_TOOLS}" ]]; then PYTHONPATH="${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc/pylibfdt" PATH="${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc:${PATH}" - ./tools/binman/binman -t && + ./tools/binman/binman --toolpath ${UBOOT_TRAVIS_BUILD_DIR}/tools -t && ./tools/patman/patman --test && ./tools/buildman/buildman -t && PYTHONPATH="${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc/pylibfdt"
test/run +6 -3
@@ -33,12 +33,14 @@ run_test "sandbox_flattree" ./test/py/test.py --bd sandbox_flattree --build \ -k test_ut # Set up a path to dtc (device-tree compiler) and libfdt.py, a library it -# provides and which is built by the sandbox_spl config. +# provides and which is built by the sandbox_spl config. Also set up the path +# to tools build by the build. DTC_DIR=build-sandbox_spl/scripts/dtc export PYTHONPATH=${DTC_DIR}/pylibfdt export DTC=${DTC_DIR}/dtc +TOOLS_DIR=build-sandbox_spl/tools -run_test "binman" ./tools/binman/binman -t +run_test "binman" ./tools/binman/binman -t --toolpath ${TOOLS_DIR} run_test "patman" ./tools/patman/patman --test [ "$1" == "quick" ] && skip=--skip-net-tests
@@ -49,7 +51,8 @@ run_test "dtoc" ./tools/dtoc/dtoc -t # This needs you to set up Python test coverage tools. # To enable Python test coverage on Debian-type distributions (e.g. Ubuntu): # $ sudo apt-get install python-pytest python-coverage -run_test "binman code coverage" ./tools/binman/binman -T +export PATH=$PATH:${TOOLS_DIR} +run_test "binman code coverage" ./tools/binman/binman -T --toolpath ${TOOLS_DIR} run_test "dtoc code coverage" ./tools/dtoc/dtoc -T run_test "fdt code coverage" ./tools/dtoc/test_fdt -T
tools/binman/binman.py +9 -3
@@ -46,7 +46,7 @@ except: import control import test_util -def RunTests(debug, verbosity, processes, test_preserve_dirs, args): +def RunTests(debug, verbosity, processes, test_preserve_dirs, args, toolpath): """Run the functional tests and any embedded doctests Args:
@@ -60,6 +60,7 @@ def RunTests(debug, verbosity, processes, test_preserve_dirs, args): processes: Number of processes to use to run tests (None=same as #CPUs) args: List of positional args provided to binman. This can hold a test name to execute (as in 'binman -t testSections', for example) + toolpath: List of paths to use for tools """ import elf_test import entry_test
@@ -79,6 +80,9 @@ def RunTests(debug, verbosity, processes, test_preserve_dirs, args): sys.argv.append('-D') if verbosity: sys.argv.append('-v%d' % verbosity) + if toolpath: + for path in toolpath: + sys.argv += ['--toolpath', path] # Run the entry tests first ,since these need to be the first to import the # 'entry' module.
@@ -91,7 +95,8 @@ def RunTests(debug, verbosity, processes, test_preserve_dirs, args): if hasattr(module, 'setup_test_args'): setup_test_args = getattr(module, 'setup_test_args') setup_test_args(preserve_indir=test_preserve_dirs, - preserve_outdirs=test_preserve_dirs and test_name is not None) + preserve_outdirs=test_preserve_dirs and test_name is not None, + toolpath=toolpath) if test_name: try: suite.addTests(loader.loadTestsFromName(test_name, module))
@@ -167,7 +172,8 @@ def RunBinman(options, args): if options.test: ret_code = RunTests(options.debug, options.verbosity, options.processes, - options.test_preserve_dirs, args[1:]) + options.test_preserve_dirs, args[1:], + options.toolpath) elif options.test_coverage: RunTestCoverage()
tools/binman/ftest.py +7 -1
@@ -144,7 +144,8 @@ class TestFunctional(unittest.TestCase): self._indir = None @classmethod - def setup_test_args(cls, preserve_indir=False, preserve_outdirs=False): + def setup_test_args(cls, preserve_indir=False, preserve_outdirs=False, + toolpath=None): """Accept arguments controlling test execution Args:
@@ -153,9 +154,11 @@ class TestFunctional(unittest.TestCase): preserve_outdir: Preserve the output directories used by tests. Each test has its own, so this is normally only useful when running a single test. + toolpath: ist of paths to use for tools """ cls.preserve_indir = preserve_indir cls.preserve_outdirs = preserve_outdirs + cls.toolpath = toolpath def setUp(self): # Enable this to turn on debugging output
@@ -256,6 +259,9 @@ class TestFunctional(unittest.TestCase): if images: for image in images: args += ['-i', image] + if self.toolpath: + for path in self.toolpath: + args += ['--toolpath', path] return self._DoBinman(*args) def _SetupDtb(self, fname, outfile='u-boot.dtb'):
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 31/37 binman: Pass the toolpath to tests
Tools like ifwitool may not be available in the PATH, but are available in the build. These tools may be needed by tests, so allow tests to use the --toolpath flag.
Also use this flag with travis.
---
Changes in v2: None
.travis.yml | 2 +- test/run | 9 ++++++--- tools/binman/binman.py | 12 +++++++++--- tools/binman/ftest.py | 8 +++++++- 4 files changed, 23 insertions(+), 8 deletions(-)
Applied to u-boot-dm, thanks!
PATCH v2 32/37 patman: Add a function to write ifwitool
In reply to Simon GlassThis tool has quite a few arguments and options, so put the functionality in a function so that we call it from one place and hopefully get it right.
---
Changes in v2: None
tools/patman/tools.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
tools/patman/tools.py +33 -0
@@ -3,6 +3,8 @@ # Copyright (c) 2016 Google, Inc # +from __future__ import print_function + import command import glob import os
@@ -440,3 +442,34 @@ def Decompress(indata, algo): else: raise ValueError("Unknown algorithm '%s'" % algo) return data + +CMD_CREATE, CMD_DELETE, CMD_ADD, CMD_REPLACE, CMD_EXTRACT = range(5) + +IFWITOOL_CMDS = { + CMD_CREATE: 'create', + CMD_DELETE: 'delete', + CMD_ADD: 'add', + CMD_REPLACE: 'replace', + CMD_EXTRACT: 'extract', + } + +def RunIfwiTool(ifwi_file, cmd, fname=None, subpart=None, entry_name=None): + """Run ifwitool with the given arguments: + + Args: + ifwi_file: IFWI file to operation on + cmd: Command to execute (CMD_...) + fname: Filename of file to add/replace/extract/create (None for + CMD_DELETE) + subpart: Name of sub-partition to operation on (None for CMD_CREATE) + entry_name: Name of directory entry to operate on, or None if none + """ + args = ['ifwitool', ifwi_file] + args.append(IFWITOOL_CMDS[cmd]) + if fname: + args += ['-f', fname] + if subpart: + args += ['-n', subpart] + if entry_name: + args += ['-d', '-e', entry_name] + Run(*args)
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 32/37 patman: Add a function to write ifwitool
This tool has quite a few arguments and options, so put the functionality in a function so that we call it from one place and hopefully get it right.
---
Changes in v2: None
tools/patman/tools.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
Applied to u-boot-dm, thanks!
PATCH v2 33/37 binman: Add a utility library for coreboot CBFS
In reply to Simon GlassCoreboot uses a simple flash-based filesystem called Coreboot Filesystem (CBFS) to organise files used during boot. This allows files to be named and their position in the flash to be set. It has special features for dealing with x86 devices which typically memory-map their SPI flash to the top of 32-bit address space and need a 'boot block' ending there.
Create a library to help create and read CBFS files. This includes a writer class, a reader class and associated other helpers. Only a subset of features are currently supported.
---
Changes in v2:
- Deal with travis's old lz4 version by skipping tests as necessary
- Install lzma tool in travis
- Skip use of cbfstool in tests if it is not available
.travis.yml | 1 + tools/binman/binman.py | 4 +- tools/binman/cbfs_util.py | 720 +++++++++++++++++++++++++++++++++ tools/binman/cbfs_util_test.py | 540 +++++++++++++++++++++++++ 4 files changed, 1264 insertions(+), 1 deletion(-) create mode 100644 tools/binman/cbfs_util.py create mode 100755 tools/binman/cbfs_util_test.py
.travis.yml +1 -0
@@ -32,6 +32,7 @@ addons: - device-tree-compiler - lzop - liblz4-tool + - lzma-alone - libisl15 - clang-7 - srecord
tools/binman/binman.py +3 -1
@@ -62,6 +62,7 @@ def RunTests(debug, verbosity, processes, test_preserve_dirs, args, toolpath): name to execute (as in 'binman -t testSections', for example) toolpath: List of paths to use for tools """ + import cbfs_util_test import elf_test import entry_test import fdt_test
@@ -90,7 +91,8 @@ def RunTests(debug, verbosity, processes, test_preserve_dirs, args, toolpath): suite = unittest.TestSuite() loader = unittest.TestLoader() for module in (entry_test.TestEntry, ftest.TestFunctional, fdt_test.TestFdt, - elf_test.TestElf, image_test.TestImage): + elf_test.TestElf, image_test.TestImage, + cbfs_util_test.TestCbfs): # Test the test module about our arguments, if it is interested if hasattr(module, 'setup_test_args'): setup_test_args = getattr(module, 'setup_test_args')
tools/binman/cbfs_util.py new file +720 -0
720 lines not on this page · raw message
tools/binman/cbfs_util_test.py new file +540 -0
540 lines not on this page · raw message
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 33/37 binman: Add a utility library for coreboot CBFS
Coreboot uses a simple flash-based filesystem called Coreboot Filesystem (CBFS) to organise files used during boot. This allows files to be named and their position in the flash to be set. It has special features for dealing with x86 devices which typically memory-map their SPI flash to the top of 32-bit address space and need a 'boot block' ending there.
Create a library to help create and read CBFS files. This includes a writer class, a reader class and associated other helpers. Only a subset of features are currently supported.
---
Changes in v2:
- Deal with travis's old lz4 version by skipping tests as necessary
- Install lzma tool in travis
- Skip use of cbfstool in tests if it is not available
.travis.yml | 1 + tools/binman/binman.py | 4 +- tools/binman/cbfs_util.py | 720 +++++++++++++++++++++++++++++++++ tools/binman/cbfs_util_test.py | 540 +++++++++++++++++++++++++ 4 files changed, 1264 insertions(+), 1 deletion(-) create mode 100644 tools/binman/cbfs_util.py create mode 100755 tools/binman/cbfs_util_test.py
Applied to u-boot-dm, thanks!
PATCH v2 34/37 binman: Add support for CBFS entries
In reply to Simon GlassAdd support for putting CBFSs (Coreboot Filesystems) in an image. This allows binman to produce firmware images used by coreboot to boot.
---
Changes in v2:
- Deal with travis's old lz4 version by skipping tests as necessary
- Skip use of cbfstool in tests if it is not available
tools/binman/README.entries | 142 ++++++++++++++ tools/binman/control.py | 2 + tools/binman/etype/cbfs.py | 193 ++++++++++++++++++++ tools/binman/ftest.py | 110 +++++++++++ tools/binman/test/102_cbfs_raw.dts | 20 ++ tools/binman/test/103_cbfs_raw_ppc.dts | 21 +++ tools/binman/test/104_cbfs_stage.dts | 19 ++ tools/binman/test/105_cbfs_raw_compress.dts | 26 +++ tools/binman/test/106_cbfs_bad_arch.dts | 15 ++ tools/binman/test/107_cbfs_no_size.dts | 13 ++ tools/binman/test/108_cbfs_no_contents.dts | 17 ++ tools/binman/test/109_cbfs_bad_compress.dts | 18 ++ tools/binman/test/110_cbfs_name.dts | 24 +++ 13 files changed, 620 insertions(+) create mode 100644 tools/binman/etype/cbfs.py create mode 100644 tools/binman/test/102_cbfs_raw.dts create mode 100644 tools/binman/test/103_cbfs_raw_ppc.dts create mode 100644 tools/binman/test/104_cbfs_stage.dts create mode 100644 tools/binman/test/105_cbfs_raw_compress.dts create mode 100644 tools/binman/test/106_cbfs_bad_arch.dts create mode 100644 tools/binman/test/107_cbfs_no_size.dts create mode 100644 tools/binman/test/108_cbfs_no_contents.dts create mode 100644 tools/binman/test/109_cbfs_bad_compress.dts create mode 100644 tools/binman/test/110_cbfs_name.dts
tools/binman/README.entries +142 -0
@@ -60,6 +60,148 @@ See cros_ec_rw for an example of this. +Entry: cbfs: Entry containing a Coreboot Filesystem (CBFS) +---------------------------------------------------------- + +A CBFS provides a way to group files into a group. It has a simple directory +structure and allows the position of individual files to be set, since it is +designed to support execute-in-place in an x86 SPI-flash device. Where XIP +is not used, it supports compression and storing ELF files. + +CBFS is used by coreboot as its way of orgnanising SPI-flash contents. + +The contents of the CBFS are defined by subnodes of the cbfs entry, e.g.: + + cbfs { + size = <0x100000>; + u-boot { + cbfs-type = "raw"; + }; + u-boot-dtb { + cbfs-type = "raw"; + }; + }; + +This creates a CBFS 1MB in size two files in it: u-boot.bin and u-boot.dtb. +Note that the size is required since binman does not support calculating it. +The contents of each entry is just what binman would normally provide if it +were not a CBFS node. A blob type can be used to import arbitrary files as +with the second subnode below: + + cbfs { + size = <0x100000>; + u-boot { + cbfs-name = "BOOT"; + cbfs-type = "raw"; + }; + + dtb { + type = "blob"; + filename = "u-boot.dtb"; + cbfs-type = "raw"; + cbfs-compress = "lz4"; + }; + }; + +This creates a CBFS 1MB in size with u-boot.bin (named "BOOT") and +u-boot.dtb (named "dtb") and compressed with the lz4 algorithm. + + +Properties supported in the top-level CBFS node: + +cbfs-arch: + Defaults to "x86", but you can specify the architecture if needed. + + +Properties supported in the CBFS entry subnodes: + +cbfs-name: + This is the name of the file created in CBFS. It defaults to the entry + name (which is the node name), but you can override it with this + property. + +cbfs-type: + This is the CBFS file type. The following are supported: + + raw: + This is a 'raw' file, although compression is supported. It can be + used to store any file in CBFS. + + stage: + This is an ELF file that has been loaded (i.e. mapped to memory), so + appears in the CBFS as a flat binary. The input file must be an ELF + image, for example this puts "u-boot" (the ELF image) into a 'stage' + entry: + + cbfs { + size = <0x100000>; + u-boot-elf { + cbfs-name = "BOOT"; + cbfs-type = "stage"; + }; + }; + + You can use your own ELF file with something like: + + cbfs { + size = <0x100000>; + something { + type = "blob"; + filename = "cbfs-stage.elf"; + cbfs-type = "stage"; + }; + }; + + As mentioned, the file is converted to a flat binary, so it is + equivalent to adding "u-boot.bin", for example, but with the load and + start addresses specified by the ELF. At present there is no option + to add a flat binary with a load/start address, similar to the + 'add-flat-binary' option in cbfstool. + + +The current implementation supports only a subset of CBFS features. It does +not support other file types (e.g. payload), adding multiple files (like the +'files' entry with a pattern supported by binman), putting files at a +particular offset in the CBFS and a few other things. + +Of course binman can create images containing multiple CBFSs, simply by +defining these in the binman config: + + + binman { + size = <0x800000>; + cbfs { + offset = <0x100000>; + size = <0x100000>; + u-boot { + cbfs-type = "raw"; + }; + u-boot-dtb { + cbfs-type = "raw"; + }; + }; + + cbfs2 { + offset = <0x700000>; + size = <0x100000>; + u-boot { + cbfs-type = "raw"; + }; + u-boot-dtb { + cbfs-type = "raw"; + }; + image { + type = "blob"; + filename = "image.jpg"; + }; + }; + }; + +This creates an 8MB image with two CBFSs, one at offset 1MB, one at 7MB, +both of size 1MB. + + + Entry: cros-ec-rw: A blob entry which contains a Chromium OS read-write EC image --------------------------------------------------------------------------------
tools/binman/control.py +2 -0
@@ -12,6 +12,7 @@ import os import sys import tools +import cbfs_util import command import elf from image import Image
@@ -108,6 +109,7 @@ def Binman(options, args): tout.Init(options.verbosity) elf.debug = options.debug + cbfs_util.VERBOSE = options.verbosity > 2 state.use_fake_dtb = options.fake_dtb try: tools.SetInputDirs(options.indir)
tools/binman/etype/cbfs.py new file +193 -0
193 lines not on this page · raw message
tools/binman/ftest.py +110 -0
146 lines not on this page · raw message
tools/binman/test/102_cbfs_raw.dts new file +20 -0
@@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + cbfs { + size = <0xb0>; + u-boot { + cbfs-type = "raw"; + }; + u-boot-dtb { + cbfs-type = "raw"; + }; + }; + }; +};
tools/binman/test/103_cbfs_raw_ppc.dts new file +21 -0
@@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + cbfs { + size = <0x100>; + cbfs-arch = "ppc64"; + u-boot { + cbfs-type = "raw"; + }; + u-boot-dtb { + cbfs-type = "raw"; + }; + }; + }; +};
tools/binman/test/104_cbfs_stage.dts new file +19 -0
@@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + cbfs { + size = <0xb0>; + u-boot { + type = "blob"; + filename = "cbfs-stage.elf"; + cbfs-type = "stage"; + }; + }; + }; +};
tools/binman/test/105_cbfs_raw_compress.dts new file +26 -0
@@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + cbfs { + size = <0x140>; + u-boot { + type = "text"; + text = "compress xxxxxxxxxxxxxxxxxxxxxx data"; + cbfs-type = "raw"; + cbfs-compress = "lz4"; + }; + u-boot-dtb { + type = "text"; + text = "compress xxxxxxxxxxxxxxxxxxxxxx data"; + cbfs-type = "raw"; + cbfs-compress = "lzma"; + }; + }; + }; +};
tools/binman/test/106_cbfs_bad_arch.dts new file +15 -0
@@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + cbfs { + size = <0x100>; + cbfs-arch = "bad-arch"; + }; + }; +};
tools/binman/test/107_cbfs_no_size.dts new file +13 -0
@@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + cbfs { + }; + }; +};
tools/binman/test/108_cbfs_no_contents.dts new file +17 -0
@@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + cbfs { + size = <0x100>; + _testing { + return-unknown-contents; + }; + }; + }; +};
tools/binman/test/109_cbfs_bad_compress.dts new file +18 -0
@@ -0,0 +1,18 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + cbfs { + size = <0xb0>; + u-boot { + cbfs-type = "raw"; + cbfs-compress = "invalid-algo"; + }; + }; + }; +};
tools/binman/test/110_cbfs_name.dts new file +24 -0
@@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + cbfs { + size = <0x100>; + u-boot { + cbfs-name = "FRED"; + cbfs-type = "raw"; + }; + + hello { + type = "blob"; + filename = "u-boot.dtb"; + cbfs-type = "raw"; + }; + }; + }; +};
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 34/37 binman: Add support for CBFS entries
Add support for putting CBFSs (Coreboot Filesystems) in an image. This allows binman to produce firmware images used by coreboot to boot.
---
Changes in v2:
- Deal with travis's old lz4 version by skipping tests as necessary
- Skip use of cbfstool in tests if it is not available
tools/binman/README.entries | 142 ++++++++++++++ tools/binman/control.py | 2 + tools/binman/etype/cbfs.py | 193 ++++++++++++++++++++ tools/binman/ftest.py | 110 +++++++++++ tools/binman/test/102_cbfs_raw.dts | 20 ++ tools/binman/test/103_cbfs_raw_ppc.dts | 21 +++ tools/binman/test/104_cbfs_stage.dts | 19 ++ tools/binman/test/105_cbfs_raw_compress.dts | 26 +++ tools/binman/test/106_cbfs_bad_arch.dts | 15 ++ tools/binman/test/107_cbfs_no_size.dts | 13 ++ tools/binman/test/108_cbfs_no_contents.dts | 17 ++ tools/binman/test/109_cbfs_bad_compress.dts | 18 ++ tools/binman/test/110_cbfs_name.dts | 24 +++ 13 files changed, 620 insertions(+) create mode 100644 tools/binman/etype/cbfs.py create mode 100644 tools/binman/test/102_cbfs_raw.dts create mode 100644 tools/binman/test/103_cbfs_raw_ppc.dts create mode 100644 tools/binman/test/104_cbfs_stage.dts create mode 100644 tools/binman/test/105_cbfs_raw_compress.dts create mode 100644 tools/binman/test/106_cbfs_bad_arch.dts create mode 100644 tools/binman/test/107_cbfs_no_size.dts create mode 100644 tools/binman/test/108_cbfs_no_contents.dts create mode 100644 tools/binman/test/109_cbfs_bad_compress.dts create mode 100644 tools/binman/test/110_cbfs_name.dts
Applied to u-boot-dm, thanks!
PATCH v2 35/37 binman: Add support for Intel IFWI entries
In reply to Simon GlassAn Integrated Firmware Image is used to hold various binaries used for booting with Apollolake and some later devices. Add support for this.
---
Changes in v2: None
tools/binman/etype/intel_descriptor.py | 6 +- tools/binman/etype/intel_ifwi.py | 100 ++++++++++++++++++ tools/binman/ftest.py | 55 ++++++++++ tools/binman/test/111_x86-rom-ifwi.dts | 29 +++++ tools/binman/test/112_x86-rom-ifwi-nodesc.dts | 28 +++++ tools/binman/test/113_x86-rom-ifwi-nodata.dts | 29 +++++ tools/binman/test/fitimage.bin.gz | Bin 0 -> 8418 bytes tools/binman/test/ifwi.bin.gz | Bin 0 -> 1884 bytes 8 files changed, 245 insertions(+), 2 deletions(-) create mode 100644 tools/binman/etype/intel_ifwi.py create mode 100644 tools/binman/test/111_x86-rom-ifwi.dts create mode 100644 tools/binman/test/112_x86-rom-ifwi-nodesc.dts create mode 100644 tools/binman/test/113_x86-rom-ifwi-nodata.dts create mode 100644 tools/binman/test/fitimage.bin.gz create mode 100644 tools/binman/test/ifwi.bin.gz
tools/binman/etype/intel_descriptor.py +4 -2
@@ -60,10 +60,12 @@ class Entry_intel_descriptor(Entry_blob): for i in range(MAX_REGIONS): self._regions.append(Region(self.data, frba, i)) - # Set the offset for ME (Management Engine) only, for now, since the - # others are not used + # Set the offset for ME (Management Engine) and IFWI (Integrated + # Firmware Image), for now, since the others are not used. info = {} if self.HasSibling('intel-me'): info['intel-me'] = [self._regions[REGION_ME].base, self._regions[REGION_ME].size] + if self.HasSibling('intel-ifwi'): + info['intel-ifwi'] = [self._regions[REGION_BIOS].base, None] return info
tools/binman/etype/intel_ifwi.py new file +100 -0
100 lines not on this page · raw message
tools/binman/ftest.py +55 -0
73 lines not on this page · raw message
tools/binman/test/111_x86-rom-ifwi.dts new file +29 -0
@@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + sort-by-offset; + end-at-4gb; + size = <0x800000>; + intel-descriptor { + filename = "descriptor.bin"; + }; + + intel-ifwi { + offset-unset; + filename = "fitimage.bin"; + convert-fit; + + u-boot-tpl { + replace; + ifwi-subpart = "IBBP"; + ifwi-entry = "IBBL"; + }; + }; + }; +};
tools/binman/test/112_x86-rom-ifwi-nodesc.dts new file +28 -0
@@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + sort-by-offset; + end-at-4gb; + size = <0x800000>; + intel-descriptor { + filename = "descriptor.bin"; + }; + + intel-ifwi { + offset-unset; + filename = "ifwi.bin"; + + u-boot-tpl { + replace; + ifwi-subpart = "IBBP"; + ifwi-entry = "IBBL"; + }; + }; + }; +};
tools/binman/test/113_x86-rom-ifwi-nodata.dts new file +29 -0
@@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + sort-by-offset; + end-at-4gb; + size = <0x800000>; + intel-descriptor { + filename = "descriptor.bin"; + }; + + intel-ifwi { + offset-unset; + filename = "ifwi.bin"; + + _testing { + return-unknown-contents; + replace; + ifwi-subpart = "IBBP"; + ifwi-entry = "IBBL"; + }; + }; + }; +};
tools/binman/test/fitimage.bin.gz new file binary +0 -0
zzr0fzJx_kkYyR8jE{kOgS41Cs at VMwo&FeqCWk3Jr%+r+;%-1{H_bktB+NF)6b33x4 z?USzmm^aJ#Y{$DD#{X{4Ib_Ss!0 at N1-23<Agx?9(x4wTguZTXCquni7ta;GiB<ODE z)vRjW>+epq8>v6)m>F|_ozktf7elWHSAVcnPA}eC<?nat<*ii=}-Ttxo1gQUESUO z_-KLp!k&+;hO><;S6z<LY<_>{YtX#wvvQZDZ at j17wrsB+0|SF}?!$zF6VB#UbHIP zbp7 at 7vLCOGW?OR4^M31Ud8#$@&lMHrGHJt8&lZ2&sT)7<8$91@9(yk30u6kb@%qm z5nI>)HMz>Y{Cr8$<dW-YPwLI*-?}JaxA^bL8~yWo<NyA<v!^aK*dFLJh7aL4dU7p+ z3?OKTH+%bkGaH06N{)sALtRd);UbUqoo=hFH%8^2o?9L2vRV|BY#z)vd;6DtG=xS& zU^E0qLjWxVZg7p(A!tD|${hX(GVC7fzc2c4S~@R7!85Z5Eu=C(GVC7fzc2c4S~@R z7!85Z5Eu=C(GVC7fzc2c4S~@RASnd?cT7Fnq181bW63Vz)mOj$$Z=mg?_|5t*296j zwUWZu&Rcyob?v?2)yx0xlsx%5z9#i=dhzn9QMaQQ85nX{xsU%=FZ!k3b?x!yy>a$i lx9Z%On{wd&ldm8bY};eMGaRUj;m<t(^-=eBGaRU9006rUF!lfd
literal 0
HcmV?d00001
tools/binman/test/ifwi.bin.gz new file binary +0 -0
z^W@~OUw-I(Z)(?+JN{~)!PWBLwn at 7MOYHd->*LY?P+wqeChi7+oxYZC%|RqCGwQ zUGTj-xATuq*m6Jp$^K}cjdFXdw_ILdTb}>t%TLSq^LW0RGXTN<Lk82Hf*3$hmviO+ zW;O_WlpGBKhJEGb0)b1`uAlfR%w}rv&%>pXfuSFnfC2L-b8%e#XaJ3dz-S1J%n+#C OAO70lJukxo2?hX1K&cV{
literal 0
HcmV?d00001
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 35/37 binman: Add support for Intel IFWI entries
An Integrated Firmware Image is used to hold various binaries used for booting with Apollolake and some later devices. Add support for this.
---
Changes in v2: None
tools/binman/etype/intel_descriptor.py | 6 +- tools/binman/etype/intel_ifwi.py | 100 ++++++++++++++++++ tools/binman/ftest.py | 55 ++++++++++ tools/binman/test/111_x86-rom-ifwi.dts | 29 +++++ tools/binman/test/112_x86-rom-ifwi-nodesc.dts | 28 +++++ tools/binman/test/113_x86-rom-ifwi-nodata.dts | 29 +++++ tools/binman/test/fitimage.bin.gz | Bin 0 -> 8418 bytes tools/binman/test/ifwi.bin.gz | Bin 0 -> 1884 bytes 8 files changed, 245 insertions(+), 2 deletions(-) create mode 100644 tools/binman/etype/intel_ifwi.py create mode 100644 tools/binman/test/111_x86-rom-ifwi.dts create mode 100644 tools/binman/test/112_x86-rom-ifwi-nodesc.dts create mode 100644 tools/binman/test/113_x86-rom-ifwi-nodata.dts create mode 100644 tools/binman/test/fitimage.bin.gz create mode 100644 tools/binman/test/ifwi.bin.gz
Applied to u-boot-dm, thanks!
PATCH v2 36/37 binman: Pad empty areas of the CBFS with files
In reply to Simon GlassWhen there is lots of open space in a CBFS it is normally padded with 'empty' files so that sequentially scanning the CBFS can skip from one to the next without a break.
Add support for this.
---
Changes in v2: None
tools/binman/cbfs_util.py | 68 ++++++++++++++++++++++++++++++++-- tools/binman/cbfs_util_test.py | 23 +++++++++++- 2 files changed, 87 insertions(+), 4 deletions(-)
tools/binman/cbfs_util.py +65 -3
@@ -11,7 +11,8 @@ The format is somewhat defined by documentation in the coreboot tree although it is necessary to rely on the C structures and source code (mostly cbfstool) to fully understand it. -Currently supported: raw and stage types with compression +Currently supported: raw and stage types with compression, padding empty areas + with empty files """ from __future__ import print_function
@@ -102,6 +103,7 @@ ARCH_NAMES = { TYPE_CBFSHEADER = 0x02 # Master header, HEADER_FORMAT TYPE_STAGE = 0x10 # Stage, holding an executable, see STAGE_FORMAT TYPE_RAW = 0x50 # Raw file, possibly compressed +TYPE_EMPTY = 0xffffffff # Empty data # Compression types COMPRESS_NONE, COMPRESS_LZMA, COMPRESS_LZ4 = range(3)
@@ -152,6 +154,19 @@ def align_int(val, align): """ return int((val + align - 1) / align) * align +def align_int_down(val, align): + """Align a value down to the given alignment + + Args: + val: Integer value to align + align: Integer alignment value (e.g. 4 to align to 4-byte boundary) + + Returns: + integer value aligned to the required boundary, rounding down if + necessary + """ + return int(val / align) * align + def _pack_string(instr): """Pack a string to the required aligned size by adding padding
@@ -184,6 +199,9 @@ class CbfsFile(object): entry: Entry address in memory if known, else None. This is where execution starts after the file is loaded base_address: Base address to use for 'stage' files + erase_byte: Erase byte to use for padding between the file header and + contents (used for empty files) + size: Size of the file in bytes (used for empty files) """ def __init__(self, name, ftype, data, compress=COMPRESS_NONE): self.name = name
@@ -196,6 +214,8 @@ class CbfsFile(object): self.entry = None self.base_address = None self.data_len = 0 + self.erase_byte = None + self.size = None def decompress(self): """Handle decompressing data if necessary"""
@@ -242,6 +262,24 @@ class CbfsFile(object): """ return CbfsFile(name, TYPE_RAW, data, compress) + @classmethod + def empty(cls, space_to_use, erase_byte): + """Create a new empty file of a given size + + Args: + space_to_use:: Size of available space, which must be at least as + large as the alignment size for this CBFS + erase_byte: Byte to use for contents of file (repeated through the + whole file) + + Returns: + CbfsFile object containing the file information + """ + cfile = CbfsFile('', TYPE_EMPTY, b'') + cfile.size = space_to_use - FILE_HEADER_LEN - FILENAME_ALIGN + cfile.erase_byte = erase_byte + return cfile + def get_data(self): """Obtain the contents of the file, in CBFS format
@@ -270,6 +308,8 @@ class CbfsFile(object): attr = struct.pack(ATTR_COMPRESSION_FORMAT, FILE_ATTR_TAG_COMPRESSION, ATTR_COMPRESSION_LEN, self.compress, len(orig_data)) + elif self.ftype == TYPE_EMPTY: + data = tools.GetBytes(self.erase_byte, self.size) else: raise ValueError('Unknown type %#x when writing\n' % self.ftype) if attr:
@@ -357,6 +397,24 @@ class CbfsWriter(object): (offset, fd.tell())) fd.write(tools.GetBytes(self._erase_byte, offset - fd.tell())) + def _pad_to(self, fd, offset): + """Write out pad bytes and/or an empty file until a given offset + + Args: + fd: File objext to write to + offset: Offset to write to + """ + self._align_to(fd, self._align) + upto = fd.tell() + if upto > offset: + raise ValueError('No space for data before pad offset %#x (current offset %#x)' % + (offset, upto)) + todo = align_int_down(offset - upto, self._align) + if todo: + cbf = CbfsFile.empty(todo, self._erase_byte) + fd.write(cbf.get_data()) + self._skip_to(fd, offset) + def _align_to(self, fd, align): """Write out pad bytes until a given alignment is reached
@@ -416,7 +474,7 @@ class CbfsWriter(object): raise ValueError('No space for header at offset %#x (current offset %#x)' % (self._header_offset, fd.tell())) if not add_fileheader: - self._skip_to(fd, self._header_offset) + self._pad_to(fd, self._header_offset) hdr = struct.pack(HEADER_FORMAT, HEADER_MAGIC, HEADER_VERSION2, self._size, self._bootblock_size, self._align, self._contents_offset, self._arch, 0xffffffff)
@@ -455,7 +513,7 @@ class CbfsWriter(object): self._write_header(fd, add_fileheader=self._add_fileheader) # Pad to the end and write a pointer to the CBFS master header - self._skip_to(fd, self._base_address or self._size - 4) + self._pad_to(fd, self._base_address or self._size - 4) rel_offset = self._header_offset - self._size fd.write(struct.pack('<I', rel_offset & 0xffffffff))
@@ -596,6 +654,10 @@ class CbfsReader(object): cfile.decompress() if DEBUG: print('data', data) + elif ftype == TYPE_EMPTY: + # Just read the data and discard it, since it is only padding + fd.read(size) + cfile = CbfsFile('', TYPE_EMPTY, b'') else: raise ValueError('Unknown type %#x when reading\n' % ftype) if cfile:
tools/binman/cbfs_util_test.py +22 -1
@@ -289,6 +289,16 @@ class TestCbfs(unittest.TestCase): self.assertIn('No space for header', str(e.exception)) def test_cbfs_no_space_skip(self): + """Check handling of running out of space in CBFS with file header""" + size = 0x5c + cbw = CbfsWriter(size, arch=cbfs_util.ARCHITECTURE_PPC64) + cbw._add_fileheader = True + cbw.add_file_raw('u-boot', U_BOOT_DATA) + with self.assertRaises(ValueError) as e: + cbw.get_data() + self.assertIn('No space for data before offset', str(e.exception)) + + def test_cbfs_no_space_pad(self): """Check handling of running out of space in CBFS with file header""" size = 0x70 cbw = CbfsWriter(size)
@@ -296,7 +306,7 @@ class TestCbfs(unittest.TestCase): cbw.add_file_raw('u-boot', U_BOOT_DATA) with self.assertRaises(ValueError) as e: cbw.get_data() - self.assertIn('No space for data before offset', str(e.exception)) + self.assertIn('No space for data before pad offset', str(e.exception)) def test_cbfs_bad_header_ptr(self): """Check handling of a bad master-header pointer"""
@@ -535,6 +545,17 @@ class TestCbfs(unittest.TestCase): cbfs_fname = self._get_expected_cbfs(size=size, compress=['lz4', 'lzma']) self._compare_expected_cbfs(data, cbfs_fname) + def test_cbfs_raw_space(self): + """Test files with unused space in the CBFS""" + size = 0xf0 + cbw = CbfsWriter(size) + cbw.add_file_raw('u-boot', U_BOOT_DATA) + cbw.add_file_raw('u-boot-dtb', U_BOOT_DTB_DATA) + data = cbw.get_data() + self._check_raw(data, size) + cbfs_fname = self._get_expected_cbfs(size=size) + self._compare_expected_cbfs(data, cbfs_fname) + if __name__ == '__main__': unittest.main()
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 36/37 binman: Pad empty areas of the CBFS with files
When there is lots of open space in a CBFS it is normally padded with 'empty' files so that sequentially scanning the CBFS can skip from one to the next without a break.
Add support for this.
---
Changes in v2: None
tools/binman/cbfs_util.py | 68 ++++++++++++++++++++++++++++++++-- tools/binman/cbfs_util_test.py | 23 +++++++++++- 2 files changed, 87 insertions(+), 4 deletions(-)
Applied to u-boot-dm, thanks!
PATCH v2 37/37 binman: Add support for fixed-offset files in CBFS
In reply to Simon GlassA feature of CBFS is that it allows files to be positioned at particular offset (as with binman in general). This is useful to support execute-in-place (XIP) code, since this may not be relocatable.
Add a new cbfs-offset property to control this.
---
Changes in v2:
- Deal with travis's old lz4 version by skipping tests as necessary
- Skip use of cbfstool in tests if it is not available
tools/binman/README.entries | 38 ++++++++ tools/binman/cbfs_util.py | 125 +++++++++++++++++++++----- tools/binman/cbfs_util_test.py | 82 +++++++++++++++-- tools/binman/etype/cbfs.py | 16 +++- tools/binman/ftest.py | 23 +++++ tools/binman/test/114_cbfs_offset.dts | 26 ++++++ 6 files changed, 276 insertions(+), 34 deletions(-) create mode 100644 tools/binman/test/114_cbfs_offset.dts
tools/binman/README.entries +38 -0
@@ -100,6 +100,7 @@ with the second subnode below: filename = "u-boot.dtb"; cbfs-type = "raw"; cbfs-compress = "lz4"; + cbfs-offset = <0x100000>; }; };
@@ -158,6 +159,15 @@ cbfs-type: to add a flat binary with a load/start address, similar to the 'add-flat-binary' option in cbfstool. +cbfs-offset: + This is the offset of the file's data within the CBFS. It is used to + specify where the file should be placed in cases where a fixed position + is needed. Typical uses are for code which is not relocatable and must + execute in-place from a particular address. This works because SPI flash + is generally mapped into memory on x86 devices. The file header is + placed before this offset so that the data start lines up exactly with + the chosen offset. If this property is not provided, then the file is + placed in the next available spot. The current implementation supports only a subset of CBFS features. It does not support other file types (e.g. payload), adding multiple files (like the
@@ -334,6 +344,34 @@ See README.x86 for information about x86 binary blobs. +Entry: intel-ifwi: Entry containing an Intel Integrated Firmware Image (IFWI) file +---------------------------------------------------------------------------------- + +Properties / Entry arguments: + - filename: Filename of file to read into entry. This is either the + IFWI file itself, or a file that can be converted into one using a + tool + - convert-fit: If present this indicates that the ifwitool should be + used to convert the provided file into a IFWI. + +This file contains code and data used by the SoC that is required to make +it work. It includes U-Boot TPL, microcode, things related to the CSE +(Converged Security Engine, the microcontroller that loads all the firmware) +and other items beyond the wit of man. + +A typical filename is 'ifwi.bin' for an IFWI file, or 'fitimage.bin' for a +file that will be converted to an IFWI. + +The position of this entry is generally set by the intel-descriptor entry. + +The contents of the IFWI are specified by the subnodes of the IFWI node. +Each subnode describes an entry which is placed into the IFWFI with a given +sub-partition (and optional entry name). + +See README.x86 for information about x86 binary blobs. + + + Entry: intel-me: Entry containing an Intel Management Engine (ME) file ----------------------------------------------------------------------
tools/binman/cbfs_util.py +102 -23
280 lines not on this page · raw message
tools/binman/cbfs_util_test.py +73 -9
166 lines not on this page · raw message
tools/binman/etype/cbfs.py +14 -2
@@ -52,6 +52,7 @@ class Entry_cbfs(Entry): filename = "u-boot.dtb"; cbfs-type = "raw"; cbfs-compress = "lz4"; + cbfs-offset = <0x100000>; }; };
@@ -110,6 +111,15 @@ class Entry_cbfs(Entry): to add a flat binary with a load/start address, similar to the 'add-flat-binary' option in cbfstool. + cbfs-offset: + This is the offset of the file's data within the CBFS. It is used to + specify where the file should be placed in cases where a fixed position + is needed. Typical uses are for code which is not relocatable and must + execute in-place from a particular address. This works because SPI flash + is generally mapped into memory on x86 devices. The file header is + placed before this offset so that the data start lines up exactly with + the chosen offset. If this property is not provided, then the file is + placed in the next available spot. The current implementation supports only a subset of CBFS features. It does not support other file types (e.g. payload), adding multiple files (like the
@@ -172,9 +182,10 @@ class Entry_cbfs(Entry): return False data = entry.GetData() if entry._type == 'raw': - cbfs.add_file_raw(entry._cbfs_name, data, entry._cbfs_compress) + cbfs.add_file_raw(entry._cbfs_name, data, entry._cbfs_offset, + entry._cbfs_compress) elif entry._type == 'stage': - cbfs.add_file_stage(entry._cbfs_name, data) + cbfs.add_file_stage(entry._cbfs_name, data, entry._cbfs_offset) data = cbfs.get_data() self.SetContents(data) return True
@@ -186,6 +197,7 @@ class Entry_cbfs(Entry): entry._cbfs_name = fdt_util.GetString(node, 'cbfs-name', entry.name) entry._type = fdt_util.GetString(node, 'cbfs-type') compress = fdt_util.GetString(node, 'cbfs-compress', 'none') + entry._cbfs_offset = fdt_util.GetInt(node, 'cbfs-offset') entry._cbfs_compress = cbfs_util.find_compress(compress) if entry._cbfs_compress is None: self.Raise("Invalid compression in '%s': '%s'" %
tools/binman/ftest.py +23 -0
@@ -2012,5 +2012,28 @@ class TestFunctional(unittest.TestCase): self.assertIn('Could not complete processing of contents', str(e.exception)) + def testCbfsOffset(self): + """Test a CBFS with files at particular offsets + + Like all CFBS tests, this is just checking the logic that calls + cbfs_util. See cbfs_util_test for fully tests (e.g. test_cbfs_offset()). + """ + data = self._DoReadFile('114_cbfs_offset.dts') + size = 0x200 + + cbfs = cbfs_util.CbfsReader(data) + self.assertEqual(size, cbfs.rom_size) + + self.assertIn('u-boot', cbfs.files) + cfile = cbfs.files['u-boot'] + self.assertEqual(U_BOOT_DATA, cfile.data) + self.assertEqual(0x40, cfile.cbfs_offset) + + self.assertIn('u-boot-dtb', cbfs.files) + cfile2 = cbfs.files['u-boot-dtb'] + self.assertEqual(U_BOOT_DTB_DATA, cfile2.data) + self.assertEqual(0x140, cfile2.cbfs_offset) + + if __name__ == "__main__": unittest.main()
tools/binman/test/114_cbfs_offset.dts new file +26 -0
@@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + sort-by-offset; + end-at-4gb; + size = <0x200>; + cbfs { + size = <0x200>; + offset = <0xfffffe00>; + u-boot { + cbfs-offset = <0x40>; + cbfs-type = "raw"; + }; + u-boot-dtb { + cbfs-offset = <0x140>; + cbfs-type = "raw"; + }; + }; + }; +};
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH v2 37/37 binman: Add support for fixed-offset files in CBFS
A feature of CBFS is that it allows files to be positioned at particular offset (as with binman in general). This is useful to support execute-in-place (XIP) code, since this may not be relocatable.
Add a new cbfs-offset property to control this.
---
Changes in v2:
- Deal with travis's old lz4 version by skipping tests as necessary
- Skip use of cbfstool in tests if it is not available
tools/binman/README.entries | 38 ++++++++ tools/binman/cbfs_util.py | 125 +++++++++++++++++++++----- tools/binman/cbfs_util_test.py | 82 +++++++++++++++-- tools/binman/etype/cbfs.py | 16 +++- tools/binman/ftest.py | 23 +++++ tools/binman/test/114_cbfs_offset.dts | 26 ++++++ 6 files changed, 276 insertions(+), 34 deletions(-) create mode 100644 tools/binman/test/114_cbfs_offset.dts
Applied to u-boot-dm, thanks!