Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 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 | |
Simon Glass | 660a995 | 2023-01-17 10:48:11 -0700 | [diff] [blame] | 10 | #include <bootdev.h> |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 11 | #include <dm/ofnode_decl.h> |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 12 | #include <linux/list.h> |
| 13 | |
Simon Glass | 0a2f6a3 | 2023-01-06 08:52:40 -0600 | [diff] [blame] | 14 | struct bootstd_priv; |
| 15 | struct expo; |
| 16 | |
Simon Glass | cb2a5cd | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 17 | enum { |
| 18 | BOOTFLOW_MAX_USED_DEVS = 16, |
| 19 | }; |
| 20 | |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 21 | /** |
| 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 | */ |
| 28 | enum 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 Glass | ca84dc8 | 2023-02-22 12:17:04 -0700 | [diff] [blame] | 40 | * 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 Glass | 254c934 | 2023-11-15 18:35:23 -0700 | [diff] [blame] | 46 | * @BOOTFLOWF_STATIC_BUF: Indicates that @bflow->buf is statically set, rather |
| 47 | * than being allocated by malloc(). |
Shantur Rathore | aab9cdb | 2023-11-19 16:55:00 +0000 | [diff] [blame] | 48 | * @BOOTFLOWF_USE_BUILTIN_FDT : Indicates that current bootflow uses built-in FDT |
Simon Glass | ca84dc8 | 2023-02-22 12:17:04 -0700 | [diff] [blame] | 49 | */ |
| 50 | enum bootflow_flags_t { |
| 51 | BOOTFLOWF_USE_PRIOR_FDT = 1 << 0, |
Simon Glass | 254c934 | 2023-11-15 18:35:23 -0700 | [diff] [blame] | 52 | BOOTFLOWF_STATIC_BUF = 1 << 1, |
Shantur Rathore | aab9cdb | 2023-11-19 16:55:00 +0000 | [diff] [blame] | 53 | BOOTFLOWF_USE_BUILTIN_FDT = 1 << 2, |
Simon Glass | ca84dc8 | 2023-02-22 12:17:04 -0700 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | /** |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 57 | * struct bootflow - information about a bootflow |
| 58 | * |
| 59 | * This is connected into two separate linked lists: |
| 60 | * |
| 61 | * bm_sibling - links all bootflows in the same bootdev |
| 62 | * glob_sibling - links all bootflows in all bootdevs |
| 63 | * |
| 64 | * @bm_node: Points to siblings in the same bootdev |
| 65 | * @glob_node: Points to siblings in the global list (all bootdev) |
Quentin Schulz | 21a6aec | 2024-06-12 16:58:49 +0200 | [diff] [blame] | 66 | * @dev: Bootdev device which produced this bootflow, NULL for flows created by |
| 67 | * BOOTMETHF_GLOBAL bootmeths |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 68 | * @blk: Block device which contains this bootflow, NULL if this is a network |
Simon Glass | 4adeeb8 | 2023-01-17 10:47:59 -0700 | [diff] [blame] | 69 | * device or sandbox 'host' device |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 70 | * @part: Partition number (0 for whole device) |
| 71 | * @fs_type: Filesystem type (FS_TYPE...) if this is fixed by the media, else 0. |
| 72 | * For example, the sandbox host-filesystem bootdev sets this to |
| 73 | * FS_TYPE_SANDBOX |
| 74 | * @method: Bootmethod device used to perform the boot and read files |
| 75 | * @name: Name of bootflow (allocated) |
| 76 | * @state: Current state (enum bootflow_state_t) |
| 77 | * @subdir: Subdirectory to fetch files from (with trailing /), or NULL if none |
| 78 | * @fname: Filename of bootflow file (allocated) |
Simon Glass | 612b9cc | 2023-01-06 08:52:34 -0600 | [diff] [blame] | 79 | * @logo: Logo to display for this bootflow (BMP format) |
| 80 | * @logo_size: Size of the logo in bytes |
Simon Glass | 254c934 | 2023-11-15 18:35:23 -0700 | [diff] [blame] | 81 | * @buf: Bootflow file contents (allocated unless @flags & BOOTFLOWF_STATIC_BUF) |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 82 | * @size: Size of bootflow file in bytes |
| 83 | * @err: Error number received (0 if OK) |
Simon Glass | 72b7b19 | 2023-01-06 08:52:33 -0600 | [diff] [blame] | 84 | * @os_name: Name of the OS / distro being booted, or NULL if not known |
| 85 | * (allocated) |
Simon Glass | 7b8c634 | 2023-01-17 10:47:56 -0700 | [diff] [blame] | 86 | * @fdt_fname: Filename of FDT file |
| 87 | * @fdt_size: Size of FDT file |
| 88 | * @fdt_addr: Address of loaded fdt |
Simon Glass | ca84dc8 | 2023-02-22 12:17:04 -0700 | [diff] [blame] | 89 | * @flags: Flags for the bootflow (see enum bootflow_flags_t) |
Simon Glass | 3392752 | 2023-07-12 09:04:34 -0600 | [diff] [blame] | 90 | * @cmdline: OS command line, or NULL if not known (allocated) |
Simon Glass | 63398b0 | 2023-07-12 09:04:36 -0600 | [diff] [blame] | 91 | * @x86_setup: Pointer to x86 setup block inside @buf, NULL if not present |
Simon Glass | 7f75f23 | 2023-07-30 11:16:56 -0600 | [diff] [blame] | 92 | * @bootmeth_priv: Private data for the bootmeth |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 93 | */ |
| 94 | struct bootflow { |
| 95 | struct list_head bm_node; |
| 96 | struct list_head glob_node; |
| 97 | struct udevice *dev; |
| 98 | struct udevice *blk; |
| 99 | int part; |
| 100 | int fs_type; |
| 101 | struct udevice *method; |
| 102 | char *name; |
| 103 | enum bootflow_state_t state; |
| 104 | char *subdir; |
| 105 | char *fname; |
Simon Glass | 612b9cc | 2023-01-06 08:52:34 -0600 | [diff] [blame] | 106 | void *logo; |
| 107 | uint logo_size; |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 108 | char *buf; |
| 109 | int size; |
| 110 | int err; |
Simon Glass | 72b7b19 | 2023-01-06 08:52:33 -0600 | [diff] [blame] | 111 | char *os_name; |
Simon Glass | 7b8c634 | 2023-01-17 10:47:56 -0700 | [diff] [blame] | 112 | char *fdt_fname; |
| 113 | int fdt_size; |
| 114 | ulong fdt_addr; |
Simon Glass | ca84dc8 | 2023-02-22 12:17:04 -0700 | [diff] [blame] | 115 | int flags; |
Simon Glass | 3392752 | 2023-07-12 09:04:34 -0600 | [diff] [blame] | 116 | char *cmdline; |
Simon Glass | 5495aaf | 2023-07-30 11:17:00 -0600 | [diff] [blame] | 117 | void *x86_setup; |
Simon Glass | 7f75f23 | 2023-07-30 11:16:56 -0600 | [diff] [blame] | 118 | void *bootmeth_priv; |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | /** |
Simon Glass | 99e6818 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 122 | * enum bootflow_iter_flags_t - flags for the bootflow iterator |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 123 | * |
Simon Glass | 99e6818 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 124 | * @BOOTFLOWIF_FIXED: Only used fixed/internal media |
| 125 | * @BOOTFLOWIF_SHOW: Show each bootdev before scanning it; show each hunter |
Simon Glass | a21e775 | 2023-01-17 10:48:06 -0700 | [diff] [blame] | 126 | * before using it |
Simon Glass | 99e6818 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 127 | * @BOOTFLOWIF_ALL: Return bootflows with errors as well |
| 128 | * @BOOTFLOWIF_HUNT: Hunt for new bootdevs using the bootdrv hunters |
Simon Glass | a21e775 | 2023-01-17 10:48:06 -0700 | [diff] [blame] | 129 | * |
| 130 | * Internal flags: |
Simon Glass | 99e6818 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 131 | * @BOOTFLOWIF_SINGLE_DEV: (internal) Just scan one bootdev |
| 132 | * @BOOTFLOWIF_SKIP_GLOBAL: (internal) Don't scan global bootmeths |
| 133 | * @BOOTFLOWIF_SINGLE_UCLASS: (internal) Keep scanning through all devices in |
Simon Glass | de567b1 | 2023-01-17 10:48:09 -0700 | [diff] [blame] | 134 | * this uclass (used with things like "mmc") |
Simon Glass | 99e6818 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 135 | * @BOOTFLOWIF_SINGLE_MEDIA: (internal) Scan one media device in the uclass (used |
Simon Glass | de567b1 | 2023-01-17 10:48:09 -0700 | [diff] [blame] | 136 | * with things like "mmc1") |
Nam Cao | cb0d3fb | 2024-02-21 13:41:44 +0100 | [diff] [blame] | 137 | * @BOOTFLOWIF_SINGLE_PARTITION: (internal) Scan one partition in media device |
| 138 | * (used with things like "mmc1:3") |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 139 | */ |
Simon Glass | 99e6818 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 140 | enum bootflow_iter_flags_t { |
| 141 | BOOTFLOWIF_FIXED = 1 << 0, |
| 142 | BOOTFLOWIF_SHOW = 1 << 1, |
| 143 | BOOTFLOWIF_ALL = 1 << 2, |
| 144 | BOOTFLOWIF_HUNT = 1 << 3, |
Simon Glass | a21e775 | 2023-01-17 10:48:06 -0700 | [diff] [blame] | 145 | |
| 146 | /* |
| 147 | * flags used internally by standard boot - do not set these when |
| 148 | * calling bootflow_scan_bootdev() etc. |
| 149 | */ |
Simon Glass | 99e6818 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 150 | BOOTFLOWIF_SINGLE_DEV = 1 << 16, |
| 151 | BOOTFLOWIF_SKIP_GLOBAL = 1 << 17, |
| 152 | BOOTFLOWIF_SINGLE_UCLASS = 1 << 18, |
| 153 | BOOTFLOWIF_SINGLE_MEDIA = 1 << 19, |
Nam Cao | cb0d3fb | 2024-02-21 13:41:44 +0100 | [diff] [blame] | 154 | BOOTFLOWIF_SINGLE_PARTITION = 1 << 20, |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 155 | }; |
| 156 | |
| 157 | /** |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 158 | * enum bootflow_meth_flags_t - flags controlling which bootmeths are used |
| 159 | * |
| 160 | * Used during iteration, e.g. by bootdev_find_by_label(), to determine which |
| 161 | * bootmeths are used for the current bootdev. The flags reset when the bootdev |
| 162 | * changes |
| 163 | * |
| 164 | * @BOOTFLOW_METHF_DHCP_ONLY: Only use dhcp (scripts and EFI) |
| 165 | * @BOOTFLOW_METHF_PXE_ONLY: Only use pxe (PXE boot) |
Simon Glass | de567b1 | 2023-01-17 10:48:09 -0700 | [diff] [blame] | 166 | * @BOOTFLOW_METHF_SINGLE_DEV: Scan only a single bootdev (used for labels like |
| 167 | * "3"). This is used if a sequence number is provided instead of a label |
| 168 | * @BOOTFLOW_METHF_SINGLE_UCLASS: Scan all bootdevs in this one uclass (used |
| 169 | * with things like "mmc"). If this is not set, then the bootdev has an integer |
| 170 | * value in the label (like "mmc2") |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 171 | */ |
| 172 | enum bootflow_meth_flags_t { |
| 173 | BOOTFLOW_METHF_DHCP_ONLY = 1 << 0, |
| 174 | BOOTFLOW_METHF_PXE_ONLY = 1 << 1, |
Simon Glass | de567b1 | 2023-01-17 10:48:09 -0700 | [diff] [blame] | 175 | BOOTFLOW_METHF_SINGLE_DEV = 1 << 2, |
| 176 | BOOTFLOW_METHF_SINGLE_UCLASS = 1 << 3, |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 177 | }; |
| 178 | |
| 179 | /** |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 180 | * struct bootflow_iter - state for iterating through bootflows |
| 181 | * |
| 182 | * This starts at with the first bootdev/partition/bootmeth and can be used to |
| 183 | * iterate through all of them. |
| 184 | * |
| 185 | * Iteration starts with the bootdev. The first partition (0, i.e. whole device) |
| 186 | * is scanned first. For partition 0, it iterates through all the available |
| 187 | * bootmeths to see which one(s) can provide a bootflow. Then it moves to |
| 188 | * parition 1 (if there is one) and the process continues. Once all partitions |
| 189 | * are examined, it moves to the next bootdev. |
| 190 | * |
| 191 | * Initially @max_part is 0, meaning that only the whole device (@part=0) can be |
| 192 | * used. During scanning, if a partition table is found, then @max_part is |
| 193 | * updated to a larger value, no less than the number of available partitions. |
| 194 | * This ensures that iteration works through all partitions on the bootdev. |
| 195 | * |
Simon Glass | 99e6818 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 196 | * @flags: Flags to use (see enum bootflow_iter_flags_t). If |
| 197 | * BOOTFLOWIF_GLOBAL_FIRST is enabled then the global bootmeths are being |
| 198 | * scanned, otherwise we have moved onto the bootdevs |
Simon Glass | 484e407 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 199 | * @dev: Current bootdev, NULL if none. This is only ever updated in |
| 200 | * bootflow_iter_set_dev() |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 201 | * @part: Current partition number (0 for whole device) |
| 202 | * @method: Current bootmeth |
| 203 | * @max_part: Maximum hardware partition number in @dev, 0 if there is no |
| 204 | * partition table |
Simon Glass | 64cbc5c | 2023-01-17 10:47:42 -0700 | [diff] [blame] | 205 | * @first_bootable: First bootable partition, or 0 if none |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 206 | * @err: Error obtained from checking the last iteration. This is used to skip |
| 207 | * forward (e.g. to skip the current partition because it is not valid) |
| 208 | * -ESHUTDOWN: try next bootdev |
Simon Glass | cb2a5cd | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 209 | * @num_devs: Number of bootdevs in @dev_used |
| 210 | * @max_devs: Maximum number of entries in @dev_used |
| 211 | * @dev_used: List of bootdevs used during iteration |
Simon Glass | ac06b26a | 2023-01-17 10:48:10 -0700 | [diff] [blame] | 212 | * @labels: List of labels to scan for bootdevs |
| 213 | * @cur_label: Current label being processed |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 214 | * @num_methods: Number of bootmeth devices in @method_order |
| 215 | * @cur_method: Current method number, an index into @method_order |
Simon Glass | 73fcf51 | 2022-07-30 15:52:25 -0600 | [diff] [blame] | 216 | * @first_glob_method: First global method, if any, else -1 |
Simon Glass | 660a995 | 2023-01-17 10:48:11 -0700 | [diff] [blame] | 217 | * @cur_prio: Current priority being scanned |
Simon Glass | 73fcf51 | 2022-07-30 15:52:25 -0600 | [diff] [blame] | 218 | * @method_order: List of bootmeth devices to use, in order. The normal methods |
| 219 | * appear first, then the global ones, if any |
| 220 | * @doing_global: true if we are iterating through the global bootmeths (which |
| 221 | * happens before the normal ones) |
Simon Glass | 30fbeb5 | 2023-01-17 10:47:58 -0700 | [diff] [blame] | 222 | * @method_flags: flags controlling which methods should be used for this @dev |
| 223 | * (enum bootflow_meth_flags_t) |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 224 | */ |
| 225 | struct bootflow_iter { |
| 226 | int flags; |
| 227 | struct udevice *dev; |
| 228 | int part; |
| 229 | struct udevice *method; |
| 230 | int max_part; |
Simon Glass | 64cbc5c | 2023-01-17 10:47:42 -0700 | [diff] [blame] | 231 | int first_bootable; |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 232 | int err; |
| 233 | int num_devs; |
Simon Glass | cb2a5cd | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 234 | int max_devs; |
| 235 | struct udevice *dev_used[BOOTFLOW_MAX_USED_DEVS]; |
Simon Glass | ac06b26a | 2023-01-17 10:48:10 -0700 | [diff] [blame] | 236 | const char *const *labels; |
| 237 | int cur_label; |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 238 | int num_methods; |
| 239 | int cur_method; |
Simon Glass | 73fcf51 | 2022-07-30 15:52:25 -0600 | [diff] [blame] | 240 | int first_glob_method; |
Simon Glass | 660a995 | 2023-01-17 10:48:11 -0700 | [diff] [blame] | 241 | enum bootdev_prio_t cur_prio; |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 242 | struct udevice **method_order; |
Simon Glass | 73fcf51 | 2022-07-30 15:52:25 -0600 | [diff] [blame] | 243 | bool doing_global; |
Simon Glass | 30fbeb5 | 2023-01-17 10:47:58 -0700 | [diff] [blame] | 244 | int method_flags; |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 245 | }; |
| 246 | |
| 247 | /** |
Simon Glass | 00501fc | 2022-10-20 18:22:51 -0600 | [diff] [blame] | 248 | * bootflow_init() - Set up a bootflow struct |
| 249 | * |
| 250 | * The bootflow is zeroed and set to state BOOTFLOWST_BASE |
| 251 | * |
| 252 | * @bflow: Struct to set up |
| 253 | * @bootdev: Bootdev to use |
| 254 | * @meth: Bootmeth to use |
| 255 | */ |
| 256 | void bootflow_init(struct bootflow *bflow, struct udevice *bootdev, |
| 257 | struct udevice *meth); |
| 258 | |
| 259 | /** |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 260 | * bootflow_iter_init() - Reset a bootflow iterator |
| 261 | * |
| 262 | * This sets everything to the starting point, ready for use. |
| 263 | * |
| 264 | * @iter: Place to store private info (inited by this call) |
Simon Glass | 99e6818 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 265 | * @flags: Flags to use (see enum bootflow_iter_flags_t) |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 266 | */ |
| 267 | void bootflow_iter_init(struct bootflow_iter *iter, int flags); |
| 268 | |
| 269 | /** |
| 270 | * bootflow_iter_uninit() - Free memory used by an interator |
| 271 | * |
| 272 | * @iter: Iterator to free |
| 273 | */ |
| 274 | void bootflow_iter_uninit(struct bootflow_iter *iter); |
| 275 | |
| 276 | /** |
Simon Glass | 03fcbf9 | 2022-04-24 23:31:09 -0600 | [diff] [blame] | 277 | * bootflow_iter_drop_bootmeth() - Remove a bootmeth from an iterator |
| 278 | * |
| 279 | * Update the iterator so that the bootmeth will not be used again while this |
| 280 | * iterator is in use |
| 281 | * |
| 282 | * @iter: Iterator to update |
| 283 | * @bmeth: Boot method to remove |
| 284 | */ |
| 285 | int bootflow_iter_drop_bootmeth(struct bootflow_iter *iter, |
| 286 | const struct udevice *bmeth); |
| 287 | |
| 288 | /** |
Simon Glass | 5d3d44f | 2023-01-17 10:48:16 -0700 | [diff] [blame] | 289 | * bootflow_scan_first() - find the first bootflow for a device or label |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 290 | * |
Simon Glass | 99e6818 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 291 | * If @flags includes BOOTFLOWIF_ALL then bootflows with errors are returned too |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 292 | * |
| 293 | * @dev: Boot device to scan, NULL to work through all of them until it |
Simon Glass | 943d38c | 2022-07-30 15:52:24 -0600 | [diff] [blame] | 294 | * finds one that can supply a bootflow |
Simon Glass | ba3d537 | 2023-01-17 10:48:15 -0700 | [diff] [blame] | 295 | * @label: Label to control the scan, NULL to work through all devices |
| 296 | * until it finds one that can supply a bootflow |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 297 | * @iter: Place to store private info (inited by this call) |
Simon Glass | 99e6818 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 298 | * @flags: Flags for iterator (enum bootflow_iter_flags_t). Note that if |
| 299 | * @dev is NULL, then BOOTFLOWIF_SKIP_GLOBAL is set automatically by this |
| 300 | * function |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 301 | * @bflow: Place to put the bootflow if found |
| 302 | * Return: 0 if found, -ENODEV if no device, other -ve on other error |
| 303 | * (iteration can continue) |
| 304 | */ |
Simon Glass | 5d3d44f | 2023-01-17 10:48:16 -0700 | [diff] [blame] | 305 | int bootflow_scan_first(struct udevice *dev, const char *label, |
| 306 | struct bootflow_iter *iter, int flags, |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 307 | struct bootflow *bflow); |
| 308 | |
| 309 | /** |
| 310 | * bootflow_scan_next() - find the next bootflow |
| 311 | * |
| 312 | * This works through the available bootdev devices until it finds one that |
| 313 | * can supply a bootflow. It then returns that bootflow |
| 314 | * |
| 315 | * @iter: Private info (as set up by bootflow_scan_first()) |
| 316 | * @bflow: Place to put the bootflow if found |
| 317 | * Return: 0 if found, -ENODEV if no device, -ESHUTDOWN if no more bootflows, |
| 318 | * other -ve on other error (iteration can continue) |
| 319 | */ |
| 320 | int bootflow_scan_next(struct bootflow_iter *iter, struct bootflow *bflow); |
| 321 | |
| 322 | /** |
| 323 | * bootflow_first_glob() - Get the first bootflow from the global list |
| 324 | * |
| 325 | * Returns the first bootflow in the global list, no matter what bootflow it is |
| 326 | * attached to |
| 327 | * |
| 328 | * @bflowp: Returns a pointer to the bootflow |
| 329 | * Return: 0 if found, -ENOENT if there are no bootflows |
| 330 | */ |
| 331 | int bootflow_first_glob(struct bootflow **bflowp); |
| 332 | |
| 333 | /** |
| 334 | * bootflow_next_glob() - Get the next bootflow from the global list |
| 335 | * |
| 336 | * Returns the next bootflow in the global list, no matter what bootflow it is |
| 337 | * attached to |
| 338 | * |
| 339 | * @bflowp: On entry, the last bootflow returned , e.g. from |
| 340 | * bootflow_first_glob() |
| 341 | * Return: 0 if found, -ENOENT if there are no more bootflows |
| 342 | */ |
| 343 | int bootflow_next_glob(struct bootflow **bflowp); |
| 344 | |
| 345 | /** |
| 346 | * bootflow_free() - Free memory used by a bootflow |
| 347 | * |
| 348 | * This frees fields within @bflow, but not the @bflow pointer itself |
| 349 | */ |
| 350 | void bootflow_free(struct bootflow *bflow); |
| 351 | |
| 352 | /** |
| 353 | * bootflow_boot() - boot a bootflow |
| 354 | * |
| 355 | * @bflow: Bootflow to boot |
| 356 | * Return: -EPROTO if bootflow has not been loaded, -ENOSYS if the bootflow |
| 357 | * type is not supported, -EFAULT if the boot returned without an error |
| 358 | * when we are expecting it to boot, -ENOTSUPP if trying method resulted in |
| 359 | * finding out that is not actually supported for this boot and should not |
| 360 | * be tried again unless something changes |
| 361 | */ |
| 362 | int bootflow_boot(struct bootflow *bflow); |
| 363 | |
| 364 | /** |
Simon Glass | 6d8f95b | 2023-08-10 19:33:18 -0600 | [diff] [blame] | 365 | * bootflow_read_all() - Read all bootflow files |
| 366 | * |
| 367 | * Some bootmeths delay reading of large files until booting is requested. This |
| 368 | * causes those files to be read. |
| 369 | * |
| 370 | * @bflow: Bootflow to read |
| 371 | * Return: result of trying to read |
| 372 | */ |
| 373 | int bootflow_read_all(struct bootflow *bflow); |
| 374 | |
| 375 | /** |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 376 | * bootflow_run_boot() - Try to boot a bootflow |
| 377 | * |
| 378 | * @iter: Current iteration (or NULL if none). Used to disable a bootmeth if the |
| 379 | * boot returns -ENOTSUPP |
| 380 | * @bflow: Bootflow to boot |
| 381 | * Return: result of trying to boot |
| 382 | */ |
| 383 | int bootflow_run_boot(struct bootflow_iter *iter, struct bootflow *bflow); |
| 384 | |
| 385 | /** |
| 386 | * bootflow_state_get_name() - Get the name of a bootflow state |
| 387 | * |
| 388 | * @state: State to check |
| 389 | * Return: name, or "?" if invalid |
| 390 | */ |
| 391 | const char *bootflow_state_get_name(enum bootflow_state_t state); |
| 392 | |
Simon Glass | 03fcbf9 | 2022-04-24 23:31:09 -0600 | [diff] [blame] | 393 | /** |
| 394 | * bootflow_remove() - Remove a bootflow and free its memory |
| 395 | * |
| 396 | * This updates the linked lists containing the bootflow then frees it. |
| 397 | * |
| 398 | * @bflow: Bootflow to remove |
| 399 | */ |
| 400 | void bootflow_remove(struct bootflow *bflow); |
| 401 | |
| 402 | /** |
Simon Glass | 18c5040 | 2023-01-17 10:47:54 -0700 | [diff] [blame] | 403 | * bootflow_iter_check_blk() - Check that a bootflow uses a block device |
Simon Glass | 03fcbf9 | 2022-04-24 23:31:09 -0600 | [diff] [blame] | 404 | * |
| 405 | * This checks the bootdev in the bootflow to make sure it uses a block device |
| 406 | * |
| 407 | * Return: 0 if OK, -ENOTSUPP if some other device is used (e.g. ethernet) |
| 408 | */ |
Simon Glass | 18c5040 | 2023-01-17 10:47:54 -0700 | [diff] [blame] | 409 | int bootflow_iter_check_blk(const struct bootflow_iter *iter); |
Simon Glass | 03fcbf9 | 2022-04-24 23:31:09 -0600 | [diff] [blame] | 410 | |
| 411 | /** |
Mattijs Korpershoek | fc420be | 2024-07-10 10:40:03 +0200 | [diff] [blame] | 412 | * bootflow_iter_check_mmc() - Check that a bootflow uses a MMC device |
| 413 | * |
| 414 | * This checks the bootdev in the bootflow to make sure it uses a mmc device |
| 415 | * |
| 416 | * Return: 0 if OK, -ENOTSUPP if some other device is used (e.g. ethernet) |
| 417 | */ |
| 418 | int bootflow_iter_check_mmc(const struct bootflow_iter *iter); |
| 419 | |
| 420 | /** |
Simon Glass | 215be68 | 2023-01-17 10:48:03 -0700 | [diff] [blame] | 421 | * bootflow_iter_check_sf() - Check that a bootflow uses SPI FLASH |
| 422 | * |
| 423 | * This checks the bootdev in the bootflow to make sure it uses SPI flash |
| 424 | * |
| 425 | * Return: 0 if OK, -ENOTSUPP if some other device is used (e.g. ethernet) |
| 426 | */ |
| 427 | int bootflow_iter_check_sf(const struct bootflow_iter *iter); |
| 428 | |
| 429 | /** |
Simon Glass | 18c5040 | 2023-01-17 10:47:54 -0700 | [diff] [blame] | 430 | * bootflow_iter_check_net() - Check that a bootflow uses a network device |
Simon Glass | 03fcbf9 | 2022-04-24 23:31:09 -0600 | [diff] [blame] | 431 | * |
| 432 | * This checks the bootdev in the bootflow to make sure it uses a network |
| 433 | * device |
| 434 | * |
| 435 | * Return: 0 if OK, -ENOTSUPP if some other device is used (e.g. MMC) |
| 436 | */ |
Simon Glass | 18c5040 | 2023-01-17 10:47:54 -0700 | [diff] [blame] | 437 | int bootflow_iter_check_net(const struct bootflow_iter *iter); |
Simon Glass | 03fcbf9 | 2022-04-24 23:31:09 -0600 | [diff] [blame] | 438 | |
| 439 | /** |
Simon Glass | 18c5040 | 2023-01-17 10:47:54 -0700 | [diff] [blame] | 440 | * bootflow_iter_check_system() - Check that a bootflow uses the bootstd device |
Simon Glass | 03fcbf9 | 2022-04-24 23:31:09 -0600 | [diff] [blame] | 441 | * |
| 442 | * This checks the bootdev in the bootflow to make sure it uses the bootstd |
| 443 | * device |
| 444 | * |
| 445 | * Return: 0 if OK, -ENOTSUPP if some other device is used (e.g. MMC) |
| 446 | */ |
Simon Glass | 18c5040 | 2023-01-17 10:47:54 -0700 | [diff] [blame] | 447 | int bootflow_iter_check_system(const struct bootflow_iter *iter); |
Simon Glass | 03fcbf9 | 2022-04-24 23:31:09 -0600 | [diff] [blame] | 448 | |
Simon Glass | 0a2f6a3 | 2023-01-06 08:52:40 -0600 | [diff] [blame] | 449 | /** |
| 450 | * bootflow_menu_new() - Create a new bootflow menu |
| 451 | * |
| 452 | * @expp: Returns the expo created |
| 453 | * Returns 0 on success, -ve on error |
| 454 | */ |
| 455 | int bootflow_menu_new(struct expo **expp); |
| 456 | |
| 457 | /** |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 458 | * bootflow_menu_apply_theme() - Apply a theme to a bootmenu |
| 459 | * |
| 460 | * @exp: Expo to update |
| 461 | * @node: Node containing the theme information |
| 462 | * Returns 0 on success, -ve on error |
| 463 | */ |
| 464 | int bootflow_menu_apply_theme(struct expo *exp, ofnode node); |
| 465 | |
| 466 | /** |
Simon Glass | 0a2f6a3 | 2023-01-06 08:52:40 -0600 | [diff] [blame] | 467 | * bootflow_menu_run() - Create and run a menu of available bootflows |
| 468 | * |
| 469 | * @std: Bootstd information |
| 470 | * @text_mode: Uses a text-based menu suitable for a serial port |
| 471 | * @bflowp: Returns chosen bootflow (set to NULL if nothing is chosen) |
| 472 | * @return 0 if an option was chosen, -EAGAIN if nothing was chosen, -ve on |
| 473 | * error |
| 474 | */ |
| 475 | int bootflow_menu_run(struct bootstd_priv *std, bool text_mode, |
| 476 | struct bootflow **bflowp); |
| 477 | |
Simon Glass | a08adca | 2023-07-12 09:04:38 -0600 | [diff] [blame] | 478 | #define BOOTFLOWCL_EMPTY ((void *)1) |
| 479 | |
| 480 | /** |
| 481 | * cmdline_set_arg() - Update or read an argument in a cmdline string |
| 482 | * |
| 483 | * Handles updating a single arg in a cmdline string, returning it in a supplied |
| 484 | * buffer; also reading an arg from a cmdline string |
| 485 | * |
| 486 | * When updating, consecutive spaces are squashed as are spaces at the start and |
| 487 | * end. |
| 488 | * |
| 489 | * @buf: Working buffer to use (initial contents are ignored). Use NULL when |
| 490 | * reading |
| 491 | * @maxlen: Length of working buffer. Use 0 when reading |
| 492 | * @cmdline: Command line to update, in the form: |
| 493 | * |
| 494 | * fred mary= jane=123 john="has spaces" |
| 495 | * |
| 496 | * @set_arg: Argument to set or read (may or may not exist) |
| 497 | * @new_val: Value for the new argument. May not include quotes (") but may |
| 498 | * include embedded spaces, in which case it will be quoted when added to the |
| 499 | * command line. Use NULL to delete the argument from @cmdline, BOOTFLOWCL_EMPTY |
| 500 | * to set it to an empty value (no '=' sign after arg), "" to add an '=' sign |
| 501 | * but with an empty value. Use NULL when reading. |
| 502 | * @posp: Ignored when setting an argument; when getting an argument, returns |
| 503 | * the start position of its value in @cmdline, after the first quote, if any |
| 504 | * |
| 505 | * Return: |
| 506 | * For updating: |
| 507 | * length of new buffer (including \0 terminator) on success, -ENOENT if |
| 508 | * @new_val is NULL and @set_arg does not exist in @from, -EINVAL if a |
| 509 | * quoted arg-value in @from is not terminated with a quote, -EBADF if |
| 510 | * @new_val has spaces but does not start and end with quotes (or it has |
| 511 | * quotes in the middle of the string), -E2BIG if @maxlen is too small |
| 512 | * For reading: |
| 513 | * length of arg value (excluding quotes), -ENOENT if not found |
| 514 | */ |
| 515 | int cmdline_set_arg(char *buf, int maxlen, const char *cmdline, |
| 516 | const char *set_arg, const char *new_val, int *posp); |
| 517 | |
Simon Glass | 55a2da3 | 2023-07-12 09:04:39 -0600 | [diff] [blame] | 518 | /** |
| 519 | * bootflow_cmdline_set_arg() - Set a single argument for a bootflow |
| 520 | * |
| 521 | * Update the allocated cmdline and set the bootargs variable |
| 522 | * |
| 523 | * @bflow: Bootflow to update |
| 524 | * @arg: Argument to update (e.g. "console") |
| 525 | * @val: Value to set (e.g. "ttyS2") or NULL to delete the argument if present, |
| 526 | * "" to set it to an empty value (e.g. "console=") and BOOTFLOWCL_EMPTY to add |
| 527 | * it without any value ("initrd") |
| 528 | * @set_env: true to set the "bootargs" environment variable too |
| 529 | * |
| 530 | * Return: 0 if OK, -ENOMEM if out of memory |
| 531 | */ |
| 532 | int bootflow_cmdline_set_arg(struct bootflow *bflow, const char *arg, |
| 533 | const char *val, bool set_env); |
| 534 | |
| 535 | /** |
| 536 | * cmdline_get_arg() - Read an argument from a cmdline |
| 537 | * |
| 538 | * @cmdline: Command line to read, in the form: |
| 539 | * |
| 540 | * fred mary= jane=123 john="has spaces" |
| 541 | * @arg: Argument to read (may or may not exist) |
| 542 | * @posp: Returns position of argument (after any leading quote) if present |
| 543 | * Return: Length of argument value excluding quotes if found, -ENOENT if not |
| 544 | * found |
| 545 | */ |
| 546 | int cmdline_get_arg(const char *cmdline, const char *arg, int *posp); |
| 547 | |
| 548 | /** |
| 549 | * bootflow_cmdline_get_arg() - Read an argument from a cmdline |
| 550 | * |
| 551 | * @bootflow: Bootflow to read from |
| 552 | * @arg: Argument to read (may or may not exist) |
| 553 | * @valp: Returns a pointer to the argument (after any leading quote) if present |
| 554 | * Return: Length of argument value excluding quotes if found, -ENOENT if not |
| 555 | * found |
| 556 | */ |
| 557 | int bootflow_cmdline_get_arg(struct bootflow *bflow, const char *arg, |
| 558 | const char **val); |
| 559 | |
Simon Glass | cd91e99 | 2023-07-12 09:04:42 -0600 | [diff] [blame] | 560 | /** |
| 561 | * bootflow_cmdline_auto() - Automatically set a value for a known argument |
| 562 | * |
| 563 | * This handles a small number of known arguments, for Linux in particular. It |
| 564 | * adds suitable kernel parameters automatically, e.g. to enable the console. |
| 565 | * |
| 566 | * @bflow: Bootflow to update |
| 567 | * @arg: Name of argument to set (e.g. "earlycon" or "console") |
| 568 | * Return: 0 if OK -ve on error |
| 569 | */ |
| 570 | int bootflow_cmdline_auto(struct bootflow *bflow, const char *arg); |
| 571 | |
Simon Glass | a16d87d | 2022-04-24 23:31:05 -0600 | [diff] [blame] | 572 | #endif |