From patchwork Fri Sep 14 10:57:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 969731 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 Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 42BXtp2F0hz9sBx for ; Fri, 14 Sep 2018 21:13:06 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 0E828C2203F; Fri, 14 Sep 2018 11:02:56 +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_MSPIKE_H2 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 EDBF8C2200F; Fri, 14 Sep 2018 10:59:00 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 54F09C22061; Fri, 14 Sep 2018 10:58:34 +0000 (UTC) Received: from mail-ua1-f73.google.com (mail-ua1-f73.google.com [209.85.222.73]) by lists.denx.de (Postfix) with ESMTPS id 154B5C2204A for ; Fri, 14 Sep 2018 10:58:28 +0000 (UTC) Received: by mail-ua1-f73.google.com with SMTP id i4-v6so2813818ual.15 for ; Fri, 14 Sep 2018 03:58:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Z32KWP5VgesIMX5N/wTKA/UgV278AH7jXi+wtdSmEJw=; b=Ma0xEWl22wB6lJDe6rLs8ZRTmDvsvbRfA56kBXsmKCBan3r1aHaT3S1n+0MoTwL7Ho 5hamQzhBCNpAxKXAxV+mSVMdD3cUH1wItTqW8SP1rnUysuT6JGlLedUy3lo6SN77/fi8 vMNxd+xOwWvoE0PBPriyyVs5jR6A64yRlKsXI6MKppMQQiajFkDp/oQsBE9x0os00AlI I6lQkORfF6dMwJ82h5trWkf4KqBmOBf7pjrTEeEnw1jPwspBhfdFmfrlhdd/CidrI6Dv CkWEL6N7KKZyWOScgkC1k+rLR79e9LrSwWyQwZ0FW7JAgPVAkIUHaM7PhICQqvt/TpDG yIdg== X-Gm-Message-State: APzg51AzGTTHvRNySAK3PXGCbmGU08T7pJez9J0zL5TGw/hrzOqnPPxF bLzVyAfYX77lrrvplJ1jtucj6fs= X-Google-Smtp-Source: ANB0Vdbz0ndZPnJLQAeR+KE1/m1xWCa50bGIgZ7G2So+OpnGxuw5f+g8oVi/aotz1/IcHlipSme6N7I= X-Received: by 2002:a67:a819:: with SMTP id r25-v6mr2165674vse.14.1536922707082; Fri, 14 Sep 2018 03:58:27 -0700 (PDT) Date: Fri, 14 Sep 2018 04:57:20 -0600 In-Reply-To: <20180914105736.162666-1-sjg@chromium.org> Message-Id: <20180914105736.162666-16-sjg@chromium.org> Mime-Version: 1.0 References: <20180914105736.162666-1-sjg@chromium.org> X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini Subject: [U-Boot] [PATCH 15/31] binman: Move state logic into the state module 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Rather than reaching into this module from control, move the code that needs this info into state. Signed-off-by: Simon Glass --- tools/binman/control.py | 21 ++++++++++++-------- tools/binman/state.py | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/tools/binman/control.py b/tools/binman/control.py index 00dcb8ad6a5..fd8b779945d 100644 --- a/tools/binman/control.py +++ b/tools/binman/control.py @@ -121,8 +121,6 @@ def Binman(options, args): outfd.write(infd.read()) dtb = fdt.FdtScan(fname) - # Note the file so that GetFdt() can find it - state.fdt_files['u-boot.dtb'] = dtb node = _FindBinmanNode(dtb) if not node: raise ValueError("Device tree '%s' does not have a 'binman' " @@ -139,6 +137,8 @@ def Binman(options, args): if skip: print 'Skipping images: %s\n' % ', '.join(skip) + state.Prepare(dtb) + # Prepare the device tree by making sure that any missing # properties are added (e.g. 'pos' and 'size'). The values of these # may not be correct yet, but we add placeholders so that the @@ -151,9 +151,10 @@ def Binman(options, args): image.AddMissingProperties() image.ProcessFdt(dtb) - dtb.Sync(auto_resize=True) - dtb.Pack() - dtb.Flush() + for dtb_item in state.GetFdts(): + dtb_item.Sync(auto_resize=True) + dtb_item.Pack() + dtb_item.Flush() for image in images.values(): # Perform all steps for this image, including checking and @@ -168,14 +169,18 @@ def Binman(options, args): image.SetImagePos() if options.update_fdt: image.SetCalculatedProperties() - dtb.Sync() + for dtb_item in state.GetFdts(): + dtb_item.Sync() image.ProcessEntryContents() image.WriteSymbols() image.BuildImage() if options.map: image.WriteMap() - with open(fname, 'wb') as outfd: - outfd.write(dtb.GetContents()) + + # Write the updated FDTs to our output files + for dtb_item in state.GetFdts(): + tools.WriteFile(dtb_item._fname, dtb_item.GetContents()) + finally: tools.FinaliseOutputDir() finally: diff --git a/tools/binman/state.py b/tools/binman/state.py index 6bc24ddf8ac..9583b3fa5f6 100644 --- a/tools/binman/state.py +++ b/tools/binman/state.py @@ -18,6 +18,15 @@ fdt_files = {} # Arguments passed to binman to provide arguments to entries entry_args = {} +# Set of all device tree files references by images +fdt_set = Set() + +# Same as above, but excluding the main one +fdt_subset = Set() + +# The DTB which contains the full image information +main_dtb = None + def GetFdt(fname): """Get the Fdt object for a particular device-tree filename @@ -75,3 +84,37 @@ def GetEntryArg(name): String value of argument """ return entry_args.get(name) + +def Prepare(dtb): + """Get device tree files ready for use + + This sets up a set of device tree files that can be retrieved by GetFdts(). + At present there is only one, that for U-Boot proper. + + Args: + dtb: Main dtb + """ + global fdt_set, fdt_subset, fdt_files, main_dtb + # Import these here in case libfdt.py is not available, in which case + # the above help option still works. + import fdt + import fdt_util + + # If we are updating the DTBs we need to put these updated versions + # where Entry_blob_dtb can find them. We can ignore 'u-boot.dtb' + # since it is assumed to be the one passed in with options.dt, and + # was handled just above. + main_dtb = dtb + fdt_files.clear() + fdt_files['u-boot.dtb'] = dtb + fdt_set = Set() + fdt_subset = Set() + +def GetFdts(): + """Yield all device tree files being used by binman + + Yields: + Device trees being used (U-Boot proper, SPL, TPL) + """ + yield main_dtb +