blob: fede8f22a2b8caf6eb52331d95be2338dcadfc5b [file] [log] [blame]
Simon Glass9d260252022-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 Glass43e89a32023-01-17 10:48:11 -070010#include <bootdev.h>
Simon Glasse64c2952023-01-06 08:52:42 -060011#include <dm/ofnode_decl.h>
Simon Glass9d260252022-04-24 23:31:05 -060012#include <linux/list.h>
13
Simon Glass02d929b2023-01-06 08:52:40 -060014struct bootstd_priv;
15struct expo;
16
Simon Glassa950f282023-01-17 10:48:17 -070017enum {
18 BOOTFLOW_MAX_USED_DEVS = 16,
19};
20
Simon Glass9d260252022-04-24 23:31:05 -060021/**
22 * enum bootflow_state_t - states that a particular bootflow can be in
23 *
24 * Only bootflows in state BOOTFLOWST_READY can be used to boot.
25 *
26 * See bootflow_state[] for the names for each of these
27 */
28enum bootflow_state_t {
29 BOOTFLOWST_BASE, /**< Nothing known yet */
30 BOOTFLOWST_MEDIA, /**< Media exists */
31 BOOTFLOWST_PART, /**< Partition exists */
32 BOOTFLOWST_FS, /**< Filesystem exists */
33 BOOTFLOWST_FILE, /**< Bootflow file exists */
34 BOOTFLOWST_READY, /**< Bootflow file loaded */
35
36 BOOTFLOWST_COUNT
37};
38
39/**
Simon Glass47dd6b42023-02-22 12:17:04 -070040 * enum bootflow_flags_t - flags for bootflows
41 *
42 * @BOOTFLOWF_USE_PRIOR_FDT: Indicates that an FDT was not found by the bootmeth
43 * and it is using the prior-stage FDT, which is the U-Boot control FDT.
44 * This is only possible with the EFI bootmeth (distro-efi) and only when
45 * CONFIG_OF_HAS_PRIOR_STAGE is enabled
Simon Glass741d1e92023-11-15 18:35:23 -070046 * @BOOTFLOWF_STATIC_BUF: Indicates that @bflow->buf is statically set, rather
47 * than being allocated by malloc().
Simon Glass47dd6b42023-02-22 12:17:04 -070048 */
49enum bootflow_flags_t {
50 BOOTFLOWF_USE_PRIOR_FDT = 1 << 0,
Simon Glass741d1e92023-11-15 18:35:23 -070051 BOOTFLOWF_STATIC_BUF = 1 << 1,
Simon Glass47dd6b42023-02-22 12:17:04 -070052};
53
54/**
Simon Glass9d260252022-04-24 23:31:05 -060055 * struct bootflow - information about a bootflow
56 *
57 * This is connected into two separate linked lists:
58 *
59 * bm_sibling - links all bootflows in the same bootdev
60 * glob_sibling - links all bootflows in all bootdevs
61 *
62 * @bm_node: Points to siblings in the same bootdev
63 * @glob_node: Points to siblings in the global list (all bootdev)
Simon Glass4de979f2023-07-12 09:04:32 -060064 * @dev: Bootdev device which produced this bootflow
Simon Glass9d260252022-04-24 23:31:05 -060065 * @blk: Block device which contains this bootflow, NULL if this is a network
Simon Glassa58e7bb2023-01-17 10:47:59 -070066 * device or sandbox 'host' device
Simon Glass9d260252022-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 Glass24d8e1b2023-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 Glass741d1e92023-11-15 18:35:23 -070078 * @buf: Bootflow file contents (allocated unless @flags & BOOTFLOWF_STATIC_BUF)
Simon Glass9d260252022-04-24 23:31:05 -060079 * @size: Size of bootflow file in bytes
80 * @err: Error number received (0 if OK)
Simon Glass2175e762023-01-06 08:52:33 -060081 * @os_name: Name of the OS / distro being booted, or NULL if not known
82 * (allocated)
Simon Glass7638c852023-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 Glass47dd6b42023-02-22 12:17:04 -070086 * @flags: Flags for the bootflow (see enum bootflow_flags_t)
Simon Glassf4a91652023-07-12 09:04:34 -060087 * @cmdline: OS command line, or NULL if not known (allocated)
Simon Glass43b6fa92023-07-12 09:04:36 -060088 * @x86_setup: Pointer to x86 setup block inside @buf, NULL if not present
Simon Glass76bd6842023-07-30 11:16:56 -060089 * @bootmeth_priv: Private data for the bootmeth
Simon Glass9d260252022-04-24 23:31:05 -060090 */
91struct bootflow {
92 struct list_head bm_node;
93 struct list_head glob_node;
94 struct udevice *dev;
95 struct udevice *blk;
96 int part;
97 int fs_type;
98 struct udevice *method;
99 char *name;
100 enum bootflow_state_t state;
101 char *subdir;
102 char *fname;
Simon Glass24d8e1b2023-01-06 08:52:34 -0600103 void *logo;
104 uint logo_size;
Simon Glass9d260252022-04-24 23:31:05 -0600105 char *buf;
106 int size;
107 int err;
Simon Glass2175e762023-01-06 08:52:33 -0600108 char *os_name;
Simon Glass7638c852023-01-17 10:47:56 -0700109 char *fdt_fname;
110 int fdt_size;
111 ulong fdt_addr;
Simon Glass47dd6b42023-02-22 12:17:04 -0700112 int flags;
Simon Glassf4a91652023-07-12 09:04:34 -0600113 char *cmdline;
Simon Glasscbb607d2023-07-30 11:17:00 -0600114 void *x86_setup;
Simon Glass76bd6842023-07-30 11:16:56 -0600115 void *bootmeth_priv;
Simon Glass9d260252022-04-24 23:31:05 -0600116};
117
118/**
Simon Glass4f806f32023-02-22 12:17:03 -0700119 * enum bootflow_iter_flags_t - flags for the bootflow iterator
Simon Glass9d260252022-04-24 23:31:05 -0600120 *
Simon Glass4f806f32023-02-22 12:17:03 -0700121 * @BOOTFLOWIF_FIXED: Only used fixed/internal media
122 * @BOOTFLOWIF_SHOW: Show each bootdev before scanning it; show each hunter
Simon Glassd73420e2023-01-17 10:48:06 -0700123 * before using it
Simon Glass4f806f32023-02-22 12:17:03 -0700124 * @BOOTFLOWIF_ALL: Return bootflows with errors as well
125 * @BOOTFLOWIF_HUNT: Hunt for new bootdevs using the bootdrv hunters
Simon Glassd73420e2023-01-17 10:48:06 -0700126 *
127 * Internal flags:
Simon Glass4f806f32023-02-22 12:17:03 -0700128 * @BOOTFLOWIF_SINGLE_DEV: (internal) Just scan one bootdev
129 * @BOOTFLOWIF_SKIP_GLOBAL: (internal) Don't scan global bootmeths
130 * @BOOTFLOWIF_SINGLE_UCLASS: (internal) Keep scanning through all devices in
Simon Glass66e3dce2023-01-17 10:48:09 -0700131 * this uclass (used with things like "mmc")
Simon Glass4f806f32023-02-22 12:17:03 -0700132 * @BOOTFLOWIF_SINGLE_MEDIA: (internal) Scan one media device in the uclass (used
Simon Glass66e3dce2023-01-17 10:48:09 -0700133 * with things like "mmc1")
Simon Glass9d260252022-04-24 23:31:05 -0600134 */
Simon Glass4f806f32023-02-22 12:17:03 -0700135enum bootflow_iter_flags_t {
136 BOOTFLOWIF_FIXED = 1 << 0,
137 BOOTFLOWIF_SHOW = 1 << 1,
138 BOOTFLOWIF_ALL = 1 << 2,
139 BOOTFLOWIF_HUNT = 1 << 3,
Simon Glassd73420e2023-01-17 10:48:06 -0700140
141 /*
142 * flags used internally by standard boot - do not set these when
143 * calling bootflow_scan_bootdev() etc.
144 */
Simon Glass4f806f32023-02-22 12:17:03 -0700145 BOOTFLOWIF_SINGLE_DEV = 1 << 16,
146 BOOTFLOWIF_SKIP_GLOBAL = 1 << 17,
147 BOOTFLOWIF_SINGLE_UCLASS = 1 << 18,
148 BOOTFLOWIF_SINGLE_MEDIA = 1 << 19,
Simon Glass9d260252022-04-24 23:31:05 -0600149};
150
151/**
Simon Glassd9f48572023-01-17 10:48:05 -0700152 * enum bootflow_meth_flags_t - flags controlling which bootmeths are used
153 *
154 * Used during iteration, e.g. by bootdev_find_by_label(), to determine which
155 * bootmeths are used for the current bootdev. The flags reset when the bootdev
156 * changes
157 *
158 * @BOOTFLOW_METHF_DHCP_ONLY: Only use dhcp (scripts and EFI)
159 * @BOOTFLOW_METHF_PXE_ONLY: Only use pxe (PXE boot)
Simon Glass66e3dce2023-01-17 10:48:09 -0700160 * @BOOTFLOW_METHF_SINGLE_DEV: Scan only a single bootdev (used for labels like
161 * "3"). This is used if a sequence number is provided instead of a label
162 * @BOOTFLOW_METHF_SINGLE_UCLASS: Scan all bootdevs in this one uclass (used
163 * with things like "mmc"). If this is not set, then the bootdev has an integer
164 * value in the label (like "mmc2")
Simon Glassd9f48572023-01-17 10:48:05 -0700165 */
166enum bootflow_meth_flags_t {
167 BOOTFLOW_METHF_DHCP_ONLY = 1 << 0,
168 BOOTFLOW_METHF_PXE_ONLY = 1 << 1,
Simon Glass66e3dce2023-01-17 10:48:09 -0700169 BOOTFLOW_METHF_SINGLE_DEV = 1 << 2,
170 BOOTFLOW_METHF_SINGLE_UCLASS = 1 << 3,
Simon Glassd9f48572023-01-17 10:48:05 -0700171};
172
173/**
Simon Glass9d260252022-04-24 23:31:05 -0600174 * struct bootflow_iter - state for iterating through bootflows
175 *
176 * This starts at with the first bootdev/partition/bootmeth and can be used to
177 * iterate through all of them.
178 *
179 * Iteration starts with the bootdev. The first partition (0, i.e. whole device)
180 * is scanned first. For partition 0, it iterates through all the available
181 * bootmeths to see which one(s) can provide a bootflow. Then it moves to
182 * parition 1 (if there is one) and the process continues. Once all partitions
183 * are examined, it moves to the next bootdev.
184 *
185 * Initially @max_part is 0, meaning that only the whole device (@part=0) can be
186 * used. During scanning, if a partition table is found, then @max_part is
187 * updated to a larger value, no less than the number of available partitions.
188 * This ensures that iteration works through all partitions on the bootdev.
189 *
Simon Glass4f806f32023-02-22 12:17:03 -0700190 * @flags: Flags to use (see enum bootflow_iter_flags_t). If
191 * BOOTFLOWIF_GLOBAL_FIRST is enabled then the global bootmeths are being
192 * scanned, otherwise we have moved onto the bootdevs
Simon Glass47aedc22023-01-17 10:48:14 -0700193 * @dev: Current bootdev, NULL if none. This is only ever updated in
194 * bootflow_iter_set_dev()
Simon Glass9d260252022-04-24 23:31:05 -0600195 * @part: Current partition number (0 for whole device)
196 * @method: Current bootmeth
197 * @max_part: Maximum hardware partition number in @dev, 0 if there is no
198 * partition table
Simon Glassf0e358f2023-01-17 10:47:42 -0700199 * @first_bootable: First bootable partition, or 0 if none
Simon Glass9d260252022-04-24 23:31:05 -0600200 * @err: Error obtained from checking the last iteration. This is used to skip
201 * forward (e.g. to skip the current partition because it is not valid)
202 * -ESHUTDOWN: try next bootdev
Simon Glassa950f282023-01-17 10:48:17 -0700203 * @num_devs: Number of bootdevs in @dev_used
204 * @max_devs: Maximum number of entries in @dev_used
205 * @dev_used: List of bootdevs used during iteration
Simon Glasse4b69482023-01-17 10:48:10 -0700206 * @labels: List of labels to scan for bootdevs
207 * @cur_label: Current label being processed
Simon Glass9d260252022-04-24 23:31:05 -0600208 * @num_methods: Number of bootmeth devices in @method_order
209 * @cur_method: Current method number, an index into @method_order
Simon Glass2b80bc12022-07-30 15:52:25 -0600210 * @first_glob_method: First global method, if any, else -1
Simon Glass43e89a32023-01-17 10:48:11 -0700211 * @cur_prio: Current priority being scanned
Simon Glass2b80bc12022-07-30 15:52:25 -0600212 * @method_order: List of bootmeth devices to use, in order. The normal methods
213 * appear first, then the global ones, if any
214 * @doing_global: true if we are iterating through the global bootmeths (which
215 * happens before the normal ones)
Simon Glass25365872023-01-17 10:47:58 -0700216 * @method_flags: flags controlling which methods should be used for this @dev
217 * (enum bootflow_meth_flags_t)
Simon Glass9d260252022-04-24 23:31:05 -0600218 */
219struct bootflow_iter {
220 int flags;
221 struct udevice *dev;
222 int part;
223 struct udevice *method;
224 int max_part;
Simon Glassf0e358f2023-01-17 10:47:42 -0700225 int first_bootable;
Simon Glass9d260252022-04-24 23:31:05 -0600226 int err;
227 int num_devs;
Simon Glassa950f282023-01-17 10:48:17 -0700228 int max_devs;
229 struct udevice *dev_used[BOOTFLOW_MAX_USED_DEVS];
Simon Glasse4b69482023-01-17 10:48:10 -0700230 const char *const *labels;
231 int cur_label;
Simon Glass9d260252022-04-24 23:31:05 -0600232 int num_methods;
233 int cur_method;
Simon Glass2b80bc12022-07-30 15:52:25 -0600234 int first_glob_method;
Simon Glass43e89a32023-01-17 10:48:11 -0700235 enum bootdev_prio_t cur_prio;
Simon Glass9d260252022-04-24 23:31:05 -0600236 struct udevice **method_order;
Simon Glass2b80bc12022-07-30 15:52:25 -0600237 bool doing_global;
Simon Glass25365872023-01-17 10:47:58 -0700238 int method_flags;
Simon Glass9d260252022-04-24 23:31:05 -0600239};
240
241/**
Simon Glassb190deb2022-10-20 18:22:51 -0600242 * bootflow_init() - Set up a bootflow struct
243 *
244 * The bootflow is zeroed and set to state BOOTFLOWST_BASE
245 *
246 * @bflow: Struct to set up
247 * @bootdev: Bootdev to use
248 * @meth: Bootmeth to use
249 */
250void bootflow_init(struct bootflow *bflow, struct udevice *bootdev,
251 struct udevice *meth);
252
253/**
Simon Glass9d260252022-04-24 23:31:05 -0600254 * bootflow_iter_init() - Reset a bootflow iterator
255 *
256 * This sets everything to the starting point, ready for use.
257 *
258 * @iter: Place to store private info (inited by this call)
Simon Glass4f806f32023-02-22 12:17:03 -0700259 * @flags: Flags to use (see enum bootflow_iter_flags_t)
Simon Glass9d260252022-04-24 23:31:05 -0600260 */
261void bootflow_iter_init(struct bootflow_iter *iter, int flags);
262
263/**
264 * bootflow_iter_uninit() - Free memory used by an interator
265 *
266 * @iter: Iterator to free
267 */
268void bootflow_iter_uninit(struct bootflow_iter *iter);
269
270/**
Simon Glassa8f5be12022-04-24 23:31:09 -0600271 * bootflow_iter_drop_bootmeth() - Remove a bootmeth from an iterator
272 *
273 * Update the iterator so that the bootmeth will not be used again while this
274 * iterator is in use
275 *
276 * @iter: Iterator to update
277 * @bmeth: Boot method to remove
278 */
279int bootflow_iter_drop_bootmeth(struct bootflow_iter *iter,
280 const struct udevice *bmeth);
281
282/**
Simon Glass4b7cb052023-01-17 10:48:16 -0700283 * bootflow_scan_first() - find the first bootflow for a device or label
Simon Glass9d260252022-04-24 23:31:05 -0600284 *
Simon Glass4f806f32023-02-22 12:17:03 -0700285 * If @flags includes BOOTFLOWIF_ALL then bootflows with errors are returned too
Simon Glass9d260252022-04-24 23:31:05 -0600286 *
287 * @dev: Boot device to scan, NULL to work through all of them until it
Simon Glassee47d4a2022-07-30 15:52:24 -0600288 * finds one that can supply a bootflow
Simon Glass91943ff2023-01-17 10:48:15 -0700289 * @label: Label to control the scan, NULL to work through all devices
290 * until it finds one that can supply a bootflow
Simon Glass9d260252022-04-24 23:31:05 -0600291 * @iter: Place to store private info (inited by this call)
Simon Glass4f806f32023-02-22 12:17:03 -0700292 * @flags: Flags for iterator (enum bootflow_iter_flags_t). Note that if
293 * @dev is NULL, then BOOTFLOWIF_SKIP_GLOBAL is set automatically by this
294 * function
Simon Glass9d260252022-04-24 23:31:05 -0600295 * @bflow: Place to put the bootflow if found
296 * Return: 0 if found, -ENODEV if no device, other -ve on other error
297 * (iteration can continue)
298 */
Simon Glass4b7cb052023-01-17 10:48:16 -0700299int bootflow_scan_first(struct udevice *dev, const char *label,
300 struct bootflow_iter *iter, int flags,
Simon Glass9d260252022-04-24 23:31:05 -0600301 struct bootflow *bflow);
302
303/**
304 * bootflow_scan_next() - find the next bootflow
305 *
306 * This works through the available bootdev devices until it finds one that
307 * can supply a bootflow. It then returns that bootflow
308 *
309 * @iter: Private info (as set up by bootflow_scan_first())
310 * @bflow: Place to put the bootflow if found
311 * Return: 0 if found, -ENODEV if no device, -ESHUTDOWN if no more bootflows,
312 * other -ve on other error (iteration can continue)
313 */
314int bootflow_scan_next(struct bootflow_iter *iter, struct bootflow *bflow);
315
316/**
317 * bootflow_first_glob() - Get the first bootflow from the global list
318 *
319 * Returns the first bootflow in the global list, no matter what bootflow it is
320 * attached to
321 *
322 * @bflowp: Returns a pointer to the bootflow
323 * Return: 0 if found, -ENOENT if there are no bootflows
324 */
325int bootflow_first_glob(struct bootflow **bflowp);
326
327/**
328 * bootflow_next_glob() - Get the next bootflow from the global list
329 *
330 * Returns the next bootflow in the global list, no matter what bootflow it is
331 * attached to
332 *
333 * @bflowp: On entry, the last bootflow returned , e.g. from
334 * bootflow_first_glob()
335 * Return: 0 if found, -ENOENT if there are no more bootflows
336 */
337int bootflow_next_glob(struct bootflow **bflowp);
338
339/**
340 * bootflow_free() - Free memory used by a bootflow
341 *
342 * This frees fields within @bflow, but not the @bflow pointer itself
343 */
344void bootflow_free(struct bootflow *bflow);
345
346/**
347 * bootflow_boot() - boot a bootflow
348 *
349 * @bflow: Bootflow to boot
350 * Return: -EPROTO if bootflow has not been loaded, -ENOSYS if the bootflow
351 * type is not supported, -EFAULT if the boot returned without an error
352 * when we are expecting it to boot, -ENOTSUPP if trying method resulted in
353 * finding out that is not actually supported for this boot and should not
354 * be tried again unless something changes
355 */
356int bootflow_boot(struct bootflow *bflow);
357
358/**
Simon Glassc2792242023-08-10 19:33:18 -0600359 * bootflow_read_all() - Read all bootflow files
360 *
361 * Some bootmeths delay reading of large files until booting is requested. This
362 * causes those files to be read.
363 *
364 * @bflow: Bootflow to read
365 * Return: result of trying to read
366 */
367int bootflow_read_all(struct bootflow *bflow);
368
369/**
Simon Glass9d260252022-04-24 23:31:05 -0600370 * bootflow_run_boot() - Try to boot a bootflow
371 *
372 * @iter: Current iteration (or NULL if none). Used to disable a bootmeth if the
373 * boot returns -ENOTSUPP
374 * @bflow: Bootflow to boot
375 * Return: result of trying to boot
376 */
377int bootflow_run_boot(struct bootflow_iter *iter, struct bootflow *bflow);
378
379/**
380 * bootflow_state_get_name() - Get the name of a bootflow state
381 *
382 * @state: State to check
383 * Return: name, or "?" if invalid
384 */
385const char *bootflow_state_get_name(enum bootflow_state_t state);
386
Simon Glassa8f5be12022-04-24 23:31:09 -0600387/**
388 * bootflow_remove() - Remove a bootflow and free its memory
389 *
390 * This updates the linked lists containing the bootflow then frees it.
391 *
392 * @bflow: Bootflow to remove
393 */
394void bootflow_remove(struct bootflow *bflow);
395
396/**
Simon Glass865328c2023-01-17 10:47:54 -0700397 * bootflow_iter_check_blk() - Check that a bootflow uses a block device
Simon Glassa8f5be12022-04-24 23:31:09 -0600398 *
399 * This checks the bootdev in the bootflow to make sure it uses a block device
400 *
401 * Return: 0 if OK, -ENOTSUPP if some other device is used (e.g. ethernet)
402 */
Simon Glass865328c2023-01-17 10:47:54 -0700403int bootflow_iter_check_blk(const struct bootflow_iter *iter);
Simon Glassa8f5be12022-04-24 23:31:09 -0600404
405/**
Simon Glass0c1f4a92023-01-17 10:48:03 -0700406 * bootflow_iter_check_sf() - Check that a bootflow uses SPI FLASH
407 *
408 * This checks the bootdev in the bootflow to make sure it uses SPI flash
409 *
410 * Return: 0 if OK, -ENOTSUPP if some other device is used (e.g. ethernet)
411 */
412int bootflow_iter_check_sf(const struct bootflow_iter *iter);
413
414/**
Simon Glass865328c2023-01-17 10:47:54 -0700415 * bootflow_iter_check_net() - Check that a bootflow uses a network device
Simon Glassa8f5be12022-04-24 23:31:09 -0600416 *
417 * This checks the bootdev in the bootflow to make sure it uses a network
418 * device
419 *
420 * Return: 0 if OK, -ENOTSUPP if some other device is used (e.g. MMC)
421 */
Simon Glass865328c2023-01-17 10:47:54 -0700422int bootflow_iter_check_net(const struct bootflow_iter *iter);
Simon Glassa8f5be12022-04-24 23:31:09 -0600423
424/**
Simon Glass865328c2023-01-17 10:47:54 -0700425 * bootflow_iter_check_system() - Check that a bootflow uses the bootstd device
Simon Glassa8f5be12022-04-24 23:31:09 -0600426 *
427 * This checks the bootdev in the bootflow to make sure it uses the bootstd
428 * device
429 *
430 * Return: 0 if OK, -ENOTSUPP if some other device is used (e.g. MMC)
431 */
Simon Glass865328c2023-01-17 10:47:54 -0700432int bootflow_iter_check_system(const struct bootflow_iter *iter);
Simon Glassa8f5be12022-04-24 23:31:09 -0600433
Simon Glass02d929b2023-01-06 08:52:40 -0600434/**
435 * bootflow_menu_new() - Create a new bootflow menu
436 *
437 * @expp: Returns the expo created
438 * Returns 0 on success, -ve on error
439 */
440int bootflow_menu_new(struct expo **expp);
441
442/**
Simon Glasse64c2952023-01-06 08:52:42 -0600443 * bootflow_menu_apply_theme() - Apply a theme to a bootmenu
444 *
445 * @exp: Expo to update
446 * @node: Node containing the theme information
447 * Returns 0 on success, -ve on error
448 */
449int bootflow_menu_apply_theme(struct expo *exp, ofnode node);
450
451/**
Simon Glass02d929b2023-01-06 08:52:40 -0600452 * bootflow_menu_run() - Create and run a menu of available bootflows
453 *
454 * @std: Bootstd information
455 * @text_mode: Uses a text-based menu suitable for a serial port
456 * @bflowp: Returns chosen bootflow (set to NULL if nothing is chosen)
457 * @return 0 if an option was chosen, -EAGAIN if nothing was chosen, -ve on
458 * error
459 */
460int bootflow_menu_run(struct bootstd_priv *std, bool text_mode,
461 struct bootflow **bflowp);
462
Simon Glassd07861c2023-07-12 09:04:38 -0600463#define BOOTFLOWCL_EMPTY ((void *)1)
464
465/**
466 * cmdline_set_arg() - Update or read an argument in a cmdline string
467 *
468 * Handles updating a single arg in a cmdline string, returning it in a supplied
469 * buffer; also reading an arg from a cmdline string
470 *
471 * When updating, consecutive spaces are squashed as are spaces at the start and
472 * end.
473 *
474 * @buf: Working buffer to use (initial contents are ignored). Use NULL when
475 * reading
476 * @maxlen: Length of working buffer. Use 0 when reading
477 * @cmdline: Command line to update, in the form:
478 *
479 * fred mary= jane=123 john="has spaces"
480 *
481 * @set_arg: Argument to set or read (may or may not exist)
482 * @new_val: Value for the new argument. May not include quotes (") but may
483 * include embedded spaces, in which case it will be quoted when added to the
484 * command line. Use NULL to delete the argument from @cmdline, BOOTFLOWCL_EMPTY
485 * to set it to an empty value (no '=' sign after arg), "" to add an '=' sign
486 * but with an empty value. Use NULL when reading.
487 * @posp: Ignored when setting an argument; when getting an argument, returns
488 * the start position of its value in @cmdline, after the first quote, if any
489 *
490 * Return:
491 * For updating:
492 * length of new buffer (including \0 terminator) on success, -ENOENT if
493 * @new_val is NULL and @set_arg does not exist in @from, -EINVAL if a
494 * quoted arg-value in @from is not terminated with a quote, -EBADF if
495 * @new_val has spaces but does not start and end with quotes (or it has
496 * quotes in the middle of the string), -E2BIG if @maxlen is too small
497 * For reading:
498 * length of arg value (excluding quotes), -ENOENT if not found
499 */
500int cmdline_set_arg(char *buf, int maxlen, const char *cmdline,
501 const char *set_arg, const char *new_val, int *posp);
502
Simon Glass82c09382023-07-12 09:04:39 -0600503/**
504 * bootflow_cmdline_set_arg() - Set a single argument for a bootflow
505 *
506 * Update the allocated cmdline and set the bootargs variable
507 *
508 * @bflow: Bootflow to update
509 * @arg: Argument to update (e.g. "console")
510 * @val: Value to set (e.g. "ttyS2") or NULL to delete the argument if present,
511 * "" to set it to an empty value (e.g. "console=") and BOOTFLOWCL_EMPTY to add
512 * it without any value ("initrd")
513 * @set_env: true to set the "bootargs" environment variable too
514 *
515 * Return: 0 if OK, -ENOMEM if out of memory
516 */
517int bootflow_cmdline_set_arg(struct bootflow *bflow, const char *arg,
518 const char *val, bool set_env);
519
520/**
521 * cmdline_get_arg() - Read an argument from a cmdline
522 *
523 * @cmdline: Command line to read, in the form:
524 *
525 * fred mary= jane=123 john="has spaces"
526 * @arg: Argument to read (may or may not exist)
527 * @posp: Returns position of argument (after any leading quote) if present
528 * Return: Length of argument value excluding quotes if found, -ENOENT if not
529 * found
530 */
531int cmdline_get_arg(const char *cmdline, const char *arg, int *posp);
532
533/**
534 * bootflow_cmdline_get_arg() - Read an argument from a cmdline
535 *
536 * @bootflow: Bootflow to read from
537 * @arg: Argument to read (may or may not exist)
538 * @valp: Returns a pointer to the argument (after any leading quote) if present
539 * Return: Length of argument value excluding quotes if found, -ENOENT if not
540 * found
541 */
542int bootflow_cmdline_get_arg(struct bootflow *bflow, const char *arg,
543 const char **val);
544
Simon Glass33ebcb42023-07-12 09:04:42 -0600545/**
546 * bootflow_cmdline_auto() - Automatically set a value for a known argument
547 *
548 * This handles a small number of known arguments, for Linux in particular. It
549 * adds suitable kernel parameters automatically, e.g. to enable the console.
550 *
551 * @bflow: Bootflow to update
552 * @arg: Name of argument to set (e.g. "earlycon" or "console")
553 * Return: 0 if OK -ve on error
554 */
555int bootflow_cmdline_auto(struct bootflow *bflow, const char *arg);
556
Simon Glass9d260252022-04-24 23:31:05 -0600557#endif