2 * (C) Copyright 2000-2009
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
10 #include <fdt_support.h>
15 DECLARE_GLOBAL_DATA_PTR
;
17 static int do_bootm_standalone(int flag
, int argc
, char * const argv
[],
18 bootm_headers_t
*images
)
21 int (*appl
)(int, char *const[]);
23 /* Don't start if "autostart" is set to "no" */
24 s
= getenv("autostart");
25 if ((s
!= NULL
) && !strcmp(s
, "no")) {
26 setenv_hex("filesize", images
->os
.image_len
);
29 appl
= (int (*)(int, char * const []))images
->ep
;
34 /*******************************************************************/
35 /* OS booting routines */
36 /*******************************************************************/
38 #if defined(CONFIG_BOOTM_NETBSD) || defined(CONFIG_BOOTM_PLAN9)
39 static void copy_args(char *dest
, int argc
, char * const argv
[], char delim
)
43 for (i
= 0; i
< argc
; i
++) {
46 strcpy(dest
, argv
[i
]);
47 dest
+= strlen(argv
[i
]);
52 #ifdef CONFIG_BOOTM_NETBSD
53 static int do_bootm_netbsd(int flag
, int argc
, char * const argv
[],
54 bootm_headers_t
*images
)
56 void (*loader
)(bd_t
*, image_header_t
*, char *, char *);
57 image_header_t
*os_hdr
, *hdr
;
58 ulong kernel_data
, kernel_len
;
62 if (flag
!= BOOTM_STATE_OS_GO
)
65 #if defined(CONFIG_FIT)
66 if (!images
->legacy_hdr_valid
) {
67 fit_unsupported_reset("NetBSD");
71 hdr
= images
->legacy_hdr_os
;
74 * Booting a (NetBSD) kernel image
76 * This process is pretty similar to a standalone application:
77 * The (first part of an multi-) image must be a stage-2 loader,
78 * which in turn is responsible for loading & invoking the actual
79 * kernel. The only differences are the parameters being passed:
80 * besides the board info strucure, the loader expects a command
81 * line, the name of the console device, and (optionally) the
82 * address of the original image header.
85 if (image_check_type(&images
->legacy_hdr_os_copy
, IH_TYPE_MULTI
)) {
86 image_multi_getimg(hdr
, 1, &kernel_data
, &kernel_len
);
92 #if defined(CONFIG_8xx_CONS_SMC1)
94 #elif defined(CONFIG_8xx_CONS_SMC2)
96 #elif defined(CONFIG_8xx_CONS_SCC2)
98 #elif defined(CONFIG_8xx_CONS_SCC3)
106 for (i
= 0, len
= 0; i
< argc
; i
+= 1)
107 len
+= strlen(argv
[i
]) + 1;
108 cmdline
= malloc(len
);
109 copy_args(cmdline
, argc
, argv
, ' ');
111 cmdline
= getenv("bootargs");
116 loader
= (void (*)(bd_t
*, image_header_t
*, char *, char *))images
->ep
;
118 printf("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
121 bootstage_mark(BOOTSTAGE_ID_RUN_OS
);
124 * NetBSD Stage-2 Loader Parameters:
125 * arg[0]: pointer to board info data
126 * arg[1]: image load address
127 * arg[2]: char pointer to the console device to use
128 * arg[3]: char pointer to the boot arguments
130 (*loader
)(gd
->bd
, os_hdr
, consdev
, cmdline
);
134 #endif /* CONFIG_BOOTM_NETBSD*/
136 #ifdef CONFIG_LYNXKDI
137 static int do_bootm_lynxkdi(int flag
, int argc
, char * const argv
[],
138 bootm_headers_t
*images
)
140 image_header_t
*hdr
= &images
->legacy_hdr_os_copy
;
142 if (flag
!= BOOTM_STATE_OS_GO
)
145 #if defined(CONFIG_FIT)
146 if (!images
->legacy_hdr_valid
) {
147 fit_unsupported_reset("Lynx");
152 lynxkdi_boot((image_header_t
*)hdr
);
156 #endif /* CONFIG_LYNXKDI */
158 #ifdef CONFIG_BOOTM_RTEMS
159 static int do_bootm_rtems(int flag
, int argc
, char * const argv
[],
160 bootm_headers_t
*images
)
162 void (*entry_point
)(bd_t
*);
164 if (flag
!= BOOTM_STATE_OS_GO
)
167 #if defined(CONFIG_FIT)
168 if (!images
->legacy_hdr_valid
) {
169 fit_unsupported_reset("RTEMS");
174 entry_point
= (void (*)(bd_t
*))images
->ep
;
176 printf("## Transferring control to RTEMS (at address %08lx) ...\n",
179 bootstage_mark(BOOTSTAGE_ID_RUN_OS
);
183 * r3: ptr to board info data
185 (*entry_point
)(gd
->bd
);
189 #endif /* CONFIG_BOOTM_RTEMS */
191 #if defined(CONFIG_BOOTM_OSE)
192 static int do_bootm_ose(int flag
, int argc
, char * const argv
[],
193 bootm_headers_t
*images
)
195 void (*entry_point
)(void);
197 if (flag
!= BOOTM_STATE_OS_GO
)
200 #if defined(CONFIG_FIT)
201 if (!images
->legacy_hdr_valid
) {
202 fit_unsupported_reset("OSE");
207 entry_point
= (void (*)(void))images
->ep
;
209 printf("## Transferring control to OSE (at address %08lx) ...\n",
212 bootstage_mark(BOOTSTAGE_ID_RUN_OS
);
222 #endif /* CONFIG_BOOTM_OSE */
224 #if defined(CONFIG_BOOTM_PLAN9)
225 static int do_bootm_plan9(int flag
, int argc
, char * const argv
[],
226 bootm_headers_t
*images
)
228 void (*entry_point
)(void);
231 if (flag
!= BOOTM_STATE_OS_GO
)
234 #if defined(CONFIG_FIT)
235 if (!images
->legacy_hdr_valid
) {
236 fit_unsupported_reset("Plan 9");
241 /* See README.plan9 */
242 s
= getenv("confaddr");
244 char *confaddr
= (char *)simple_strtoul(s
, NULL
, 16);
247 copy_args(confaddr
, argc
, argv
, '\n');
249 s
= getenv("bootargs");
255 entry_point
= (void (*)(void))images
->ep
;
257 printf("## Transferring control to Plan 9 (at address %08lx) ...\n",
260 bootstage_mark(BOOTSTAGE_ID_RUN_OS
);
270 #endif /* CONFIG_BOOTM_PLAN9 */
272 #if defined(CONFIG_BOOTM_VXWORKS) && \
273 (defined(CONFIG_PPC) || defined(CONFIG_ARM))
275 void do_bootvx_fdt(bootm_headers_t
*images
)
277 #if defined(CONFIG_OF_LIBFDT)
280 ulong of_size
= images
->ft_len
;
281 char **of_flat_tree
= &images
->ft_addr
;
282 struct lmb
*lmb
= &images
->lmb
;
285 boot_fdt_add_mem_rsv_regions(lmb
, *of_flat_tree
);
287 ret
= boot_relocate_fdt(lmb
, of_flat_tree
, &of_size
);
291 ret
= fdt_add_subnode(*of_flat_tree
, 0, "chosen");
292 if ((ret
>= 0 || ret
== -FDT_ERR_EXISTS
)) {
293 bootline
= getenv("bootargs");
295 ret
= fdt_find_and_setprop(*of_flat_tree
,
296 "/chosen", "bootargs",
298 strlen(bootline
) + 1, 1);
300 printf("## ERROR: %s : %s\n", __func__
,
306 printf("## ERROR: %s : %s\n", __func__
,
313 boot_prep_vxworks(images
);
315 bootstage_mark(BOOTSTAGE_ID_RUN_OS
);
317 #if defined(CONFIG_OF_LIBFDT)
318 printf("## Starting vxWorks at 0x%08lx, device tree at 0x%08lx ...\n",
319 (ulong
)images
->ep
, (ulong
)*of_flat_tree
);
321 printf("## Starting vxWorks at 0x%08lx\n", (ulong
)images
->ep
);
324 boot_jump_vxworks(images
);
326 puts("## vxWorks terminated\n");
329 static int do_bootm_vxworks(int flag
, int argc
, char * const argv
[],
330 bootm_headers_t
*images
)
332 if (flag
!= BOOTM_STATE_OS_GO
)
335 #if defined(CONFIG_FIT)
336 if (!images
->legacy_hdr_valid
) {
337 fit_unsupported_reset("VxWorks");
342 do_bootvx_fdt(images
);
348 #if defined(CONFIG_CMD_ELF)
349 static int do_bootm_qnxelf(int flag
, int argc
, char * const argv
[],
350 bootm_headers_t
*images
)
356 if (flag
!= BOOTM_STATE_OS_GO
)
359 #if defined(CONFIG_FIT)
360 if (!images
->legacy_hdr_valid
) {
361 fit_unsupported_reset("QNX");
366 sprintf(str
, "%lx", images
->ep
); /* write entry-point into string */
367 local_args
[0] = argv
[0];
368 local_args
[1] = str
; /* and provide it via the arguments */
371 * QNX images require the data cache is disabled.
373 dcache
= dcache_status();
377 do_bootelf(NULL
, 0, 2, local_args
);
386 #ifdef CONFIG_INTEGRITY
387 static int do_bootm_integrity(int flag
, int argc
, char * const argv
[],
388 bootm_headers_t
*images
)
390 void (*entry_point
)(void);
392 if (flag
!= BOOTM_STATE_OS_GO
)
395 #if defined(CONFIG_FIT)
396 if (!images
->legacy_hdr_valid
) {
397 fit_unsupported_reset("INTEGRITY");
402 entry_point
= (void (*)(void))images
->ep
;
404 printf("## Transferring control to INTEGRITY (at address %08lx) ...\n",
407 bootstage_mark(BOOTSTAGE_ID_RUN_OS
);
410 * INTEGRITY Parameters:
419 #ifdef CONFIG_BOOTM_OPENRTOS
420 static int do_bootm_openrtos(int flag
, int argc
, char * const argv
[],
421 bootm_headers_t
*images
)
423 void (*entry_point
)(void);
425 if (flag
!= BOOTM_STATE_OS_GO
)
428 entry_point
= (void (*)(void))images
->ep
;
430 printf("## Transferring control to OpenRTOS (at address %08lx) ...\n",
433 bootstage_mark(BOOTSTAGE_ID_RUN_OS
);
436 * OpenRTOS Parameters:
445 static boot_os_fn
*boot_os
[] = {
446 [IH_OS_U_BOOT
] = do_bootm_standalone
,
447 #ifdef CONFIG_BOOTM_LINUX
448 [IH_OS_LINUX
] = do_bootm_linux
,
450 #ifdef CONFIG_BOOTM_NETBSD
451 [IH_OS_NETBSD
] = do_bootm_netbsd
,
453 #ifdef CONFIG_LYNXKDI
454 [IH_OS_LYNXOS
] = do_bootm_lynxkdi
,
456 #ifdef CONFIG_BOOTM_RTEMS
457 [IH_OS_RTEMS
] = do_bootm_rtems
,
459 #if defined(CONFIG_BOOTM_OSE)
460 [IH_OS_OSE
] = do_bootm_ose
,
462 #if defined(CONFIG_BOOTM_PLAN9)
463 [IH_OS_PLAN9
] = do_bootm_plan9
,
465 #if defined(CONFIG_BOOTM_VXWORKS) && \
466 (defined(CONFIG_PPC) || defined(CONFIG_ARM))
467 [IH_OS_VXWORKS
] = do_bootm_vxworks
,
469 #if defined(CONFIG_CMD_ELF)
470 [IH_OS_QNX
] = do_bootm_qnxelf
,
472 #ifdef CONFIG_INTEGRITY
473 [IH_OS_INTEGRITY
] = do_bootm_integrity
,
475 #ifdef CONFIG_BOOTM_OPENRTOS
476 [IH_OS_OPENRTOS
] = do_bootm_openrtos
,
480 /* Allow for arch specific config before we boot */
481 __weak
void arch_preboot_os(void)
483 /* please define platform specific arch_preboot_os() */
486 int boot_selected_os(int argc
, char * const argv
[], int state
,
487 bootm_headers_t
*images
, boot_os_fn
*boot_fn
)
490 boot_fn(state
, argc
, argv
, images
);
492 /* Stand-alone may return when 'autostart' is 'no' */
493 if (images
->os
.type
== IH_TYPE_STANDALONE
||
494 IS_ENABLED(CONFIG_SANDBOX
) ||
495 state
== BOOTM_STATE_OS_FAKE_GO
) /* We expect to return */
497 bootstage_error(BOOTSTAGE_ID_BOOT_OS_RETURNED
);
498 debug("\n## Control returned to monitor - resetting...\n");
500 return BOOTM_ERR_RESET
;
503 boot_os_fn
*bootm_os_get_boot_func(int os
)
505 #ifdef CONFIG_NEEDS_MANUAL_RELOC
506 static bool relocated
;
511 /* relocate boot function table */
512 for (i
= 0; i
< ARRAY_SIZE(boot_os
); i
++)
513 if (boot_os
[i
] != NULL
)
514 boot_os
[i
] += gd
->reloc_off
;