blob: 7ab8919eb9091e2ffdf1a1d8c2e0afd87065bf23 [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 Glass691d7192020-05-10 11:40:02 -06009#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060010#include <log.h>
Simon Glasse961a662016-07-04 11:57:51 -060011#include <os.h>
Simon Glassa091a8f2016-07-04 11:57:55 -060012#include <spl.h>
Simon Glasse961a662016-07-04 11:57:51 -060013#include <asm/spl.h>
14#include <asm/state.h>
15
16DECLARE_GLOBAL_DATA_PTR;
17
Simon Glass912dcb12019-05-18 11:59:46 -060018/* SPL / TPL init function */
Simon Glasse961a662016-07-04 11:57:51 -060019void 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
27u32 spl_boot_device(void)
28{
29 return BOOT_DEVICE_BOARD;
30}
31
Simon Glass2a2ee2a2016-09-24 18:20:13 -060032static int spl_board_load_image(struct spl_image_info *spl_image,
33 struct spl_boot_device *bootdev)
Simon Glasse961a662016-07-04 11:57:51 -060034{
35 char fname[256];
36 int ret;
37
38 ret = os_find_u_boot(fname, sizeof(fname));
Simon Glassf831b8e2016-11-30 15:30:56 -070039 if (ret) {
40 printf("(%s not found, error %d)\n", fname, ret);
Simon Glasse961a662016-07-04 11:57:51 -060041 return ret;
Simon Glassf831b8e2016-11-30 15:30:56 -070042 }
Simon Glasse961a662016-07-04 11:57:51 -060043
Simon Glass27028f12018-11-15 18:44:08 -070044 /* 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;
Simon Glasse961a662016-07-04 11:57:51 -060050}
Simon Glass3f2f5cf2019-05-18 11:59:45 -060051SPL_LOAD_IMAGE_METHOD("sandbox", 9, BOOT_DEVICE_BOARD, spl_board_load_image);
Simon Glassa091a8f2016-07-04 11:57:55 -060052
53void spl_board_init(void)
54{
Simon Glass1ca910b2018-11-15 18:44:01 -070055 struct sandbox_state *state = state_get_current();
56 struct udevice *dev;
57
Simon Glassa091a8f2016-07-04 11:57:55 -060058 preloader_console_init();
Simon Glass1ca910b2018-11-15 18:44:01 -070059 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 }
Simon Glassa091a8f2016-07-04 11:57:55 -060070}
Simon Glass27028f12018-11-15 18:44:08 -070071
72void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
73{
74 const char *fname = spl_image->arg;
75
Simon Glass12efc932018-11-23 21:29:25 -070076 if (fname) {
77 os_fd_restore();
78 os_spl_to_uboot(fname);
79 } else {
80 printf("No filename provided for U-Boot\n");
81 }
Simon Glass27028f12018-11-15 18:44:08 -070082 hang();
83}
Simon Glass366291a2019-09-25 08:11:18 -060084
85int handoff_arch_save(struct spl_handoff *ho)
86{
87 ho->arch.magic = TEST_HANDOFF_MAGIC;
88
89 return 0;
90}