1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright 2021 Google LLC
4 * Written by Simon Glass <sjg@chromium.org>
16 * enum bootmeth_flags - Flags for bootmeths
18 * @BOOTMETHF_GLOBAL: bootmeth handles bootdev selection automatically
21 BOOTMETHF_GLOBAL = BIT(0),
25 * struct bootmeth_uc_plat - information the uclass keeps about each bootmeth
27 * @desc: A long description of the bootmeth
28 * @flags: Flags for this bootmeth (enum bootmeth_flags)
30 struct bootmeth_uc_plat {
35 /** struct bootmeth_ops - Operations for boot methods */
38 * get_state_desc() - get detailed state information
40 * Prodecues a textual description of the state of the bootmeth. This
41 * can include newline characters if it extends to multiple lines. It
42 * must be a nul-terminated string.
44 * This may involve reading state from the system, e.g. some data in
47 * @dev: Bootmethod device to check
48 * @buf: Buffer to place the info in (terminator must fit)
49 * @maxsize: Size of buffer
50 * Returns: 0 if OK, -ENOSPC is buffer is too small, other -ve error if
51 * something else went wrong
53 int (*get_state_desc)(struct udevice *dev, char *buf, int maxsize);
56 * check_supported() - check if a bootmeth supports this bootdev
58 * This is optional. If not provided, the bootdev is assumed to be
61 * The bootmeth can check the bootdev (e.g. to make sure it is a
62 * network device) or the partition information. The following fields
63 * in @iter are available:
65 * name, dev, state, part
66 * max_part may be set if part != 0 (i.e. there is a valid partition
67 * table). Otherwise max_part is 0
68 * method is available but is the same as @dev
69 * the partition has not yet been read, nor has the filesystem been
72 * It may update only the flags in @iter
74 * @dev: Bootmethod device to check against
75 * @iter: On entry, provides bootdev, hwpart, part
76 * Return: 0 if OK, -ENOTSUPP if this bootdev is not supported
78 int (*check)(struct udevice *dev, struct bootflow_iter *iter);
81 * read_bootflow() - read a bootflow for a device
83 * @dev: Bootmethod device to use
84 * @bflow: On entry, provides dev, hwpart, part and method.
85 * Returns updated bootflow if found
86 * Return: 0 if OK, -ve on error
88 int (*read_bootflow)(struct udevice *dev, struct bootflow *bflow);
91 * read_file() - read a file needed for a bootflow
93 * Read a file from the same place as the bootflow came from
95 * @dev: Bootmethod device to use
96 * @bflow: Bootflow providing info on where to read from
97 * @file_path: Path to file (may be absolute or relative)
98 * @addr: Address to load file
99 * @sizep: On entry provides the maximum permitted size; on exit
100 * returns the size of the file
101 * Return: 0 if OK, -ENOSPC if the file is too large for @sizep, other
102 * -ve value if something else goes wrong
104 int (*read_file)(struct udevice *dev, struct bootflow *bflow,
105 const char *file_path, ulong addr, ulong *sizep);
108 * boot() - boot a bootflow
110 * @dev: Bootmethod device to boot
111 * @bflow: Bootflow to boot
112 * Return: does not return on success, since it should boot the
113 * Operating Systemn. Returns -EFAULT if that fails, -ENOTSUPP if
114 * trying method resulted in finding out that is not actually
115 * supported for this boot and should not be tried again unless
116 * something changes, other -ve on other error
118 int (*boot)(struct udevice *dev, struct bootflow *bflow);
121 #define bootmeth_get_ops(dev) ((struct bootmeth_ops *)(dev)->driver->ops)
124 * bootmeth_get_state_desc() - get detailed state information
126 * Prodecues a textual description of the state of the bootmeth. This
127 * can include newline characters if it extends to multiple lines. It
128 * must be a nul-terminated string.
130 * This may involve reading state from the system, e.g. some data in
133 * @dev: Bootmethod device to check
134 * @buf: Buffer to place the info in (terminator must fit)
135 * @maxsize: Size of buffer
136 * Returns: 0 if OK, -ENOSPC is buffer is too small, other -ve error if
137 * something else went wrong
139 int bootmeth_get_state_desc(struct udevice *dev, char *buf, int maxsize);
142 * bootmeth_check() - check if a bootmeth supports this bootflow
144 * This is optional. If not provided, the bootdev is assumed to be
147 * The bootmeth can check the bootdev (e.g. to make sure it is a
148 * network device) or the partition information. The following fields
149 * in @iter are available:
151 * name, dev, state, part
152 * max_part may be set if part != 0 (i.e. there is a valid partition
153 * table). Otherwise max_part is 0
154 * method is available but is the same as @dev
155 * the partition has not yet been read, nor has the filesystem been
158 * It may update only the flags in @iter
160 * @dev: Bootmethod device to check against
161 * @iter: On entry, provides bootdev, hwpart, part
162 * Return: 0 if OK, -ENOTSUPP if this bootdev is not supported
164 int bootmeth_check(struct udevice *dev, struct bootflow_iter *iter);
167 * bootmeth_read_bootflow() - set up a bootflow for a device
169 * @dev: Bootmethod device to check
170 * @bflow: On entry, provides dev, hwpart, part and method.
171 * Returns updated bootflow if found
172 * Return: 0 if OK, -ve on error
174 int bootmeth_read_bootflow(struct udevice *dev, struct bootflow *bflow);
177 * bootmeth_read_file() - read a file needed for a bootflow
179 * Read a file from the same place as the bootflow came from
181 * @dev: Bootmethod device to use
182 * @bflow: Bootflow providing info on where to read from
183 * @file_path: Path to file (may be absolute or relative)
184 * @addr: Address to load file
185 * @sizep: On entry provides the maximum permitted size; on exit
186 * returns the size of the file
187 * Return: 0 if OK, -ENOSPC if the file is too large for @sizep, other
188 * -ve value if something else goes wrong
190 int bootmeth_read_file(struct udevice *dev, struct bootflow *bflow,
191 const char *file_path, ulong addr, ulong *sizep);
194 * bootmeth_boot() - boot a bootflow
196 * @dev: Bootmethod device to boot
197 * @bflow: Bootflow to boot
198 * Return: does not return on success, since it should boot the
199 * Operating Systemn. Returns -EFAULT if that fails, other -ve on
202 int bootmeth_boot(struct udevice *dev, struct bootflow *bflow);
205 * bootmeth_setup_iter_order() - Set up the ordering of bootmeths to scan
207 * This sets up the ordering information in @iter, based on the selected
208 * ordering of the bootmethds in bootstd_priv->bootmeth_order. If there is no
209 * ordering there, then all bootmethods are added
211 * @iter: Iterator to update with the order
212 * @include_global: true to add the global bootmeths, in which case they appear
214 * Return: 0 if OK, -ENOENT if no bootdevs, -ENOMEM if out of memory, other -ve
217 int bootmeth_setup_iter_order(struct bootflow_iter *iter, bool include_global);
220 * bootmeth_set_order() - Set the bootmeth order
222 * This selects the ordering to use for bootmeths
224 * @order_str: String containing the ordering. This is a comma-separate list of
225 * bootmeth-device names, e.g. "syslinux,efi". If empty then a default ordering
226 * is used, based on the sequence number of devices (i.e. using aliases)
227 * Return: 0 if OK, -ENODEV if an unknown bootmeth is mentioned, -ENOMEM if
228 * out of memory, -ENOENT if there are no bootmeth devices
230 int bootmeth_set_order(const char *order_str);
233 * bootmeth_try_file() - See we can access a given file
235 * Check for a file with a given name. If found, the filename is allocated in
238 * Sets the state to BOOTFLOWST_FILE on success. It also calls
239 * fs_set_blk_dev_with_part() so that this does not need to be done by the
240 * caller before reading the file.
242 * @bflow: Information about file to try
243 * @desc: Block descriptor to read from
244 * @prefix: Filename prefix to prepend to @fname (NULL for none)
245 * @fname: Filename to read
246 * Return: 0 if OK, -ENOMEM if not enough memory to allocate bflow->fname,
247 * other -ve value on other error
249 int bootmeth_try_file(struct bootflow *bflow, struct blk_desc *desc,
250 const char *prefix, const char *fname);
253 * bootmeth_alloc_file() - Allocate and read a bootflow file
255 * Allocates memory for a bootflow file and reads it in. Sets the state to
256 * BOOTFLOWST_READY on success
258 * Note that fs_set_blk_dev_with_part() must have been called previously.
260 * @bflow: Information about file to read
261 * @size_limit: Maximum file size to permit
262 * @align: Allocation alignment (1 for unaligned)
263 * Return: 0 if OK, -E2BIG if file is too large, -ENOMEM if out of memory,
264 * other -ve on other error
266 int bootmeth_alloc_file(struct bootflow *bflow, uint size_limit, uint align);
269 * bootmeth_common_read_file() - Common handler for reading a file
271 * Reads a named file from the same location as the bootflow file.
273 * @dev: bootmeth device to read from
274 * @bflow: Bootflow information
275 * @file_path: Path to file
276 * @addr: Address to load file to
277 * @sizep: On entry, the maximum file size to accept, on exit the actual file
280 int bootmeth_common_read_file(struct udevice *dev, struct bootflow *bflow,
281 const char *file_path, ulong addr, ulong *sizep);
284 * bootmeth_get_bootflow() - Get a bootflow from a global bootmeth
286 * Check the bootmeth for a bootflow which can be used. In this case the
287 * bootmeth handles all bootdev selection, etc.
289 * @dev: bootmeth device to read from
290 * @bflow: Bootflow information
291 * @return 0 on success, -ve if a bootflow could not be found or had an error
293 int bootmeth_get_bootflow(struct udevice *dev, struct bootflow *bflow);