binman: A tool for creating firmware images
Subsystems (4)
cover binman: A tool for creating firmware images
This series introduces binman, a tool designed to create firmware images. It provides a way to bring together various binaries and place them in an image, at particular positions and with configurable alignment.
Packaging of firmware is quite a different task from building the various parts. In many cases the various binaries which go into the image come from separate build systems. For example, ARM Trusted Firmware is used on ARMv8 devices but is not built in the U-Boot tree. If a Linux kernel is included in the firmware image, it is built elsewhere.
It is of course possible to add more and more build rules to the U-Boot build system to cover these cases. It can shell out to other Makefiles and build scripts. But it seems better to create a clear divide between building software and packaging it.
U-Boot supports a very large number of boards. Many of these have their own specific rules for how an image should be put together so that it boots correctly. At present these rules are described by manual instructions, different for each board. By turning these instructions into a standard format, we can support making valid images for any board without manual effort, lots of READMEs, etc.
Images consist of a number of entries which are combined to make up the final image. The image is described in the device tree for the board, meaning that it can be accessed at run-time if desired.
Binman is an extensible tool. A set of standard entries is provides, but new entries can be created fairly easily. Entries can be as simple as providing the name of a file to include. They can also handle more complex requirements, such as adjusting the input file or reading header information from one entry to control the position of another.
U-Boot's mkimage builds FIT images and various other binaries. Binman augments this by allowing these binaries to be packed together. While FIT should be used where possible, it cannot be used everywhere. For example, many devices require executable code at a particular offset in the image. X86 machines require lots of binary blobs at particular places, and a microcode collection easily accessible at boot.
So far binman has enough functionality to be useful, but apart from a few RFC patches, no attempt is made to switch boards over to use it. There should be enough material to permit review and comments.
The series is available at u-boot-dm/binman-working
Future work and missing features are documented in the README.
Simon Glass (30):
x86: Add debugging when a microcode update fails
x86: ivybridge: Allow microcode to be collated
x86: Add debugging when cpu_common_init() fails
patman: Adjust command.Output() to raise an error by default
dtoc: Move the struct import into the correct order
dtoc: Move the fdt library selection into fdt_select
dtoc: Rename fdt.py to fdt_normal.py
dtoc: Create a base class for Fdt
dtoc: Move BytesToValue() and GetEmpty() into PropBase
dtoc: Move Widen() and GetPhandle() into the base class
dtoc: Move a few more common functions into fdt.py
patman: Add a tools library for using temporary files
patman: Add a library to handle logging and progress
dtoc: Allow the device tree to be compiled from source
dtoc: Drop the convert_dash parameter to GetProps()
dtoc: Prepare for supporting changing of device trees
dtoc: Move to using bytearray
dtoc: Support deleting device tree properties
dtoc: Support packing the device tree
dtoc: Support finding the offset of a property
dtoc: Correct quotes in fdt_util
dtoc: Add methods for reading data from properties
binman: Introduce binman, a tool for building binary images
binman: Add basic entry types for U-Boot
binman: Add support for building x86 ROMs
binman: Add support for u-boot.img as an input binary
binman: Add a build rule for binman
binman: Allow configuration options to be used in .dts files
RFC: Use binman for a sunxi board
RFC: Use binman for an x86 board
Makefile | 55 +- arch/arm/dts/sun7i-a20-pcduino3.dts | 12 + arch/x86/cpu/intel_common/cpu.c | 4 +- arch/x86/cpu/intel_common/microcode.c | 12 +- arch/x86/cpu/ivybridge/cpu.c | 4 +- arch/x86/dts/chromebook_link.dts | 52 ++ lib/libfdt/libfdt.swig | 24 + scripts/Makefile.lib | 5 + tools/binman/.gitignore | 1 + tools/binman/README | 491 ++++++++++++++++ tools/binman/binman | 1 + tools/binman/binman.py | 96 +++ tools/binman/cmdline.py | 48 ++ tools/binman/control.py | 106 ++++ tools/binman/etype/blob.py | 37 ++ tools/binman/etype/entry.py | 186 ++++++ tools/binman/etype/intel_descriptor.py | 55 ++ tools/binman/etype/intel_me.py | 17 + tools/binman/etype/intel_mrc.py | 17 + tools/binman/etype/intel_vga.py | 17 + tools/binman/etype/u_boot.py | 17 + tools/binman/etype/u_boot_dtb.py | 17 + tools/binman/etype/u_boot_dtb_with_ucode.py | 69 +++ tools/binman/etype/u_boot_img.py | 17 + tools/binman/etype/u_boot_nodtb.py | 17 + tools/binman/etype/u_boot_spl.py | 17 + tools/binman/etype/u_boot_ucode.py | 77 +++ tools/binman/etype/u_boot_with_ucode_ptr.py | 71 +++ tools/binman/etype/x86_start16.py | 17 + tools/binman/func_test.py | 652 +++++++++++++++++++++ tools/binman/image.py | 233 ++++++++ tools/binman/test/01_invalid.dts | 5 + tools/binman/test/02_missing_node.dts | 6 + tools/binman/test/03_empty.dts | 9 + tools/binman/test/04_invalid_entry.dts | 11 + tools/binman/test/05_simple.dts | 11 + tools/binman/test/06_dual_image.dts | 22 + tools/binman/test/07_bad_align.dts | 12 + tools/binman/test/08_pack.dts | 30 + tools/binman/test/09_pack_extra.dts | 35 ++ tools/binman/test/10_pack_align_power2.dts | 12 + tools/binman/test/11_pack_align_size_power2.dts | 12 + tools/binman/test/12_pack_inv_align.dts | 13 + tools/binman/test/13_pack_inv_size_align.dts | 13 + tools/binman/test/14_pack_overlap.dts | 16 + tools/binman/test/15_pack_overflow.dts | 12 + tools/binman/test/16_pack_image_overflow.dts | 13 + tools/binman/test/17_pack_image_size.dts | 13 + tools/binman/test/18_pack_image_align.dts | 13 + tools/binman/test/19_pack_inv_image_align.dts | 14 + .../binman/test/20_pack_inv_image_align_power2.dts | 13 + tools/binman/test/21_image_pad.dts | 16 + tools/binman/test/22_image_name.dts | 21 + tools/binman/test/23_blob.dts | 12 + tools/binman/test/24_sorted.dts | 17 + tools/binman/test/25_pack_zero_size.dts | 15 + tools/binman/test/26_pack_u_boot_dtb.dts | 14 + tools/binman/test/27_pack_4gb_no_size.dts | 18 + tools/binman/test/28_pack_4gb_outside.dts | 19 + tools/binman/test/29_x86-rom.dts | 19 + tools/binman/test/30_x86-rom-me-no-desc.dts | 15 + tools/binman/test/31_x86-rom-me.dts | 18 + tools/binman/test/32_intel-vga.dts | 13 + tools/binman/test/33_x86-start16.dts | 13 + tools/binman/test/34_x86_ucode.dts | 29 + tools/binman/test/35_x86_single_ucode.dts | 26 + tools/binman/test/36_u_boot_img.dts | 11 + tools/binman/test/u_boot_ucode_ptr | Bin 0 -> 4175 bytes tools/binman/test/u_boot_ucode_ptr.c | 15 + tools/binman/test/u_boot_ucode_ptr.lds | 18 + tools/buildman/control.py | 2 +- tools/dtoc/dtoc.py | 38 +- tools/dtoc/fdt.py | 219 +++++-- tools/dtoc/fdt_fallback.py | 133 ++--- tools/dtoc/fdt_normal.py | 228 +++++++ tools/dtoc/fdt_select.py | 26 + tools/dtoc/fdt_util.py | 126 ++-- tools/patman/checkpatch.py | 3 +- tools/patman/command.py | 5 +- tools/patman/gitutil.py | 3 +- tools/patman/tools.py | 120 ++++ tools/patman/tout.py | 166 ++++++ 82 files changed, 3821 insertions(+), 286 deletions(-) create mode 100644 tools/binman/.gitignore create mode 100644 tools/binman/README create mode 120000 tools/binman/binman create mode 100755 tools/binman/binman.py create mode 100644 tools/binman/cmdline.py create mode 100644 tools/binman/control.py create mode 100644 tools/binman/etype/blob.py create mode 100644 tools/binman/etype/entry.py create mode 100644 tools/binman/etype/intel_descriptor.py create mode 100644 tools/binman/etype/intel_me.py create mode 100644 tools/binman/etype/intel_mrc.py create mode 100644 tools/binman/etype/intel_vga.py create mode 100644 tools/binman/etype/u_boot.py create mode 100644 tools/binman/etype/u_boot_dtb.py create mode 100644 tools/binman/etype/u_boot_dtb_with_ucode.py create mode 100644 tools/binman/etype/u_boot_img.py create mode 100644 tools/binman/etype/u_boot_nodtb.py create mode 100644 tools/binman/etype/u_boot_spl.py create mode 100644 tools/binman/etype/u_boot_ucode.py create mode 100644 tools/binman/etype/u_boot_with_ucode_ptr.py create mode 100644 tools/binman/etype/x86_start16.py create mode 100644 tools/binman/func_test.py create mode 100644 tools/binman/image.py create mode 100644 tools/binman/test/01_invalid.dts create mode 100644 tools/binman/test/02_missing_node.dts create mode 100644 tools/binman/test/03_empty.dts create mode 100644 tools/binman/test/04_invalid_entry.dts create mode 100644 tools/binman/test/05_simple.dts create mode 100644 tools/binman/test/06_dual_image.dts create mode 100644 tools/binman/test/07_bad_align.dts create mode 100644 tools/binman/test/08_pack.dts create mode 100644 tools/binman/test/09_pack_extra.dts create mode 100644 tools/binman/test/10_pack_align_power2.dts create mode 100644 tools/binman/test/11_pack_align_size_power2.dts create mode 100644 tools/binman/test/12_pack_inv_align.dts create mode 100644 tools/binman/test/13_pack_inv_size_align.dts create mode 100644 tools/binman/test/14_pack_overlap.dts create mode 100644 tools/binman/test/15_pack_overflow.dts create mode 100644 tools/binman/test/16_pack_image_overflow.dts create mode 100644 tools/binman/test/17_pack_image_size.dts create mode 100644 tools/binman/test/18_pack_image_align.dts create mode 100644 tools/binman/test/19_pack_inv_image_align.dts create mode 100644 tools/binman/test/20_pack_inv_image_align_power2.dts create mode 100644 tools/binman/test/21_image_pad.dts create mode 100644 tools/binman/test/22_image_name.dts create mode 100644 tools/binman/test/23_blob.dts create mode 100644 tools/binman/test/24_sorted.dts create mode 100644 tools/binman/test/25_pack_zero_size.dts create mode 100644 tools/binman/test/26_pack_u_boot_dtb.dts create mode 100644 tools/binman/test/27_pack_4gb_no_size.dts create mode 100644 tools/binman/test/28_pack_4gb_outside.dts create mode 100644 tools/binman/test/29_x86-rom.dts create mode 100644 tools/binman/test/30_x86-rom-me-no-desc.dts create mode 100644 tools/binman/test/31_x86-rom-me.dts create mode 100644 tools/binman/test/32_intel-vga.dts create mode 100644 tools/binman/test/33_x86-start16.dts create mode 100644 tools/binman/test/34_x86_ucode.dts create mode 100644 tools/binman/test/35_x86_single_ucode.dts create mode 100644 tools/binman/test/36_u_boot_img.dts create mode 100755 tools/binman/test/u_boot_ucode_ptr create mode 100644 tools/binman/test/u_boot_ucode_ptr.c create mode 100644 tools/binman/test/u_boot_ucode_ptr.lds create mode 100644 tools/dtoc/fdt_normal.py create mode 100644 tools/dtoc/fdt_select.py create mode 100644 tools/patman/tools.py create mode 100644 tools/patman/tout.py
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 1/30 x86: Add debugging when a microcode update fails
Add a debug() at this point to help figure out what is wrong.
---
arch/x86/cpu/intel_common/cpu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/cpu/intel_common/cpu.c +3 -1
@@ -42,8 +42,10 @@ int cpu_common_init(void)enable_lapic (); ret =microcode_update_intel (); -if (ret && ret != -EEXIST ) +if (ret && ret != -EEXIST ) { +debug ("%s: Microcode update failure (err=%d)\n" , __func__, ret);return ret; + }/* Enable upper 128bytes of CMOS */ writel (1 <<2 ,RCB_REG (RC ));
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 1/30 x86: Add debugging when a microcode update fails
Hello Simon,
Am 26.07.2016 um 02:58 schrieb Simon Glass:
Quoted 7 lines
Add a
debug()at this point to help figure out what is wrong.Signed-off-by Simon Glass <[email protected]>---
arch/x86/cpu/intel_common/cpu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
but wondering why this is in the "binman: A tool for creating firmware images" series.
bye,
Heiko
Quoted 18 lines
arch/x86/cpu/intel_common/cpu.c +3
-1@@ -42,8 +42,10 @@ int cpu_common_init(void)enable_lapic (); ret =microcode_update_intel (); -if (ret && ret != -EEXIST ) +if (ret && ret != -EEXIST ) { +debug ("%s: Microcode update failure (err=%d)\n" , __func__, ret);return ret; + }/* Enable upper 128bytes of CMOS */ writel (1 <<2 ,RCB_REG (RC ));
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 1/30 x86: Add debugging when a microcode update fails
In reply to Simon GlassQuoted 8 lines · Simon Glass
Add a
debug()at this point to help figure out what is wrong.Signed-off-by Simon Glass <[email protected]>---
arch/x86/cpu/intel_common/cpu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
PATCH 1/30 x86: Add debugging when a microcode update fails
Quoted 11 lines · Bin Meng
Quoted 8 lines · Simon Glass
Add a
debug()at this point to help figure out what is wrong.Signed-off-by Simon Glass <[email protected]>---
arch/x86/cpu/intel_common/cpu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Reviewed-by Bin Meng <[email protected]>
applied to u-boot-x86, thanks!
PATCH 2/30 x86: ivybridge: Allow microcode to be collated
In reply to Simon GlassGenerally the microcode is combined into a single block only (and removed from the device tree) when there are multiple blocks. But this is not a requirement.
Adjust the ivybridge code to avoid assuming this.
---
arch/x86/cpu/intel_common/microcode.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
arch/x86/cpu/intel_common/microcode.c +11 -1
@@ -43,7 +43,7 @@ static int microcode_decode_node(const void *blob, int node, { update->data =fdt_getprop (blob, node,"data" , &update->size);if (!update->data) -return -EINVAL ; +return -ENOENT ; update->data +=UCODE_HEADER_LEN ; update->size -=UCODE_HEADER_LEN ;
@@ -145,6 +145,16 @@ int microcode_update_intel(void) } ret =microcode_decode_node (blob, node, &update); +if (ret == -ENOENT && ucode_base) { +/* +* The microcode has been removed from the device tree +* in the build system. In that case it will have +* already been updated in car_init(). +*/ +debug ("%s: Microcode data not available\n" , __func__); + skipped++; +continue ; + }if (ret) {debug ("%s: Unable to decode update: %d\n" , __func__, ret);
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 2/30 x86: ivybridge: Allow microcode to be collated
Quoted 4 lines · Simon Glass
Generally the microcode is combined into a single block only (and removed from the device tree) when there are multiple blocks. But this is not a requirement.
Quoted 8 lines
Adjust the ivybridge code to avoid assuming this.
Signed-off-by Simon Glass <[email protected]>---
arch/x86/cpu/intel_common/microcode.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
PATCH 2/30 x86: ivybridge: Allow microcode to be collated
Quoted 7 lines · Bin Meng
Quoted 6 lines · Simon Glass
Generally the microcode is combined into a single block only (and removed from the device tree) when there are multiple blocks. But this is not a requirement.
Adjust the ivybridge code to avoid assuming this.
Quoted 8 lines
Quoted 6 lines
Signed-off-by Simon Glass <[email protected]>---
arch/x86/cpu/intel_common/microcode.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)Reviewed-by Bin Meng <[email protected]>
applied to u-boot-x86, thanks!
PATCH 3/30 x86: Add debugging when cpu_common_init() fails
In reply to Simon GlassAdd a debug() at this point to help figure out what is wrong.
---
arch/x86/cpu/ivybridge/cpu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/cpu/ivybridge/cpu.c +3 -1
@@ -146,8 +146,10 @@ int print_cpuinfo(void) } ret =cpu_common_init (); -if (ret) +if (ret) { +debug ("%s: cpu_common_init() failed\n" , __func__);return ret; + }/* Check PM1_STS[15] to see if we are waking from Sx */ pm1_sts =inw (DEFAULT_PMBASE +PM1_STS );
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 3/30 x86: Add debugging when cpu_common_init() fails
Quoted 8 lines · Simon Glass
Add a
debug()at this point to help figure out what is wrong.Signed-off-by Simon Glass <[email protected]>---
arch/x86/cpu/ivybridge/cpu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
PATCH 3/30 x86: Add debugging when cpu_common_init() fails
Quoted 11 lines · Bin Meng
Quoted 8 lines · Simon Glass
Add a
debug()at this point to help figure out what is wrong.Signed-off-by Simon Glass <[email protected]>---
arch/x86/cpu/ivybridge/cpu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Reviewed-by Bin Meng <[email protected]>
applied to u-boot-x86, thanks!
PATCH 4/30 patman: Adjust command.Output() to raise an error by default
In reply to Simon GlassIt is more useful to have this method raise an error when something goes wrong. Make this the default and adjust the few callers that don't want to use it this way.
---
tools/buildman/control.py | 2 +- tools/patman/checkpatch.py | 3 ++- tools/patman/command.py | 5 +++-- tools/patman/gitutil.py | 3 ++- 4 files changed, 8 insertions(+), 5 deletions(-)
tools/buildman/control.py +1 -1
@@ -231,7 +231,7 @@ def DoBuildman(options, args, toolchains=None, make_func=None, boards=None, options.step = len(series.commits) - 1 gnu_make = command.Output(os.path.join(options.git, - 'scripts/show-gnu-make')).rstrip() + 'scripts/show-gnu-make'), raise_on_error=False).rstrip() if not gnu_make: sys.exit('GNU Make not found')
tools/patman/checkpatch.py +2 -1
@@ -63,7 +63,8 @@ def CheckPatch(fname, verbose=False): result.problems = [] chk = FindCheckPatch() item = {} - result.stdout = command.Output(chk, '--no-tree', fname) + result.stdout = command.Output(chk, '--no-tree', fname, + raise_on_error=False) #pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE) #stdout, stderr = pipe.communicate()
tools/patman/command.py +3 -2
@@ -104,8 +104,9 @@ def RunPipe(pipe_list, infile=None, outfile=None, raise Exception("Error running '%s'" % user_pipestr) return result -def Output(*cmd): - return RunPipe([cmd], capture=True, raise_on_error=False).stdout +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 def OutputOneLine(*cmd, **kwargs): raise_on_error = kwargs.pop('raise_on_error', True)
tools/patman/gitutil.py +2 -1
@@ -391,7 +391,8 @@ def EmailPatches(series, cover_fname, args, dry_run, raise_on_error, cc_fname, """ to = BuildEmailList(series.get('to'), '--to', alias, raise_on_error) if not to: - git_config_to = command.Output('git', 'config', 'sendemail.to') + git_config_to = command.Output('git', 'config', 'sendemail.to', + raise_on_error=False) if not git_config_to: print ("No recipient.\n" "Please add something like this to a commit\n"
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 4/30 patman: Adjust command.Output() to raise an error by default
Quoted 4 lines · Simon Glass
It is more useful to have this method raise an error when something goes wrong. Make this the default and adjust the few callers that don't want to use it this way.
Quoted 8 lines
Signed-off-by Simon Glass <[email protected]>---
tools/buildman/control.py | 2 +- tools/patman/checkpatch.py | 3 ++- tools/patman/command.py | 5 +++-- tools/patman/gitutil.py | 3 ++- 4 files changed, 8 insertions(+), 5 deletions(-)
Applied to u-boot-dm/next.
PATCH 5/30 dtoc: Move the struct import into the correct order
In reply to Simon GlassThis should be in with the other system includes. Move it.
---
tools/dtoc/dtoc.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
tools/dtoc/dtoc.py +1 -2
@@ -9,6 +9,7 @@ import copy from optparse import OptionError, OptionParser import os +import struct import sys import fdt_util
@@ -29,8 +30,6 @@ except ImportError: from fdt_fallback import Fdt import fdt_fallback as fdt -import struct - # When we see these properties we ignore them - i.e. do not create a structure member PROP_IGNORE_LIST = [ '#address-cells',
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 5/30 dtoc: Move the struct import into the correct order
Quoted 7 lines · Simon Glass
This should be in with the other system includes. Move it.
Signed-off-by Simon Glass <[email protected]>---
tools/dtoc/dtoc.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Applied to u-boot-dm/next.
PATCH 6/30 dtoc: Move the fdt library selection into fdt_select
In reply to Simon GlassRather than have dtc worry about which fdt library to use, move this into a helper file. Add a function which creates a new Fdt object and scans it, regardless of the implementation.
---
tools/dtoc/dtoc.py | 18 +++--------------- tools/dtoc/fdt_select.py | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 tools/dtoc/fdt_select.py
tools/dtoc/dtoc.py +3 -15
@@ -12,23 +12,12 @@ import os import struct import sys -import fdt_util - # Bring in the patman libraries our_path = os.path.dirname(os.path.realpath(__file__)) sys.path.append(os.path.join(our_path, '../patman')) -# Bring in either the normal fdt library (which relies on libfdt) or the -# fallback one (which uses fdtget and is slower). Both provide the same -# interfface for this file to use. -try: - from fdt import Fdt - import fdt - have_libfdt = True -except ImportError: - have_libfdt = False - from fdt_fallback import Fdt - import fdt_fallback as fdt +import fdt_select +import fdt_util # When we see these properties we ignore them - i.e. do not create a structure member PROP_IGNORE_LIST = [
@@ -177,8 +166,7 @@ class DtbPlatdata: Once this is done, self.fdt.GetRoot() can be called to obtain the device tree root node, and progress from there. """ - self.fdt = Fdt(self._dtb_fname) - self.fdt.Scan() + self.fdt = fdt_select.FdtScan(self._dtb_fname) def ScanTree(self): """Scan the device tree for useful information
tools/dtoc/fdt_select.py new file +23 -0
@@ -0,0 +1,23 @@ +#!/usr/bin/python +# +# Copyright (C) 2016 Google, Inc +# Written by Simon Glass <[email protected]> +# +# SPDX-License-Identifier: GPL-2.0+ +# + +# Bring in either the normal fdt library (which relies on libfdt) or the +# fallback one (which uses fdtget and is slower). Both provide the same +# interface for this file to use. +try: + import fdt + have_libfdt = True +except ImportError: + have_libfdt = False + import fdt_fallback as fdt + +def FdtScan(fname): + """Returns a new Fdt object from the implementation we are using""" + dtb = fdt.Fdt(fname) + dtb.Scan() + return dtb
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 6/30 dtoc: Move the fdt library selection into fdt_select
Quoted 11 lines · Simon Glass
Rather than have dtc worry about which fdt library to use, move this into a helper file. Add a function which creates a new Fdt object and scans it, regardless of the implementation.
Signed-off-by Simon Glass <[email protected]>---
tools/dtoc/dtoc.py | 18 +++--------------- tools/dtoc/fdt_select.py | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 tools/dtoc/fdt_select.py
Applied to u-boot-dm/next.
PATCH 7/30 dtoc: Rename fdt.py to fdt_normal.py
In reply to Simon GlassIn preparation for creating an Fdt base class, rename this file to indicate it is the normal Fdt implementation.
---
tools/dtoc/{fdt.py => fdt_normal.py} | 0
tools/dtoc/fdt_select.py | 2 +-
2 files changed, 1 insertion(+), 1 deletion(-)
rename tools/dtoc/{fdt.py => fdt_normal.py} (100%)tools/dtoc/fdt_normal.py renamed from tools/dtoc/fdt.py +0 -0
tools/dtoc/fdt_select.py +1 -1
@@ -10,7 +10,7 @@ # fallback one (which uses fdtget and is slower). Both provide the same # interface for this file to use. try: - import fdt + import fdt_normal as fdt have_libfdt = True except ImportError: have_libfdt = False
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 7/30 dtoc: Rename fdt.py to fdt_normal.py
Quoted 10 lines · Simon Glass
In preparation for creating an Fdt base class, rename this file to indicate it is the normal Fdt implementation.
Signed-off-by Simon Glass <[email protected]>---
tools/dtoc/{fdt.py => fdt_normal.py} | 0 tools/dtoc/fdt_select.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename tools/dtoc/{fdt.py => fdt_normal.py} (100%)
Applied to u-boot-dm/next.
PATCH 8/30 dtoc: Create a base class for Fdt
In reply to Simon GlassAt present we have two separate implementations of the Fdt library, one which uses fdtget/fdtput and one which uses libfdt (via swig).
Before adding more functionality it makes sense to create a base class for these. This will allow common functions to be shared, and make the Fdt API a little clearer.
Create a new fdt.py file with the base class, and adjust fdt_normal.py and fdt_fallback.py to use it.
---
tools/dtoc/fdt.py | 68 ++++++++++++++++++++++++++++++++++++++++++++++ tools/dtoc/fdt_fallback.py | 61 +++++++++++++++++++++++++---------------- tools/dtoc/fdt_normal.py | 58 +++++++++++++++++++++++++-------------- tools/dtoc/fdt_select.py | 9 ++++-- 4 files changed, 148 insertions(+), 48 deletions(-) create mode 100644 tools/dtoc/fdt.py
tools/dtoc/fdt.py new file +68 -0
@@ -0,0 +1,68 @@ +#!/usr/bin/python +# +# Copyright (C) 2016 Google, Inc +# Written by Simon Glass <[email protected]> +# +# SPDX-License-Identifier: GPL-2.0+ +# + +import struct +import sys + +import fdt_util + +# This deals with a device tree, presenting it as an assortment of Node and +# Prop objects, representing nodes and properties, respectively. This file +# contains the base classes and defines the high-level API. Most of the +# implementation is in the FdtFallback and FdtNormal subclasses. See +# fdt_select.py for how to create an Fdt object. + +def CheckErr(errnum, msg): + if errnum: + raise ValueError('Error %d: %s: %s' % + (errnum, libfdt.fdt_strerror(errnum), msg)) + +class PropBase: + """A device tree property + + Properties: + name: Property name (as per the device tree) + value: Property value as a string of bytes, or a list of strings of + bytes + type: Value type + """ + def __init__(self, node, offset, name): + self._node = node + self._offset = offset + self.name = name + self.value = None + +class NodeBase: + """A device tree node + + Properties: + offset: Integer offset in the device tree + name: Device tree node tname + path: Full path to node, along with the node name itself + _fdt: Device tree object + subnodes: A list of subnodes for this node, each a Node object + props: A dict of properties for this node, each a Prop object. + Keyed by property name + """ + def __init__(self, fdt, offset, name, path): + self._fdt = fdt + self._offset = offset + self.name = name + self.path = path + self.subnodes = [] + self.props = {} + +class Fdt: + """Provides simple access to a flat device tree blob. + + Properties: + fname: Filename of fdt + _root: Root of device tree (a Node object) + """ + def __init__(self, fname): + self._fname = fname
tools/dtoc/fdt_fallback.py +37 -24
142 lines not on this page · raw message
tools/dtoc/fdt_normal.py +37 -21
113 lines not on this page · raw message
tools/dtoc/fdt_select.py +6 -3
@@ -10,14 +10,17 @@ # fallback one (which uses fdtget and is slower). Both provide the same # interface for this file to use. try: - import fdt_normal as fdt + import fdt_normal have_libfdt = True except ImportError: have_libfdt = False - import fdt_fallback as fdt + import fdt_fallback def FdtScan(fname): """Returns a new Fdt object from the implementation we are using""" - dtb = fdt.Fdt(fname) + if have_libfdt: + dtb = fdt_normal.FdtNormal(fname) + else: + dtb = fdt_fallback.FdtFallback(fname) dtb.Scan() return dtb
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 8/30 dtoc: Create a base class for Fdt
Quoted 11 lines · Simon Glass
At present we have two separate implementations of the Fdt library, one which uses fdtget/fdtput and one which uses libfdt (via swig).
Before adding more functionality it makes sense to create a base class for these. This will allow common functions to be shared, and make the Fdt API a little clearer.
Create a new
fdt.pyfile with the base class, and adjustfdt_normal.pyandfdt_fallback.pyto use it.Signed-off-by Simon Glass <[email protected]>
Quoted 8 lines
---
tools/dtoc/fdt.py | 68 ++++++++++++++++++++++++++++++++++++++++++++++ tools/dtoc/fdt_fallback.py | 61 +++++++++++++++++++++++++---------------- tools/dtoc/fdt_normal.py | 58 +++++++++++++++++++++++++-------------- tools/dtoc/fdt_select.py | 9 ++++-- 4 files changed, 148 insertions(+), 48 deletions(-) create mode 100644 tools/dtoc/fdt.py
Applied to u-boot-dm/next.
PATCH 9/30 dtoc: Move BytesToValue() and GetEmpty() into PropBase
In reply to Simon GlassThese functions are currently in a separate fdt_util file. Since they are only used from PropBase and subclasses, it makes sense for them to be in the PropBase class.
Move these functions into fdt.py along with the list of types.
---
tools/dtoc/dtoc.py | 17 ++++++------ tools/dtoc/fdt.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++ tools/dtoc/fdt_fallback.py | 4 +-- tools/dtoc/fdt_normal.py | 6 ++--- tools/dtoc/fdt_util.py | 66 ---------------------------------------------- 5 files changed, 80 insertions(+), 79 deletions(-)
tools/dtoc/dtoc.py +9 -8
@@ -16,6 +16,7 @@ import sys our_path = os.path.dirname(os.path.realpath(__file__)) sys.path.append(os.path.join(our_path, '../patman')) +import fdt import fdt_select import fdt_util
@@ -33,10 +34,10 @@ PROP_IGNORE_LIST = [ # C type declarations for the tyues we support TYPE_NAMES = { - fdt_util.TYPE_INT: 'fdt32_t', - fdt_util.TYPE_BYTE: 'unsigned char', - fdt_util.TYPE_STRING: 'const char *', - fdt_util.TYPE_BOOL: 'bool', + fdt.TYPE_INT: 'fdt32_t', + fdt.TYPE_BYTE: 'unsigned char', + fdt.TYPE_STRING: 'const char *', + fdt.TYPE_BOOL: 'bool', }; STRUCT_PREFIX = 'dtd_'
@@ -138,13 +139,13 @@ class DtbPlatdata: type: Data type (fdt_util) value: Data value, as a string of bytes """ - if type == fdt_util.TYPE_INT: + if type == fdt.TYPE_INT: return '%#x' % fdt_util.fdt32_to_cpu(value) - elif type == fdt_util.TYPE_BYTE: + elif type == fdt.TYPE_BYTE: return '%#x' % ord(value[0]) - elif type == fdt_util.TYPE_STRING: + elif type == fdt.TYPE_STRING: return '"%s"' % value - elif type == fdt_util.TYPE_BOOL: + elif type == fdt.TYPE_BOOL: return 'true' def GetCompatName(self, node):
tools/dtoc/fdt.py +66 -0
78 lines not on this page · raw message
tools/dtoc/fdt_fallback.py +2 -2
@@ -31,11 +31,11 @@ class Prop(PropBase): def __init__(self, node, name, byte_list_str): PropBase.__init__(self, node, 0, name) if not byte_list_str.strip(): - self.type = fdt_util.TYPE_BOOL + self.type = fdt.TYPE_BOOL return self.bytes = [chr(int(byte, 16)) for byte in byte_list_str.strip().split(' ')] - self.type, self.value = fdt_util.BytesToValue(''.join(self.bytes)) + self.type, self.value = self.BytesToValue(''.join(self.bytes)) def GetPhandle(self): """Get a (single) phandle value from a property
tools/dtoc/fdt_normal.py +3 -3
@@ -33,10 +33,10 @@ class Prop(PropBase): PropBase.__init__(self, node, offset, name) self.bytes = bytes if not bytes: - self.type = fdt_util.TYPE_BOOL + self.type = fdt.TYPE_BOOL self.value = True return - self.type, self.value = fdt_util.BytesToValue(bytes) + self.type, self.value = self.BytesToValue(bytes) def GetPhandle(self): """Get a (single) phandle value from a property
@@ -75,7 +75,7 @@ class Prop(PropBase): self.value = [self.value] if type(self.value) == list and len(newprop.value) > len(self.value): - val = fdt_util.GetEmpty(self.type) + val = self.GetEmpty(self.type) while len(self.value) < len(newprop.value): self.value.append(val)
tools/dtoc/fdt_util.py +0 -66
72 lines not on this page · raw message
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 9/30 dtoc: Move BytesToValue() and GetEmpty() into PropBase
Quoted 7 lines · Simon Glass
These functions are currently in a separate
fdt_utilfile. Since they are only used from PropBase and subclasses, it makes sense for them to be in the PropBase class.Move these functions into
fdt.pyalong with the list of types.Signed-off-by Simon Glass <[email protected]>
Quoted 8 lines
---
tools/dtoc/dtoc.py | 17 ++++++------ tools/dtoc/fdt.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++ tools/dtoc/fdt_fallback.py | 4 +-- tools/dtoc/fdt_normal.py | 6 ++--- tools/dtoc/fdt_util.py | 66 ---------------------------------------------- 5 files changed, 80 insertions(+), 79 deletions(-)
Applied to u-boot-dm/next.
PATCH 10/30 dtoc: Move Widen() and GetPhandle() into the base class
In reply to Simon GlassThese functions are identical in both subclasses. Move them into the base class.
Note: In fact there is a bug in one version, which was fixed by this patch:
https://patchwork.ozlabs.org/patch/651697/
---
tools/dtoc/fdt.py | 41 +++++++++++++++++++++++++++++++++++++++++ tools/dtoc/fdt_fallback.py | 36 ------------------------------------ tools/dtoc/fdt_normal.py | 42 ------------------------------------------ 3 files changed, 41 insertions(+), 78 deletions(-)
tools/dtoc/fdt.py +41 -0
@@ -40,6 +40,47 @@ class PropBase: self.name = name self.value = None + def GetPhandle(self): + """Get a (single) phandle value from a property + + Gets the phandle valuie from a property and returns it as an integer + """ + return fdt_util.fdt32_to_cpu(self.value[:4]) + + def Widen(self, newprop): + """Figure out which property type is more general + + Given a current property and a new property, this function returns the + one that is less specific as to type. The less specific property will + be ble to represent the data in the more specific property. This is + used for things like: + + node1 { + compatible = "fred"; + value = <1>; + }; + node1 { + compatible = "fred"; + value = <1 2>; + }; + + He we want to use an int array for 'value'. The first property + suggests that a single int is enough, but the second one shows that + it is not. Calling this function with these two propertes would + update the current property to be like the second, since it is less + specific. + """ + if newprop.type < self.type: + self.type = newprop.type + + if type(newprop.value) == list and type(self.value) != list: + self.value = [self.value] + + if type(self.value) == list and len(newprop.value) > len(self.value): + val = self.GetEmpty(self.type) + while len(self.value) < len(newprop.value): + self.value.append(val) + def BytesToValue(self, bytes): """Converts a string of bytes into a type and value
tools/dtoc/fdt_fallback.py +0 -36
@@ -37,42 +37,6 @@ class Prop(PropBase): for byte in byte_list_str.strip().split(' ')] self.type, self.value = self.BytesToValue(''.join(self.bytes)) - def GetPhandle(self): - """Get a (single) phandle value from a property - - Gets the phandle valuie from a property and returns it as an integer - """ - return fdt_util.fdt32_to_cpu(self.value[:4]) - - def Widen(self, newprop): - """Figure out which property type is more general - - Given a current property and a new property, this function returns the - one that is less specific as to type. The less specific property will - be ble to represent the data in the more specific property. This is - used for things like: - - node1 { - compatible = "fred"; - value = <1>; - }; - node1 { - compatible = "fred"; - value = <1 2>; - }; - - He we want to use an int array for 'value'. The first property - suggests that a single int is enough, but the second one shows that - it is not. Calling this function with these two propertes would - update the current property to be like the second, since it is less - specific. - """ - if newprop.type < self.type: - self.type = newprop.type - - if type(newprop.value) == list and type(self.value) != list: - self.value = newprop.value - class Node(NodeBase): """A device tree node
tools/dtoc/fdt_normal.py +0 -42
48 lines not on this page · raw message
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 10/30 dtoc: Move Widen() and GetPhandle() into the base class
Quoted 7 lines · Simon Glass
These functions are identical in both subclasses. Move them into the base class.
Note: In fact there is a bug in one version, which was fixed by this patch:
Quoted 7 lines
Signed-off-by Simon Glass <[email protected]>---
tools/dtoc/fdt.py | 41 +++++++++++++++++++++++++++++++++++++++++ tools/dtoc/fdt_fallback.py | 36 ------------------------------------ tools/dtoc/fdt_normal.py | 42 ------------------------------------------ 3 files changed, 41 insertions(+), 78 deletions(-)
Applied to u-boot-dm/next.
PATCH 11/30 dtoc: Move a few more common functions into fdt.py
In reply to Simon GlassSome functions have the same code in the subclasses. Move these into the superclass to avoid duplication.
---
tools/dtoc/fdt.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++ tools/dtoc/fdt_fallback.py | 16 ------------- tools/dtoc/fdt_normal.py | 16 ------------- 3 files changed, 57 insertions(+), 32 deletions(-)
tools/dtoc/fdt.py +57 -0
@@ -164,6 +164,26 @@ class NodeBase: self.subnodes = [] self.props = {} + def _FindNode(self, name): + """Find a node given its name + + Args: + name: Node name to look for + Returns: + Node object if found, else None + """ + for subnode in self.subnodes: + if subnode.name == name: + return subnode + return None + + def Scan(self): + """Scan the subnodes of a node + + This should be implemented by subclasses + """ + raise NotImplementedError() + class Fdt: """Provides simple access to a flat device tree blob.
@@ -173,3 +193,40 @@ class Fdt: """ def __init__(self, fname): self._fname = fname + + def Scan(self, root='/'): + """Scan a device tree, building up a tree of Node objects + + This fills in the self._root property + + Args: + root: Ignored + + TODO(sjg at chromium.org): Implement the 'root' parameter + """ + self._root = self.Node(self, 0, '/', '/') + self._root.Scan() + + def GetRoot(self): + """Get the root Node of the device tree + + Returns: + The root Node object + """ + return self._root + + def GetNode(self, path): + """Look up a node from its path + + Args: + path: Path to look up, e.g. '/microcode/update at 0' + Returns: + Node object, or None if not found + """ + node = self._root + for part in path.split('/')[1:]: + node = node._FindNode(part) + if not node: + return None + return node +
tools/dtoc/fdt_fallback.py +0 -16
@@ -80,22 +80,6 @@ class FdtFallback(Fdt): def __init__(self, fname): Fdt.__init__(self, fname) - def Scan(self): - """Scan a device tree, building up a tree of Node objects - - This fills in the self._root property - """ - self._root = Node(self, 0, '/', '/') - self._root.Scan() - - def GetRoot(self): - """Get the root Node of the device tree - - Returns: - The root Node object - """ - return self._root - def GetSubNodes(self, node): """Returns a list of sub-nodes of a given node
tools/dtoc/fdt_normal.py +0 -16
@@ -94,22 +94,6 @@ class FdtNormal(Fdt): """ return self._fdt - def Scan(self): - """Scan a device tree, building up a tree of Node objects - - This fills in the self._root property - """ - self._root = Node(self, 0, '/', '/') - self._root.Scan() - - def GetRoot(self): - """Get the root Node of the device tree - - Returns: - The root Node object - """ - return self._root - def GetProps(self, node): """Get all properties from a node.
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 11/30 dtoc: Move a few more common functions into fdt.py
Quoted 10 lines · Simon Glass
Some functions have the same code in the subclasses. Move these into the superclass to avoid duplication.
Signed-off-by Simon Glass <[email protected]>---
tools/dtoc/fdt.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++ tools/dtoc/fdt_fallback.py | 16 ------------- tools/dtoc/fdt_normal.py | 16 ------------- 3 files changed, 57 insertions(+), 32 deletions(-)
Applied to u-boot-dm/next.
PATCH 12/30 patman: Add a tools library for using temporary files
In reply to Simon GlassFor tools which want to use input files and temporary output, it is useful to have the handling of these dealt with in one place. Add a new library which allows input files to be read, and output files to be written, all based on a common directory structure.
---
tools/patman/tools.py | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 tools/patman/tools.py
tools/patman/tools.py new file +120 -0
@@ -0,0 +1,120 @@ +# +# Copyright (c) 2016 Google, Inc +# +# SPDX-License-Identifier: GPL-2.0+ +# + +import os +import shutil +import tempfile + +import tout + +outdir = None +indirs = None +preserve_outdir = False + +def PrepareOutputDir(dirname, preserve=False): + """Select an output directory, ensuring it exists. + + This either creates a temporary directory or checks that the one supplied + by the user is valid. For a temporary directory, it makes a note to + remove it later if required. + + Args: + dirname: a string, name of the output directory to use to store + intermediate and output files. If is None - create a temporary + directory. + preserve: a Boolean. If outdir above is None and preserve is False, the + created temporary directory will be destroyed on exit. + + Raises: + OSError: If it cannot create the output directory. + """ + global outdir, preserve_outdir + + preserve_outdir = dirname or preserve + if dirname: + outdir = dirname + if not os.path.isdir(outdir): + try: + os.makedirs(outdir) + except OSError as err: + raise CmdError("Cannot make output directory '%s': '%s'" % + (outdir, err.strerror)) + tout.Debug("Using output directory '%s'" % outdir) + else: + outdir = tempfile.mkdtemp(prefix='binman.') + tout.Debug("Using temporary directory '%s'" % outdir) + +def _RemoveOutputDir(): + global outdir + + shutil.rmtree(outdir) + tout.Debug("Deleted temporary directory '%s'" % outdir) + outdir = None + +def FinaliseOutputDir(): + global outdir, preserve_outdir + + """Tidy up: delete output directory if temporary and not preserved.""" + if outdir and not preserve_outdir: + _RemoveOutputDir() + +def GetOutputFilename(fname): + """Return a filename within the output directory. + + Args: + fname: Filename to use for new file + + Returns: + The full path of the filename, within the output directory + """ + return os.path.join(outdir, fname) + +def _FinaliseForTest(): + """Remove the output directory (for use by tests)""" + global outdir + + if outdir: + _RemoveOutputDir() + +def SetInputDirs(dirname): + """Add a list of input directories, where input files are kept. + + Args: + dirname: a list of paths to input directories to use for obtaining + files needed by binman to place in the image. + """ + global indir + + indir = dirname + tout.Debug("Using input directories %s" % indir) + +def GetInputFilename(fname): + """Return a filename for use as input. + + Args: + fname: Filename to use for new file + + Returns: + The full path of the filename, within the input directory + """ + if not indir: + return fname + for dirname in indir: + pathname = os.path.join(dirname, fname) + if os.path.exists(pathname): + return pathname + + raise ValueError("Filename '%s' not found in input path (%s)" % + (fname, ','.join(indir))) + +def Align(pos, align): + if align: + mask = align - 1 + pos = (pos + mask) & ~mask + return pos + +def NotPowerOfTwo(num): + return num and (num & (num - 1))
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 12/30 patman: Add a tools library for using temporary files
Quoted 11 lines · Simon Glass
For tools which want to use input files and temporary output, it is useful to have the handling of these dealt with in one place. Add a new library which allows input files to be read, and output files to be written, all based on a common directory structure.
Signed-off-by Simon Glass <[email protected]>---
tools/patman/tools.py | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 tools/patman/tools.py
Applied to u-boot-dm/next.
PATCH 13/30 patman: Add a library to handle logging and progress
In reply to Simon GlassWhen tools want to display information of varying levels of importance, it helps to provide the user with control over the verbosity of these messages. Progress messages work best if they are displayed and then removed from the display when no-longer relevant.
Add a new tout library (terminal out) to handle these tasks.
---
tools/patman/tout.py | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 tools/patman/tout.py
tools/patman/tout.py new file +166 -0
@@ -0,0 +1,166 @@ +# Copyright (c) 2016 Google, Inc +# +# SPDX-License-Identifier: GPL-2.0+ +# +# Terminal output logging. +# + +import sys + +import terminal + +# Output verbosity levels that we support +ERROR = 0 +WARNING = 1 +NOTICE = 2 +INFO = 3 +DEBUG = 4 + +""" +This class handles output of progress and other useful information +to the user. It provides for simple verbosity level control and can +output nothing but errors at verbosity zero. + +The idea is that modules set up an Output object early in their years and pass +it around to other modules that need it. This keeps the output under control +of a single class. + +Public properties: + verbose: Verbosity level: 0=silent, 1=progress, 3=full, 4=debug +""" +def __enter__(): + return + +def __exit__(unused1, unused2, unused3): + """Clean up and remove any progress message.""" + ClearProgress() + return False + +def UserIsPresent(): + """This returns True if it is likely that a user is present. + + Sometimes we want to prompt the user, but if no one is there then this + is a waste of time, and may lock a script which should otherwise fail. + + Returns: + True if it thinks the user is there, and False otherwise + """ + return stdout_is_tty and verbose > 0 + +def ClearProgress(): + """Clear any active progress message on the terminal.""" + if verbose > 0 and stdout_is_tty: + _stdout.write('\r%s\r' % (" " * len (_progress))) + _stdout.flush() + +def Progress(msg, warning=False, trailer='...'): + """Display progress information. + + Args: + msg: Message to display. + warning: True if this is a warning.""" + ClearProgress() + if verbose > 0: + _progress = msg + trailer + if stdout_is_tty: + col = _color.YELLOW if warning else _color.GREEN + _stdout.write('\r' + _color.Color(col, _progress)) + _stdout.flush() + else: + _stdout.write(_progress + '\n') + +def _Output(level, msg, color=None): + """Output a message to the terminal. + + Args: + level: Verbosity level for this message. It will only be displayed if + this as high as the currently selected level. + msg; Message to display. + error: True if this is an error message, else False. + """ + if verbose >= level: + ClearProgress() + if color: + msg = _color.Color(color, msg) + _stdout.write(msg + '\n') + +def DoOutput(level, msg): + """Output a message to the terminal. + + Args: + level: Verbosity level for this message. It will only be displayed if + this as high as the currently selected level. + msg; Message to display. + """ + _Output(level, msg) + +def Error(msg): + """Display an error message + + Args: + msg; Message to display. + """ + _Output(0, msg, _color.RED) + +def Warning(msg): + """Display a warning message + + Args: + msg; Message to display. + """ + _Output(1, msg, _color.YELLOW) + +def Notice(msg): + """Display an important infomation message + + Args: + msg; Message to display. + """ + _Output(2, msg) + +def Info(msg): + """Display an infomation message + + Args: + msg; Message to display. + """ + _Output(3, msg) + +def Debug(msg): + """Display a debug message + + Args: + msg; Message to display. + """ + _Output(4, msg) + +def UserOutput(msg): + """Display a message regardless of the current output level. + + This is used when the output was specifically requested by the user. + Args: + msg; Message to display. + """ + _Output(0, msg) + +def Init(_verbose=WARNING, stdout=sys.stdout): + """Initialize a new output object. + + Args: + verbose: Verbosity level (0-4). + stdout: File to use for stdout. + """ + global verbose, _progress, _color, _stdout, stdout_is_tty + + verbose = _verbose + _progress = '' # Our last progress message + _color = terminal.Color() + _stdout = stdout + + # TODO(sjg): Move this into Chromite libraries when we have them + stdout_is_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty() + +def Uninit(): + ClearProgress() + +Init()
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 13/30 patman: Add a library to handle logging and progress
Quoted 5 lines · Simon Glass
When tools want to display information of varying levels of importance, it helps to provide the user with control over the verbosity of these messages. Progress messages work best if they are displayed and then removed from the display when no-longer relevant.
Quoted 8 lines
Add a new tout library (terminal out) to handle these tasks.
Signed-off-by Simon Glass <[email protected]>---
tools/patman/tout.py | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 tools/patman/tout.py
Applied to u-boot-dm/next.
PATCH 14/30 dtoc: Allow the device tree to be compiled from source
In reply to Simon GlassIf a source device tree is provide to the Fdt() constructors, compile it automatically. This will be used in tests, where we want to build a particular test .dts file and check that it works correctly in binman.
---
tools/dtoc/fdt_fallback.py | 2 ++ tools/dtoc/fdt_normal.py | 7 +++++-- tools/dtoc/fdt_util.py | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-)
tools/dtoc/fdt_fallback.py +2 -0
@@ -79,6 +79,8 @@ class FdtFallback(Fdt): def __init__(self, fname): Fdt.__init__(self, fname) + if self._fname: + self._fname = fdt_util.EnsureCompiled(self._fname) def GetSubNodes(self, node): """Returns a list of sub-nodes of a given node
tools/dtoc/fdt_normal.py +5 -2
@@ -83,8 +83,11 @@ class FdtNormal(Fdt): """ def __init__(self, fname): Fdt.__init__(self, fname) - with open(self._fname) as fd: - self._fdt = fd.read() + if self._fname: + self._fname = fdt_util.EnsureCompiled(self._fname) + + with open(self._fname) as fd: + self._fdt = fd.read() def GetFdt(self): """Get the contents of the FDT
tools/dtoc/fdt_util.py +41 -0
51 lines not on this page · raw message
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 14/30 dtoc: Allow the device tree to be compiled from source
Quoted 11 lines · Simon Glass
If a source device tree is provide to the
Fdt()constructors, compile it automatically. This will be used in tests, where we want to build a particular test .dts file and check that it works correctly in binman.Signed-off-by Simon Glass <[email protected]>---
tools/dtoc/fdt_fallback.py | 2 ++ tools/dtoc/fdt_normal.py | 7 +++++-- tools/dtoc/fdt_util.py | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-)
Applied to u-boot-dm/next.
PATCH 15/30 dtoc: Drop the convert_dash parameter to GetProps()
In reply to Simon GlassThis is not used anywhere in dtoc, so drop it.
---
tools/dtoc/fdt_fallback.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
tools/dtoc/fdt_fallback.py +1 -4
@@ -97,12 +97,11 @@ class FdtFallback(Fdt): out = command.Output('fdtget', self._fname, '-l', node) return out.strip().splitlines() - def GetProps(self, node, convert_dashes=False): + def GetProps(self, node): """Get all properties from a node Args: node: full path to node name to look in - convert_dashes: True to convert - to _ in node names Returns: A dictionary containing all the properties, indexed by node name.
@@ -117,8 +116,6 @@ class FdtFallback(Fdt): props_dict = {} for prop in props: name = prop - if convert_dashes: - prop = re.sub('-', '_', prop) props_dict[prop] = self.GetProp(node, name) return props_dict
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 15/30 dtoc: Drop the convert_dash parameter to GetProps()
Quoted 7 lines · Simon Glass
This is not used anywhere in dtoc, so drop it.
Signed-off-by Simon Glass <[email protected]>---
tools/dtoc/fdt_fallback.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
Applied to u-boot-dm/next.
PATCH 16/30 dtoc: Prepare for supporting changing of device trees
In reply to Simon GlassFor binman we need to support deleting properties in the device tree. This will change the offsets of nodes after the deletion. In preparation, add code to keep track of when the offsets are invalid, and regenerate them.
---
tools/dtoc/fdt_normal.py | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-)
tools/dtoc/fdt_normal.py +42 -4
@@ -53,15 +53,24 @@ class Node(NodeBase): def __init__(self, fdt, offset, name, path): NodeBase.__init__(self, fdt, offset, name, path) + def Offset(self): + """Returns the offset of a node, after checking the cache + + This should be used instead of self._offset directly, to ensure that + the cache does not contain invalid offsets. + """ + self._fdt.CheckCache() + return self._offset + def Scan(self): """Scan a node's properties and subnodes This fills in the props and subnodes properties, recursively searching into subnodes so that the entire tree is built. """ - self.props = self._fdt.GetProps(self.path) + self.props = self._fdt.GetProps(self, self.path) - offset = libfdt.fdt_first_subnode(self._fdt.GetFdt(), self._offset) + offset = libfdt.fdt_first_subnode(self._fdt.GetFdt(), self.Offset()) while offset >= 0: sep = '' if self.path[-1] == '/' else '/' name = libfdt.Name(self._fdt.GetFdt(), offset)
@@ -72,6 +81,19 @@ class Node(NodeBase): node.Scan() offset = libfdt.fdt_next_subnode(self._fdt.GetFdt(), offset) + def Refresh(self, my_offset): + """Fix up the _offset for each node, recursively + + Note: This does not take account of property offsets - these will not + be updated. + """ + if self._offset != my_offset: + #print '%s: %d -> %d\n' % (self.path, self._offset, my_offset) + self._offset = my_offset + offset = libfdt.fdt_first_subnode(self._fdt.GetFdt(), self._offset) + for subnode in self.subnodes: + subnode.Refresh(offset) + offset = libfdt.fdt_next_subnode(self._fdt.GetFdt(), offset) class FdtNormal(Fdt): """Provides simple access to a flat device tree blob using libfdt.
@@ -83,6 +105,7 @@ class FdtNormal(Fdt): """ def __init__(self, fname): Fdt.__init__(self, fname) + self._cached_offsets = False if self._fname: self._fname = fdt_util.EnsureCompiled(self._fname)
@@ -97,7 +120,7 @@ class FdtNormal(Fdt): """ return self._fdt - def GetProps(self, node): + def GetProps(self, node, path): """Get all properties from a node. Args:
@@ -110,7 +133,7 @@ class FdtNormal(Fdt): Raises: ValueError: if the node does not exist. """ - offset = libfdt.fdt_path_offset(self._fdt, node) + offset = libfdt.fdt_path_offset(self._fdt, path) if offset < 0: libfdt.Raise(offset) props_dict = {}
@@ -124,6 +147,21 @@ class FdtNormal(Fdt): poffset = libfdt.fdt_next_property_offset(self._fdt, poffset) return props_dict + def Invalidate(self): + """Mark our offset cache as invalid""" + self._cached_offsets = False + + def CheckCache(self): + """Refresh the offset cache if needed""" + if self._cached_offsets: + return + self.Refresh() + self._cached_offsets = True + + def Refresh(self): + """Refresh the offset cache""" + self._root.Refresh(0) + @classmethod def Node(self, fdt, offset, name, path): """Create a new node
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 16/30 dtoc: Prepare for supporting changing of device trees
Quoted 9 lines · Simon Glass
For binman we need to support deleting properties in the device tree. This will change the offsets of nodes after the deletion. In preparation, add code to keep track of when the offsets are invalid, and regenerate them.
Signed-off-by Simon Glass <[email protected]>---
tools/dtoc/fdt_normal.py | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-)
Applied to u-boot-dm/next.
PATCH 17/30 dtoc: Move to using bytearray
In reply to Simon GlassSince we want to be able to change the in-memory device tree using libfdt, use a bytearray instead of a string. This makes interfacing from Python easier.
---
lib/libfdt/libfdt.swig | 8 ++++++++ tools/dtoc/fdt_normal.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-)
lib/libfdt/libfdt.swig +8 -0
@@ -75,6 +75,14 @@ struct fdt_property { } %} +%typemap(in) (const void *) { + if (!PyByteArray_Check($input)) { + SWIG_exception_fail(SWIG_TypeError, "in method '" "$symname" "', argument " + "$argnum"" of type '" "$type""'"); + } + $1 = (void *) PyByteArray_AsString($input); +} + const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int checklen); int fdt_path_offset(const void *fdt, const char *path); int fdt_first_property_offset(const void *fdt, int nodeoffset);
tools/dtoc/fdt_normal.py +1 -1
@@ -110,7 +110,7 @@ class FdtNormal(Fdt): self._fname = fdt_util.EnsureCompiled(self._fname) with open(self._fname) as fd: - self._fdt = fd.read() + self._fdt = bytearray(fd.read()) def GetFdt(self): """Get the contents of the FDT
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 17/30 dtoc: Move to using bytearray
Quoted 10 lines · Simon Glass
Since we want to be able to change the in-memory device tree using libfdt, use a bytearray instead of a string. This makes interfacing from Python easier.
Signed-off-by Simon Glass <[email protected]>---
lib/libfdt/libfdt.swig | 8 ++++++++ tools/dtoc/fdt_normal.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-)
Applied to u-boot-dm/next.
PATCH 18/30 dtoc: Support deleting device tree properties
In reply to Simon GlassAdd support for deleting a device tree property. With the fallback implementation this uses fdtput. With libfdt it uses the API call and updates the offsets afterwards.
---
lib/libfdt/libfdt.swig | 12 ++++++++++++ tools/dtoc/fdt.py | 10 ++++++++++ tools/dtoc/fdt_fallback.py | 13 +++++++++++++ tools/dtoc/fdt_normal.py | 20 ++++++++++++++++++++ 4 files changed, 55 insertions(+)
lib/libfdt/libfdt.swig +12 -0
@@ -95,3 +95,15 @@ const char *fdt_get_name(const void *fdt, int nodeoffset, int *OUTPUT); const char *fdt_string(const void *fdt, int stroffset); int fdt_first_subnode(const void *fdt, int offset); int fdt_next_subnode(const void *fdt, int offset); + +%typemap(in) (void *) { + if (!PyByteArray_Check($input)) { + SWIG_exception_fail(SWIG_TypeError, "in method '" "$symname" "', argument " + "$argnum"" of type '" "$type""'"); + } + $1 = PyByteArray_AsString($input); +} + +int fdt_delprop(void *fdt, int nodeoffset, const char *name); + +const char *fdt_strerror(int errval);
tools/dtoc/fdt.py +10 -0
@@ -184,6 +184,16 @@ class NodeBase: """ raise NotImplementedError() + def DeleteProp(self, prop_name): + """Delete a property of a node + + This should be implemented by subclasses + + Args: + prop_name: Name of the property to delete + """ + raise NotImplementedError() + class Fdt: """Provides simple access to a flat device tree blob.
tools/dtoc/fdt_fallback.py +13 -0
@@ -69,6 +69,19 @@ class Node(NodeBase): node.Scan() + def DeleteProp(self, prop_name): + """Delete a property of a node + + The property is deleted using fdtput. + + Args: + prop_name: Name of the property to delete + Raises: + CommandError if the property does not exist + """ + args = [self._fdt._fname, '-d', self.path, prop_name] + command.Output('fdtput', *args) + del self.props[prop_name] class FdtFallback(Fdt): """Provides simple access to a flat device tree blob using fdtget/fdtput
tools/dtoc/fdt_normal.py +20 -0
@@ -20,6 +20,11 @@ import libfdt # This implementation uses a libfdt Python library to access the device tree, # so it is fairly efficient. +def CheckErr(errnum, msg): + if errnum: + raise ValueError('Error %d: %s: %s' % + (errnum, libfdt.fdt_strerror(errnum), msg)) + class Prop(PropBase): """A device tree property
@@ -95,6 +100,21 @@ class Node(NodeBase): subnode.Refresh(offset) offset = libfdt.fdt_next_subnode(self._fdt.GetFdt(), offset) + def DeleteProp(self, prop_name): + """Delete a property of a node + + The property is deleted and the offset cache is invalidated. + + Args: + prop_name: Name of the property to delete + Raises: + ValueError if the property does not exist + """ + CheckErr(libfdt.fdt_delprop(self._fdt.GetFdt(), self.Offset(), prop_name), + "Node '%s': delete property: '%s'" % (self.path, prop_name)) + del self.props[prop_name] + self._fdt.Invalidate() + class FdtNormal(Fdt): """Provides simple access to a flat device tree blob using libfdt.
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 18/30 dtoc: Support deleting device tree properties
Quoted 4 lines · Simon Glass
Add support for deleting a device tree property. With the fallback implementation this uses fdtput. With libfdt it uses the API call and updates the offsets afterwards.
Quoted 8 lines
Signed-off-by Simon Glass <[email protected]>---
lib/libfdt/libfdt.swig | 12 ++++++++++++ tools/dtoc/fdt.py | 10 ++++++++++ tools/dtoc/fdt_fallback.py | 13 +++++++++++++ tools/dtoc/fdt_normal.py | 20 ++++++++++++++++++++ 4 files changed, 55 insertions(+)
Applied to u-boot-dm/next.
PATCH 19/30 dtoc: Support packing the device tree
In reply to Simon GlassAfter any node/property deletion the device tree can be packed to remove spare space. Add a way to perform this operation.
Note that for fdt_fallback, fdtput automatically packs the device tree after deletion, so no action is required here.
---
lib/libfdt/libfdt.swig | 1 + tools/dtoc/fdt.py | 16 ++++++++++++++++ tools/dtoc/fdt_normal.py | 11 +++++++++++ 3 files changed, 28 insertions(+)
lib/libfdt/libfdt.swig +1 -0
@@ -107,3 +107,4 @@ int fdt_next_subnode(const void *fdt, int offset); int fdt_delprop(void *fdt, int nodeoffset, const char *name); const char *fdt_strerror(int errval); +int fdt_pack(void *fdt);
tools/dtoc/fdt.py +16 -0
@@ -240,3 +240,19 @@ class Fdt: return None return node + def Flush(self): + """Flush device tree changes back to the file + + If the device tree has changed in memory, write it back to the file. + Subclasses can implement this if needed. + """ + pass + + def Pack(self): + """Pack the device tree down to its minimum size + + When nodes and properties shrink or are deleted, wasted space can + build up in the device tree binary. Subclasses can implement this + to remove that spare space. + """ + pass
tools/dtoc/fdt_normal.py +11 -0
@@ -140,6 +140,17 @@ class FdtNormal(Fdt): """ return self._fdt + def Flush(self): + """Flush device tree changes back to the file""" + with open(self._fname, 'wb') as fd: + fd.write(self._fdt) + + def Pack(self): + """Pack the device tree down to its minimum size""" + CheckErr(libfdt.fdt_pack(self._fdt), 'pack') + fdt_len = libfdt.fdt_totalsize(self._fdt) + del self._fdt[fdt_len:] + def GetProps(self, node, path): """Get all properties from a node.
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 19/30 dtoc: Support packing the device tree
Quoted 6 lines · Simon Glass
After any node/property deletion the device tree can be packed to remove spare space. Add a way to perform this operation.
Note that for
fdt_fallback, fdtput automatically packs the device tree after deletion, so no action is required here.
Quoted 7 lines
Signed-off-by Simon Glass <[email protected]>---
lib/libfdt/libfdt.swig | 1 + tools/dtoc/fdt.py | 16 ++++++++++++++++ tools/dtoc/fdt_normal.py | 11 +++++++++++ 3 files changed, 28 insertions(+)
Applied to u-boot-dm/next.
PATCH 20/30 dtoc: Support finding the offset of a property
In reply to Simon GlassAdd a way to find the byte offset of a property within the device tree. This is only supported with the normal libfdt implementation since fdtget does not provide this information.
---
lib/libfdt/libfdt.swig | 3 +++ tools/dtoc/fdt.py | 11 +++++++++++ tools/dtoc/fdt_normal.py | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+)
lib/libfdt/libfdt.swig +3 -0
@@ -108,3 +108,6 @@ int fdt_delprop(void *fdt, int nodeoffset, const char *name); const char *fdt_strerror(int errval); int fdt_pack(void *fdt); + +int fdt_totalsize(const void *fdt); +int fdt_off_dt_struct(const void *fdt);
tools/dtoc/fdt.py +11 -0
@@ -144,6 +144,17 @@ class PropBase: else: return True + def GetOffset(self): + """Get the offset of a property + + This can be implemented by subclasses. + + Returns: + The offset of the property (struct fdt_property) within the + file, or None if not known. + """ + return None + class NodeBase: """A device tree node
tools/dtoc/fdt_normal.py +18 -0
@@ -43,6 +43,14 @@ class Prop(PropBase): return self.type, self.value = self.BytesToValue(bytes) + def GetOffset(self): + """Get the offset of a property + + Returns: + The offset of the property (struct fdt_property) within the file + """ + return self._node._fdt.GetStructOffset(self._offset) + class Node(NodeBase): """A device tree node
@@ -193,6 +201,16 @@ class FdtNormal(Fdt): """Refresh the offset cache""" self._root.Refresh(0) + def GetStructOffset(self, offset): + """Get the file offset of a given struct offset + + Args: + offset: Offset within the 'struct' region of the device tree + Returns: + Position of @offset within the device tree binary + """ + return libfdt.fdt_off_dt_struct(self._fdt) + offset + @classmethod def Node(self, fdt, offset, name, path): """Create a new node
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 20/30 dtoc: Support finding the offset of a property
Quoted 11 lines · Simon Glass
Add a way to find the byte offset of a property within the device tree. This is only supported with the normal libfdt implementation since fdtget does not provide this information.
Signed-off-by Simon Glass <[email protected]>---
lib/libfdt/libfdt.swig | 3 +++ tools/dtoc/fdt.py | 11 +++++++++++ tools/dtoc/fdt_normal.py | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+)
Applied to u-boot-dm/next.
PATCH 21/30 dtoc: Correct quotes in fdt_util
In reply to Simon GlassThe style is to use single quotes for strings where possible. Adjust this function.
---
tools/dtoc/fdt_util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/dtoc/fdt_util.py +1 -1
@@ -22,7 +22,7 @@ def fdt32_to_cpu(val): Return: A native-endian integer value """ - return struct.unpack(">I", val)[0] + return struct.unpack('>I', val)[0] def EnsureCompiled(fname): """Compile an fdt .dts source file into a .dtb binary blob if needed.
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 21/30 dtoc: Correct quotes in fdt_util
Quoted 8 lines · Simon Glass
The style is to use single quotes for strings where possible. Adjust this function.
Signed-off-by Simon Glass <[email protected]>---
tools/dtoc/fdt_util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied to u-boot-dm/next.
PATCH 22/30 dtoc: Add methods for reading data from properties
In reply to Simon GlassProvide easy helpers for reading integer, string and boolean values from device-tree properties.
---
tools/dtoc/fdt_util.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
tools/dtoc/fdt_util.py +25 -0
@@ -59,3 +59,28 @@ def EnsureCompiled(fname): args.append(dts_input) command.Run('dtc', *args) return dtb_output + +def GetInt(node, propname, default=None): + prop = node.props.get(propname) + if not prop: + return default + value = fdt32_to_cpu(prop.value) + if type(value) == type(list): + raise ValueError("Node '%s' property '%' has list value: expecting" + "a single integer" % (node.name, propname)) + return value + +def GetString(node, propname, default=None): + prop = node.props.get(propname) + if not prop: + return default + value = prop.value + if type(value) == type(list): + raise ValueError("Node '%s' property '%' has list value: expecting" + "a single string" % (node.name, propname)) + return value + +def GetBool(node, propname, default=False): + if propname in node.props: + return True + return default
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 22/30 dtoc: Add methods for reading data from properties
Quoted 8 lines · Simon Glass
Provide easy helpers for reading integer, string and boolean values from device-tree properties.
Signed-off-by Simon Glass <[email protected]>---
tools/dtoc/fdt_util.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
Applied to u-boot-dm/next.
PATCH 23/30 binman: Introduce binman, a tool for building binary images
In reply to Simon GlassThis adds the basic code for binman, including command parsing, processing of entries and generation of images.
So far no entry types are supported. These will be added in future commits as examples of how to add new types.
See the README for documentation.
---
tools/binman/.gitignore | 1 + tools/binman/README | 491 ++++++++++++++++++++++++++++++++++++++++++++ tools/binman/binman | 1 + tools/binman/binman.py | 96 +++++++++ tools/binman/cmdline.py | 48 +++++ tools/binman/control.py | 106 ++++++++++ tools/binman/etype/entry.py | 186 +++++++++++++++++ tools/binman/image.py | 233 +++++++++++++++++++++ 8 files changed, 1162 insertions(+) create mode 100644 tools/binman/.gitignore create mode 100644 tools/binman/README create mode 120000 tools/binman/binman create mode 100755 tools/binman/binman.py create mode 100644 tools/binman/cmdline.py create mode 100644 tools/binman/control.py create mode 100644 tools/binman/etype/entry.py create mode 100644 tools/binman/image.py
tools/binman/.gitignore new file +1 -0
@@ -0,0 +1 @@ +*.pyc
tools/binman/README new file +491 -0
491 lines not on this page · raw message
tools/binman/binman new file +1 -0
@@ -0,0 +1 @@ +binman.py
tools/binman/binman.py new file +96 -0
96 lines not on this page · raw message
tools/binman/cmdline.py new file +48 -0
48 lines not on this page · raw message
tools/binman/control.py new file +106 -0
106 lines not on this page · raw message
tools/binman/etype/entry.py new file +186 -0
186 lines not on this page · raw message
tools/binman/image.py new file +233 -0
233 lines not on this page · raw message
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 23/30 binman: Introduce binman, a tool for building binary images
Hello Simon,
Am 26.07.2016 um 02:59 schrieb Simon Glass:
Quoted 20 lines
This adds the basic code for binman, including command parsing, processing of entries and generation of images.
So far no entry types are supported. These will be added in future commits as examples of how to add new types.
See the README for documentation.
Signed-off-by Simon Glass <[email protected]>---
tools/binman/.gitignore | 1 + tools/binman/README | 491 ++++++++++++++++++++++++++++++++++++++++++++ tools/binman/binman | 1 + tools/binman/binman.py | 96 +++++++++ tools/binman/cmdline.py | 48 +++++ tools/binman/control.py | 106 ++++++++++ tools/binman/etype/entry.py | 186 +++++++++++++++++ tools/binman/image.py | 233 +++++++++++++++++++++ 8 files changed, 1162 insertions(+)
Quoted 8 lines
create mode 100644
tools/binman/.gitignore
create mode 100644tools/binman/README
create mode 120000tools/binman/binman
create mode 100755tools/binman/binman.py
create mode 100644tools/binman/cmdline.py
create mode 100644tools/binman/control.py
create mode 100644tools/binman/etype/entry.py
create mode 100644tools/binman/image.py
Sounds great. I try to find time to try it, thanks!
just some nitpick...
Quoted 6 lines
tools/binman/README new file +0
-0@@ -0,0 +1,491 @@
[...]
tools/binman/README line 481
Quoted 13 lines
tools/binman/README new file +13
-0+To do +----- + +Some ideas: +- Fill out the device tree to include the final position and size of each + entry (since the input file may not always specify these) +- Use of-platdata to make the information available to code that is unable + to use device tree (such as a very small SPL image) +- Write an image map to a text file +- Allow easy building of images by specifying just the board name +- Produce a full Python binding for libfdt (for upstream) +- Add an option to decode an image into the constituent binaries +- Suppoort hierarchical images (packing of binaries into another binary
typing error: Suppoort -> Support
tools/binman/README line 491
Quoted 10 lines
tools/binman/README new file +10
-0+ which is then placed in the image) +- Support building an image for a board (-b) more completely, with a + configurable build directory +- Consider making binman work with buildman, although if it is used in the + Makefile, this will be automatic +- Implement align-end + +-- +Simon Glass <[email protected]> +7/7/2016
bye,
Heiko
Signature · 2 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 24/30 binman: Add basic entry types for U-Boot
In reply to Simon GlassAdd entries to support some standard U-Boot binaries, such as u-boot.bin, u-boot.dtb, etc. Also add some tests for these.
---
tools/binman/etype/blob.py | 37 ++ tools/binman/etype/u_boot.py | 17 + tools/binman/etype/u_boot_dtb.py | 17 + tools/binman/etype/u_boot_nodtb.py | 17 + tools/binman/etype/u_boot_spl.py | 17 + tools/binman/func_test.py | 509 +++++++++++++++++++++ tools/binman/test/01_invalid.dts | 5 + tools/binman/test/02_missing_node.dts | 6 + tools/binman/test/03_empty.dts | 9 + tools/binman/test/04_invalid_entry.dts | 11 + tools/binman/test/05_simple.dts | 11 + tools/binman/test/06_dual_image.dts | 22 + tools/binman/test/07_bad_align.dts | 12 + tools/binman/test/08_pack.dts | 30 ++ tools/binman/test/09_pack_extra.dts | 35 ++ tools/binman/test/10_pack_align_power2.dts | 12 + tools/binman/test/11_pack_align_size_power2.dts | 12 + tools/binman/test/12_pack_inv_align.dts | 13 + tools/binman/test/13_pack_inv_size_align.dts | 13 + tools/binman/test/14_pack_overlap.dts | 16 + tools/binman/test/15_pack_overflow.dts | 12 + tools/binman/test/16_pack_image_overflow.dts | 13 + tools/binman/test/17_pack_image_size.dts | 13 + tools/binman/test/18_pack_image_align.dts | 13 + tools/binman/test/19_pack_inv_image_align.dts | 14 + .../binman/test/20_pack_inv_image_align_power2.dts | 13 + tools/binman/test/21_image_pad.dts | 16 + tools/binman/test/22_image_name.dts | 21 + tools/binman/test/23_blob.dts | 12 + tools/binman/test/24_sorted.dts | 17 + tools/binman/test/25_pack_zero_size.dts | 15 + tools/binman/test/26_pack_u_boot_dtb.dts | 14 + 32 files changed, 994 insertions(+) create mode 100644 tools/binman/etype/blob.py create mode 100644 tools/binman/etype/u_boot.py create mode 100644 tools/binman/etype/u_boot_dtb.py create mode 100644 tools/binman/etype/u_boot_nodtb.py create mode 100644 tools/binman/etype/u_boot_spl.py create mode 100644 tools/binman/func_test.py create mode 100644 tools/binman/test/01_invalid.dts create mode 100644 tools/binman/test/02_missing_node.dts create mode 100644 tools/binman/test/03_empty.dts create mode 100644 tools/binman/test/04_invalid_entry.dts create mode 100644 tools/binman/test/05_simple.dts create mode 100644 tools/binman/test/06_dual_image.dts create mode 100644 tools/binman/test/07_bad_align.dts create mode 100644 tools/binman/test/08_pack.dts create mode 100644 tools/binman/test/09_pack_extra.dts create mode 100644 tools/binman/test/10_pack_align_power2.dts create mode 100644 tools/binman/test/11_pack_align_size_power2.dts create mode 100644 tools/binman/test/12_pack_inv_align.dts create mode 100644 tools/binman/test/13_pack_inv_size_align.dts create mode 100644 tools/binman/test/14_pack_overlap.dts create mode 100644 tools/binman/test/15_pack_overflow.dts create mode 100644 tools/binman/test/16_pack_image_overflow.dts create mode 100644 tools/binman/test/17_pack_image_size.dts create mode 100644 tools/binman/test/18_pack_image_align.dts create mode 100644 tools/binman/test/19_pack_inv_image_align.dts create mode 100644 tools/binman/test/20_pack_inv_image_align_power2.dts create mode 100644 tools/binman/test/21_image_pad.dts create mode 100644 tools/binman/test/22_image_name.dts create mode 100644 tools/binman/test/23_blob.dts create mode 100644 tools/binman/test/24_sorted.dts create mode 100644 tools/binman/test/25_pack_zero_size.dts create mode 100644 tools/binman/test/26_pack_u_boot_dtb.dts
tools/binman/etype/blob.py new file +37 -0
@@ -0,0 +1,37 @@ +# Copyright (c) 2016 Google, Inc +# Written by Simon Glass <[email protected]> +# +# SPDX-License-Identifier: GPL-2.0+ +# +# Entry-type module for blobs, which are binary objects read from files +# + +from entry import Entry +import fdt_util +import tools + +class Entry_blob(Entry): + def __init__(self, image, etype, node): + Entry.__init__(self, image, etype, node) + self._filename = fdt_util.GetString(self._node, "filename", self.etype) + + def ObtainContents(self): + self._filename = self.GetDefaultFilename() + self._pathname = tools.GetInputFilename(self._filename) + self.ReadContents() + return True + + def ReadContents(self): + with open(self._pathname) as fd: + # We assume the data is small enough to fit into memory. If this + # is used for large filesystem image that might not be true. + # In that case, Image.BuildImage() could be adjusted to use a + # 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. + self.data = fd.read() + self.contents_size = len(self.data) + return True + + def GetDefaultFilename(self): + return self._filename
tools/binman/etype/u_boot.py new file +17 -0
@@ -0,0 +1,17 @@ +# Copyright (c) 2016 Google, Inc +# Written by Simon Glass <[email protected]> +# +# SPDX-License-Identifier: GPL-2.0+ +# +# Entry-type module for U-Boot binary +# + +from entry import Entry +from blob import Entry_blob + +class Entry_u_boot(Entry_blob): + def __init__(self, image, etype, node): + Entry_blob.__init__(self, image, etype, node) + + def GetDefaultFilename(self): + return 'u-boot.bin'
tools/binman/etype/u_boot_dtb.py new file +17 -0
@@ -0,0 +1,17 @@ +# Copyright (c) 2016 Google, Inc +# Written by Simon Glass <[email protected]> +# +# SPDX-License-Identifier: GPL-2.0+ +# +# Entry-type module for U-Boot device tree +# + +from entry import Entry +from blob import Entry_blob + +class Entry_u_boot_dtb(Entry_blob): + def __init__(self, image, etype, node): + Entry_blob.__init__(self, image, etype, node) + + def GetDefaultFilename(self): + return 'u-boot.dtb'
tools/binman/etype/u_boot_nodtb.py new file +17 -0
@@ -0,0 +1,17 @@ +# Copyright (c) 2016 Google, Inc +# Written by Simon Glass <[email protected]> +# +# SPDX-License-Identifier: GPL-2.0+ +# +# Entry-type module for 'u-boot-nodtb.bin' +# + +from entry import Entry +from blob import Entry_blob + +class Entry_u_boot_nodtb(Entry_blob): + def __init__(self, image, etype, node): + Entry_blob.__init__(self, image, etype, node) + + def GetDefaultFilename(self): + return 'u-boot-nodtb.bin'
tools/binman/etype/u_boot_spl.py new file +17 -0
@@ -0,0 +1,17 @@ +# Copyright (c) 2016 Google, Inc +# Written by Simon Glass <[email protected]> +# +# SPDX-License-Identifier: GPL-2.0+ +# +# Entry-type module for spl/u-boot-spl.bin +# + +from entry import Entry +from blob import Entry_blob + +class Entry_u_boot_spl(Entry_blob): + def __init__(self, image, etype, node): + Entry_blob.__init__(self, image, etype, node) + + def GetDefaultFilename(self): + return 'spl/u-boot-spl.bin'
tools/binman/func_test.py new file +509 -0
509 lines not on this page · raw message
tools/binman/test/01_invalid.dts new file +5 -0
@@ -0,0 +1,5 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>;
tools/binman/test/02_missing_node.dts new file +6 -0
@@ -0,0 +1,6 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; +};
tools/binman/test/03_empty.dts new file +9 -0
@@ -0,0 +1,9 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + }; +};
tools/binman/test/04_invalid_entry.dts new file +11 -0
@@ -0,0 +1,11 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + not-a-valid-type { + }; + }; +};
tools/binman/test/05_simple.dts new file +11 -0
@@ -0,0 +1,11 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + u-boot { + }; + }; +};
tools/binman/test/06_dual_image.dts new file +22 -0
@@ -0,0 +1,22 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + multiple-images; + image1 { + u-boot { + }; + }; + + image2 { + pad-before = <3>; + pad-after = <5>; + + u-boot { + }; + }; + }; +};
tools/binman/test/07_bad_align.dts new file +12 -0
@@ -0,0 +1,12 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + u-boot { + align = <23>; + }; + }; +};
tools/binman/test/08_pack.dts new file +30 -0
@@ -0,0 +1,30 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + u-boot { + }; + + u-boot-align { + type = "u-boot"; + align = <16>; + }; + + u-boot-size { + type = "u-boot"; + size = <23>; + }; + + u-boot-next { + type = "u-boot"; + }; + + u-boot-fixed { + type = "u-boot"; + pos = <61>; + }; + }; +};
tools/binman/test/09_pack_extra.dts new file +35 -0
@@ -0,0 +1,35 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + u-boot { + pad-before = <3>; + pad-after = <5>; + }; + + u-boot-align-size-nop { + type = "u-boot"; + align-size = <4>; + }; + + u-boot-align-size { + type = "u-boot"; + align = <16>; + align-size = <32>; + }; + + u-boot-align-end { + type = "u-boot"; + align-end = <64>; + }; + + u-boot-align-both { + type = "u-boot"; + align= <64>; + align-end = <128>; + }; + }; +};
tools/binman/test/10_pack_align_power2.dts new file +12 -0
@@ -0,0 +1,12 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + u-boot { + align = <5>; + }; + }; +};
tools/binman/test/11_pack_align_size_power2.dts new file +12 -0
@@ -0,0 +1,12 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + u-boot { + align-size = <55>; + }; + }; +};
tools/binman/test/12_pack_inv_align.dts new file +13 -0
@@ -0,0 +1,13 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + u-boot { + pos = <5>; + align = <4>; + }; + }; +};
tools/binman/test/13_pack_inv_size_align.dts new file +13 -0
@@ -0,0 +1,13 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + u-boot { + size = <5>; + align-size = <4>; + }; + }; +};
tools/binman/test/14_pack_overlap.dts new file +16 -0
@@ -0,0 +1,16 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + u-boot { + }; + + u-boot-align { + type = "u-boot"; + pos = <3>; + }; + }; +};
tools/binman/test/15_pack_overflow.dts new file +12 -0
@@ -0,0 +1,12 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + u-boot { + size = <3>; + }; + }; +};
tools/binman/test/16_pack_image_overflow.dts new file +13 -0
@@ -0,0 +1,13 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + size = <3>; + + u-boot { + }; + }; +};
tools/binman/test/17_pack_image_size.dts new file +13 -0
@@ -0,0 +1,13 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + size = <7>; + + u-boot { + }; + }; +};
tools/binman/test/18_pack_image_align.dts new file +13 -0
@@ -0,0 +1,13 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + align-size = <16>; + + u-boot { + }; + }; +};
tools/binman/test/19_pack_inv_image_align.dts new file +14 -0
@@ -0,0 +1,14 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + size = <7>; + align-size = <8>; + + u-boot { + }; + }; +};
tools/binman/test/20_pack_inv_image_align_power2.dts new file +13 -0
@@ -0,0 +1,13 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + align-size = <131>; + + u-boot { + }; + }; +};
tools/binman/test/21_image_pad.dts new file +16 -0
@@ -0,0 +1,16 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + pad-byte = <0xff>; + u-boot-spl { + }; + + u-boot { + pos = <12>; + }; + }; +};
tools/binman/test/22_image_name.dts new file +21 -0
@@ -0,0 +1,21 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + multiple-images; + image1 { + filename = "test-name"; + u-boot { + }; + }; + + image2 { + filename = "test-name.xx"; + u-boot { + }; + }; + }; +};
tools/binman/test/23_blob.dts new file +12 -0
@@ -0,0 +1,12 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + blob { + filename = "blobfile"; + }; + }; +};
tools/binman/test/24_sorted.dts new file +17 -0
@@ -0,0 +1,17 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + sort-by-pos; + u-boot { + pos = <10>; + }; + + u-boot-spl { + pos = <5>; + }; + }; +};
tools/binman/test/25_pack_zero_size.dts new file +15 -0
@@ -0,0 +1,15 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + u-boot { + }; + + u-boot-spl { + pos = <0>; + }; + }; +};
tools/binman/test/26_pack_u_boot_dtb.dts new file +14 -0
@@ -0,0 +1,14 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + u-boot-nodtb { + }; + + u-boot-dtb { + }; + }; +};
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 25/30 binman: Add support for building x86 ROMs
In reply to Simon GlassThe structure of x86 ROMs is pretty complex. There are various binary blobs to place in the image. Microcode requires special handling so that it is available to very early code and can be used without any memory whatsoever.
Add support for the various entry types that are currently needed, along with some tests.
---
tools/binman/etype/intel_descriptor.py | 55 +++++++++++ tools/binman/etype/intel_me.py | 17 ++++ tools/binman/etype/intel_mrc.py | 17 ++++ tools/binman/etype/intel_vga.py | 17 ++++ tools/binman/etype/u_boot_dtb_with_ucode.py | 69 ++++++++++++++ tools/binman/etype/u_boot_ucode.py | 77 ++++++++++++++++ tools/binman/etype/u_boot_with_ucode_ptr.py | 71 +++++++++++++++ tools/binman/etype/x86_start16.py | 17 ++++ tools/binman/func_test.py | 136 ++++++++++++++++++++++++++++ tools/binman/test/27_pack_4gb_no_size.dts | 18 ++++ tools/binman/test/28_pack_4gb_outside.dts | 19 ++++ tools/binman/test/29_x86-rom.dts | 19 ++++ tools/binman/test/30_x86-rom-me-no-desc.dts | 15 +++ tools/binman/test/31_x86-rom-me.dts | 18 ++++ tools/binman/test/32_intel-vga.dts | 13 +++ tools/binman/test/33_x86-start16.dts | 13 +++ tools/binman/test/34_x86_ucode.dts | 29 ++++++ tools/binman/test/35_x86_single_ucode.dts | 26 ++++++ tools/binman/test/u_boot_ucode_ptr | Bin 0 -> 4175 bytes tools/binman/test/u_boot_ucode_ptr.c | 15 +++ tools/binman/test/u_boot_ucode_ptr.lds | 18 ++++ 21 files changed, 679 insertions(+) create mode 100644 tools/binman/etype/intel_descriptor.py create mode 100644 tools/binman/etype/intel_me.py create mode 100644 tools/binman/etype/intel_mrc.py create mode 100644 tools/binman/etype/intel_vga.py create mode 100644 tools/binman/etype/u_boot_dtb_with_ucode.py create mode 100644 tools/binman/etype/u_boot_ucode.py create mode 100644 tools/binman/etype/u_boot_with_ucode_ptr.py create mode 100644 tools/binman/etype/x86_start16.py create mode 100644 tools/binman/test/27_pack_4gb_no_size.dts create mode 100644 tools/binman/test/28_pack_4gb_outside.dts create mode 100644 tools/binman/test/29_x86-rom.dts create mode 100644 tools/binman/test/30_x86-rom-me-no-desc.dts create mode 100644 tools/binman/test/31_x86-rom-me.dts create mode 100644 tools/binman/test/32_intel-vga.dts create mode 100644 tools/binman/test/33_x86-start16.dts create mode 100644 tools/binman/test/34_x86_ucode.dts create mode 100644 tools/binman/test/35_x86_single_ucode.dts create mode 100755 tools/binman/test/u_boot_ucode_ptr create mode 100644 tools/binman/test/u_boot_ucode_ptr.c create mode 100644 tools/binman/test/u_boot_ucode_ptr.lds
tools/binman/etype/intel_descriptor.py new file +55 -0
@@ -0,0 +1,55 @@ +# Copyright (c) 2016 Google, Inc +# Written by Simon Glass <[email protected]> +# +# SPDX-License-Identifier: GPL-2.0+ +# +# Entry-type module for 'u-boot' +# + +import struct + +from entry import Entry +from blob import Entry_blob + +FD_SIGNATURE = struct.pack('<L', 0x0ff0a55a) +MAX_REGIONS = 5 + +(REGION_DESCRIPTOR, REGION_BIOS, REGION_ME, REGION_GBE, + REGION_PDATA) = range(5) + +class Region: + def __init__(self, data, frba, region_num): + pos = frba + region_num * 4 + val = struct.unpack('<L', data[pos:pos + 4])[0] + self.base = (val & 0xfff) << 12 + self.limit = ((val & 0x0fff0000) >> 4) | 0xfff + self.size = self.limit - self.base + 1 + +class Entry_intel_descriptor(Entry_blob): + """Intel flash descriptor block (4KB) + + This is placed at the start of flash and provides information about + the SPI flash regions. In particular it provides the base address and + size of the ME region, allowing us to place the ME binary in the right + place. + """ + def __init__(self, image, etype, node): + Entry_blob.__init__(self, image, etype, node) + self._regions = [] + + def GetDefaultFilename(self): + return 'descriptor.bin' + + def GetPositions(self): + pos = self.data.find(FD_SIGNATURE) + if pos == -1: + self.Raise('Cannot find FD signature') + flvalsig, flmap0, flmap1, flmap2 = struct.unpack('<LLLL', + self.data[pos:pos + 16]) + frba = ((flmap0 >> 16) & 0xff) << 4 + 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]}
tools/binman/etype/intel_me.py new file +17 -0
@@ -0,0 +1,17 @@ +# Copyright (c) 2016 Google, Inc +# Written by Simon Glass <[email protected]> +# +# SPDX-License-Identifier: GPL-2.0+ +# +# Entry-type module for 'u-boot' +# + +from entry import Entry +from blob import Entry_blob + +class Entry_intel_me(Entry_blob): + def __init__(self, image, etype, node): + Entry_blob.__init__(self, image, etype, node) + + def GetDefaultFilename(self): + return 'me.bin'
tools/binman/etype/intel_mrc.py new file +17 -0
@@ -0,0 +1,17 @@ +# Copyright (c) 2016 Google, Inc +# Written by Simon Glass <[email protected]> +# +# SPDX-License-Identifier: GPL-2.0+ +# +# Entry-type module for 'u-boot' +# + +from entry import Entry +from blob import Entry_blob + +class Entry_intel_mrc(Entry_blob): + def __init__(self, image, etype, node): + Entry_blob.__init__(self, image, etype, node) + + def GetDefaultFilename(self): + return 'mrc.bin'
tools/binman/etype/intel_vga.py new file +17 -0
@@ -0,0 +1,17 @@ +# Copyright (c) 2016 Google, Inc +# Written by Simon Glass <[email protected]> +# +# SPDX-License-Identifier: GPL-2.0+ +# +# Entry-type module for 'u-boot' +# + +from entry import Entry +from blob import Entry_blob + +class Entry_intel_vga(Entry_blob): + def __init__(self, image, etype, node): + Entry_blob.__init__(self, image, etype, node) + + def GetDefaultFilename(self): + return 'vga.bin'
tools/binman/etype/u_boot_dtb_with_ucode.py new file +69 -0
69 lines not on this page · raw message
tools/binman/etype/u_boot_ucode.py new file +77 -0
77 lines not on this page · raw message
tools/binman/etype/u_boot_with_ucode_ptr.py new file +71 -0
71 lines not on this page · raw message
tools/binman/etype/x86_start16.py new file +17 -0
@@ -0,0 +1,17 @@ +# Copyright (c) 2016 Google, Inc +# Written by Simon Glass <[email protected]> +# +# SPDX-License-Identifier: GPL-2.0+ +# +# Entry-type module for 'u-boot' +# + +from entry import Entry +from blob import Entry_blob + +class Entry_x86_start16(Entry_blob): + def __init__(self, image, etype, node): + Entry_blob.__init__(self, image, etype, node) + + def GetDefaultFilename(self): + return 'u-boot-x86-16bit.bin'
tools/binman/func_test.py +136 -0
148 lines not on this page · raw message
tools/binman/test/27_pack_4gb_no_size.dts new file +18 -0
@@ -0,0 +1,18 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + sort-by-pos; + end-at-4gb; + u-boot { + pos = <0xfffffff0>; + }; + + u-boot-spl { + pos = <0xfffffff7>; + }; + }; +};
tools/binman/test/28_pack_4gb_outside.dts new file +19 -0
@@ -0,0 +1,19 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + sort-by-pos; + end-at-4gb; + size = <16>; + u-boot { + pos = <0>; + }; + + u-boot-spl { + pos = <0xfffffff7>; + }; + }; +};
tools/binman/test/29_x86-rom.dts new file +19 -0
@@ -0,0 +1,19 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + sort-by-pos; + end-at-4gb; + size = <16>; + u-boot { + pos = <0xfffffff0>; + }; + + u-boot-spl { + pos = <0xfffffff7>; + }; + }; +};
tools/binman/test/30_x86-rom-me-no-desc.dts new file +15 -0
@@ -0,0 +1,15 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + sort-by-pos; + end-at-4gb; + size = <16>; + intel-me { + pos-unset; + }; + }; +};
tools/binman/test/31_x86-rom-me.dts new file +18 -0
@@ -0,0 +1,18 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + sort-by-pos; + end-at-4gb; + size = <0x800000>; + intel-descriptor { + }; + + intel-me { + pos-unset; + }; + }; +};
tools/binman/test/32_intel-vga.dts new file +13 -0
@@ -0,0 +1,13 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + size = <16>; + + intel-vga { + }; + }; +};
tools/binman/test/33_x86-start16.dts new file +13 -0
@@ -0,0 +1,13 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + size = <16>; + + x86-start16 { + }; + }; +};
tools/binman/test/34_x86_ucode.dts new file +29 -0
@@ -0,0 +1,29 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + sort-by-pos; + end-at-4gb; + size = <0x200>; + u-boot-with-ucode-ptr { + }; + + u-boot-dtb-with-ucode { + }; + + u-boot-ucode { + }; + }; + + microcode { + update at 0 { + data = <0x12345678 0x12345679>; + }; + update at 1 { + data = <0xabcd0000 0x78235609>; + }; + }; +};
tools/binman/test/35_x86_single_ucode.dts new file +26 -0
@@ -0,0 +1,26 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + sort-by-pos; + end-at-4gb; + size = <0x200>; + u-boot-with-ucode-ptr { + }; + + u-boot-dtb-with-ucode { + }; + + u-boot-ucode { + }; + }; + + microcode { + update at 0 { + data = <0x12345678 0x12345679>; + }; + }; +};
tools/binman/test/u_boot_ucode_ptr new file binary +0 -0
zgM)i3QgG0CU(yE=7YE1p!Ew2t at 9xWVH@o|LsZ@#-(v%@sqt7rjSl=(i5rZlmsZoxy zQ9SaF!jM>&I0rHVXMs3_>*wPh=u>4I0zc&NRXVJG0rgz2p&8H&Xa+OngPv#W<WEb z8PE)91~dczzyR*A5=(}qebAw|qP00Wx+^}sOy2XS&mWD8@+0oQG~%t+cBR&_15XAO zLu?77z7|AQ^SWt>h9TCMV?U7?UiPJBvzCKcpQta-m##SW0$~TeGpF8jNCaKqaY=Oj ze&6*ZKlNvnIWxzCEXm}&a5V?u^%8<um|=meT89(@6%cSR#15x>_A>)8o(X9qLQXD z#1~o6OQFqqJIY{<8~_@#DLmzgZrQ+Xi@EVGZrnMRWWNeKSJ|ha`YAi9u{Z4aQjhnG z?c~ddtBklhOXCp#9(;g{)Q?Fq+c>PTU-d6wo4~YvUz*V$GtcEfbjfs-ZCgXv9QLkU KGKbO{NcskUZF7hK
literal 0
HcmV?d00001
tools/binman/test/u_boot_ucode_ptr.c new file +15 -0
@@ -0,0 +1,15 @@ +/* +* Copyright (c) 2016 Google, Inc +* +* SPDX-License-Identifier: GPL-2.0+ +* +* Simple program to create a _dt_ucode_base_size symbol which can be read +* by 'nm'. This is used by binman tests. +* +* Build with: +* cc -march=i386 -m32 -o u_boot_ucode_ptr -T u_boot_ucode_ptr.lds -nostdlib \ +u_boot_ucode_ptr.c +*/ + +static unsigned long _dt_ucode_base_size[2] + __attribute__((section(".ucode"))) = {1, 2};
tools/binman/test/u_boot_ucode_ptr.lds new file +18 -0
@@ -0,0 +1,18 @@ +/* + * Copyright (c) 2016 Google, Inc + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") +OUTPUT_ARCH(i386) +ENTRY(_start) + +SECTIONS +{ + . = 0xfffffdf0; + _start = .; + .ucode : { + *(.ucode) + } +}
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 26/30 binman: Add support for u-boot.img as an input binary
In reply to Simon GlassAdd an entry type for u-boot.img (a legacy U-Boot image) and a simple test.
---
tools/binman/etype/u_boot_img.py | 17 +++++++++++++++++ tools/binman/func_test.py | 7 +++++++ tools/binman/test/36_u_boot_img.dts | 11 +++++++++++ 3 files changed, 35 insertions(+) create mode 100644 tools/binman/etype/u_boot_img.py create mode 100644 tools/binman/test/36_u_boot_img.dts
tools/binman/etype/u_boot_img.py new file +17 -0
@@ -0,0 +1,17 @@ +# Copyright (c) 2016 Google, Inc +# Written by Simon Glass <[email protected]> +# +# SPDX-License-Identifier: GPL-2.0+ +# +# Entry-type module for U-Boot binary +# + +from entry import Entry +from blob import Entry_blob + +class Entry_u_boot_img(Entry_blob): + def __init__(self, image, etype, node): + Entry_blob.__init__(self, image, etype, node) + + def GetDefaultFilename(self): + return 'u-boot.img'
tools/binman/func_test.py +7 -0
@@ -27,6 +27,7 @@ import tout # Contents of test files, corresponding to different entry types U_BOOT_DATA = '1234' +U_BOOT_IMG_DATA = 'img' U_BOOT_SPL_DATA = '567' BLOB_DATA = '89' ME_DATA = '0abcd'
@@ -60,6 +61,7 @@ class TestFunctional(unittest.TestCase): # Create some test files TestFunctional._MakeInputFile('u-boot.bin', U_BOOT_DATA) + TestFunctional._MakeInputFile('u-boot.img', U_BOOT_IMG_DATA) TestFunctional._MakeInputFile('spl/u-boot-spl.bin', U_BOOT_SPL_DATA) TestFunctional._MakeInputFile('blobfile', BLOB_DATA) TestFunctional._MakeInputFile('me.bin', ME_DATA)
@@ -643,3 +645,8 @@ class TestFunctional(unittest.TestCase): first = data[:len(U_BOOT_NODTB_DATA)] self.assertEqual('nodtb with microcode' + pos_and_size + ' somewhere in here', first) + + def testUBootImg(self): + """Test that u-boot.img can be put in a file""" + data = self._DoReadFile('36_u_boot_img.dts') + self.assertEqual(U_BOOT_IMG_DATA, data)
tools/binman/test/36_u_boot_img.dts new file +11 -0
@@ -0,0 +1,11 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + u-boot-img { + }; + }; +};
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 27/30 binman: Add a build rule for binman
In reply to Simon GlassAdd a standard command definition for binman so that it can be used in makefiles.
---
Makefile | 6 ++++++ 1 file changed, 6 insertions(+)
Makefile +6 -0
@@ -870,6 +870,12 @@ u-boot.ldr: u-boot $(LDR) -T $(CONFIG_CPU) -c $@ $< $(LDR_FLAGS) $(BOARD_SIZE_CHECK) +# binman +# --------------------------------------------------------------------------- +quiet_cmd_binman = BINMAN $@ +cmd_binman = $(srctree)/tools/binman/binman -d u-boot.dtb -O . \ + -I . -I $(srctree)/board/$(BOARDDIR) $< + OBJCOPYFLAGS_u-boot.ldr.hex := -I binary -O ihex OBJCOPYFLAGS_u-boot.ldr.srec := -I binary -O srec
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 28/30 binman: Allow configuration options to be used in .dts files
In reply to Simon GlassIt is sometimes useful to be able to reference configuration options in a device tree source file. Add the necessary includes so that this works.
---
scripts/Makefile.lib | 5 +++++ 1 file changed, 5 insertions(+)
scripts/Makefile.lib +5 -0
@@ -168,6 +168,11 @@ ld_flags = $(LDFLAGS) $(ldflags-y) dtc_cpp_flags = -Wp,-MD,$(depfile).pre.tmp -nostdinc \ -I$(srctree)/arch/$(ARCH)/dts \ -I$(srctree)/arch/$(ARCH)/dts/include \ + -Iinclude \ + -I$(srctree)/include \ + -I$(srctree)/arch/$(ARCH)/include \ + -include $(srctree)/include/linux/kconfig.h \ + -D__ASSEMBLY__ \ -undef -D__DTS__ # Finds the multi-part object the current object will be linked into
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 29/30 RFC: Use binman for a sunxi board
In reply to Simon GlassAdd an example usage of binman for a sunxi board. This involves adding the image definition to the device tree and using it in the Makefile.
This is for example only.
---
Makefile | 4 +--- arch/arm/dts/sun7i-a20-pcduino3.dts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-)
Makefile +1 -3
@@ -1084,10 +1084,8 @@ u-boot-x86-16bit.bin: u-boot FORCE endif ifneq ($(CONFIG_SUNXI),) -OBJCOPYFLAGS_u-boot-sunxi-with-spl.bin = -I binary -O binary \ - --pad-to=$(CONFIG_SPL_PAD_TO) --gap-fill=0xff u-boot-sunxi-with-spl.bin: spl/sunxi-spl.bin u-boot.img FORCE - $(call if_changed,pad_cat) + $(call if_changed,binman) endif ifneq ($(CONFIG_TEGRA),)
arch/arm/dts/sun7i-a20-pcduino3.dts +12 -0
@@ -42,6 +42,7 @@ */ /dts-v1/; +#include <config.h> #include "sun7i-a20.dtsi" #include "sunxi-common-regulators.dtsi"
@@ -62,6 +63,17 @@ stdout-path = "serial0:115200n8"; }; + binman { + filename = "u-boot-sunxi-with-spl.bin"; + pad-byte = <0xff>; + blob { + filename = "spl/sunxi-spl.bin"; + }; + u-boot-img { + pos = <CONFIG_SPL_PAD_TO>; + }; + }; + leds { compatible = "gpio-leds"; pinctrl-names = "default";
Signature · 1 line
2.8.0.rc3.226.g39d4020
PATCH 29/30 RFC: Use binman for a sunxi board
(adding Hans)
Quoted 2 lines · Simon Glass
Add an example usage of binman for a sunxi board. This involves adding the
Quoted 1 line
image definition to the device tree and using it in the
Makefile.
My concern with this approach is that the *.dts(i) files used for sunxi are sync'd unmodified from the upstream repo. I think this is a valuable property to retain in terms of maintenance burden for us (resync is trivial only if there are no local changes).
The conflict is then whether the device tree people would consider this new block to be "describing the hardware" or not and therefore whether these changes would be welcomed/allowed upstream. I'm not sure which way it would go TBH.
There is also an issue with duplication, since this stanza is going to be the same for all the dozens of sunxi platforms. I suppose this can be addressed by putting it in a suitable .dtsi file, but that does sort of start to suggest that this information belongs outside the per-board .dts in a per-platform file (at which point I would have have to ask if .dts is the best/most convenient syntax?).
Ian.
PATCH 29/30 RFC: Use binman for a sunxi board
Hi Ian,
Quoted 10 lines · Ian Campbell
(adding Hans)
Quoted 2 lines · Simon Glass
Add an example usage of binman for a sunxi board. This involves adding the
Quoted 1 line
image definition to the device tree and using it in the
Makefile.My concern with this approach is that the *.dts(i) files used for sunxi are sync'd unmodified from the upstream repo. I think this is a valuable property to retain in terms of maintenance burden for us (resync is trivial only if there are no local changes).
Thanks for looking at it.
One option is to put the local changes in an #include file. We have a similar problem with "u-boot,dm-pre-reloc". We really should be able to push these sorts of things upstream....
Quoted 5 lines
The conflict is then whether the device tree people would consider this new block to be "describing the hardware" or not and therefore whether these changes would be welcomed/allowed upstream. I'm not sure which way it would go TBH.
Me neither. Although there is a flash map / partition map device tree binding and this is similar.
The binman description lays out what the boot ROM needs in many cases, which is pretty close to being the 'hardware'.
Quoted 7 lines
There is also an issue with duplication, since this stanza is going to be the same for all the dozens of sunxi platforms. I suppose this can be addressed by putting it in a suitable .dtsi file, but that does sort of start to suggest that this information belongs outside the per-board .dts in a per-platform file (at which point I would have have to ask if .dts is the best/most convenient syntax?).
Yes I think we could use the same thing for large groups of boards, but we already have an soc-specific .dtsi in most cases, so that should work quite nicely.
The nice things about device tree are:
- people understand it
- it can be accessed at run-time (e.g. so we know where to find the next image to load)
- we have robust tools for dealing with device tree source and binaries
Regards,
Simon
PATCH 30/30 RFC: Use binman for an x86 board
In reply to Simon GlassAdd an example usage of binman for an x86 board. This involves adding the image definition to the device tree and using it in the Makefile. The existing ifdtool features are no-longer needed.
This is for example only.
---
Makefile | 45 +++------------------------------- arch/x86/dts/chromebook_link.dts | 52 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 42 deletions(-)
Makefile +3 -42
@@ -1023,50 +1023,11 @@ endif # x86 uses a large ROM. We fill it with 0xff, put the 16-bit stuff (including # reset vector) at the top, Intel ME descriptor at the bottom, and U-Boot in -# the middle. +# the middle. This is handled by binman based on an image description in the +# board's device tree. ifneq ($(CONFIG_X86_RESET_VECTOR),) rom: u-boot.rom FORCE -IFDTOOL=$(objtree)/tools/ifdtool -IFDTOOL_FLAGS = -f 0:$(objtree)/u-boot.dtb -IFDTOOL_FLAGS += -m 0x$(shell $(NM) u-boot |grep _dt_ucode_base_size |cut -d' ' -f1) -IFDTOOL_FLAGS += -U $(CONFIG_SYS_TEXT_BASE):$(objtree)/u-boot-nodtb.bin -IFDTOOL_FLAGS += -w $(CONFIG_SYS_X86_START16):$(objtree)/u-boot-x86-16bit.bin -IFDTOOL_FLAGS += -C - -ifneq ($(CONFIG_HAVE_INTEL_ME),) -IFDTOOL_ME_FLAGS = -D $(srctree)/board/$(BOARDDIR)/descriptor.bin -IFDTOOL_ME_FLAGS += -i ME:$(srctree)/board/$(BOARDDIR)/me.bin -endif - -ifneq ($(CONFIG_HAVE_MRC),) -IFDTOOL_FLAGS += -w $(CONFIG_X86_MRC_ADDR):$(srctree)/board/$(BOARDDIR)/mrc.bin -endif - -ifneq ($(CONFIG_HAVE_FSP),) -IFDTOOL_FLAGS += -w $(CONFIG_FSP_ADDR):$(srctree)/board/$(BOARDDIR)/$(CONFIG_FSP_FILE) -endif - -ifneq ($(CONFIG_HAVE_CMC),) -IFDTOOL_FLAGS += -w $(CONFIG_CMC_ADDR):$(srctree)/board/$(BOARDDIR)/$(CONFIG_CMC_FILE) -endif - -ifneq ($(CONFIG_HAVE_VGA_BIOS),) -IFDTOOL_FLAGS += -w $(CONFIG_VGA_BIOS_ADDR):$(srctree)/board/$(BOARDDIR)/$(CONFIG_VGA_BIOS_FILE) -endif - -ifneq ($(CONFIG_HAVE_REFCODE),) -IFDTOOL_FLAGS += -w $(CONFIG_X86_REFCODE_ADDR):refcode.bin -endif - -quiet_cmd_ifdtool = IFDTOOL $@ -cmd_ifdtool = $(IFDTOOL) -c -r $(CONFIG_ROM_SIZE) u-boot.tmp; -ifneq ($(CONFIG_HAVE_INTEL_ME),) -cmd_ifdtool += $(IFDTOOL) $(IFDTOOL_ME_FLAGS) u-boot.tmp; -endif -cmd_ifdtool += $(IFDTOOL) $(IFDTOOL_FLAGS) u-boot.tmp; -cmd_ifdtool += mv u-boot.tmp $@ - refcode.bin: $(srctree)/board/$(BOARDDIR)/refcode.bin FORCE $(call if_changed,copy)
@@ -1076,7 +1037,7 @@ cmd_ldr = $(LD) $(LDFLAGS_$(@F)) \ u-boot.rom: u-boot-x86-16bit.bin u-boot.bin FORCE \ $(if $(CONFIG_HAVE_REFCODE),refcode.bin) - $(call if_changed,ifdtool) + $(call if_changed,binman) OBJCOPYFLAGS_u-boot-x86-16bit.bin := -O binary -j .start16 -j .resetvec u-boot-x86-16bit.bin: u-boot FORCE
arch/x86/dts/chromebook_link.dts +52 -0
63 lines not on this page · raw message
Signature · 1 line
2.8.0.rc3.226.g39d4020
cover binman: A tool for creating firmware images
In reply to Simon GlassHi,
Quoted 39 lines · Simon Glass
This series introduces binman, a tool designed to create firmware images. It provides a way to bring together various binaries and place them in an image, at particular positions and with configurable alignment.
Packaging of firmware is quite a different task from building the various parts. In many cases the various binaries which go into the image come from separate build systems. For example, ARM Trusted Firmware is used on ARMv8 devices but is not built in the U-Boot tree. If a Linux kernel is included in the firmware image, it is built elsewhere.
It is of course possible to add more and more build rules to the U-Boot build system to cover these cases. It can shell out to other Makefiles and build scripts. But it seems better to create a clear divide between building software and packaging it.
U-Boot supports a very large number of boards. Many of these have their own specific rules for how an image should be put together so that it boots correctly. At present these rules are described by manual instructions, different for each board. By turning these instructions into a standard format, we can support making valid images for any board without manual effort, lots of READMEs, etc.
Images consist of a number of entries which are combined to make up the final image. The image is described in the device tree for the board, meaning that it can be accessed at run-time if desired.
Binman is an extensible tool. A set of standard entries is provides, but new entries can be created fairly easily. Entries can be as simple as providing the name of a file to include. They can also handle more complex requirements, such as adjusting the input file or reading header information from one entry to control the position of another.
U-Boot's mkimage builds FIT images and various other binaries. Binman augments this by allowing these binaries to be packed together. While FIT should be used where possible, it cannot be used everywhere. For example, many devices require executable code at a particular offset in the image. X86 machines require lots of binary blobs at particular places, and a microcode collection easily accessible at boot.
Quoted 7 lines
So far binman has enough functionality to be useful, but apart from a few RFC patches, no attempt is made to switch boards over to use it. There should be enough material to permit review and comments.
The series is available at u-boot-dm/binman-working
Future work and missing features are documented in the README.
I'm going to apply the clean-up parts of this series to u-boot-dm/next and then resend just the tool as a shorter series with some updates.
Regards,
Simon