ARM: imx6q_logic: Fix MMC2 booting
[oweals/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 <os.h>
9 #include <spl.h>
10 #include <asm/spl.h>
11 #include <asm/state.h>
12
13 DECLARE_GLOBAL_DATA_PTR;
14
15 /* SPL / TPL init function */
16 void board_init_f(ulong flag)
17 {
18         struct sandbox_state *state = state_get_current();
19
20         gd->arch.ram_buf = state->ram_buf;
21         gd->ram_size = state->ram_size;
22 }
23
24 u32 spl_boot_device(void)
25 {
26         return BOOT_DEVICE_BOARD;
27 }
28
29 static int spl_board_load_image(struct spl_image_info *spl_image,
30                                 struct spl_boot_device *bootdev)
31 {
32         char fname[256];
33         int ret;
34
35         ret = os_find_u_boot(fname, sizeof(fname));
36         if (ret) {
37                 printf("(%s not found, error %d)\n", fname, ret);
38                 return ret;
39         }
40
41         /* Set up spl_image to boot from jump_to_image_no_args() */
42         spl_image->arg = strdup(fname);
43         if (!spl_image->arg)
44                 return log_msg_ret("Setup exec filename", -ENOMEM);
45
46         return 0;
47 }
48 SPL_LOAD_IMAGE_METHOD("sandbox", 9, BOOT_DEVICE_BOARD, spl_board_load_image);
49
50 void spl_board_init(void)
51 {
52         struct sandbox_state *state = state_get_current();
53         struct udevice *dev;
54
55         preloader_console_init();
56         if (state->show_of_platdata) {
57                 /*
58                  * Scan all the devices so that we can output their platform
59                  * data. See sandbox_spl_probe().
60                  */
61                 printf("Scanning misc devices\n");
62                 for (uclass_first_device(UCLASS_MISC, &dev);
63                      dev;
64                      uclass_next_device(&dev))
65                         ;
66         }
67 }
68
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 }