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