blob: 2bc464756dd90371da22fcc371eb8a500e24c3ef [file] [log] [blame]
Simon Glass08ad13e2022-04-24 23:31:06 -06001/* 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 Glass199f5882024-11-15 16:19:12 -070012#include <alist.h>
Simon Glassd92bcc42023-01-06 08:52:42 -060013#include <dm/ofnode_decl.h>
Tom Rinidec7ea02024-05-20 13:35:03 -060014#include <linux/list.h>
15#include <linux/types.h>
Simon Glassd92bcc42023-01-06 08:52:42 -060016
Simon Glass08ad13e2022-04-24 23:31:06 -060017struct udevice;
18
19/**
20 * struct bootstd_priv - priv data for the bootstd driver
21 *
22 * This is attached to the (only) bootstd device, so there is only one instance
23 * of this struct. It provides overall information about bootdevs and bootflows.
24 *
Simon Glass60d3c512025-03-15 14:25:59 +000025 * TODO(sjg@chromium.org): Convert prefixes, bootdev_order and env_order to use
26 * alist
27 *
Simon Glass08ad13e2022-04-24 23:31:06 -060028 * @prefixes: NULL-terminated list of prefixes to use for bootflow filenames,
29 * e.g. "/", "/boot/"; NULL if none
30 * @bootdev_order: Order to use for bootdevs (or NULL if none), with each item
Simon Glassa1bcafb2023-01-17 10:47:15 -070031 * being a bootdev label, e.g. "mmc2", "mmc1" (NULL terminated)
32 * @env_order: Order as specified by the boot_targets env var (or NULL if none),
33 * with each item being a bootdev label, e.g. "mmc2", "mmc1" (NULL
34 * terminated)
Simon Glass08ad13e2022-04-24 23:31:06 -060035 * @cur_bootdev: Currently selected bootdev (for commands)
36 * @cur_bootflow: Currently selected bootflow (for commands)
Simon Glass199f5882024-11-15 16:19:12 -070037 * @bootflows: (struct bootflow) Global list of all bootflows across all
38 * bootdevs
Simon Glass08ad13e2022-04-24 23:31:06 -060039 * @bootmeth_count: Number of bootmeth devices in @bootmeth_order
40 * @bootmeth_order: List of bootmeth devices to use, in order, NULL-terminated
Simon Glass0a9f4262022-07-30 15:52:32 -060041 * @vbe_bootmeth: Currently selected VBE bootmeth, NULL if none
Simon Glassd92bcc42023-01-06 08:52:42 -060042 * @theme: Node containing the theme information
Simon Glass5acb97a2023-01-17 10:47:33 -070043 * @hunters_used: Bitmask of used hunters, indexed by their position in the
44 * linker list. The bit is set if the hunter has been used already
Simon Glass08ad13e2022-04-24 23:31:06 -060045 */
46struct bootstd_priv {
47 const char **prefixes;
48 const char **bootdev_order;
Simon Glassa1bcafb2023-01-17 10:47:15 -070049 const char **env_order;
Simon Glass08ad13e2022-04-24 23:31:06 -060050 struct udevice *cur_bootdev;
51 struct bootflow *cur_bootflow;
Simon Glass199f5882024-11-15 16:19:12 -070052 struct alist bootflows;
Simon Glass08ad13e2022-04-24 23:31:06 -060053 int bootmeth_count;
54 struct udevice **bootmeth_order;
Simon Glass0a9f4262022-07-30 15:52:32 -060055 struct udevice *vbe_bootmeth;
Simon Glassd92bcc42023-01-06 08:52:42 -060056 ofnode theme;
Simon Glass5acb97a2023-01-17 10:47:33 -070057 uint hunters_used;
Simon Glass08ad13e2022-04-24 23:31:06 -060058};
59
60/**
61 * bootstd_get_bootdev_order() - Get the boot-order list
62 *
63 * This reads the boot order, e.g. {"mmc0", "mmc2", NULL}
64 *
65 * The list is alloced by the bootstd driver so should not be freed. That is the
66 * reason for all the const stuff in the function signature
67 *
Simon Glassa1bcafb2023-01-17 10:47:15 -070068 * @dev: bootstd device
69 * @okp: returns true if OK, false if out of memory
70 * Return: list of string pointers, terminated by NULL; or NULL if no boot
71 * order. Note that this returns NULL in the case of an empty list
Simon Glass08ad13e2022-04-24 23:31:06 -060072 */
Simon Glassa1bcafb2023-01-17 10:47:15 -070073const char *const *const bootstd_get_bootdev_order(struct udevice *dev,
74 bool *okp);
Simon Glass08ad13e2022-04-24 23:31:06 -060075
76/**
77 * bootstd_get_prefixes() - Get the filename-prefixes list
78 *
Julien Delbergueb5fb4802023-07-13 11:53:09 +020079 * This reads the prefixes, e.g. {"/", "/boot", NULL}
Simon Glass08ad13e2022-04-24 23:31:06 -060080 *
81 * The list is alloced by the bootstd driver so should not be freed. That is the
82 * reason for all the const stuff in the function signature
83 *
84 * Return: list of string points, terminated by NULL; or NULL if no boot order
85 */
86const char *const *const bootstd_get_prefixes(struct udevice *dev);
87
88/**
89 * bootstd_get_priv() - Get the (single) state for the bootstd system
90 *
91 * The state holds a global list of all bootflows that have been found.
92 *
93 * Return: 0 if OK, -ve if the uclass does not exist
94 */
95int bootstd_get_priv(struct bootstd_priv **stdp);
96
97/**
Simon Glass2bcd9ea2024-11-15 16:19:10 -070098 * bootstd_try_priv() - Try to get the (single) state for the bootstd system
99 *
100 * The state holds a global list of all bootflows that have been found. This
101 * function returns the state if available, but takes care not to create the
102 * device (or uclass) if it doesn't exist.
103 *
104 * This function is safe to use in the 'unbind' path. It will always return NULL
105 * unless the bootstd device is probed and ready, e.g. bootstd_get_priv() has
106 * previously been called.
107 *
108 * TODO(sjg@chromium.org): Consider adding a bootstd pointer to global_data
109 *
110 * Return: pointer if the device exists, else NULL
111 */
112struct bootstd_priv *bootstd_try_priv(void);
113
114/**
Simon Glass08ad13e2022-04-24 23:31:06 -0600115 * bootstd_clear_glob() - Clear the global list of bootflows
116 *
117 * This removes all bootflows globally and across all bootdevs.
118 */
119void bootstd_clear_glob(void);
120
Simon Glass92368522023-11-18 14:05:19 -0700121/**
122 * bootstd_prog_boot() - Run standard boot in a fully programmatic mode
123 *
124 * Attempts to boot without making any use of U-Boot commands
125 *
126 * Returns: -ve error value (does not return except on failure to boot)
127 */
128int bootstd_prog_boot(void);
129
Simon Glassc01d83f2024-11-15 16:19:08 -0700130/**
Simon Glass1d8f8642024-11-15 16:19:11 -0700131 * bootstd_add_bootflow() - Add a bootflow to the global list
Simon Glassc01d83f2024-11-15 16:19:08 -0700132 *
133 * All fields in @bflow must be set up. Note that @bflow->dev is used to add the
134 * bootflow to that device.
135 *
136 * The bootflow is also added to the global list of all bootflows
137 *
138 * @dev: Bootdev device to add to
139 * @bflow: Bootflow to add. Note that fields within bflow must be allocated
140 * since this function takes over ownership of these. This functions makes
141 * a copy of @bflow itself (without allocating its fields again), so the
142 * caller must dispose of the memory used by the @bflow pointer itself
Simon Glass199f5882024-11-15 16:19:12 -0700143 * Return: element number in the list, if OK, -ENOMEM if out of memory
Simon Glassc01d83f2024-11-15 16:19:08 -0700144 */
145int bootstd_add_bootflow(struct bootflow *bflow);
146
Simon Glass346ab5d2024-11-15 16:19:09 -0700147/**
148 * bootstd_clear_bootflows_for_bootdev() - Clear bootflows from a bootdev
149 *
150 * Each bootdev maintains a list of discovered bootflows. This provides a
151 * way to clear it. These bootflows are removed from the global list too.
152 *
153 * @dev: bootdev device to update
154 */
155int bootstd_clear_bootflows_for_bootdev(struct udevice *dev);
156
Simon Glass08ad13e2022-04-24 23:31:06 -0600157#endif