From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 40D0DC433EF for ; Mon, 10 Jan 2022 03:17:35 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id ECFC0831E0; Mon, 10 Jan 2022 04:16:01 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Wq0i5xUp"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3C69281DE9; Mon, 10 Jan 2022 04:15:29 +0100 (CET) Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0B3C381B53 for ; Mon, 10 Jan 2022 04:15:18 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd2f.google.com with SMTP id h23so15677602iol.11 for ; Sun, 09 Jan 2022 19:15:17 -0800 (PST) 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=O0J8bTt+qBUwPs1oA/WwiVbxK4TwWqg5+09GlkMz1is=; b=Wq0i5xUpcy+/unX/2TFKeafyZXUKaFM+y2oXf9lB6/DIgCZnBH+iuH5V8m4xTWROI3 zaw4RkAxOqbBbQCij/H/vYxWVUdBiFZlriQuR9uHsbgfHr0Kve0Ad2lE7X2aOfPFP5Co BD4tauphQkBzh/sV7BYi8ul4Wp38TF/u5c4Ec= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O0J8bTt+qBUwPs1oA/WwiVbxK4TwWqg5+09GlkMz1is=; b=EMc2mN3LrnDT0cUIpRJG2468c5hqx9Wd5Wm3Z3mS2gynnYALjZtXMF9FFNB+20aCG6 +TRKVqqdoW+Z3ltk+ErBobvw2Vou/o0YgTYM3sc54tUbOXEt1IgjxxwLgiMK3E0tfCDD 52CeuzJWuLjmPYi2o+GBKQx0htqkuMZrIV+WbUC8zj8MXIGi3YsphLc0YzH49n4Xh9MY 0QMf3GE2JX90JuADK6QP1jPIPsg5HzrDkmnjVBZzn5FxuXpQf6tkiBKNQ0KRSGALsE1x If6NKKiYh2lOyRSZZv0SM6uIZdX/Ion8EkVsuMG/r/ShVyBz5rdmpDygd5Ctcn3r3jS1 wG6A== X-Gm-Message-State: AOAM533RkyGapQHLEnjaRxvfT9xscHt21UWQLkUKz7lYs/duX1zBLiJZ QkDDMiSbSDp78JKqlEE5pkYn/9ueg89b+A== X-Google-Smtp-Source: ABdhPJxEvAOXWYAuUTIxKyU6O/OZfaCvyF+4amvLfbl/o7SQrHpDa/iSRllMfZymw6kwbGvEgDFr1w== X-Received: by 2002:a5e:c104:: with SMTP id v4mr33869456iol.218.1641784516597; Sun, 09 Jan 2022 19:15:16 -0800 (PST) Received: from sjg1.roam.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id d16sm3542182ioy.29.2022.01.09.19.15.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jan 2022 19:15:16 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass Subject: [PATCH v2 15/38] binman: Plumb in support for bintools Date: Sun, 9 Jan 2022 20:13:50 -0700 Message-Id: <20220110031413.1970836-16-sjg@chromium.org> X-Mailer: git-send-email 2.34.1.575.g55b058a8bb-goog In-Reply-To: <20220110031413.1970836-1-sjg@chromium.org> References: <20220110031413.1970836-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Support collecting the available bintools needed by an image, by scanning the entries in the image. Also add a command-line interface to access the basic bintool features, such as listing the bintools and fetching them if needed. Signed-off-by: Simon Glass --- (no changes since v1) tools/binman/cmdline.py | 7 +++++++ tools/binman/control.py | 17 ++++++++++++++++- tools/binman/entry.py | 22 ++++++++++++++++++++++ tools/binman/etype/section.py | 4 ++++ tools/binman/ftest.py | 1 + tools/binman/image.py | 14 ++++++++++++++ 6 files changed, 64 insertions(+), 1 deletion(-) diff --git a/tools/binman/cmdline.py b/tools/binman/cmdline.py index 6c685954619..92cc14b6fc7 100644 --- a/tools/binman/cmdline.py +++ b/tools/binman/cmdline.py @@ -167,4 +167,11 @@ controlled by a description in the board device tree.''' test_parser.add_argument('tests', nargs='*', help='Test names to run (omit for all)') + tool_parser = subparsers.add_parser('tool', help='Check bintools') + tool_parser.add_argument('-l', '--list', action='store_true', + help='List all known bintools') + tool_parser.add_argument('-f', '--fetch', action='store_true', + help='fetch a bintool from a known location (or: all/missing)') + tool_parser.add_argument('bintools', type=str, nargs='*') + return parser.parse_args(argv) diff --git a/tools/binman/control.py b/tools/binman/control.py index e0d2b3879d8..5b10f192360 100644 --- a/tools/binman/control.py +++ b/tools/binman/control.py @@ -14,6 +14,7 @@ import re import sys from patman import tools +from binman import bintool from binman import cbfs_util from binman import elf from patman import command @@ -487,6 +488,7 @@ def PrepareImagesAndDtbs(dtb_fname, select_images, update_fdt, use_expanded): # without changing the device-tree size, thus ensuring that our # entry offsets remain the same. for image in images.values(): + image.CollectBintools() image.ExpandEntries() if update_fdt: image.AddMissingProperties(True) @@ -606,7 +608,7 @@ def Binman(args): from binman.image import Image from binman import state - if args.cmd in ['ls', 'extract', 'replace']: + if args.cmd in ['ls', 'extract', 'replace', 'tool']: try: tout.Init(args.verbosity) tools.PrepareOutputDir(None) @@ -621,6 +623,19 @@ def Binman(args): ReplaceEntries(args.image, args.filename, args.indir, args.paths, do_compress=not args.compressed, allow_resize=not args.fix_size, write_map=args.map) + + if args.cmd == 'tool': + tools.SetToolPaths(args.toolpath) + if args.list: + bintool.Bintool.list_all() + elif args.fetch: + if not args.bintools: + raise ValueError( + "Please specify bintools to fetch or 'all' or 'missing'") + bintool.Bintool.fetch_tools(bintool.FETCH_ANY, + args.bintools) + else: + raise ValueError("Invalid arguments to 'tool' subcommand") except: raise finally: diff --git a/tools/binman/entry.py b/tools/binman/entry.py index e4a1f2d5d5c..9cd900670e1 100644 --- a/tools/binman/entry.py +++ b/tools/binman/entry.py @@ -10,6 +10,7 @@ import os import pathlib import sys +from binman import bintool from dtoc import fdt_util from patman import tools from patman.tools import ToHex, ToHexSize @@ -74,6 +75,7 @@ class Entry(object): allow_fake: Allow creating a dummy fake file if the blob file is not available. This is mainly used for testing. external: True if this entry contains an external binary blob + bintools: Bintools used by this entry (only populated for Image) """ def __init__(self, section, etype, node, name_prefix=''): # Put this here to allow entry-docs and help to work without libfdt @@ -105,6 +107,7 @@ class Entry(object): self.external = False self.allow_missing = False self.allow_fake = False + self.bintools = {} @staticmethod def FindEntryClass(etype, expanded): @@ -1065,3 +1068,22 @@ features to produce new behaviours. value: Help text """ pass + + def AddBintools(self, tools): + """Add the bintools used by this entry type + + Args: + tools (dict of Bintool): + """ + pass + + @classmethod + def AddBintool(self, tools, name): + """Add a new bintool to the tools used by this etype + + Args: + name: Name of the tool + """ + btool = bintool.Bintool.create(name) + tools[name] = btool + return btool diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py index fdd4cbb21ad..221a64cd032 100644 --- a/tools/binman/etype/section.py +++ b/tools/binman/etype/section.py @@ -880,3 +880,7 @@ class Entry_section(Entry): def CheckAltFormats(self, alt_formats): for entry in self._entries.values(): entry.CheckAltFormats(alt_formats) + + def AddBintools(self, tools): + for entry in self._entries.values(): + entry.AddBintools(tools) diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index ac6aabbf9c3..179326c42a3 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -18,6 +18,7 @@ import sys import tempfile import unittest +from binman import bintool from binman import cbfs_util from binman import cmdline from binman import control diff --git a/tools/binman/image.py b/tools/binman/image.py index f0a7d65299e..0f0c1d29e80 100644 --- a/tools/binman/image.py +++ b/tools/binman/image.py @@ -82,6 +82,7 @@ class Image(section.Entry_section): self.missing_etype = missing_etype self.use_expanded = use_expanded self.test_section_timeout = False + self.bintools = {} if not test: self.ReadNode() @@ -394,3 +395,16 @@ class Image(section.Entry_section): self._CollectEntries(entries, entries_by_name, self) return self.LookupSymbol(sym_name, optional, msg, base_addr, entries_by_name) + + def CollectBintools(self): + """Collect all the bintools used by this image + + Returns: + Dict of bintools: + key: name of tool + value: Bintool object + """ + bintools = {} + super().AddBintools(bintools) + self.bintools = bintools + return bintools -- 2.34.1.575.g55b058a8bb-goog