From patchwork Fri Sep 9 15:18:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1676122 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=L4luedTw; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MPKSy5jT3z1yhP for ; Sat, 10 Sep 2022 01:21:06 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id F3B1184BBC; Fri, 9 Sep 2022 17:19:21 +0200 (CEST) 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="L4luedTw"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 23C1084B89; Fri, 9 Sep 2022 17:19:00 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oo1-xc33.google.com (mail-oo1-xc33.google.com [IPv6:2607:f8b0:4864:20::c33]) (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 0C42C84B6B for ; Fri, 9 Sep 2022 17:18:56 +0200 (CEST) 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-oo1-xc33.google.com with SMTP id c22-20020a4a4f16000000b00474a44441c8so293483oob.7 for ; Fri, 09 Sep 2022 08:18:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=x7O19AfEasIvQ+xvvCpUPQYe3OcePuZ+FtKp/73FtfM=; b=L4luedTwC+Z9dYXDITh9os3w0U/j5e3CR+gPs5tXftG2xXbx9rhuNN2387FbHYXCsu IGzir7qjIYD5/iNz7+PIONYtIHxOO8zpga5RWw6lMZnTAlVXu+zcCNl7ii7dNLJI/fnf 4MvU47v5f5U5IH0U63fIdT+qNo753GrwzK4xk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=x7O19AfEasIvQ+xvvCpUPQYe3OcePuZ+FtKp/73FtfM=; b=hENhf2xpAoXEXpHz8EsS/SdFbkKWBF04SnrZ1WE+p8Bdwbp2JROvUTQLUFcBcZyQmt Ohhj6pNCglpVuIiUDJQPB/lONbmY80TmyNj0cTlcOSkBf1EbZ92peP2czpkiVREBwbRW wxs+fPWAbtjhpmh+wcNAEmqZdoNoD8k/TB9lb+ZFZVkggJH+qs6fvVYJFJdnGEGz/+2k DIaaon5Q+U7rYIJcKexDe28lHzIBc9y0x4JCLAD1DV0K8sNMDJ4GooWXFpu4MX5YfmqX LqYBJ9HKsiYqVA55YwTA4uROqgCAKr3h/F4z2Msyc7uTwLF8wPeMyzNX2NPxgj5k6UH/ opVw== X-Gm-Message-State: ACgBeo0HZ7gQLZ8jxAIPabU5FgCDJb7dncCLKA1gddjFbyFdwAprUNq8 TrrxNjdaZ5vsyqVzZbGxv4N6cFPTyMnaRQ== X-Google-Smtp-Source: AA6agR4s8GAjwyePE45pGBWkZOyyTm//vM2D9EAq0IidO4GrmVOSYlLQjzJlV/4mMIMuokvnYyEVgg== X-Received: by 2002:a4a:be06:0:b0:472:9d27:695e with SMTP id l6-20020a4abe06000000b004729d27695emr1948209oop.36.1662736734125; Fri, 09 Sep 2022 08:18:54 -0700 (PDT) Received: from sjg1.roam.corp.google.com (c-67-190-102-125.hsd1.co.comcast.net. [67.190.102.125]) by smtp.gmail.com with ESMTPSA id eq22-20020a056870a91600b0012779ba00fesm591977oab.2.2022.09.09.08.18.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Sep 2022 08:18:53 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass Subject: [PATCH 14/14] vbe: Add a test for VBE device tree fixups Date: Fri, 9 Sep 2022 09:18:01 -0600 Message-Id: <20220909151801.336551-15-sjg@chromium.org> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220909151801.336551-1-sjg@chromium.org> References: <20220909151801.336551-1-sjg@chromium.org> MIME-Version: 1.0 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.6 at phobos.denx.de X-Virus-Status: Clean When a FIT includes some OS requests, U-Boot should process these and add the requested info to corresponding subnodes of the /chosen node. Add a pytest for this, which sets up the FIT, runs bootm and then uses a C unit test to check that everything looks OK. The test needs to run on sandbox_flattree since we don't support device tree fixups on sandbox (live tree) yet. So enable BOOTMETH_VBE and disable bootflow_system(), since EFI is not supported on sandbox_flattree. Add a link to the initial documentation. Signed-off-by: Simon Glass --- configs/sandbox_flattree_defconfig | 2 +- doc/develop/vbe.rst | 3 +- test/boot/Makefile | 1 + test/boot/bootflow.c | 2 + test/boot/vbe_fixup.c | 59 ++++++++++++++ test/py/tests/fit_util.py | 5 +- test/py/tests/test_vbe.py | 123 +++++++++++++++++++++++++++++ 7 files changed, 192 insertions(+), 3 deletions(-) create mode 100644 test/boot/vbe_fixup.c create mode 100644 test/py/tests/test_vbe.py diff --git a/configs/sandbox_flattree_defconfig b/configs/sandbox_flattree_defconfig index a8b439faa96..58fd4ad6395 100644 --- a/configs/sandbox_flattree_defconfig +++ b/configs/sandbox_flattree_defconfig @@ -11,7 +11,6 @@ CONFIG_DISTRO_DEFAULTS=y CONFIG_FIT=y CONFIG_FIT_SIGNATURE=y CONFIG_FIT_VERBOSE=y -# CONFIG_BOOTMETH_VBE is not set CONFIG_BOOTSTAGE=y CONFIG_BOOTSTAGE_REPORT=y CONFIG_BOOTSTAGE_FDT=y @@ -83,6 +82,7 @@ CONFIG_REGMAP=y CONFIG_SYSCON=y CONFIG_DEVRES=y CONFIG_DEBUG_DEVRES=y +CONFIG_OFNODE_MULTI_TREE=y CONFIG_ADC=y CONFIG_ADC_SANDBOX=y CONFIG_SYS_SATA_MAX_DEVICE=2 diff --git a/doc/develop/vbe.rst b/doc/develop/vbe.rst index 8f147fd9360..cca193c8fd4 100644 --- a/doc/develop/vbe.rst +++ b/doc/develop/vbe.rst @@ -19,8 +19,9 @@ listing methods and getting the status for a method. For a detailed overview of VBE, see vbe-intro_. A fuller description of bootflows is at vbe-bootflows_ and the firmware-update mechanism is described at -vbe-fwupdate_. +vbe-fwupdate_. VBE OS requests are described at vbe-osrequests_. .. _vbe-intro: https://docs.google.com/document/d/e/2PACX-1vQjXLPWMIyVktaTMf8edHZYDrEvMYD_iNzIj1FgPmKF37fpglAC47Tt5cvPBC5fvTdoK-GA5Zv1wifo/pub .. _vbe-bootflows: https://docs.google.com/document/d/e/2PACX-1vR0OzhuyRJQ8kdeOibS3xB1rVFy3J4M_QKTM5-3vPIBNcdvR0W8EXu9ymG-yWfqthzWoM4JUNhqwydN/pub .. _vbe-fwupdate: https://docs.google.com/document/d/e/2PACX-1vTnlIL17vVbl6TVoTHWYMED0bme7oHHNk-g5VGxblbPiKIdGDALE1HKId8Go5f0g1eziLsv4h9bocbk/pub +.. _vbe-osrequests: https://docs.google.com/document/d/e/2PACX-1vTHhxX7WSZe68i9rAkW-DHdx6koU-jxYHhamLhZn9GQ9QT2_epSBosMV1_r7yPHOXZccx71rF_t0PXL/pub diff --git a/test/boot/Makefile b/test/boot/Makefile index 9e9d5ae21f3..5bb3f889759 100644 --- a/test/boot/Makefile +++ b/test/boot/Makefile @@ -7,3 +7,4 @@ obj-$(CONFIG_BOOTSTD) += bootdev.o bootstd_common.o bootflow.o bootmeth.o ifdef CONFIG_OF_LIVE obj-$(CONFIG_BOOTMETH_VBE_SIMPLE) += vbe_simple.o endif +obj-$(CONFIG_BOOTMETH_VBE) += vbe_fixup.o diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c index 85305234e01..1e8ea754bcd 100644 --- a/test/boot/bootflow.c +++ b/test/boot/bootflow.c @@ -329,6 +329,8 @@ static int bootflow_system(struct unit_test_state *uts) { struct udevice *dev; + if (!IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR)) + return 0; ut_assertok(uclass_get_device_by_name(UCLASS_BOOTMETH, "efi_mgr", &dev)); sandbox_set_fake_efi_mgr_dev(dev, true); diff --git a/test/boot/vbe_fixup.c b/test/boot/vbe_fixup.c new file mode 100644 index 00000000000..1b488e25ab6 --- /dev/null +++ b/test/boot/vbe_fixup.c @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test for VBE device tree fix-ups + * + * Copyright 2022 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include +#include +#include +#include "bootstd_common.h" + +/* Basic test of reading nvdata and updating a fwupd node in the device tree */ +static int vbe_test_fixup(struct unit_test_state *uts) +{ + ofnode chosen, node; + const char *data; + oftree tree; + int size; + + /* + * This test works when called from test_vbe.py and it must use the + * flat tree, since device tree fix-ups do not yet support live tree. + */ + if (!working_fdt) + return 0; + + tree = oftree_from_fdt(working_fdt); + ut_assert(oftree_valid(tree)); + + chosen = oftree_path(tree, "/chosen"); + ut_assert(ofnode_valid(chosen)); + + /* check the things set up for the FIT in test_vbe.py */ + node = ofnode_find_subnode(chosen, "random"); + + /* ignore if this test is run on its own */ + if (!ofnode_valid(node)) + return 0; + data = ofnode_read_prop(node, "data", &size); + ut_asserteq(0x40, size); + + node = ofnode_find_subnode(chosen, "aslr2"); + ut_assert(ofnode_valid(node)); + data = ofnode_read_prop(node, "data", &size); + ut_asserteq(4, size); + + node = ofnode_find_subnode(chosen, "efi-runtime"); + ut_assert(ofnode_valid(node)); + data = ofnode_read_prop(node, "data", &size); + ut_asserteq(4, size); + + return 0; +} +BOOTSTD_TEST(vbe_test_fixup, + UT_TESTF_DM | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE); diff --git a/test/py/tests/fit_util.py b/test/py/tests/fit_util.py index fcec4c43c3c..79718d431a0 100644 --- a/test/py/tests/fit_util.py +++ b/test/py/tests/fit_util.py @@ -36,7 +36,7 @@ def make_its(cons, base_its, params, basename='test.its'): print(base_its % params, file=outf) return its -def make_fit(cons, mkimage, base_its, params, basename='test.fit'): +def make_fit(cons, mkimage, base_its, params, basename='test.fit', base_fdt=None): """Make a sample .fit file ready for loading This creates a .its script with the selected parameters and uses mkimage to @@ -55,6 +55,9 @@ def make_fit(cons, mkimage, base_its, params, basename='test.fit'): fit = make_fname(cons, basename) its = make_its(cons, base_its, params) util.run_and_log(cons, [mkimage, '-f', its, fit]) + if base_fdt: + with open(make_fname(cons, 'u-boot.dts'), 'w') as fd: + fd.write(base_fdt) return fit def make_kernel(cons, basename, text): diff --git a/test/py/tests/test_vbe.py b/test/py/tests/test_vbe.py new file mode 100644 index 00000000000..559c2918868 --- /dev/null +++ b/test/py/tests/test_vbe.py @@ -0,0 +1,123 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright 2022 Google LLC +# +# Test addition of VBE + +import pytest + +import fit_util + +# Define a base ITS which we can adjust using % and a dictionary +base_its = ''' +/dts-v1/; + +/ { + description = "Example kernel"; + + images { + kernel-1 { + data = /incbin/("%(kernel)s"); + type = "kernel"; + arch = "sandbox"; + os = "linux"; + load = <0x40000>; + entry = <0x8>; + compression = "%(compression)s"; + + random { + compatible = "vbe,random-rand"; + vbe,size = <0x40>; + vbe,required; + }; + aslr1 { + compatible = "vbe,aslr-move"; + vbe,align = <0x100000>; + }; + aslr2 { + compatible = "vbe,aslr-rand"; + }; + efi-runtime { + compatible = "vbe,efi-runtime-rand"; + }; + wibble { + compatible = "vbe,wibble"; + }; + }; + + fdt-1 { + description = "snow"; + data = /incbin/("%(fdt)s"); + type = "flat_dt"; + arch = "sandbox"; + load = <%(fdt_addr)#x>; + compression = "%(compression)s"; + }; + }; + configurations { + default = "conf-1"; + conf-1 { + kernel = "kernel-1"; + fdt = "fdt-1"; + }; + }; +}; +''' + +# Define a base FDT - currently we don't use anything in this +base_fdt = ''' +/dts-v1/; + +/ { + chosen { + }; +}; +''' + +# This is the U-Boot script that is run for each test. First load the FIT, +# then run the 'bootm' command, then run the unit test which checks that the +# working tree has the required things filled in according to the OS requests +# above (random, aslr2, etc.) +base_script = ''' +host load hostfs 0 %(fit_addr)x %(fit)s +fdt addr %(fit_addr)x +bootm start %(fit_addr)x +bootm loados +bootm prep +fdt addr +fdt print +ut bootstd vbe_test_fixup +''' + +@pytest.mark.boardspec('sandbox_flattree') +@pytest.mark.requiredtool('dtc') +def test_vbe(u_boot_console): + cons = u_boot_console + kernel = fit_util.make_kernel(cons, 'vbe-kernel.bin', 'kernel') + fdt = fit_util.make_dtb(cons, base_fdt, 'vbe-fdt') + fdt_out = fit_util.make_fname(cons, 'fdt-out.dtb') + + params = { + 'fit_addr' : 0x1000, + + 'kernel' : kernel, + + 'fdt' : fdt, + 'fdt_out' : fdt_out, + 'fdt_addr' : 0x80000, + 'fdt_size' : 0x1000, + + 'compression' : 'none', + } + mkimage = cons.config.build_dir + '/tools/mkimage' + fit = fit_util.make_fit(cons, mkimage, base_its, params, 'test-vbe.fit', + base_fdt) + params['fit'] = fit + cmd = base_script % params + + with cons.log.section('Kernel load'): + output = cons.run_command_list(cmd.splitlines()) + + # This is a little wonky since there are two tests running in CI. The final + # one is the 'ut bootstd' command above + failures = [line for line in output if 'Failures' in line] + assert len(failures) >= 1 and 'Failures: 0' in failures[-1]