1 // SPDX-License-Identifier: GPL-2.0
3 * Verified Boot for Embedded (VBE) loading firmware phases
5 * Copyright 2022 Google LLC
9 #define LOG_CATEGORY LOGC_BOOT
14 #include <version_string.h>
15 #include <dm/device-internal.h>
16 #include "vbe_simple.h"
18 int vbe_simple_fixup_node(ofnode node, struct simple_state *state)
20 const char *version, *str;
23 version = strdup(state->fw_version);
25 return log_msg_ret("dup", -ENOMEM);
27 ret = ofnode_write_string(node, "cur-version", version);
29 return log_msg_ret("ver", ret);
30 ret = ofnode_write_u32(node, "cur-vernum", state->fw_vernum);
32 return log_msg_ret("num", ret);
34 /* Drop the 'U-Boot ' at the start */
36 if (!strncmp("U-Boot ", str, 7))
38 ret = ofnode_write_string(node, "bootloader-version", str);
40 return log_msg_ret("bl", ret);
46 * bootmeth_vbe_simple_ft_fixup() - Write out all VBE simple data to the DT
48 * @ctx: Context for event
49 * @event: Event to process
50 * @return 0 if OK, -ve on error
52 static int bootmeth_vbe_simple_ft_fixup(void *ctx, struct event *event)
54 oftree tree = event->data.ft_fixup.tree;
58 * Ideally we would have driver model support for fixups, but that does
59 * not exist yet. It is a step too far to try to do this before VBE is
62 for (vbe_find_first_device(&dev); dev; vbe_find_next_device(&dev)) {
63 struct simple_state state;
64 ofnode node, subnode, chosen;
67 if (strcmp("vbe_simple", dev->driver->name))
70 /* Check if there is a node to fix up, adding if not */
71 chosen = oftree_path(tree, "/chosen");
72 if (!ofnode_valid(chosen))
75 ret = device_probe(dev);
78 * This should become an error when VBE is updated to
79 * only bind this device when a node exists
81 log_debug("VBE device '%s' failed to probe (err=%d)",
86 ret = ofnode_add_subnode(chosen, "fwupd", &node);
87 if (ret && ret != -EEXIST)
88 return log_msg_ret("fwu", ret);
90 ret = ofnode_add_subnode(node, dev->name, &subnode);
91 if (ret && ret != -EEXIST)
92 return log_msg_ret("dev", ret);
94 /* Copy over the vbe properties for fwupd */
95 log_debug("Fixing up: %s\n", dev->name);
96 ret = ofnode_copy_props(subnode, dev_ofnode(dev));
98 return log_msg_ret("cp", ret);
100 ret = vbe_simple_read_state(dev, &state);
102 return log_msg_ret("read", ret);
104 ret = vbe_simple_fixup_node(subnode, &state);
106 return log_msg_ret("fix", ret);
111 EVENT_SPY_FULL(EVT_FT_FIXUP, bootmeth_vbe_simple_ft_fixup);