blob: 44c68a39bc628e75115b6e693c9d5c30061a79a3 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glasse961a662016-07-04 11:57:51 -06002/*
3 * Copyright (c) 2016 Google, Inc
Simon Glasse961a662016-07-04 11:57:51 -06004 */
5
6#include <common.h>
7#include <dm.h>
8#include <os.h>
Simon Glassa091a8f2016-07-04 11:57:55 -06009#include <spl.h>
Simon Glasse961a662016-07-04 11:57:51 -060010#include <asm/spl.h>
11#include <asm/state.h>
12
13DECLARE_GLOBAL_DATA_PTR;
14
Simon Glass912dcb12019-05-18 11:59:46 -060015/* SPL / TPL init function */
Simon Glasse961a662016-07-04 11:57:51 -060016void 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
24u32 spl_boot_device(void)
25{
26 return BOOT_DEVICE_BOARD;
27}
28
Simon Glass2a2ee2a2016-09-24 18:20:13 -060029static int spl_board_load_image(struct spl_image_info *spl_image,
30 struct spl_boot_device *bootdev)
Simon Glasse961a662016-07-04 11:57:51 -060031{
32 char fname[256];
33 int ret;
34
35 ret = os_find_u_boot(fname, sizeof(fname));
Simon Glassf831b8e2016-11-30 15:30:56 -070036 if (ret) {
37 printf("(%s not found, error %d)\n", fname, ret);
Simon Glasse961a662016-07-04 11:57:51 -060038 return ret;
Simon Glassf831b8e2016-11-30 15:30:56 -070039 }
Simon Glasse961a662016-07-04 11:57:51 -060040
Simon Glass27028f12018-11-15 18:44:08 -070041 /* 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;
Simon Glasse961a662016-07-04 11:57:51 -060047}
Simon Glass3f2f5cf2019-05-18 11:59:45 -060048SPL_LOAD_IMAGE_METHOD("sandbox", 9, BOOT_DEVICE_BOARD, spl_board_load_image);
Simon Glassa091a8f2016-07-04 11:57:55 -060049
50void spl_board_init(void)
51{
Simon Glass1ca910b2018-11-15 18:44:01 -070052 struct sandbox_state *state = state_get_current();
53 struct udevice *dev;
54
Simon Glassa091a8f2016-07-04 11:57:55 -060055 preloader_console_init();
Simon Glass1ca910b2018-11-15 18:44:01 -070056 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 }
Simon Glassa091a8f2016-07-04 11:57:55 -060067}
Simon Glass27028f12018-11-15 18:44:08 -070068
69void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
70{
71 const char *fname = spl_image->arg;
72
Simon Glass12efc932018-11-23 21:29:25 -070073 if (fname) {
74 os_fd_restore();
75 os_spl_to_uboot(fname);
76 } else {
77 printf("No filename provided for U-Boot\n");
78 }
Simon Glass27028f12018-11-15 18:44:08 -070079 hang();
80}
Simon Glass366291a2019-09-25 08:11:18 -060081
82int handoff_arch_save(struct spl_handoff *ho)
83{
84 ho->arch.magic = TEST_HANDOFF_MAGIC;
85
86 return 0;
87}