1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (c) 2016 Google, Inc
4 */
5
6 #include <common.h>
7 #include <dm.h>
8 #include <hang.h>
9 #include <init.h>
10 #include <log.h>
11 #include <os.h>
12 #include <spl.h>
13 #include <asm/global_data.h>
14 #include <asm/spl.h>
15 #include <asm/state.h>
16 #include <test/test.h>
17
18 DECLARE_GLOBAL_DATA_PTR;
19
20 /* SPL / TPL init function */
board_init_f(ulong flag)21 void board_init_f(ulong flag)
22 {
23 struct sandbox_state *state = state_get_current();
24
25 gd->arch.ram_buf = state->ram_buf;
26 gd->ram_size = state->ram_size;
27 }
28
spl_boot_device(void)29 u32 spl_boot_device(void)
30 {
31 return BOOT_DEVICE_BOARD;
32 }
33
spl_board_load_image(struct spl_image_info * spl_image,struct spl_boot_device * bootdev)34 static int spl_board_load_image(struct spl_image_info *spl_image,
35 struct spl_boot_device *bootdev)
36 {
37 char fname[256];
38 int ret;
39
40 ret = os_find_u_boot(fname, sizeof(fname));
41 if (ret) {
42 printf("(%s not found, error %d)\n", fname, ret);
43 return ret;
44 }
45
46 /* Set up spl_image to boot from jump_to_image_no_args() */
47 spl_image->arg = strdup(fname);
48 if (!spl_image->arg)
49 return log_msg_ret("Setup exec filename", -ENOMEM);
50
51 return 0;
52 }
53 SPL_LOAD_IMAGE_METHOD("sandbox", 9, BOOT_DEVICE_BOARD, spl_board_load_image);
54
spl_board_init(void)55 void spl_board_init(void)
56 {
57 struct sandbox_state *state = state_get_current();
58
59 preloader_console_init();
60
61 if (state->run_unittests) {
62 int ret;
63
64 ret = dm_test_main(state->select_unittests);
65 /* continue execution into U-Boot */
66 }
67 }
68
jump_to_image_no_args(struct spl_image_info * spl_image)69 void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
70 {
71 const char *fname = spl_image->arg;
72
73 if (fname) {
74 os_fd_restore();
75 os_spl_to_uboot(fname);
76 } else {
77 printf("No filename provided for U-Boot\n");
78 }
79 hang();
80 }
81
handoff_arch_save(struct spl_handoff * ho)82 int handoff_arch_save(struct spl_handoff *ho)
83 {
84 ho->arch.magic = TEST_HANDOFF_MAGIC;
85
86 return 0;
87 }
88