Simon Glass | 08ad13e | 2022-04-24 23:31:06 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* |
| 3 | * Standard U-Boot boot framework |
| 4 | * |
| 5 | * Copyright 2021 Google LLC |
| 6 | * Written by Simon Glass <sjg@chromium.org> |
| 7 | */ |
| 8 | |
| 9 | #ifndef __bootstd_h |
| 10 | #define __bootstd_h |
| 11 | |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 12 | #include <dm/ofnode_decl.h> |
Tom Rini | d22d069 | 2024-04-27 08:10:58 -0600 | [diff] [blame^] | 13 | #include <linux/list.h> |
| 14 | #include <linux/types.h> |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 15 | |
Simon Glass | 08ad13e | 2022-04-24 23:31:06 -0600 | [diff] [blame] | 16 | struct udevice; |
| 17 | |
| 18 | /** |
| 19 | * struct bootstd_priv - priv data for the bootstd driver |
| 20 | * |
| 21 | * This is attached to the (only) bootstd device, so there is only one instance |
| 22 | * of this struct. It provides overall information about bootdevs and bootflows. |
| 23 | * |
| 24 | * @prefixes: NULL-terminated list of prefixes to use for bootflow filenames, |
| 25 | * e.g. "/", "/boot/"; NULL if none |
| 26 | * @bootdev_order: Order to use for bootdevs (or NULL if none), with each item |
Simon Glass | a1bcafb | 2023-01-17 10:47:15 -0700 | [diff] [blame] | 27 | * being a bootdev label, e.g. "mmc2", "mmc1" (NULL terminated) |
| 28 | * @env_order: Order as specified by the boot_targets env var (or NULL if none), |
| 29 | * with each item being a bootdev label, e.g. "mmc2", "mmc1" (NULL |
| 30 | * terminated) |
Simon Glass | 08ad13e | 2022-04-24 23:31:06 -0600 | [diff] [blame] | 31 | * @cur_bootdev: Currently selected bootdev (for commands) |
| 32 | * @cur_bootflow: Currently selected bootflow (for commands) |
| 33 | * @glob_head: Head for the global list of all bootflows across all bootdevs |
| 34 | * @bootmeth_count: Number of bootmeth devices in @bootmeth_order |
| 35 | * @bootmeth_order: List of bootmeth devices to use, in order, NULL-terminated |
Simon Glass | 0a9f426 | 2022-07-30 15:52:32 -0600 | [diff] [blame] | 36 | * @vbe_bootmeth: Currently selected VBE bootmeth, NULL if none |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 37 | * @theme: Node containing the theme information |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 38 | * @hunters_used: Bitmask of used hunters, indexed by their position in the |
| 39 | * linker list. The bit is set if the hunter has been used already |
Simon Glass | 08ad13e | 2022-04-24 23:31:06 -0600 | [diff] [blame] | 40 | */ |
| 41 | struct bootstd_priv { |
| 42 | const char **prefixes; |
| 43 | const char **bootdev_order; |
Simon Glass | a1bcafb | 2023-01-17 10:47:15 -0700 | [diff] [blame] | 44 | const char **env_order; |
Simon Glass | 08ad13e | 2022-04-24 23:31:06 -0600 | [diff] [blame] | 45 | struct udevice *cur_bootdev; |
| 46 | struct bootflow *cur_bootflow; |
| 47 | struct list_head glob_head; |
| 48 | int bootmeth_count; |
| 49 | struct udevice **bootmeth_order; |
Simon Glass | 0a9f426 | 2022-07-30 15:52:32 -0600 | [diff] [blame] | 50 | struct udevice *vbe_bootmeth; |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 51 | ofnode theme; |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 52 | uint hunters_used; |
Simon Glass | 08ad13e | 2022-04-24 23:31:06 -0600 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | /** |
| 56 | * bootstd_get_bootdev_order() - Get the boot-order list |
| 57 | * |
| 58 | * This reads the boot order, e.g. {"mmc0", "mmc2", NULL} |
| 59 | * |
| 60 | * The list is alloced by the bootstd driver so should not be freed. That is the |
| 61 | * reason for all the const stuff in the function signature |
| 62 | * |
Simon Glass | a1bcafb | 2023-01-17 10:47:15 -0700 | [diff] [blame] | 63 | * @dev: bootstd device |
| 64 | * @okp: returns true if OK, false if out of memory |
| 65 | * Return: list of string pointers, terminated by NULL; or NULL if no boot |
| 66 | * order. Note that this returns NULL in the case of an empty list |
Simon Glass | 08ad13e | 2022-04-24 23:31:06 -0600 | [diff] [blame] | 67 | */ |
Simon Glass | a1bcafb | 2023-01-17 10:47:15 -0700 | [diff] [blame] | 68 | const char *const *const bootstd_get_bootdev_order(struct udevice *dev, |
| 69 | bool *okp); |
Simon Glass | 08ad13e | 2022-04-24 23:31:06 -0600 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * bootstd_get_prefixes() - Get the filename-prefixes list |
| 73 | * |
Julien Delbergue | b5fb480 | 2023-07-13 11:53:09 +0200 | [diff] [blame] | 74 | * This reads the prefixes, e.g. {"/", "/boot", NULL} |
Simon Glass | 08ad13e | 2022-04-24 23:31:06 -0600 | [diff] [blame] | 75 | * |
| 76 | * The list is alloced by the bootstd driver so should not be freed. That is the |
| 77 | * reason for all the const stuff in the function signature |
| 78 | * |
| 79 | * Return: list of string points, terminated by NULL; or NULL if no boot order |
| 80 | */ |
| 81 | const char *const *const bootstd_get_prefixes(struct udevice *dev); |
| 82 | |
| 83 | /** |
| 84 | * bootstd_get_priv() - Get the (single) state for the bootstd system |
| 85 | * |
| 86 | * The state holds a global list of all bootflows that have been found. |
| 87 | * |
| 88 | * Return: 0 if OK, -ve if the uclass does not exist |
| 89 | */ |
| 90 | int bootstd_get_priv(struct bootstd_priv **stdp); |
| 91 | |
| 92 | /** |
| 93 | * bootstd_clear_glob() - Clear the global list of bootflows |
| 94 | * |
| 95 | * This removes all bootflows globally and across all bootdevs. |
| 96 | */ |
| 97 | void bootstd_clear_glob(void); |
| 98 | |
Simon Glass | 9236852 | 2023-11-18 14:05:19 -0700 | [diff] [blame] | 99 | /** |
| 100 | * bootstd_prog_boot() - Run standard boot in a fully programmatic mode |
| 101 | * |
| 102 | * Attempts to boot without making any use of U-Boot commands |
| 103 | * |
| 104 | * Returns: -ve error value (does not return except on failure to boot) |
| 105 | */ |
| 106 | int bootstd_prog_boot(void); |
| 107 | |
Simon Glass | 08ad13e | 2022-04-24 23:31:06 -0600 | [diff] [blame] | 108 | #endif |