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