[U-Boot] [PATCH v2 06/12] binman: Add support for sections

2018-06-01 Thread Simon Glass
It is useful to be able to split an image into multiple sections,
each with its own size and position, for cases where a flash device has
read-only and read-write portions.

Add support for this.

Signed-off-by: Simon Glass 
---

Changes in v2:
- Add SPDX tag to .dts file

 tools/binman/README   | 41 +++--
 tools/binman/bsection.py  |  1 +
 tools/binman/entry.py |  9 ++
 tools/binman/etype/section.py | 50 +++
 tools/binman/ftest.py |  5 
 tools/binman/test/55_sections.dts | 28 +
 6 files changed, 132 insertions(+), 2 deletions(-)
 create mode 100644 tools/binman/etype/section.py
 create mode 100644 tools/binman/test/55_sections.dts

diff --git a/tools/binman/README b/tools/binman/README
index 196dda1fb4c..5ef1246f296 100644
--- a/tools/binman/README
+++ b/tools/binman/README
@@ -392,6 +392,45 @@ either by using a unit number suffix (u-boot@0, u-boot@1) 
or by using a
 different name for each and specifying the type with the 'type' attribute.
 
 
+Sections and hiearchical images
+---
+
+Sometimes it is convenient to split an image into several pieces, each of which
+contains its own set of binaries. An example is a flash device where part of
+the image is read-only and part is read-write. We can set up sections for each
+of these, and place binaries in them independently. The image is still produced
+as a single output file.
+
+This feature provides a way of creating hierarchical images. For example here
+is an example with two copies of U-Boot. One is read-only (ro), intended to be
+written only in the factory. Another is read-write (rw), so that it can be
+upgraded in the field. The sizes are fixed so that the ro/rw boundary is known
+and can be programmed:
+
+   binman {
+   section@0 {
+   read-only;
+   size = <0x10>;
+   u-boot {
+   };
+   };
+   section@1 {
+   size = <0x10>;
+   u-boot {
+   };
+   };
+   };
+
+This image could be placed into a SPI flash chip, with the protection boundary
+set at 1MB.
+
+A few special properties are provided for sections:
+
+read-only:
+   Indicates that this section is read-only. This has no impact on binman's
+   operation, but his property can be read at run time.
+
+
 Special properties
 --
 
@@ -586,8 +625,6 @@ Some ideas:
 - 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
-  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
diff --git a/tools/binman/bsection.py b/tools/binman/bsection.py
index 07c72d34c43..331f806d9ab 100644
--- a/tools/binman/bsection.py
+++ b/tools/binman/bsection.py
@@ -201,6 +201,7 @@ class Section(object):
 pos = 0
 prev_name = 'None'
 for entry in self._entries.values():
+entry.CheckPosition()
 if (entry.pos < self._skip_at_start or
 entry.pos >= self._skip_at_start + self._size):
 entry.Raise("Position %#x (%d) is outside the section starting 
"
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index 5374178542e..8b46fbb5fa6 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -220,3 +220,12 @@ class Entry(object):
   section: Section containing the entry
 """
 pass
+
+def CheckPosition(self):
+"""Check that the entry positions are correct
+
+This is used for entries which have extra position requirements (other
+than having to be fully inside their section). Sub-classes can 
implement
+this function and raise if there is a problem.
+"""
+pass
diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py
new file mode 100644
index 000..4e2f686eea8
--- /dev/null
+++ b/tools/binman/etype/section.py
@@ -0,0 +1,50 @@
+# SPDX-License-Identifier:  GPL-2.0+
+# Copyright (c) 2018 Google, Inc
+# Written by Simon Glass 
+#
+# Entry-type module for sections, which are entries which can contain other
+# entries.
+#
+
+from entry import Entry
+import fdt_util
+import tools
+
+import bsection
+
+class Entry_section(Entry):
+def __init__(self, image, etype, node):
+Entry.__init__(self, image, etype, node)
+self._section = bsection.Section(node.name, node)
+
+def ObtainContents(self):
+self._section.GetEntryContents()
+
+def GetData(self):
+return self._section.GetData()

Re: [U-Boot] [PATCH v2 06/12] binman: Add support for sections

2018-06-07 Thread Simon Glass
On 1 June 2018 at 07:38, Simon Glass  wrote:
> It is useful to be able to split an image into multiple sections,
> each with its own size and position, for cases where a flash device has
> read-only and read-write portions.
>
> Add support for this.
>
> Signed-off-by: Simon Glass 
> ---
>
> Changes in v2:
> - Add SPDX tag to .dts file
>
>  tools/binman/README   | 41 +++--
>  tools/binman/bsection.py  |  1 +
>  tools/binman/entry.py |  9 ++
>  tools/binman/etype/section.py | 50 +++
>  tools/binman/ftest.py |  5 
>  tools/binman/test/55_sections.dts | 28 +
>  6 files changed, 132 insertions(+), 2 deletions(-)
>  create mode 100644 tools/binman/etype/section.py
>  create mode 100644 tools/binman/test/55_sections.dts

Applied to u-boot-dm
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot