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 
13 DECLARE_GLOBAL_DATA_PTR;
14 
15 #define AST_BOOTMODE_SPI  0
16 #define AST_BOOTMODE_EMMC 1
17 
18 u32 aspeed_bootmode(void);
19 
20 void board_init_f(ulong dummy)
21 {
22 #ifndef CONFIG_SPL_TINY
23 	spl_early_init();
24 	timer_init();
25 	preloader_console_init();
26 	dram_init();
27 #endif
28 }
29 
30 u32 spl_boot_device(void)
31 {
32 	switch(aspeed_bootmode()) {
33 #ifdef CONFIG_SPL_MMC_SUPPORT
34 		case AST_BOOTMODE_EMMC:
35 			return BOOT_DEVICE_MMC1;
36 #endif
37 		case AST_BOOTMODE_SPI:
38 			return BOOT_DEVICE_RAM;
39 		default:
40 			break;
41 	}
42 	return BOOT_DEVICE_NONE;
43  }
44 
45 struct image_header *spl_get_load_buffer(ssize_t offset, size_t size)
46 {
47 #ifdef CONFIG_SECURE_BOOT
48 	void *dst = (void*)CONFIG_SYS_UBOOT_START;
49 	void *src = (void*)CONFIG_SYS_TEXT_BASE;
50 	u32 count = CONFIG_SYS_MONITOR_LEN;
51 	memmove(dst, src, count);
52 #endif
53     return (struct image_header *)(CONFIG_SYS_TEXT_BASE);
54 }
55 
56 #ifdef CONFIG_SPL_MMC_SUPPORT
57 u32 spl_boot_mode(const u32 boot_device)
58 {
59 	return MMCSD_MODE_RAW;
60 }
61 #endif
62 
63 #ifdef CONFIG_SPL_OS_BOOT
64 int spl_start_uboot(void)
65 {
66 	/* boot linux */
67 	return 0;
68 }
69 #endif
70 
71 #ifdef CONFIG_SPL_LOAD_FIT
72 int board_fit_config_name_match(const char *name)
73 {
74 	/* Just empty function now - can't decide what to choose */
75 	debug("%s: %s\n", __func__, name);
76 
77 	return 0;
78 }
79 #endif
80