blob: b92422171a8499cbc0c9e27bc4786e20f75da0a4 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassb6396402014-06-12 07:24:46 -06002/*
3 * (C) Copyright 2000-2009
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Simon Glassb6396402014-06-12 07:24:46 -06005 */
6
7#include <common.h>
8#include <bootm.h>
Simon Glass52f24232020-05-10 11:40:00 -06009#include <bootstage.h>
Simon Glass9edefc22019-11-14 12:57:37 -070010#include <cpu_func.h>
Cristian Ciocalteaecc7fda2019-12-24 18:05:39 +020011#include <efi_loader.h>
Simon Glassc7694dd2019-08-01 09:46:46 -060012#include <env.h>
Simon Glassb6396402014-06-12 07:24:46 -060013#include <fdt_support.h>
Simon Glass4d72caa2020-05-10 11:40:01 -060014#include <image.h>
15#include <lmb.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060016#include <log.h>
Simon Glass401d1c42020-10-30 21:38:53 -060017#include <asm/global_data.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090018#include <linux/libfdt.h>
Simon Glassb6396402014-06-12 07:24:46 -060019#include <malloc.h>
Cristian Ciocalteaecc7fda2019-12-24 18:05:39 +020020#include <mapmem.h>
Simon Glassb6396402014-06-12 07:24:46 -060021#include <vxworks.h>
Bryan O'Donoghuec225e7c2018-03-13 16:50:36 +000022#include <tee/optee.h>
Simon Glassb6396402014-06-12 07:24:46 -060023
24DECLARE_GLOBAL_DATA_PTR;
25
Simon Glass09140112020-05-10 11:40:03 -060026static int do_bootm_standalone(int flag, int argc, char *const argv[],
Simon Glassd9d7c202022-09-06 20:26:50 -060027 struct bootm_headers *images)
Simon Glassb6396402014-06-12 07:24:46 -060028{
Simon Glassb6396402014-06-12 07:24:46 -060029 int (*appl)(int, char *const[]);
30
Simon Glass78398652021-10-21 21:08:52 -060031 if (!env_get_autostart()) {
Simon Glass018f5302017-08-03 12:22:10 -060032 env_set_hex("filesize", images->os.image_len);
Simon Glassb6396402014-06-12 07:24:46 -060033 return 0;
34 }
35 appl = (int (*)(int, char * const []))images->ep;
36 appl(argc, argv);
37 return 0;
38}
39
40/*******************************************************************/
41/* OS booting routines */
42/*******************************************************************/
43
44#if defined(CONFIG_BOOTM_NETBSD) || defined(CONFIG_BOOTM_PLAN9)
Simon Glass09140112020-05-10 11:40:03 -060045static void copy_args(char *dest, int argc, char *const argv[], char delim)
Simon Glassb6396402014-06-12 07:24:46 -060046{
47 int i;
48
49 for (i = 0; i < argc; i++) {
50 if (i > 0)
51 *dest++ = delim;
52 strcpy(dest, argv[i]);
53 dest += strlen(argv[i]);
54 }
55}
56#endif
57
Simon Glass0ab5e022021-09-25 19:43:32 -060058static void __maybe_unused fit_unsupported_reset(const char *msg)
59{
60 if (CONFIG_IS_ENABLED(FIT_VERBOSE)) {
61 printf("! FIT images not supported for '%s' - must reset board to recover!\n",
62 msg);
63 }
64}
65
Simon Glassb6396402014-06-12 07:24:46 -060066#ifdef CONFIG_BOOTM_NETBSD
Simon Glass09140112020-05-10 11:40:03 -060067static int do_bootm_netbsd(int flag, int argc, char *const argv[],
Simon Glassd9d7c202022-09-06 20:26:50 -060068 struct bootm_headers *images)
Simon Glassb6396402014-06-12 07:24:46 -060069{
Simon Glassf3543e62022-09-06 20:26:52 -060070 void (*loader)(struct bd_info *bd, struct legacy_img_hdr *hdr,
71 char *console, char *cmdline);
72 struct legacy_img_hdr *os_hdr, *hdr;
Simon Glassb6396402014-06-12 07:24:46 -060073 ulong kernel_data, kernel_len;
Simon Glassb6396402014-06-12 07:24:46 -060074 char *cmdline;
75
76 if (flag != BOOTM_STATE_OS_GO)
77 return 0;
78
79#if defined(CONFIG_FIT)
80 if (!images->legacy_hdr_valid) {
81 fit_unsupported_reset("NetBSD");
82 return 1;
83 }
84#endif
85 hdr = images->legacy_hdr_os;
86
87 /*
88 * Booting a (NetBSD) kernel image
89 *
90 * This process is pretty similar to a standalone application:
91 * The (first part of an multi-) image must be a stage-2 loader,
92 * which in turn is responsible for loading & invoking the actual
93 * kernel. The only differences are the parameters being passed:
94 * besides the board info strucure, the loader expects a command
95 * line, the name of the console device, and (optionally) the
96 * address of the original image header.
97 */
98 os_hdr = NULL;
99 if (image_check_type(&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
100 image_multi_getimg(hdr, 1, &kernel_data, &kernel_len);
101 if (kernel_len)
102 os_hdr = hdr;
103 }
104
Simon Glassb6396402014-06-12 07:24:46 -0600105 if (argc > 0) {
106 ulong len;
107 int i;
108
109 for (i = 0, len = 0; i < argc; i += 1)
110 len += strlen(argv[i]) + 1;
111 cmdline = malloc(len);
112 copy_args(cmdline, argc, argv, ' ');
113 } else {
Simon Glass00caae62017-08-03 12:22:12 -0600114 cmdline = env_get("bootargs");
Simon Glassb6396402014-06-12 07:24:46 -0600115 if (cmdline == NULL)
116 cmdline = "";
117 }
118
Simon Glassf3543e62022-09-06 20:26:52 -0600119 loader = (void (*)(struct bd_info *, struct legacy_img_hdr *, char *, char *))images->ep;
Simon Glassb6396402014-06-12 07:24:46 -0600120
121 printf("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
122 (ulong)loader);
123
124 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
125
126 /*
127 * NetBSD Stage-2 Loader Parameters:
128 * arg[0]: pointer to board info data
129 * arg[1]: image load address
130 * arg[2]: char pointer to the console device to use
131 * arg[3]: char pointer to the boot arguments
132 */
Heiko Schocher5b8e76c2017-06-07 17:33:09 +0200133 (*loader)(gd->bd, os_hdr, "", cmdline);
Simon Glassb6396402014-06-12 07:24:46 -0600134
135 return 1;
136}
137#endif /* CONFIG_BOOTM_NETBSD*/
138
Simon Glassb6396402014-06-12 07:24:46 -0600139#ifdef CONFIG_BOOTM_RTEMS
Simon Glass09140112020-05-10 11:40:03 -0600140static int do_bootm_rtems(int flag, int argc, char *const argv[],
Simon Glassd9d7c202022-09-06 20:26:50 -0600141 struct bootm_headers *images)
Simon Glassb6396402014-06-12 07:24:46 -0600142{
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900143 void (*entry_point)(struct bd_info *);
Simon Glassb6396402014-06-12 07:24:46 -0600144
145 if (flag != BOOTM_STATE_OS_GO)
146 return 0;
147
148#if defined(CONFIG_FIT)
149 if (!images->legacy_hdr_valid) {
150 fit_unsupported_reset("RTEMS");
151 return 1;
152 }
153#endif
154
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900155 entry_point = (void (*)(struct bd_info *))images->ep;
Simon Glassb6396402014-06-12 07:24:46 -0600156
157 printf("## Transferring control to RTEMS (at address %08lx) ...\n",
158 (ulong)entry_point);
159
160 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
161
162 /*
163 * RTEMS Parameters:
164 * r3: ptr to board info data
165 */
166 (*entry_point)(gd->bd);
167
168 return 1;
169}
170#endif /* CONFIG_BOOTM_RTEMS */
171
172#if defined(CONFIG_BOOTM_OSE)
Simon Glass09140112020-05-10 11:40:03 -0600173static int do_bootm_ose(int flag, int argc, char *const argv[],
Simon Glassd9d7c202022-09-06 20:26:50 -0600174 struct bootm_headers *images)
Simon Glassb6396402014-06-12 07:24:46 -0600175{
176 void (*entry_point)(void);
177
178 if (flag != BOOTM_STATE_OS_GO)
179 return 0;
180
181#if defined(CONFIG_FIT)
182 if (!images->legacy_hdr_valid) {
183 fit_unsupported_reset("OSE");
184 return 1;
185 }
186#endif
187
188 entry_point = (void (*)(void))images->ep;
189
190 printf("## Transferring control to OSE (at address %08lx) ...\n",
191 (ulong)entry_point);
192
193 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
194
195 /*
196 * OSE Parameters:
197 * None
198 */
199 (*entry_point)();
200
201 return 1;
202}
203#endif /* CONFIG_BOOTM_OSE */
204
205#if defined(CONFIG_BOOTM_PLAN9)
Simon Glass09140112020-05-10 11:40:03 -0600206static int do_bootm_plan9(int flag, int argc, char *const argv[],
Simon Glassd9d7c202022-09-06 20:26:50 -0600207 struct bootm_headers *images)
Simon Glassb6396402014-06-12 07:24:46 -0600208{
209 void (*entry_point)(void);
210 char *s;
211
212 if (flag != BOOTM_STATE_OS_GO)
213 return 0;
214
215#if defined(CONFIG_FIT)
216 if (!images->legacy_hdr_valid) {
217 fit_unsupported_reset("Plan 9");
218 return 1;
219 }
220#endif
221
222 /* See README.plan9 */
Simon Glass00caae62017-08-03 12:22:12 -0600223 s = env_get("confaddr");
Simon Glassb6396402014-06-12 07:24:46 -0600224 if (s != NULL) {
Simon Glass7e5f4602021-07-24 09:03:29 -0600225 char *confaddr = (char *)hextoul(s, NULL);
Simon Glassb6396402014-06-12 07:24:46 -0600226
227 if (argc > 0) {
228 copy_args(confaddr, argc, argv, '\n');
229 } else {
Simon Glass00caae62017-08-03 12:22:12 -0600230 s = env_get("bootargs");
Simon Glassb6396402014-06-12 07:24:46 -0600231 if (s != NULL)
232 strcpy(confaddr, s);
233 }
234 }
235
236 entry_point = (void (*)(void))images->ep;
237
238 printf("## Transferring control to Plan 9 (at address %08lx) ...\n",
239 (ulong)entry_point);
240
241 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
242
243 /*
244 * Plan 9 Parameters:
245 * None
246 */
247 (*entry_point)();
248
249 return 1;
250}
251#endif /* CONFIG_BOOTM_PLAN9 */
252
253#if defined(CONFIG_BOOTM_VXWORKS) && \
254 (defined(CONFIG_PPC) || defined(CONFIG_ARM))
255
Simon Glassd9d7c202022-09-06 20:26:50 -0600256static void do_bootvx_fdt(struct bootm_headers *images)
Simon Glassb6396402014-06-12 07:24:46 -0600257{
258#if defined(CONFIG_OF_LIBFDT)
259 int ret;
260 char *bootline;
261 ulong of_size = images->ft_len;
262 char **of_flat_tree = &images->ft_addr;
263 struct lmb *lmb = &images->lmb;
264
265 if (*of_flat_tree) {
266 boot_fdt_add_mem_rsv_regions(lmb, *of_flat_tree);
267
268 ret = boot_relocate_fdt(lmb, of_flat_tree, &of_size);
269 if (ret)
270 return;
271
Hannes Schmelzera223e2b2017-08-25 14:27:37 +0200272 /* Update ethernet nodes */
273 fdt_fixup_ethernet(*of_flat_tree);
274
Simon Glassb6396402014-06-12 07:24:46 -0600275 ret = fdt_add_subnode(*of_flat_tree, 0, "chosen");
276 if ((ret >= 0 || ret == -FDT_ERR_EXISTS)) {
Simon Glass00caae62017-08-03 12:22:12 -0600277 bootline = env_get("bootargs");
Simon Glassb6396402014-06-12 07:24:46 -0600278 if (bootline) {
279 ret = fdt_find_and_setprop(*of_flat_tree,
280 "/chosen", "bootargs",
281 bootline,
282 strlen(bootline) + 1, 1);
283 if (ret < 0) {
284 printf("## ERROR: %s : %s\n", __func__,
285 fdt_strerror(ret));
286 return;
287 }
288 }
289 } else {
290 printf("## ERROR: %s : %s\n", __func__,
291 fdt_strerror(ret));
292 return;
293 }
294 }
295#endif
296
297 boot_prep_vxworks(images);
298
299 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
300
301#if defined(CONFIG_OF_LIBFDT)
302 printf("## Starting vxWorks at 0x%08lx, device tree at 0x%08lx ...\n",
303 (ulong)images->ep, (ulong)*of_flat_tree);
304#else
305 printf("## Starting vxWorks at 0x%08lx\n", (ulong)images->ep);
306#endif
Pali Rohárefc3f952022-09-05 11:31:21 +0200307 flush();
Simon Glassb6396402014-06-12 07:24:46 -0600308
309 boot_jump_vxworks(images);
310
311 puts("## vxWorks terminated\n");
312}
313
Simon Glass09140112020-05-10 11:40:03 -0600314static int do_bootm_vxworks_legacy(int flag, int argc, char *const argv[],
Simon Glassd9d7c202022-09-06 20:26:50 -0600315 struct bootm_headers *images)
Simon Glassb6396402014-06-12 07:24:46 -0600316{
317 if (flag != BOOTM_STATE_OS_GO)
318 return 0;
319
Simon Glassb6396402014-06-12 07:24:46 -0600320 do_bootvx_fdt(images);
321
322 return 1;
323}
Lihua Zhao1e26f642019-11-15 00:21:17 -0800324
Simon Glass09140112020-05-10 11:40:03 -0600325int do_bootm_vxworks(int flag, int argc, char *const argv[],
Simon Glassd9d7c202022-09-06 20:26:50 -0600326 struct bootm_headers *images)
Lihua Zhao1e26f642019-11-15 00:21:17 -0800327{
328 char *bootargs;
329 int pos;
330 unsigned long vxflags;
331 bool std_dtb = false;
332
333 /* get bootargs env */
334 bootargs = env_get("bootargs");
335
336 if (bootargs != NULL) {
337 for (pos = 0; pos < strlen(bootargs); pos++) {
338 /* find f=0xnumber flag */
339 if ((bootargs[pos] == '=') && (pos >= 1) &&
340 (bootargs[pos - 1] == 'f')) {
Simon Glass7e5f4602021-07-24 09:03:29 -0600341 vxflags = hextoul(&bootargs[pos + 1], NULL);
Lihua Zhao1e26f642019-11-15 00:21:17 -0800342 if (vxflags & VXWORKS_SYSFLG_STD_DTB)
343 std_dtb = true;
344 }
345 }
346 }
347
348 if (std_dtb) {
349 if (flag & BOOTM_STATE_OS_PREP)
350 printf(" Using standard DTB\n");
351 return do_bootm_linux(flag, argc, argv, images);
352 } else {
353 if (flag & BOOTM_STATE_OS_PREP)
354 printf(" !!! WARNING !!! Using legacy DTB\n");
355 return do_bootm_vxworks_legacy(flag, argc, argv, images);
356 }
357}
Simon Glassb6396402014-06-12 07:24:46 -0600358#endif
359
360#if defined(CONFIG_CMD_ELF)
Simon Glass09140112020-05-10 11:40:03 -0600361static int do_bootm_qnxelf(int flag, int argc, char *const argv[],
Simon Glassd9d7c202022-09-06 20:26:50 -0600362 struct bootm_headers *images)
Simon Glassb6396402014-06-12 07:24:46 -0600363{
364 char *local_args[2];
365 char str[16];
Emmanuel Vadot995eab82017-01-19 10:23:56 +0100366 int dcache;
Simon Glassb6396402014-06-12 07:24:46 -0600367
368 if (flag != BOOTM_STATE_OS_GO)
369 return 0;
370
371#if defined(CONFIG_FIT)
372 if (!images->legacy_hdr_valid) {
373 fit_unsupported_reset("QNX");
374 return 1;
375 }
376#endif
377
378 sprintf(str, "%lx", images->ep); /* write entry-point into string */
379 local_args[0] = argv[0];
380 local_args[1] = str; /* and provide it via the arguments */
Emmanuel Vadot995eab82017-01-19 10:23:56 +0100381
382 /*
383 * QNX images require the data cache is disabled.
384 */
385 dcache = dcache_status();
386 if (dcache)
387 dcache_disable();
388
Simon Glassb6396402014-06-12 07:24:46 -0600389 do_bootelf(NULL, 0, 2, local_args);
390
Emmanuel Vadot995eab82017-01-19 10:23:56 +0100391 if (dcache)
392 dcache_enable();
393
Simon Glassb6396402014-06-12 07:24:46 -0600394 return 1;
395}
396#endif
397
398#ifdef CONFIG_INTEGRITY
Simon Glass09140112020-05-10 11:40:03 -0600399static int do_bootm_integrity(int flag, int argc, char *const argv[],
Simon Glassd9d7c202022-09-06 20:26:50 -0600400 struct bootm_headers *images)
Simon Glassb6396402014-06-12 07:24:46 -0600401{
402 void (*entry_point)(void);
403
404 if (flag != BOOTM_STATE_OS_GO)
405 return 0;
406
407#if defined(CONFIG_FIT)
408 if (!images->legacy_hdr_valid) {
409 fit_unsupported_reset("INTEGRITY");
410 return 1;
411 }
412#endif
413
414 entry_point = (void (*)(void))images->ep;
415
416 printf("## Transferring control to INTEGRITY (at address %08lx) ...\n",
417 (ulong)entry_point);
418
419 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
420
421 /*
422 * INTEGRITY Parameters:
423 * None
424 */
425 (*entry_point)();
426
427 return 1;
428}
429#endif
430
Marek Vasut67ddd952014-12-16 14:07:21 +0100431#ifdef CONFIG_BOOTM_OPENRTOS
Simon Glass09140112020-05-10 11:40:03 -0600432static int do_bootm_openrtos(int flag, int argc, char *const argv[],
Simon Glassd9d7c202022-09-06 20:26:50 -0600433 struct bootm_headers *images)
Marek Vasut67ddd952014-12-16 14:07:21 +0100434{
435 void (*entry_point)(void);
436
437 if (flag != BOOTM_STATE_OS_GO)
438 return 0;
439
440 entry_point = (void (*)(void))images->ep;
441
442 printf("## Transferring control to OpenRTOS (at address %08lx) ...\n",
443 (ulong)entry_point);
444
445 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
446
447 /*
448 * OpenRTOS Parameters:
449 * None
450 */
451 (*entry_point)();
452
453 return 1;
454}
455#endif
456
Bryan O'Donoghuec225e7c2018-03-13 16:50:36 +0000457#ifdef CONFIG_BOOTM_OPTEE
Simon Glass09140112020-05-10 11:40:03 -0600458static int do_bootm_tee(int flag, int argc, char *const argv[],
Simon Glassd9d7c202022-09-06 20:26:50 -0600459 struct bootm_headers *images)
Bryan O'Donoghuec225e7c2018-03-13 16:50:36 +0000460{
461 int ret;
462
Bryan O'Donoghuec225e7c2018-03-13 16:50:36 +0000463 /* Validate OPTEE header */
464 ret = optee_verify_bootm_image(images->os.image_start,
465 images->os.load,
466 images->os.image_len);
467 if (ret)
468 return ret;
469
Bryan O'Donoghuec225e7c2018-03-13 16:50:36 +0000470 /* From here we can run the regular linux boot path */
471 return do_bootm_linux(flag, argc, argv, images);
472}
473#endif
474
Cristian Ciocalteaecc7fda2019-12-24 18:05:39 +0200475#ifdef CONFIG_BOOTM_EFI
Simon Glass09140112020-05-10 11:40:03 -0600476static int do_bootm_efi(int flag, int argc, char *const argv[],
Simon Glassd9d7c202022-09-06 20:26:50 -0600477 struct bootm_headers *images)
Cristian Ciocalteaecc7fda2019-12-24 18:05:39 +0200478{
Cristian Ciocalteaecc7fda2019-12-24 18:05:39 +0200479 efi_status_t efi_ret;
480 void *image_buf;
481
482 if (flag != BOOTM_STATE_OS_GO)
483 return 0;
484
Cristian Ciocalteaecc7fda2019-12-24 18:05:39 +0200485 /* Initialize EFI drivers */
486 efi_ret = efi_init_obj_list();
487 if (efi_ret != EFI_SUCCESS) {
488 printf("## Failed to initialize UEFI sub-system: r = %lu\n",
489 efi_ret & ~EFI_ERROR_MASK);
490 return 1;
491 }
492
493 /* Install device tree */
494 efi_ret = efi_install_fdt(images->ft_len
495 ? images->ft_addr : EFI_FDT_USE_INTERNAL);
496 if (efi_ret != EFI_SUCCESS) {
497 printf("## Failed to install device tree: r = %lu\n",
498 efi_ret & ~EFI_ERROR_MASK);
499 return 1;
500 }
501
502 /* Run EFI image */
503 printf("## Transferring control to EFI (at address %08lx) ...\n",
504 images->ep);
505 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
506
Heinrich Schuchardtbf758122020-07-18 10:54:26 +0200507 /* We expect to return */
508 images->os.type = IH_TYPE_STANDALONE;
509
Cristian Ciocalteaecc7fda2019-12-24 18:05:39 +0200510 image_buf = map_sysmem(images->ep, images->os.image_len);
511
512 efi_ret = efi_run_image(image_buf, images->os.image_len);
Heinrich Schuchardtbf758122020-07-18 10:54:26 +0200513 if (efi_ret != EFI_SUCCESS)
Cristian Ciocalteaecc7fda2019-12-24 18:05:39 +0200514 return 1;
Cristian Ciocalteaecc7fda2019-12-24 18:05:39 +0200515 return 0;
516}
517#endif
518
Simon Glassb6396402014-06-12 07:24:46 -0600519static boot_os_fn *boot_os[] = {
520 [IH_OS_U_BOOT] = do_bootm_standalone,
521#ifdef CONFIG_BOOTM_LINUX
522 [IH_OS_LINUX] = do_bootm_linux,
523#endif
524#ifdef CONFIG_BOOTM_NETBSD
525 [IH_OS_NETBSD] = do_bootm_netbsd,
526#endif
Simon Glassb6396402014-06-12 07:24:46 -0600527#ifdef CONFIG_BOOTM_RTEMS
528 [IH_OS_RTEMS] = do_bootm_rtems,
529#endif
530#if defined(CONFIG_BOOTM_OSE)
531 [IH_OS_OSE] = do_bootm_ose,
532#endif
533#if defined(CONFIG_BOOTM_PLAN9)
534 [IH_OS_PLAN9] = do_bootm_plan9,
535#endif
536#if defined(CONFIG_BOOTM_VXWORKS) && \
Bin Meng08337cd2018-12-21 07:13:41 -0800537 (defined(CONFIG_PPC) || defined(CONFIG_ARM) || defined(CONFIG_RISCV))
Simon Glassb6396402014-06-12 07:24:46 -0600538 [IH_OS_VXWORKS] = do_bootm_vxworks,
539#endif
540#if defined(CONFIG_CMD_ELF)
541 [IH_OS_QNX] = do_bootm_qnxelf,
542#endif
543#ifdef CONFIG_INTEGRITY
544 [IH_OS_INTEGRITY] = do_bootm_integrity,
545#endif
Marek Vasut67ddd952014-12-16 14:07:21 +0100546#ifdef CONFIG_BOOTM_OPENRTOS
547 [IH_OS_OPENRTOS] = do_bootm_openrtos,
548#endif
Bryan O'Donoghuec225e7c2018-03-13 16:50:36 +0000549#ifdef CONFIG_BOOTM_OPTEE
550 [IH_OS_TEE] = do_bootm_tee,
551#endif
Cristian Ciocalteaecc7fda2019-12-24 18:05:39 +0200552#ifdef CONFIG_BOOTM_EFI
553 [IH_OS_EFI] = do_bootm_efi,
554#endif
Simon Glassb6396402014-06-12 07:24:46 -0600555};
556
557/* Allow for arch specific config before we boot */
Jeroen Hofstee82c3a4c2014-07-10 23:06:25 +0200558__weak void arch_preboot_os(void)
Simon Glassb6396402014-06-12 07:24:46 -0600559{
560 /* please define platform specific arch_preboot_os() */
561}
Simon Glassb6396402014-06-12 07:24:46 -0600562
Marek Vasutfd3d1212018-10-04 21:16:31 +0200563/* Allow for board specific config before we boot */
564__weak void board_preboot_os(void)
565{
566 /* please define board specific board_preboot_os() */
567}
568
Simon Glass09140112020-05-10 11:40:03 -0600569int boot_selected_os(int argc, char *const argv[], int state,
Simon Glassd9d7c202022-09-06 20:26:50 -0600570 struct bootm_headers *images, boot_os_fn *boot_fn)
Simon Glassb6396402014-06-12 07:24:46 -0600571{
572 arch_preboot_os();
Marek Vasutfd3d1212018-10-04 21:16:31 +0200573 board_preboot_os();
Simon Glassb6396402014-06-12 07:24:46 -0600574 boot_fn(state, argc, argv, images);
575
576 /* Stand-alone may return when 'autostart' is 'no' */
577 if (images->os.type == IH_TYPE_STANDALONE ||
Simon Glassb9c771b2016-07-03 09:40:35 -0600578 IS_ENABLED(CONFIG_SANDBOX) ||
Simon Glassb6396402014-06-12 07:24:46 -0600579 state == BOOTM_STATE_OS_FAKE_GO) /* We expect to return */
580 return 0;
581 bootstage_error(BOOTSTAGE_ID_BOOT_OS_RETURNED);
Lukasz Majewski851bda82016-05-08 08:52:21 +0200582 debug("\n## Control returned to monitor - resetting...\n");
583
Simon Glassb6396402014-06-12 07:24:46 -0600584 return BOOTM_ERR_RESET;
585}
586
587boot_os_fn *bootm_os_get_boot_func(int os)
588{
Simon Glassb6396402014-06-12 07:24:46 -0600589 return boot_os[os];
590}