blob: d5f683bbaae1fe2f539b0bd0a5c19f606c5f3014 [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>
Simon Glassdb41d652019-12-28 10:45:07 -07008#include <hang.h>
Simon Glasse961a662016-07-04 11:57:51 -06009#include <os.h>
Simon Glassa091a8f2016-07-04 11:57:55 -060010#include <spl.h>
Simon Glasse961a662016-07-04 11:57:51 -060011#include <asm/spl.h>
12#include <asm/state.h>
13
14DECLARE_GLOBAL_DATA_PTR;
15
Simon Glass912dcb12019-05-18 11:59:46 -060016/* SPL / TPL init function */
Simon Glasse961a662016-07-04 11:57:51 -060017void board_init_f(ulong flag)
18{
19 struct sandbox_state *state = state_get_current();
20
21 gd->arch.ram_buf = state->ram_buf;
22 gd->ram_size = state->ram_size;
23}
24
25u32 spl_boot_device(void)
26{
27 return BOOT_DEVICE_BOARD;
28}
29
Simon Glass2a2ee2a2016-09-24 18:20:13 -060030static int spl_board_load_image(struct spl_image_info *spl_image,
31 struct spl_boot_device *bootdev)
Simon Glasse961a662016-07-04 11:57:51 -060032{
33 char fname[256];
34 int ret;
35
36 ret = os_find_u_boot(fname, sizeof(fname));
Simon Glassf831b8e2016-11-30 15:30:56 -070037 if (ret) {
38 printf("(%s not found, error %d)\n", fname, ret);
Simon Glasse961a662016-07-04 11:57:51 -060039 return ret;
Simon Glassf831b8e2016-11-30 15:30:56 -070040 }
Simon Glasse961a662016-07-04 11:57:51 -060041
Simon Glass27028f12018-11-15 18:44:08 -070042 /* Set up spl_image to boot from jump_to_image_no_args() */
43 spl_image->arg = strdup(fname);
44 if (!spl_image->arg)
45 return log_msg_ret("Setup exec filename", -ENOMEM);
46
47 return 0;
Simon Glasse961a662016-07-04 11:57:51 -060048}
Simon Glass3f2f5cf2019-05-18 11:59:45 -060049SPL_LOAD_IMAGE_METHOD("sandbox", 9, BOOT_DEVICE_BOARD, spl_board_load_image);
Simon Glassa091a8f2016-07-04 11:57:55 -060050
51void spl_board_init(void)
52{
Simon Glass1ca910b2018-11-15 18:44:01 -070053 struct sandbox_state *state = state_get_current();
54 struct udevice *dev;
55
Simon Glassa091a8f2016-07-04 11:57:55 -060056 preloader_console_init();
Simon Glass1ca910b2018-11-15 18:44:01 -070057 if (state->show_of_platdata) {
58 /*
59 * Scan all the devices so that we can output their platform
60 * data. See sandbox_spl_probe().
61 */
62 printf("Scanning misc devices\n");
63 for (uclass_first_device(UCLASS_MISC, &dev);
64 dev;
65 uclass_next_device(&dev))
66 ;
67 }
Simon Glassa091a8f2016-07-04 11:57:55 -060068}
Simon Glass27028f12018-11-15 18:44:08 -070069
70void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
71{
72 const char *fname = spl_image->arg;
73
Simon Glass12efc932018-11-23 21:29:25 -070074 if (fname) {
75 os_fd_restore();
76 os_spl_to_uboot(fname);
77 } else {
78 printf("No filename provided for U-Boot\n");
79 }
Simon Glass27028f12018-11-15 18:44:08 -070080 hang();
81}
Simon Glass366291a2019-09-25 08:11:18 -060082
83int handoff_arch_save(struct spl_handoff *ho)
84{
85 ho->arch.magic = TEST_HANDOFF_MAGIC;
86
87 return 0;
88}