From patchwork Tue Jul 2 00:24:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1125741 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="J9PUYMVO"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45d4ym5Zw9z9s4V for ; Tue, 2 Jul 2019 10:35:28 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 77E6FC21CB6; Tue, 2 Jul 2019 00:29:54 +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, 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 E606FC21D74; Tue, 2 Jul 2019 00:25:36 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 5DF8BC21E63; Tue, 2 Jul 2019 00:25:19 +0000 (UTC) Received: from mail-io1-f68.google.com (mail-io1-f68.google.com [209.85.166.68]) by lists.denx.de (Postfix) with ESMTPS id E207CC21C4A for ; Tue, 2 Jul 2019 00:25:13 +0000 (UTC) Received: by mail-io1-f68.google.com with SMTP id k8so33075382iot.1 for ; Mon, 01 Jul 2019 17:25:13 -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=9tXJS95CCiVRMc1Pk8BjW0/4h/ztgiKta+ZWfRs9PkY=; b=J9PUYMVOjhdpOCWenMM8CCJsOcA8N8WTTEFABAci9UMJeFE/foCq2xlHXRuaPsuVoQ S1yXjekvaH+TaCUTrN0vZSVfpVWTbxWpuqEjE59O38ZspaA33ZHvtjAt2ssRn18lrg5x aWnxtRZdmrXdvEdkl2Pu9l5NvGPF1shbhKs0s= 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=9tXJS95CCiVRMc1Pk8BjW0/4h/ztgiKta+ZWfRs9PkY=; b=dsM+o9M2Q2kp1yJ2XPM31LP58tLvykiLFMYxEi+0IwBEF2yRbdxd8IFKBJCJ/ZFhi8 J1bGpBtmmr67Je2iaAnsm7BCFyTANL9wwEJGiKLB/zSYXXmtDV6qPgjjBDGlq51M/ta/ s+Qv/Jvor9FcPlxU24pAiuhiIKXH0DX17t/5f9fpjhAfRYZkFbCmLdnyRMDzmaSizfvp jva4aY8eVsN2XWyqnspN2Th/mLvb+2cm7lDTHNbM3Gi+qRrOO/GuWqBi3yH4VDjDktWX XzhqOFM82AgSIvp9BWH8FCIa7l6u6egODGZE0et62MqYhMU5syr9w2mwMtHHrOawc+0t q8mw== X-Gm-Message-State: APjAAAVYA62nzRxtffdbs4JZjzG9nJl3aYny8PXaCZ00x3M54kJzNzAg zIGxcyn0IrPatUgxabythXdw6upIMpA= X-Google-Smtp-Source: APXvYqwP373Up/oscNWSp5IlqOLrS1oDVnk0llLkI8WROdEhlDOW4wUlSB6Wdl1E5s4T0uj4Kmm6Yg== X-Received: by 2002:a6b:3883:: with SMTP id f125mr30176929ioa.109.1562027112738; Mon, 01 Jul 2019 17:25:12 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h19sm10539202iol.65.2019.07.01.17.25.11 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 17:25:12 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 1 Jul 2019 18:24:30 -0600 Message-Id: <20190702002455.996-2-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190702002455.996-1-sjg@chromium.org> References: <20190702002455.996-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH 01/26] binman: Simplify the entry test 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 current test for the 'entry' module is a bit convoluted since it has to import the module multiple times. It also relies on ordering, in that test1EntryNoImportLib() must run before test2EntryImportLib() if they are running in the same Python process. This is unreliable since neither the ordering of tests nor the process that they run in is defined. Fix this by always reloading the entry in these two tests. Also add a check that the expected value of have_importlib is obtained. This corrects a code-coverage problem in the 'entry' module on some systems. Signed-off-by: Simon Glass --- tools/binman/entry_test.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tools/binman/entry_test.py b/tools/binman/entry_test.py index b30a7beecc8..b6ad3edb8dc 100644 --- a/tools/binman/entry_test.py +++ b/tools/binman/entry_test.py @@ -9,12 +9,11 @@ import os import sys import unittest +import entry import fdt import fdt_util import tools -entry = None - class TestEntry(unittest.TestCase): def setUp(self): tools.PrepareOutputDir(None) @@ -29,16 +28,7 @@ class TestEntry(unittest.TestCase): dtb = fdt.FdtScan(fname) return dtb.GetNode('/binman/u-boot') - def test1EntryNoImportLib(self): - """Test that we can import Entry subclassess successfully""" - - sys.modules['importlib'] = None - global entry - import entry - entry.Entry.Create(None, self.GetNode(), 'u-boot') - - def test2EntryImportLib(self): - del sys.modules['importlib'] + def _ReloadEntry(self): global entry if entry: if sys.version_info[0] >= 3: @@ -48,8 +38,21 @@ class TestEntry(unittest.TestCase): reload(entry) else: import entry + + def test1EntryNoImportLib(self): + """Test that we can import Entry subclassess successfully""" + sys.modules['importlib'] = None + global entry + self._ReloadEntry() + entry.Entry.Create(None, self.GetNode(), 'u-boot') + self.assertFalse(entry.have_importlib) + + def test2EntryImportLib(self): + del sys.modules['importlib'] + global entry + self._ReloadEntry() entry.Entry.Create(None, self.GetNode(), 'u-boot-spl') - del entry + self.assertTrue(entry.have_importlib) def testEntryContents(self): """Test the Entry bass class""" @@ -59,7 +62,6 @@ class TestEntry(unittest.TestCase): def testUnknownEntry(self): """Test that unknown entry types are detected""" - import entry Node = collections.namedtuple('Node', ['name', 'path']) node = Node('invalid-name', 'invalid-path') with self.assertRaises(ValueError) as e: @@ -69,7 +71,6 @@ class TestEntry(unittest.TestCase): def testUniqueName(self): """Test Entry.GetUniqueName""" - import entry Node = collections.namedtuple('Node', ['name', 'parent']) base_node = Node('root', None) base_entry = entry.Entry(None, None, base_node, read_node=False) @@ -80,7 +81,6 @@ class TestEntry(unittest.TestCase): def testGetDefaultFilename(self): """Trivial test for this base class function""" - import entry base_entry = entry.Entry(None, None, None, read_node=False) self.assertIsNone(base_entry.GetDefaultFilename()) From patchwork Tue Jul 2 00:24:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1125748 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="LNJ2B167"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45d52T27sdz9s4V for ; Tue, 2 Jul 2019 10:38:41 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id EAC8DC21E08; Tue, 2 Jul 2019 00:30:34 +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 63888C21C27; Tue, 2 Jul 2019 00:25:38 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B8ABBC21E16; Tue, 2 Jul 2019 00:25:19 +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 93FDDC21C2C for ; Tue, 2 Jul 2019 00:25:14 +0000 (UTC) Received: by mail-io1-f67.google.com with SMTP id u19so24468138ior.9 for ; Mon, 01 Jul 2019 17:25:14 -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=CUnomXLS2lCbYZtzr6RT4SvnKnjmFRF4Q8ZFLElz/a8=; b=LNJ2B167YwHjaJOQ6j27BgDaymZ+cMAXTrA4UJu64BSCmfJgrMTl6e94/ldh6dYxRL Uh3tK0S8ZQgiLj+crABDxxa33xkXaulM4zpfjhgUCJ5BN28zbBWaovK5l0DX6aSOLgNj jNtzdbJYtq5kpWRuYE0FBYsyu/qk25cUhzwlM= 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=CUnomXLS2lCbYZtzr6RT4SvnKnjmFRF4Q8ZFLElz/a8=; b=T/k7ReMJTZOd3U4TZdGV6k952StqpUFp4K/CGq+MCK9COf0z0kqJt55R06kncyM+HZ df5AybWPY57xzfFGDH1dkDlzksvanWAACeO55tRzN03p7VTRrkLVKy6L77aWvDb2PMJ8 +9rfn+3zWSh31COSwAGQr0vZe+5ePKwgpRIIow1FnItPB0V7t86PZnILiaOnZUUT+2vV 7ZYnd60bd7PTxO5/jYKVScGz8Ld+u3RaUDdkTmAF9rXGySacxtT0/OLJeFzxaazhYaRC rIPxCA3ioraN0UF1F6k/szHfvGzg8++alp9G34CdukcJm2WQCiYtp/GGKQTkcHZJHRiS xm2g== X-Gm-Message-State: APjAAAUQ4KUMUa9rbCKTF3/0/SwvNHtwTE3AJwXkEJ1Kx7EQOejlsJhi L3nW36PrdW6As/kZaDpIVk/ONWgcLtA= X-Google-Smtp-Source: APXvYqzqB83LA0XOD54Rf+2WJOopRh5P0WSRuWWWhuiBXiWSO5Gz19GDCj72rpPM8b4wP08274SflA== X-Received: by 2002:a02:1948:: with SMTP id b69mr32479901jab.55.1562027113435; Mon, 01 Jul 2019 17:25:13 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h19sm10539202iol.65.2019.07.01.17.25.12 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 17:25:13 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 1 Jul 2019 18:24:31 -0600 Message-Id: <20190702002455.996-3-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190702002455.996-1-sjg@chromium.org> References: <20190702002455.996-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH 02/26] binman: Update future features 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" A few features have been completed and a few items are added. Signed-off-by: Simon Glass --- tools/binman/README | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/binman/README b/tools/binman/README index 2f4c7fec21e..92341a14b61 100644 --- a/tools/binman/README +++ b/tools/binman/README @@ -811,13 +811,13 @@ Some ideas: - Use of-platdata to make the information available to code that is unable to use device tree (such as a very small SPL image) - Allow easy building of images by specifying just the board name -- Produce a full Python binding for libfdt (for upstream). This is nearing - completion but some work remains - Add an option to decode an image into the constituent binaries - 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 +- Support putting the FDT in an image with a suitable magic number +- Support adding a pointer to the FDT map +- Support listing files in images +- Support logging of binman's operations, with different levels of verbosity -- Simon Glass From patchwork Tue Jul 2 00:24:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1125724 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="R06HMT3x"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45d4mw6YSCz9s4V for ; Tue, 2 Jul 2019 10:26:56 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 81374C21E13; Tue, 2 Jul 2019 00:26:27 +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 A62F4C21E0D; Tue, 2 Jul 2019 00:25:28 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id C7C75C21DA1; Tue, 2 Jul 2019 00:25:19 +0000 (UTC) Received: from mail-io1-f65.google.com (mail-io1-f65.google.com [209.85.166.65]) by lists.denx.de (Postfix) with ESMTPS id 2DDA3C21E02 for ; Tue, 2 Jul 2019 00:25:15 +0000 (UTC) Received: by mail-io1-f65.google.com with SMTP id w25so32967035ioc.8 for ; Mon, 01 Jul 2019 17:25:15 -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=BILwmdtM5ZnWghHAKqFTrcZnh5BDq6/S0tDAkedG3cs=; b=R06HMT3xhIiOLw2GwTBFckdERmlnjuXe2qGTOZgMimrRXL24svikdqyAp5R426ekaa 9L+MykaWNIGa43WR6QXjoYA8VrqGV9GVtkB2/SyQYtfcCiaXLSaflia4tapfBWw4PbNP /RzG1Oe/inhE5/66ZgPBl3ZavGDqInbZAzrIY= 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=BILwmdtM5ZnWghHAKqFTrcZnh5BDq6/S0tDAkedG3cs=; b=Z08N6EgmGcMD6jdLA3cC6GGhSfvh7X+7fS32KTbvN6r6z9r1Q/brju5dj7BGL+tUYL VOoKSrtV0ywrHzYLS1V68GBqKRu4YL6hskiNx+KIRAYLX965wLRHEveowEmPX1Jl0OMd jgImoCsjhi/cNP+K62d0hvnYuTB/3r7VI2GMlTtKrUgAwbTiK80VZyDop2J51vwnpyqU esEqG7k4qbukjinJ/rXFDdYMA/wtaGPECfhyoYvH3SWbTik/XaANigMjP1MOU+ZIBYxd aO6u1NGDrmIygguIm8WtUocgGiNHZF6oYBGfb0FzSpLqZtj5apwgyvTNzY7rxUJCrhQc zGTQ== X-Gm-Message-State: APjAAAWuGAOWJ87oyT0QAh9big8/T3ZJCZOH3Yha3WAq2y9WgDXUWghi GLDVUk40eBXuNnMOTDBn+HyjhHs1YcM= X-Google-Smtp-Source: APXvYqz/3jBUPfqwshVBeF9b4ni2VmUak9p2hMObWf1Qnd4uqYhfLOXqvPFori8Bsi5J1vkKlU/pKA== X-Received: by 2002:a02:c492:: with SMTP id t18mr32024873jam.67.1562027114071; Mon, 01 Jul 2019 17:25:14 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h19sm10539202iol.65.2019.07.01.17.25.13 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 17:25:13 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 1 Jul 2019 18:24:32 -0600 Message-Id: <20190702002455.996-4-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190702002455.996-1-sjg@chromium.org> References: <20190702002455.996-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH 03/26] binman: Update help for new features 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" A few new features have been added. This has rendered part of the README obsolete. Update it. Signed-off-by: Simon Glass --- tools/binman/README | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/binman/README b/tools/binman/README index 92341a14b61..f07de350f60 100644 --- a/tools/binman/README +++ b/tools/binman/README @@ -36,10 +36,9 @@ suitable padding and alignment. It provides a way to process binaries before they are included, by adding a Python plug-in. The device tree is available to U-Boot at run-time so that the images can be interpreted. -Binman does not yet update the device tree with the final location of -everything when it is done. A simple C structure could be generated for -constrained environments like SPL (using dtoc) but this is also not -implemented. +Binman can update the device tree with the final location of everything when it +is done. Entry positions can be provided to U-Boot SPL as run-time symbols, +avoiding device-tree code overhead. Binman can also support incorporating filesystems in the image if required. For example x86 platforms may use CBFS in some cases. From patchwork Tue Jul 2 00:24:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1125726 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="WnYt753p"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45d4q14swTz9s4V for ; Tue, 2 Jul 2019 10:28:45 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 5C407C21DA1; Tue, 2 Jul 2019 00:27:52 +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 E9471C21E42; Tue, 2 Jul 2019 00:25:30 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D2A3BC21DFD; Tue, 2 Jul 2019 00:25:20 +0000 (UTC) Received: from mail-io1-f65.google.com (mail-io1-f65.google.com [209.85.166.65]) by lists.denx.de (Postfix) with ESMTPS id 2F99FC21BE5 for ; Tue, 2 Jul 2019 00:25:16 +0000 (UTC) Received: by mail-io1-f65.google.com with SMTP id s7so32925618iob.11 for ; Mon, 01 Jul 2019 17:25:16 -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=bMEazc1o2EXWsoVgNd+zOrKEHpehsQZ5rINs8Nsg7KA=; b=WnYt753pt4wjBErLNEtibaX8GHW20ZzEE1l/nEi1Wnlgk9DFF62RD2q+r6vUfjrniy 0/CGFCbpV0BD7uHmF0HFxedHOHAbLZoxecLruSkMXPvFsbSgoad+NW2nxxPR1lapjnQC E84euApttrJynUrgz7UbSrQ4eH2SMp3Hswqqk= 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=bMEazc1o2EXWsoVgNd+zOrKEHpehsQZ5rINs8Nsg7KA=; b=iaM7jDIr6VJP0Eop5510BmbIlEtsCloqLQIgCxeEiyoMDUc+H0Ucll21Ah4Jb/UXlh okJDWsmeNTS38K6iL6tjDtF+LlEuNWalDstfPBhfW7t0yFJbYETYpA3fNu7FwiCzK5sd k0//DW94zu2hV9q3tVIlfDNBZjM7X+gFFeKRr9QLOQ5Z9LKd0VqGTKK62SjyJYpRKV3H ZI7xAPfQuXXEc/yMxibydUdory810udf5cO9RMsqdsuG9UD8P5AvXKFYNLoHI8NbcEFw NqFiOYseTAHMUOh3PgwX3MryQUS689GL/WC6loECosXvRuxrenjO26y8fYsaTUn7Csr0 MlDQ== X-Gm-Message-State: APjAAAVAAh2w3A30uLYxLuj2Jflux8Fs8R6hFfz65+WLQQxFGLTxSpaY UaTI8TNMqoxtL+Uw5U4PUvOd4wKvemI= X-Google-Smtp-Source: APXvYqzYrteUqahEcVfJNiSJ19saCPqHwvc8m+WgQr2qz80192CahbHFc1G2rzMDFzM9PWRAF8q43w== X-Received: by 2002:a6b:7606:: with SMTP id g6mr19039788iom.288.1562027114785; Mon, 01 Jul 2019 17:25:14 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h19sm10539202iol.65.2019.07.01.17.25.14 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 17:25:14 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 1 Jul 2019 18:24:33 -0600 Message-Id: <20190702002455.996-5-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190702002455.996-1-sjg@chromium.org> References: <20190702002455.996-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH 04/26] binman: Add an FDT map 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" An FDT map is an entry which holds a full description of the image entries, in FDT format. It can be discovered using the magic string at its start. Tools can locate and read this entry to find out what entries are in the image and where each entry is located. Signed-off-by: Simon Glass --- tools/binman/README | 5 +- tools/binman/README.entries | 38 +++++++++++ tools/binman/etype/fdtmap.py | 109 +++++++++++++++++++++++++++++++ tools/binman/ftest.py | 54 +++++++++++++-- tools/binman/state.py | 2 +- tools/binman/test/115_fdtmap.dts | 13 ++++ 6 files changed, 213 insertions(+), 8 deletions(-) create mode 100644 tools/binman/etype/fdtmap.py create mode 100644 tools/binman/test/115_fdtmap.dts diff --git a/tools/binman/README b/tools/binman/README index f07de350f60..77f047bf6a3 100644 --- a/tools/binman/README +++ b/tools/binman/README @@ -638,6 +638,10 @@ the image definition, binman calculates the final values and writes these to the device tree. These can be used by U-Boot at run-time to find the location of each entry. +Alternatively, an FDT map entry can be used to add a special FDT containing +just the information about the image. This is preceeded by a magic string so can +be located anywhere in the image. + Compression ----------- @@ -814,7 +818,6 @@ Some ideas: - Support building an image for a board (-b) more completely, with a configurable build directory - Support putting the FDT in an image with a suitable magic number -- Support adding a pointer to the FDT map - Support listing files in images - Support logging of binman's operations, with different levels of verbosity diff --git a/tools/binman/README.entries b/tools/binman/README.entries index 3241befc7f4..7014d36f5ff 100644 --- a/tools/binman/README.entries +++ b/tools/binman/README.entries @@ -223,6 +223,44 @@ updating the EC on startup via software sync. +Entry: fdtmap: An entry which contains an FDT map +------------------------------------------------- + +Properties / Entry arguments: + None + +An FDT map is just a header followed by an FDT containing a list of all the +entries in the image. + +The header is the string _FDTMAP_ followed by 8 unused bytes. + +When used, this entry will be populated with an FDT map which reflects the +entries in the current image. Hierarchy is preserved, and all offsets and +sizes are included. + +Note that the -u option must be provided to ensure that binman updates the +FDT with the position of each entry. + +Example output for a simple image with U-Boot and an FDT map: + +/ { + size = <0x00000112>; + image-pos = <0x00000000>; + offset = <0x00000000>; + u-boot { + size = <0x00000004>; + image-pos = <0x00000000>; + offset = <0x00000000>; + }; + fdtmap { + size = <0x0000010e>; + image-pos = <0x00000004>; + offset = <0x00000004>; + }; +}; + + + Entry: files: Entry containing a set of files --------------------------------------------- diff --git a/tools/binman/etype/fdtmap.py b/tools/binman/etype/fdtmap.py new file mode 100644 index 00000000000..cdeb491ebdc --- /dev/null +++ b/tools/binman/etype/fdtmap.py @@ -0,0 +1,109 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2018 Google, Inc +# Written by Simon Glass + +"""# Entry-type module for a full map of the firmware image + +This handles putting an FDT into the image with just the information about the +image. +""" + +import libfdt + +from entry import Entry +from fdt import Fdt +import state +import tools + +FDTMAP_MAGIC = b'_FDTMAP_' + +class Entry_fdtmap(Entry): + """An entry which contains an FDT map + + Properties / Entry arguments: + None + + An FDT map is just a header followed by an FDT containing a list of all the + entries in the image. + + The header is the string _FDTMAP_ followed by 8 unused bytes. + + When used, this entry will be populated with an FDT map which reflects the + entries in the current image. Hierarchy is preserved, and all offsets and + sizes are included. + + Note that the -u option must be provided to ensure that binman updates the + FDT with the position of each entry. + + Example output for a simple image with U-Boot and an FDT map: + + / { + size = <0x00000112>; + image-pos = <0x00000000>; + offset = <0x00000000>; + u-boot { + size = <0x00000004>; + image-pos = <0x00000000>; + offset = <0x00000000>; + }; + fdtmap { + size = <0x0000010e>; + image-pos = <0x00000004>; + offset = <0x00000004>; + }; + }; + """ + def __init__(self, section, etype, node): + Entry.__init__(self, section, etype, node) + + def _GetFdtmap(self): + """Build an FDT map from the entries in the current image + + Returns: + FDT map binary data + """ + def _AddNode(node): + """Add a node to the FDT map""" + for pname, prop in node.props.items(): + fsw.property(pname, prop.bytes) + for subnode in node.subnodes: + with fsw.add_node(subnode.name): + _AddNode(subnode) + + # Get the FDT data into an Fdt object + data = state.GetFdtContents()[1] + infdt = Fdt.FromData(data) + infdt.Scan() + + # Find the node for the image containing the Fdt-map entry + path = self.section.GetPath() + node = infdt.GetNode(path) + if not node: + self.Raise("Internal error: Cannot locate node for path '%s'" % + path) + + # Build a new tree with all nodes and properties starting from that node + fsw = libfdt.FdtSw() + fsw.finish_reservemap() + with fsw.add_node(''): + _AddNode(node) + fdt = fsw.as_fdt() + + # Pack this new FDT and return its contents + fdt.pack() + outfdt = Fdt.FromData(fdt.as_bytearray()) + data = FDTMAP_MAGIC + tools.GetBytes(0, 8) + outfdt.GetContents() + return data + + def ObtainContents(self): + """Obtain a placeholder for the fdt-map contents""" + self.SetContents(self._GetFdtmap()) + return True + + def ProcessContents(self): + """Write an updated version of the FDT map to this entry + + This is necessary since new data may have been written back to it during + processing, e.g. the image-pos properties. + """ + self.SetContents(self._GetFdtmap()) diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 4c5fd920e10..9e61f785d92 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -464,16 +464,16 @@ class TestFunctional(unittest.TestCase): """ return struct.unpack('>L', dtb[4:8])[0] - def _GetPropTree(self, dtb, prop_names): + def _GetPropTree(self, dtb, prop_names, prefix='/binman/'): def AddNode(node, path): if node.name != '/': path += '/' + node.name + for prop in node.props.values(): + if prop.name in prop_names: + prop_path = path + ':' + prop.name + tree[prop_path[len(prefix):]] = fdt_util.fdt32_to_cpu( + prop.value) for subnode in node.subnodes: - for prop in subnode.props.values(): - if prop.name in prop_names: - prop_path = path + '/' + subnode.name + ':' + prop.name - tree[prop_path[len('/binman/'):]] = fdt_util.fdt32_to_cpu( - prop.value) AddNode(subnode, path) tree = {} @@ -2015,6 +2015,48 @@ class TestFunctional(unittest.TestCase): self.assertEqual(U_BOOT_DTB_DATA, cfile2.data) self.assertEqual(0x140, cfile2.cbfs_offset) + def testFdtmap(self): + """Test an FDT map can be inserted in the image""" + data = self._DoReadFileDtb('115_fdtmap.dts', use_real_dtb=True, + update_dtb=True)[0] + fdtmap_data = data[len(U_BOOT_DATA):] + magic = fdtmap_data[:8] + self.assertEqual('_FDTMAP_', magic) + self.assertEqual(tools.GetBytes(0, 8), fdtmap_data[8:16]) + + fdt_data = fdtmap_data[16:] + dtb = fdt.Fdt.FromData(fdt_data) + dtb.Scan() + props = self._GetPropTree(dtb, ['offset', 'size', 'image-pos'], + prefix='/') + self.assertEqual({ + 'image-pos': 0, + 'offset': 0, + 'u-boot:offset': 0, + 'u-boot:size': len(U_BOOT_DATA), + 'u-boot:image-pos': 0, + 'fdtmap:image-pos': 4, + 'fdtmap:offset': 4, + 'fdtmap:size': len(fdtmap_data), + 'size': len(data), + }, props) + + def testFdtmapNoMatch(self): + """Check handling of an FDT map when the section cannot be found""" + self._DoReadFileDtb('115_fdtmap.dts', use_real_dtb=True, + update_dtb=True) + + # Mangle the section name, which should cause a mismatch between the + # correct FDT path and the one expected by the section + image = control.images['image'] + image._section._node.path += '-suffix' + entries = image.GetEntries() + fdtmap = entries['fdtmap'] + with self.assertRaises(ValueError) as e: + fdtmap._GetFdtmap() + self.assertIn("Cannot locate node for path '/binman-suffix'", + str(e.exception)) + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/state.py b/tools/binman/state.py index af9678649cd..3ccd7855d47 100644 --- a/tools/binman/state.py +++ b/tools/binman/state.py @@ -59,7 +59,7 @@ def GetFdtPath(fname): """ return fdt_files[fname]._fname -def GetFdtContents(fname): +def GetFdtContents(fname='u-boot.dtb'): """Looks up the FDT pathname and contents This is used to obtain the Fdt pathname and contents when needed by an diff --git a/tools/binman/test/115_fdtmap.dts b/tools/binman/test/115_fdtmap.dts new file mode 100644 index 00000000000..2450c41f200 --- /dev/null +++ b/tools/binman/test/115_fdtmap.dts @@ -0,0 +1,13 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + u-boot { + }; + fdtmap { + }; + }; +}; From patchwork Tue Jul 2 00:24:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1125730 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="I0TUOLc6"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45d4v86K3gz9s4V for ; Tue, 2 Jul 2019 10:32:20 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 91456C21C93; Tue, 2 Jul 2019 00:28:40 +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 C7691C21E3B; Tue, 2 Jul 2019 00:25:33 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id CE8EFC21DCA; Tue, 2 Jul 2019 00:25:21 +0000 (UTC) Received: from mail-io1-f54.google.com (mail-io1-f54.google.com [209.85.166.54]) by lists.denx.de (Postfix) with ESMTPS id BCCE2C21DD9 for ; Tue, 2 Jul 2019 00:25:16 +0000 (UTC) Received: by mail-io1-f54.google.com with SMTP id m24so33071057ioo.2 for ; Mon, 01 Jul 2019 17:25:16 -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=NQdF6Vy0GyYZiQlqFoaKBbrLlcZPMbUcOcATAShbDu8=; b=I0TUOLc6UQLWhtUqStcFzymBCwTvkZaDGYoyD3ukCveNkyu6p6Y3NJZBKqbHW+ZjJx M9cloJHcN3Hhhq/8Fg1CMhmOM3Hr4O1i6QmwsXzCezYtGvvDwJ6DSFpgpcHy2VjGrwB3 33AJIMNFQlVZFjmNlDOqPF34vqR08xNfXVIHU= 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=NQdF6Vy0GyYZiQlqFoaKBbrLlcZPMbUcOcATAShbDu8=; b=MhhG5XzyW2L2vrh5COpCp7+3AR359hsWQSLBIDoC8XXsP7iGOm3yAYkGjmxu8fYcOE pnX2nvmOUcMqvO/JYew/EMaL0B6wC2Vg27f49Fb721LWeEaIbcncQ/OLwGJU7LWa1rgL 9pcnIxPf9VWud+xEj5Ma1xdO4zn2cxcozvlrtmLNLkqrv01/tZAOO2atyztzzpYTnUpr 6E8tZ7+9rO66xUFN5YfbRWwkk6gKWvtr9//zJDg+5cNbboVKO7RHJuSRfl3wkZetHZ/P y1rNXbapu/zf9/kgzqD4dGhVjSnTfnasV/eTgE6wAWdGXPOGdoSJNKUVvp5TRhHN6E6v hliw== X-Gm-Message-State: APjAAAWwRRKSosflkIVZsDVFOIxaS+WQtGxUww2/6J+RNO9f2U8iHZhf SRTIcy5pw35owVKMRW5n6eoP4aXphGU= X-Google-Smtp-Source: APXvYqxRnn47rQvYhkXzC0yTLxsTye02srB2za7rgE/ow/GjQ4Az4nqwVAg3+I5O6WzABftFweOZTg== X-Received: by 2002:a02:b10b:: with SMTP id r11mr30823397jah.140.1562027115342; Mon, 01 Jul 2019 17:25:15 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h19sm10539202iol.65.2019.07.01.17.25.14 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 17:25:15 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 1 Jul 2019 18:24:34 -0600 Message-Id: <20190702002455.996-6-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190702002455.996-1-sjg@chromium.org> References: <20190702002455.996-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH 05/26] binman: Add an image header 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" It is useful to be able to quickly locate the FDT map in the image. An easy way to do this is with a pointer at the start or end of the image. Add an 'image header' entry, which places a magic number followed by a pointer to the FDT map. This can be located at the start or end of the image, or at a chosen location. As part of this, update GetSiblingImagePos() to detect missing siblings. Signed-off-by: Simon Glass --- tools/binman/README | 5 +- tools/binman/README.entries | 19 +++++ tools/binman/entry.py | 11 +++ tools/binman/etype/image_header.py | 76 ++++++++++++++++++++ tools/binman/ftest.py | 50 +++++++++++++ tools/binman/test/116_fdtmap_hdr.dts | 17 +++++ tools/binman/test/117_fdtmap_hdr_start.dts | 19 +++++ tools/binman/test/118_fdtmap_hdr_pos.dts | 19 +++++ tools/binman/test/119_fdtmap_hdr_missing.dts | 16 +++++ tools/binman/test/120_hdr_no_location.dts | 16 +++++ 10 files changed, 246 insertions(+), 2 deletions(-) create mode 100644 tools/binman/etype/image_header.py create mode 100644 tools/binman/test/116_fdtmap_hdr.dts create mode 100644 tools/binman/test/117_fdtmap_hdr_start.dts create mode 100644 tools/binman/test/118_fdtmap_hdr_pos.dts create mode 100644 tools/binman/test/119_fdtmap_hdr_missing.dts create mode 100644 tools/binman/test/120_hdr_no_location.dts diff --git a/tools/binman/README b/tools/binman/README index 77f047bf6a3..61a7a20f232 100644 --- a/tools/binman/README +++ b/tools/binman/README @@ -640,7 +640,9 @@ of each entry. Alternatively, an FDT map entry can be used to add a special FDT containing just the information about the image. This is preceeded by a magic string so can -be located anywhere in the image. +be located anywhere in the image. An image header (typically at the start or end +of the image) can be used to point to the FDT map. See fdtmap and image-header +entries for more information. Compression @@ -817,7 +819,6 @@ Some ideas: - Add an option to decode an image into the constituent binaries - Support building an image for a board (-b) more completely, with a configurable build directory -- Support putting the FDT in an image with a suitable magic number - Support listing files in images - Support logging of binman's operations, with different levels of verbosity diff --git a/tools/binman/README.entries b/tools/binman/README.entries index 7014d36f5ff..598d8278a70 100644 --- a/tools/binman/README.entries +++ b/tools/binman/README.entries @@ -331,6 +331,25 @@ README.chromium for how to obtain the required keys and tools. +Entry: image-header: An entry which contains a pointer to the FDT map +--------------------------------------------------------------------- + +Properties / Entry arguments: + location: Location of header ("start" or "end" of image). This is + optional. If omitted then the entry must have an offset property. + +This adds an 8-byte entry to the start or end of the image, pointing to the +location of the FDT map. The format is a magic number followed by an offset +from the start or end of the image, in twos-compliment format. + +This entry must be in the top-level part of the image. + +NOTE: If the location is at the start/end, you will probably need to specify +sort-by-offset for the image, unless you actually put the image header +first/last in the entry list. + + + Entry: intel-cmc: Entry containing an Intel Chipset Micro Code (CMC) file ------------------------------------------------------------------------- diff --git a/tools/binman/entry.py b/tools/binman/entry.py index 7356c49c626..e1cd0d3a882 100644 --- a/tools/binman/entry.py +++ b/tools/binman/entry.py @@ -561,3 +561,14 @@ features to produce new behaviours. else False """ return name in self.section.GetEntries() + + def GetSiblingImagePos(self, name): + """Return the image position of the given sibling + + Returns: + Image position of sibling, or None if the sibling has no position, + or False if there is no such sibling + """ + if not self.HasSibling(name): + return False + return self.section.GetEntries()[name].image_pos diff --git a/tools/binman/etype/image_header.py b/tools/binman/etype/image_header.py new file mode 100644 index 00000000000..9bc84ec01d4 --- /dev/null +++ b/tools/binman/etype/image_header.py @@ -0,0 +1,76 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2018 Google, Inc +# Written by Simon Glass + +"""Entry-type module for an image header which points to the FDT map + +This creates an 8-byte entry with a magic number and the offset of the FDT map +(which is another entry in the image), relative to the start or end of the +image. +""" + +import struct + +from entry import Entry +import fdt_util + +IMAGE_HEADER_MAGIC = b'BinM' + +class Entry_image_header(Entry): + """An entry which contains a pointer to the FDT map + + Properties / Entry arguments: + location: Location of header ("start" or "end" of image). This is + optional. If omitted then the entry must have an offset property. + + This adds an 8-byte entry to the start or end of the image, pointing to the + location of the FDT map. The format is a magic number followed by an offset + from the start or end of the image, in twos-compliment format. + + This entry must be in the top-level part of the image. + + NOTE: If the location is at the start/end, you will probably need to specify + sort-by-offset for the image, unless you actually put the image header + first/last in the entry list. + """ + def __init__(self, section, etype, node): + Entry.__init__(self, section, etype, node) + self.location = fdt_util.GetString(self._node, 'location') + + def _GetHeader(self): + image_pos = self.GetSiblingImagePos('fdtmap') + if image_pos == False: + self.Raise("'image_header' section must have an 'fdtmap' sibling") + elif image_pos is None: + # This will be available when called from ProcessContents(), but not + # when called from ObtainContents() + offset = 0xffffffff + else: + image_size = self.section.GetImageSize() or 0 + base = (0 if self.location != 'end' else image_size) + offset = (image_pos - base) & 0xffffffff + data = IMAGE_HEADER_MAGIC + struct.pack('; + #size-cells = <1>; + + binman { + size = <0x400>; + u-boot { + }; + fdtmap { + }; + image-header { + location = "end"; + }; + }; +}; diff --git a/tools/binman/test/117_fdtmap_hdr_start.dts b/tools/binman/test/117_fdtmap_hdr_start.dts new file mode 100644 index 00000000000..17b6be00470 --- /dev/null +++ b/tools/binman/test/117_fdtmap_hdr_start.dts @@ -0,0 +1,19 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + size = <0x400>; + sort-by-offset; + u-boot { + offset = <0x100>; + }; + fdtmap { + }; + image-header { + location = "start"; + }; + }; +}; diff --git a/tools/binman/test/118_fdtmap_hdr_pos.dts b/tools/binman/test/118_fdtmap_hdr_pos.dts new file mode 100644 index 00000000000..fd803f57fba --- /dev/null +++ b/tools/binman/test/118_fdtmap_hdr_pos.dts @@ -0,0 +1,19 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + size = <0x400>; + sort-by-offset; + u-boot { + offset = <0x100>; + }; + fdtmap { + }; + image-header { + offset = <0x80>; + }; + }; +}; diff --git a/tools/binman/test/119_fdtmap_hdr_missing.dts b/tools/binman/test/119_fdtmap_hdr_missing.dts new file mode 100644 index 00000000000..41bb680f08f --- /dev/null +++ b/tools/binman/test/119_fdtmap_hdr_missing.dts @@ -0,0 +1,16 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + sort-by-offset; + u-boot { + }; + image-header { + offset = <0x80>; + location = "start"; + }; + }; +}; diff --git a/tools/binman/test/120_hdr_no_location.dts b/tools/binman/test/120_hdr_no_location.dts new file mode 100644 index 00000000000..585e21f456b --- /dev/null +++ b/tools/binman/test/120_hdr_no_location.dts @@ -0,0 +1,16 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + sort-by-offset; + u-boot { + }; + fdtmap { + }; + image-header { + }; + }; +}; From patchwork Tue Jul 2 00:24:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1125725 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="cQ10lTyH"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45d4pq6Ws8z9s4V for ; Tue, 2 Jul 2019 10:28:35 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 6CDEBC21DA1; Tue, 2 Jul 2019 00:26:51 +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 3A6ABC21DB5; Tue, 2 Jul 2019 00:25:29 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 571C3C21E15; Tue, 2 Jul 2019 00:25:21 +0000 (UTC) Received: from mail-io1-f65.google.com (mail-io1-f65.google.com [209.85.166.65]) by lists.denx.de (Postfix) with ESMTPS id 016ECC21E16 for ; Tue, 2 Jul 2019 00:25:17 +0000 (UTC) Received: by mail-io1-f65.google.com with SMTP id e3so32934621ioc.12 for ; Mon, 01 Jul 2019 17:25:16 -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=UM96OJPXWgPNuL+zT88B318W/CGD82E9q0/lb1btfao=; b=cQ10lTyHU6oey8x8Jgl0p4vxryE05tSMB46xibjzyeFS5Ind4gGUNyuzHgPtBPGdbS UkUNNvU/HmFvaNI2YY2aKzmGFNnmgwvXTywGCLTT8isJA9skeAtiF3gr5+89m9wHra1k SQdlmgsKDX+JWt4RRUuGY8hjNy0czSwg35/Wk= 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=UM96OJPXWgPNuL+zT88B318W/CGD82E9q0/lb1btfao=; b=K1Mk5ZYsdDinWfclPj5j/J1pZzgCHuPQU+B/f9WS7i6WUemS9Xt9BZt/N7xxkJ4Ivz 0KVkWosusJOQ6uCnqdqLjEy19LJHANY1ILnZs0D4DQVeU9a+sZmUInAQ90psa6FwDLNP YphrgUNX5kag2TkZP8dBD1OwYzsa1nMKro2OES85VpL4ak0OeekXPqyZ7XN5YYDWSOYF f9ITK2E79GI94BLvRg+d1euSh5kycKKr1oEnTj30mHSYmm9ZCLjOu3wcDs8XlbMXJCy5 t6N59nAymdzv47JjORqXozZTpe0qGPm/efRbptlTUQHNCljAi1GxGnHwUAWcGIhdlf2U uzuw== X-Gm-Message-State: APjAAAXX1OqiceAfm0y+EO/aNC0IMrSzADZM6qmpPuKO3+KGiLl360IE yl8fPoiIyt2ECxsZXgMTdE2doMTv2ag= X-Google-Smtp-Source: APXvYqwiiKyqsdKvHB+JzT9bygQYXpo+qZO14OZVIRM0S/+r02iUJOXVxpORsyzRMuzd7gnGb+8KEg== X-Received: by 2002:a5d:834f:: with SMTP id q15mr609273ior.59.1562027115868; Mon, 01 Jul 2019 17:25:15 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h19sm10539202iol.65.2019.07.01.17.25.15 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 17:25:15 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 1 Jul 2019 18:24:35 -0600 Message-Id: <20190702002455.996-7-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190702002455.996-1-sjg@chromium.org> References: <20190702002455.996-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH 06/26] binman: Allow cbfstool to be optional with tests 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" If cbfstool is available, it is useful to compare the output of binman's CBFS generation with the output from that tool. However this is not absolutely necessary for tests, and cbfstool is not widely available, so make it optional. This allows tests to run on travis, for example. Also update travis to install the lzma tool required for CBFS. Signed-off-by: Simon Glass --- .travis.yml | 1 + tools/binman/cbfs_util_test.py | 37 +++++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 941f032cd38..ae68a2d351c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,6 +32,7 @@ addons: - device-tree-compiler - lzop - liblz4-tool + - lzma-alone - libisl15 - clang-7 - srecord diff --git a/tools/binman/cbfs_util_test.py b/tools/binman/cbfs_util_test.py index a0eb68ffce4..e77f5c51c98 100755 --- a/tools/binman/cbfs_util_test.py +++ b/tools/binman/cbfs_util_test.py @@ -47,6 +47,12 @@ class TestCbfs(unittest.TestCase): # compressing files tools.PrepareOutputDir(None) + cls.have_cbfstool = True + try: + tools.Run('which', 'cbfstool') + except: + cls.have_cbfstool = False + @classmethod def tearDownClass(cls): """Remove the temporary input directory and its contents""" @@ -152,6 +158,19 @@ class TestCbfs(unittest.TestCase): self._check_dtb(cbfs) def _get_expected_cbfs(self, size, arch='x86', compress=None, base=None): + """Get the file created by cbfstool for a particular scenario + + Args: + size: Size of the CBFS in bytes + arch: Architecture of the CBFS, as a string + compress: Compression to use, e.g. cbfs_util.COMPRESS_LZMA + base: Base address of file, or None to put it anywhere + + Returns: + Resulting CBFS file, or None if cbfstool is not available + """ + if not self.have_cbfstool: + return None cbfs_fname = os.path.join(self._indir, 'test.cbfs') cbfs_util.cbfstool(cbfs_fname, 'create', '-m', arch, '-s', '%#x' % size) if base: @@ -178,6 +197,8 @@ class TestCbfs(unittest.TestCase): data: CBFS created by binman cbfstool_fname: CBFS created by cbfstool """ + if not self.have_cbfstool: + return expect = tools.ReadFile(cbfstool_fname) if expect != data: tools.WriteFile('/tmp/expect', expect) @@ -195,6 +216,8 @@ class TestCbfs(unittest.TestCase): def test_cbfstool_failure(self): """Test failure to run cbfstool""" + if not self.have_cbfstool: + self.skipTest('No cbfstool available') try: # In verbose mode this test fails since stderr is not captured. Fix # this by turning off verbosity. @@ -467,12 +490,6 @@ class TestCbfs(unittest.TestCase): cbw = CbfsWriter(size) cbw.add_file_stage('u-boot', tools.ReadFile(elf_fname)) - cbfs_fname = os.path.join(self._indir, 'test.cbfs') - cbfs_util.cbfstool(cbfs_fname, 'create', '-m', 'x86', '-s', - '%#x' % size) - cbfs_util.cbfstool(cbfs_fname, 'add-stage', '-n', 'u-boot', - '-f', elf_fname) - data = cbw.get_data() cbfs = self._check_hdr(data, size) load = 0xfef20000 @@ -487,7 +504,13 @@ class TestCbfs(unittest.TestCase): cfile.data_len) # Compare against what cbfstool creates - self._compare_expected_cbfs(data, cbfs_fname) + if self.have_cbfstool: + cbfs_fname = os.path.join(self._indir, 'test.cbfs') + cbfs_util.cbfstool(cbfs_fname, 'create', '-m', 'x86', '-s', + '%#x' % size) + cbfs_util.cbfstool(cbfs_fname, 'add-stage', '-n', 'u-boot', + '-f', elf_fname) + self._compare_expected_cbfs(data, cbfs_fname) def test_cbfs_raw_compress(self): """Test base handling of compressing raw files""" From patchwork Tue Jul 2 00:24:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1125722 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="Yk9K1dxm"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45d4lV4XzCz9s4V for ; Tue, 2 Jul 2019 10:25:42 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 600DDC21DFD; Tue, 2 Jul 2019 00:25:31 +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 343DCC21DE8; Tue, 2 Jul 2019 00:25:27 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D38E5C21C38; Tue, 2 Jul 2019 00:25:21 +0000 (UTC) Received: from mail-io1-f66.google.com (mail-io1-f66.google.com [209.85.166.66]) by lists.denx.de (Postfix) with ESMTPS id 1651DC21DD3 for ; Tue, 2 Jul 2019 00:25:18 +0000 (UTC) Received: by mail-io1-f66.google.com with SMTP id e5so33020152iok.4 for ; Mon, 01 Jul 2019 17:25:18 -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=jnq0kO8zJih75lGFlkCpQjpj4JqcjUGooobjo8hhBlY=; b=Yk9K1dxmZFptuKhjy1jBzXQceAElhpPwN0rjvsdsVx6mAFafF+r9oXBJqmNXlvHFdk GcgBm+WT/p5/UxXVFCH4/qIeLHdHNHLuiXNTqgMcZVoW0NtEP1OV8Ock0PkGZDzMyib9 iTqKQPqV7CdLpsqey5RrW9MEWBhAwQGay0vIc= 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=jnq0kO8zJih75lGFlkCpQjpj4JqcjUGooobjo8hhBlY=; b=rkjSrHEkIhzezDPTX2H8P6xc5NP5fGb4yH8ucoBUIPBTCZBsNHuEa4sLsvBNJ6txmm H7yhap4qw0F3rY3WmII/NNWaadq4R0AjiVIunT0RFATB66Tz8gRGwOCdmR3dsZ3scNxK bkDyS3IUoRQIz0Bj+7/7K2/suGFsPrCAkh4WK6NTND2YTFa2aewf/Np84AH6aQLm2UE1 1yu0GXVBKuRdKaPNoURN3WFkUunoayaP+DqPRK3zK9hfy0YBAesNZXaBZJeJjiu/svIX 1xmQEs5EBDT5sj7D1Szy3uUJN8mfk0DdGMbyM6odvEsowS5vQaPKfO7Zbgm1+lDR5OcV JWHA== X-Gm-Message-State: APjAAAUxp3BF5bThSjLg5Up/hjb4bx9jMpmiQ7Ap2O/9LVt3Yx0W2bm7 +qKpspN7UwbcfygYgKei3Rc4NwFkgsk= X-Google-Smtp-Source: APXvYqxpbt3YM0VFq997yrDXm5gs2yhEjAHJZ8pUpjlQ3iH0h3Gx7uWyVVgWiDCf0CuyWKOLRDvN3A== X-Received: by 2002:a5d:8759:: with SMTP id k25mr3504715iol.307.1562027116571; Mon, 01 Jul 2019 17:25:16 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h19sm10539202iol.65.2019.07.01.17.25.15 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 17:25:16 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 1 Jul 2019 18:24:36 -0600 Message-Id: <20190702002455.996-8-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190702002455.996-1-sjg@chromium.org> References: <20190702002455.996-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH 07/26] binman: Convert to use ArgumentParser 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" This class is the new way to handle arguments in Python. Convert binman over to use it. At the same time, introduce commands so that we can separate out the different parts of binman functionality. Signed-off-by: Simon Glass --- .travis.yml | 2 +- test/run | 5 ++- tools/binman/README | 6 +-- tools/binman/binman.py | 43 ++++++++++--------- tools/binman/cmdline.py | 90 +++++++++++++++++++++++---------------- tools/binman/control.py | 51 +++++++++++----------- tools/binman/ftest.py | 35 +++++++-------- tools/patman/test_util.py | 5 ++- 8 files changed, 128 insertions(+), 109 deletions(-) diff --git a/.travis.yml b/.travis.yml index ae68a2d351c..4592c00c9ce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -146,7 +146,7 @@ script: if [[ -n "${TEST_PY_TOOLS}" ]]; then PYTHONPATH="${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc/pylibfdt" PATH="${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc:${PATH}" - ./tools/binman/binman --toolpath ${UBOOT_TRAVIS_BUILD_DIR}/tools -t && + ./tools/binman/binman --toolpath ${UBOOT_TRAVIS_BUILD_DIR}/tools test && ./tools/patman/patman --test && ./tools/buildman/buildman -t && PYTHONPATH="${UBOOT_TRAVIS_BUILD_DIR}/scripts/dtc/pylibfdt" diff --git a/test/run b/test/run index b97647eba6f..fc7fe5c2bbc 100755 --- a/test/run +++ b/test/run @@ -40,7 +40,7 @@ export PYTHONPATH=${DTC_DIR}/pylibfdt export DTC=${DTC_DIR}/dtc TOOLS_DIR=build-sandbox_spl/tools -run_test "binman" ./tools/binman/binman -t --toolpath ${TOOLS_DIR} +run_test "binman" ./tools/binman/binman test --toolpath ${TOOLS_DIR} run_test "patman" ./tools/patman/patman --test [ "$1" == "quick" ] && skip=--skip-net-tests @@ -52,7 +52,8 @@ run_test "dtoc" ./tools/dtoc/dtoc -t # To enable Python test coverage on Debian-type distributions (e.g. Ubuntu): # $ sudo apt-get install python-pytest python-coverage export PATH=$PATH:${TOOLS_DIR} -run_test "binman code coverage" ./tools/binman/binman -T --toolpath ${TOOLS_DIR} +run_test "binman code coverage" ./tools/binman/binman test -T \ + --toolpath ${TOOLS_DIR} run_test "dtoc code coverage" ./tools/dtoc/dtoc -T run_test "fdt code coverage" ./tools/dtoc/test_fdt -T diff --git a/tools/binman/README b/tools/binman/README index 61a7a20f232..99b4e5f4504 100644 --- a/tools/binman/README +++ b/tools/binman/README @@ -187,7 +187,7 @@ First install prerequisites, e.g. Type: - binman -b + binman build -b to build an image for a board. The board name is the same name used when configuring U-Boot (e.g. for sandbox_defconfig the board name is 'sandbox'). @@ -195,7 +195,7 @@ Binman assumes that the input files for the build are in ../b/. Or you can specify this explicitly: - binman -I + binman build -I where is the build directory containing the output of the U-Boot build. @@ -483,7 +483,7 @@ Entry Documentation For details on the various entry types supported by binman and how to use them, see README.entries. This is generated from the source code using: - binman -E >tools/binman/README.entries + binman entry-docs >tools/binman/README.entries Hashing Entries diff --git a/tools/binman/binman.py b/tools/binman/binman.py index 613aad5c451..d225fe86024 100755 --- a/tools/binman/binman.py +++ b/tools/binman/binman.py @@ -20,14 +20,15 @@ import sys import traceback import unittest -# Bring in the patman and dtoc libraries +# Bring in the patman and dtoc libraries (but don't override the first path +# in PYTHONPATH) our_path = os.path.dirname(os.path.realpath(__file__)) for dirname in ['../patman', '../dtoc', '..', '../concurrencytest']: - sys.path.insert(0, os.path.join(our_path, dirname)) + sys.path.insert(2, os.path.join(our_path, dirname)) # Bring in the libfdt module -sys.path.insert(0, 'scripts/dtc/pylibfdt') -sys.path.insert(0, os.path.join(our_path, +sys.path.insert(2, 'scripts/dtc/pylibfdt') +sys.path.insert(2, os.path.join(our_path, '../../build-sandbox_spl/scripts/dtc/pylibfdt')) # When running under python-coverage on Ubuntu 16.04, the dist-packages @@ -158,37 +159,36 @@ def RunTestCoverage(): for item in glob_list if '_testing' not in item]) test_util.RunTestCoverage('tools/binman/binman.py', None, ['*test*', '*binman.py', 'tools/patman/*', 'tools/dtoc/*'], - options.build_dir, all_set) + args.build_dir, all_set) -def RunBinman(options, args): +def RunBinman(args): """Main entry point to binman once arguments are parsed Args: - options: Command-line options - args: Non-option arguments + args: Command line arguments Namespace object """ ret_code = 0 - if not options.debug: + if not args.debug: sys.tracebacklimit = 0 - if options.test: - ret_code = RunTests(options.debug, options.verbosity, options.processes, - options.test_preserve_dirs, args[1:], - options.toolpath) - - elif options.test_coverage: - RunTestCoverage() + if args.cmd == 'test': + if args.test_coverage: + RunTestCoverage() + else: + ret_code = RunTests(args.debug, args.verbosity, args.processes, + args.test_preserve_dirs, args.tests, + args.toolpath) - elif options.entry_docs: + elif args.cmd == 'entry-docs': control.WriteEntryDocs(GetEntryModules()) else: try: - ret_code = control.Binman(options, args) + ret_code = control.Binman(args) except Exception as e: print('binman: %s' % e) - if options.debug: + if args.debug: print() traceback.print_exc() ret_code = 1 @@ -196,6 +196,7 @@ def RunBinman(options, args): if __name__ == "__main__": - (options, args) = cmdline.ParseArgs(sys.argv) - ret_code = RunBinman(options, args) + args = cmdline.ParseArgs(sys.argv[1:]) + + ret_code = RunBinman(args) sys.exit(ret_code) diff --git a/tools/binman/cmdline.py b/tools/binman/cmdline.py index 91e007e4e03..99ca6564654 100644 --- a/tools/binman/cmdline.py +++ b/tools/binman/cmdline.py @@ -5,7 +5,7 @@ # Command-line parser for binman # -from optparse import OptionParser +from argparse import ArgumentParser def ParseArgs(argv): """Parse the binman command-line arguments @@ -17,56 +17,72 @@ def ParseArgs(argv): options provides access to the options (e.g. option.debug) args is a list of string arguments """ - parser = OptionParser() - parser.add_option('-a', '--entry-arg', type='string', action='append', + if '-H' in argv: + argv.insert(0, 'build') + + usage = '''binman [-B ] [--toolpath ] + +Create and manipulate images for a board from a set of binaries. Binman is +controlled by a description in the board device tree.''' + + base_parser = ArgumentParser(add_help=False) + base_parser.add_argument('-B', '--build-dir', type=str, default='b', + help='Directory containing the build output') + base_parser.add_argument('-D', '--debug', action='store_true', + help='Enabling debugging (provides a full traceback on error)') + base_parser.add_argument('-H', '--full-help', action='store_true', + default=False, help='Display the README file') + base_parser.add_argument('--toolpath', type=str, action='append', + help='Add a path to the directories containing tools') + base_parser.add_argument('-v', '--verbosity', default=1, + type=int, help='Control verbosity: 0=silent, 1=progress, 3=full, ' + '4=debug') + + parser = ArgumentParser(usage=usage, parents=[base_parser]) + subparsers = parser.add_subparsers(dest='cmd') + + build_parser = subparsers.add_parser('build', help='Build firmware image', + parents=[base_parser]) + build_parser.add_argument('-a', '--entry-arg', type=str, action='append', help='Set argument value arg=value') - parser.add_option('-b', '--board', type='string', + build_parser.add_argument('-b', '--board', type=str, help='Board name to build') - parser.add_option('-B', '--build-dir', type='string', default='b', - help='Directory containing the build output') - parser.add_option('-d', '--dt', type='string', + build_parser.add_argument('-d', '--dt', type=str, help='Configuration file (.dtb) to use') - parser.add_option('-D', '--debug', action='store_true', - help='Enabling debugging (provides a full traceback on error)') - parser.add_option('-E', '--entry-docs', action='store_true', - help='Write out entry documentation (see README.entries)') - parser.add_option('--fake-dtb', action='store_true', + build_parser.add_argument('--fake-dtb', action='store_true', help='Use fake device tree contents (for testing only)') - parser.add_option('-i', '--image', type='string', action='append', + build_parser.add_argument('-i', '--image', type=str, action='append', help='Image filename to build (if not specified, build all)') - parser.add_option('-I', '--indir', action='append', + build_parser.add_argument('-I', '--indir', action='append', help='Add a path to the list of directories to use for input files') - parser.add_option('-H', '--full-help', action='store_true', - default=False, help='Display the README file') - parser.add_option('-m', '--map', action='store_true', + build_parser.add_argument('-m', '--map', action='store_true', default=False, help='Output a map file for each image') - parser.add_option('-O', '--outdir', type='string', + build_parser.add_argument('-O', '--outdir', type=str, action='store', help='Path to directory to use for intermediate and ' 'output files') - parser.add_option('-p', '--preserve', action='store_true',\ + build_parser.add_argument('-p', '--preserve', action='store_true',\ help='Preserve temporary output directory even if option -O is not ' 'given') - parser.add_option('-P', '--processes', type=int, - help='set number of processes to use for running tests') - parser.add_option('-t', '--test', action='store_true', - default=False, help='run tests') - parser.add_option('-T', '--test-coverage', action='store_true', - default=False, help='run tests and check for 100% coverage') - parser.add_option('--toolpath', type='string', action='append', - help='Add a path to the directories containing tools') - parser.add_option('-u', '--update-fdt', action='store_true', + build_parser.add_argument('-u', '--update-fdt', action='store_true', default=False, help='Update the binman node with offset/size info') - parser.add_option('-v', '--verbosity', default=1, - type='int', help='Control verbosity: 0=silent, 1=progress, 3=full, ' - '4=debug') - parser.add_option('-X', '--test-preserve-dirs', action='store_true', + + entry_parser = subparsers.add_parser('entry-docs', + help='Write out entry documentation (see README.entries)') + + list_parser = subparsers.add_parser('list', help='List files in an image') + list_parser.add_argument('fname', type=str, help='Image file to list') + + test_parser = subparsers.add_parser('test', help='Run tests', + parents=[base_parser]) + test_parser.add_argument('-P', '--processes', type=int, + help='set number of processes to use for running tests') + test_parser.add_argument('-T', '--test-coverage', action='store_true', + default=False, help='run tests and check for 100%% coverage') + test_parser.add_argument('-X', '--test-preserve-dirs', action='store_true', help='Preserve and display test-created input directories; also ' 'preserve the output directory if a single test is run (pass test ' 'name at the end of the command line') - - parser.usage += """ - -Create images for a board from a set of binaries. It is controlled by a -description in the board device tree.""" + test_parser.add_argument('tests', nargs='*', + help='Test names to run (omit for all)') return parser.parse_args(argv) diff --git a/tools/binman/control.py b/tools/binman/control.py index 4a94afc8640..9022cf76e99 100644 --- a/tools/binman/control.py +++ b/tools/binman/control.py @@ -67,19 +67,18 @@ def WriteEntryDocs(modules, test_missing=None): from entry import Entry Entry.WriteDocs(modules, test_missing) -def Binman(options, args): +def Binman(args): """The main control code for binman This assumes that help and test options have already been dealt with. It deals with the core task of building images. Args: - options: Command line options object - args: Command line arguments (list of strings) + args: Command line arguments Namespace object """ global images - if options.full_help: + if args.full_help: pager = os.getenv('PAGER') if not pager: pager = 'more' @@ -89,17 +88,17 @@ def Binman(options, args): return 0 # Try to figure out which device tree contains our image description - if options.dt: - dtb_fname = options.dt + if args.dt: + dtb_fname = args.dt else: - board = options.board + board = args.board if not board: raise ValueError('Must provide a board to process (use -b )') - board_pathname = os.path.join(options.build_dir, board) + board_pathname = os.path.join(args.build_dir, board) dtb_fname = os.path.join(board_pathname, 'u-boot.dtb') - if not options.indir: - options.indir = ['.'] - options.indir.append(board_pathname) + if not args.indir: + args.indir = ['.'] + args.indir.append(board_pathname) try: # Import these here in case libfdt.py is not available, in which case @@ -107,15 +106,15 @@ def Binman(options, args): import fdt import fdt_util - tout.Init(options.verbosity) - elf.debug = options.debug - cbfs_util.VERBOSE = options.verbosity > 2 - state.use_fake_dtb = options.fake_dtb + tout.Init(args.verbosity) + elf.debug = args.debug + cbfs_util.VERBOSE = args.verbosity > 2 + state.use_fake_dtb = args.fake_dtb try: - tools.SetInputDirs(options.indir) - tools.PrepareOutputDir(options.outdir, options.preserve) - tools.SetToolPaths(options.toolpath) - state.SetEntryArgs(options.entry_arg) + tools.SetInputDirs(args.indir) + tools.PrepareOutputDir(args.outdir, args.preserve) + tools.SetToolPaths(args.toolpath) + state.SetEntryArgs(args.entry_arg) # Get the device tree ready by compiling it and copying the compiled # output into a file in our output directly. Then scan it for use @@ -132,16 +131,16 @@ def Binman(options, args): images = _ReadImageDesc(node) - if options.image: + if args.image: skip = [] new_images = OrderedDict() for name, image in images.items(): - if name in options.image: + if name in args.image: new_images[name] = image else: skip.append(name) images = new_images - if skip and options.verbosity >= 2: + if skip and args.verbosity >= 2: print('Skipping images: %s' % ', '.join(skip)) state.Prepare(images, dtb) @@ -155,7 +154,7 @@ def Binman(options, args): # entry offsets remain the same. for image in images.values(): image.ExpandEntries() - if options.update_fdt: + if args.update_fdt: image.AddMissingProperties() image.ProcessFdt(dtb) @@ -176,19 +175,19 @@ def Binman(options, args): image.CheckSize() image.CheckEntries() except Exception as e: - if options.map: + if args.map: fname = image.WriteMap() print("Wrote map file '%s' to show errors" % fname) raise image.SetImagePos() - if options.update_fdt: + if args.update_fdt: image.SetCalculatedProperties() for dtb_item in state.GetFdts(): dtb_item.Sync() image.ProcessEntryContents() image.WriteSymbols() image.BuildImage() - if options.map: + if args.map: image.WriteMap() # Write the updated FDTs to our output files diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 46540e8f5dd..f1a79baa905 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -207,7 +207,7 @@ class TestFunctional(unittest.TestCase): result.stdout + result.stderr)) return result - def _DoBinman(self, *args): + def _DoBinman(self, *argv): """Run binman using directly (in the same process) Args: @@ -215,16 +215,16 @@ class TestFunctional(unittest.TestCase): Returns: Return value (0 for success) """ - args = list(args) + argv = list(argv) if '-D' in sys.argv: - args = args + ['-D'] - (options, args) = cmdline.ParseArgs(args) - options.pager = 'binman-invalid-pager' - options.build_dir = self._indir + argv = argv + ['-D'] + args = cmdline.ParseArgs(argv) + args.pager = 'binman-invalid-pager' + args.build_dir = self._indir # For testing, you can force an increase in verbosity here - # options.verbosity = tout.DEBUG - return control.Binman(options, args) + # args.verbosity = tout.DEBUG + return control.Binman(args) def _DoTestFile(self, fname, debug=False, map=False, update_dtb=False, entry_args=None, images=None, use_real_dtb=False, @@ -242,7 +242,7 @@ class TestFunctional(unittest.TestCase): value: value of that arg images: List of image names to build """ - args = ['-p', '-I', self._indir, '-d', self.TestFile(fname)] + args = ['build', '-p', '-I', self._indir, '-d', self.TestFile(fname)] if debug: args.append('-D') if map: @@ -515,20 +515,20 @@ class TestFunctional(unittest.TestCase): """Test that we can run it with a specific board""" self._SetupDtb('005_simple.dts', 'sandbox/u-boot.dtb') TestFunctional._MakeInputFile('sandbox/u-boot.bin', U_BOOT_DATA) - result = self._DoBinman('-b', 'sandbox') + result = self._DoBinman('build', '-b', 'sandbox') self.assertEqual(0, result) def testNeedBoard(self): """Test that we get an error when no board ius supplied""" with self.assertRaises(ValueError) as e: - result = self._DoBinman() + result = self._DoBinman('build') self.assertIn("Must provide a board to process (use -b )", str(e.exception)) def testMissingDt(self): """Test that an invalid device-tree file generates an error""" with self.assertRaises(Exception) as e: - self._RunBinman('-d', 'missing_file') + self._RunBinman('build', '-d', 'missing_file') # We get one error from libfdt, and a different one from fdtget. self.AssertInList(["Couldn't open blob from 'missing_file'", 'No such file or directory'], str(e.exception)) @@ -540,26 +540,26 @@ class TestFunctional(unittest.TestCase): will come from the device-tree compiler (dtc). """ with self.assertRaises(Exception) as e: - self._RunBinman('-d', self.TestFile('001_invalid.dts')) + self._RunBinman('build', '-d', self.TestFile('001_invalid.dts')) self.assertIn("FATAL ERROR: Unable to parse input tree", str(e.exception)) def testMissingNode(self): """Test that a device tree without a 'binman' node generates an error""" with self.assertRaises(Exception) as e: - self._DoBinman('-d', self.TestFile('002_missing_node.dts')) + self._DoBinman('build', '-d', self.TestFile('002_missing_node.dts')) self.assertIn("does not have a 'binman' node", str(e.exception)) def testEmpty(self): """Test that an empty binman node works OK (i.e. does nothing)""" - result = self._RunBinman('-d', self.TestFile('003_empty.dts')) + result = self._RunBinman('build', '-d', self.TestFile('003_empty.dts')) self.assertEqual(0, len(result.stderr)) self.assertEqual(0, result.return_code) def testInvalidEntry(self): """Test that an invalid entry is flagged""" with self.assertRaises(Exception) as e: - result = self._RunBinman('-d', + result = self._RunBinman('build', '-d', self.TestFile('004_invalid_entry.dts')) self.assertIn("Unknown entry type 'not-a-valid-type' in node " "'/binman/not-a-valid-type'", str(e.exception)) @@ -1290,7 +1290,8 @@ class TestFunctional(unittest.TestCase): def testEntryArgsInvalidFormat(self): """Test that an invalid entry-argument format is detected""" - args = ['-d', self.TestFile('064_entry_args_required.dts'), '-ano-value'] + args = ['build', '-d', self.TestFile('064_entry_args_required.dts'), + '-ano-value'] with self.assertRaises(ValueError) as e: self._DoBinman(*args) self.assertIn("Invalid entry arguemnt 'no-value'", str(e.exception)) diff --git a/tools/patman/test_util.py b/tools/patman/test_util.py index ea36cd16339..40098159c08 100644 --- a/tools/patman/test_util.py +++ b/tools/patman/test_util.py @@ -46,9 +46,10 @@ def RunTestCoverage(prog, filter_fname, exclude_list, build_dir, required=None): glob_list = [] glob_list += exclude_list glob_list += ['*libfdt.py', '*site-packages*', '*dist-packages*'] + test_cmd = 'test' if 'binman.py' in prog else '-t' cmd = ('PYTHONPATH=$PYTHONPATH:%s/sandbox_spl/tools %s-coverage run ' - '--omit "%s" %s -P1 -t' % (build_dir, PYTHON, ','.join(glob_list), - prog)) + '--omit "%s" %s %s -P1' % (build_dir, PYTHON, ','.join(glob_list), + prog, test_cmd)) os.system(cmd) stdout = command.Output('%s-coverage' % PYTHON, 'report') lines = stdout.splitlines() From patchwork Tue Jul 2 00:24:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1125743 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="G4ifVQJd"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45d50S2t1Vz9s4V for ; Tue, 2 Jul 2019 10:36:56 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id E5C03C21C38; Tue, 2 Jul 2019 00:30:48 +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, 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 14AF1C21E0B; Tue, 2 Jul 2019 00:25:39 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 42785C21E2C; Tue, 2 Jul 2019 00:25:21 +0000 (UTC) Received: from mail-io1-f68.google.com (mail-io1-f68.google.com [209.85.166.68]) by lists.denx.de (Postfix) with ESMTPS id 451F3C21DCA for ; Tue, 2 Jul 2019 00:25:18 +0000 (UTC) Received: by mail-io1-f68.google.com with SMTP id k20so6655919ios.10 for ; Mon, 01 Jul 2019 17:25:18 -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=ZeGVNgoiGdoWQqDWdAPCuqsKPhFwwaL53/AoX3T09U0=; b=G4ifVQJdq0fHRAl4oWV4dxBeTOB75Q5TnILKByHeuT4kUYj9q8H6s0UBX99bkIFxtf nizjX+vaxh/qlEel19+saBzOQj0/mwlDvZTnafXWcdM4FB5cYE0ocEyrvpipLyY4+TWt CZh/uxO6/mCVSUGXFZWCKGct4NZQ1oTinGG3g= 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=ZeGVNgoiGdoWQqDWdAPCuqsKPhFwwaL53/AoX3T09U0=; b=jiJ5rTjflkyDKeTfejfFPbuOtpSiWrl3sLtitdz5l7mkDhIz+thStmpsR2ji3wYVJb FynNNu3bfEbCuo/Ovx4DvSuPtfWT80iIQah0K4U4WZzFImXXcAdhwHr40BXGnMIAUJR6 8Pf/1lPCefaN9V3F23onqzIj88yXYl6XwYYHZLnValXAh2FvdgRK+IMxpcqAs7YfwW0f xvuzS9b2VIiUBicExLF742JSMfuxIP54zs0nWAR/LsSn9xF85spX2DtndEzkYi/WXWca SgsYZgY21OnvWRy4EWyKtKbT6cgivdeyeMpHfPbEOHd44CGPL0Xcxk8Tw0REsLjWfMuD w8hw== X-Gm-Message-State: APjAAAX6tWIYKM5S4PYYBTeJFrPWklkmRxF6AFYmAplVyMFm+SR3avkC SkAoYJke2XrmsCGbUDY6ypZ4qDjT2Xc= X-Google-Smtp-Source: APXvYqwri4BkyrSTD1KSXLGaOAaWxblK3mqPfLnpcIetdwRyLmPYj6ZjDQg+MoovBtz6SJcJhagOfw== X-Received: by 2002:a6b:6f0e:: with SMTP id k14mr1238707ioc.257.1562027117091; Mon, 01 Jul 2019 17:25:17 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h19sm10539202iol.65.2019.07.01.17.25.16 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 17:25:16 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 1 Jul 2019 18:24:37 -0600 Message-Id: <20190702002455.996-9-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190702002455.996-1-sjg@chromium.org> References: <20190702002455.996-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH 08/26] binman: Move compression into the Entry base class 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" Compression is currently available only with blobs. However we want to report the compression algorithm and uncompressed size for all entries, so that other entry types can support compression. This will help with the forthcoming 'list' feature which lists entries in the image. Move the compression properties into the base class. Also fix up the docs which had the wrong property name. Signed-off-by: Simon Glass --- tools/binman/README | 11 ++++++++--- tools/binman/entry.py | 9 +++++++++ tools/binman/etype/blob.py | 19 ++++--------------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/tools/binman/README b/tools/binman/README index 99b4e5f4504..150d94c65b8 100644 --- a/tools/binman/README +++ b/tools/binman/README @@ -339,6 +339,10 @@ expand-size: limited by the size of the image/section and the position of the next entry. +compress: + Sets the compression algortihm to use (for blobs only). See the entry + documentation for details. + The attributes supported for images and sections are described below. Several are similar to those for entries. @@ -649,15 +653,16 @@ Compression ----------- Binman support compression for 'blob' entries (those of type 'blob' and -derivatives). To enable this for an entry, add a 'compression' property: +derivatives). To enable this for an entry, add a 'compress' property: blob { filename = "datafile"; - compression = "lz4"; + compress = "lz4"; }; The entry will then contain the compressed data, using the 'lz4' compression -algorithm. Currently this is the only one that is supported. +algorithm. Currently this is the only one that is supported. The uncompressed +size is written to the node in an 'uncomp-size' property, if -u is used. diff --git a/tools/binman/entry.py b/tools/binman/entry.py index e1cd0d3a882..8cccc2ed5f0 100644 --- a/tools/binman/entry.py +++ b/tools/binman/entry.py @@ -51,6 +51,8 @@ class Entry(object): offset: Offset of entry within the section, None if not known yet (in which case it will be calculated by Pack()) size: Entry size in bytes, None if not known + uncomp_size: Size of uncompressed data in bytes, if the entry is + compressed, else None contents_size: Size of contents in bytes, 0 by default align: Entry start offset alignment, or None align_size: Entry size alignment, or None @@ -58,6 +60,7 @@ class Entry(object): pad_before: Number of pad bytes before the contents, 0 if none pad_after: Number of pad bytes after the contents, 0 if none data: Contents of entry (string of bytes) + compress: Compression algoithm used (e.g. 'lz4'), 'none' if none """ def __init__(self, section, etype, node, read_node=True, name_prefix=''): self.section = section @@ -66,6 +69,7 @@ class Entry(object): self.name = node and (name_prefix + node.name) or 'none' self.offset = None self.size = None + self.uncomp_size = None self.data = None self.contents_size = 0 self.align = None @@ -76,6 +80,7 @@ class Entry(object): self.offset_unset = False self.image_pos = None self._expand_size = False + self.compress = 'none' if read_node: self.ReadNode() @@ -188,6 +193,8 @@ class Entry(object): for prop in ['offset', 'size', 'image-pos']: if not prop in self._node.props: state.AddZeroProp(self._node, prop) + if self.compress != 'none': + state.AddZeroProp(self._node, 'uncomp-size') err = state.CheckAddHashProp(self._node) if err: self.Raise(err) @@ -198,6 +205,8 @@ class Entry(object): state.SetInt(self._node, 'size', self.size) state.SetInt(self._node, 'image-pos', self.image_pos - self.section.GetRootSkipAtStart()) + if self.uncomp_size is not None: + state.SetInt(self._node, 'uncomp-size', self.uncomp_size) state.CheckSetHashValue(self._node, self.GetData) def ProcessFdt(self, fdt): diff --git a/tools/binman/etype/blob.py b/tools/binman/etype/blob.py index a91e7847009..ec94568ac0a 100644 --- a/tools/binman/etype/blob.py +++ b/tools/binman/etype/blob.py @@ -33,8 +33,7 @@ class Entry_blob(Entry): def __init__(self, section, etype, node): Entry.__init__(self, section, etype, node) self._filename = fdt_util.GetString(self._node, 'filename', self.etype) - self._compress = fdt_util.GetString(self._node, 'compress', 'none') - self._uncompressed_size = None + self.compress = fdt_util.GetString(self._node, 'compress', 'none') def ObtainContents(self): self._filename = self.GetDefaultFilename() @@ -50,21 +49,11 @@ class Entry_blob(Entry): # the data in chunks and avoid reading it all at once. For now # this seems like an unnecessary complication. indata = tools.ReadFile(self._pathname) - if self._compress != 'none': - self._uncompressed_size = len(indata) - data = tools.Compress(indata, self._compress) + if self.compress != 'none': + self.uncomp_size = len(indata) + data = tools.Compress(indata, self.compress) self.SetContents(data) return True def GetDefaultFilename(self): return self._filename - - def AddMissingProperties(self): - Entry.AddMissingProperties(self) - if self._compress != 'none': - state.AddZeroProp(self._node, 'uncomp-size') - - def SetCalculatedProperties(self): - Entry.SetCalculatedProperties(self) - if self._uncompressed_size is not None: - state.SetInt(self._node, 'uncomp-size', self._uncompressed_size) From patchwork Tue Jul 2 00:24:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1125731 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="lX3wjD5X"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45d4vK6S1Vz9s4V for ; Tue, 2 Jul 2019 10:32:29 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 82254C21C93; Tue, 2 Jul 2019 00:29:01 +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 AD879C21DE8; Tue, 2 Jul 2019 00:25:34 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 913C5C21E36; Tue, 2 Jul 2019 00:25:21 +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 CA1F2C21DF9 for ; Tue, 2 Jul 2019 00:25:18 +0000 (UTC) Received: by mail-io1-f67.google.com with SMTP id s7so32925810iob.11 for ; Mon, 01 Jul 2019 17:25:18 -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=YNDOtDtmKmeZQZEz6qieuDVbQ0ZZalID768LCa7jn64=; b=lX3wjD5XDlSHzeaMpaU1c0ZncSwNbb4avy4/fyyb/GOnHAXnz8vE2kkMpatqNn8KUp dPEGZMGHU9LDFbJY7VuWaNV+weGAsDQR1mErdGFhJ0E91mJAMp/NRwvH0/ZVootvSkv6 DH+G6Yug7ORJIFqfHSiKKo53jDGgGuGQBsu2Q= 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=YNDOtDtmKmeZQZEz6qieuDVbQ0ZZalID768LCa7jn64=; b=MQ0X5VTgEAQ9Nldj1ZOsX1HH3+rmfY9Gg5kbGm1fsL4peXrVsPOGmCWLRtUapGzzq/ q3cr/faYhw4uFlBNY4CHw7EbNdgiITEmFGvQtt24XNKg9Qpb4sfxiKaRVaPXloiwhW2E Wc04xO4tsRKMVp5N/5MiU4eQasf3jNmnKr82LTwyrpL/op+2CV3E4cLjHlHKe5jOg3o1 zwC/obC9R6tVHdux0qbVo4lAGlEYgJUPLlP6BKtZLhDsmZsAcxq5LPqBCyHTsWKxnQI3 8sZG1zBeSwUuK2XYD0pmXkdoIxh52wRQ4JNrs2WUmW1agHEc/UmkqfdLxtFyoycLpt1r I/Gw== X-Gm-Message-State: APjAAAVZ1cnmAjUTzbzN2LhQNbTBHNzfC0LHsCtMA0q6siPBVqI9jk0H Ni6xJvlnc01kbNiGv8qLAUcIRvqtVqc= X-Google-Smtp-Source: APXvYqy50gHkBrx4j4A8i/FA8E8ma0lM/kKfe7Az3DKHBuHJCDHmVxIwYTwcGIcoXAjFEaPLO2G0Xg== X-Received: by 2002:a02:c95a:: with SMTP id u26mr30648274jao.15.1562027117706; Mon, 01 Jul 2019 17:25:17 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h19sm10539202iol.65.2019.07.01.17.25.17 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 17:25:17 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 1 Jul 2019 18:24:38 -0600 Message-Id: <20190702002455.996-10-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190702002455.996-1-sjg@chromium.org> References: <20190702002455.996-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH 09/26] binman: Drop an unused arg in Entry.Lookup() 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 first argument is not used. Remove it. Signed-off-by: Simon Glass --- tools/binman/entry.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/binman/entry.py b/tools/binman/entry.py index 8cccc2ed5f0..00bb1d190a9 100644 --- a/tools/binman/entry.py +++ b/tools/binman/entry.py @@ -85,11 +85,10 @@ class Entry(object): self.ReadNode() @staticmethod - def Lookup(section, node_path, etype): + def Lookup(node_path, etype): """Look up the entry class for a node. Args: - section: Section object containing this node node_node: Path name of Node object containing information about the entry to create (used for errors) etype: Entry type to use @@ -140,7 +139,7 @@ class Entry(object): """ if not etype: etype = fdt_util.GetString(node, 'type', node.name) - obj = Entry.Lookup(section, node.path, etype) + obj = Entry.Lookup(node.path, etype) # Call its constructor to get the object we want. return obj(section, etype, node) @@ -514,7 +513,7 @@ features to produce new behaviours. modules.remove('_testing') missing = [] for name in modules: - module = Entry.Lookup(name, name, name) + module = Entry.Lookup(name, name) docs = getattr(module, '__doc__') if test_missing == name: docs = None From patchwork Tue Jul 2 00:24:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1125746 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="Nz0DnUwI"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45d51G6wvKz9s4V for ; Tue, 2 Jul 2019 10:37:38 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id A6332C21D65; Tue, 2 Jul 2019 00:29:41 +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, 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 56C95C21E73; Tue, 2 Jul 2019 00:25:36 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 8C811C21E47; Tue, 2 Jul 2019 00:25:21 +0000 (UTC) Received: from mail-io1-f68.google.com (mail-io1-f68.google.com [209.85.166.68]) by lists.denx.de (Postfix) with ESMTPS id 76161C21C27 for ; Tue, 2 Jul 2019 00:25:19 +0000 (UTC) Received: by mail-io1-f68.google.com with SMTP id i10so19193770iol.13 for ; Mon, 01 Jul 2019 17:25:19 -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=zA34B1tNlOkUm9xZhMdP8VwIMz5P88cRukHPiXiZFDc=; b=Nz0DnUwI8q3yssHjGgX+XYH0W766QJVTqmfVpDWr5spv36Epo0eNi9okfYXL6Nbxto gItER1Pyb5vHFb9WqvHQqf7xiovofavMNapOfZZ2AvSRjNcX2xcTh4AoOEuRcoQsEl4y zWRblRGrK2UyWIgwIHWJLSdivb3EjOJYTYz8Y= 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=zA34B1tNlOkUm9xZhMdP8VwIMz5P88cRukHPiXiZFDc=; b=KxMWv22zD1/j3sOm/peaPHzCrI7GH7arwcLJ6XOKZZdSkQIYhQd1/W0jaUcKJTI4T+ McadhurTq6SgJ2oT80NZWsIJW2pvuEUcsI+xGo7EOsaJ3llvJVKnNxnP5OQDOmsXtKlM PaCOWWL/LwDUzlwoGzkioF21owjOyMl51dZeCDJ9VJMDq8KYB818Xogh7nxDOVlWqL8O N7f3ER2QXd9sy5zzba+5DaljzGnI6jocAXWDvcuSiUGj3WL3smQYlmdQf//621P2sKSZ FbzvKolcdz2RmtZtVAqZiZV3mecZxyAhag3Afcb8ZIfxly7zYnrcMmwsWD2cYrE4+6Q5 FJIg== X-Gm-Message-State: APjAAAWF7XTJSAgChS4OkcFajMhy24KfeBcifs5AtcqXW4TSIVyjwt5i fiE6jK+4sef4uKC0+urH81yw0GjYPdA= X-Google-Smtp-Source: APXvYqzOahAwg1/y5GyjDJp6ghvlkIA9wco6Es4DwXCh09t+7b39RuAKpDModcmyxYVkDV/i8KBMZA== X-Received: by 2002:a6b:f80b:: with SMTP id o11mr16508179ioh.40.1562027118343; Mon, 01 Jul 2019 17:25:18 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h19sm10539202iol.65.2019.07.01.17.25.17 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 17:25:18 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 1 Jul 2019 18:24:39 -0600 Message-Id: <20190702002455.996-11-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190702002455.996-1-sjg@chromium.org> References: <20190702002455.996-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH 10/26] binman: Allow easy importing of entry modules 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" At present entry modules can only be accessed using Entry.Lookup() or Entry.Create(). Most of the time this is fine, but sometimes a module needs to provide constants or helper functions useful to other modules. It is easier in this case to use 'import'. Add an __init__ file to permit this. Signed-off-by: Simon Glass --- tools/binman/entry.py | 2 ++ tools/binman/etype/__init__.py | 0 tools/patman/test_util.py | 1 + 3 files changed, 3 insertions(+) create mode 100644 tools/binman/etype/__init__.py diff --git a/tools/binman/entry.py b/tools/binman/entry.py index 00bb1d190a9..a04e149d96c 100644 --- a/tools/binman/entry.py +++ b/tools/binman/entry.py @@ -513,6 +513,8 @@ features to produce new behaviours. modules.remove('_testing') missing = [] for name in modules: + if name.startswith('__'): + continue module = Entry.Lookup(name, name) docs = getattr(module, '__doc__') if test_missing == name: diff --git a/tools/binman/etype/__init__.py b/tools/binman/etype/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tools/patman/test_util.py b/tools/patman/test_util.py index 40098159c08..09f258c26b4 100644 --- a/tools/patman/test_util.py +++ b/tools/patman/test_util.py @@ -58,6 +58,7 @@ def RunTestCoverage(prog, filter_fname, exclude_list, build_dir, required=None): test_set = set([os.path.splitext(os.path.basename(line.split()[0]))[0] for line in lines if '/etype/' in line]) missing_list = required + missing_list.discard('__init__') missing_list.difference_update(test_set) if missing_list: print('Missing tests for %s' % (', '.join(missing_list))) From patchwork Tue Jul 2 00:24:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1125728 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="cqhZG6qu"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45d4rP2Fhbz9s4V for ; Tue, 2 Jul 2019 10:29:57 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id CA5AEC21DB6; Tue, 2 Jul 2019 00:27:37 +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 6A3A9C21E30; Tue, 2 Jul 2019 00:25:30 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B2FC7C21DAF; Tue, 2 Jul 2019 00:25:21 +0000 (UTC) Received: from mail-io1-f49.google.com (mail-io1-f49.google.com [209.85.166.49]) by lists.denx.de (Postfix) with ESMTPS id 33282C21DAF for ; Tue, 2 Jul 2019 00:25:20 +0000 (UTC) Received: by mail-io1-f49.google.com with SMTP id s7so32925901iob.11 for ; Mon, 01 Jul 2019 17:25:20 -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=Trb4uzjcPmX949OAQ+hFO2XlKWug4Q/hvikVJ5DwbtM=; b=cqhZG6quPxl6Qkf55Av4dbv6XdYBVzSR/5mm3EelRvhFM5ma/qiavZuxYwYyPzbjTU 95EqFoeFt5lFNqaGAN8TAc80fEfPUwZptsm1n9rjgzF7CA6Z9mecWfnzIkW8oSX1w7K9 +tswZZiHHgJ8WJxq/oBeiDkKu0EhNkkPr4doY= 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=Trb4uzjcPmX949OAQ+hFO2XlKWug4Q/hvikVJ5DwbtM=; b=Q5yffCkDPntp9lJvYFbREsh2A+NgtDaDS75wJzsxbu/lEagfVlUqGyh/+tm2rtPsO8 cP7wulM/zUv1zL25mI4KkQKPWIbtRIvIanpdi1sT4B65Wu+jiLT3bZ3DPXh0uZTYcb7N xufnX9V62kLPA0NwD08RiIM/60FG9oNSJjZxSftHC+Nfvo+P/yEDNK8IPUg6PoYHi6ky 9R8YkUNO/k9pbomA2IQn60jQpW//sLzvWXI4SNfXwfXjuNhE/vWDdHHIHtzbd2eUqhZE CYIJl7asEDnMg7H3zYOd65bfBvixLbUAxRifbewkPRTCE8zsNKI0ghYyWEIg/0kr8d88 5/wA== X-Gm-Message-State: APjAAAUO7GMIN4W2uYhxcNsJbjw0cTw5B7K//aD9AlXhNGiaBuamusme zLekvNQ9HCZfaxwkGik8EM7ATASW+qw= X-Google-Smtp-Source: APXvYqzLEV9M2Qya8KVr49dsRrWaQxzRgs3usOZVDEAcj0AfOOtWzAOmqnxLFThXONSGcij9TOvPSQ== X-Received: by 2002:a02:aa1d:: with SMTP id r29mr10077117jam.127.1562027118970; Mon, 01 Jul 2019 17:25:18 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h19sm10539202iol.65.2019.07.01.17.25.18 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 17:25:18 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 1 Jul 2019 18:24:40 -0600 Message-Id: <20190702002455.996-12-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190702002455.996-1-sjg@chromium.org> References: <20190702002455.996-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH 11/26] binman: Fix up ProcessUpdateContents error and comments 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" This function raises an exception with its arguments around the wrong way so the message is incorrect. Fix this as well as a few minor comment problems. Signed-off-by: Simon Glass --- tools/binman/entry.py | 8 ++++---- tools/binman/ftest.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/binman/entry.py b/tools/binman/entry.py index a04e149d96c..b19a3b026f2 100644 --- a/tools/binman/entry.py +++ b/tools/binman/entry.py @@ -237,25 +237,25 @@ class Entry(object): This sets both the data and content_size properties Args: - data: Data to set to the contents (string) + data: Data to set to the contents (bytes) """ self.data = data self.contents_size = len(self.data) def ProcessContentsUpdate(self, data): - """Update the contens of an entry, after the size is fixed + """Update the contents of an entry, after the size is fixed This checks that the new data is the same size as the old. Args: - data: Data to set to the contents (string) + data: Data to set to the contents (bytes) Raises: ValueError if the new data size is not the same as the old """ if len(data) != self.contents_size: self.Raise('Cannot update entry size from %d to %d' % - (len(data), self.contents_size)) + (self.contents_size, len(data))) self.SetContents(data) def ObtainContents(self): diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index f1a79baa905..8c9942982ba 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -1213,7 +1213,7 @@ class TestFunctional(unittest.TestCase): with self.assertRaises(ValueError) as e: self._DoReadFile('059_change_size.dts', True) self.assertIn("Node '/binman/_testing': Cannot update entry size from " - '2 to 1', str(e.exception)) + '1 to 2', str(e.exception)) def testUpdateFdt(self): """Test that we can update the device tree with offset/size info""" From patchwork Tue Jul 2 00:24:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1125738 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="noAPAmwz"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45d4x552cyz9s4V for ; Tue, 2 Jul 2019 10:34:01 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 44150C21DAF; Tue, 2 Jul 2019 00:33: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=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 7E024C21E85; Tue, 2 Jul 2019 00:25:40 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id C01F8C21E0B; Tue, 2 Jul 2019 00:25:21 +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 AE1C5C21DB6 for ; Tue, 2 Jul 2019 00:25:20 +0000 (UTC) Received: by mail-io1-f67.google.com with SMTP id k20so6656054ios.10 for ; Mon, 01 Jul 2019 17:25:20 -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=wBgBD0dqITbkphDF77Z7HXhyiaq484i/plJ7zt7+J1A=; b=noAPAmwz4QXHRRjujiGbyS+V0opQNh6IslwL/wJQ0Zvityc/UVbjH0QuMR93voz3Th eH+oD3IIPqhUK7sZyHJ3hCfrgN21OvbpRInMk1NVfmGXRzmF5DUXAdxjxf+KPiocuEbE QwmPN1F4QMAqoQIr9apGRt1pZPHM+Z/ncvGBw= 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=wBgBD0dqITbkphDF77Z7HXhyiaq484i/plJ7zt7+J1A=; b=uIfqD49QLms7o+Q8NPW1AS071aqDKkAk1Y9/yX44PmLkP8ixEmANV3rrU5jsIATe48 FSTIDR00TRg84uRlened5BsBiDAuV6YI5sOdCxGAZEq2wrunBqeos3t9KdS834v9TiVM yc5EidpVLp5t63USo+oJPDTK9ecs1WLEmSSemNoQkILCZ3XL7s+kw+5zDT9IdpH7hqZU LKhGPnrrO+3bFvkeQBLhEl246rle6ANc8q2+ia2w6jqYy0aK0B2WIUbW5bbgbt9RzBpf sqt8f24s3QjPWDBL01r/L++5vmuh9FqrYh8TcNX23BvZPak2bcEG7CHUQt04ysDlkpPl b+JA== X-Gm-Message-State: APjAAAX4vGwUwtc3D61b+EJuZy80i7YG89y3cR+a4bXiEGud/DbBzfTp Guo3eSEoNz6juKGi0mhLugEHwc5k0js= X-Google-Smtp-Source: APXvYqxcxoDCtUiwBMGXf+XaahIa002E6k+/TRJyd6vrS5iOXtq4H+bk6v4FxMtswr22E7pENh13DQ== X-Received: by 2002:a6b:6f06:: with SMTP id k6mr114255ioc.32.1562027119580; Mon, 01 Jul 2019 17:25:19 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h19sm10539202iol.65.2019.07.01.17.25.19 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 17:25:19 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 1 Jul 2019 18:24:41 -0600 Message-Id: <20190702002455.996-13-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190702002455.996-1-sjg@chromium.org> References: <20190702002455.996-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH 12/26] binman: Call ProcessUpdateContents() consistently 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" SetContents() should only be called to set the contents of an entry from within the ObtainContents() call, since it has no guard against increasing the size of the contents, thus triggering incorrect operation. Change all such calls to use ProcessUpdateContents() instead. Signed-off-by: Simon Glass --- tools/binman/etype/blob_dtb.py | 2 +- tools/binman/etype/fdtmap.py | 2 +- tools/binman/etype/fmap.py | 2 +- tools/binman/etype/image_header.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/binman/etype/blob_dtb.py b/tools/binman/etype/blob_dtb.py index cc5b4a3f760..d80c3d7e006 100644 --- a/tools/binman/etype/blob_dtb.py +++ b/tools/binman/etype/blob_dtb.py @@ -30,4 +30,4 @@ class Entry_blob_dtb(Entry_blob): def ProcessContents(self): """Re-read the DTB contents so that we get any calculated properties""" _, data = state.GetFdtContents(self._filename) - self.SetContents(data) + self.ProcessContentsUpdate(data) diff --git a/tools/binman/etype/fdtmap.py b/tools/binman/etype/fdtmap.py index cdeb491ebdc..ddac148b9ba 100644 --- a/tools/binman/etype/fdtmap.py +++ b/tools/binman/etype/fdtmap.py @@ -106,4 +106,4 @@ class Entry_fdtmap(Entry): This is necessary since new data may have been written back to it during processing, e.g. the image-pos properties. """ - self.SetContents(self._GetFdtmap()) + self.ProcessContentsUpdate(self._GetFdtmap()) diff --git a/tools/binman/etype/fmap.py b/tools/binman/etype/fmap.py index e6b5c5c74c0..45d6db18a31 100644 --- a/tools/binman/etype/fmap.py +++ b/tools/binman/etype/fmap.py @@ -62,4 +62,4 @@ class Entry_fmap(Entry): return True def ProcessContents(self): - self.SetContents(self._GetFmap()) + self.ProcessContentsUpdate(self._GetFmap()) diff --git a/tools/binman/etype/image_header.py b/tools/binman/etype/image_header.py index 9bc84ec01d4..d6de58ce4b7 100644 --- a/tools/binman/etype/image_header.py +++ b/tools/binman/etype/image_header.py @@ -73,4 +73,4 @@ class Entry_image_header(Entry): This is necessary since image_pos is not available when ObtainContents() is called, since by then the entries have not been packed in the image. """ - self.SetContents(self._GetHeader()) + self.ProcessContentsUpdate(self._GetHeader()) From patchwork Tue Jul 2 00:24:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1125729 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="NIrdKwNH"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45d4tb0Sf9z9s4Y for ; Tue, 2 Jul 2019 10:31:51 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id C13F7C21DB6; Tue, 2 Jul 2019 00:27:19 +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, 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 BCDEFC21E2F; Tue, 2 Jul 2019 00:25:29 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 86499C21DD7; Tue, 2 Jul 2019 00:25:21 +0000 (UTC) Received: from mail-io1-f68.google.com (mail-io1-f68.google.com [209.85.166.68]) by lists.denx.de (Postfix) with ESMTPS id 766EBC21C93 for ; Tue, 2 Jul 2019 00:25:21 +0000 (UTC) Received: by mail-io1-f68.google.com with SMTP id j6so33020104ioa.5 for ; Mon, 01 Jul 2019 17:25:21 -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=2Fi+HpT5KtGBtkoA6m9/PDccxg7Rys69BBZx5my66yc=; b=NIrdKwNH9F4iRKG9MpGsqW5qyNAEsPZ4En+5USMmk2A3TxrXMOBtX1nnHTX7U2BFAL aJcxgG9Inwhzwwf6+zHvDt0aR8MvSqvBbGLDNVOMSGzmCk65z5alx1xL2DB1XGMhGHlH LzXWqhBaaW2OJspZE4JsQ1EGL/ItgpnFX+wWY= 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=2Fi+HpT5KtGBtkoA6m9/PDccxg7Rys69BBZx5my66yc=; b=KPDvlN5QDnsAT8am+fGfs83X/3YQCZ+lry7cF2GdAODD734QWWe4QuAF/fvs5Axw7A KG1t1mk2JGhj5TH94As1dkywxWXJAOghsr2Dsd5E+Q4BamTQQGZWscgZZnheQt2amAVo q1NWmoezbuu/jgLkJoLqv2W1+dF4wkWiFsoNvgXylX9z462v+mNhjvbkBHXt5vsZPXyW 7YlzET5gpORDD8tw2yRb7OS+4CK2CsL5mPeQpeGlg1I9O/F1PBL8bJxhjQRwZUnAv8AJ j8rAYma9q/cW/EuiQ82j3qc6L9umm04NMMCWqJ1ARqNzggU5VqLaTkzies74IUmCR/xq lLAA== X-Gm-Message-State: APjAAAW4acsF3JYQ0LL48FWxpj55POfU9D0O8Eir8WrJnkIIH0kg26/M LlV/lfjVvVF2iMawjgNNKTfER1UaUNo= X-Google-Smtp-Source: APXvYqw339yNuqICTRhFJqjTqO8OHn10URIvtVbM6eXTC3LzJGzlXyarGxRXGQS6VgHbqfKpk3HXvQ== X-Received: by 2002:a5e:da47:: with SMTP id o7mr30233870iop.83.1562027120225; Mon, 01 Jul 2019 17:25:20 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h19sm10539202iol.65.2019.07.01.17.25.19 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 17:25:19 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 1 Jul 2019 18:24:42 -0600 Message-Id: <20190702002455.996-14-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190702002455.996-1-sjg@chromium.org> References: <20190702002455.996-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH 13/26] binman: Add a return value to ProcessContentsUpdate() 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" At present if this function tries to update the contents such that the size changes, it raises an error. We plan to add the ability to change the size of entries after packing is completed, since in some cases it is not possible to determine the size in advance. An example of this is with a compressed device tree, where the values of the device tree change in SetCalculatedProperties() or ProcessEntryContents(). While the device tree itself does not change size, since placeholders for any new properties have already bee added by AddMissingProperties(), we cannot predict the size of the device tree after compression. If a value changes from 0 to 0x1234 (say), then the compressed device tree may expand. As a first step towards supporting this, make ProcessContentsUpdate() return a value indicating whether the content size is OK. For now this is always True (since otherwise binman raises an error), but later patches will adjust this. Signed-off-by: Simon Glass --- tools/binman/bsection.py | 8 +++++++- tools/binman/entry.py | 22 +++++++++++++++++++-- tools/binman/etype/_testing.py | 5 +++-- tools/binman/etype/blob_dtb.py | 2 +- tools/binman/etype/fdtmap.py | 2 +- tools/binman/etype/fmap.py | 2 +- tools/binman/etype/image_header.py | 2 +- tools/binman/etype/section.py | 5 +++-- tools/binman/etype/u_boot_with_ucode_ptr.py | 6 +++--- tools/binman/image.py | 5 ++++- 10 files changed, 44 insertions(+), 15 deletions(-) diff --git a/tools/binman/bsection.py b/tools/binman/bsection.py index 3e3d369d5e4..f49a6e93bc7 100644 --- a/tools/binman/bsection.py +++ b/tools/binman/bsection.py @@ -317,9 +317,15 @@ class Section(object): """Call the ProcessContents() method for each entry This is intended to adjust the contents as needed by the entry type. + + Returns: + True if no entries needed to change their size """ + sizes_ok = True for entry in self._entries.values(): - entry.ProcessContents() + if not entry.ProcessContents(): + sizes_ok = False + return sizes_ok def WriteSymbols(self): """Write symbol values into binary files for access at run time""" diff --git a/tools/binman/entry.py b/tools/binman/entry.py index b19a3b026f2..7db1402b84f 100644 --- a/tools/binman/entry.py +++ b/tools/binman/entry.py @@ -245,7 +245,8 @@ class Entry(object): def ProcessContentsUpdate(self, data): """Update the contents of an entry, after the size is fixed - This checks that the new data is the same size as the old. + This checks that the new data is the same size as the old. If the size + has changed, this triggers a re-run of the packing algorithm. Args: data: Data to set to the contents (bytes) @@ -253,10 +254,12 @@ class Entry(object): Raises: ValueError if the new data size is not the same as the old """ + size_ok = True if len(data) != self.contents_size: self.Raise('Cannot update entry size from %d to %d' % (self.contents_size, len(data))) self.SetContents(data) + return size_ok def ObtainContents(self): """Figure out the contents of an entry. @@ -401,7 +404,22 @@ class Entry(object): self.image_pos = image_pos + self.offset def ProcessContents(self): - pass + """Do any post-packing updates of entry contents + + This function should call ProcessContentsUpdate() to update the entry + contents, if necessary, returning its return value here. + + Args: + data: Data to set to the contents (bytes) + + Returns: + True if the new data size is OK, False if expansion is needed + + Raises: + ValueError if the new data size is not the same as the old and + state.AllowEntryExpansion() is False + """ + return True def WriteSymbols(self, section): """Write symbol values into binary files for access at run time diff --git a/tools/binman/etype/_testing.py b/tools/binman/etype/_testing.py index ac62d2e2005..2204362281c 100644 --- a/tools/binman/etype/_testing.py +++ b/tools/binman/etype/_testing.py @@ -88,9 +88,10 @@ class Entry__testing(Entry): def ProcessContents(self): if self.bad_update_contents: - # Request to update the conents with something larger, to cause a + # Request to update the contents with something larger, to cause a # failure. - self.ProcessContentsUpdate('aa') + return self.ProcessContentsUpdate('aa') + return True def ProcessFdt(self, fdt): """Force reprocessing the first time""" diff --git a/tools/binman/etype/blob_dtb.py b/tools/binman/etype/blob_dtb.py index d80c3d7e006..09d5d727138 100644 --- a/tools/binman/etype/blob_dtb.py +++ b/tools/binman/etype/blob_dtb.py @@ -30,4 +30,4 @@ class Entry_blob_dtb(Entry_blob): def ProcessContents(self): """Re-read the DTB contents so that we get any calculated properties""" _, data = state.GetFdtContents(self._filename) - self.ProcessContentsUpdate(data) + return self.ProcessContentsUpdate(data) diff --git a/tools/binman/etype/fdtmap.py b/tools/binman/etype/fdtmap.py index ddac148b9ba..bfd7962be3a 100644 --- a/tools/binman/etype/fdtmap.py +++ b/tools/binman/etype/fdtmap.py @@ -106,4 +106,4 @@ class Entry_fdtmap(Entry): This is necessary since new data may have been written back to it during processing, e.g. the image-pos properties. """ - self.ProcessContentsUpdate(self._GetFdtmap()) + return self.ProcessContentsUpdate(self._GetFdtmap()) diff --git a/tools/binman/etype/fmap.py b/tools/binman/etype/fmap.py index 45d6db18a31..3a809486098 100644 --- a/tools/binman/etype/fmap.py +++ b/tools/binman/etype/fmap.py @@ -62,4 +62,4 @@ class Entry_fmap(Entry): return True def ProcessContents(self): - self.ProcessContentsUpdate(self._GetFmap()) + return self.ProcessContentsUpdate(self._GetFmap()) diff --git a/tools/binman/etype/image_header.py b/tools/binman/etype/image_header.py index d6de58ce4b7..b1c4f8a07e9 100644 --- a/tools/binman/etype/image_header.py +++ b/tools/binman/etype/image_header.py @@ -73,4 +73,4 @@ class Entry_image_header(Entry): This is necessary since image_pos is not available when ObtainContents() is called, since by then the entries have not been packed in the image. """ - self.ProcessContentsUpdate(self._GetHeader()) + return self.ProcessContentsUpdate(self._GetHeader()) diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py index 3681a484689..51eddcd995a 100644 --- a/tools/binman/etype/section.py +++ b/tools/binman/etype/section.py @@ -85,8 +85,9 @@ class Entry_section(Entry): self._section.SetCalculatedProperties() def ProcessContents(self): - self._section.ProcessEntryContents() - super(Entry_section, self).ProcessContents() + sizes_ok = self._section.ProcessEntryContents() + sizes_ok_base = super(Entry_section, self).ProcessContents() + return sizes_ok and sizes_ok_base def CheckOffset(self): self._section.CheckEntries() diff --git a/tools/binman/etype/u_boot_with_ucode_ptr.py b/tools/binman/etype/u_boot_with_ucode_ptr.py index da0e12417b5..4104bf8bf13 100644 --- a/tools/binman/etype/u_boot_with_ucode_ptr.py +++ b/tools/binman/etype/u_boot_with_ucode_ptr.py @@ -91,6 +91,6 @@ class Entry_u_boot_with_ucode_ptr(Entry_blob): # Write the microcode offset and size into the entry offset_and_size = struct.pack('<2L', offset, size) self.target_offset -= self.image_pos - self.ProcessContentsUpdate(self.data[:self.target_offset] + - offset_and_size + - self.data[self.target_offset + 8:]) + return self.ProcessContentsUpdate(self.data[:self.target_offset] + + offset_and_size + + self.data[self.target_offset + 8:]) diff --git a/tools/binman/image.py b/tools/binman/image.py index f237ae302df..c8bce394aa1 100644 --- a/tools/binman/image.py +++ b/tools/binman/image.py @@ -122,8 +122,11 @@ class Image: """Call the ProcessContents() method for each entry This is intended to adjust the contents as needed by the entry type. + + Returns: + True if the new data size is OK, False if expansion is needed """ - self._section.ProcessEntryContents() + return self._section.ProcessEntryContents() def WriteSymbols(self): """Write symbol values into binary files for access at run time""" From patchwork Tue Jul 2 00:24:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1125727 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="Tk2hccXZ"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45d4qq4qVqz9s4V for ; Tue, 2 Jul 2019 10:29:27 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 65CBBC21C38; Tue, 2 Jul 2019 00:28:25 +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 410CBC21E52; Tue, 2 Jul 2019 00:25:32 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 9FCA1C21D9A; Tue, 2 Jul 2019 00:25:22 +0000 (UTC) Received: from mail-io1-f66.google.com (mail-io1-f66.google.com [209.85.166.66]) by lists.denx.de (Postfix) with ESMTPS id 11440C21DED for ; Tue, 2 Jul 2019 00:25:22 +0000 (UTC) Received: by mail-io1-f66.google.com with SMTP id u13so33072597iop.0 for ; Mon, 01 Jul 2019 17:25:22 -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=APtrC//+udyVZOPX3BNrxIMDs63QQ4d8J2rf6ABAZZc=; b=Tk2hccXZY502veomYgWJogt7rFYykEpPfW8uDItE0dnYTWXRl81rWD4KhTw+SMpi1V DEnMVNg9rLvJhMw0mAiiRXqjnahdp6TkqZWopWbFjxt4xcK+gd4TNYWiDsVPoJgZNCpI xwrKTUIeZDMmdTkPtVPIvpcjRCXRjLNZUjpuw= 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=APtrC//+udyVZOPX3BNrxIMDs63QQ4d8J2rf6ABAZZc=; b=aB0reuNb22VyN6i2598bdQNF/hGik576UdpTi5XuiPbjy1deTnZzpg39Kn3dMhjzhv mHDx7rpEP7ia0q7BZYxZWp1IOpgHBXz9FDv/g/JJqs4SmUF/s10ePekm4BI8rmTYENTA hawf4942aEOBT18wDOv2t856P++RpZ60+YhTrEhxkW83WyptBkoWM6FHnMDBqo9Wyo7r Hx113lNDny9GQDltm0Ievm5YwNPDC/7X0x95jImM1mtJz90kFDFA2kPOOXCrdSfel0fN SJUoLeYIf4o2kyTKVEIpmuk38j/FyteTcA3E/dIN8qhC2Mm8kluKAog+ad3iRB+OGNxj qJKw== X-Gm-Message-State: APjAAAXdZsosZWegtcocUK5E6DvsXAyhL9ln/SWBD9wNyMAs27l13nwM tsDbD8ppJP4e6WIqYOuc/gacYRAtrvU= X-Google-Smtp-Source: APXvYqzYUZEqnQXgv5QLs7o7fODUSV8HEMMOFQ6xS6dEjPq91fjxJwiwQK9t+9xH4GdFsgyv4o6ziA== X-Received: by 2002:a05:6602:2252:: with SMTP id o18mr28021563ioo.63.1562027120920; Mon, 01 Jul 2019 17:25:20 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h19sm10539202iol.65.2019.07.01.17.25.20 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 17:25:20 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 1 Jul 2019 18:24:43 -0600 Message-Id: <20190702002455.996-15-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190702002455.996-1-sjg@chromium.org> References: <20190702002455.996-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH 14/26] binman: Add a control for post-pack entry expansion 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" We plan to support changing the size of entries after they have been packed. For now it will always be enabled. But to aid testing of both cases (in the event that we want to add a command-line flag, for example), add a setting to control it. Signed-off-by: Simon Glass --- tools/binman/state.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tools/binman/state.py b/tools/binman/state.py index 3ccd7855d47..382bda32219 100644 --- a/tools/binman/state.py +++ b/tools/binman/state.py @@ -31,6 +31,11 @@ fdt_subset = set() # The DTB which contains the full image information main_dtb = None +# Allow entries to expand after they have been packed. This is detected and +# forces a re-pack. If not allowed, any attempted expansion causes an error in +# Entry.ProcessContentsUpdate() +allow_entry_expansion = True + def GetFdt(fname): """Get the Fdt object for a particular device-tree filename @@ -250,3 +255,22 @@ def CheckSetHashValue(node, get_data_func): data = m.digest() for n in GetUpdateNodes(hash_node): n.SetData('value', data) + +def SetAllowEntryExpansion(allow): + """Set whether post-pack expansion of entries is allowed + + Args: + allow: True to allow expansion, False to raise an exception + """ + global allow_entry_expansion + + allow_entry_expansion = allow + +def AllowEntryExpansion(): + """Check whether post-pack expansion of entries is allowed + + Returns: + True if expansion should be allowed, False if an exception should be + raised + """ + return allow_entry_expansion From patchwork Tue Jul 2 00:24:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1125733 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="O6T5CEV+"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45d4vc0r9Tz9s4V for ; Tue, 2 Jul 2019 10:32:44 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id CEC75C21DA2; Tue, 2 Jul 2019 00:30:10 +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 83D41C21DA6; Tue, 2 Jul 2019 00:25:37 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id C721CC21DA1; Tue, 2 Jul 2019 00:25:23 +0000 (UTC) Received: from mail-io1-f43.google.com (mail-io1-f43.google.com [209.85.166.43]) by lists.denx.de (Postfix) with ESMTPS id 1511AC21E2B for ; Tue, 2 Jul 2019 00:25:23 +0000 (UTC) Received: by mail-io1-f43.google.com with SMTP id k8so33076022iot.1 for ; Mon, 01 Jul 2019 17:25:23 -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=Lbbhi6fu0aa4ES3Li0LvrwYpeT/xKy4nzDqbd3vaW2U=; b=O6T5CEV+o7IRKkcMvFEkGlsf3ifijp1z18Jm2mF2B5ZnhjwSUTbdJLQHpR+kTL83PU tWwZndegvkM+pR8qSi77jkdk/UKXBZM688oXA3+qjaI3JBbaxPRXG+3Y7EwP8F0bZSDd 6q0EAphIKda8JUKSQJ77CZx8jgcIjiUMKwXmo= 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=Lbbhi6fu0aa4ES3Li0LvrwYpeT/xKy4nzDqbd3vaW2U=; b=HSlA8aNnKG0iF4e21h/YOhzdGerMFaZjuEuqXuAnyIoNTGeHZVC2haRHUOrRO7Kavm m1WoX/X7x7ECNTTndKE0ApIz9o1TwS47obUsxG1s7LBkErh0H8Nw4NE3oJZAm8McKOUR pC5o4q7IDZn8BJvz9tHXdhAKOORHyQm6ecotN2+orzFxlGrAsYXf50t2QpBum5x6qnfu uoyLjfzvuWAPYqkpj8eGh8R13HpmtqktKvkTYrEY62HpWlKuzj9HdGAOEHKbO0uQIIEq AQQDzkan6JbddoMybo11UGet0uCnv5ce+4PQPlcOiTwefA0Al1UfDSHCOD+GUIZ5WQGd PHSw== X-Gm-Message-State: APjAAAXUggxqhja+ugLZvIypkB/qesZxvPYuGTebd6nsHvtj2RzJzGhg tO2rTgkmfMfQzCooFhQnJgmTstyG0w4= X-Google-Smtp-Source: APXvYqwBP6mP9a+C/uNfodTCf3ed6iW2378uv9E2uMg719XVEcsc3KRdXW+SGPwLN/Tah3lsZKoRSg== X-Received: by 2002:a05:6638:38a:: with SMTP id y10mr33476916jap.104.1562027121603; Mon, 01 Jul 2019 17:25:21 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h19sm10539202iol.65.2019.07.01.17.25.21 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 17:25:21 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 1 Jul 2019 18:24:44 -0600 Message-Id: <20190702002455.996-16-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190702002455.996-1-sjg@chromium.org> References: <20190702002455.996-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH 15/26] binman: Allow entries to expand after packing 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" Add support for detecting entries that change size after they have already been packed, and re-running packing when it happens. This removes the limitation that entry size cannot change after PackEntries() is called. Signed-off-by: Simon Glass --- tools/binman/README | 3 +- tools/binman/bsection.py | 11 ++++++ tools/binman/control.py | 39 ++++++++++++------- tools/binman/entry.py | 18 ++++++++- tools/binman/etype/_testing.py | 11 +++++- tools/binman/etype/section.py | 5 +++ tools/binman/etype/u_boot_with_ucode_ptr.py | 2 +- tools/binman/ftest.py | 33 ++++++++++++++-- tools/binman/image.py | 8 ++++ tools/binman/test/121_entry_expand.dts | 20 ++++++++++ tools/binman/test/122_entry_expand_twice.dts | 21 ++++++++++ .../binman/test/123_entry_expand_section.dts | 22 +++++++++++ 12 files changed, 168 insertions(+), 25 deletions(-) create mode 100644 tools/binman/test/121_entry_expand.dts create mode 100644 tools/binman/test/122_entry_expand_twice.dts create mode 100644 tools/binman/test/123_entry_expand_section.dts diff --git a/tools/binman/README b/tools/binman/README index 150d94c65b8..7e745a2d466 100644 --- a/tools/binman/README +++ b/tools/binman/README @@ -566,7 +566,8 @@ tree. This sets the correct 'offset' and 'size' vaues, for example. The default implementatoin does nothing. This can be overriden to adjust the contents of an entry in some way. For example, it would be possible to create an entry containing a hash of the contents of some other entries. At this -stage the offset and size of entries should not be adjusted. +stage the offset and size of entries should not be adjusted unless absolutely +necessary, since it requires a repack (going back to PackEntries()). 10. WriteSymbols() - write the value of symbols into the U-Boot SPL binary. See 'Access to binman entry offsets at run time' below for a description of diff --git a/tools/binman/bsection.py b/tools/binman/bsection.py index f49a6e93bc7..d368e3f6baa 100644 --- a/tools/binman/bsection.py +++ b/tools/binman/bsection.py @@ -45,6 +45,8 @@ class Section(object): _name_prefix: Prefix to add to the name of all entries within this section _entries: OrderedDict() of entries + _orig_offset: Original offset value read from node + _orig_size: Original size value read from node """ def __init__(self, name, parent_section, node, image, test=False): global entry @@ -76,6 +78,8 @@ class Section(object): """Read properties from the section node""" self._offset = fdt_util.GetInt(self._node, 'offset') self._size = fdt_util.GetInt(self._node, 'size') + self._orig_offset = self._offset + self._orig_size = self._size self._align_size = fdt_util.GetInt(self._node, 'align-size') if tools.NotPowerOfTwo(self._align_size): self._Raise("Alignment size %s must be a power of two" % @@ -257,6 +261,13 @@ class Section(object): for name, info in offset_dict.items(): self._SetEntryOffsetSize(name, *info) + def ResetForPack(self): + """Reset offset/size fields so that packing can be done again""" + self._offset = self._orig_offset + self._size = self._orig_size + for entry in self._entries.values(): + entry.ResetForPack() + def PackEntries(self): """Pack all entries into the section""" offset = self._skip_at_start diff --git a/tools/binman/control.py b/tools/binman/control.py index 9022cf76e99..d48e7ac0070 100644 --- a/tools/binman/control.py +++ b/tools/binman/control.py @@ -170,21 +170,30 @@ def Binman(args): # completed and written, but that does not seem important. image.GetEntryContents() image.GetEntryOffsets() - 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() - image.ProcessEntryContents() + passes = 2 + 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: diff --git a/tools/binman/entry.py b/tools/binman/entry.py index 7db1402b84f..a9a9d119e1d 100644 --- a/tools/binman/entry.py +++ b/tools/binman/entry.py @@ -61,6 +61,8 @@ class Entry(object): pad_after: Number of pad bytes after the contents, 0 if none data: Contents of entry (string of bytes) compress: Compression algoithm used (e.g. 'lz4'), 'none' if none + orig_offset: Original offset value read from node + orig_size: Original size value read from node """ def __init__(self, section, etype, node, read_node=True, name_prefix=''): self.section = section @@ -153,6 +155,7 @@ class Entry(object): self.Raise("Please use 'offset' instead of 'pos'") self.offset = fdt_util.GetInt(self._node, 'offset') self.size = fdt_util.GetInt(self._node, 'size') + self.orig_offset, self.orig_size = self.offset, self.size self.align = fdt_util.GetInt(self._node, 'align') if tools.NotPowerOfTwo(self.align): raise ValueError("Node '%s': Alignment %s must be a power of two" % @@ -255,9 +258,16 @@ class Entry(object): ValueError if the new data size is not the same as the old """ size_ok = True - if len(data) != self.contents_size: + new_size = len(data) + if state.AllowEntryExpansion(): + if new_size > self.contents_size: + print("Entry '%s' size change from %#x to %#x" % ( + self._node.path, self.contents_size, new_size)) + # self.data will indicate the new size needed + size_ok = False + elif new_size != self.contents_size: self.Raise('Cannot update entry size from %d to %d' % - (self.contents_size, len(data))) + (self.contents_size, new_size)) self.SetContents(data) return size_ok @@ -271,6 +281,10 @@ class Entry(object): # No contents by default: subclasses can implement this return True + def ResetForPack(self): + """Reset offset/size fields so that packing can be done again""" + self.offset, self.size = self.orig_offset, self.orig_size + def Pack(self, offset): """Figure out how to pack the entry into the section diff --git a/tools/binman/etype/_testing.py b/tools/binman/etype/_testing.py index 2204362281c..ae24fe8105a 100644 --- a/tools/binman/etype/_testing.py +++ b/tools/binman/etype/_testing.py @@ -50,6 +50,8 @@ class Entry__testing(Entry): 'bad-update-contents') self.return_contents_once = fdt_util.GetBool(self._node, 'return-contents-once') + self.bad_update_contents_twice = fdt_util.GetBool(self._node, + 'bad-update-contents-twice') # Set to True when the entry is ready to process the FDT. self.process_fdt_ready = False @@ -71,11 +73,12 @@ class Entry__testing(Entry): if self.force_bad_datatype: self.GetEntryArgsOrProps([EntryArg('test-bad-datatype-arg', bool)]) self.return_contents = True + self.contents = b'a' def ObtainContents(self): if self.return_unknown_contents or not self.return_contents: return False - self.data = b'a' + self.data = self.contents self.contents_size = len(self.data) if self.return_contents_once: self.return_contents = False @@ -90,7 +93,11 @@ class Entry__testing(Entry): if self.bad_update_contents: # Request to update the contents with something larger, to cause a # failure. - return self.ProcessContentsUpdate('aa') + if self.bad_update_contents_twice: + self.contents += b'a' + else: + self.contents = b'aa' + return self.ProcessContentsUpdate(self.contents) return True def ProcessFdt(self, fdt): diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py index 51eddcd995a..23bf22113d4 100644 --- a/tools/binman/etype/section.py +++ b/tools/binman/etype/section.py @@ -64,6 +64,11 @@ class Entry_section(Entry): self._section.GetEntryOffsets() return {} + def ResetForPack(self): + """Reset offset/size fields so that packing can be done again""" + self._section.ResetForPack() + Entry.ResetForPack(self) + def Pack(self, offset): """Pack all entries into the section""" self._section.PackEntries() diff --git a/tools/binman/etype/u_boot_with_ucode_ptr.py b/tools/binman/etype/u_boot_with_ucode_ptr.py index 4104bf8bf13..cb7dbc68dbb 100644 --- a/tools/binman/etype/u_boot_with_ucode_ptr.py +++ b/tools/binman/etype/u_boot_with_ucode_ptr.py @@ -49,7 +49,7 @@ class Entry_u_boot_with_ucode_ptr(Entry_blob): def ProcessContents(self): # If the image does not need microcode, there is nothing to do if not self.target_offset: - return + return True # Get the offset of the microcode ucode_entry = self.section.FindEntryType('u-boot-ucode') diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 8c9942982ba..0ff8b5e2de8 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -1210,10 +1210,14 @@ class TestFunctional(unittest.TestCase): def testBadChangeSize(self): """Test that trying to change the size of an entry fails""" - with self.assertRaises(ValueError) as e: - self._DoReadFile('059_change_size.dts', True) - self.assertIn("Node '/binman/_testing': Cannot update entry size from " - '1 to 2', str(e.exception)) + try: + state.SetAllowEntryExpansion(False) + with self.assertRaises(ValueError) as e: + self._DoReadFile('059_change_size.dts', True) + self.assertIn("Node '/binman/_testing': Cannot update entry size from 1 to 2", + str(e.exception)) + finally: + state.SetAllowEntryExpansion(True) def testUpdateFdt(self): """Test that we can update the device tree with offset/size info""" @@ -2108,6 +2112,27 @@ class TestFunctional(unittest.TestCase): self.assertIn("Invalid location 'None', expected 'start' or 'end'", str(e.exception)) + def testEntryExpand(self): + """Test expanding an entry after it is packed""" + data = self._DoReadFile('121_entry_expand.dts') + self.assertEqual('aa', data[:2]) + self.assertEqual(U_BOOT_DATA, data[2:2 + len(U_BOOT_DATA)]) + self.assertEqual('aa', data[-2:]) + + def testEntryExpandBad(self): + """Test expanding an entry after it is packed, twice""" + with self.assertRaises(ValueError) as e: + self._DoReadFile('122_entry_expand_twice.dts') + self.assertIn("Image '/binman': Entries expanded after packing", + str(e.exception)) + + def testEntryExpandSection(self): + """Test expanding an entry within a section after it is packed""" + data = self._DoReadFile('123_entry_expand_section.dts') + self.assertEqual('aa', data[:2]) + self.assertEqual(U_BOOT_DATA, data[2:2 + len(U_BOOT_DATA)]) + self.assertEqual('aa', data[-2:]) + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/image.py b/tools/binman/image.py index c8bce394aa1..6339d020e76 100644 --- a/tools/binman/image.py +++ b/tools/binman/image.py @@ -55,6 +55,10 @@ class Image: self._filename = filename self._section = bsection.Section('main-section', None, self._node, self) + def Raise(self, msg): + """Convenience function to raise an error referencing an image""" + raise ValueError("Image '%s': %s" % (self._node.path, msg)) + def GetFdtSet(self): """Get the set of device tree files used by this image""" return self._section.GetFdtSet() @@ -100,6 +104,10 @@ class Image: """ self._section.GetEntryOffsets() + def ResetForPack(self): + """Reset offset/size fields so that packing can be done again""" + self._section.ResetForPack() + def PackEntries(self): """Pack all entries into the image""" self._section.PackEntries() diff --git a/tools/binman/test/121_entry_expand.dts b/tools/binman/test/121_entry_expand.dts new file mode 100644 index 00000000000..ebb7816db90 --- /dev/null +++ b/tools/binman/test/121_entry_expand.dts @@ -0,0 +1,20 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + _testing { + bad-update-contents; + }; + + u-boot { + }; + + _testing2 { + type = "_testing"; + bad-update-contents; + }; + }; +}; diff --git a/tools/binman/test/122_entry_expand_twice.dts b/tools/binman/test/122_entry_expand_twice.dts new file mode 100644 index 00000000000..258cf859f4b --- /dev/null +++ b/tools/binman/test/122_entry_expand_twice.dts @@ -0,0 +1,21 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + _testing { + bad-update-contents; + bad-update-contents-twice; + }; + + u-boot { + }; + + _testing2 { + type = "_testing"; + bad-update-contents; + }; + }; +}; diff --git a/tools/binman/test/123_entry_expand_section.dts b/tools/binman/test/123_entry_expand_section.dts new file mode 100644 index 00000000000..046f7234348 --- /dev/null +++ b/tools/binman/test/123_entry_expand_section.dts @@ -0,0 +1,22 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + _testing { + bad-update-contents; + }; + + u-boot { + }; + + section { + _testing2 { + type = "_testing"; + bad-update-contents; + }; + }; + }; +}; From patchwork Tue Jul 2 00:24:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1125735 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="eO5fxVDF"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45d4w019VCz9s4V for ; Tue, 2 Jul 2019 10:33:03 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 9C7BBC21E35; Tue, 2 Jul 2019 00:29:15 +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, 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 38D26C21E62; Tue, 2 Jul 2019 00:25:35 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 39F46C21D65; Tue, 2 Jul 2019 00:25:23 +0000 (UTC) Received: from mail-io1-f68.google.com (mail-io1-f68.google.com [209.85.166.68]) by lists.denx.de (Postfix) with ESMTPS id 6CE56C21E2C for ; Tue, 2 Jul 2019 00:25:23 +0000 (UTC) Received: by mail-io1-f68.google.com with SMTP id s7so32926115iob.11 for ; Mon, 01 Jul 2019 17:25:23 -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=SEkdcSJRTswghzQQAbF4+yoOnBeU6uDLJxsM9lw1Ils=; b=eO5fxVDFbpobQCzD1iwQwfJuZT5312RVIXqChp1EPw6WiBxnFwyZNpecm2MNgV6Hoq ub5MUVH+WRRm2h74XBmycQPmTYnk60mResYu9APphehCtsAcqiWIxUra9uqfBXXEK9oT 8RDnUBto1HAn8YqnDAmJ7wV1OBkga392DtE/o= 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=SEkdcSJRTswghzQQAbF4+yoOnBeU6uDLJxsM9lw1Ils=; b=PGm061mEOSV04rmoZNUhJfvNQTWPL5v7WlZqGR5BYXNVTqgWNahoRmL48W5p0Kl4rW 5wNKXcl1jG1GQy0hKDx6Vh7b8hDz9Zxm7IVD6FucbuR/+dbLUIgqWrmweARZ8GwMbyu5 u3kFP7TjRKBLQ8HdDNpFR4nBTW4WgioHMwpw7d5NMuXKB2Yfy1XE1K7AWnpDCnkQUSP/ dVL3jTHs9LGFu+Qcpc5nUnqqW2hjfvbgtKn5qCjizzWVuMRfdO5HGZ+8qV3GEAHPccql PETpZlQQVwagVQudM/iO3pgL2QqzlxQW9WZg+jyBgGG7/5dKJyQu1SfL1X8alVLsuDe9 Xreg== X-Gm-Message-State: APjAAAVcByttXN6+Ep+7ZgiOsViy3VIdGPC1GZcgwJD2W4pIdVb4nbGo YMyJ9WZ1EsJ6/Ky9gkMB0GxKw/PiXTM= X-Google-Smtp-Source: APXvYqz2vRGcoKj3Xn3QLF28Llru2J7ot0zyTUod/XS/nbWD0tUygQkdokIijv7g0dE7URxOSGRxnA== X-Received: by 2002:a05:6602:218b:: with SMTP id b11mr1669913iob.264.1562027122209; Mon, 01 Jul 2019 17:25:22 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h19sm10539202iol.65.2019.07.01.17.25.21 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 17:25:21 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 1 Jul 2019 18:24:45 -0600 Message-Id: <20190702002455.996-17-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190702002455.996-1-sjg@chromium.org> References: <20190702002455.996-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH 16/26] binman: Allow device-tree entries to be compressed 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" At present the logic skips the blob class' handling of compression, so this is not supported with device tree entries. Fix this. Signed-off-by: Simon Glass --- tools/binman/etype/blob.py | 25 +++++++++++++++++-------- tools/binman/etype/blob_dtb.py | 8 ++++---- tools/binman/ftest.py | 18 ++++++++++++++++++ tools/binman/test/124_compress_dtb.dts | 14 ++++++++++++++ 4 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 tools/binman/test/124_compress_dtb.dts diff --git a/tools/binman/etype/blob.py b/tools/binman/etype/blob.py index ec94568ac0a..a4ff0efcebc 100644 --- a/tools/binman/etype/blob.py +++ b/tools/binman/etype/blob.py @@ -41,17 +41,26 @@ class Entry_blob(Entry): self.ReadBlobContents() return True - def ReadBlobContents(self): - # 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. - indata = tools.ReadFile(self._pathname) + def CompressData(self, indata): if self.compress != 'none': self.uncomp_size = len(indata) data = tools.Compress(indata, self.compress) + return data + + def ReadBlobContents(self): + """Read blob contents into memory + + This function compresses the data before storing if needed. + + 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. + """ + indata = tools.ReadFile(self._pathname) + data = self.CompressData(indata) self.SetContents(data) return True diff --git a/tools/binman/etype/blob_dtb.py b/tools/binman/etype/blob_dtb.py index 09d5d727138..88ed55d8865 100644 --- a/tools/binman/etype/blob_dtb.py +++ b/tools/binman/etype/blob_dtb.py @@ -23,11 +23,11 @@ class Entry_blob_dtb(Entry_blob): def ObtainContents(self): """Get the device-tree from the list held by the 'state' module""" self._filename = self.GetDefaultFilename() - self._pathname, data = state.GetFdtContents(self._filename) - self.SetContents(data) - return True + self._pathname, _ = state.GetFdtContents(self._filename) + return Entry_blob.ReadBlobContents(self) def ProcessContents(self): """Re-read the DTB contents so that we get any calculated properties""" - _, data = state.GetFdtContents(self._filename) + _, indata = state.GetFdtContents(self._filename) + data = self.CompressData(indata) return self.ProcessContentsUpdate(data) diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 0ff8b5e2de8..b1dc1643011 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -2133,6 +2133,24 @@ class TestFunctional(unittest.TestCase): self.assertEqual(U_BOOT_DATA, data[2:2 + len(U_BOOT_DATA)]) self.assertEqual('aa', data[-2:]) + def testCompressDtb(self): + """Test that compress of device-tree files is supported""" + data = self._DoReadFileDtb('124_compress_dtb.dts', use_real_dtb=True, + update_dtb=True)[0] + self.assertEqual(U_BOOT_DATA, data[:len(U_BOOT_DATA)]) + comp_data = data[len(U_BOOT_DATA):] + orig = self._decompress(comp_data) + dtb = fdt.Fdt.FromData(orig) + dtb.Scan() + props = self._GetPropTree(dtb, ['size', 'uncomp-size']) + expected = { + 'u-boot:size': len(U_BOOT_DATA), + 'u-boot-dtb:uncomp-size': len(orig), + 'u-boot-dtb:size': len(comp_data), + 'size': len(data), + } + self.assertEqual(expected, props) + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/test/124_compress_dtb.dts b/tools/binman/test/124_compress_dtb.dts new file mode 100644 index 00000000000..46bfd8b265f --- /dev/null +++ b/tools/binman/test/124_compress_dtb.dts @@ -0,0 +1,14 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + u-boot { + }; + u-boot-dtb { + compress = "lz4"; + }; + }; +}; From patchwork Tue Jul 2 00:24:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1125732 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="VDdYCRbw"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45d4vT5D0Pz9s4V for ; Tue, 2 Jul 2019 10:32:37 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 72499C21E0D; Tue, 2 Jul 2019 00:28: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 A20D8C21D65; Tue, 2 Jul 2019 00:25:31 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id C9438C21E26; Tue, 2 Jul 2019 00:25:24 +0000 (UTC) Received: from mail-io1-f65.google.com (mail-io1-f65.google.com [209.85.166.65]) by lists.denx.de (Postfix) with ESMTPS id 09FF9C21DB3 for ; Tue, 2 Jul 2019 00:25:24 +0000 (UTC) Received: by mail-io1-f65.google.com with SMTP id k20so6656319ios.10 for ; Mon, 01 Jul 2019 17:25:23 -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=Qo6E4cp2raKGLcEAMfv/6VtMFekTh9iFfHbUMPB7II8=; b=VDdYCRbwIx4VOGJzm/EtyjCRbsDg985vx78KQZn3BpRiVQqhMSu84ZSV5dtjjNzs8O fnu0FERXv8rS7KzoahsIaQ3YGyqWuvK0cbuO7YMIONeiY2otPuIFjQVIE0THae+iPUqV Z36kGB5QMvLa2xNimahDFqjQrk9+chLuOnYm8= 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=Qo6E4cp2raKGLcEAMfv/6VtMFekTh9iFfHbUMPB7II8=; b=EuyOWwNSW0o0uTJZ8LjKWX8nm3SSnhJIAPYsaPKk7sVb5xvf/ir1uDXM2/E1d0/jk+ 3UYLTLlLtfHYcMPcshf5RE0wFntjV/jHgh1VA4rodoIjZu26hoJUI155N4NWrJZgnBHQ wJRAqwRKRRQRv2dDaIK98DRmpbm/58shyj1guTHTp+QFJlhiHOlYpKs7xwLWwWHbQCEG p+0UzvhpsadBqH/QfHCLBfXN+BRoTVqbET4h1qUJufUhB7jPyH3ptmuaqtNSdr6q5j6G mkzh1psIAcP8Oi4LnMBEU3WkTSw6MeyN2mTklefYc57vdMUYQ65QRK2xbB3qmuo2fy2r vjIA== X-Gm-Message-State: APjAAAXP8yQzZwJSTxfdyw7d/ucVuml12grWKf2GuWFv/bPlWECa4ajT ilIeqlvmOYjr3+f5R9WO1bBTx26pVe8= X-Google-Smtp-Source: APXvYqxfLED7wAXbOC0bZT9j4iR5Nw3GLC8C4N/RD+qiPlD2BjTav6BR8921x1hi6S/EG6lofEue/g== X-Received: by 2002:a5d:9acf:: with SMTP id x15mr1053537ion.190.1562027122836; Mon, 01 Jul 2019 17:25:22 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h19sm10539202iol.65.2019.07.01.17.25.22 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 17:25:22 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 1 Jul 2019 18:24:46 -0600 Message-Id: <20190702002455.996-18-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190702002455.996-1-sjg@chromium.org> References: <20190702002455.996-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH 17/26] binman: Provide the actual data address for cbfs files 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" At present a file with no explicit CBFS offset is placed in the next available location but there is no way to find out where it ended up. Update and rename the get_data() function to provide this information. Signed-off-by: Simon Glass --- tools/binman/cbfs_util.py | 31 ++++++++++++++++++++----------- tools/binman/cbfs_util_test.py | 12 ++++++++++++ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/tools/binman/cbfs_util.py b/tools/binman/cbfs_util.py index 1cdbcb2339e..530629a5c96 100644 --- a/tools/binman/cbfs_util.py +++ b/tools/binman/cbfs_util.py @@ -185,7 +185,8 @@ class CbfsFile(object): """Class to represent a single CBFS file This is used to hold the information about a file, including its contents. - Use the get_data() method to obtain the raw output for writing to CBFS. + Use the get_data_and_offset() method to obtain the raw output for writing to + CBFS. Properties: name: Name of file @@ -319,12 +320,15 @@ class CbfsFile(object): raise ValueError('Unknown file type %#x\n' % self.ftype) return hdr_len - def get_data(self, offset=None, pad_byte=None): - """Obtain the contents of the file, in CBFS format + def get_data_and_offset(self, offset=None, pad_byte=None): + """Obtain the contents of the file, in CBFS format and the offset of + the data within the file Returns: - bytes representing the contents of this file, packed and aligned - for directly inserting into the final CBFS output + tuple: + bytes representing the contents of this file, packed and aligned + for directly inserting into the final CBFS output + offset to the file data from the start of the returned data. """ name = _pack_string(self.name) hdr_len = len(name) + FILE_HEADER_LEN @@ -368,8 +372,10 @@ class CbfsFile(object): (self.name, self.cbfs_offset, offset)) pad = tools.GetBytes(pad_byte, pad_len) hdr_len += pad_len - self.offset = len(content) + len(data) - hdr = struct.pack(FILE_HEADER_FORMAT, FILE_MAGIC, self.offset, + + # This is the offset of the start of the file's data, + size = len(content) + len(data) + hdr = struct.pack(FILE_HEADER_FORMAT, FILE_MAGIC, size, self.ftype, attr_pos, hdr_len) # Do a sanity check of the get_header_len() function, to ensure that it @@ -381,7 +387,7 @@ class CbfsFile(object): # happen. It probably indicates that get_header_len() is broken. raise ValueError("Internal error: CBFS file '%s': Expected headers of %#x bytes, got %#d" % (self.name, expected_len, actual_len)) - return hdr + name + attr + pad + content + data + return hdr + name + attr + pad + content + data, hdr_len class CbfsWriter(object): @@ -392,7 +398,7 @@ class CbfsWriter(object): cbw = CbfsWriter(size) cbw.add_file_raw('u-boot', tools.ReadFile('u-boot.bin')) ... - data = cbw.get_data() + data, cbfs_offset = cbw.get_data_and_offset() Attributes: _master_name: Name of the file containing the master header @@ -475,7 +481,7 @@ class CbfsWriter(object): todo = align_int_down(offset - upto, self._align) if todo: cbf = CbfsFile.empty(todo, self._erase_byte) - fd.write(cbf.get_data()) + fd.write(cbf.get_data_and_offset()[0]) self._skip_to(fd, offset) def _align_to(self, fd, align): @@ -579,8 +585,11 @@ class CbfsWriter(object): offset = cbf.calc_start_offset() if offset is not None: self._pad_to(fd, align_int_down(offset, self._align)) - fd.write(cbf.get_data(fd.tell(), self._erase_byte)) + pos = fd.tell() + data, data_offset = cbf.get_data_and_offset(pos, self._erase_byte) + fd.write(data) self._align_to(fd, self._align) + cbf.calced_cbfs_offset = pos + data_offset if not self._hdr_at_start: self._write_header(fd, add_fileheader=self._add_fileheader) diff --git a/tools/binman/cbfs_util_test.py b/tools/binman/cbfs_util_test.py index e77f5c51c98..894c0c383b1 100755 --- a/tools/binman/cbfs_util_test.py +++ b/tools/binman/cbfs_util_test.py @@ -595,6 +595,18 @@ class TestCbfs(unittest.TestCase): cbw.get_data() self.assertIn('No space for data before pad offset', str(e.exception)) + def test_cbfs_check_offset(self): + """Test that we can discover the offset of a file after writing it""" + size = 0xb0 + cbw = CbfsWriter(size) + cbw.add_file_raw('u-boot', U_BOOT_DATA) + cbw.add_file_raw('u-boot-dtb', U_BOOT_DTB_DATA) + data = cbw.get_data() + + cbfs = cbfs_util.CbfsReader(data) + self.assertEqual(0x38, cbfs.files['u-boot'].cbfs_offset) + self.assertEqual(0x78, cbfs.files['u-boot-dtb'].cbfs_offset) + if __name__ == '__main__': unittest.main() From patchwork Tue Jul 2 00:24:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1125723 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="froCsWgX"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45d4mG1Pxgz9s4V for ; Tue, 2 Jul 2019 10:26:22 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id D45ACC21DB3; Tue, 2 Jul 2019 00:26: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 EAC7CC21DD7; Tue, 2 Jul 2019 00:25:27 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id EE856C21D65; Tue, 2 Jul 2019 00:25:25 +0000 (UTC) Received: from mail-io1-f65.google.com (mail-io1-f65.google.com [209.85.166.65]) by lists.denx.de (Postfix) with ESMTPS id 9284FC21BE5 for ; Tue, 2 Jul 2019 00:25:24 +0000 (UTC) Received: by mail-io1-f65.google.com with SMTP id u13so33072831iop.0 for ; Mon, 01 Jul 2019 17:25:24 -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=+wlbsCTq3lKTpwdb5b0aKZYq06Akv+jsQicAQ2SmuMU=; b=froCsWgXkrYS8Y14yxRXKTpdLRlEmLkNKZA7STtT9e75wY3e/oZG0FSUBwGwfaC4M+ TKCSQDHSXEfBI14bb6QVVmEarY5Tj1+94tAxAGR034x/mLNGJ5tw0E8qeAcXqDfY0v90 nzR6v58QYLVBLPkIcQcfNMRwMJbOPEmesaR+U= 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=+wlbsCTq3lKTpwdb5b0aKZYq06Akv+jsQicAQ2SmuMU=; b=pW4lzrm8UdOZjr2wQ/pISGfuZJzLCsl/FW7rGbUomBAXOhuJkLUU5VlcvUtdxMXlNN XZSVTS47hn07QUbR2iF3WRrZbKYEE+TQXIZsdeeOpr/O4aPlL1TncjZzvBAZuarG33/7 U8lRG0qWV37p91wvWV5oh9s2hCnbBNszWUG5P1Fv18iV9b1ZuR+bgOxksvpzJ/F8aBuZ 3C7L6o27fhPLEO5Qe0qUbJ7zGAJ0GQ3z5KIscuJYuVu+vvghjS4UnFwIeYrlsad6nJ5u U2sW8swy0UdHtSmyS/5cHsOv+OxKchBEvuFRJ9ypd8uSEyRgkJAoQA593xfUMrOSAqpS 4Agg== X-Gm-Message-State: APjAAAXdaqyqgkc/7iwxOfFIKq3qMZ3EoPSc2X/547aRHooT9/cvWaXY Q58zy21E4M6aozQWfy68w3amF4SQWhA= X-Google-Smtp-Source: APXvYqyZvVRg2cK3JttMT0k3KLaMAbplTn9VRNEIssaYyDPoY1SQ7WOqFBpfV4tkIq/hxj2mgsuXQw== X-Received: by 2002:a5d:8ad0:: with SMTP id e16mr674373iot.262.1562027123477; Mon, 01 Jul 2019 17:25:23 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h19sm10539202iol.65.2019.07.01.17.25.22 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 17:25:23 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 1 Jul 2019 18:24:47 -0600 Message-Id: <20190702002455.996-19-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190702002455.996-1-sjg@chromium.org> References: <20190702002455.996-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH 18/26] binman: Use the cbfs memlen field only for uncompressed length 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 purpose of this badly named field is a bit ambiguous. Adjust the code to use it only to store the uncompressed length of a file, leaving it set to None if there is no compression used. This makes it easy to see if the value in this field is relevant / useful. Also set data_len for compressed fields, since it should be the length of the compressed data, not the uncompressed data. Signed-off-by: Simon Glass --- tools/binman/cbfs_util.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/binman/cbfs_util.py b/tools/binman/cbfs_util.py index 530629a5c96..4691be4aee2 100644 --- a/tools/binman/cbfs_util.py +++ b/tools/binman/cbfs_util.py @@ -197,7 +197,8 @@ class CbfsFile(object): data_len: Length of (possibly compressed) data in bytes ftype: File type (TYPE_...) compression: Compression type (COMPRESS_...) - memlen: Length of data in memory (typically the uncompressed length) + memlen: Length of data in memory, i.e. the uncompressed length, None if + no compression algortihm is selected load: Load address in memory if known, else None entry: Entry address in memory if known, else None. This is where execution starts after the file is loaded @@ -213,11 +214,11 @@ class CbfsFile(object): self.data = data self.ftype = ftype self.compress = compress - self.memlen = len(data) + self.memlen = None self.load = None self.entry = None self.base_address = None - self.data_len = 0 + self.data_len = len(data) self.erase_byte = None self.size = None @@ -349,9 +350,11 @@ class CbfsFile(object): data = tools.Compress(orig_data, 'lz4') elif self.compress == COMPRESS_LZMA: data = tools.Compress(orig_data, 'lzma') + self.memlen = len(orig_data) + self.data_len = len(data) attr = struct.pack(ATTR_COMPRESSION_FORMAT, FILE_ATTR_TAG_COMPRESSION, ATTR_COMPRESSION_LEN, - self.compress, len(orig_data)) + self.compress, self.memlen) elif self.ftype == TYPE_EMPTY: data = tools.GetBytes(self.erase_byte, self.size) else: From patchwork Tue Jul 2 00:24:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1125740 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="CXKJ23ZM"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45d4y66brqz9s4V for ; Tue, 2 Jul 2019 10:34:54 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 7FD95C21C2C; Tue, 2 Jul 2019 00:29:28 +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 C06FCC21E38; Tue, 2 Jul 2019 00:25:35 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 4FBB6C21DED; Tue, 2 Jul 2019 00:25:25 +0000 (UTC) Received: from mail-io1-f66.google.com (mail-io1-f66.google.com [209.85.166.66]) by lists.denx.de (Postfix) with ESMTPS id 54789C21DA6 for ; Tue, 2 Jul 2019 00:25:25 +0000 (UTC) Received: by mail-io1-f66.google.com with SMTP id h6so33077903ioh.3 for ; Mon, 01 Jul 2019 17:25:25 -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=9RmGFRksZzJ6WtwE6jG3PPq3pol/HTZYgnzfwIJcYes=; b=CXKJ23ZMwCnMRccbyw9KreP27SKFazekuAfPpsjmfdzWSi0BvJpkchFYAcbq+J9cdO HxXD4ZtNlcTE0O2fZaH6fBKgoRhxHtp1nBzNtGYo9qrJ247Ib5Tcr5gfdtOogAn6zhkO opqLN76VERyBca7Lv4mvXtdaeaMEyXa9YLXyA= 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=9RmGFRksZzJ6WtwE6jG3PPq3pol/HTZYgnzfwIJcYes=; b=MaTjbWF4OUc9aUAH5Ii3WYn5fMN2xWlID6fdcxy6UjXDTqmY4mQz6YzuZj0e6skldf PXygh6RWCJ/bMK2enqOAOLwlgluX3Xb6O9oIjbhjOhwc25Ri5W+ZWMxn15tgdKQmx7y/ iIraTwxEzxjtPmHEfbhITvuCK3cXK2w7x2y1guuhjob6MTVle//TmztHfBuqY8rYyD0m 7xysQfQ+AF7UquNvQP4snE0ME31A/HJWIBeowvk6l03+Kb3rnnW0qDY24m3QQbV2Tymz ryoUJnPZ+7FwfMuvZtEYAvX+Xb19cTIjSU5Gotv3jMhRd4NoXOCrnU0T9+XE2ZZGtq01 nyMw== X-Gm-Message-State: APjAAAXPwCsuFm0L9+E0knZyKJ8IZbxyJ2Is/4WI+tHQ9Cgs1U5Jofj7 rSDbrvCXSuFUbA+XRgwuZMBJw9vYob0= X-Google-Smtp-Source: APXvYqwhK1Ab7tB11I32o4QDbaqmDZp3oHgcxppS+4prxKuk7aRPIVtz8TK2bKYNKn+CeatRDKVgIA== X-Received: by 2002:a02:b883:: with SMTP id p3mr17991331jam.79.1562027124124; Mon, 01 Jul 2019 17:25:24 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h19sm10539202iol.65.2019.07.01.17.25.23 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 17:25:23 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 1 Jul 2019 18:24:48 -0600 Message-Id: <20190702002455.996-20-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190702002455.996-1-sjg@chromium.org> References: <20190702002455.996-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH 19/26] binman: Add a comment about CBFS test structure 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" Most of the CBFS functionality is tested by cbfs_util rather than the binman functional tests. Add a comment to that effect. Signed-off-by: Simon Glass --- tools/binman/ftest.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index b1dc1643011..bee4feb1c3a 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -2003,7 +2003,11 @@ class TestFunctional(unittest.TestCase): str(e.exception)) def testCbfsOffset(self): - """Test a CBFS with files at particular offsets""" + """Test a CBFS with files at particular offsets + + Like all CFBS tests, this is just checking the logic that calls + cbfs_util. See cbfs_util_test for fully tests (e.g. test_cbfs_offset()). + """ data = self._DoReadFile('114_cbfs_offset.dts') size = 0x200 From patchwork Tue Jul 2 00:24:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1125749 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="jXtF9S/i"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45d52f6xtgz9s4V for ; Tue, 2 Jul 2019 10:38:50 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 96423C21E1D; Tue, 2 Jul 2019 00:33:33 +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, 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 273DBC21E9F; Tue, 2 Jul 2019 00:25:42 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id F0A8FC21E9F; Tue, 2 Jul 2019 00:25:26 +0000 (UTC) Received: from mail-io1-f68.google.com (mail-io1-f68.google.com [209.85.166.68]) by lists.denx.de (Postfix) with ESMTPS id 1A06CC21C38 for ; Tue, 2 Jul 2019 00:25:26 +0000 (UTC) Received: by mail-io1-f68.google.com with SMTP id j6so33020417ioa.5 for ; Mon, 01 Jul 2019 17:25:26 -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=lywgHDP9Em7U4L25csb71ehddxVU8Ou39SKF6NvXB+I=; b=jXtF9S/isG6U0LABeJO5s033DyfyvoS/X/ddW6U5txMJXIju0n6f7B+aSNhDsaK/eG YJVoAXWA/qucSP/puHhbpgiv4YQlOkDMDWAfWXZfkIYno+2+1asGoDH3g0UMZY0Q+1lP 8io44hOmG80iMy8tleURSAPcqlvp5amGPwH+4= 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=lywgHDP9Em7U4L25csb71ehddxVU8Ou39SKF6NvXB+I=; b=rOI+BK4CZ1TA81JbuKM+Y8cKpRanDJQJAULVnxUFlqpJ1benJzlAnJMKvo16KMDLbB 82L+IisQelNdXm9udAprhKpyN7VXEemtagOMgqnw85SCBwhdq1JQhc731KFjy5Ndx4o+ nVxObiD23HJe6fBiZcfNqMLymKyeqvBwFtaFkVwQjnB+mubNA3dqvWt9yIZj6FI34A61 l6tb9de8OEI1h7ixZ55H6jaYFe8MwTaYbFGCqXBLojp2Q6Xbdg7E83s/O7i/VSH2MEfZ 4nRMFqHC2Z6NMaTScFIQKRx6tO3HGcq6eXEpY76ET5JzSh2gmas696CPqJSxJFbpsAxv HQEg== X-Gm-Message-State: APjAAAV4qFQHNUO6vvZo5y/yLSQDVuVjaXVoojbiydFAQjcoSdyzrCdQ NO/kzSCXPHSMZXowMOMQgi7z9QbMl9M= X-Google-Smtp-Source: APXvYqyx4b9jFvTbTfX2ccBcU7kSmEnsFD3KOrRYqkkwiVgJxQF2XC5k20TgjioxdW1mErsNMXMtww== X-Received: by 2002:a6b:b9c2:: with SMTP id j185mr29002276iof.148.1562027124864; Mon, 01 Jul 2019 17:25:24 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h19sm10539202iol.65.2019.07.01.17.25.24 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 17:25:24 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 1 Jul 2019 18:24:49 -0600 Message-Id: <20190702002455.996-21-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190702002455.996-1-sjg@chromium.org> References: <20190702002455.996-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH 20/26] binman: Support FDT update for CBFS 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" It is useful to add the CBFS file information (offset, size, etc.) into the FDT so that the layout is complete. Add support for this. Signed-off-by: Simon Glass --- tools/binman/etype/cbfs.py | 49 +++++++++++++++++++++++++-- tools/binman/ftest.py | 24 +++++++++++++ tools/binman/test/125_cbfs_update.dts | 21 ++++++++++++ 3 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 tools/binman/test/125_cbfs_update.dts diff --git a/tools/binman/etype/cbfs.py b/tools/binman/etype/cbfs.py index 49baa6a4f63..a46bb98a033 100644 --- a/tools/binman/etype/cbfs.py +++ b/tools/binman/etype/cbfs.py @@ -11,6 +11,7 @@ import cbfs_util from cbfs_util import CbfsWriter from entry import Entry import fdt_util +import state class Entry_cbfs(Entry): """Entry containing a Coreboot Filesystem (CBFS) @@ -181,11 +182,17 @@ class Entry_cbfs(Entry): if not entry.ObtainContents(): return False data = entry.GetData() + cfile = None if entry._type == 'raw': - cbfs.add_file_raw(entry._cbfs_name, data, entry._cbfs_offset, - entry._cbfs_compress) + cfile = cbfs.add_file_raw(entry._cbfs_name, data, + entry._cbfs_offset, + entry._cbfs_compress) elif entry._type == 'stage': - cbfs.add_file_stage(entry._cbfs_name, data, entry._cbfs_offset) + cfile = cbfs.add_file_stage(entry._cbfs_name, data, + entry._cbfs_offset) + if cfile: + entry._cbfs_file = cfile + entry.size = cfile.data_len data = cbfs.get_data() self.SetContents(data) return True @@ -203,3 +210,39 @@ class Entry_cbfs(Entry): self.Raise("Invalid compression in '%s': '%s'" % (node.name, compress)) self._cbfs_entries[entry._cbfs_name] = entry + + def SetImagePos(self, image_pos): + """Override this function to set all the entry properties from CBFS + + We can only do this once image_pos is known + + Args: + image_pos: Position of this entry in the image + """ + Entry.SetImagePos(self, image_pos) + + # Now update the entries with info from the CBFS entries + for entry in self._cbfs_entries.values(): + cfile = entry._cbfs_file + entry.size = cfile.data_len + entry.offset = cfile.calced_cbfs_offset + entry.image_pos = self.image_pos + entry.offset + if entry._cbfs_compress: + entry.uncomp_size = cfile.memlen + + def AddMissingProperties(self): + Entry.AddMissingProperties(self) + for entry in self._cbfs_entries.values(): + entry.AddMissingProperties() + if entry._cbfs_compress: + state.AddZeroProp(entry._node, 'uncomp-size') + + def SetCalculatedProperties(self): + """Set the value of device-tree properties calculated by binman""" + Entry.SetCalculatedProperties(self) + for entry in self._cbfs_entries.values(): + state.SetInt(entry._node, 'offset', entry.offset) + state.SetInt(entry._node, 'size', entry.size) + state.SetInt(entry._node, 'image-pos', entry.image_pos) + if entry.uncomp_size is not None: + state.SetInt(entry._node, 'uncomp-size', entry.uncomp_size) diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index bee4feb1c3a..9cdbf798b87 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -2155,6 +2155,30 @@ class TestFunctional(unittest.TestCase): } self.assertEqual(expected, props) + def testCbfsUpdateFdt(self): + """Test that we can update the device tree with CBFS offset/size info""" + data, _, _, out_dtb_fname = self._DoReadFileDtb('125_cbfs_update.dts', + update_dtb=True) + dtb = fdt.Fdt(out_dtb_fname) + dtb.Scan() + props = self._GetPropTree(dtb, ['offset', 'size', 'image-pos', + 'uncomp-size']) + del props['cbfs/u-boot:size'] + self.assertEqual({ + 'offset': 0, + 'size': len(data), + 'image-pos': 0, + 'cbfs:offset': 0, + 'cbfs:size': len(data), + 'cbfs:image-pos': 0, + 'cbfs/u-boot:offset': 0x38, + 'cbfs/u-boot:uncomp-size': len(U_BOOT_DATA), + 'cbfs/u-boot:image-pos': 0x38, + 'cbfs/u-boot-dtb:offset': 0xb8, + 'cbfs/u-boot-dtb:size': len(U_BOOT_DATA), + 'cbfs/u-boot-dtb:image-pos': 0xb8, + }, props) + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/test/125_cbfs_update.dts b/tools/binman/test/125_cbfs_update.dts new file mode 100644 index 00000000000..6d2e8a0b8ff --- /dev/null +++ b/tools/binman/test/125_cbfs_update.dts @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + cbfs { + size = <0x100>; + u-boot { + cbfs-type = "raw"; + cbfs-compress = "lz4"; + }; + u-boot-dtb { + cbfs-type = "raw"; + }; + }; + }; +}; From patchwork Tue Jul 2 00:24:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1125742 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="evW+MXci"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45d4zv08rHz9s4V for ; Tue, 2 Jul 2019 10:36:26 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 842B7C21D56; Tue, 2 Jul 2019 00:33:48 +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 9A15AC21E60; Tue, 2 Jul 2019 00:25:47 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 91DA6C21E4F; Tue, 2 Jul 2019 00:25:27 +0000 (UTC) Received: from mail-io1-f51.google.com (mail-io1-f51.google.com [209.85.166.51]) by lists.denx.de (Postfix) with ESMTPS id AC28CC21DE8 for ; Tue, 2 Jul 2019 00:25:26 +0000 (UTC) Received: by mail-io1-f51.google.com with SMTP id w25so32967805ioc.8 for ; Mon, 01 Jul 2019 17:25:26 -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=bRLot5b1paVBpWIw0HIIq7T0HzKuTyUQwbWZsg8s1Y0=; b=evW+MXci/ckyZw/iLlXsQZ2jsWUGztAc7wqvaQAZuii5e0F+hZBSGZ5YpaX0lwCdqr i9j8Qb08IVhOwjLSbXlwwbsIrhWaY9qX3f5TsHAf41TPZRUoHrISagFk+Ze6TiAyYTXN PUDoxcvfrn7EOumeaHL/0zWJBwQ3lE8FLdVec= 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=bRLot5b1paVBpWIw0HIIq7T0HzKuTyUQwbWZsg8s1Y0=; b=fJc/rgcbhXxxlZXg+dQodZyZwW9p666jh4TnVt+XX9I5qH2YbhGpi6t9zkKSMntqAr 4ubji77yYvFcXCxY1MNHHNeSNb0LppFLmEEhw74AZrfbmGMlmFrDoNLMl6xbvKsfyfOy ldJshJ7C4T5asH/x8fOfWnr1eB+S+RGsJyZl1dhbWxk7jqSsVOkBgZnomWm3AsV7pxOT f4fx8Rj8BHD6PGb92Sgq3rIHi7BW9WAygLEh9c79ObsOmyz9GiAmWyQGF6ZM9E8DPQy9 SoWOKpGnpBgjye1JWJh1oPJlqPmQXdt5v+nf998NKuhziuohNdgZWeQbQLBDHOEDLdwR JWSg== X-Gm-Message-State: APjAAAWoGeTFmdvtxZXp8wdzaA6BdKMIR2mpsvKHDqEBHIdNVb7WTuYV 38Rj5jXrX2ZXoKp/M4jW67cuwhiJjcE= X-Google-Smtp-Source: APXvYqzwZWTBerMD5wuTkYbme9I7XxCaD22AgxWwh96EtGkOxqMFuXe4afKFu8fRrMUZs2jEMRHRaA== X-Received: by 2002:a6b:d81a:: with SMTP id y26mr28350182iob.126.1562027125522; Mon, 01 Jul 2019 17:25:25 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h19sm10539202iol.65.2019.07.01.17.25.25 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 17:25:25 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 1 Jul 2019 18:24:50 -0600 Message-Id: <20190702002455.996-22-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190702002455.996-1-sjg@chromium.org> References: <20190702002455.996-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH 21/26] binman: Detect bad CBFS file types 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" Detect when an unknown or unsupported file type is specified and report an error. Signed-off-by: Simon Glass --- tools/binman/etype/cbfs.py | 3 +++ tools/binman/ftest.py | 6 ++++++ tools/binman/test/126_cbfs_bad_type.dts | 17 +++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 tools/binman/test/126_cbfs_bad_type.dts diff --git a/tools/binman/etype/cbfs.py b/tools/binman/etype/cbfs.py index a46bb98a033..175ecae1584 100644 --- a/tools/binman/etype/cbfs.py +++ b/tools/binman/etype/cbfs.py @@ -190,6 +190,9 @@ class Entry_cbfs(Entry): elif entry._type == 'stage': cfile = cbfs.add_file_stage(entry._cbfs_name, data, entry._cbfs_offset) + else: + entry.Raise("Unknown cbfs-type '%s' (use 'raw', 'stage')" % + entry._type) if cfile: entry._cbfs_file = cfile entry.size = cfile.data_len diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 9cdbf798b87..4f29a294e61 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -2179,6 +2179,12 @@ class TestFunctional(unittest.TestCase): 'cbfs/u-boot-dtb:image-pos': 0xb8, }, props) + def testCbfsBadType(self): + """Test an image header with a no specified location is detected""" + with self.assertRaises(ValueError) as e: + self._DoReadFile('126_cbfs_bad_type.dts') + self.assertIn("Unknown cbfs-type 'badtype'", str(e.exception)) + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/test/126_cbfs_bad_type.dts b/tools/binman/test/126_cbfs_bad_type.dts new file mode 100644 index 00000000000..2cd6fc6d52d --- /dev/null +++ b/tools/binman/test/126_cbfs_bad_type.dts @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + cbfs { + size = <0x100>; + u-boot { + cbfs-type = "badtype"; + }; + }; + }; +}; From patchwork Tue Jul 2 00:24:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1125750 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="ewYnSTb1"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45d52g4PPbz9s4Y for ; Tue, 2 Jul 2019 10:38:51 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 5F281C21E26; Tue, 2 Jul 2019 00:34:18 +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 8D38DC21C8B; Tue, 2 Jul 2019 00:25:51 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 70972C21E18; Tue, 2 Jul 2019 00:25:37 +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 746F2C21E18 for ; Tue, 2 Jul 2019 00:25:27 +0000 (UTC) Received: by mail-io1-f67.google.com with SMTP id u13so33073040iop.0 for ; Mon, 01 Jul 2019 17:25:27 -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=USC8TfCnHIFCzWbhAenHAj5Ai9YH6ALDx7OGVYPf5VI=; b=ewYnSTb1t/tctBIoYYt6qsKtXOlSNRdBtZMke3Vm6nOcp+sAWLZmMOT1Xa6jpQHjFk 0+vdxRUt4obhS1g65GmCbDrpdIjv0+3UrS84BbSVmvmx2dGVVC6fECOv2oNQM46O9CWJ AF9amddkpkdwwZsGFWTZuxjtefSZYwlS5Week= 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=USC8TfCnHIFCzWbhAenHAj5Ai9YH6ALDx7OGVYPf5VI=; b=tVkLf6JxXCRcamQKjXzI1HDat7fxm266jTeME5cdUU/9GYf3MU1UNKku21LmClCqE7 Wjw3Sp3HbEG/w4MN8NsLWtTGwWr70JgYZiXW5aNWHBOnLrd3zcPwdZKEN2gC1go79INu d2AIpxCDQJerbdfGQ8dHHpMU1ecTWrlxw9iCIHA0uV1vkjDZQDvuuaJnNDXt2rTu8A+F bq07L0FNWYN0lnQMykvHhUJZloFzDC9vyfIKODA5WDsdHzL2vLf8qi14o/jHE61j5Hkw azSAGpdcBUl/DzLrYHwc2RREtTsC5UZa6/T8rRcGkHCCdhGQyIJu2x1SbpwHOStIXnRO AEXw== X-Gm-Message-State: APjAAAUEw/Pw47FQ6nYoGdDpUb9Ds82GLdJF62SiztaefUBeUIFvOiVv ta4HdMinqvfas1UtEwPPnu2zlbtMLkc= X-Google-Smtp-Source: APXvYqwe/Rs3rA6oxI5hfFVDHpSZcmkgXtH/AunxDmQMxOgA+Wnbjli/3KdnGJsxsLrAXPeqeG89Dg== X-Received: by 2002:a6b:6f09:: with SMTP id k9mr5940940ioc.223.1562027126210; Mon, 01 Jul 2019 17:25:26 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h19sm10539202iol.65.2019.07.01.17.25.25 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 17:25:25 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 1 Jul 2019 18:24:51 -0600 Message-Id: <20190702002455.996-23-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190702002455.996-1-sjg@chromium.org> References: <20190702002455.996-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH 22/26] binman: Allow listing the entries in an image 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" It is useful to be able to summarise all the entries in an image, e.g. to display this to this user. Add a new ListEntries() method to Entry, and set up a way to call it through the Image class. Signed-off-by: Simon Glass --- tools/binman/bsection.py | 8 ++++ tools/binman/entry.py | 34 ++++++++++++++++ tools/binman/etype/cbfs.py | 7 +++- tools/binman/etype/section.py | 4 ++ tools/binman/ftest.py | 74 ++++++++++++++++++++++++++++++++++ tools/binman/image.py | 10 +++++ tools/binman/test/127_list.dts | 33 +++++++++++++++ 7 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 tools/binman/test/127_list.dts diff --git a/tools/binman/bsection.py b/tools/binman/bsection.py index d368e3f6baa..79639f28cfa 100644 --- a/tools/binman/bsection.py +++ b/tools/binman/bsection.py @@ -10,6 +10,7 @@ from __future__ import print_function from collections import OrderedDict import sys +from entry import Entry import fdt_util import re import state @@ -511,3 +512,10 @@ class Section(object): image size is dynamic and its sections have not yet been packed """ return self._image._size + + def ListEntries(self, entries, indent): + """Override this method to list all files in the section""" + Entry.AddEntryInfo(entries, indent, self._name, 'section', self._size, + self._image_pos, None, self._offset) + for entry in self._entries.values(): + entry.ListEntries(entries, indent + 1) diff --git a/tools/binman/entry.py b/tools/binman/entry.py index a9a9d119e1d..a39b316b3eb 100644 --- a/tools/binman/entry.py +++ b/tools/binman/entry.py @@ -33,6 +33,9 @@ our_path = os.path.dirname(os.path.realpath(__file__)) # device-tree properties. EntryArg = namedtuple('EntryArg', ['name', 'datatype']) +# Information about an entry for use when displaying summaries +EntryInfo = namedtuple('EntryInfo', ['indent', 'name', 'etype', 'size', + 'image_pos', 'uncomp_size', 'offset']) class Entry(object): """An Entry in the section @@ -614,3 +617,34 @@ features to produce new behaviours. if not self.HasSibling(name): return False return self.section.GetEntries()[name].image_pos + + @staticmethod + def AddEntryInfo(entries, indent, name, etype, size, image_pos, + uncomp_size, offset): + """Add a new entry to the entries list + + Args: + entries: List (of EntryInfo objects) to add to + indent: Current indent level to add to list + name: Entry name (string) + etype: Entry type (string) + size: Entry size in bytes (int) + image_pos: Position within image in bytes (int) + uncomp_size: Uncompressed size if the entry uses compression, else + None + offset: Entry offset within parent in bytes (int) + """ + entries.append(EntryInfo(indent, name, etype, size, image_pos, + uncomp_size, offset)) + + def ListEntries(self, entries, indent): + """Add files in this entry to the list of entries + + This can be overridden by subclasses which need different behaviour. + + Args: + entries: List (of EntryInfo objects) to add to + indent: Current indent level to add to list + """ + self.AddEntryInfo(entries, indent, self.name, self.etype, self.size, + self.image_pos, self.uncomp_size, self.offset) diff --git a/tools/binman/etype/cbfs.py b/tools/binman/etype/cbfs.py index 175ecae1584..953d6f4868d 100644 --- a/tools/binman/etype/cbfs.py +++ b/tools/binman/etype/cbfs.py @@ -195,7 +195,6 @@ class Entry_cbfs(Entry): entry._type) if cfile: entry._cbfs_file = cfile - entry.size = cfile.data_len data = cbfs.get_data() self.SetContents(data) return True @@ -249,3 +248,9 @@ class Entry_cbfs(Entry): state.SetInt(entry._node, 'image-pos', entry.image_pos) if entry.uncomp_size is not None: state.SetInt(entry._node, 'uncomp-size', entry.uncomp_size) + + def ListEntries(self, entries, indent): + """Override this method to list all files in the section""" + Entry.ListEntries(self, entries, indent) + for entry in self._cbfs_entries.values(): + entry.ListEntries(entries, indent + 1) diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py index 23bf22113d4..178e89352e5 100644 --- a/tools/binman/etype/section.py +++ b/tools/binman/etype/section.py @@ -111,3 +111,7 @@ class Entry_section(Entry): def ExpandToLimit(self, limit): super(Entry_section, self).ExpandToLimit(limit) self._section.ExpandSize(self.size) + + def ListEntries(self, entries, indent): + """List the files in the section""" + self._section.ListEntries(entries, indent) diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 4f29a294e61..9552c3b2761 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -2185,6 +2185,80 @@ class TestFunctional(unittest.TestCase): self._DoReadFile('126_cbfs_bad_type.dts') self.assertIn("Unknown cbfs-type 'badtype'", str(e.exception)) + def testList(self): + """Test listing the files in an image""" + data = self._DoReadFile('127_list.dts') + image = control.images['image'] + entries = image.ListEntries() + self.assertEqual(7, len(entries)) + + ent = entries[0] + self.assertEqual(0, ent.indent) + self.assertEqual('main-section', ent.name) + self.assertEqual('section', ent.etype) + self.assertEqual(len(data), ent.size) + self.assertEqual(0, ent.image_pos) + self.assertEqual(None, ent.uncomp_size) + self.assertEqual(None, ent.offset) + + ent = entries[1] + self.assertEqual(1, ent.indent) + self.assertEqual('u-boot', ent.name) + self.assertEqual('u-boot', ent.etype) + self.assertEqual(len(U_BOOT_DATA), ent.size) + self.assertEqual(0, ent.image_pos) + self.assertEqual(None, ent.uncomp_size) + self.assertEqual(0, ent.offset) + + ent = entries[2] + self.assertEqual(1, ent.indent) + self.assertEqual('section', ent.name) + self.assertEqual('section', ent.etype) + section_size = ent.size + self.assertEqual(0x100, ent.image_pos) + self.assertEqual(None, ent.uncomp_size) + self.assertEqual(len(U_BOOT_DATA), ent.offset) + + ent = entries[3] + self.assertEqual(2, ent.indent) + self.assertEqual('cbfs', ent.name) + self.assertEqual('cbfs', ent.etype) + self.assertEqual(0x400, ent.size) + self.assertEqual(0x100, ent.image_pos) + self.assertEqual(None, ent.uncomp_size) + self.assertEqual(0, ent.offset) + + ent = entries[4] + self.assertEqual(3, ent.indent) + self.assertEqual('u-boot', ent.name) + self.assertEqual('u-boot', ent.etype) + self.assertEqual(len(U_BOOT_DATA), ent.size) + self.assertEqual(0x138, ent.image_pos) + self.assertEqual(None, ent.uncomp_size) + self.assertEqual(0x38, ent.offset) + + ent = entries[5] + self.assertEqual(3, ent.indent) + self.assertEqual('u-boot-dtb', ent.name) + self.assertEqual('text', ent.etype) + self.assertGreater(len(COMPRESS_DATA), ent.size) + self.assertEqual(0x178, ent.image_pos) + self.assertEqual(len(COMPRESS_DATA), ent.uncomp_size) + self.assertEqual(0x78, ent.offset) + + ent = entries[6] + self.assertEqual(2, ent.indent) + self.assertEqual('u-boot-dtb', ent.name) + self.assertEqual('u-boot-dtb', ent.etype) + self.assertEqual(0x500, ent.image_pos) + self.assertEqual(len(U_BOOT_DTB_DATA), ent.uncomp_size) + dtb_size = ent.size + # Compressing this data expands it since headers are added + self.assertGreater(dtb_size, len(U_BOOT_DTB_DATA)) + self.assertEqual(0x400, ent.offset) + + self.assertEqual(len(data), 0x100 + section_size) + self.assertEqual(section_size, 0x400 + dtb_size) if __name__ == "__main__": unittest.main() diff --git a/tools/binman/image.py b/tools/binman/image.py index 6339d020e76..d4145685972 100644 --- a/tools/binman/image.py +++ b/tools/binman/image.py @@ -162,3 +162,13 @@ class Image: file=fd) self._section.WriteMap(fd, 0) return fname + + def ListEntries(self): + """List the files in an image + + Returns: + List of entry.EntryInfo objects describing all entries in the image + """ + entries = [] + self._section.ListEntries(entries, 0) + return entries diff --git a/tools/binman/test/127_list.dts b/tools/binman/test/127_list.dts new file mode 100644 index 00000000000..c1d6fce3f9e --- /dev/null +++ b/tools/binman/test/127_list.dts @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + u-boot { + }; + section { + align = <0x100>; + cbfs { + size = <0x400>; + u-boot { + cbfs-type = "raw"; + cbfs-offset = <0x38>; + }; + u-boot-dtb { + type = "text"; + text = "compress xxxxxxxxxxxxxxxxxxxxxx data"; + cbfs-type = "raw"; + cbfs-compress = "lzma"; + cbfs-offset = <0x78>; + }; + }; + u-boot-dtb { + compress = "lz4"; + }; + }; + }; +}; From patchwork Tue Jul 2 00:24:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1125745 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="E5gBqxLJ"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45d51D1Ykfz9s4V for ; Tue, 2 Jul 2019 10:37:36 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id E654DC21DAF; Tue, 2 Jul 2019 00:35:05 +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 67E6FC21EF0; Tue, 2 Jul 2019 00:25:53 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 7F56CC21EDE; Tue, 2 Jul 2019 00:25:38 +0000 (UTC) Received: from mail-io1-f47.google.com (mail-io1-f47.google.com [209.85.166.47]) by lists.denx.de (Postfix) with ESMTPS id 27C84C21DF9 for ; Tue, 2 Jul 2019 00:25:28 +0000 (UTC) Received: by mail-io1-f47.google.com with SMTP id j6so33020539ioa.5 for ; Mon, 01 Jul 2019 17:25:28 -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=B3nA6Xef71YdfjfGW/AZUzSeDRlXm3KiDfLeoukbjuc=; b=E5gBqxLJO7fHLzCbU3cFVtvKDU7qtXnm+LJ9KKqCeEtw/O6UIQes7xPo15/qjaSw0s 2O7Hjoe7oUCka84bGLAux2YEvwglYbYAfB9z6fO3bXIsq7mEv8TDdWxXFF0l7K/OSsw8 UYQHJbE0NcvWk7JDVw8oSaD+DzY8cUpcpMJjI= 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=B3nA6Xef71YdfjfGW/AZUzSeDRlXm3KiDfLeoukbjuc=; b=an1eOXAMqBp/soN9ES/Y7ZoH7Yus6lJ7UJAFSSdz0HbhveBy945QKHOowr7kThrPoN 5ZpsH/uoaoYTc7iYf53yprIerFLKR1fSLv0ZipYGX1s727I6ZTydhXB1lyMpIyUOQFEW 33G/M64an+rwuX1X9WyAtKHOTRnLUpwiLkLYlE2JC4bAdlT+HrLvbabz/23xdRrU+8Ej P5TLEAQmTSohUeViM4DlxlXYu0CePQXDhC24t1F31dMkdB2G0bxiwTOZXo2u4jQopIjU gigr5jYMK9USFdnrLl0Cti82HjHs9WEkm6WQiJKoC5RA3Jj428Z9OXt1iSj4DsDXSt2K aOog== X-Gm-Message-State: APjAAAWTQWip8+MWLDeqPKzdq7nzTcgHfU5IELfEFT5a7eJN0rE8dPmp 6FLzfINjrVfd1j2C1EcdXy6Y9JLDmCI= X-Google-Smtp-Source: APXvYqxiPh33j1vj2CwI3Wl79lwCus6aqjll2zGDSgU6yxiuEvb0dNEqC7kAimnHHrB0rJ82fTKWfQ== X-Received: by 2002:a02:662f:: with SMTP id k47mr32470919jac.4.1562027126923; Mon, 01 Jul 2019 17:25:26 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h19sm10539202iol.65.2019.07.01.17.25.26 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 17:25:26 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 1 Jul 2019 18:24:52 -0600 Message-Id: <20190702002455.996-24-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190702002455.996-1-sjg@chromium.org> References: <20190702002455.996-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH 23/26] binman: Support reading in firmware images 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" Add support for reading in an image and locating its Fdt map. Signed-off-by: Simon Glass --- tools/binman/etype/fdtmap.py | 22 +++++++++++++++- tools/binman/ftest.py | 17 ++++++++++++ tools/binman/test/128_decode_image.dts | 36 ++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 tools/binman/test/128_decode_image.dts diff --git a/tools/binman/etype/fdtmap.py b/tools/binman/etype/fdtmap.py index bfd7962be3a..4fe5f8d9e10 100644 --- a/tools/binman/etype/fdtmap.py +++ b/tools/binman/etype/fdtmap.py @@ -15,7 +15,27 @@ from fdt import Fdt import state import tools -FDTMAP_MAGIC = b'_FDTMAP_' +FDTMAP_MAGIC = b'_FDTMAP_' +FDTMAP_HDR_LEN = 16 + +def LocateFdtmap(data): + """Search an image for an fdt map + + Args: + data: Data to search + + Returns: + Position of fdt map in data, or None if not found. Note that the + position returned is of the FDT map data itself, i.e. after the + header + """ + hdr_pos = data.find(FDTMAP_MAGIC) + size = len(data) + if hdr_pos: + hdr = data[hdr_pos:hdr_pos + FDTMAP_HDR_LEN] + if len(hdr) == FDTMAP_HDR_LEN: + return hdr_pos + FDTMAP_HDR_LEN + return None class Entry_fdtmap(Entry): """An entry which contains an FDT map diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 9552c3b2761..2536d03c374 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -24,6 +24,7 @@ import command import control import elf import fdt +from etype import fdtmap import fdt_util import fmap_util import test_util @@ -2260,5 +2261,21 @@ class TestFunctional(unittest.TestCase): self.assertEqual(len(data), 0x100 + section_size) self.assertEqual(section_size, 0x400 + dtb_size) + def testFindFdtmap(self): + """Test locating an FDT map in an image""" + data = self._DoReadFileDtb('128_decode_image.dts', use_real_dtb=True, + update_dtb=True)[0] + image = control.images['image'] + entries = image.GetEntries() + entry = entries['fdtmap'] + self.assertEqual(entry.image_pos + fdtmap.FDTMAP_HDR_LEN, + fdtmap.LocateFdtmap(data)) + + def testFindFdtmapMissing(self): + """Test failing to locate an FDP map""" + data = self._DoReadFile('005_simple.dts') + self.assertEqual(None, fdtmap.LocateFdtmap(data)) + + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/test/128_decode_image.dts b/tools/binman/test/128_decode_image.dts new file mode 100644 index 00000000000..449fccc41df --- /dev/null +++ b/tools/binman/test/128_decode_image.dts @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + size = <0xc00>; + u-boot { + }; + section { + align = <0x100>; + cbfs { + size = <0x400>; + u-boot { + cbfs-type = "raw"; + }; + u-boot-dtb { + cbfs-type = "raw"; + cbfs-compress = "lzma"; + cbfs-offset = <0x80>; + }; + }; + u-boot-dtb { + compress = "lz4"; + }; + }; + fdtmap { + }; + image-header { + location = "end"; + }; + }; +}; From patchwork Tue Jul 2 00:24:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1125744 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="XXo0MqH6"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45d5153GtDz9s4Y for ; Tue, 2 Jul 2019 10:37:29 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 2C345C21E16; Tue, 2 Jul 2019 00:34:51 +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 E262BC21EDC; Tue, 2 Jul 2019 00:25:52 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 483D3C21E08; Tue, 2 Jul 2019 00:25:39 +0000 (UTC) Received: from mail-io1-f50.google.com (mail-io1-f50.google.com [209.85.166.50]) by lists.denx.de (Postfix) with ESMTPS id B86DFC21E1A for ; Tue, 2 Jul 2019 00:25:28 +0000 (UTC) Received: by mail-io1-f50.google.com with SMTP id e5so33020898iok.4 for ; Mon, 01 Jul 2019 17:25:28 -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=rYKTjcBLKLM7dwr16cYNPGapoZieIj3P2HX5VXWgCy0=; b=XXo0MqH6963+wpBSRbFti5XbwpFP7sZcA3AUbS8wZsEcQ4DWeXX7l0dgAFb11GNRVn cgd247VcsPL4KyRIoj5rqYLMr+QYPtM8ltsc9/V7D72DLhhjn8gI4NaN2vw6ASSr7nVf TdbtAkotShyqAWeqsV3TV5TNL6Fz0HROZEmdU= 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=rYKTjcBLKLM7dwr16cYNPGapoZieIj3P2HX5VXWgCy0=; b=DW/qQv/9nWli7oo1J0///9/8Yzbr2N9lDiXPDA7m+wbIn/Nk4QfQoNzsIacbxWadz8 vqhv01c1ksDZaQJnrv8rBxrA/6PE6zKpWIvuwqqvwb06y4z+aqe9ld++s/o69GIlO1+P 4dQBb1NIRd0sYYubKG77ivsZwjG/PxN/MdBrjqPRMvq0VrBT6rX9UdFiiZMFfypRS9K3 54WalvrpTVd642hLCWGWQIITS3BSGFhINOASxRVENyowk9/Yf4EAQelRR1/14kQiKpjp KaOjRH6AfFgnXo+9bG7FKXpCaBuSLQQ6pyjJOc/rUa3PUb9NlwOuWxwWaFSU7YsxgeSj NanQ== X-Gm-Message-State: APjAAAXXXHFklU6lFx8vN05QR/ntlBlpKF/bQB7GkWlQ8bk4sCnpwhQ9 MjNJJ3qkz0z5Th0MA8BhRMFIi0CkKHE= X-Google-Smtp-Source: APXvYqwfHlrBm4Ya0Ai54ZhSTd9cT20ypzkmiryiipQx80v8wdmmNzWtgtqTjG/jxfXnLY68DeTWhw== X-Received: by 2002:a05:6602:2248:: with SMTP id o8mr12061643ioo.90.1562027127569; Mon, 01 Jul 2019 17:25:27 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h19sm10539202iol.65.2019.07.01.17.25.27 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 17:25:27 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 1 Jul 2019 18:24:53 -0600 Message-Id: <20190702002455.996-25-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190702002455.996-1-sjg@chromium.org> References: <20190702002455.996-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH 24/26] binman: Support locating an image header 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" Add support for locating an image header in an image. Signed-off-by: Simon Glass --- tools/binman/etype/image_header.py | 23 +++++++++++++++++++++++ tools/binman/ftest.py | 26 ++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/tools/binman/etype/image_header.py b/tools/binman/etype/image_header.py index b1c4f8a07e9..8f9c5aa5d9e 100644 --- a/tools/binman/etype/image_header.py +++ b/tools/binman/etype/image_header.py @@ -15,6 +15,29 @@ from entry import Entry import fdt_util IMAGE_HEADER_MAGIC = b'BinM' +IMAGE_HEADER_LEN = 8 + +def LocateHeaderOffset(data): + """Search an image for an image header + + Args: + data: Data to search + + Returns: + Offset of image header in the image, or None if not found + """ + hdr_pos = data.find(IMAGE_HEADER_MAGIC) + if hdr_pos != -1: + size = len(data) + hdr = data[hdr_pos:hdr_pos + IMAGE_HEADER_LEN] + if len(hdr) == IMAGE_HEADER_LEN: + offset = struct.unpack(' X-Patchwork-Id: 1125747 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="ERl8OSVO"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45d5213DBWz9s4V for ; Tue, 2 Jul 2019 10:38:17 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 145AAC21DFB; Tue, 2 Jul 2019 00:34:02 +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, 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 0E6F2C21EC8; Tue, 2 Jul 2019 00:25:49 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 7D899C21E56; Tue, 2 Jul 2019 00:25:39 +0000 (UTC) Received: from mail-io1-f68.google.com (mail-io1-f68.google.com [209.85.166.68]) by lists.denx.de (Postfix) with ESMTPS id 6B4A5C21E07 for ; Tue, 2 Jul 2019 00:25:29 +0000 (UTC) Received: by mail-io1-f68.google.com with SMTP id s7so32926507iob.11 for ; Mon, 01 Jul 2019 17:25:29 -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=szF7ZcoeLAuHqGe00L+P+NMQWbhXPBpD3YbAPdZdg2M=; b=ERl8OSVOKNKdQg+th7J5woiVTGditemPVw43niKROGI72znF0xU09hpnbscL+8ob0S C0lQ9E/7o9v94YQLY51IR9+gcxWylu7KqDpuYacVXPKtzElkBgOisqyH6yFjtYl1Lr1D WMNI2IsHAq496rusUwJWDA7LE2NK7BZjhfkwI= 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=szF7ZcoeLAuHqGe00L+P+NMQWbhXPBpD3YbAPdZdg2M=; b=IeUWKf+07TSawQWZXxwCslf0bSXWRjS1mIUFE2JBFMcIfl5Psa1gPjE8uzfF+bo82X 6Yn1NiRPFjvvZ3Zwb91NnU5tB09Sjv4QSH5575SNCzRnefTdFqmE2R40fZlIMuiqlbmN uz2fAtubtjyXsJcON/KFQWKr33sSsHOvDUw+wghdgnjJd71Fl+pCeMnWURRhKdsGs2vh C9Cuox1XHa6h11NcAGCufcEp149XyLsWxGCAnuA/I8LyUzTMOJv2KG3/tJ0THV2h3L9K YOQ9ovsmWBQZmD5qcnj0Vwjw6h+nK+F9rqzqLSy4jL8h6YOoeJ11uglhFDlAJo8Zx6Q7 g9PA== X-Gm-Message-State: APjAAAWKCw7KE8Ab6+toIGIqgvDAd6Rw1qvNDEsfj38al2PeZtCB9BaP 6emZxLpWcq1/TO7TVZd0SHpWFp0Z34A= X-Google-Smtp-Source: APXvYqxxjyK5NDVTo+7VCLhGVbi+RsY35/bb8+6halRW4FrRHCCRn1K4Q5HpytA7mBVUFVKJ2ykuqw== X-Received: by 2002:a02:b90e:: with SMTP id v14mr32231953jan.122.1562027128196; Mon, 01 Jul 2019 17:25:28 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h19sm10539202iol.65.2019.07.01.17.25.27 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 17:25:27 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 1 Jul 2019 18:24:54 -0600 Message-Id: <20190702002455.996-26-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190702002455.996-1-sjg@chromium.org> References: <20190702002455.996-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH 25/26] binman: Support reading an image into an Image object 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" It is possible to read an Image, locate its FDT map and then read it into the binman data structures. This allows full access to the entries that were written to the image. Add support for this. Signed-off-by: Simon Glass --- tools/binman/entry.py | 6 ++++ tools/binman/ftest.py | 33 +++++++++++++++++ tools/binman/image.py | 36 +++++++++++++++++++ tools/binman/test/128_decode_image_no_hdr.dts | 33 +++++++++++++++++ tools/binman/test/129_list_fdtmap.dts | 36 +++++++++++++++++++ 5 files changed, 144 insertions(+) create mode 100644 tools/binman/test/128_decode_image_no_hdr.dts create mode 100644 tools/binman/test/129_list_fdtmap.dts diff --git a/tools/binman/entry.py b/tools/binman/entry.py index a39b316b3eb..1fe905ae904 100644 --- a/tools/binman/entry.py +++ b/tools/binman/entry.py @@ -159,6 +159,12 @@ class Entry(object): self.offset = fdt_util.GetInt(self._node, 'offset') self.size = fdt_util.GetInt(self._node, 'size') self.orig_offset, self.orig_size = self.offset, self.size + + # These should not be set in input files, but are set in an FDT map, + # which is also read by this code. + self.image_pos = fdt_util.GetInt(self._node, 'image-pos') + self.uncomp_size = fdt_util.GetInt(self._node, 'uncomp-size') + self.align = fdt_util.GetInt(self._node, 'align') if tools.NotPowerOfTwo(self.align): raise ValueError("Node '%s': Alignment %s must be a power of two" % diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 15cf5cea457..88c3d847f82 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -30,6 +30,7 @@ import fdt_util import fmap_util import test_util import gzip +from image import Image import state import tools import tout @@ -2302,6 +2303,38 @@ class TestFunctional(unittest.TestCase): data = self._DoReadFile('005_simple.dts') self.assertEqual(None, image_header.LocateHeaderOffset(data)) + def testReadImage(self): + """Test reading an image and accessing its FDT map""" + data = self._DoReadFileDtb('128_decode_image.dts', + use_real_dtb=True, update_dtb=True)[0] + image_fname = tools.GetOutputFilename('image.bin') + orig_image = control.images['image'] + image = Image.FromFile(image_fname) + self.assertEqual(orig_image.GetEntries().keys(), + image.GetEntries().keys()) + + orig_entry = orig_image.GetEntries()['fdtmap'] + entry = image.GetEntries()['fdtmap'] + self.assertEquals(orig_entry.offset, entry.offset) + self.assertEquals(orig_entry.size, entry.size) + self.assertEquals(orig_entry.image_pos, entry.image_pos) + + def testReadImageNoHeader(self): + """Test accessing an image's FDT map without an image header""" + data = self._DoReadFileDtb('128_decode_image_no_hdr.dts', + use_real_dtb=True, update_dtb=True)[0] + image_fname = tools.GetOutputFilename('image.bin') + image = Image.FromFile(image_fname) + self.assertTrue(isinstance(image, Image)) + self.assertEqual('image', image._name) + + def testReadImageFail(self): + """Test failing to read an image image's FDT map""" + self._DoReadFile('005_simple.dts') + image_fname = tools.GetOutputFilename('image.bin') + image = Image.FromFile(image_fname) + self.assertTrue(isinstance(image, str)) + self.assertEqual('Cannot find FDT map in image', image) if __name__ == "__main__": unittest.main() diff --git a/tools/binman/image.py b/tools/binman/image.py index d4145685972..d918b5a7194 100644 --- a/tools/binman/image.py +++ b/tools/binman/image.py @@ -12,6 +12,9 @@ from operator import attrgetter import re import sys +from etype import fdtmap +from etype import image_header +import fdt import fdt_util import bsection import tools @@ -47,6 +50,39 @@ class Image: else: self._ReadNode() + @classmethod + def FromFile(cls, fname): + """Convert an image file into an Image for use in binman + + Args: + fname: Filename of image file to read + + Returns: + Image object on success, or string error message on failure + """ + data = tools.ReadFile(fname) + size = len(data) + + # First look for an image header + pos = image_header.LocateHeaderOffset(data) + if pos is None: + # Look for the FDT map + pos = fdtmap.LocateFdtmap(data) + else: + # Move past the header to the FDT + pos += fdtmap.FDTMAP_HDR_LEN + if pos is None: + return 'Cannot find FDT map in image' + + # We don't knowe the FDT size, so check its header first + probe_dtb = fdt.Fdt.FromData(data[pos:pos + 256]) + dtb_size = probe_dtb.GetFdtObj().totalsize() + dtb = fdt.Fdt.FromData(data[pos:pos + dtb_size]) + dtb.Scan() + + # Return an Image with the associated nodes + return Image('image', dtb.GetRoot()) + def _ReadNode(self): """Read properties from the image node""" self._size = fdt_util.GetInt(self._node, 'size') diff --git a/tools/binman/test/128_decode_image_no_hdr.dts b/tools/binman/test/128_decode_image_no_hdr.dts new file mode 100644 index 00000000000..90fdd8820ca --- /dev/null +++ b/tools/binman/test/128_decode_image_no_hdr.dts @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + size = <0xc00>; + u-boot { + }; + section { + align = <0x100>; + cbfs { + size = <0x400>; + u-boot { + cbfs-type = "raw"; + }; + u-boot-dtb { + cbfs-type = "raw"; + cbfs-compress = "lzma"; + cbfs-offset = <0x80>; + }; + }; + u-boot-dtb { + compress = "lz4"; + }; + }; + fdtmap { + }; + }; +}; diff --git a/tools/binman/test/129_list_fdtmap.dts b/tools/binman/test/129_list_fdtmap.dts new file mode 100644 index 00000000000..449fccc41df --- /dev/null +++ b/tools/binman/test/129_list_fdtmap.dts @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + size = <0xc00>; + u-boot { + }; + section { + align = <0x100>; + cbfs { + size = <0x400>; + u-boot { + cbfs-type = "raw"; + }; + u-boot-dtb { + cbfs-type = "raw"; + cbfs-compress = "lzma"; + cbfs-offset = <0x80>; + }; + }; + u-boot-dtb { + compress = "lz4"; + }; + }; + fdtmap { + }; + image-header { + location = "end"; + }; + }; +}; From patchwork Tue Jul 2 00:24:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1125751 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="SLd/gY7R"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45d53W0kWjz9s8m for ; Tue, 2 Jul 2019 10:39:35 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id C5E3AC21D56; Tue, 2 Jul 2019 00:34:37 +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 53072C21EC2; Tue, 2 Jul 2019 00:25:52 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 7ACFDC21ED6; Tue, 2 Jul 2019 00:25:40 +0000 (UTC) Received: from mail-io1-f65.google.com (mail-io1-f65.google.com [209.85.166.65]) by lists.denx.de (Postfix) with ESMTPS id 1593CC21DA2 for ; Tue, 2 Jul 2019 00:25:30 +0000 (UTC) Received: by mail-io1-f65.google.com with SMTP id h6so33078195ioh.3 for ; Mon, 01 Jul 2019 17:25:30 -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=6eZtr5VTO2mDAZhMfwTB3GYqUpjc0F2frb0qiH6dDf4=; b=SLd/gY7R2rSpAwyFIjAqjXl4Tw77vfNpLUA3cN/uFMArlDu8nvVB8JiZL7Vum19sjC QFLMJue9d31GXXIond+mzUsNPtQqDiblIwe1HKF5Jq1fWngCBfYl6nmZC5N9aher3+IS Q+6e7termOorXfAgyZtNINnVk1AzEsJg4Zq7Q= 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=6eZtr5VTO2mDAZhMfwTB3GYqUpjc0F2frb0qiH6dDf4=; b=R3pbJT1DMR8LaJturw47E3AJ1i5KNUUuJMD3R0sws0GYz5QOc8C6F4da/ayjpah0TL O5Cc8aEt0DuF96eVtRNtqNBNhVafLRwDEwyZasbpq4MezXiwobx2FWMBPoNvo1EQ1Wj2 18IQzj2PlALAQmfNeVGKEWSTFdYvEKIOqm9Ws1I7FMtuoM5ToqbGbabTQqyFBllZEaLj KKRDIJgObilYV+oEBJQiizDSp7XyBYsTuQ+jkeyX7aZcIPqQIREsmhKaRlangVwju5S4 oPd8rFge/dpSkwEwdF76V24UNpwTOmHDg9Fifwl/lkKaraE0JuYb8fYMRN/MsntO1yzG Ewhg== X-Gm-Message-State: APjAAAUb6eRhLuZh3TkAPtpbRfY3PB+HG2wpXWifxIci1qHLG3kZeryk BlZSNlMXOkCl6YS1dif6gE7VdaTJJHk= X-Google-Smtp-Source: APXvYqwuItRzbJtLEqgsG2+8Ek0fJCOrbf2836z4mfRmJxqgz4rh1koWp40enlvnRpDOs/frw6IQVg== X-Received: by 2002:a02:3904:: with SMTP id l4mr776663jaa.81.1562027128853; Mon, 01 Jul 2019 17:25:28 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h19sm10539202iol.65.2019.07.01.17.25.28 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 17:25:28 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 1 Jul 2019 18:24:55 -0600 Message-Id: <20190702002455.996-27-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190702002455.996-1-sjg@chromium.org> References: <20190702002455.996-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH 26/26] binman: Support listing an image 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" Add support for listing the entries in an image. This relies on the image having an FDT map. Signed-off-by: Simon Glass --- tools/binman/README | 25 +++++++++++++- tools/binman/control.py | 73 +++++++++++++++++++++++++++++++++++++++++ tools/binman/ftest.py | 31 +++++++++++++++++ 3 files changed, 128 insertions(+), 1 deletion(-) diff --git a/tools/binman/README b/tools/binman/README index 7e745a2d466..2f3ded58c91 100644 --- a/tools/binman/README +++ b/tools/binman/README @@ -490,6 +490,30 @@ see README.entries. This is generated from the source code using: binman entry-docs >tools/binman/README.entries +Listing images +-------------- + +It is possible to list the entries in an existing firmware image created by +binman. For example: + + $ binman list image.bin + Name Image-pos Size Entry-type Offset Uncomp-size + ---------------------------------------------------------------------- + main-section c00 section 0 + u-boot 0 4 u-boot 0 + section 5ff section 4 + cbfs 100 400 cbfs 0 + u-boot 138 4 u-boot 38 + u-boot-dtb 180 108 u-boot-dtb 80 3b5 + u-boot-dtb 500 1ff u-boot-dtb 400 3b5 + fdtmap 6ff 381 fdtmap 6ff + image-header bf8 8 image-header bf8 + +This shows the hierarchy of the image, the position, size and type of each +entry, the offset of each entry within its parent and the uncompressed size if +the entry is compressed. + + Hashing Entries --------------- @@ -825,7 +849,6 @@ Some ideas: - Add an option to decode an image into the constituent binaries - Support building an image for a board (-b) more completely, with a configurable build directory -- Support listing files in images - Support logging of binman's operations, with different levels of verbosity -- diff --git a/tools/binman/control.py b/tools/binman/control.py index d48e7ac0070..3ac3f0c3e71 100644 --- a/tools/binman/control.py +++ b/tools/binman/control.py @@ -67,6 +67,75 @@ def WriteEntryDocs(modules, test_missing=None): from entry import Entry Entry.WriteDocs(modules, test_missing) +def EntryToStrings(entry): + """Convert an entry to a list of strings, one for each column + + Args: + entry: EntryInfo object containing information to output + + Returns: + List of strings, one for each field in entry + """ + def _AppendHex(val): + """Append a hex value, or an empty string if val is None + + Args: + val: Integer value, or None if none + """ + args.append('' if val is None else '>%x' % val) + + args = [' ' * entry.indent + entry.name] + _AppendHex(entry.image_pos) + _AppendHex(entry.size) + args.append(entry.etype) + _AppendHex(entry.offset) + _AppendHex(entry.uncomp_size) + return args + +def ListEntries(fname): + """List the entries in an image + + This decodes the supplied image and displays a table of entries from that + image, preceded by a header. + + Args: + fname: Filename to process + """ + def _DoLine(line): + out = [] + for i, item in enumerate(line): + lengths[i] = max(lengths[i], len(item)) + out.append(item) + return out + + image = Image.FromFile(fname) + + # Check for error + if isinstance(image, str): + print("Unable to read image '%s' (%s)" % (fname, image)) + return + entries = image.ListEntries() + + num_columns = 6 + lines = [] + lengths = [0] * num_columns + lines.append(_DoLine(['Name', 'Image-pos', 'Size', 'Entry-type', + 'Offset', 'Uncomp-size'])) + for entry in entries: + lines.append(_DoLine(EntryToStrings(entry))) + for linenum, line in enumerate(lines): + if linenum == 1: + print('-' * (sum(lengths) + num_columns * 2)) + out = '' + for i, item in enumerate(line): + width = -lengths[i] + if item.startswith('>'): + width = -width + item = item[1:] + txt = '%*s ' % (width, item) + out += txt + print(out.rstrip()) + def Binman(args): """The main control code for binman @@ -87,6 +156,10 @@ def Binman(args): command.Run(pager, fname) return 0 + if args.cmd == 'list': + ListEntries(args.fname) + return 0 + # Try to figure out which device tree contains our image description if args.dt: dtb_fname = args.dt diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 88c3d847f82..f5353911705 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -2336,5 +2336,36 @@ class TestFunctional(unittest.TestCase): self.assertTrue(isinstance(image, str)) self.assertEqual('Cannot find FDT map in image', image) + def testListCmd(self): + """Test listing the files in an image using an Fdtmap""" + data = self._DoReadFileDtb('129_list_fdtmap.dts', use_real_dtb=True, + update_dtb=True)[0] + image_fname = tools.GetOutputFilename('image.bin') + with test_util.capture_sys_output() as (stdout, stderr): + self._DoBinman('list', image_fname) + lines = stdout.getvalue().splitlines() + expected = [ + 'Name Image-pos Size Entry-type Offset Uncomp-size', +'----------------------------------------------------------------------', +'main-section c00 section 0', +' u-boot 0 4 u-boot 0', +' section 5ff section 4', +' cbfs 100 400 cbfs 0', +' u-boot 138 4 u-boot 38', +' u-boot-dtb 180 108 u-boot-dtb 80 3b5', +' u-boot-dtb 500 1ff u-boot-dtb 400 3b5', +' fdtmap 6ff 381 fdtmap 6ff', +' image-header bf8 8 image-header bf8', + ] + self.assertEqual(expected, lines) + + def testListCmdFail(self): + """Test failing to list an image""" + self._DoReadFile('005_simple.dts') + image_fname = tools.GetOutputFilename('image.bin') + with test_util.capture_sys_output() as (stdout, stderr): + self._DoBinman('list', image_fname) + + if __name__ == "__main__": unittest.main()