1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright 2021 Google LLC
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 * set_bootflow() - set the bootflow for a device
93 * This provides a bootflow file to the bootmeth, to see if it is valid.
94 * If it is, the bootflow is set up accordingly.
96 * @dev: Bootmethod device to use
97 * @bflow: On entry, provides bootdev.
98 * Returns updated bootflow if found
99 * @buf: Buffer containing the possible bootflow file
100 * @size: Size of file
101 * Return: 0 if OK, -ve on error
103 int (*set_bootflow)(struct udevice *dev, struct bootflow *bflow,
104 char *buf, int size);
107 * read_file() - read a file needed for a bootflow
109 * Read a file from the same place as the bootflow came from
111 * @dev: Bootmethod device to use
112 * @bflow: Bootflow providing info on where to read from
113 * @file_path: Path to file (may be absolute or relative)
114 * @addr: Address to load file
115 * @sizep: On entry provides the maximum permitted size; on exit
116 * returns the size of the file
117 * Return: 0 if OK, -ENOSPC if the file is too large for @sizep, other
118 * -ve value if something else goes wrong
120 int (*read_file)(struct udevice *dev, struct bootflow *bflow,
121 const char *file_path, ulong addr, ulong *sizep);
124 * boot() - boot a bootflow
126 * @dev: Bootmethod device to boot
127 * @bflow: Bootflow to boot
128 * Return: does not return on success, since it should boot the
129 * Operating Systemn. Returns -EFAULT if that fails, -ENOTSUPP if
130 * trying method resulted in finding out that is not actually
131 * supported for this boot and should not be tried again unless
132 * something changes, other -ve on other error
134 int (*boot)(struct udevice *dev, struct bootflow *bflow);
137 #define bootmeth_get_ops(dev) ((struct bootmeth_ops *)(dev)->driver->ops)
140 * bootmeth_get_state_desc() - get detailed state information
142 * Prodecues a textual description of the state of the bootmeth. This
143 * can include newline characters if it extends to multiple lines. It
144 * must be a nul-terminated string.
146 * This may involve reading state from the system, e.g. some data in
149 * @dev: Bootmethod device to check
150 * @buf: Buffer to place the info in (terminator must fit)
151 * @maxsize: Size of buffer
152 * Returns: 0 if OK, -ENOSPC is buffer is too small, other -ve error if
153 * something else went wrong
155 int bootmeth_get_state_desc(struct udevice *dev, char *buf, int maxsize);
158 * bootmeth_check() - check if a bootmeth supports this bootflow
160 * This is optional. If not provided, the bootdev is assumed to be
163 * The bootmeth can check the bootdev (e.g. to make sure it is a
164 * network device) or the partition information. The following fields
165 * in @iter are available:
167 * name, dev, state, part
168 * max_part may be set if part != 0 (i.e. there is a valid partition
169 * table). Otherwise max_part is 0
170 * method is available but is the same as @dev
171 * the partition has not yet been read, nor has the filesystem been
174 * It may update only the flags in @iter
176 * @dev: Bootmethod device to check against
177 * @iter: On entry, provides bootdev, hwpart, part
178 * Return: 0 if OK, -ENOTSUPP if this bootdev is not supported
180 int bootmeth_check(struct udevice *dev, struct bootflow_iter *iter);
183 * bootmeth_read_bootflow() - set up a bootflow for a device
185 * @dev: Bootmethod device to check
186 * @bflow: On entry, provides dev, hwpart, part and method.
187 * Returns updated bootflow if found
188 * Return: 0 if OK, -ve on error
190 int bootmeth_read_bootflow(struct udevice *dev, struct bootflow *bflow);
193 * bootmeth_set_bootflow() - set the bootflow for a device
195 * This provides a bootflow file to the bootmeth, to see if it is valid.
196 * If it is, the bootflow is set up accordingly.
198 * @dev: Bootmethod device to use
199 * @bflow: On entry, provides bootdev.
200 * Returns updated bootflow if found
201 * @buf: Buffer containing the possible bootflow file (must be allocated
202 * by caller to @size + 1 bytes)
203 * @size: Size of file
204 * Return: 0 if OK, -ve on error
206 int bootmeth_set_bootflow(struct udevice *dev, struct bootflow *bflow,
207 char *buf, int size);
210 * bootmeth_read_file() - read a file needed for a bootflow
212 * Read a file from the same place as the bootflow came from
214 * @dev: Bootmethod device to use
215 * @bflow: Bootflow providing info on where to read from
216 * @file_path: Path to file (may be absolute or relative)
217 * @addr: Address to load file
218 * @sizep: On entry provides the maximum permitted size; on exit
219 * returns the size of the file
220 * Return: 0 if OK, -ENOSPC if the file is too large for @sizep, other
221 * -ve value if something else goes wrong
223 int bootmeth_read_file(struct udevice *dev, struct bootflow *bflow,
224 const char *file_path, ulong addr, ulong *sizep);
227 * bootmeth_boot() - boot a bootflow
229 * @dev: Bootmethod device to boot
230 * @bflow: Bootflow to boot
231 * Return: does not return on success, since it should boot the
232 * Operating Systemn. Returns -EFAULT if that fails, other -ve on
235 int bootmeth_boot(struct udevice *dev, struct bootflow *bflow);
238 * bootmeth_setup_iter_order() - Set up the ordering of bootmeths to scan
240 * This sets up the ordering information in @iter, based on the selected
241 * ordering of the bootmethds in bootstd_priv->bootmeth_order. If there is no
242 * ordering there, then all bootmethods are added
244 * @iter: Iterator to update with the order
245 * @include_global: true to add the global bootmeths, in which case they appear
247 * Return: 0 if OK, -ENOENT if no bootdevs, -ENOMEM if out of memory, other -ve
250 int bootmeth_setup_iter_order(struct bootflow_iter *iter, bool include_global);
253 * bootmeth_set_order() - Set the bootmeth order
255 * This selects the ordering to use for bootmeths
257 * @order_str: String containing the ordering. This is a comma-separate list of
258 * bootmeth-device names, e.g. "syslinux,efi". If empty then a default ordering
259 * is used, based on the sequence number of devices (i.e. using aliases)
260 * Return: 0 if OK, -ENODEV if an unknown bootmeth is mentioned, -ENOMEM if
261 * out of memory, -ENOENT if there are no bootmeth devices
263 int bootmeth_set_order(const char *order_str);
266 * bootmeth_try_file() - See we can access a given file
268 * Check for a file with a given name. If found, the filename is allocated in
271 * Sets the state to BOOTFLOWST_FILE on success. It also calls
272 * fs_set_blk_dev_with_part() so that this does not need to be done by the
273 * caller before reading the file.
275 * @bflow: Information about file to try
276 * @desc: Block descriptor to read from (NULL for sandbox host)
277 * @prefix: Filename prefix to prepend to @fname (NULL for none)
278 * @fname: Filename to read
279 * Return: 0 if OK, -ENOMEM if not enough memory to allocate bflow->fname,
280 * other -ve value on other error
282 int bootmeth_try_file(struct bootflow *bflow, struct blk_desc *desc,
283 const char *prefix, const char *fname);
286 * bootmeth_alloc_file() - Allocate and read a bootflow file
288 * Allocates memory for a bootflow file and reads it in. Sets the state to
289 * BOOTFLOWST_READY on success
291 * Note that fs_set_blk_dev_with_part() must have been called previously.
293 * @bflow: Information about file to read
294 * @size_limit: Maximum file size to permit
295 * @align: Allocation alignment (1 for unaligned)
296 * Return: 0 if OK, -E2BIG if file is too large, -ENOMEM if out of memory,
297 * other -ve on other error
299 int bootmeth_alloc_file(struct bootflow *bflow, uint size_limit, uint align);
302 * bootmeth_alloc_other() - Allocate and read a file for a bootflow
304 * This reads an arbitrary file in the same directory as the bootflow,
305 * allocating memory for it. The buffer is one byte larger than the file length,
306 * so that it can be nul-terminated.
308 * @bflow: Information about file to read
309 * @fname: Filename to read from (within bootflow->subdir)
310 * @bufp: Returns a pointer to the allocated buffer
311 * @sizep: Returns the size of the buffer
312 * Return: 0 if OK, -ENOMEM if out of memory, other -ve on other error
314 int bootmeth_alloc_other(struct bootflow *bflow, const char *fname,
315 void **bufp, uint *sizep);
318 * bootmeth_common_read_file() - Common handler for reading a file
320 * Reads a named file from the same location as the bootflow file.
322 * @dev: bootmeth device to read from
323 * @bflow: Bootflow information
324 * @file_path: Path to file
325 * @addr: Address to load file to
326 * @sizep: On entry, the maximum file size to accept, on exit the actual file
329 int bootmeth_common_read_file(struct udevice *dev, struct bootflow *bflow,
330 const char *file_path, ulong addr, ulong *sizep);
333 * bootmeth_get_bootflow() - Get a bootflow from a global bootmeth
335 * Check the bootmeth for a bootflow which can be used. In this case the
336 * bootmeth handles all bootdev selection, etc.
338 * @dev: bootmeth device to read from
339 * @bflow: Bootflow information
340 * @return 0 on success, -ve if a bootflow could not be found or had an error
342 int bootmeth_get_bootflow(struct udevice *dev, struct bootflow *bflow);