blob: 7ab8919eb9091e2ffdf1a1d8c2e0afd87065bf23 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassa7e2d4d2016-07-04 11:57:51 -06002/*
3 * Copyright (c) 2016 Google, Inc
Simon Glassa7e2d4d2016-07-04 11:57:51 -06004 */
5
6#include <common.h>
7#include <dm.h>
Simon Glassf11478f2019-12-28 10:45:07 -07008#include <hang.h>
Simon Glass97589732020-05-10 11:40:02 -06009#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Simon Glassa7e2d4d2016-07-04 11:57:51 -060011#include <os.h>
Simon Glass4e9c1312016-07-04 11:57:55 -060012#include <spl.h>
Simon Glassa7e2d4d2016-07-04 11:57:51 -060013#include <asm/spl.h>
14#include <asm/state.h>
15
16DECLARE_GLOBAL_DATA_PTR;
17
Simon Glasse55cc062019-05-18 11:59:46 -060018/* SPL / TPL init function */
Simon Glassa7e2d4d2016-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 Glassee306792016-09-24 18:20:13 -060032static int spl_board_load_image(struct spl_image_info *spl_image,
33 struct spl_boot_device *bootdev)
Simon Glassa7e2d4d2016-07-04 11:57:51 -060034{
35 char fname[256];
36 int ret;
37
38 ret = os_find_u_boot(fname, sizeof(fname));
Simon Glasse8845d22016-11-30 15:30:56 -070039 if (ret) {
40 printf("(%s not found, error %d)\n", fname, ret);
Simon Glassa7e2d4d2016-07-04 11:57:51 -060041 return ret;
Simon Glasse8845d22016-11-30 15:30:56 -070042 }
Simon Glassa7e2d4d2016-07-04 11:57:51 -060043
Simon Glasscca25522018-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 Glassa7e2d4d2016-07-04 11:57:51 -060050}
Simon Glassfb9128d2019-05-18 11:59:45 -060051SPL_LOAD_IMAGE_METHOD("sandbox", 9, BOOT_DEVICE_BOARD, spl_board_load_image);
Simon Glass4e9c1312016-07-04 11:57:55 -060052
53void spl_board_init(void)
54{
Simon Glassb5dfea82018-11-15 18:44:01 -070055 struct sandbox_state *state = state_get_current();
56 struct udevice *dev;
57
Simon Glass4e9c1312016-07-04 11:57:55 -060058 preloader_console_init();
Simon Glassb5dfea82018-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 Glass4e9c1312016-07-04 11:57:55 -060070}
Simon Glasscca25522018-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 Glass38c2eae2018-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 Glasscca25522018-11-15 18:44:08 -070082 hang();
83}
Simon Glassc5d27202019-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}