Simon Glass | 4b508b8 | 2022-04-24 23:31:08 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2021 Google LLC |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
| 5 | */ |
| 6 | |
| 7 | #define LOG_CATEGORY UCLASS_BOOTSTD |
| 8 | |
Simon Glass | 8db2a38 | 2024-11-15 16:19:14 -0700 | [diff] [blame] | 9 | #include <alist.h> |
Simon Glass | 4b508b8 | 2022-04-24 23:31:08 -0600 | [diff] [blame] | 10 | #include <blk.h> |
| 11 | #include <bootflow.h> |
| 12 | #include <bootmeth.h> |
| 13 | #include <bootstd.h> |
| 14 | #include <dm.h> |
Sam Protsenko | fa78d2a | 2025-01-11 21:42:12 -0600 | [diff] [blame] | 15 | #include <dm/device-internal.h> |
Simon Glass | 4b508b8 | 2022-04-24 23:31:08 -0600 | [diff] [blame] | 16 | #include <env_internal.h> |
| 17 | #include <fs.h> |
| 18 | #include <malloc.h> |
| 19 | #include <mapmem.h> |
| 20 | #include <dm/uclass-internal.h> |
| 21 | |
| 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
Simon Glass | f6d71a8 | 2022-07-30 15:52:19 -0600 | [diff] [blame] | 24 | int bootmeth_get_state_desc(struct udevice *dev, char *buf, int maxsize) |
| 25 | { |
| 26 | const struct bootmeth_ops *ops = bootmeth_get_ops(dev); |
| 27 | |
| 28 | if (!ops->get_state_desc) |
| 29 | return -ENOSYS; |
| 30 | |
| 31 | return ops->get_state_desc(dev, buf, maxsize); |
| 32 | } |
| 33 | |
Simon Glass | 4b508b8 | 2022-04-24 23:31:08 -0600 | [diff] [blame] | 34 | int bootmeth_check(struct udevice *dev, struct bootflow_iter *iter) |
| 35 | { |
| 36 | const struct bootmeth_ops *ops = bootmeth_get_ops(dev); |
| 37 | |
| 38 | if (!ops->check) |
| 39 | return 0; |
| 40 | |
| 41 | return ops->check(dev, iter); |
| 42 | } |
| 43 | |
| 44 | int bootmeth_read_bootflow(struct udevice *dev, struct bootflow *bflow) |
| 45 | { |
| 46 | const struct bootmeth_ops *ops = bootmeth_get_ops(dev); |
| 47 | |
| 48 | if (!ops->read_bootflow) |
| 49 | return -ENOSYS; |
| 50 | |
| 51 | return ops->read_bootflow(dev, bflow); |
| 52 | } |
| 53 | |
Simon Glass | a63bda6 | 2023-01-17 10:48:01 -0700 | [diff] [blame] | 54 | int bootmeth_set_bootflow(struct udevice *dev, struct bootflow *bflow, |
| 55 | char *buf, int size) |
| 56 | { |
| 57 | const struct bootmeth_ops *ops = bootmeth_get_ops(dev); |
| 58 | |
| 59 | if (!ops->set_bootflow) |
| 60 | return -ENOSYS; |
| 61 | |
| 62 | return ops->set_bootflow(dev, bflow, buf, size); |
| 63 | } |
| 64 | |
Simon Glass | 6d8f95b | 2023-08-10 19:33:18 -0600 | [diff] [blame] | 65 | #if CONFIG_IS_ENABLED(BOOTSTD_FULL) |
| 66 | int bootmeth_read_all(struct udevice *dev, struct bootflow *bflow) |
| 67 | { |
| 68 | const struct bootmeth_ops *ops = bootmeth_get_ops(dev); |
| 69 | |
| 70 | if (!ops->read_all) |
| 71 | return -ENOSYS; |
| 72 | |
| 73 | return ops->read_all(dev, bflow); |
| 74 | } |
| 75 | #endif /* BOOTSTD_FULL */ |
| 76 | |
Simon Glass | 4b508b8 | 2022-04-24 23:31:08 -0600 | [diff] [blame] | 77 | int bootmeth_boot(struct udevice *dev, struct bootflow *bflow) |
| 78 | { |
| 79 | const struct bootmeth_ops *ops = bootmeth_get_ops(dev); |
| 80 | |
| 81 | if (!ops->boot) |
| 82 | return -ENOSYS; |
| 83 | |
| 84 | return ops->boot(dev, bflow); |
| 85 | } |
| 86 | |
| 87 | int bootmeth_read_file(struct udevice *dev, struct bootflow *bflow, |
Simon Glass | f39b559 | 2024-11-15 16:19:17 -0700 | [diff] [blame] | 88 | const char *file_path, ulong addr, |
| 89 | enum bootflow_img_t type, ulong *sizep) |
Simon Glass | 4b508b8 | 2022-04-24 23:31:08 -0600 | [diff] [blame] | 90 | { |
| 91 | const struct bootmeth_ops *ops = bootmeth_get_ops(dev); |
| 92 | |
| 93 | if (!ops->read_file) |
| 94 | return -ENOSYS; |
| 95 | |
Simon Glass | f39b559 | 2024-11-15 16:19:17 -0700 | [diff] [blame] | 96 | return ops->read_file(dev, bflow, file_path, addr, type, sizep); |
Simon Glass | 4b508b8 | 2022-04-24 23:31:08 -0600 | [diff] [blame] | 97 | } |
| 98 | |
Simon Glass | 4f8633d | 2022-07-30 15:52:21 -0600 | [diff] [blame] | 99 | int bootmeth_get_bootflow(struct udevice *dev, struct bootflow *bflow) |
| 100 | { |
| 101 | const struct bootmeth_ops *ops = bootmeth_get_ops(dev); |
| 102 | |
| 103 | if (!ops->read_bootflow) |
| 104 | return -ENOSYS; |
Simon Glass | 00501fc | 2022-10-20 18:22:51 -0600 | [diff] [blame] | 105 | bootflow_init(bflow, NULL, dev); |
Simon Glass | 4f8633d | 2022-07-30 15:52:21 -0600 | [diff] [blame] | 106 | |
| 107 | return ops->read_bootflow(dev, bflow); |
| 108 | } |
| 109 | |
Simon Glass | cc15e14 | 2022-07-30 15:52:27 -0600 | [diff] [blame] | 110 | int bootmeth_setup_iter_order(struct bootflow_iter *iter, bool include_global) |
Simon Glass | 4b508b8 | 2022-04-24 23:31:08 -0600 | [diff] [blame] | 111 | { |
| 112 | struct bootstd_priv *std; |
| 113 | struct udevice **order; |
| 114 | int count; |
| 115 | int ret; |
| 116 | |
| 117 | ret = bootstd_get_priv(&std); |
| 118 | if (ret) |
| 119 | return ret; |
| 120 | |
| 121 | /* Create an array large enough */ |
| 122 | count = std->bootmeth_count ? std->bootmeth_count : |
| 123 | uclass_id_count(UCLASS_BOOTMETH); |
| 124 | if (!count) |
| 125 | return log_msg_ret("count", -ENOENT); |
| 126 | |
| 127 | order = calloc(count, sizeof(struct udevice *)); |
| 128 | if (!order) |
| 129 | return log_msg_ret("order", -ENOMEM); |
| 130 | |
| 131 | /* If we have an ordering, copy it */ |
| 132 | if (IS_ENABLED(CONFIG_BOOTSTD_FULL) && std->bootmeth_count) { |
Simon Glass | cc15e14 | 2022-07-30 15:52:27 -0600 | [diff] [blame] | 133 | int i; |
| 134 | |
| 135 | /* |
| 136 | * We don't support skipping global bootmeths. Instead, the user |
| 137 | * should omit them from the ordering |
| 138 | */ |
Sam Protsenko | b1c6d81 | 2025-01-11 21:42:11 -0600 | [diff] [blame] | 139 | if (!include_global) { |
| 140 | ret = log_msg_ret("glob", -EPERM); |
| 141 | goto err_order; |
| 142 | } |
Simon Glass | 4b508b8 | 2022-04-24 23:31:08 -0600 | [diff] [blame] | 143 | memcpy(order, std->bootmeth_order, |
Sam Protsenko | 0330279 | 2025-01-11 21:42:13 -0600 | [diff] [blame] | 144 | count * sizeof(struct udevice *)); |
Simon Glass | cc15e14 | 2022-07-30 15:52:27 -0600 | [diff] [blame] | 145 | |
| 146 | if (IS_ENABLED(CONFIG_BOOTMETH_GLOBAL)) { |
| 147 | for (i = 0; i < count; i++) { |
| 148 | struct udevice *dev = order[i]; |
| 149 | struct bootmeth_uc_plat *ucp; |
| 150 | bool is_global; |
| 151 | |
Sam Protsenko | fa78d2a | 2025-01-11 21:42:12 -0600 | [diff] [blame] | 152 | ret = device_probe(dev); |
| 153 | if (ret) { |
| 154 | ret = log_msg_ret("probe", ret); |
| 155 | goto err_order; |
| 156 | } |
| 157 | |
Simon Glass | cc15e14 | 2022-07-30 15:52:27 -0600 | [diff] [blame] | 158 | ucp = dev_get_uclass_plat(dev); |
| 159 | is_global = ucp->flags & |
| 160 | BOOTMETHF_GLOBAL; |
| 161 | if (is_global) { |
| 162 | iter->first_glob_method = i; |
| 163 | break; |
| 164 | } |
| 165 | } |
| 166 | } |
Simon Glass | 4b508b8 | 2022-04-24 23:31:08 -0600 | [diff] [blame] | 167 | } else { |
| 168 | struct udevice *dev; |
Simon Glass | cc15e14 | 2022-07-30 15:52:27 -0600 | [diff] [blame] | 169 | int i, upto, pass; |
Simon Glass | 4b508b8 | 2022-04-24 23:31:08 -0600 | [diff] [blame] | 170 | |
| 171 | /* |
Simon Glass | cc15e14 | 2022-07-30 15:52:27 -0600 | [diff] [blame] | 172 | * Do two passes, one to find the normal bootmeths and another |
| 173 | * to find the global ones, if required, The global ones go at |
| 174 | * the end. |
Simon Glass | 4b508b8 | 2022-04-24 23:31:08 -0600 | [diff] [blame] | 175 | */ |
Simon Glass | cc15e14 | 2022-07-30 15:52:27 -0600 | [diff] [blame] | 176 | for (pass = 0, upto = 0; pass < 1 + include_global; pass++) { |
| 177 | if (pass) |
| 178 | iter->first_glob_method = upto; |
| 179 | /* |
| 180 | * Get a list of bootmethods, in seq order (i.e. using |
| 181 | * aliases). There may be gaps so try to count up high |
| 182 | * enough to find them all. |
| 183 | */ |
| 184 | for (i = 0; upto < count && i < 20 + count * 2; i++) { |
| 185 | struct bootmeth_uc_plat *ucp; |
| 186 | bool is_global; |
| 187 | |
| 188 | ret = uclass_get_device_by_seq(UCLASS_BOOTMETH, |
| 189 | i, &dev); |
| 190 | if (ret) |
| 191 | continue; |
| 192 | ucp = dev_get_uclass_plat(dev); |
| 193 | is_global = |
| 194 | IS_ENABLED(CONFIG_BOOTMETH_GLOBAL) && |
| 195 | (ucp->flags & BOOTMETHF_GLOBAL); |
| 196 | if (pass ? is_global : !is_global) |
| 197 | order[upto++] = dev; |
| 198 | } |
Simon Glass | 4b508b8 | 2022-04-24 23:31:08 -0600 | [diff] [blame] | 199 | } |
| 200 | count = upto; |
| 201 | } |
Sam Protsenko | b1c6d81 | 2025-01-11 21:42:11 -0600 | [diff] [blame] | 202 | if (!count) { |
| 203 | ret = log_msg_ret("count2", -ENOENT); |
| 204 | goto err_order; |
| 205 | } |
Simon Glass | 4b508b8 | 2022-04-24 23:31:08 -0600 | [diff] [blame] | 206 | |
Simon Glass | cc15e14 | 2022-07-30 15:52:27 -0600 | [diff] [blame] | 207 | if (IS_ENABLED(CONFIG_BOOTMETH_GLOBAL) && include_global && |
| 208 | iter->first_glob_method != -1 && iter->first_glob_method != count) { |
| 209 | iter->cur_method = iter->first_glob_method; |
| 210 | iter->doing_global = true; |
| 211 | } |
Simon Glass | 4b508b8 | 2022-04-24 23:31:08 -0600 | [diff] [blame] | 212 | iter->method_order = order; |
| 213 | iter->num_methods = count; |
Simon Glass | 4b508b8 | 2022-04-24 23:31:08 -0600 | [diff] [blame] | 214 | |
| 215 | return 0; |
Sam Protsenko | b1c6d81 | 2025-01-11 21:42:11 -0600 | [diff] [blame] | 216 | |
| 217 | err_order: |
| 218 | free(order); |
| 219 | return ret; |
Simon Glass | 4b508b8 | 2022-04-24 23:31:08 -0600 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | int bootmeth_set_order(const char *order_str) |
| 223 | { |
| 224 | struct bootstd_priv *std; |
| 225 | struct udevice **order; |
| 226 | int count, ret, i, len; |
| 227 | const char *s, *p; |
| 228 | |
| 229 | ret = bootstd_get_priv(&std); |
| 230 | if (ret) |
| 231 | return ret; |
| 232 | |
| 233 | if (!order_str) { |
| 234 | free(std->bootmeth_order); |
| 235 | std->bootmeth_order = NULL; |
| 236 | std->bootmeth_count = 0; |
| 237 | return 0; |
| 238 | } |
| 239 | |
| 240 | /* Create an array large enough */ |
| 241 | count = uclass_id_count(UCLASS_BOOTMETH); |
| 242 | if (!count) |
| 243 | return log_msg_ret("count", -ENOENT); |
| 244 | |
| 245 | order = calloc(count + 1, sizeof(struct udevice *)); |
| 246 | if (!order) |
| 247 | return log_msg_ret("order", -ENOMEM); |
| 248 | |
| 249 | for (i = 0, s = order_str; *s && i < count; s = p + (*p == ' '), i++) { |
| 250 | struct udevice *dev; |
| 251 | |
| 252 | p = strchrnul(s, ' '); |
| 253 | len = p - s; |
| 254 | ret = uclass_find_device_by_namelen(UCLASS_BOOTMETH, s, len, |
| 255 | &dev); |
| 256 | if (ret) { |
| 257 | printf("Unknown bootmeth '%.*s'\n", len, s); |
| 258 | free(order); |
| 259 | return ret; |
| 260 | } |
| 261 | order[i] = dev; |
| 262 | } |
| 263 | order[i] = NULL; |
| 264 | free(std->bootmeth_order); |
| 265 | std->bootmeth_order = order; |
| 266 | std->bootmeth_count = i; |
| 267 | |
| 268 | return 0; |
| 269 | } |
| 270 | |
Martyn Welch | 93a0d16 | 2024-10-09 14:15:40 +0100 | [diff] [blame] | 271 | int bootmeth_set_property(const char *name, const char *property, const char *value) |
| 272 | { |
| 273 | int ret; |
| 274 | int len; |
| 275 | struct udevice *dev; |
| 276 | const struct bootmeth_ops *ops; |
| 277 | |
| 278 | len = strlen(name); |
| 279 | |
| 280 | ret = uclass_find_device_by_namelen(UCLASS_BOOTMETH, name, len, |
| 281 | &dev); |
| 282 | if (ret) { |
| 283 | printf("Unknown bootmeth '%s'\n", name); |
| 284 | return ret; |
| 285 | } |
| 286 | |
| 287 | ops = bootmeth_get_ops(dev); |
| 288 | if (!ops->set_property) { |
| 289 | printf("set_property not found\n"); |
| 290 | return -ENODEV; |
| 291 | } |
| 292 | |
| 293 | return ops->set_property(dev, property, value); |
| 294 | } |
| 295 | |
Simon Glass | f41c445 | 2023-07-26 21:01:21 -0600 | [diff] [blame] | 296 | int bootmeth_setup_fs(struct bootflow *bflow, struct blk_desc *desc) |
Simon Glass | 4b508b8 | 2022-04-24 23:31:08 -0600 | [diff] [blame] | 297 | { |
| 298 | int ret; |
| 299 | |
| 300 | if (desc) { |
| 301 | ret = fs_set_blk_dev_with_part(desc, bflow->part); |
| 302 | if (ret) |
| 303 | return log_msg_ret("set", ret); |
| 304 | } else if (IS_ENABLED(CONFIG_BOOTSTD_FULL) && bflow->fs_type) { |
| 305 | fs_set_type(bflow->fs_type); |
| 306 | } |
| 307 | |
| 308 | return 0; |
| 309 | } |
| 310 | |
| 311 | int bootmeth_try_file(struct bootflow *bflow, struct blk_desc *desc, |
| 312 | const char *prefix, const char *fname) |
| 313 | { |
| 314 | char path[200]; |
| 315 | loff_t size; |
| 316 | int ret, ret2; |
| 317 | |
| 318 | snprintf(path, sizeof(path), "%s%s", prefix ? prefix : "", fname); |
| 319 | log_debug("trying: %s\n", path); |
| 320 | |
| 321 | free(bflow->fname); |
| 322 | bflow->fname = strdup(path); |
| 323 | if (!bflow->fname) |
| 324 | return log_msg_ret("name", -ENOMEM); |
| 325 | |
| 326 | if (IS_ENABLED(CONFIG_BOOTSTD_FULL) && bflow->fs_type) |
| 327 | fs_set_type(bflow->fs_type); |
| 328 | |
| 329 | ret = fs_size(path, &size); |
| 330 | log_debug(" %s - err=%d\n", path, ret); |
| 331 | |
| 332 | /* Sadly FS closes the file after fs_size() so we must redo this */ |
Simon Glass | f41c445 | 2023-07-26 21:01:21 -0600 | [diff] [blame] | 333 | ret2 = bootmeth_setup_fs(bflow, desc); |
Simon Glass | 4b508b8 | 2022-04-24 23:31:08 -0600 | [diff] [blame] | 334 | if (ret2) |
| 335 | return log_msg_ret("fs", ret2); |
| 336 | |
| 337 | if (ret) |
| 338 | return log_msg_ret("size", ret); |
| 339 | |
| 340 | bflow->size = size; |
| 341 | bflow->state = BOOTFLOWST_FILE; |
| 342 | |
| 343 | return 0; |
| 344 | } |
| 345 | |
Simon Glass | 8db2a38 | 2024-11-15 16:19:14 -0700 | [diff] [blame] | 346 | int bootmeth_alloc_file(struct bootflow *bflow, uint size_limit, uint align, |
| 347 | enum bootflow_img_t type) |
Simon Glass | 612b9cc | 2023-01-06 08:52:34 -0600 | [diff] [blame] | 348 | { |
Simon Glass | 8db2a38 | 2024-11-15 16:19:14 -0700 | [diff] [blame] | 349 | struct blk_desc *desc = NULL; |
Simon Glass | 612b9cc | 2023-01-06 08:52:34 -0600 | [diff] [blame] | 350 | void *buf; |
| 351 | uint size; |
| 352 | int ret; |
| 353 | |
| 354 | size = bflow->size; |
| 355 | log_debug(" - script file size %x\n", size); |
| 356 | if (size > size_limit) |
| 357 | return log_msg_ret("chk", -E2BIG); |
| 358 | |
Simon Glass | e6c49fc | 2023-06-01 10:22:38 -0600 | [diff] [blame] | 359 | ret = fs_read_alloc(bflow->fname, bflow->size, align, &buf); |
Simon Glass | 612b9cc | 2023-01-06 08:52:34 -0600 | [diff] [blame] | 360 | if (ret) |
| 361 | return log_msg_ret("all", ret); |
| 362 | |
Simon Glass | 4b508b8 | 2022-04-24 23:31:08 -0600 | [diff] [blame] | 363 | bflow->state = BOOTFLOWST_READY; |
| 364 | bflow->buf = buf; |
| 365 | |
Simon Glass | 8db2a38 | 2024-11-15 16:19:14 -0700 | [diff] [blame] | 366 | if (bflow->blk) |
| 367 | desc = dev_get_uclass_plat(bflow->blk); |
| 368 | |
| 369 | if (!bootflow_img_add(bflow, bflow->fname, type, map_to_sysmem(buf), |
| 370 | size)) |
| 371 | return log_msg_ret("bai", -ENOMEM); |
| 372 | |
Simon Glass | 4b508b8 | 2022-04-24 23:31:08 -0600 | [diff] [blame] | 373 | return 0; |
| 374 | } |
| 375 | |
Simon Glass | 612b9cc | 2023-01-06 08:52:34 -0600 | [diff] [blame] | 376 | int bootmeth_alloc_other(struct bootflow *bflow, const char *fname, |
Simon Glass | 62632b2 | 2024-11-15 16:19:21 -0700 | [diff] [blame] | 377 | enum bootflow_img_t type, void **bufp, uint *sizep) |
Simon Glass | 612b9cc | 2023-01-06 08:52:34 -0600 | [diff] [blame] | 378 | { |
| 379 | struct blk_desc *desc = NULL; |
| 380 | char path[200]; |
| 381 | loff_t size; |
| 382 | void *buf; |
| 383 | int ret; |
| 384 | |
| 385 | snprintf(path, sizeof(path), "%s%s", bflow->subdir, fname); |
| 386 | log_debug("trying: %s\n", path); |
| 387 | |
| 388 | if (bflow->blk) |
| 389 | desc = dev_get_uclass_plat(bflow->blk); |
| 390 | |
Simon Glass | f41c445 | 2023-07-26 21:01:21 -0600 | [diff] [blame] | 391 | ret = bootmeth_setup_fs(bflow, desc); |
Simon Glass | 612b9cc | 2023-01-06 08:52:34 -0600 | [diff] [blame] | 392 | if (ret) |
| 393 | return log_msg_ret("fs", ret); |
| 394 | |
| 395 | ret = fs_size(path, &size); |
| 396 | log_debug(" %s - err=%d\n", path, ret); |
| 397 | |
Simon Glass | f41c445 | 2023-07-26 21:01:21 -0600 | [diff] [blame] | 398 | ret = bootmeth_setup_fs(bflow, desc); |
Simon Glass | 612b9cc | 2023-01-06 08:52:34 -0600 | [diff] [blame] | 399 | if (ret) |
| 400 | return log_msg_ret("fs", ret); |
| 401 | |
Simon Glass | e6c49fc | 2023-06-01 10:22:38 -0600 | [diff] [blame] | 402 | ret = fs_read_alloc(path, size, 0, &buf); |
Simon Glass | 612b9cc | 2023-01-06 08:52:34 -0600 | [diff] [blame] | 403 | if (ret) |
| 404 | return log_msg_ret("all", ret); |
| 405 | |
Simon Glass | 62632b2 | 2024-11-15 16:19:21 -0700 | [diff] [blame] | 406 | if (!bootflow_img_add(bflow, bflow->fname, type, map_to_sysmem(buf), |
| 407 | size)) |
| 408 | return log_msg_ret("boi", -ENOMEM); |
| 409 | |
Simon Glass | 612b9cc | 2023-01-06 08:52:34 -0600 | [diff] [blame] | 410 | *bufp = buf; |
| 411 | *sizep = size; |
| 412 | |
| 413 | return 0; |
| 414 | } |
| 415 | |
Simon Glass | 4b508b8 | 2022-04-24 23:31:08 -0600 | [diff] [blame] | 416 | int bootmeth_common_read_file(struct udevice *dev, struct bootflow *bflow, |
Simon Glass | f39b559 | 2024-11-15 16:19:17 -0700 | [diff] [blame] | 417 | const char *file_path, ulong addr, |
| 418 | enum bootflow_img_t type, ulong *sizep) |
Simon Glass | 4b508b8 | 2022-04-24 23:31:08 -0600 | [diff] [blame] | 419 | { |
| 420 | struct blk_desc *desc = NULL; |
| 421 | loff_t len_read; |
| 422 | loff_t size; |
| 423 | int ret; |
| 424 | |
| 425 | if (bflow->blk) |
| 426 | desc = dev_get_uclass_plat(bflow->blk); |
| 427 | |
Simon Glass | f41c445 | 2023-07-26 21:01:21 -0600 | [diff] [blame] | 428 | ret = bootmeth_setup_fs(bflow, desc); |
Simon Glass | 4b508b8 | 2022-04-24 23:31:08 -0600 | [diff] [blame] | 429 | if (ret) |
| 430 | return log_msg_ret("fs", ret); |
| 431 | |
| 432 | ret = fs_size(file_path, &size); |
| 433 | if (ret) |
| 434 | return log_msg_ret("size", ret); |
| 435 | if (size > *sizep) |
| 436 | return log_msg_ret("spc", -ENOSPC); |
| 437 | |
Simon Glass | f41c445 | 2023-07-26 21:01:21 -0600 | [diff] [blame] | 438 | ret = bootmeth_setup_fs(bflow, desc); |
Simon Glass | 4b508b8 | 2022-04-24 23:31:08 -0600 | [diff] [blame] | 439 | if (ret) |
| 440 | return log_msg_ret("fs", ret); |
| 441 | |
| 442 | ret = fs_read(file_path, addr, 0, 0, &len_read); |
| 443 | if (ret) |
| 444 | return ret; |
| 445 | *sizep = len_read; |
| 446 | |
Simon Glass | f39b559 | 2024-11-15 16:19:17 -0700 | [diff] [blame] | 447 | if (!bootflow_img_add(bflow, bflow->fname, type, addr, size)) |
| 448 | return log_msg_ret("bci", -ENOMEM); |
| 449 | |
Simon Glass | 4b508b8 | 2022-04-24 23:31:08 -0600 | [diff] [blame] | 450 | return 0; |
| 451 | } |
| 452 | |
| 453 | #ifdef CONFIG_BOOTSTD_FULL |
| 454 | /** |
| 455 | * on_bootmeths() - Update the bootmeth order |
| 456 | * |
Simon Glass | 7fbbbc8 | 2023-07-12 09:04:33 -0600 | [diff] [blame] | 457 | * This will check for a valid list of bootmeths and only apply it if valid. |
Simon Glass | 4b508b8 | 2022-04-24 23:31:08 -0600 | [diff] [blame] | 458 | */ |
| 459 | static int on_bootmeths(const char *name, const char *value, enum env_op op, |
| 460 | int flags) |
| 461 | { |
| 462 | int ret; |
| 463 | |
| 464 | switch (op) { |
| 465 | case env_op_create: |
| 466 | case env_op_overwrite: |
| 467 | ret = bootmeth_set_order(value); |
| 468 | if (ret) |
| 469 | return 1; |
| 470 | return 0; |
| 471 | case env_op_delete: |
| 472 | bootmeth_set_order(NULL); |
| 473 | fallthrough; |
| 474 | default: |
| 475 | return 0; |
| 476 | } |
| 477 | } |
| 478 | U_BOOT_ENV_CALLBACK(bootmeths, on_bootmeths); |
| 479 | #endif /* CONFIG_BOOTSTD_FULL */ |
| 480 | |
| 481 | UCLASS_DRIVER(bootmeth) = { |
| 482 | .id = UCLASS_BOOTMETH, |
| 483 | .name = "bootmeth", |
| 484 | .flags = DM_UC_FLAG_SEQ_ALIAS, |
| 485 | .per_device_plat_auto = sizeof(struct bootmeth_uc_plat), |
| 486 | }; |