blob: fe5d44d36edc4010fac4a74a683c8bf4aabc088b [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 Glass9ee7b732022-02-28 15:13:46 -07009#include <handoff.h>
Simon Glass97589732020-05-10 11:40:02 -060010#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Simon Glassa7e2d4d2016-07-04 11:57:51 -060012#include <os.h>
Simon Glass4e9c1312016-07-04 11:57:55 -060013#include <spl.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060014#include <asm/global_data.h>
Simon Glassa7e2d4d2016-07-04 11:57:51 -060015#include <asm/spl.h>
16#include <asm/state.h>
Simon Glass1ef74ab2021-03-07 17:35:12 -070017#include <test/ut.h>
Simon Glassa7e2d4d2016-07-04 11:57:51 -060018
19DECLARE_GLOBAL_DATA_PTR;
20
Simon Glass1cd06002021-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 Glassc86e6202022-04-30 00:56:54 -060035/* SPL / TPL / VPL init function */
Simon Glassa7e2d4d2016-07-04 11:57:51 -060036void board_init_f(ulong flag)
37{
38 struct sandbox_state *state = state_get_current();
Simon Glassc86e6202022-04-30 00:56:54 -060039 int ret;
Simon Glassa7e2d4d2016-07-04 11:57:51 -060040
41 gd->arch.ram_buf = state->ram_buf;
42 gd->ram_size = state->ram_size;
Simon Glassc86e6202022-04-30 00:56:54 -060043
44 ret = spl_early_init();
45 if (ret) {
46 debug("spl_early_init() failed: %d\n", ret);
47 hang();
48 }
49 preloader_console_init();
Simon Glassa7e2d4d2016-07-04 11:57:51 -060050}
51
52u32 spl_boot_device(void)
53{
54 return BOOT_DEVICE_BOARD;
55}
56
Simon Glassee306792016-09-24 18:20:13 -060057static int spl_board_load_image(struct spl_image_info *spl_image,
58 struct spl_boot_device *bootdev)
Simon Glassa7e2d4d2016-07-04 11:57:51 -060059{
60 char fname[256];
61 int ret;
62
Simon Glass1cd06002021-07-05 16:32:45 -060063 ret = sandbox_find_next_phase(fname, sizeof(fname), false);
Simon Glasse8845d22016-11-30 15:30:56 -070064 if (ret) {
65 printf("(%s not found, error %d)\n", fname, ret);
Simon Glassa7e2d4d2016-07-04 11:57:51 -060066 return ret;
Simon Glasse8845d22016-11-30 15:30:56 -070067 }
Simon Glassa7e2d4d2016-07-04 11:57:51 -060068
Simon Glassedd094e2021-02-06 09:57:33 -070069 /*
70 * Set up spl_image to boot from jump_to_image_no_args(). Allocate this
71 * outsdide the RAM buffer (i.e. don't use strdup()).
72 */
73 spl_image->arg = os_malloc(strlen(fname) + 1);
Simon Glasscca25522018-11-15 18:44:08 -070074 if (!spl_image->arg)
Simon Glassedd094e2021-02-06 09:57:33 -070075 return log_msg_ret("exec", -ENOMEM);
76 strcpy(spl_image->arg, fname);
Simon Glasscca25522018-11-15 18:44:08 -070077
78 return 0;
Simon Glassa7e2d4d2016-07-04 11:57:51 -060079}
Simon Glassfb9128d2019-05-18 11:59:45 -060080SPL_LOAD_IMAGE_METHOD("sandbox", 9, BOOT_DEVICE_BOARD, spl_board_load_image);
Simon Glass4e9c1312016-07-04 11:57:55 -060081
82void spl_board_init(void)
83{
Simon Glassb5dfea82018-11-15 18:44:01 -070084 struct sandbox_state *state = state_get_current();
Simon Glassb5dfea82018-11-15 18:44:01 -070085
Simon Glassa4e289b2020-10-25 20:38:28 -060086 if (state->run_unittests) {
Simon Glass1ef74ab2021-03-07 17:35:12 -070087 struct unit_test *tests = UNIT_TEST_ALL_START();
88 const int count = UNIT_TEST_ALL_COUNT();
Simon Glassa4e289b2020-10-25 20:38:28 -060089 int ret;
90
Simon Glass1ef74ab2021-03-07 17:35:12 -070091 ret = ut_run_list("spl", NULL, tests, count,
92 state->select_unittests);
Simon Glassa4e289b2020-10-25 20:38:28 -060093 /* continue execution into U-Boot */
94 }
Simon Glass4e9c1312016-07-04 11:57:55 -060095}
Simon Glasscca25522018-11-15 18:44:08 -070096
97void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
98{
99 const char *fname = spl_image->arg;
100
Simon Glass38c2eae2018-11-23 21:29:25 -0700101 if (fname) {
102 os_fd_restore();
103 os_spl_to_uboot(fname);
104 } else {
105 printf("No filename provided for U-Boot\n");
106 }
Simon Glasscca25522018-11-15 18:44:08 -0700107 hang();
108}
Simon Glassc5d27202019-09-25 08:11:18 -0600109
110int handoff_arch_save(struct spl_handoff *ho)
111{
112 ho->arch.magic = TEST_HANDOFF_MAGIC;
113
114 return 0;
115}