xref: /openbmc/u-boot/arch/arm/mach-aspeed/ast2600/spl.c (revision 07b728f9ef87a3dfb27857f4cf1c782bb8f20e28)
1 /*
2  * (C) Copyright ASPEED Technology Inc.
3  *
4  * SPDX-License-Identifier:	GPL-2.0+
5  */
6 #include <common.h>
7 #include <debug_uart.h>
8 #include <spl.h>
9 
10 #include <asm/io.h>
11 #include <asm/spl.h>
12 #include <asm/arch/aspeed_verify.h>
13 
14 DECLARE_GLOBAL_DATA_PTR;
15 
16 #define AST_BOOTMODE_SPI	0
17 #define AST_BOOTMODE_EMMC	1
18 #define AST_BOOTMODE_UART	2
19 
20 u32 aspeed_bootmode(void);
21 
22 void board_init_f(ulong dummy)
23 {
24 #ifndef CONFIG_SPL_TINY
25 	spl_early_init();
26 	timer_init();
27 	preloader_console_init();
28 	dram_init();
29 #endif
30 }
31 
32 u32 spl_boot_device(void)
33 {
34 	switch(aspeed_bootmode()) {
35 		case AST_BOOTMODE_EMMC:
36 			return BOOT_DEVICE_MMC1;
37 		case AST_BOOTMODE_SPI:
38 			return BOOT_DEVICE_RAM;
39 		case AST_BOOTMODE_UART:
40 			return BOOT_DEVICE_UART;
41 		default:
42 			break;
43 	}
44 	return BOOT_DEVICE_NONE;
45 }
46 
47 struct image_header *spl_get_load_buffer(ssize_t offset, size_t size)
48 {
49 #ifdef CONFIG_SECURE_BOOT
50 	void *dst = (void*)CONFIG_SYS_UBOOT_START;
51 	void *src = (void*)CONFIG_SYS_TEXT_BASE;
52 	u32 count = CONFIG_SYS_MONITOR_LEN;
53 	memmove(dst, src, count);
54 #endif
55     return (struct image_header *)(CONFIG_SYS_TEXT_BASE);
56 }
57 
58 #ifdef CONFIG_SECURE_BOOT
59 void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
60 {
61 	typedef void __noreturn (*image_entry_noargs_t)(void);
62 
63 	image_entry_noargs_t image_entry =
64 		(image_entry_noargs_t)spl_image->entry_point;
65 	if (aspeed_bl2_verify((void*)spl_image->entry_point, CONFIG_SPL_TEXT_BASE) != 0)
66 		hang();
67 	image_entry();
68 }
69 #endif
70 
71 #ifdef CONFIG_SPL_MMC_SUPPORT
72 u32 spl_boot_mode(const u32 boot_device)
73 {
74 	return MMCSD_MODE_RAW;
75 }
76 #endif
77 
78 #ifdef CONFIG_SPL_OS_BOOT
79 int spl_start_uboot(void)
80 {
81 	/* boot linux */
82 	return 0;
83 }
84 #endif
85 
86 #ifdef CONFIG_SPL_LOAD_FIT
87 int board_fit_config_name_match(const char *name)
88 {
89 	/* Just empty function now - can't decide what to choose */
90 	debug("%s: %s\n", __func__, name);
91 
92 	return 0;
93 }
94 #endif
95