]> Git Repo - J-u-boot.git/blob - boot/vbe_simple_os.c
Revert "Merge patch series "vbe: Series part E""
[J-u-boot.git] / boot / vbe_simple_os.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Verified Boot for Embedded (VBE) loading firmware phases
4  *
5  * Copyright 2022 Google LLC
6  * Written by Simon Glass <[email protected]>
7  */
8
9 #define LOG_CATEGORY LOGC_BOOT
10
11 #include <dm.h>
12 #include <bootflow.h>
13 #include <vbe.h>
14 #include <version_string.h>
15 #include <dm/device-internal.h>
16 #include "vbe_simple.h"
17
18 int vbe_simple_fixup_node(ofnode node, struct simple_state *state)
19 {
20         const char *version, *str;
21         int ret;
22
23         version = strdup(state->fw_version);
24         if (!version)
25                 return log_msg_ret("dup", -ENOMEM);
26
27         ret = ofnode_write_string(node, "cur-version", version);
28         if (ret)
29                 return log_msg_ret("ver", ret);
30         ret = ofnode_write_u32(node, "cur-vernum", state->fw_vernum);
31         if (ret)
32                 return log_msg_ret("num", ret);
33
34         /* Drop the 'U-Boot ' at the start */
35         str = version_string;
36         if (!strncmp("U-Boot ", str, 7))
37                 str += 7;
38         ret = ofnode_write_string(node, "bootloader-version", str);
39         if (ret)
40                 return log_msg_ret("bl", ret);
41
42         return 0;
43 }
44
45 /**
46  * bootmeth_vbe_simple_ft_fixup() - Write out all VBE simple data to the DT
47  *
48  * @ctx: Context for event
49  * @event: Event to process
50  * @return 0 if OK, -ve on error
51  */
52 static int bootmeth_vbe_simple_ft_fixup(void *ctx, struct event *event)
53 {
54         oftree tree = event->data.ft_fixup.tree;
55         struct udevice *dev;
56
57         /*
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
60          * in place.
61          */
62         for (vbe_find_first_device(&dev); dev; vbe_find_next_device(&dev)) {
63                 struct simple_state state;
64                 ofnode node, subnode, chosen;
65                 int ret;
66
67                 if (strcmp("vbe_simple", dev->driver->name))
68                         continue;
69
70                 /* Check if there is a node to fix up, adding if not */
71                 chosen = oftree_path(tree, "/chosen");
72                 if (!ofnode_valid(chosen))
73                         continue;
74
75                 ret = device_probe(dev);
76                 if (ret) {
77                         /*
78                          * This should become an error when VBE is updated to
79                          * only bind this device when a node exists
80                          */
81                         log_debug("VBE device '%s' failed to probe (err=%d)",
82                                   dev->name, ret);
83                         return 0;
84                 }
85
86                 ret = ofnode_add_subnode(chosen, "fwupd", &node);
87                 if (ret && ret != -EEXIST)
88                         return log_msg_ret("fwu", ret);
89
90                 ret = ofnode_add_subnode(node, dev->name, &subnode);
91                 if (ret && ret != -EEXIST)
92                         return log_msg_ret("dev", ret);
93
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));
97                 if (ret)
98                         return log_msg_ret("cp", ret);
99
100                 ret = vbe_simple_read_state(dev, &state);
101                 if (ret)
102                         return log_msg_ret("read", ret);
103
104                 ret = vbe_simple_fixup_node(subnode, &state);
105                 if (ret)
106                         return log_msg_ret("fix", ret);
107         }
108
109         return 0;
110 }
111 EVENT_SPY_FULL(EVT_FT_FIXUP, bootmeth_vbe_simple_ft_fixup);
This page took 0.030006 seconds and 4 git commands to generate.