From patchwork Wed May 16 01:52:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 914115 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="fVYknimu"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40lyDq0CWPz9ryk for ; Wed, 16 May 2018 11:55:06 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id ABA10C21E1A; Wed, 16 May 2018 01:54:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 9E112C21DCA; Wed, 16 May 2018 01:53:20 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 7C7FCC21BE5; Wed, 16 May 2018 01:53:15 +0000 (UTC) Received: from mail-it0-f50.google.com (mail-it0-f50.google.com [209.85.214.50]) by lists.denx.de (Postfix) with ESMTPS id 1D2DCC21DB5 for ; Wed, 16 May 2018 01:53:11 +0000 (UTC) Received: by mail-it0-f50.google.com with SMTP id 144-v6so6546764iti.5 for ; Tue, 15 May 2018 18:53:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=MXGpf/LzJdPQ2BhVM45oV8hY64t1YmhhdJboK/dOigk=; b=fVYknimuGAKvcxKr8ks60c6pAkMMboqK1rMYB/f8xoTwQDZ5vTqjnB3SzEG+6pnkbU coWwbIg5w6PG0VZEI+axpCfGpjb3kU1CcYBl7fpjEFQ6pKPqBYFldaAljrGiWWbUJlML HQgS6LbUotXYJx1Avr9cKpPh6cH847rt6RLbqPs4540NbqGNWBZ3z5lTufnr7uikEbzu w0ziJXijppaXKqY0b6I8OC5bvIbrJIH7S4eYlft9oF0uW7+FQeSTeoTR9fpD8Tqbcc1A WKkpO8AEU4ozJnpOrlz6fRRBygirv6/4Xxr1g9XCw4ogul7tnDcd99HBWsZITcktkUTv sIrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=MXGpf/LzJdPQ2BhVM45oV8hY64t1YmhhdJboK/dOigk=; b=McBWhrUVCKwW4Ohl2a5yheE6rre9fXnOvOxBOwTvdDK/drnlQocBrO8L8saN1CQ2SI NMIKpxU/dVNlcP15tNzCEx8qcIdB6fWT7v1HYCu1KzoGqZj+boKh29QS5HDiH+PpSD2w 7XtfyUiTVOLIjTcfKUuNvZGmmkpJ+vVqH0HdFXfOZUTxXkGrVxrgShWPl2gsdKV0u8JF pjqiK+pkP0+3wsh0546ZryeXD83cuZwszDD2zWyk3eMMl0dWviwCCi+i4ozE3Go55FaX kh63TvdjRqvZHpkpxmqtxOwDR2iSkmEr8QnFFj1kQI/cmDisaFxJtM4PIZLLqze/3SI4 /ZsQ== X-Gm-Message-State: ALKqPwe+CPszGIQfppjc3UdoxKJGh+Lubtbopzc2mVxn3OzIqh6GXlBh 8a0QBOwdJAANOw4FPuFfc2RxmA== X-Google-Smtp-Source: AB8JxZr7ScXhjoZ8w/4nOI9+qso+y463JJqxqwwnFpH76NlN9HGH8ttWCG6hISXDTARyLpFhwHHWyw== X-Received: by 2002:a6b:1801:: with SMTP id 1-v6mr18380664ioy.129.1526435589471; Tue, 15 May 2018 18:53:09 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id x64-v6sm1416876ioe.5.2018.05.15.18.53.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 15 May 2018 18:53:08 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 34359140C6B; Tue, 15 May 2018 19:53:08 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 15 May 2018 19:52:52 -0600 Message-Id: <20180516015258.187295-7-sjg@chromium.org> X-Mailer: git-send-email 2.17.0.441.gb46fe60e1d-goog In-Reply-To: <20180516015258.187295-1-sjg@chromium.org> References: <20180516015258.187295-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 06/12] binman: Add support for sections X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 --- tools/binman/README | 41 +++++++++++++++++++++++-- tools/binman/bsection.py | 1 + tools/binman/entry.py | 9 ++++++ tools/binman/etype/section.py | 51 +++++++++++++++++++++++++++++++ tools/binman/ftest.py | 5 +++ tools/binman/test/55_sections.dts | 26 ++++++++++++++++ 6 files changed, 131 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 = <0x100000>; + u-boot { + }; + }; + section@1 { + size = <0x100000>; + 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 70da2c9ef50..9333932d41e 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 00000000000..7437f91567d --- /dev/null +++ b/tools/binman/etype/section.py @@ -0,0 +1,51 @@ +# Copyright (c) 2018 Google, Inc +# Written by Simon Glass +# +# SPDX-License-Identifier: GPL-2.0+ +# +# 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() + + def GetPositions(self): + """Handle entries that want to set the position/size of other entries + + This calls each entry's GetPositions() method. If it returns a list + of entries to update, it updates them. + """ + self._section.GetEntryPositions() + return {} + + def Pack(self, pos): + """Pack all entries into the section""" + self._section.PackEntries() + self.size = self._section.CheckSize() + return super(Entry_section, self).Pack(pos) + + def WriteSymbols(self, section): + """Write symbol values into binary files for access at run time""" + self._section.WriteSymbols() + + def ProcessContents(self): + self._section.ProcessEntryContents() + super(Entry_section, self).ProcessContents() + + def CheckPosition(self): + self._section.CheckEntries() diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 96a5535626d..06b8132f01f 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -914,6 +914,11 @@ class TestFunctional(unittest.TestCase): data = self._DoReadFile('54_unit_address.dts') self.assertEqual(U_BOOT_DATA + U_BOOT_DATA, data) + def testSections(self): + """Basic test of sections""" + data = self._DoReadFile('55_sections.dts') + expected = U_BOOT_DATA + '!' * 12 + U_BOOT_DATA + 'a' * 12 + '&' * 8 + self.assertEqual(expected, data) if __name__ == "__main__": unittest.main() diff --git a/tools/binman/test/55_sections.dts b/tools/binman/test/55_sections.dts new file mode 100644 index 00000000000..04081f78d60 --- /dev/null +++ b/tools/binman/test/55_sections.dts @@ -0,0 +1,26 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + pad-byte = <0x26>; + size = <0x28>; + section@0 { + read-only; + size = <0x10>; + pad-byte = <0x21>; + + u-boot { + }; + }; + section@1 { + size = <0x10>; + pad-byte = <0x61>; + + u-boot { + }; + }; + }; +};