blob: 3f107b8acbdb1295df4e0064e4286f17cf28f080 [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 Glassacc874a2022-02-28 15:13:46 -07009#include <handoff.h>
Simon Glass691d7192020-05-10 11:40:02 -060010#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060011#include <log.h>
Simon Glasse961a662016-07-04 11:57:51 -060012#include <os.h>
Simon Glassa091a8f2016-07-04 11:57:55 -060013#include <spl.h>
Simon Glass401d1c42020-10-30 21:38:53 -060014#include <asm/global_data.h>
Simon Glasse961a662016-07-04 11:57:51 -060015#include <asm/spl.h>
16#include <asm/state.h>
Simon Glass84823562021-03-07 17:35:12 -070017#include <test/ut.h>
Simon Glasse961a662016-07-04 11:57:51 -060018
19DECLARE_GLOBAL_DATA_PTR;
20
Simon Glassf178beb2021-07-05 16:32:45 -060021int sandbox_find_next_phase(char *fname, int maxlen, bool use_img)
22{
23 const char *cur_prefix, *next_prefix;
24 int ret;
25
26 cur_prefix = spl_phase_prefix(spl_phase());
27 next_prefix = spl_phase_prefix(spl_next_phase());
28 ret = os_find_u_boot(fname, maxlen, use_img, cur_prefix, next_prefix);
29 if (ret)
30 return log_msg_ret("find", ret);
31
32 return 0;
33}
34
Simon Glass912dcb12019-05-18 11:59:46 -060035/* SPL / TPL init function */
Simon Glasse961a662016-07-04 11:57:51 -060036void board_init_f(ulong flag)
37{
38 struct sandbox_state *state = state_get_current();
39
40 gd->arch.ram_buf = state->ram_buf;
41 gd->ram_size = state->ram_size;
42}
43
44u32 spl_boot_device(void)
45{
46 return BOOT_DEVICE_BOARD;
47}
48
Simon Glass2a2ee2a2016-09-24 18:20:13 -060049static int spl_board_load_image(struct spl_image_info *spl_image,
50 struct spl_boot_device *bootdev)
Simon Glasse961a662016-07-04 11:57:51 -060051{
52 char fname[256];
53 int ret;
54
Simon Glassf178beb2021-07-05 16:32:45 -060055 ret = sandbox_find_next_phase(fname, sizeof(fname), false);
Simon Glassf831b8e2016-11-30 15:30:56 -070056 if (ret) {
57 printf("(%s not found, error %d)\n", fname, ret);
Simon Glasse961a662016-07-04 11:57:51 -060058 return ret;
Simon Glassf831b8e2016-11-30 15:30:56 -070059 }
Simon Glasse961a662016-07-04 11:57:51 -060060
Simon Glassb308d9f2021-02-06 09:57:33 -070061 /*
62 * Set up spl_image to boot from jump_to_image_no_args(). Allocate this
63 * outsdide the RAM buffer (i.e. don't use strdup()).
64 */
65 spl_image->arg = os_malloc(strlen(fname) + 1);
Simon Glass27028f12018-11-15 18:44:08 -070066 if (!spl_image->arg)
Simon Glassb308d9f2021-02-06 09:57:33 -070067 return log_msg_ret("exec", -ENOMEM);
68 strcpy(spl_image->arg, fname);
Simon Glass27028f12018-11-15 18:44:08 -070069
70 return 0;
Simon Glasse961a662016-07-04 11:57:51 -060071}
Simon Glass3f2f5cf2019-05-18 11:59:45 -060072SPL_LOAD_IMAGE_METHOD("sandbox", 9, BOOT_DEVICE_BOARD, spl_board_load_image);
Simon Glassa091a8f2016-07-04 11:57:55 -060073
74void spl_board_init(void)
75{
Simon Glass1ca910b2018-11-15 18:44:01 -070076 struct sandbox_state *state = state_get_current();
Simon Glass1ca910b2018-11-15 18:44:01 -070077
Simon Glassa091a8f2016-07-04 11:57:55 -060078 preloader_console_init();
Simon Glassb25ff5c2020-10-25 20:38:28 -060079
80 if (state->run_unittests) {
Simon Glass84823562021-03-07 17:35:12 -070081 struct unit_test *tests = UNIT_TEST_ALL_START();
82 const int count = UNIT_TEST_ALL_COUNT();
Simon Glassb25ff5c2020-10-25 20:38:28 -060083 int ret;
84
Simon Glass84823562021-03-07 17:35:12 -070085 ret = ut_run_list("spl", NULL, tests, count,
86 state->select_unittests);
Simon Glassb25ff5c2020-10-25 20:38:28 -060087 /* continue execution into U-Boot */
88 }
Simon Glassa091a8f2016-07-04 11:57:55 -060089}
Simon Glass27028f12018-11-15 18:44:08 -070090
91void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
92{
93 const char *fname = spl_image->arg;
94
Simon Glass12efc932018-11-23 21:29:25 -070095 if (fname) {
96 os_fd_restore();
97 os_spl_to_uboot(fname);
98 } else {
99 printf("No filename provided for U-Boot\n");
100 }
Simon Glass27028f12018-11-15 18:44:08 -0700101 hang();
102}
Simon Glass366291a2019-09-25 08:11:18 -0600103
104int handoff_arch_save(struct spl_handoff *ho)
105{
106 ho->arch.magic = TEST_HANDOFF_MAGIC;
107
108 return 0;
109}