From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Tom Rini <trini@konsulko.com>, Simon Glass <sjg@chromium.org>,
Artem Lapkin <email2tema@gmail.com>,
Heinrich Schuchardt <xypron.glpk@gmx.de>,
John Keeping <john@metanate.com>
Subject: [PATCH 35/45] vbe: Move OS implementation into a separate file
Date: Sun, 25 Sep 2022 09:02:38 -0600 [thread overview]
Message-ID: <20220925150248.2524421-36-sjg@chromium.org> (raw)
In-Reply-To: <20220925150248.2524421-1-sjg@chromium.org>
Move this into its own file so it can be built only by U-Boot proper.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
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 <memalign.h>
#include <mmc.h>
#include <vbe.h>
-#include <version_string.h>
#include <dm/device-internal.h>
#include <dm/ofnode.h>
#include <u-boot/crc.h>
#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 <sjg@chromium.org>
+ */
+
+#define LOG_CATEGORY LOGC_BOOT
+
+#include <common.h>
+#include <dm.h>
+#include <bootflow.h>
+#include <vbe.h>
+#include <version_string.h>
+#include <dm/device-internal.h>
+#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
next prev parent reply other threads:[~2022-09-25 15:10 UTC|newest]
Thread overview: 72+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-25 15:02 [PATCH 00/45] vbe: Implement the full firmware flow Simon Glass
2022-09-25 15:02 ` [PATCH 01/45] Rename CONFIG_SYS_TEXT_BASE to CONFIG_TEXT_BASE Simon Glass
2022-09-25 15:02 ` [PATCH 02/45] disk: Drop debug messages in part_efi Simon Glass
2022-09-26 6:11 ` Heinrich Schuchardt
2022-09-25 15:02 ` [PATCH 03/45] bloblist: Drop debugging Simon Glass
2022-09-25 15:02 ` [PATCH 04/45] rsa: Avoid warning in padding_pss_verify() Simon Glass
2022-09-26 6:23 ` Heinrich Schuchardt
2022-09-25 15:02 ` [PATCH 05/45] spl: Use binman suffix allow symbols of any SPL etype Simon Glass
2022-09-25 15:02 ` [PATCH 06/45] spl: Split up the board_init_r() function Simon Glass
2022-09-25 15:02 ` [PATCH 07/45] spl: Refactor controls for console output Simon Glass
2022-09-29 15:16 ` Tom Rini
2022-09-25 15:02 ` [PATCH 08/45] spl: Add a separate silence option for SPL Simon Glass
2022-09-25 15:02 ` [PATCH 09/45] CI: Install pyelftools for builds Simon Glass
2022-09-26 6:29 ` Heinrich Schuchardt
2022-09-28 10:20 ` Simon Glass
2022-09-29 15:05 ` Tom Rini
2022-09-29 23:55 ` Simon Glass
2022-09-30 12:56 ` Tom Rini
2022-09-30 13:28 ` Simon Glass
2022-09-25 15:02 ` [PATCH 10/45] binman: Allow obtaining a symbol value Simon Glass
2022-09-25 15:02 ` [PATCH 11/45] binman: Split out looking up a symbol into a function Simon Glass
2022-09-25 15:02 ` [PATCH 12/45] binman: Handle writing ELF symbols in the Entry class Simon Glass
2022-09-25 15:02 ` [PATCH 13/45] binman: Support writing symbols into ELF files Simon Glass
2022-09-25 15:02 ` [PATCH 14/45] dm: blk: Add udevice functions Simon Glass
2022-09-26 0:17 ` AKASHI Takahiro
2022-09-28 10:20 ` Simon Glass
2022-09-29 0:51 ` AKASHI Takahiro
2022-09-29 2:35 ` Simon Glass
2022-09-30 1:54 ` AKASHI Takahiro
2022-09-25 15:02 ` [PATCH 15/45] dm: usb: Update the test to cover reading and writing Simon Glass
2022-09-25 15:02 ` [PATCH 16/45] dm: blk: mmc: Tidy up some Makefile rules for SPL Simon Glass
2022-09-25 15:02 ` [PATCH 17/45] dm: mmc: Allow sandbox emulator to build without writes Simon Glass
2022-09-25 15:02 ` [PATCH 18/45] sandbox: Drop message about writing sandbox state Simon Glass
2022-09-26 6:31 ` Heinrich Schuchardt
2022-09-25 15:02 ` [PATCH 19/45] sandbox: Generalise SPL booting Simon Glass
2022-09-25 15:02 ` [PATCH 20/45] sandbox: Add a way to specify the sandbox executable Simon Glass
2022-09-26 6:49 ` Heinrich Schuchardt
2022-11-07 23:35 ` Simon Glass
2022-09-25 15:02 ` [PATCH 21/45] bootstd: Add a way to set up a bootflow Simon Glass
2022-09-25 15:02 ` [PATCH 22/45] image: Move comment for fit_conf_find_compat() Simon Glass
2022-09-26 6:54 ` Heinrich Schuchardt
2022-09-25 15:02 ` [PATCH 23/45] test: Report skippped tests Simon Glass
2022-09-25 15:02 ` [PATCH 24/45] test: Update tests to use the skip feature Simon Glass
2022-09-25 15:02 ` [PATCH 25/45] test: Support tests which can only be run manually Simon Glass
2022-09-26 6:56 ` Heinrich Schuchardt
2022-09-28 10:20 ` Simon Glass
2022-09-25 15:02 ` [PATCH 26/45] image: Add the concept of a phase to FIT Simon Glass
2022-09-25 15:02 ` [PATCH 27/45] image: Allow loading a FIT config for a particular phase Simon Glass
2022-09-25 15:02 ` [PATCH 28/45] image: Correct strncpy() warning with image_set_name() Simon Glass
2022-09-25 15:02 ` [PATCH 29/45] vbe: Rename vbe_fixup to vbe_request Simon Glass
2022-09-25 15:02 ` [PATCH 30/45] vbe: Use a warning for a failed requests Simon Glass
2022-09-25 15:02 ` [PATCH 31/45] spl: Allow multiple loaders of the same type Simon Glass
2022-09-30 16:28 ` Tom Rini
2022-09-30 16:37 ` Simon Glass
2022-09-30 16:39 ` Tom Rini
2022-09-30 16:45 ` Simon Glass
2022-09-30 16:50 ` Tom Rini
2022-09-30 16:55 ` Simon Glass
2022-09-25 15:02 ` [PATCH 32/45] sandbox: Support obtaining the next phase from an image Simon Glass
2022-09-25 15:02 ` [PATCH 33/45] vbe: Support selecting operations by SPL phase Simon Glass
2022-09-25 15:02 ` [PATCH 34/45] vbe: Support reading the next SPL phase via VBE Simon Glass
2022-09-25 15:02 ` Simon Glass [this message]
2022-09-25 15:02 ` [PATCH 36/45] vbe: Drop the U-Boot prefix from the version Simon Glass
2022-09-25 15:02 ` [PATCH 37/45] vbe: Add Kconfig options for VPL Simon Glass
2022-09-25 15:02 ` [PATCH 38/45] vbe: Add info about the VBE device to the fwupd node Simon Glass
2022-09-25 15:02 ` [PATCH 39/45] sandbox: Add a binman image for VPL Simon Glass
2022-09-25 15:02 ` [PATCH 40/45] vbe: Correct pylint warnings in test_vbe Simon Glass
2022-09-25 15:02 ` [PATCH 41/45] vbe: Use a manual test Simon Glass
2022-09-25 15:02 ` [PATCH 42/45] vbe: Record which phases loaded using VBE Simon Glass
2022-09-25 15:02 ` [PATCH 43/45] vbe: Add docs and a test for the VBE command Simon Glass
2022-09-25 15:02 ` [PATCH 44/45] vbe: Add a subcommand to show the VBE state Simon Glass
2022-09-25 15:02 ` [PATCH 45/45] vbe: Add a test for the VBE flow into U-Boot proper Simon Glass
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220925150248.2524421-36-sjg@chromium.org \
--to=sjg@chromium.org \
--cc=email2tema@gmail.com \
--cc=john@metanate.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=xypron.glpk@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).