1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright 2021 Google LLC
4 * Written by Simon Glass <sjg@chromium.org>
16 * struct bootmeth_uc_plat - information the uclass keeps about each bootmeth
18 * @desc: A long description of the bootmeth
20 struct bootmeth_uc_plat {
24 /** struct bootmeth_ops - Operations for boot methods */
27 * check_supported() - check if a bootmeth supports this bootflow
29 * This is optional. If not provided, the bootdev is assumed to be
32 * The bootmeth can check the bootdev (e.g. to make sure it is a
33 * network device) or the partition information. The following fields
34 * in @iter are available:
36 * name, dev, state, part
37 * max_part may be set if part != 0 (i.e. there is a valid partition
38 * table). Otherwise max_part is 0
39 * method is available but is the same as @dev
40 * the partition has not yet been read, nor has the filesystem been
43 * It may update only the flags in @iter
45 * @dev: Bootmethod device to check against
46 * @iter: On entry, provides bootdev, hwpart, part
47 * Return: 0 if OK, -ENOTSUPP if this bootdev is not supported
49 int (*check)(struct udevice *dev, struct bootflow_iter *iter);
52 * read_bootflow() - read a bootflow for a device
54 * @dev: Bootmethod device to use
55 * @bflow: On entry, provides dev, hwpart, part and method.
56 * Returns updated bootflow if found
57 * Return: 0 if OK, -ve on error
59 int (*read_bootflow)(struct udevice *dev, struct bootflow *bflow);
62 * read_file() - read a file needed for a bootflow
64 * Read a file from the same place as the bootflow came from
66 * @dev: Bootmethod device to use
67 * @bflow: Bootflow providing info on where to read from
68 * @file_path: Path to file (may be absolute or relative)
69 * @addr: Address to load file
70 * @sizep: On entry provides the maximum permitted size; on exit
71 * returns the size of the file
72 * Return: 0 if OK, -ENOSPC if the file is too large for @sizep, other
73 * -ve value if something else goes wrong
75 int (*read_file)(struct udevice *dev, struct bootflow *bflow,
76 const char *file_path, ulong addr, ulong *sizep);
79 * boot() - boot a bootflow
81 * @dev: Bootmethod device to boot
82 * @bflow: Bootflow to boot
83 * Return: does not return on success, since it should boot the
84 * Operating Systemn. Returns -EFAULT if that fails, -ENOTSUPP if
85 * trying method resulted in finding out that is not actually
86 * supported for this boot and should not be tried again unless
87 * something changes, other -ve on other error
89 int (*boot)(struct udevice *dev, struct bootflow *bflow);
92 #define bootmeth_get_ops(dev) ((struct bootmeth_ops *)(dev)->driver->ops)
95 * bootmeth_check() - check if a bootmeth supports this bootflow
97 * This is optional. If not provided, the bootdev is assumed to be
100 * The bootmeth can check the bootdev (e.g. to make sure it is a
101 * network device) or the partition information. The following fields
102 * in @iter are available:
104 * name, dev, state, part
105 * max_part may be set if part != 0 (i.e. there is a valid partition
106 * table). Otherwise max_part is 0
107 * method is available but is the same as @dev
108 * the partition has not yet been read, nor has the filesystem been
111 * It may update only the flags in @iter
113 * @dev: Bootmethod device to check against
114 * @iter: On entry, provides bootdev, hwpart, part
115 * Return: 0 if OK, -ENOTSUPP if this bootdev is not supported
117 int bootmeth_check(struct udevice *dev, struct bootflow_iter *iter);
120 * bootmeth_read_bootflow() - set up a bootflow for a device
122 * @dev: Bootmethod device to check
123 * @bflow: On entry, provides dev, hwpart, part and method.
124 * Returns updated bootflow if found
125 * Return: 0 if OK, -ve on error
127 int bootmeth_read_bootflow(struct udevice *dev, struct bootflow *bflow);
130 * bootmeth_read_file() - read a file needed for a bootflow
132 * Read a file from the same place as the bootflow came from
134 * @dev: Bootmethod device to use
135 * @bflow: Bootflow providing info on where to read from
136 * @file_path: Path to file (may be absolute or relative)
137 * @addr: Address to load file
138 * @sizep: On entry provides the maximum permitted size; on exit
139 * returns the size of the file
140 * Return: 0 if OK, -ENOSPC if the file is too large for @sizep, other
141 * -ve value if something else goes wrong
143 int bootmeth_read_file(struct udevice *dev, struct bootflow *bflow,
144 const char *file_path, ulong addr, ulong *sizep);
147 * bootmeth_boot() - boot a bootflow
149 * @dev: Bootmethod device to boot
150 * @bflow: Bootflow to boot
151 * Return: does not return on success, since it should boot the
152 * Operating Systemn. Returns -EFAULT if that fails, other -ve on
155 int bootmeth_boot(struct udevice *dev, struct bootflow *bflow);
158 * bootmeth_setup_iter_order() - Set up the ordering of bootmeths to scan
160 * This sets up the ordering information in @iter, based on the selected
161 * ordering of the bootmethds in bootstd_priv->bootmeth_order. If there is no
162 * ordering there, then all bootmethods are added
164 * @iter: Iterator to update with the order
165 * Return: 0 if OK, -ENOENT if no bootdevs, -ENOMEM if out of memory, other -ve
168 int bootmeth_setup_iter_order(struct bootflow_iter *iter);
171 * bootmeth_set_order() - Set the bootmeth order
173 * This selects the ordering to use for bootmeths
175 * @order_str: String containing the ordering. This is a comma-separate list of
176 * bootmeth-device names, e.g. "syslinux,efi". If empty then a default ordering
177 * is used, based on the sequence number of devices (i.e. using aliases)
178 * Return: 0 if OK, -ENODEV if an unknown bootmeth is mentioned, -ENOMEM if
179 * out of memory, -ENOENT if there are no bootmeth devices
181 int bootmeth_set_order(const char *order_str);
184 * bootmeth_try_file() - See we can access a given file
186 * Check for a file with a given name. If found, the filename is allocated in
189 * Sets the state to BOOTFLOWST_FILE on success. It also calls
190 * fs_set_blk_dev_with_part() so that this does not need to be done by the
191 * caller before reading the file.
193 * @bflow: Information about file to try
194 * @desc: Block descriptor to read from
195 * @prefix: Filename prefix to prepend to @fname (NULL for none)
196 * @fname: Filename to read
197 * Return: 0 if OK, -ENOMEM if not enough memory to allocate bflow->fname,
198 * other -ve value on other error
200 int bootmeth_try_file(struct bootflow *bflow, struct blk_desc *desc,
201 const char *prefix, const char *fname);
204 * bootmeth_alloc_file() - Allocate and read a bootflow file
206 * Allocates memory for a bootflow file and reads it in. Sets the state to
207 * BOOTFLOWST_READY on success
209 * Note that fs_set_blk_dev_with_part() must have been called previously.
211 * @bflow: Information about file to read
212 * @size_limit: Maximum file size to permit
213 * @align: Allocation alignment (1 for unaligned)
214 * Return: 0 if OK, -E2BIG if file is too large, -ENOMEM if out of memory,
215 * other -ve on other error
217 int bootmeth_alloc_file(struct bootflow *bflow, uint size_limit, uint align);
220 * bootmeth_common_read_file() - Common handler for reading a file
222 * Reads a named file from the same location as the bootflow file.
224 * @dev: bootmeth device to read from
225 * @bflow: Bootflow information
226 * @file_path: Path to file
227 * @addr: Address to load file to
228 * @sizep: On entry, the maximum file size to accept, on exit the actual file
231 int bootmeth_common_read_file(struct udevice *dev, struct bootflow *bflow,
232 const char *file_path, ulong addr, ulong *sizep);