xref: /openbmc/u-boot/arch/arm/lib/spl.c (revision 83d290c56fab2d38cd1ab4c4cc7099559c1d5046)
1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
26507f133STom Rini /*
36507f133STom Rini  * (C) Copyright 2010-2012
46507f133STom Rini  * Texas Instruments, <www.ti.com>
56507f133STom Rini  *
66507f133STom Rini  * Aneesh V <aneesh@ti.com>
76507f133STom Rini  * Tom Rini <trini@ti.com>
86507f133STom Rini  */
9fb97b862SYork Sun 
106507f133STom Rini #include <common.h>
116507f133STom Rini #include <config.h>
126507f133STom Rini #include <spl.h>
136507f133STom Rini #include <image.h>
146507f133STom Rini #include <linux/compiler.h>
15c62db35dSSimon Glass #include <asm/mach-types.h>
166507f133STom Rini 
17b5d92ba1STom Rini #ifndef CONFIG_SPL_DM
186507f133STom Rini /* Pointer to as well as the global data structure for SPL */
196507f133STom Rini DECLARE_GLOBAL_DATA_PTR;
20480ca13eSSimon Glass 
21480ca13eSSimon Glass /*
22480ca13eSSimon Glass  * WARNING: This is going away very soon. Don't use it and don't submit
23480ca13eSSimon Glass  * pafches that rely on it. The global_data area is set up in crt0.S.
24480ca13eSSimon Glass  */
256507f133STom Rini gd_t gdata __attribute__ ((section(".data")));
26fc8fdc76SSimon Glass #endif
276507f133STom Rini 
286507f133STom Rini /*
29b8cb51d0SJeremy Hunt  * In the context of SPL, board_init_f() prepares the hardware for execution
30b8cb51d0SJeremy Hunt  * from system RAM (DRAM, DDR...). As system RAM may not be available yet,
31b8cb51d0SJeremy Hunt  * board_init_f() must use the current GD to store any data which must be
32b8cb51d0SJeremy Hunt  * passed on to later stages. These data include the relocation destination,
33b8cb51d0SJeremy Hunt  * the future stack, and the future GD location. BSS is cleared after this
34b8cb51d0SJeremy Hunt  * function (and therefore must be accessible).
35b8cb51d0SJeremy Hunt  *
36b8cb51d0SJeremy Hunt  * We provide this version by default but mark it as __weak to allow for
37b8cb51d0SJeremy Hunt  * platforms to do this in their own way if needed. Please see the top
38b8cb51d0SJeremy Hunt  * level U-Boot README "Board Initialization Flow" section for info on what
39b8cb51d0SJeremy Hunt  * to put in this function.
406507f133STom Rini  */
board_init_f(ulong dummy)416507f133STom Rini void __weak board_init_f(ulong dummy)
426507f133STom Rini {
436507f133STom Rini }
446507f133STom Rini 
456507f133STom Rini /*
466507f133STom Rini  * This function jumps to an image with argument. Normally an FDT or ATAGS
476507f133STom Rini  * image.
486507f133STom Rini  */
496507f133STom Rini #ifdef CONFIG_SPL_OS_BOOT
50fb97b862SYork Sun #ifdef CONFIG_ARM64
jump_to_image_linux(struct spl_image_info * spl_image)51fb97b862SYork Sun void __noreturn jump_to_image_linux(struct spl_image_info *spl_image)
52fb97b862SYork Sun {
53fb97b862SYork Sun 	debug("Entering kernel arg pointer: 0x%p\n", spl_image->arg);
54fb97b862SYork Sun 	cleanup_before_linux();
55fb97b862SYork Sun 	armv8_switch_to_el2((u64)spl_image->arg, 0, 0, 0,
56fb97b862SYork Sun 			    spl_image->entry_point, ES_TO_AARCH64);
57fb97b862SYork Sun }
58fb97b862SYork Sun #else
jump_to_image_linux(struct spl_image_info * spl_image)595bf5250eSVikas Manocha void __noreturn jump_to_image_linux(struct spl_image_info *spl_image)
606507f133STom Rini {
61ec101fdbSTom Rini 	unsigned long machid = 0xffffffff;
62ec101fdbSTom Rini #ifdef CONFIG_MACH_TYPE
63ec101fdbSTom Rini 	machid = CONFIG_MACH_TYPE;
64ec101fdbSTom Rini #endif
65ec101fdbSTom Rini 
665bf5250eSVikas Manocha 	debug("Entering kernel arg pointer: 0x%p\n", spl_image->arg);
676507f133STom Rini 	typedef void (*image_entry_arg_t)(int, int, void *)
686507f133STom Rini 		__attribute__ ((noreturn));
696507f133STom Rini 	image_entry_arg_t image_entry =
70ca12e65cSSimon Glass 		(image_entry_arg_t)(uintptr_t) spl_image->entry_point;
716507f133STom Rini 	cleanup_before_linux();
725bf5250eSVikas Manocha 	image_entry(0, machid, spl_image->arg);
736507f133STom Rini }
74fb97b862SYork Sun #endif	/* CONFIG_ARM64 */
756507f133STom Rini #endif
76