blob: 480cf8a5af1ab0fe1f39eb7f2755de29d5e39401 [file] [log] [blame]
Simon Glassa16d87d2022-04-24 23:31:05 -06001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright 2021 Google LLC
4 * Written by Simon Glass <sjg@chromium.org>
5 */
6
7#ifndef __bootflow_h
8#define __bootflow_h
9
Simon Glassc2a16c92024-11-15 16:19:13 -070010#include <alist.h>
Simon Glass660a9952023-01-17 10:48:11 -070011#include <bootdev.h>
Simon Glassc2a16c92024-11-15 16:19:13 -070012#include <image.h>
Simon Glassd92bcc42023-01-06 08:52:42 -060013#include <dm/ofnode_decl.h>
Simon Glassa16d87d2022-04-24 23:31:05 -060014#include <linux/list.h>
15
Simon Glass0a2f6a32023-01-06 08:52:40 -060016struct bootstd_priv;
17struct expo;
18
Simon Glasscb2a5cd2023-01-17 10:48:17 -070019enum {
20 BOOTFLOW_MAX_USED_DEVS = 16,
21};
22
Simon Glassa16d87d2022-04-24 23:31:05 -060023/**
24 * enum bootflow_state_t - states that a particular bootflow can be in
25 *
26 * Only bootflows in state BOOTFLOWST_READY can be used to boot.
27 *
28 * See bootflow_state[] for the names for each of these
29 */
30enum bootflow_state_t {
31 BOOTFLOWST_BASE, /**< Nothing known yet */
32 BOOTFLOWST_MEDIA, /**< Media exists */
33 BOOTFLOWST_PART, /**< Partition exists */
34 BOOTFLOWST_FS, /**< Filesystem exists */
35 BOOTFLOWST_FILE, /**< Bootflow file exists */
36 BOOTFLOWST_READY, /**< Bootflow file loaded */
37
38 BOOTFLOWST_COUNT
39};
40
41/**
Simon Glassca84dc82023-02-22 12:17:04 -070042 * enum bootflow_flags_t - flags for bootflows
43 *
44 * @BOOTFLOWF_USE_PRIOR_FDT: Indicates that an FDT was not found by the bootmeth
45 * and it is using the prior-stage FDT, which is the U-Boot control FDT.
46 * This is only possible with the EFI bootmeth (distro-efi) and only when
47 * CONFIG_OF_HAS_PRIOR_STAGE is enabled
Simon Glass254c9342023-11-15 18:35:23 -070048 * @BOOTFLOWF_STATIC_BUF: Indicates that @bflow->buf is statically set, rather
49 * than being allocated by malloc().
Shantur Rathoreaab9cdb2023-11-19 16:55:00 +000050 * @BOOTFLOWF_USE_BUILTIN_FDT : Indicates that current bootflow uses built-in FDT
Simon Glassca84dc82023-02-22 12:17:04 -070051 */
52enum bootflow_flags_t {
53 BOOTFLOWF_USE_PRIOR_FDT = 1 << 0,
Simon Glass254c9342023-11-15 18:35:23 -070054 BOOTFLOWF_STATIC_BUF = 1 << 1,
Shantur Rathoreaab9cdb2023-11-19 16:55:00 +000055 BOOTFLOWF_USE_BUILTIN_FDT = 1 << 2,
Simon Glassca84dc82023-02-22 12:17:04 -070056};
57
58/**
Simon Glassa16d87d2022-04-24 23:31:05 -060059 * struct bootflow - information about a bootflow
60 *
Simon Glass199f5882024-11-15 16:19:12 -070061 * All bootflows are listed in bootstd's bootflow alist in struct bootstd_priv
Simon Glassa16d87d2022-04-24 23:31:05 -060062 *
Quentin Schulz21a6aec2024-06-12 16:58:49 +020063 * @dev: Bootdev device which produced this bootflow, NULL for flows created by
64 * BOOTMETHF_GLOBAL bootmeths
Simon Glassa16d87d2022-04-24 23:31:05 -060065 * @blk: Block device which contains this bootflow, NULL if this is a network
Simon Glass4adeeb82023-01-17 10:47:59 -070066 * device or sandbox 'host' device
Simon Glassa16d87d2022-04-24 23:31:05 -060067 * @part: Partition number (0 for whole device)
68 * @fs_type: Filesystem type (FS_TYPE...) if this is fixed by the media, else 0.
69 * For example, the sandbox host-filesystem bootdev sets this to
70 * FS_TYPE_SANDBOX
71 * @method: Bootmethod device used to perform the boot and read files
72 * @name: Name of bootflow (allocated)
73 * @state: Current state (enum bootflow_state_t)
74 * @subdir: Subdirectory to fetch files from (with trailing /), or NULL if none
75 * @fname: Filename of bootflow file (allocated)
Simon Glass612b9cc2023-01-06 08:52:34 -060076 * @logo: Logo to display for this bootflow (BMP format)
77 * @logo_size: Size of the logo in bytes
Simon Glass254c9342023-11-15 18:35:23 -070078 * @buf: Bootflow file contents (allocated unless @flags & BOOTFLOWF_STATIC_BUF)
Simon Glassa16d87d2022-04-24 23:31:05 -060079 * @size: Size of bootflow file in bytes
80 * @err: Error number received (0 if OK)
Simon Glass72b7b192023-01-06 08:52:33 -060081 * @os_name: Name of the OS / distro being booted, or NULL if not known
82 * (allocated)
Simon Glass7b8c6342023-01-17 10:47:56 -070083 * @fdt_fname: Filename of FDT file
84 * @fdt_size: Size of FDT file
85 * @fdt_addr: Address of loaded fdt
Simon Glassca84dc82023-02-22 12:17:04 -070086 * @flags: Flags for the bootflow (see enum bootflow_flags_t)
Simon Glass33927522023-07-12 09:04:34 -060087 * @cmdline: OS command line, or NULL if not known (allocated)
Simon Glass63398b02023-07-12 09:04:36 -060088 * @x86_setup: Pointer to x86 setup block inside @buf, NULL if not present
Simon Glass7f75f232023-07-30 11:16:56 -060089 * @bootmeth_priv: Private data for the bootmeth
Simon Glassc2a16c92024-11-15 16:19:13 -070090 * @images: List of loaded images (struct bootstd_img)
Simon Glassa16d87d2022-04-24 23:31:05 -060091 */
92struct bootflow {
Simon Glassa16d87d2022-04-24 23:31:05 -060093 struct udevice *dev;
94 struct udevice *blk;
95 int part;
96 int fs_type;
97 struct udevice *method;
98 char *name;
99 enum bootflow_state_t state;
100 char *subdir;
101 char *fname;
Simon Glass612b9cc2023-01-06 08:52:34 -0600102 void *logo;
103 uint logo_size;
Simon Glassa16d87d2022-04-24 23:31:05 -0600104 char *buf;
105 int size;
106 int err;
Simon Glass72b7b192023-01-06 08:52:33 -0600107 char *os_name;
Simon Glass7b8c6342023-01-17 10:47:56 -0700108 char *fdt_fname;
109 int fdt_size;
110 ulong fdt_addr;
Simon Glassca84dc82023-02-22 12:17:04 -0700111 int flags;
Simon Glass33927522023-07-12 09:04:34 -0600112 char *cmdline;
Simon Glass5495aaf2023-07-30 11:17:00 -0600113 void *x86_setup;
Simon Glass7f75f232023-07-30 11:16:56 -0600114 void *bootmeth_priv;
Simon Glassc2a16c92024-11-15 16:19:13 -0700115 struct alist images;
Simon Glassa16d87d2022-04-24 23:31:05 -0600116};
117
118/**
Simon Glassc2a16c92024-11-15 16:19:13 -0700119 * bootflow_img_t: Supported image types
120 *
121 * This uses image_type_t for most types, but extends it
122 *
123 * @BFI_EXTLINUX_CFG: extlinux configuration-file
124 * @BFI_LOGO: logo image
125 * @BFI_EFI: EFI PE image
126 * @BFI_CMDLINE: OS command-line string
127 */
128enum bootflow_img_t {
129 BFI_FIRST = IH_TYPE_COUNT,
130 BFI_EXTLINUX_CFG = BFI_FIRST,
131 BFI_LOGO,
132 BFI_EFI,
133 BFI_CMDLINE,
134
135 BFI_COUNT,
136};
137
138/**
139 * struct bootflow_img - Information about an image which has been loaded
140 *
141 * This keeps track of a single, loaded image.
142 *
143 * @fname: Filename used to load the image (allocated)
144 * @type: Image type (IH_TYPE_...)
145 * @addr: Address to which the image was loaded, 0 if not yet loaded
146 * @size: Size of the image
147 */
148struct bootflow_img {
149 char *fname;
150 enum bootflow_img_t type;
151 ulong addr;
152 ulong size;
153};
154
155/**
Simon Glass99e68182023-02-22 12:17:03 -0700156 * enum bootflow_iter_flags_t - flags for the bootflow iterator
Simon Glassa16d87d2022-04-24 23:31:05 -0600157 *
Simon Glass99e68182023-02-22 12:17:03 -0700158 * @BOOTFLOWIF_FIXED: Only used fixed/internal media
159 * @BOOTFLOWIF_SHOW: Show each bootdev before scanning it; show each hunter
Simon Glassa21e7752023-01-17 10:48:06 -0700160 * before using it
Simon Glass99e68182023-02-22 12:17:03 -0700161 * @BOOTFLOWIF_ALL: Return bootflows with errors as well
162 * @BOOTFLOWIF_HUNT: Hunt for new bootdevs using the bootdrv hunters
Simon Glassa21e7752023-01-17 10:48:06 -0700163 *
164 * Internal flags:
Simon Glass99e68182023-02-22 12:17:03 -0700165 * @BOOTFLOWIF_SINGLE_DEV: (internal) Just scan one bootdev
166 * @BOOTFLOWIF_SKIP_GLOBAL: (internal) Don't scan global bootmeths
167 * @BOOTFLOWIF_SINGLE_UCLASS: (internal) Keep scanning through all devices in
Simon Glassde567b12023-01-17 10:48:09 -0700168 * this uclass (used with things like "mmc")
Simon Glass99e68182023-02-22 12:17:03 -0700169 * @BOOTFLOWIF_SINGLE_MEDIA: (internal) Scan one media device in the uclass (used
Simon Glassde567b12023-01-17 10:48:09 -0700170 * with things like "mmc1")
Nam Caocb0d3fb2024-02-21 13:41:44 +0100171 * @BOOTFLOWIF_SINGLE_PARTITION: (internal) Scan one partition in media device
172 * (used with things like "mmc1:3")
Simon Glassa16d87d2022-04-24 23:31:05 -0600173 */
Simon Glass99e68182023-02-22 12:17:03 -0700174enum bootflow_iter_flags_t {
175 BOOTFLOWIF_FIXED = 1 << 0,
176 BOOTFLOWIF_SHOW = 1 << 1,
177 BOOTFLOWIF_ALL = 1 << 2,
178 BOOTFLOWIF_HUNT = 1 << 3,
Simon Glassa21e7752023-01-17 10:48:06 -0700179
180 /*
181 * flags used internally by standard boot - do not set these when
182 * calling bootflow_scan_bootdev() etc.
183 */
Simon Glass99e68182023-02-22 12:17:03 -0700184 BOOTFLOWIF_SINGLE_DEV = 1 << 16,
185 BOOTFLOWIF_SKIP_GLOBAL = 1 << 17,
186 BOOTFLOWIF_SINGLE_UCLASS = 1 << 18,
187 BOOTFLOWIF_SINGLE_MEDIA = 1 << 19,
Nam Caocb0d3fb2024-02-21 13:41:44 +0100188 BOOTFLOWIF_SINGLE_PARTITION = 1 << 20,
Simon Glassa16d87d2022-04-24 23:31:05 -0600189};
190
191/**
Simon Glasse22fe922023-01-17 10:48:05 -0700192 * enum bootflow_meth_flags_t - flags controlling which bootmeths are used
193 *
194 * Used during iteration, e.g. by bootdev_find_by_label(), to determine which
195 * bootmeths are used for the current bootdev. The flags reset when the bootdev
196 * changes
197 *
198 * @BOOTFLOW_METHF_DHCP_ONLY: Only use dhcp (scripts and EFI)
199 * @BOOTFLOW_METHF_PXE_ONLY: Only use pxe (PXE boot)
Simon Glassde567b12023-01-17 10:48:09 -0700200 * @BOOTFLOW_METHF_SINGLE_DEV: Scan only a single bootdev (used for labels like
201 * "3"). This is used if a sequence number is provided instead of a label
202 * @BOOTFLOW_METHF_SINGLE_UCLASS: Scan all bootdevs in this one uclass (used
203 * with things like "mmc"). If this is not set, then the bootdev has an integer
204 * value in the label (like "mmc2")
Simon Glasse22fe922023-01-17 10:48:05 -0700205 */
206enum bootflow_meth_flags_t {
207 BOOTFLOW_METHF_DHCP_ONLY = 1 << 0,
208 BOOTFLOW_METHF_PXE_ONLY = 1 << 1,
Simon Glassde567b12023-01-17 10:48:09 -0700209 BOOTFLOW_METHF_SINGLE_DEV = 1 << 2,
210 BOOTFLOW_METHF_SINGLE_UCLASS = 1 << 3,
Simon Glasse22fe922023-01-17 10:48:05 -0700211};
212
213/**
Simon Glassa16d87d2022-04-24 23:31:05 -0600214 * struct bootflow_iter - state for iterating through bootflows
215 *
216 * This starts at with the first bootdev/partition/bootmeth and can be used to
217 * iterate through all of them.
218 *
219 * Iteration starts with the bootdev. The first partition (0, i.e. whole device)
220 * is scanned first. For partition 0, it iterates through all the available
221 * bootmeths to see which one(s) can provide a bootflow. Then it moves to
222 * parition 1 (if there is one) and the process continues. Once all partitions
223 * are examined, it moves to the next bootdev.
224 *
225 * Initially @max_part is 0, meaning that only the whole device (@part=0) can be
226 * used. During scanning, if a partition table is found, then @max_part is
227 * updated to a larger value, no less than the number of available partitions.
228 * This ensures that iteration works through all partitions on the bootdev.
229 *
Simon Glass99e68182023-02-22 12:17:03 -0700230 * @flags: Flags to use (see enum bootflow_iter_flags_t). If
231 * BOOTFLOWIF_GLOBAL_FIRST is enabled then the global bootmeths are being
232 * scanned, otherwise we have moved onto the bootdevs
Simon Glass484e4072023-01-17 10:48:14 -0700233 * @dev: Current bootdev, NULL if none. This is only ever updated in
234 * bootflow_iter_set_dev()
Simon Glassa16d87d2022-04-24 23:31:05 -0600235 * @part: Current partition number (0 for whole device)
236 * @method: Current bootmeth
237 * @max_part: Maximum hardware partition number in @dev, 0 if there is no
238 * partition table
Simon Glass64cbc5c2023-01-17 10:47:42 -0700239 * @first_bootable: First bootable partition, or 0 if none
Simon Glassa16d87d2022-04-24 23:31:05 -0600240 * @err: Error obtained from checking the last iteration. This is used to skip
241 * forward (e.g. to skip the current partition because it is not valid)
242 * -ESHUTDOWN: try next bootdev
Simon Glasscb2a5cd2023-01-17 10:48:17 -0700243 * @num_devs: Number of bootdevs in @dev_used
244 * @max_devs: Maximum number of entries in @dev_used
245 * @dev_used: List of bootdevs used during iteration
Simon Glassac06b26a2023-01-17 10:48:10 -0700246 * @labels: List of labels to scan for bootdevs
247 * @cur_label: Current label being processed
Simon Glassa16d87d2022-04-24 23:31:05 -0600248 * @num_methods: Number of bootmeth devices in @method_order
249 * @cur_method: Current method number, an index into @method_order
Simon Glass73fcf512022-07-30 15:52:25 -0600250 * @first_glob_method: First global method, if any, else -1
Simon Glass660a9952023-01-17 10:48:11 -0700251 * @cur_prio: Current priority being scanned
Simon Glass73fcf512022-07-30 15:52:25 -0600252 * @method_order: List of bootmeth devices to use, in order. The normal methods
253 * appear first, then the global ones, if any
254 * @doing_global: true if we are iterating through the global bootmeths (which
255 * happens before the normal ones)
Simon Glass30fbeb52023-01-17 10:47:58 -0700256 * @method_flags: flags controlling which methods should be used for this @dev
257 * (enum bootflow_meth_flags_t)
Simon Glassa16d87d2022-04-24 23:31:05 -0600258 */
259struct bootflow_iter {
260 int flags;
261 struct udevice *dev;
262 int part;
263 struct udevice *method;
264 int max_part;
Simon Glass64cbc5c2023-01-17 10:47:42 -0700265 int first_bootable;
Simon Glassa16d87d2022-04-24 23:31:05 -0600266 int err;
267 int num_devs;
Simon Glasscb2a5cd2023-01-17 10:48:17 -0700268 int max_devs;
269 struct udevice *dev_used[BOOTFLOW_MAX_USED_DEVS];
Simon Glassac06b26a2023-01-17 10:48:10 -0700270 const char *const *labels;
271 int cur_label;
Simon Glassa16d87d2022-04-24 23:31:05 -0600272 int num_methods;
273 int cur_method;
Simon Glass73fcf512022-07-30 15:52:25 -0600274 int first_glob_method;
Simon Glass660a9952023-01-17 10:48:11 -0700275 enum bootdev_prio_t cur_prio;
Simon Glassa16d87d2022-04-24 23:31:05 -0600276 struct udevice **method_order;
Simon Glass73fcf512022-07-30 15:52:25 -0600277 bool doing_global;
Simon Glass30fbeb52023-01-17 10:47:58 -0700278 int method_flags;
Simon Glassa16d87d2022-04-24 23:31:05 -0600279};
280
281/**
Simon Glass00501fc2022-10-20 18:22:51 -0600282 * bootflow_init() - Set up a bootflow struct
283 *
284 * The bootflow is zeroed and set to state BOOTFLOWST_BASE
285 *
286 * @bflow: Struct to set up
287 * @bootdev: Bootdev to use
288 * @meth: Bootmeth to use
289 */
290void bootflow_init(struct bootflow *bflow, struct udevice *bootdev,
291 struct udevice *meth);
292
293/**
Simon Glassa16d87d2022-04-24 23:31:05 -0600294 * bootflow_iter_init() - Reset a bootflow iterator
295 *
296 * This sets everything to the starting point, ready for use.
297 *
298 * @iter: Place to store private info (inited by this call)
Simon Glass99e68182023-02-22 12:17:03 -0700299 * @flags: Flags to use (see enum bootflow_iter_flags_t)
Simon Glassa16d87d2022-04-24 23:31:05 -0600300 */
301void bootflow_iter_init(struct bootflow_iter *iter, int flags);
302
303/**
304 * bootflow_iter_uninit() - Free memory used by an interator
305 *
306 * @iter: Iterator to free
307 */
308void bootflow_iter_uninit(struct bootflow_iter *iter);
309
310/**
Simon Glass03fcbf92022-04-24 23:31:09 -0600311 * bootflow_iter_drop_bootmeth() - Remove a bootmeth from an iterator
312 *
313 * Update the iterator so that the bootmeth will not be used again while this
314 * iterator is in use
315 *
316 * @iter: Iterator to update
317 * @bmeth: Boot method to remove
318 */
319int bootflow_iter_drop_bootmeth(struct bootflow_iter *iter,
320 const struct udevice *bmeth);
321
322/**
Simon Glass5d3d44f2023-01-17 10:48:16 -0700323 * bootflow_scan_first() - find the first bootflow for a device or label
Simon Glassa16d87d2022-04-24 23:31:05 -0600324 *
Simon Glass99e68182023-02-22 12:17:03 -0700325 * If @flags includes BOOTFLOWIF_ALL then bootflows with errors are returned too
Simon Glassa16d87d2022-04-24 23:31:05 -0600326 *
327 * @dev: Boot device to scan, NULL to work through all of them until it
Simon Glass943d38c2022-07-30 15:52:24 -0600328 * finds one that can supply a bootflow
Simon Glassba3d5372023-01-17 10:48:15 -0700329 * @label: Label to control the scan, NULL to work through all devices
330 * until it finds one that can supply a bootflow
Simon Glassa16d87d2022-04-24 23:31:05 -0600331 * @iter: Place to store private info (inited by this call)
Simon Glass99e68182023-02-22 12:17:03 -0700332 * @flags: Flags for iterator (enum bootflow_iter_flags_t). Note that if
333 * @dev is NULL, then BOOTFLOWIF_SKIP_GLOBAL is set automatically by this
334 * function
Simon Glassa16d87d2022-04-24 23:31:05 -0600335 * @bflow: Place to put the bootflow if found
336 * Return: 0 if found, -ENODEV if no device, other -ve on other error
337 * (iteration can continue)
338 */
Simon Glass5d3d44f2023-01-17 10:48:16 -0700339int bootflow_scan_first(struct udevice *dev, const char *label,
340 struct bootflow_iter *iter, int flags,
Simon Glassa16d87d2022-04-24 23:31:05 -0600341 struct bootflow *bflow);
342
343/**
344 * bootflow_scan_next() - find the next bootflow
345 *
346 * This works through the available bootdev devices until it finds one that
347 * can supply a bootflow. It then returns that bootflow
348 *
349 * @iter: Private info (as set up by bootflow_scan_first())
350 * @bflow: Place to put the bootflow if found
351 * Return: 0 if found, -ENODEV if no device, -ESHUTDOWN if no more bootflows,
352 * other -ve on other error (iteration can continue)
353 */
354int bootflow_scan_next(struct bootflow_iter *iter, struct bootflow *bflow);
355
356/**
357 * bootflow_first_glob() - Get the first bootflow from the global list
358 *
359 * Returns the first bootflow in the global list, no matter what bootflow it is
360 * attached to
361 *
362 * @bflowp: Returns a pointer to the bootflow
363 * Return: 0 if found, -ENOENT if there are no bootflows
364 */
365int bootflow_first_glob(struct bootflow **bflowp);
366
367/**
368 * bootflow_next_glob() - Get the next bootflow from the global list
369 *
370 * Returns the next bootflow in the global list, no matter what bootflow it is
371 * attached to
372 *
373 * @bflowp: On entry, the last bootflow returned , e.g. from
374 * bootflow_first_glob()
375 * Return: 0 if found, -ENOENT if there are no more bootflows
376 */
377int bootflow_next_glob(struct bootflow **bflowp);
378
379/**
380 * bootflow_free() - Free memory used by a bootflow
381 *
382 * This frees fields within @bflow, but not the @bflow pointer itself
383 */
384void bootflow_free(struct bootflow *bflow);
385
386/**
387 * bootflow_boot() - boot a bootflow
388 *
389 * @bflow: Bootflow to boot
390 * Return: -EPROTO if bootflow has not been loaded, -ENOSYS if the bootflow
391 * type is not supported, -EFAULT if the boot returned without an error
392 * when we are expecting it to boot, -ENOTSUPP if trying method resulted in
393 * finding out that is not actually supported for this boot and should not
394 * be tried again unless something changes
395 */
396int bootflow_boot(struct bootflow *bflow);
397
398/**
Simon Glass6d8f95b2023-08-10 19:33:18 -0600399 * bootflow_read_all() - Read all bootflow files
400 *
401 * Some bootmeths delay reading of large files until booting is requested. This
402 * causes those files to be read.
403 *
404 * @bflow: Bootflow to read
405 * Return: result of trying to read
406 */
407int bootflow_read_all(struct bootflow *bflow);
408
409/**
Simon Glassa16d87d2022-04-24 23:31:05 -0600410 * bootflow_run_boot() - Try to boot a bootflow
411 *
412 * @iter: Current iteration (or NULL if none). Used to disable a bootmeth if the
413 * boot returns -ENOTSUPP
414 * @bflow: Bootflow to boot
415 * Return: result of trying to boot
416 */
417int bootflow_run_boot(struct bootflow_iter *iter, struct bootflow *bflow);
418
419/**
420 * bootflow_state_get_name() - Get the name of a bootflow state
421 *
422 * @state: State to check
423 * Return: name, or "?" if invalid
424 */
425const char *bootflow_state_get_name(enum bootflow_state_t state);
426
Simon Glass03fcbf92022-04-24 23:31:09 -0600427/**
428 * bootflow_remove() - Remove a bootflow and free its memory
429 *
Simon Glass199f5882024-11-15 16:19:12 -0700430 * This updates the 'global' linked list containing the bootflow, then frees it.
431 * It does not remove it from bootflows alist in struct bootstd_priv
432 *
433 * This does not free bflow itself, since this is assumed to be in an alist
Simon Glass03fcbf92022-04-24 23:31:09 -0600434 *
435 * @bflow: Bootflow to remove
436 */
437void bootflow_remove(struct bootflow *bflow);
438
439/**
Simon Glass18c50402023-01-17 10:47:54 -0700440 * bootflow_iter_check_blk() - Check that a bootflow uses a block device
Simon Glass03fcbf92022-04-24 23:31:09 -0600441 *
442 * This checks the bootdev in the bootflow to make sure it uses a block device
443 *
444 * Return: 0 if OK, -ENOTSUPP if some other device is used (e.g. ethernet)
445 */
Simon Glass18c50402023-01-17 10:47:54 -0700446int bootflow_iter_check_blk(const struct bootflow_iter *iter);
Simon Glass03fcbf92022-04-24 23:31:09 -0600447
448/**
Mattijs Korpershoekfc420be2024-07-10 10:40:03 +0200449 * bootflow_iter_check_mmc() - Check that a bootflow uses a MMC device
450 *
451 * This checks the bootdev in the bootflow to make sure it uses a mmc device
452 *
453 * Return: 0 if OK, -ENOTSUPP if some other device is used (e.g. ethernet)
454 */
455int bootflow_iter_check_mmc(const struct bootflow_iter *iter);
456
457/**
Simon Glass215be682023-01-17 10:48:03 -0700458 * bootflow_iter_check_sf() - Check that a bootflow uses SPI FLASH
459 *
460 * This checks the bootdev in the bootflow to make sure it uses SPI flash
461 *
462 * Return: 0 if OK, -ENOTSUPP if some other device is used (e.g. ethernet)
463 */
464int bootflow_iter_check_sf(const struct bootflow_iter *iter);
465
466/**
Simon Glass18c50402023-01-17 10:47:54 -0700467 * bootflow_iter_check_net() - Check that a bootflow uses a network device
Simon Glass03fcbf92022-04-24 23:31:09 -0600468 *
469 * This checks the bootdev in the bootflow to make sure it uses a network
470 * device
471 *
472 * Return: 0 if OK, -ENOTSUPP if some other device is used (e.g. MMC)
473 */
Simon Glass18c50402023-01-17 10:47:54 -0700474int bootflow_iter_check_net(const struct bootflow_iter *iter);
Simon Glass03fcbf92022-04-24 23:31:09 -0600475
476/**
Simon Glass18c50402023-01-17 10:47:54 -0700477 * bootflow_iter_check_system() - Check that a bootflow uses the bootstd device
Simon Glass03fcbf92022-04-24 23:31:09 -0600478 *
479 * This checks the bootdev in the bootflow to make sure it uses the bootstd
480 * device
481 *
482 * Return: 0 if OK, -ENOTSUPP if some other device is used (e.g. MMC)
483 */
Simon Glass18c50402023-01-17 10:47:54 -0700484int bootflow_iter_check_system(const struct bootflow_iter *iter);
Simon Glass03fcbf92022-04-24 23:31:09 -0600485
Simon Glass0a2f6a32023-01-06 08:52:40 -0600486/**
487 * bootflow_menu_new() - Create a new bootflow menu
488 *
489 * @expp: Returns the expo created
490 * Returns 0 on success, -ve on error
491 */
492int bootflow_menu_new(struct expo **expp);
493
494/**
Simon Glassd92bcc42023-01-06 08:52:42 -0600495 * bootflow_menu_apply_theme() - Apply a theme to a bootmenu
496 *
497 * @exp: Expo to update
498 * @node: Node containing the theme information
499 * Returns 0 on success, -ve on error
500 */
501int bootflow_menu_apply_theme(struct expo *exp, ofnode node);
502
503/**
Simon Glass0a2f6a32023-01-06 08:52:40 -0600504 * bootflow_menu_run() - Create and run a menu of available bootflows
505 *
506 * @std: Bootstd information
507 * @text_mode: Uses a text-based menu suitable for a serial port
508 * @bflowp: Returns chosen bootflow (set to NULL if nothing is chosen)
509 * @return 0 if an option was chosen, -EAGAIN if nothing was chosen, -ve on
510 * error
511 */
512int bootflow_menu_run(struct bootstd_priv *std, bool text_mode,
513 struct bootflow **bflowp);
514
Simon Glassa08adca2023-07-12 09:04:38 -0600515#define BOOTFLOWCL_EMPTY ((void *)1)
516
517/**
518 * cmdline_set_arg() - Update or read an argument in a cmdline string
519 *
520 * Handles updating a single arg in a cmdline string, returning it in a supplied
521 * buffer; also reading an arg from a cmdline string
522 *
523 * When updating, consecutive spaces are squashed as are spaces at the start and
524 * end.
525 *
526 * @buf: Working buffer to use (initial contents are ignored). Use NULL when
527 * reading
528 * @maxlen: Length of working buffer. Use 0 when reading
529 * @cmdline: Command line to update, in the form:
530 *
531 * fred mary= jane=123 john="has spaces"
532 *
533 * @set_arg: Argument to set or read (may or may not exist)
534 * @new_val: Value for the new argument. May not include quotes (") but may
535 * include embedded spaces, in which case it will be quoted when added to the
536 * command line. Use NULL to delete the argument from @cmdline, BOOTFLOWCL_EMPTY
537 * to set it to an empty value (no '=' sign after arg), "" to add an '=' sign
538 * but with an empty value. Use NULL when reading.
539 * @posp: Ignored when setting an argument; when getting an argument, returns
540 * the start position of its value in @cmdline, after the first quote, if any
541 *
542 * Return:
543 * For updating:
544 * length of new buffer (including \0 terminator) on success, -ENOENT if
545 * @new_val is NULL and @set_arg does not exist in @from, -EINVAL if a
546 * quoted arg-value in @from is not terminated with a quote, -EBADF if
547 * @new_val has spaces but does not start and end with quotes (or it has
548 * quotes in the middle of the string), -E2BIG if @maxlen is too small
549 * For reading:
550 * length of arg value (excluding quotes), -ENOENT if not found
551 */
552int cmdline_set_arg(char *buf, int maxlen, const char *cmdline,
553 const char *set_arg, const char *new_val, int *posp);
554
Simon Glass55a2da32023-07-12 09:04:39 -0600555/**
556 * bootflow_cmdline_set_arg() - Set a single argument for a bootflow
557 *
558 * Update the allocated cmdline and set the bootargs variable
559 *
560 * @bflow: Bootflow to update
561 * @arg: Argument to update (e.g. "console")
562 * @val: Value to set (e.g. "ttyS2") or NULL to delete the argument if present,
563 * "" to set it to an empty value (e.g. "console=") and BOOTFLOWCL_EMPTY to add
564 * it without any value ("initrd")
565 * @set_env: true to set the "bootargs" environment variable too
566 *
567 * Return: 0 if OK, -ENOMEM if out of memory
568 */
569int bootflow_cmdline_set_arg(struct bootflow *bflow, const char *arg,
570 const char *val, bool set_env);
571
572/**
573 * cmdline_get_arg() - Read an argument from a cmdline
574 *
575 * @cmdline: Command line to read, in the form:
576 *
577 * fred mary= jane=123 john="has spaces"
578 * @arg: Argument to read (may or may not exist)
579 * @posp: Returns position of argument (after any leading quote) if present
580 * Return: Length of argument value excluding quotes if found, -ENOENT if not
581 * found
582 */
583int cmdline_get_arg(const char *cmdline, const char *arg, int *posp);
584
585/**
586 * bootflow_cmdline_get_arg() - Read an argument from a cmdline
587 *
588 * @bootflow: Bootflow to read from
589 * @arg: Argument to read (may or may not exist)
590 * @valp: Returns a pointer to the argument (after any leading quote) if present
591 * Return: Length of argument value excluding quotes if found, -ENOENT if not
592 * found
593 */
594int bootflow_cmdline_get_arg(struct bootflow *bflow, const char *arg,
595 const char **val);
596
Simon Glasscd91e992023-07-12 09:04:42 -0600597/**
598 * bootflow_cmdline_auto() - Automatically set a value for a known argument
599 *
600 * This handles a small number of known arguments, for Linux in particular. It
601 * adds suitable kernel parameters automatically, e.g. to enable the console.
602 *
603 * @bflow: Bootflow to update
604 * @arg: Name of argument to set (e.g. "earlycon" or "console")
605 * Return: 0 if OK -ve on error
606 */
607int bootflow_cmdline_auto(struct bootflow *bflow, const char *arg);
608
Simon Glassc2a16c92024-11-15 16:19:13 -0700609/**
610 * bootflow_img_type_name() - Get the name for an image type
611 *
612 * @type: Type to check (either enum bootflow_img_t or enum image_type_t
613 * Return: Image name, or "unknown" if not known
614 */
615const char *bootflow_img_type_name(enum bootflow_img_t type);
Simon Glass8db2a382024-11-15 16:19:14 -0700616
617/**
618 * bootflow_img_add() - Add a new image to a bootflow
619 *
620 * @bflow: Bootflow to add to
621 * @fname: Image filename (will be allocated)
622 * @type: Image type
623 * @addr: Address the image was loaded to, or 0 if not loaded
624 * @size: Image size
625 * Return: pointer to the added image, or NULL if out of memory
626 */
627struct bootflow_img *bootflow_img_add(struct bootflow *bflow, const char *fname,
628 enum bootflow_img_t type, ulong addr,
629 ulong size);
Simon Glassc6a52e72024-11-15 16:19:23 -0700630/**
631 * bootflow_get_seq() - Get the sequence number of a bootflow
632 *
633 * Bootflows are numbered by their position in the bootstd list.
634 *
635 * Return: Sequence number of bootflow (0 = first)
636 */
637int bootflow_get_seq(const struct bootflow *bflow);
Simon Glass8db2a382024-11-15 16:19:14 -0700638
Simon Glassa16d87d2022-04-24 23:31:05 -0600639#endif