"Das U-Boot" Source Tree
1/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Standard U-Boot boot framework
4 *
5 * Copyright 2021 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
7 */
8
9#ifndef __bootstd_h
10#define __bootstd_h
11
12#include <alist.h>
13#include <dm/ofnode_decl.h>
14#include <linux/list.h>
15#include <linux/types.h>
16
17struct udevice;
18
19/**
20 * struct bootstd_priv - priv data for the bootstd driver
21 *
22 * This is attached to the (only) bootstd device, so there is only one instance
23 * of this struct. It provides overall information about bootdevs and bootflows.
24 *
25 * @prefixes: NULL-terminated list of prefixes to use for bootflow filenames,
26 * e.g. "/", "/boot/"; NULL if none
27 * @bootdev_order: Order to use for bootdevs (or NULL if none), with each item
28 * being a bootdev label, e.g. "mmc2", "mmc1" (NULL terminated)
29 * @env_order: Order as specified by the boot_targets env var (or NULL if none),
30 * with each item being a bootdev label, e.g. "mmc2", "mmc1" (NULL
31 * terminated)
32 * @cur_bootdev: Currently selected bootdev (for commands)
33 * @cur_bootflow: Currently selected bootflow (for commands)
34 * @bootflows: (struct bootflow) Global list of all bootflows across all
35 * bootdevs
36 * @bootmeth_count: Number of bootmeth devices in @bootmeth_order
37 * @bootmeth_order: List of bootmeth devices to use, in order, NULL-terminated
38 * @vbe_bootmeth: Currently selected VBE bootmeth, NULL if none
39 * @theme: Node containing the theme information
40 * @hunters_used: Bitmask of used hunters, indexed by their position in the
41 * linker list. The bit is set if the hunter has been used already
42 */
43struct bootstd_priv {
44 const char **prefixes;
45 const char **bootdev_order;
46 const char **env_order;
47 struct udevice *cur_bootdev;
48 struct bootflow *cur_bootflow;
49 struct alist bootflows;
50 int bootmeth_count;
51 struct udevice **bootmeth_order;
52 struct udevice *vbe_bootmeth;
53 ofnode theme;
54 uint hunters_used;
55};
56
57/**
58 * bootstd_get_bootdev_order() - Get the boot-order list
59 *
60 * This reads the boot order, e.g. {"mmc0", "mmc2", NULL}
61 *
62 * The list is alloced by the bootstd driver so should not be freed. That is the
63 * reason for all the const stuff in the function signature
64 *
65 * @dev: bootstd device
66 * @okp: returns true if OK, false if out of memory
67 * Return: list of string pointers, terminated by NULL; or NULL if no boot
68 * order. Note that this returns NULL in the case of an empty list
69 */
70const char *const *const bootstd_get_bootdev_order(struct udevice *dev,
71 bool *okp);
72
73/**
74 * bootstd_get_prefixes() - Get the filename-prefixes list
75 *
76 * This reads the prefixes, e.g. {"/", "/boot", NULL}
77 *
78 * The list is alloced by the bootstd driver so should not be freed. That is the
79 * reason for all the const stuff in the function signature
80 *
81 * Return: list of string points, terminated by NULL; or NULL if no boot order
82 */
83const char *const *const bootstd_get_prefixes(struct udevice *dev);
84
85/**
86 * bootstd_get_priv() - Get the (single) state for the bootstd system
87 *
88 * The state holds a global list of all bootflows that have been found.
89 *
90 * Return: 0 if OK, -ve if the uclass does not exist
91 */
92int bootstd_get_priv(struct bootstd_priv **stdp);
93
94/**
95 * bootstd_try_priv() - Try to get the (single) state for the bootstd system
96 *
97 * The state holds a global list of all bootflows that have been found. This
98 * function returns the state if available, but takes care not to create the
99 * device (or uclass) if it doesn't exist.
100 *
101 * This function is safe to use in the 'unbind' path. It will always return NULL
102 * unless the bootstd device is probed and ready, e.g. bootstd_get_priv() has
103 * previously been called.
104 *
105 * TODO(sjg@chromium.org): Consider adding a bootstd pointer to global_data
106 *
107 * Return: pointer if the device exists, else NULL
108 */
109struct bootstd_priv *bootstd_try_priv(void);
110
111/**
112 * bootstd_clear_glob() - Clear the global list of bootflows
113 *
114 * This removes all bootflows globally and across all bootdevs.
115 */
116void bootstd_clear_glob(void);
117
118/**
119 * bootstd_prog_boot() - Run standard boot in a fully programmatic mode
120 *
121 * Attempts to boot without making any use of U-Boot commands
122 *
123 * Returns: -ve error value (does not return except on failure to boot)
124 */
125int bootstd_prog_boot(void);
126
127/**
128 * bootstd_add_bootflow() - Add a bootflow to the global list
129 *
130 * All fields in @bflow must be set up. Note that @bflow->dev is used to add the
131 * bootflow to that device.
132 *
133 * The bootflow is also added to the global list of all bootflows
134 *
135 * @dev: Bootdev device to add to
136 * @bflow: Bootflow to add. Note that fields within bflow must be allocated
137 * since this function takes over ownership of these. This functions makes
138 * a copy of @bflow itself (without allocating its fields again), so the
139 * caller must dispose of the memory used by the @bflow pointer itself
140 * Return: element number in the list, if OK, -ENOMEM if out of memory
141 */
142int bootstd_add_bootflow(struct bootflow *bflow);
143
144/**
145 * bootstd_clear_bootflows_for_bootdev() - Clear bootflows from a bootdev
146 *
147 * Each bootdev maintains a list of discovered bootflows. This provides a
148 * way to clear it. These bootflows are removed from the global list too.
149 *
150 * @dev: bootdev device to update
151 */
152int bootstd_clear_bootflows_for_bootdev(struct udevice *dev);
153
154#endif