From patchwork Sat Jul 20 18:23:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1134445 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" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="jqw1FZH4"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45rcB84lzLz9s7T for ; Sun, 21 Jul 2019 04:40:16 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 53D79C21C2F; Sat, 20 Jul 2019 18:27:11 +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=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 25C4AC21DD7; Sat, 20 Jul 2019 18:25:29 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D3B62C21E02; Sat, 20 Jul 2019 18:25:05 +0000 (UTC) Received: from mail-io1-f67.google.com (mail-io1-f67.google.com [209.85.166.67]) by lists.denx.de (Postfix) with ESMTPS id EC017C21DB3 for ; Sat, 20 Jul 2019 18:25:01 +0000 (UTC) Received: by mail-io1-f67.google.com with SMTP id z3so65310583iog.0 for ; Sat, 20 Jul 2019 11:25:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ul9Bn9QkbtN39BRbgN45100bUEcKwgok9Gdkf0khgUI=; b=jqw1FZH4MxoDvcfIo6GXzHBOw6CBWYH8Tivv4I7xhw0g3C5JHMSuK25jokHu9WmfUf NJBtQqiee0cP9T7NHIBY+uyjG7fYYbPgjZuImxwmX5Q2XvBnzVbiMYCg83NDPbdg18nR esxpoYvFoRhBRO59DM5IXRd2wwF4OSUgDBZAc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ul9Bn9QkbtN39BRbgN45100bUEcKwgok9Gdkf0khgUI=; b=NE3DXt4s0hTdKTh8akLdrNX36z5XF5PwbMzLbZvOAt8FK2LTXYuOnfB13e598r48OO Rq3mimsfVYJzeVWFC+ARO5f1SVi74xLnKcoAZLqamVa9u2ubTklEw9U6rr2uRrsWMIFV erMh9PHiChQY/nBDYqPsS/lTZuWxg3MTdK+lBGQPLl1opTn3itlcSaqMCgyHg7UqbUrc s6Z2ohSGusb4GBHAAQOnaln8nhk7rw/Io3uLeILRAjv8I9cF9a/BIal/IorAcHveeqWg xFe0paxxACIhQrWQSlvK+xfRuUrbN6Y7NOS/Sj7OlAaIrXlWbx0Vn1AEeEiJjHbGhF95 KybQ== X-Gm-Message-State: APjAAAVIWlSp85AUtRAFtpEqAWyC5Epzr6Z8NLjbOf6s84ih8yAeS8ke opw3LMNAi+t4w2ShoUYJDem4LM7VBvE= X-Google-Smtp-Source: APXvYqxa5W/xeJ5VNtiUpzplgynz/OtCs3QTr64wJAhs1GqQvQeNVKrTuvTB7TT/0+7NEKMrn9GPfA== X-Received: by 2002:a5e:9701:: with SMTP id w1mr56824564ioj.294.1563647100779; Sat, 20 Jul 2019 11:25:00 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id z17sm49778933iol.73.2019.07.20.11.25.00 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 20 Jul 2019 11:25:00 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Sat, 20 Jul 2019 12:23:24 -0600 Message-Id: <20190720182416.183626-3-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.657.g960e92d24f-goog In-Reply-To: <20190720182416.183626-1-sjg@chromium.org> References: <20190720182416.183626-1-sjg@chromium.org> MIME-Version: 1.0 Subject: [U-Boot] [PATCH 02/53] binman: Move image-processing code into a function 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" The Binman() function is very long. Split out the image code to make it more manageable. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- tools/binman/control.py | 103 ++++++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 46 deletions(-) diff --git a/tools/binman/control.py b/tools/binman/control.py index dc898be6179..a92056846d0 100644 --- a/tools/binman/control.py +++ b/tools/binman/control.py @@ -169,6 +169,62 @@ def ExtractEntries(image_fname, output_fname, outdir, entry_paths, return einfos +def ProcessImage(image, update_fdt, write_map): + """Perform all steps for this image, including checking and # writing it. + + This means that errors found with a later image will be reported after + earlier images are already completed and written, but that does not seem + important. + + Args: + image: Image to process + update_fdt: True to update the FDT wth entry offsets, etc. + write_map: True to write a map file + """ + image.GetEntryContents() + image.GetEntryOffsets() + + # We need to pack the entries to figure out where everything + # should be placed. This sets the offset/size of each entry. + # However, after packing we call ProcessEntryContents() which + # may result in an entry changing size. In that case we need to + # do another pass. Since the device tree often contains the + # final offset/size information we try to make space for this in + # AddMissingProperties() above. However, if the device is + # compressed we cannot know this compressed size in advance, + # since changing an offset from 0x100 to 0x104 (for example) can + # alter the compressed size of the device tree. So we need a + # third pass for this. + passes = 3 + for pack_pass in range(passes): + try: + image.PackEntries() + image.CheckSize() + image.CheckEntries() + except Exception as e: + if write_map: + fname = image.WriteMap() + print("Wrote map file '%s' to show errors" % fname) + raise + image.SetImagePos() + if update_fdt: + image.SetCalculatedProperties() + for dtb_item in state.GetFdts(): + dtb_item.Sync() + sizes_ok = image.ProcessEntryContents() + if sizes_ok: + break + image.ResetForPack() + if not sizes_ok: + image.Raise('Entries expanded after packing (tried %s passes)' % + passes) + + image.WriteSymbols() + image.BuildImage() + if write_map: + image.WriteMap() + + def Binman(args): """The main control code for binman @@ -279,52 +335,7 @@ def Binman(args): dtb_item.Flush() for image in images.values(): - # Perform all steps for this image, including checking and - # writing it. This means that errors found with a later - # image will be reported after earlier images are already - # completed and written, but that does not seem important. - image.GetEntryContents() - image.GetEntryOffsets() - - # We need to pack the entries to figure out where everything - # should be placed. This sets the offset/size of each entry. - # However, after packing we call ProcessEntryContents() which - # may result in an entry changing size. In that case we need to - # do another pass. Since the device tree often contains the - # final offset/size information we try to make space for this in - # AddMissingProperties() above. However, if the device is - # compressed we cannot know this compressed size in advance, - # since changing an offset from 0x100 to 0x104 (for example) can - # alter the compressed size of the device tree. So we need a - # third pass for this. - passes = 3 - for pack_pass in range(passes): - try: - image.PackEntries() - image.CheckSize() - image.CheckEntries() - except Exception as e: - if args.map: - fname = image.WriteMap() - print("Wrote map file '%s' to show errors" % fname) - raise - image.SetImagePos() - if args.update_fdt: - image.SetCalculatedProperties() - for dtb_item in state.GetFdts(): - dtb_item.Sync() - sizes_ok = image.ProcessEntryContents() - if sizes_ok: - break - image.ResetForPack() - if not sizes_ok: - image.Raise('Entries expanded after packing (tried %s passes)' % - passes) - - image.WriteSymbols() - image.BuildImage() - if args.map: - image.WriteMap() + ProcessImage(image, args.update_fdt, args.map) # Write the updated FDTs to our output files for dtb_item in state.GetFdts():