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 31690C54EE9 for ; Sun, 25 Sep 2022 15:10:54 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B982B84DBF; Sun, 25 Sep 2022 17:05:28 +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="KZgPmJB2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 30F0784D77; Sun, 25 Sep 2022 17:04:10 +0200 (CEST) Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) (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 85787848C2 for ; Sun, 25 Sep 2022 17:04:06 +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-io1-xd2d.google.com with SMTP id r134so3416866iod.8 for ; Sun, 25 Sep 2022 08:04:06 -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=vgPemOC43azJDZCKducfSX7/maMDIR6PBLUxMsxm3Z0=; b=KZgPmJB2GSpIp4p5BdZyTLHJJxuBqLvQR3v/KSBFWsh9w9f+zGRweOTIc9eZlhJpNR I6sk/jFMiNY70aYES2nWPUVhYbKu1SQZj15syBPg64BDDcGgJpiVyF86uBktX8K/xW9L l0onZUqYJs9g1Ywd7CQ6aBVK+Fuc5/1bEDweU= 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=vgPemOC43azJDZCKducfSX7/maMDIR6PBLUxMsxm3Z0=; b=ogEk/wDmWkr+1m2BA5rCzGYnXFKjIb7wxsHapH9y3eL4BCRvkcs73Xzlh7Vpqi4r7F QGC56MuRwSJ0kr7jGeuAJ+pCqTxiTLqRcShw3dNqFSBV9FU1dRedXW+bS9zlrAYsLp6x 8CCXacwIBj2nOPAAyyRIZTk9Y1jwM85TEoay+bxj5umEmhsf9y1EuBHPftClRXK907oY wrZCiFfvwvD4vrFce7mm5QWb+Ae1Fpef4rRGKl//SUUSkiaFGYWfU5Nn0IjVcHy35eXF PiGfODCiFd5YLqAPQWWW1M/BkosYdQLzHJj9s/AklA0+X3x8cA5QyluR2krVrzX8eNQ7 Cb6A== X-Gm-Message-State: ACrzQf3MKHi3/j1AyQVGFGXPlX2+h4fMFnEWKYtovO+tWiPLktmKbcuJ xBBN+dft1qMXf6IjE9+TOL1rhtNiAn/7CA== X-Google-Smtp-Source: AMsMyM4eLMR9Bj3r+EhxJ++iG7f6110dgX/zB+dXUozkRH0oshyiQJJA1dcuQ1GS2AK0vJ4HnnLtBw== X-Received: by 2002:a05:6602:2a47:b0:6a2:a5d9:c5f2 with SMTP id k7-20020a0566022a4700b006a2a5d9c5f2mr7816878iov.131.1664118227519; Sun, 25 Sep 2022 08:03:47 -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 u19-20020a926013000000b002f19d9838c6sm5360578ilb.25.2022.09.25.08.03.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Sep 2022 08:03:47 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Simon Glass , Artem Lapkin , Heinrich Schuchardt , John Keeping Subject: [PATCH 35/45] vbe: Move OS implementation into a separate file Date: Sun, 25 Sep 2022 09:02:38 -0600 Message-Id: <20220925150248.2524421-36-sjg@chromium.org> X-Mailer: git-send-email 2.37.3.998.g577e59143f-goog In-Reply-To: <20220925150248.2524421-1-sjg@chromium.org> References: <20220925150248.2524421-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.6 at phobos.denx.de X-Virus-Status: Clean Move this into its own file so it can be built only by U-Boot proper. Signed-off-by: Simon Glass --- boot/Makefile | 1 + boot/vbe_simple.c | 102 +------------------------------ boot/vbe_simple.h | 34 +++++++++++ boot/vbe_simple_os.c | 89 +++++++++++++++++++++++++++ test/py/tests/test_event_dump.py | 1 - 5 files changed, 126 insertions(+), 101 deletions(-) create mode 100644 boot/vbe_simple_os.c diff --git a/boot/Makefile b/boot/Makefile index e5c27900ea7..f0c31549213 100644 --- a/boot/Makefile +++ b/boot/Makefile @@ -50,3 +50,4 @@ endif obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE) += vbe.o vbe_request.o obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE) += vbe_simple.o obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE_FW) += vbe_simple_fw.o +obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE_OS) += vbe_simple_os.o diff --git a/boot/vbe_simple.c b/boot/vbe_simple.c index 1ccd416e4bb..59676d8613f 100644 --- a/boot/vbe_simple.c +++ b/boot/vbe_simple.c @@ -17,37 +17,11 @@ #include #include #include -#include #include #include #include #include "vbe_simple.h" -enum { - MAX_VERSION_LEN = 256, - - NVD_HDR_VER_SHIFT = 0, - NVD_HDR_VER_MASK = 0xf, - NVD_HDR_SIZE_SHIFT = 4, - NVD_HDR_SIZE_MASK = 0xf << NVD_HDR_SIZE_SHIFT, - - /* Firmware key-version is in the top 16 bits of fw_ver */ - FWVER_KEY_SHIFT = 16, - FWVER_FW_MASK = 0xffff, - - NVD_HDR_VER_CUR = 1, /* current version */ -}; - -/** struct simple_state - state information read from media - * - * @fw_version: Firmware version string - * @fw_vernum: Firmware version number - */ -struct simple_state { - char fw_version[MAX_VERSION_LEN]; - u32 fw_vernum; -}; - /** struct simple_nvdata - storage format for non-volatile data */ struct simple_nvdata { u8 crc8; @@ -116,7 +90,7 @@ static int simple_read_nvdata(struct udevice *dev, struct blk_desc *desc, return 0; } -static int simple_read_state(struct udevice *dev, struct simple_state *state) +int vbe_simple_read_state(struct udevice *dev, struct simple_state *state) { ALLOC_CACHE_ALIGN_BUFFER(u8, buf, MMC_MAX_BLOCK_LEN); struct simple_priv *priv = dev_get_priv(dev); @@ -157,7 +131,7 @@ static int vbe_simple_get_state_desc(struct udevice *dev, char *buf, struct simple_state state; int ret; - ret = simple_read_state(dev, &state); + ret = vbe_simple_read_state(dev, &state); if (ret) return log_msg_ret("read", ret); @@ -206,78 +180,6 @@ static struct bootmeth_ops bootmeth_vbe_simple_ops = { .read_file = vbe_simple_read_file, }; -int vbe_simple_fixup_node(ofnode node, struct simple_state *state) -{ - char *version; - int ret; - - version = strdup(state->fw_version); - if (!version) - return log_msg_ret("dup", -ENOMEM); - - ret = ofnode_write_string(node, "cur-version", version); - if (ret) - return log_msg_ret("ver", ret); - ret = ofnode_write_u32(node, "cur-vernum", state->fw_vernum); - if (ret) - return log_msg_ret("num", ret); - ret = ofnode_write_string(node, "bootloader-version", version_string); - if (ret) - return log_msg_ret("bl", ret); - - return 0; -} - -/** - * bootmeth_vbe_simple_ft_fixup() - Write out all VBE simple data to the DT - * - * @ctx: Context for event - * @event: Event to process - * @return 0 if OK, -ve on error - */ -static int bootmeth_vbe_simple_ft_fixup(void *ctx, struct event *event) -{ - oftree tree = event->data.ft_fixup.tree; - struct udevice *dev; - - /* - * Ideally we would have driver model support for fixups, but that does - * not exist yet. It is a step too far to try to do this before VBE is - * in place. - */ - for (vbe_find_first_device(&dev); dev; vbe_find_next_device(&dev)) { - struct simple_state state; - ofnode node, subnode; - int ret; - - if (strcmp("vbe_simple", dev->driver->name)) - continue; - - /* Check if there is a node to fix up */ - node = oftree_path(tree, "/chosen/fwupd"); - if (!ofnode_valid(node)) - continue; - subnode = ofnode_find_subnode(node, dev->name); - if (!ofnode_valid(subnode)) - continue; - - log_debug("Fixing up: %s\n", dev->name); - ret = device_probe(dev); - if (ret) - return log_msg_ret("probe", ret); - ret = simple_read_state(dev, &state); - if (ret) - return log_msg_ret("read", ret); - - ret = vbe_simple_fixup_node(subnode, &state); - if (ret) - return log_msg_ret("fix", ret); - } - - return 0; -} -EVENT_SPY(EVT_FT_FIXUP, bootmeth_vbe_simple_ft_fixup); - static int bootmeth_vbe_simple_probe(struct udevice *dev) { struct simple_priv *priv = dev_get_priv(dev); diff --git a/boot/vbe_simple.h b/boot/vbe_simple.h index e37a9fae379..56d319206f2 100644 --- a/boot/vbe_simple.h +++ b/boot/vbe_simple.h @@ -9,6 +9,21 @@ #ifndef __VBE_SIMPLE_H #define __VBE_SIMPLE_H +enum { + MAX_VERSION_LEN = 256, + + NVD_HDR_VER_SHIFT = 0, + NVD_HDR_VER_MASK = 0xf, + NVD_HDR_SIZE_SHIFT = 4, + NVD_HDR_SIZE_MASK = 0xf << NVD_HDR_SIZE_SHIFT, + + /* Firmware key-version is in the top 16 bits of fw_ver */ + FWVER_KEY_SHIFT = 16, + FWVER_FW_MASK = 0xffff, + + NVD_HDR_VER_CUR = 1, /* current version */ +}; + /** struct simple_priv - information read from the device tree */ struct simple_priv { u32 area_start; @@ -21,6 +36,16 @@ struct simple_priv { const char *storage; }; +/** struct simple_state - state information read from media + * + * @fw_version: Firmware version string + * @fw_vernum: Firmware version number + */ +struct simple_state { + char fw_version[MAX_VERSION_LEN]; + u32 fw_vernum; +}; + /** * vbe_simple_read_fw_bootflow() - Read a bootflow for firmware * @@ -34,4 +59,13 @@ struct simple_priv { */ int vbe_simple_read_bootflow_fw(struct udevice *dev, struct bootflow *bflow); +/** + * vbe_simple_read_state() - Read the VBE simple state information + * + * @dev: VBE bootmeth + * @state: Place to put the state + * @return 0 if OK, -ve on error + */ +int vbe_simple_read_state(struct udevice *dev, struct simple_state *state); + #endif /* __VBE_SIMPLE_H */ diff --git a/boot/vbe_simple_os.c b/boot/vbe_simple_os.c new file mode 100644 index 00000000000..7761b9ef656 --- /dev/null +++ b/boot/vbe_simple_os.c @@ -0,0 +1,89 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Verified Boot for Embedded (VBE) loading firmware phases + * + * Copyright 2022 Google LLC + * Written by Simon Glass + */ + +#define LOG_CATEGORY LOGC_BOOT + +#include +#include +#include +#include +#include +#include +#include "vbe_simple.h" + +int vbe_simple_fixup_node(ofnode node, struct simple_state *state) +{ + char *version; + int ret; + + version = strdup(state->fw_version); + if (!version) + return log_msg_ret("dup", -ENOMEM); + + ret = ofnode_write_string(node, "cur-version", version); + if (ret) + return log_msg_ret("ver", ret); + ret = ofnode_write_u32(node, "cur-vernum", state->fw_vernum); + if (ret) + return log_msg_ret("num", ret); + ret = ofnode_write_string(node, "bootloader-version", version_string); + if (ret) + return log_msg_ret("bl", ret); + + return 0; +} + +/** + * bootmeth_vbe_simple_ft_fixup() - Write out all VBE simple data to the DT + * + * @ctx: Context for event + * @event: Event to process + * @return 0 if OK, -ve on error + */ +static int bootmeth_vbe_simple_ft_fixup(void *ctx, struct event *event) +{ + oftree tree = event->data.ft_fixup.tree; + struct udevice *dev; + + /* + * Ideally we would have driver model support for fixups, but that does + * not exist yet. It is a step too far to try to do this before VBE is + * in place. + */ + for (vbe_find_first_device(&dev); dev; vbe_find_next_device(&dev)) { + struct simple_state state; + ofnode node, subnode; + int ret; + + if (strcmp("vbe_simple", dev->driver->name)) + continue; + + /* Check if there is a node to fix up */ + node = oftree_path(tree, "/chosen/fwupd"); + if (!ofnode_valid(node)) + continue; + subnode = ofnode_find_subnode(node, dev->name); + if (!ofnode_valid(subnode)) + continue; + + log_debug("Fixing up: %s\n", dev->name); + ret = device_probe(dev); + if (ret) + return log_msg_ret("probe", ret); + ret = simple_read_state(dev, &state); + if (ret) + return log_msg_ret("read", ret); + + ret = vbe_simple_fixup_node(subnode, &state); + if (ret) + return log_msg_ret("fix", ret); + } + + return 0; +} +EVENT_SPY(EVT_FT_FIXUP, bootmeth_vbe_simple_ft_fixup); diff --git a/test/py/tests/test_event_dump.py b/test/py/tests/test_event_dump.py index 46d6384eb3a..5da2e191dfa 100644 --- a/test/py/tests/test_event_dump.py +++ b/test/py/tests/test_event_dump.py @@ -17,6 +17,5 @@ def test_event_dump(u_boot_console): expect = '''.*Event type Id Source location -------------------- ------------------------------ ------------------------------ EVT_FT_FIXUP bootmeth_vbe_ft_fixup .*boot/vbe_request.c:.* -EVT_FT_FIXUP bootmeth_vbe_simple_ft_fixup .*boot/vbe_simple.c:.* EVT_MISC_INIT_F sandbox_misc_init_f .*arch/sandbox/cpu/start.c:''' assert re.match(expect, out, re.MULTILINE) is not None -- 2.37.3.998.g577e59143f-goog