blob: 650bdb0a7014ecd7c764d0097f036e5b45f8c06f [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 Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Simon Glassa7e2d4d2016-07-04 11:57:51 -060014#include <asm/spl.h>
15#include <asm/state.h>
Simon Glass1ef74ab2021-03-07 17:35:12 -070016#include <test/ut.h>
Simon Glassa7e2d4d2016-07-04 11:57:51 -060017
18DECLARE_GLOBAL_DATA_PTR;
19
Simon Glass1cd06002021-07-05 16:32:45 -060020int sandbox_find_next_phase(char *fname, int maxlen, bool use_img)
21{
22 const char *cur_prefix, *next_prefix;
23 int ret;
24
25 cur_prefix = spl_phase_prefix(spl_phase());
26 next_prefix = spl_phase_prefix(spl_next_phase());
27 ret = os_find_u_boot(fname, maxlen, use_img, cur_prefix, next_prefix);
28 if (ret)
29 return log_msg_ret("find", ret);
30
31 return 0;
32}
33
Simon Glasse55cc062019-05-18 11:59:46 -060034/* SPL / TPL init function */
Simon Glassa7e2d4d2016-07-04 11:57:51 -060035void board_init_f(ulong flag)
36{
37 struct sandbox_state *state = state_get_current();
38
39 gd->arch.ram_buf = state->ram_buf;
40 gd->ram_size = state->ram_size;
41}
42
43u32 spl_boot_device(void)
44{
45 return BOOT_DEVICE_BOARD;
46}
47
Simon Glassee306792016-09-24 18:20:13 -060048static int spl_board_load_image(struct spl_image_info *spl_image,
49 struct spl_boot_device *bootdev)
Simon Glassa7e2d4d2016-07-04 11:57:51 -060050{
51 char fname[256];
52 int ret;
53
Simon Glass1cd06002021-07-05 16:32:45 -060054 ret = sandbox_find_next_phase(fname, sizeof(fname), false);
Simon Glasse8845d22016-11-30 15:30:56 -070055 if (ret) {
56 printf("(%s not found, error %d)\n", fname, ret);
Simon Glassa7e2d4d2016-07-04 11:57:51 -060057 return ret;
Simon Glasse8845d22016-11-30 15:30:56 -070058 }
Simon Glassa7e2d4d2016-07-04 11:57:51 -060059
Simon Glassedd094e2021-02-06 09:57:33 -070060 /*
61 * Set up spl_image to boot from jump_to_image_no_args(). Allocate this
62 * outsdide the RAM buffer (i.e. don't use strdup()).
63 */
64 spl_image->arg = os_malloc(strlen(fname) + 1);
Simon Glasscca25522018-11-15 18:44:08 -070065 if (!spl_image->arg)
Simon Glassedd094e2021-02-06 09:57:33 -070066 return log_msg_ret("exec", -ENOMEM);
67 strcpy(spl_image->arg, fname);
Simon Glasscca25522018-11-15 18:44:08 -070068
69 return 0;
Simon Glassa7e2d4d2016-07-04 11:57:51 -060070}
Simon Glassfb9128d2019-05-18 11:59:45 -060071SPL_LOAD_IMAGE_METHOD("sandbox", 9, BOOT_DEVICE_BOARD, spl_board_load_image);
Simon Glass4e9c1312016-07-04 11:57:55 -060072
73void spl_board_init(void)
74{
Simon Glassb5dfea82018-11-15 18:44:01 -070075 struct sandbox_state *state = state_get_current();
Simon Glassb5dfea82018-11-15 18:44:01 -070076
Simon Glass4e9c1312016-07-04 11:57:55 -060077 preloader_console_init();
Simon Glassa4e289b2020-10-25 20:38:28 -060078
79 if (state->run_unittests) {
Simon Glass1ef74ab2021-03-07 17:35:12 -070080 struct unit_test *tests = UNIT_TEST_ALL_START();
81 const int count = UNIT_TEST_ALL_COUNT();
Simon Glassa4e289b2020-10-25 20:38:28 -060082 int ret;
83
Simon Glass1ef74ab2021-03-07 17:35:12 -070084 ret = ut_run_list("spl", NULL, tests, count,
85 state->select_unittests);
Simon Glassa4e289b2020-10-25 20:38:28 -060086 /* continue execution into U-Boot */
87 }
Simon Glass4e9c1312016-07-04 11:57:55 -060088}
Simon Glasscca25522018-11-15 18:44:08 -070089
90void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
91{
92 const char *fname = spl_image->arg;
93
Simon Glass38c2eae2018-11-23 21:29:25 -070094 if (fname) {
95 os_fd_restore();
96 os_spl_to_uboot(fname);
97 } else {
98 printf("No filename provided for U-Boot\n");
99 }
Simon Glasscca25522018-11-15 18:44:08 -0700100 hang();
101}
Simon Glassc5d27202019-09-25 08:11:18 -0600102
103int handoff_arch_save(struct spl_handoff *ho)
104{
105 ho->arch.magic = TEST_HANDOFF_MAGIC;
106
107 return 0;
108}