Merge tag 'u-boot-atmel-fixes-2020.07-a' of https://gitlab.denx.de/u-boot/custodians...
[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 <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
16 DECLARE_GLOBAL_DATA_PTR;
17
18 /* SPL / TPL init function */
19 void board_init_f(ulong flag)
20 {
21         struct sandbox_state *state = state_get_current();
22
23         gd->arch.ram_buf = state->ram_buf;
24         gd->ram_size = state->ram_size;
25 }
26
27 u32 spl_boot_device(void)
28 {
29         return BOOT_DEVICE_BOARD;
30 }
31
32 static int spl_board_load_image(struct spl_image_info *spl_image,
33                                 struct spl_boot_device *bootdev)
34 {
35         char fname[256];
36         int ret;
37
38         ret = os_find_u_boot(fname, sizeof(fname));
39         if (ret) {
40                 printf("(%s not found, error %d)\n", fname, ret);
41                 return ret;
42         }
43
44         /* Set up spl_image to boot from jump_to_image_no_args() */
45         spl_image->arg = strdup(fname);
46         if (!spl_image->arg)
47                 return log_msg_ret("Setup exec filename", -ENOMEM);
48
49         return 0;
50 }
51 SPL_LOAD_IMAGE_METHOD("sandbox", 9, BOOT_DEVICE_BOARD, spl_board_load_image);
52
53 void spl_board_init(void)
54 {
55         struct sandbox_state *state = state_get_current();
56         struct udevice *dev;
57
58         preloader_console_init();
59         if (state->show_of_platdata) {
60                 /*
61                  * Scan all the devices so that we can output their platform
62                  * data. See sandbox_spl_probe().
63                  */
64                 printf("Scanning misc devices\n");
65                 for (uclass_first_device(UCLASS_MISC, &dev);
66                      dev;
67                      uclass_next_device(&dev))
68                         ;
69         }
70 }
71
72 void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
73 {
74         const char *fname = spl_image->arg;
75
76         if (fname) {
77                 os_fd_restore();
78                 os_spl_to_uboot(fname);
79         } else {
80                 printf("No filename provided for U-Boot\n");
81         }
82         hang();
83 }
84
85 int handoff_arch_save(struct spl_handoff *ho)
86 {
87         ho->arch.magic = TEST_HANDOFF_MAGIC;
88
89         return 0;
90 }