1 /* 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 
10 #include <alist.h>
11 #include <bootdev.h>
12 #include <image.h>
13 #include <dm/ofnode_decl.h>
14 #include <linux/types.h>
15 
16 struct bootstd_priv;
17 struct expo;
18 struct scene;
19 
20 enum {
21 	BOOTFLOW_MAX_USED_DEVS	= 16,
22 };
23 
24 /**
25  * enum bootflow_state_t - states that a particular bootflow can be in
26  *
27  * Only bootflows in state BOOTFLOWST_READY can be used to boot.
28  *
29  * See bootflow_state[] for the names for each of these
30  */
31 enum bootflow_state_t {
32 	BOOTFLOWST_BASE,	/**< Nothing known yet */
33 	BOOTFLOWST_MEDIA,	/**< Media exists */
34 	BOOTFLOWST_PART,	/**< Partition exists */
35 	BOOTFLOWST_FS,		/**< Filesystem exists */
36 	BOOTFLOWST_FILE,	/**< Bootflow file exists */
37 	BOOTFLOWST_READY,	/**< Bootflow file loaded */
38 
39 	BOOTFLOWST_COUNT
40 };
41 
42 /**
43  * enum bootflow_flags_t - flags for bootflows
44  *
45  * @BOOTFLOWF_USE_PRIOR_FDT: Indicates that an FDT was not found by the bootmeth
46  *	and it is using the prior-stage FDT, which is the U-Boot control FDT.
47  *	This is only possible with the EFI bootmeth (distro-efi) and only when
48  *	CONFIG_OF_HAS_PRIOR_STAGE is enabled
49  * @BOOTFLOWF_STATIC_BUF: Indicates that @bflow->buf is statically set, rather
50  *	than being allocated by malloc().
51  * @BOOTFLOWF_USE_BUILTIN_FDT : Indicates that current bootflow uses built-in FDT
52  */
53 enum bootflow_flags_t {
54 	BOOTFLOWF_USE_PRIOR_FDT	= 1 << 0,
55 	BOOTFLOWF_STATIC_BUF	= 1 << 1,
56 	BOOTFLOWF_USE_BUILTIN_FDT	= 1 << 2,
57 };
58 
59 /**
60  * struct bootflow - information about a bootflow
61  *
62  * All bootflows are listed in bootstd's bootflow alist in struct bootstd_priv
63  *
64  * @dev: Bootdev device which produced this bootflow, NULL for flows created by
65  *      BOOTMETHF_GLOBAL bootmeths
66  * @blk: Block device which contains this bootflow, NULL if this is a network
67  *	device or sandbox 'host' device
68  * @part: Partition number (0 for whole device)
69  * @fs_type: Filesystem type (FS_TYPE...) if this is fixed by the media, else 0.
70  *	For example, the sandbox host-filesystem bootdev sets this to
71  *	FS_TYPE_SANDBOX
72  * @method: Bootmethod device used to perform the boot and read files
73  * @name: Name of bootflow (allocated)
74  * @state: Current state (enum bootflow_state_t)
75  * @subdir: Subdirectory to fetch files from (with trailing /), or NULL if none
76  * @fname: Filename of bootflow file (allocated)
77  * @logo: Logo to display for this bootflow (BMP format)
78  * @logo_size: Size of the logo in bytes
79  * @buf: Bootflow file contents (allocated unless @flags & BOOTFLOWF_STATIC_BUF)
80  * @size: Size of bootflow file in bytes
81  * @err: Error number received (0 if OK)
82  * @os_name: Name of the OS / distro being booted, or NULL if not known
83  *	(allocated)
84  * @fdt_fname: Filename of FDT file
85  * @fdt_size: Size of FDT file
86  * @fdt_addr: Address of loaded fdt
87  * @flags: Flags for the bootflow (see enum bootflow_flags_t)
88  * @cmdline: OS command line, or NULL if not known (allocated)
89  * @x86_setup: Pointer to x86 setup block inside @buf, NULL if not present
90  * @bootmeth_priv: Private data for the bootmeth
91  * @images: List of loaded images (struct bootstd_img)
92  */
93 struct bootflow {
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;
103 	void *logo;
104 	uint logo_size;
105 	char *buf;
106 	int size;
107 	int err;
108 	char *os_name;
109 	char *fdt_fname;
110 	int fdt_size;
111 	ulong fdt_addr;
112 	int flags;
113 	char *cmdline;
114 	void *x86_setup;
115 	void *bootmeth_priv;
116 	struct alist images;
117 };
118 
119 /**
120  * bootflow_img_t: Supported image types
121  *
122  * This uses image_type_t for most types, but extends it
123  *
124  * @BFI_EXTLINUX_CFG: extlinux configuration-file
125  * @BFI_LOGO: logo image
126  * @BFI_EFI: EFI PE image
127  * @BFI_CMDLINE: OS command-line string
128  */
129 enum bootflow_img_t {
130 	BFI_FIRST = IH_TYPE_COUNT,
131 	BFI_EXTLINUX_CFG = BFI_FIRST,
132 	BFI_LOGO,
133 	BFI_EFI,
134 	BFI_CMDLINE,
135 
136 	BFI_COUNT,
137 };
138 
139 /**
140  * struct bootflow_img - Information about an image which has been loaded
141  *
142  * This keeps track of a single, loaded image.
143  *
144  * @fname: Filename used to load the image (allocated)
145  * @type: Image type (IH_TYPE_...)
146  * @addr: Address to which the image was loaded, 0 if not yet loaded
147  * @size: Size of the image
148  */
149 struct bootflow_img {
150 	char *fname;
151 	enum bootflow_img_t type;
152 	ulong addr;
153 	ulong size;
154 };
155 
156 /**
157  * enum bootflow_iter_flags_t - flags for the bootflow iterator
158  *
159  * @BOOTFLOWIF_FIXED: Only used fixed/internal media
160  * @BOOTFLOWIF_SHOW: Show each bootdev before scanning it; show each hunter
161  * before using it
162  * @BOOTFLOWIF_ALL: Return bootflows with errors as well
163  * @BOOTFLOWIF_HUNT: Hunt for new bootdevs using the bootdrv hunters
164  * @BOOTFLOWIF_ONLY_BOOTABLE: Only consider partitions marked 'bootable'
165  *
166  * Internal flags:
167  * @BOOTFLOWIF_SINGLE_DEV: (internal) Just scan one bootdev
168  * @BOOTFLOWIF_SKIP_GLOBAL: (internal) Don't scan global bootmeths
169  * @BOOTFLOWIF_SINGLE_UCLASS: (internal) Keep scanning through all devices in
170  * this uclass (used with things like "mmc")
171  * @BOOTFLOWIF_SINGLE_MEDIA: (internal) Scan one media device in the uclass (used
172  * with things like "mmc1")
173  * @BOOTFLOWIF_SINGLE_PARTITION: (internal) Scan one partition in media device
174  * (used with things like "mmc1:3")
175  */
176 enum bootflow_iter_flags_t {
177 	BOOTFLOWIF_FIXED		= 1 << 0,
178 	BOOTFLOWIF_SHOW			= 1 << 1,
179 	BOOTFLOWIF_ALL			= 1 << 2,
180 	BOOTFLOWIF_HUNT			= 1 << 3,
181 	BOOTFLOWIF_ONLY_BOOTABLE	= BIT(4),
182 
183 	/*
184 	 * flags used internally by standard boot - do not set these when
185 	 * calling bootflow_scan_bootdev() etc.
186 	 */
187 	BOOTFLOWIF_SINGLE_DEV		= 1 << 16,
188 	BOOTFLOWIF_SKIP_GLOBAL		= 1 << 17,
189 	BOOTFLOWIF_SINGLE_UCLASS	= 1 << 18,
190 	BOOTFLOWIF_SINGLE_MEDIA		= 1 << 19,
191 	BOOTFLOWIF_SINGLE_PARTITION	= 1 << 20,
192 };
193 
194 /**
195  * enum bootflow_meth_flags_t - flags controlling which bootmeths are used
196  *
197  * Used during iteration, e.g. by bootdev_find_by_label(), to determine which
198  * bootmeths are used for the current bootdev. The flags reset when the bootdev
199  * changes
200  *
201  * @BOOTFLOW_METHF_DHCP_ONLY: Only use dhcp (scripts and EFI)
202  * @BOOTFLOW_METHF_PXE_ONLY: Only use pxe (PXE boot)
203  * @BOOTFLOW_METHF_SINGLE_DEV: Scan only a single bootdev (used for labels like
204  * "3"). This is used if a sequence number is provided instead of a label
205  * @BOOTFLOW_METHF_SINGLE_UCLASS: Scan all bootdevs in this one uclass (used
206  * with things like "mmc"). If this is not set, then the bootdev has an integer
207  * value in the label (like "mmc2")
208  */
209 enum bootflow_meth_flags_t {
210 	BOOTFLOW_METHF_DHCP_ONLY	= 1 << 0,
211 	BOOTFLOW_METHF_PXE_ONLY		= 1 << 1,
212 	BOOTFLOW_METHF_SINGLE_DEV	= 1 << 2,
213 	BOOTFLOW_METHF_SINGLE_UCLASS	= 1 << 3,
214 };
215 
216 /**
217  * struct bootflow_iter - state for iterating through bootflows
218  *
219  * This starts at with the first bootdev/partition/bootmeth and can be used to
220  * iterate through all of them.
221  *
222  * Iteration starts with the bootdev. The first partition (0, i.e. whole device)
223  * is scanned first. For partition 0, it iterates through all the available
224  * bootmeths to see which one(s) can provide a bootflow. Then it moves to
225  * parition 1 (if there is one) and the process continues. Once all partitions
226  * are examined, it moves to the next bootdev.
227  *
228  * Initially @max_part is 0, meaning that only the whole device (@part=0) can be
229  * used. During scanning, if a partition table is found, then @max_part is
230  * updated to a larger value, no less than the number of available partitions.
231  * This ensures that iteration works through all partitions on the bootdev.
232  *
233  * @flags: Flags to use (see enum bootflow_iter_flags_t). If
234  *	BOOTFLOWIF_GLOBAL_FIRST is enabled then the global bootmeths are being
235  *	scanned, otherwise we have moved onto the bootdevs
236  * @dev: Current bootdev, NULL if none. This is only ever updated in
237  * bootflow_iter_set_dev()
238  * @part: Current partition number (0 for whole device)
239  * @method: Current bootmeth
240  * @max_part: Maximum hardware partition number in @dev, 0 if there is no
241  *	partition table
242  * @first_bootable: First bootable partition, or 0 if none
243  * @err: Error obtained from checking the last iteration. This is used to skip
244  *	forward (e.g. to skip the current partition because it is not valid)
245  *	-ESHUTDOWN: try next bootdev
246  * @num_devs: Number of bootdevs in @dev_used
247  * @max_devs: Maximum number of entries in @dev_used
248  * @dev_used: List of bootdevs used during iteration
249  * @labels: List of labels to scan for bootdevs
250  * @cur_label: Current label being processed
251  * @num_methods: Number of bootmeth devices in @method_order
252  * @cur_method: Current method number, an index into @method_order
253  * @first_glob_method: First global method, if any, else -1
254  * @cur_prio: Current priority being scanned
255  * @method_order: List of bootmeth devices to use, in order. The normal methods
256  *	appear first, then the global ones, if any
257  * @doing_global: true if we are iterating through the global bootmeths (which
258  *	happens before the normal ones)
259  * @method_flags: flags controlling which methods should be used for this @dev
260  * (enum bootflow_meth_flags_t)
261  */
262 struct bootflow_iter {
263 	int flags;
264 	struct udevice *dev;
265 	int part;
266 	struct udevice *method;
267 	int max_part;
268 	int first_bootable;
269 	int err;
270 	int num_devs;
271 	int max_devs;
272 	struct udevice *dev_used[BOOTFLOW_MAX_USED_DEVS];
273 	const char *const *labels;
274 	int cur_label;
275 	int num_methods;
276 	int cur_method;
277 	int first_glob_method;
278 	enum bootdev_prio_t cur_prio;
279 	struct udevice **method_order;
280 	bool doing_global;
281 	int method_flags;
282 };
283 
284 /**
285  * bootflow_init() - Set up a bootflow struct
286  *
287  * The bootflow is zeroed and set to state BOOTFLOWST_BASE
288  *
289  * @bflow: Struct to set up
290  * @bootdev: Bootdev to use
291  * @meth: Bootmeth to use
292  */
293 void bootflow_init(struct bootflow *bflow, struct udevice *bootdev,
294 		   struct udevice *meth);
295 
296 /**
297  * bootflow_iter_init() - Reset a bootflow iterator
298  *
299  * This sets everything to the starting point, ready for use.
300  *
301  * @iter: Place to store private info (inited by this call)
302  * @flags: Flags to use (see enum bootflow_iter_flags_t)
303  */
304 void bootflow_iter_init(struct bootflow_iter *iter, int flags);
305 
306 /**
307  * bootflow_iter_uninit() - Free memory used by an interator
308  *
309  * @iter:	Iterator to free
310  */
311 void bootflow_iter_uninit(struct bootflow_iter *iter);
312 
313 /**
314  * bootflow_iter_drop_bootmeth() - Remove a bootmeth from an iterator
315  *
316  * Update the iterator so that the bootmeth will not be used again while this
317  * iterator is in use
318  *
319  * @iter: Iterator to update
320  * @bmeth: Boot method to remove
321  */
322 int bootflow_iter_drop_bootmeth(struct bootflow_iter *iter,
323 				const struct udevice *bmeth);
324 
325 /**
326  * bootflow_scan_first() - find the first bootflow for a device or label
327  *
328  * If @flags includes BOOTFLOWIF_ALL then bootflows with errors are returned too
329  *
330  * @dev:	Boot device to scan, NULL to work through all of them until it
331  *	finds one that can supply a bootflow
332  * @label:	Label to control the scan, NULL to work through all devices
333  *	until it finds one that can supply a bootflow
334  * @iter:	Place to store private info (inited by this call)
335  * @flags:	Flags for iterator (enum bootflow_iter_flags_t). Note that if
336  *	@dev is NULL, then BOOTFLOWIF_SKIP_GLOBAL is set automatically by this
337  *	function
338  * @bflow:	Place to put the bootflow if found
339  * Return: 0 if found,  -ENODEV if no device, other -ve on other error
340  *	(iteration can continue)
341  */
342 int bootflow_scan_first(struct udevice *dev, const char *label,
343 			struct bootflow_iter *iter, int flags,
344 			struct bootflow *bflow);
345 
346 /**
347  * bootflow_scan_next() - find the next bootflow
348  *
349  * This works through the available bootdev devices until it finds one that
350  * can supply a bootflow. It then returns that bootflow
351  *
352  * @iter:	Private info (as set up by bootflow_scan_first())
353  * @bflow:	Place to put the bootflow if found
354  * Return: 0 if found, -ENODEV if no device, -ESHUTDOWN if no more bootflows,
355  *	other -ve on other error (iteration can continue)
356  */
357 int bootflow_scan_next(struct bootflow_iter *iter, struct bootflow *bflow);
358 
359 /**
360  * bootflow_first_glob() - Get the first bootflow from the global list
361  *
362  * Returns the first bootflow in the global list, no matter what bootflow it is
363  * attached to
364  *
365  * @bflowp: Returns a pointer to the bootflow
366  * Return: 0 if found, -ENOENT if there are no bootflows
367  */
368 int bootflow_first_glob(struct bootflow **bflowp);
369 
370 /**
371  * bootflow_next_glob() - Get the next bootflow from the global list
372  *
373  * Returns the next bootflow in the global list, no matter what bootflow it is
374  * attached to
375  *
376  * @bflowp: On entry, the last bootflow returned , e.g. from
377  *	bootflow_first_glob()
378  * Return: 0 if found, -ENOENT if there are no more bootflows
379  */
380 int bootflow_next_glob(struct bootflow **bflowp);
381 
382 /**
383  * bootflow_free() - Free memory used by a bootflow
384  *
385  * This frees fields within @bflow, but not the @bflow pointer itself
386  */
387 void bootflow_free(struct bootflow *bflow);
388 
389 /**
390  * bootflow_boot() - boot a bootflow
391  *
392  * @bflow: Bootflow to boot
393  * Return: -EPROTO if bootflow has not been loaded, -ENOSYS if the bootflow
394  *	type is not supported, -EFAULT if the boot returned without an error
395  *	when we are expecting it to boot, -ENOTSUPP if trying method resulted in
396  *	finding out that is not actually supported for this boot and should not
397  *	be tried again unless something changes
398  */
399 int bootflow_boot(struct bootflow *bflow);
400 
401 /**
402  * bootflow_read_all() - Read all bootflow files
403  *
404  * Some bootmeths delay reading of large files until booting is requested. This
405  * causes those files to be read.
406  *
407  * @bflow: Bootflow to read
408  * Return: result of trying to read
409  */
410 int bootflow_read_all(struct bootflow *bflow);
411 
412 /**
413  * bootflow_run_boot() - Try to boot a bootflow
414  *
415  * @iter: Current iteration (or NULL if none). Used to disable a bootmeth if the
416  *	boot returns -ENOTSUPP
417  * @bflow: Bootflow to boot
418  * Return: result of trying to boot
419  */
420 int bootflow_run_boot(struct bootflow_iter *iter, struct bootflow *bflow);
421 
422 /**
423  * bootflow_state_get_name() - Get the name of a bootflow state
424  *
425  * @state: State to check
426  * Return: name, or "?" if invalid
427  */
428 const char *bootflow_state_get_name(enum bootflow_state_t state);
429 
430 /**
431  * bootflow_remove() - Remove a bootflow and free its memory
432  *
433  * This updates the 'global' linked list containing the bootflow, then frees it.
434  * It does not remove it from bootflows alist in struct bootstd_priv
435  *
436  * This does not free bflow itself, since this is assumed to be in an alist
437  *
438  * @bflow: Bootflow to remove
439  */
440 void bootflow_remove(struct bootflow *bflow);
441 
442 /**
443  * bootflow_iter_check_blk() - Check that a bootflow uses a block device
444  *
445  * This checks the bootdev in the bootflow to make sure it uses a block device
446  *
447  * Return: 0 if OK, -ENOTSUPP if some other device is used (e.g. ethernet)
448  */
449 int bootflow_iter_check_blk(const struct bootflow_iter *iter);
450 
451 /**
452  * bootflow_iter_check_mmc() - Check that a bootflow uses a MMC device
453  *
454  * This checks the bootdev in the bootflow to make sure it uses a mmc device
455  *
456  * Return: 0 if OK, -ENOTSUPP if some other device is used (e.g. ethernet)
457  */
458 int bootflow_iter_check_mmc(const struct bootflow_iter *iter);
459 
460 /**
461  * bootflow_iter_check_sf() - Check that a bootflow uses SPI FLASH
462  *
463  * This checks the bootdev in the bootflow to make sure it uses SPI flash
464  *
465  * Return: 0 if OK, -ENOTSUPP if some other device is used (e.g. ethernet)
466  */
467 int bootflow_iter_check_sf(const struct bootflow_iter *iter);
468 
469 /**
470  * bootflow_iter_check_net() - Check that a bootflow uses a network device
471  *
472  * This checks the bootdev in the bootflow to make sure it uses a network
473  * device
474  *
475  * Return: 0 if OK, -ENOTSUPP if some other device is used (e.g. MMC)
476  */
477 int bootflow_iter_check_net(const struct bootflow_iter *iter);
478 
479 /**
480  * bootflow_iter_check_system() - Check that a bootflow uses the bootstd device
481  *
482  * This checks the bootdev in the bootflow to make sure it uses the bootstd
483  * device
484  *
485  * Return: 0 if OK, -ENOTSUPP if some other device is used (e.g. MMC)
486  */
487 int bootflow_iter_check_system(const struct bootflow_iter *iter);
488 
489 /**
490  * bootflow_menu_new() - Create a new bootflow menu
491  *
492  * This is initially empty. Call bootflow_menu_add_all() to add all the
493  * bootflows to it.
494  *
495  * @expp: Returns the expo created
496  * Returns 0 on success, -ve on error
497  */
498 int bootflow_menu_new(struct expo **expp);
499 
500 /**
501  * bootflow_menu_add_all() - Add all bootflows to a menu
502  *
503  * Loops through all bootflows and adds them to the menu
504  *
505  * @exp: Menu to update
506  * Return 0 on success, -ve on error
507  */
508 int bootflow_menu_add_all(struct expo *exp);
509 
510 /**
511  * bootflow_menu_add() - Add a bootflow to a menu
512  *
513  * Adds a new bootflow to the end of a menu. The caller must be careful to pass
514  * seq=0 for the first bootflow added, 1 for the second, etc.
515  *
516  * @exp: Menu to update
517  * @bflow: Bootflow to add
518  * @seq: Sequence number of this bootflow (0 = first)
519  * @scnp: Returns a pointer to the scene
520  * Return 0 on success, -ve on error
521  */
522 int bootflow_menu_add(struct expo *exp, struct bootflow *bflow, int seq,
523 		      struct scene **scnp);
524 
525 /**
526  * bootflow_menu_apply_theme() - Apply a theme to a bootmenu
527  *
528  * @exp: Expo to update
529  * @node: Node containing the theme information
530  * Returns 0 on success, -ve on error
531  */
532 int bootflow_menu_apply_theme(struct expo *exp, ofnode node);
533 
534 #define BOOTFLOWCL_EMPTY	((void *)1)
535 
536 /**
537  * cmdline_set_arg() - Update or read an argument in a cmdline string
538  *
539  * Handles updating a single arg in a cmdline string, returning it in a supplied
540  * buffer; also reading an arg from a cmdline string
541  *
542  * When updating, consecutive spaces are squashed as are spaces at the start and
543  * end.
544  *
545  * @buf: Working buffer to use (initial contents are ignored). Use NULL when
546  * reading
547  * @maxlen: Length of working buffer. Use 0 when reading
548  * @cmdline: Command line to update, in the form:
549  *
550  *	fred mary= jane=123 john="has spaces"
551  *
552  * @set_arg: Argument to set or read (may or may not exist)
553  * @new_val: Value for the new argument. May not include quotes (") but may
554  * include embedded spaces, in which case it will be quoted when added to the
555  * command line. Use NULL to delete the argument from @cmdline, BOOTFLOWCL_EMPTY
556  * to set it to an empty value (no '=' sign after arg), "" to add an '=' sign
557  * but with an empty value. Use NULL when reading.
558  * @posp: Ignored when setting an argument; when getting an argument, returns
559  * the start position of its value in @cmdline, after the first quote, if any
560  *
561  * Return:
562  * For updating:
563  *	length of new buffer (including \0 terminator) on success, -ENOENT if
564  *	@new_val is NULL and @set_arg does not exist in @from, -EINVAL if a
565  *	quoted arg-value in @from is not terminated with a quote, -EBADF if
566  *	@new_val has spaces but does not start and end with quotes (or it has
567  *	quotes in the middle of the string), -E2BIG if @maxlen is too small
568  * For reading:
569  *	length of arg value (excluding quotes), -ENOENT if not found
570  */
571 int cmdline_set_arg(char *buf, int maxlen, const char *cmdline,
572 		    const char *set_arg, const char *new_val, int *posp);
573 
574 /**
575  * bootflow_cmdline_set_arg() - Set a single argument for a bootflow
576  *
577  * Update the allocated cmdline and set the bootargs variable
578  *
579  * @bflow: Bootflow to update
580  * @arg: Argument to update (e.g. "console")
581  * @val: Value to set (e.g. "ttyS2") or NULL to delete the argument if present,
582  * "" to set it to an empty value (e.g. "console=") and BOOTFLOWCL_EMPTY to add
583  * it without any value ("initrd")
584  * @set_env: true to set the "bootargs" environment variable too
585  *
586  * Return: 0 if OK, -ENOMEM if out of memory
587  */
588 int bootflow_cmdline_set_arg(struct bootflow *bflow, const char *arg,
589 			     const char *val, bool set_env);
590 
591 /**
592  * cmdline_get_arg() - Read an argument from a cmdline
593  *
594  * @cmdline: Command line to read, in the form:
595  *
596  *	fred mary= jane=123 john="has spaces"
597  * @arg: Argument to read (may or may not exist)
598  * @posp: Returns position of argument (after any leading quote) if present
599  * Return: Length of argument value excluding quotes if found, -ENOENT if not
600  * found
601  */
602 int cmdline_get_arg(const char *cmdline, const char *arg, int *posp);
603 
604 /**
605  * bootflow_cmdline_get_arg() - Read an argument from a cmdline
606  *
607  * @bootflow: Bootflow to read from
608  * @arg: Argument to read (may or may not exist)
609  * @valp: Returns a pointer to the argument (after any leading quote) if present
610  * Return: Length of argument value excluding quotes if found, -ENOENT if not
611  * found
612  */
613 int bootflow_cmdline_get_arg(struct bootflow *bflow, const char *arg,
614 			     const char **val);
615 
616 /**
617  * bootflow_cmdline_auto() - Automatically set a value for a known argument
618  *
619  * This handles a small number of known arguments, for Linux in particular. It
620  * adds suitable kernel parameters automatically, e.g. to enable the console.
621  *
622  * @bflow: Bootflow to update
623  * @arg: Name of argument to set (e.g. "earlycon" or "console")
624  * Return: 0 if OK -ve on error
625  */
626 int bootflow_cmdline_auto(struct bootflow *bflow, const char *arg);
627 
628 /**
629  * bootflow_img_type_name() - Get the name for an image type
630  *
631  * @type: Type to check (either enum bootflow_img_t or enum image_type_t
632  * Return: Image name, or "unknown" if not known
633  */
634 const char *bootflow_img_type_name(enum bootflow_img_t type);
635 
636 /**
637  * bootflow_img_add() - Add a new image to a bootflow
638  *
639  * @bflow: Bootflow to add to
640  * @fname: Image filename (will be allocated)
641  * @type: Image type
642  * @addr: Address the image was loaded to, or 0 if not loaded
643  * @size: Image size
644  * Return: pointer to the added image, or NULL if out of memory
645  */
646 struct bootflow_img *bootflow_img_add(struct bootflow *bflow, const char *fname,
647 				      enum bootflow_img_t type, ulong addr,
648 				      ulong size);
649 /**
650  * bootflow_get_seq() - Get the sequence number of a bootflow
651  *
652  * Bootflows are numbered by their position in the bootstd list.
653  *
654  * Return: Sequence number of bootflow (0 = first)
655  */
656 int bootflow_get_seq(const struct bootflow *bflow);
657 
658 /**
659  * bootflow_menu_setup() - Set up a menu for bootflows
660  *
661  * Set up the expo, initially empty
662  *
663  * @std: bootstd information
664  * @text_mode: true to show the menu in text mode, false to use video display
665  * @expp: Returns the expo created, on success
666  * Return: 0 if OK, -ve on error
667  */
668 int bootflow_menu_setup(struct bootstd_priv *std, bool text_mode,
669 			struct expo **expp);
670 
671 /**
672  * bootflow_menu_start() - Start up a menu for bootflows
673  *
674  * Set up the expo and add items
675  *
676  * @std: bootstd information
677  * @text_mode: true to show the menu in text mode, false to use video display
678  * @expp: Returns the expo created, on success
679  * Return: 0 if OK, -ve on error
680  */
681 int bootflow_menu_start(struct bootstd_priv *std, bool text_mode,
682 			struct expo **expp);
683 
684 /**
685  * bootflow_menu_poll() - Poll a menu for user action
686  *
687  * @exp: Expo to poll
688  * @seqp: Returns the bootflow chosen or currently pointed to (numbered from 0)
689  * Return: 0 if a bootflow was chosen, -EAGAIN if nothing is chosen yet, -EPIPE
690  *	if the user quit, -ERESTART if the expo needs refreshing
691  */
692 int bootflow_menu_poll(struct expo *exp, int *seqp);
693 
694 #endif
695