From 988cacaeedae920c13741c9ab2fc580f63a06c3a Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 30 Jul 2022 15:52:19 -0600 Subject: bootstd: Provide a bootmeth method to obtain state info Some bootmeths can provide information about what is available to boot. For example, VBE simple provides access to the firmware state. Add a new method for this, along with a sandbox test. Signed-off-by: Simon Glass --- include/bootmeth.h | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'include/bootmeth.h') diff --git a/include/bootmeth.h b/include/bootmeth.h index 484e503e338..4967031a0a8 100644 --- a/include/bootmeth.h +++ b/include/bootmeth.h @@ -24,7 +24,25 @@ struct bootmeth_uc_plat { /** struct bootmeth_ops - Operations for boot methods */ struct bootmeth_ops { /** - * check_supported() - check if a bootmeth supports this bootflow + * get_state_desc() - get detailed state information + * + * Prodecues a textual description of the state of the bootmeth. This + * can include newline characters if it extends to multiple lines. It + * must be a nul-terminated string. + * + * This may involve reading state from the system, e.g. some data in + * the firmware area. + * + * @dev: Bootmethod device to check + * @buf: Buffer to place the info in (terminator must fit) + * @maxsize: Size of buffer + * Returns: 0 if OK, -ENOSPC is buffer is too small, other -ve error if + * something else went wrong + */ + int (*get_state_desc)(struct udevice *dev, char *buf, int maxsize); + + /** + * check_supported() - check if a bootmeth supports this bootdev * * This is optional. If not provided, the bootdev is assumed to be * supported @@ -91,6 +109,24 @@ struct bootmeth_ops { #define bootmeth_get_ops(dev) ((struct bootmeth_ops *)(dev)->driver->ops) +/** + * bootmeth_get_state_desc() - get detailed state information + * + * Prodecues a textual description of the state of the bootmeth. This + * can include newline characters if it extends to multiple lines. It + * must be a nul-terminated string. + * + * This may involve reading state from the system, e.g. some data in + * the firmware area. + * + * @dev: Bootmethod device to check + * @buf: Buffer to place the info in (terminator must fit) + * @maxsize: Size of buffer + * Returns: 0 if OK, -ENOSPC is buffer is too small, other -ve error if + * something else went wrong + */ +int bootmeth_get_state_desc(struct udevice *dev, char *buf, int maxsize); + /** * bootmeth_check() - check if a bootmeth supports this bootflow * -- cgit v1.2.3 From bc06aa035d8f78a713a3d339d45f3d05ef0f0d67 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 30 Jul 2022 15:52:21 -0600 Subject: bootstd: Allow bootmeths to be marked as global The current way of handling things like EFI bootmgr is a bit odd, since that bootmeth handles selection of the bootdev itself. VBE needs to work the same way, so we should support it properly. Add a flag that indicates that the bootmeth is global, rather than being invoked on each bootdev. Provide a helper to read a bootflow from the bootmeth. Signed-off-by: Simon Glass --- include/bootmeth.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'include/bootmeth.h') diff --git a/include/bootmeth.h b/include/bootmeth.h index 4967031a0a8..c93367b0995 100644 --- a/include/bootmeth.h +++ b/include/bootmeth.h @@ -12,13 +12,24 @@ struct bootflow; struct bootflow_iter; struct udevice; +/** + * enum bootmeth_flags - Flags for bootmeths + * + * @BOOTMETHF_GLOBAL: bootmeth handles bootdev selection automatically + */ +enum bootmeth_flags { + BOOTMETHF_GLOBAL = BIT(0), +}; + /** * struct bootmeth_uc_plat - information the uclass keeps about each bootmeth * * @desc: A long description of the bootmeth + * @flags: Flags for this bootmeth (enum bootmeth_flags) */ struct bootmeth_uc_plat { const char *desc; + int flags; }; /** struct bootmeth_ops - Operations for boot methods */ @@ -267,4 +278,16 @@ int bootmeth_alloc_file(struct bootflow *bflow, uint size_limit, uint align); int bootmeth_common_read_file(struct udevice *dev, struct bootflow *bflow, const char *file_path, ulong addr, ulong *sizep); +/** + * bootmeth_get_bootflow() - Get a bootflow from a global bootmeth + * + * Check the bootmeth for a bootflow which can be used. In this case the + * bootmeth handles all bootdev selection, etc. + * + * @dev: bootmeth device to read from + * @bflow: Bootflow information + * @return 0 on success, -ve if a bootflow could not be found or had an error + */ +int bootmeth_get_bootflow(struct udevice *dev, struct bootflow *bflow); + #endif -- cgit v1.2.3 From c627cfc14c08a803f5aa9e39d841dcf990d8d034 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 30 Jul 2022 15:52:27 -0600 Subject: bootstd: Allow scanning for global bootmeths separately Typically we want to find and use global bootmeths first, since they have the best idea of how the system should boot. We then use normal bootmeths as a fallback. Add the logic for this, putting global bootmeths at the end of the ordering. We can then easily scan the global bootmeths first, then drop them from the list for subsequent bootdev-centric scans. This changes the ordering of global bootmeths, so update the bootflow_system() accordingly. Drop the comment from bootmeth_setup_iter_order() since this is an exported function and it should be in the header file. Signed-off-by: Simon Glass --- include/bootmeth.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include/bootmeth.h') diff --git a/include/bootmeth.h b/include/bootmeth.h index c93367b0995..50ded055f3f 100644 --- a/include/bootmeth.h +++ b/include/bootmeth.h @@ -209,10 +209,12 @@ int bootmeth_boot(struct udevice *dev, struct bootflow *bflow); * ordering there, then all bootmethods are added * * @iter: Iterator to update with the order + * @include_global: true to add the global bootmeths, in which case they appear + * first * Return: 0 if OK, -ENOENT if no bootdevs, -ENOMEM if out of memory, other -ve * on other error */ -int bootmeth_setup_iter_order(struct bootflow_iter *iter); +int bootmeth_setup_iter_order(struct bootflow_iter *iter, bool include_global); /** * bootmeth_set_order() - Set the bootmeth order -- cgit v1.2.3