1 // SPDX-License-Identifier: GPL-2.0+
3 * Uclass implementation for standard boot
5 * Copyright 2021 Google LLC
15 #include <dm/device-internal.h>
18 #include <dm/uclass-internal.h>
20 DECLARE_GLOBAL_DATA_PTR;
22 /* These are used if filename-prefixes is not present */
23 const char *const default_prefixes[] = {"/", "/boot/", NULL};
25 static int bootstd_of_to_plat(struct udevice *dev)
27 struct bootstd_priv *priv = dev_get_priv(dev);
30 if (IS_ENABLED(CONFIG_BOOTSTD_FULL)) {
31 /* Don't check errors since livetree and flattree are different */
32 ret = dev_read_string_list(dev, "filename-prefixes",
34 dev_read_string_list(dev, "bootdev-order",
35 &priv->bootdev_order);
37 priv->theme = ofnode_find_subnode(dev_ofnode(dev), "theme");
43 static void bootstd_clear_glob_(struct bootstd_priv *priv)
45 while (!list_empty(&priv->glob_head)) {
46 struct bootflow *bflow;
48 bflow = list_first_entry(&priv->glob_head, struct bootflow,
50 bootflow_remove(bflow);
54 void bootstd_clear_glob(void)
56 struct bootstd_priv *std;
58 if (bootstd_get_priv(&std))
61 bootstd_clear_glob_(std);
64 static int bootstd_remove(struct udevice *dev)
66 struct bootstd_priv *priv = dev_get_priv(dev);
69 free(priv->bootdev_order);
70 bootstd_clear_glob_(priv);
75 const char *const *const bootstd_get_bootdev_order(struct udevice *dev,
78 struct bootstd_priv *std = dev_get_priv(dev);
79 const char *targets = env_get("boot_targets");
82 log_debug("- targets %s %p\n", targets, std->bootdev_order);
83 if (targets && *targets) {
84 str_free_list(std->env_order);
85 std->env_order = str_to_list(targets);
86 if (!std->env_order) {
90 return std->env_order;
93 return std->bootdev_order;
96 const char *const *const bootstd_get_prefixes(struct udevice *dev)
98 struct bootstd_priv *std = dev_get_priv(dev);
100 return std->prefixes ? std->prefixes : default_prefixes;
103 int bootstd_get_priv(struct bootstd_priv **stdp)
108 ret = uclass_first_device_err(UCLASS_BOOTSTD, &dev);
111 *stdp = dev_get_priv(dev);
116 static int bootstd_probe(struct udevice *dev)
118 struct bootstd_priv *std = dev_get_priv(dev);
120 INIT_LIST_HEAD(&std->glob_head);
125 /* For now, bind the boormethod device if none are found in the devicetree */
126 int dm_scan_other(bool pre_reloc_only)
128 struct driver *drv = ll_entry_start(struct driver, driver);
129 const int n_ents = ll_entry_count(struct driver, driver);
130 struct udevice *dev, *bootstd;
133 /* These are not needed before relocation */
134 if (!(gd->flags & GD_FLG_RELOC))
137 /* Create a bootstd device if needed */
138 uclass_find_first_device(UCLASS_BOOTSTD, &bootstd);
140 ret = device_bind_driver(gd->dm_root, "bootstd_drv", "bootstd",
143 return log_msg_ret("bootstd", ret);
146 /* If there are no bootmeth devices, create them */
147 uclass_find_first_device(UCLASS_BOOTMETH, &dev);
151 for (i = 0; i < n_ents; i++, drv++) {
152 if (drv->id == UCLASS_BOOTMETH) {
153 const char *name = drv->name;
155 if (!strncmp("bootmeth_", name, 9))
157 ret = device_bind(bootstd, drv, name, 0, ofnode_null(),
160 return log_msg_ret("meth", ret);
167 static const struct udevice_id bootstd_ids[] = {
168 { .compatible = "u-boot,boot-std" },
172 U_BOOT_DRIVER(bootstd_drv) = {
173 .id = UCLASS_BOOTSTD,
174 .name = "bootstd_drv",
175 .of_to_plat = bootstd_of_to_plat,
176 .probe = bootstd_probe,
177 .remove = bootstd_remove,
178 .of_match = bootstd_ids,
179 .priv_auto = sizeof(struct bootstd_priv),
182 UCLASS_DRIVER(bootstd) = {
183 .id = UCLASS_BOOTSTD,
185 #if CONFIG_IS_ENABLED(OF_REAL)
186 .post_bind = dm_scan_fdt_dev,