2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2016-07-04 17:57:51 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Google, Inc
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
2019-12-28 17:45:07 +00:00
|
|
|
#include <hang.h>
|
2020-05-10 17:40:02 +00:00
|
|
|
#include <init.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2016-07-04 17:57:51 +00:00
|
|
|
#include <os.h>
|
2016-07-04 17:57:55 +00:00
|
|
|
#include <spl.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2016-07-04 17:57:51 +00:00
|
|
|
#include <asm/spl.h>
|
|
|
|
#include <asm/state.h>
|
2021-03-08 00:35:12 +00:00
|
|
|
#include <test/ut.h>
|
2016-07-04 17:57:51 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2021-07-05 22:32:45 +00:00
|
|
|
int sandbox_find_next_phase(char *fname, int maxlen, bool use_img)
|
|
|
|
{
|
|
|
|
const char *cur_prefix, *next_prefix;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
cur_prefix = spl_phase_prefix(spl_phase());
|
|
|
|
next_prefix = spl_phase_prefix(spl_next_phase());
|
|
|
|
ret = os_find_u_boot(fname, maxlen, use_img, cur_prefix, next_prefix);
|
|
|
|
if (ret)
|
|
|
|
return log_msg_ret("find", ret);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-05-18 17:59:46 +00:00
|
|
|
/* SPL / TPL init function */
|
2016-07-04 17:57:51 +00:00
|
|
|
void board_init_f(ulong flag)
|
|
|
|
{
|
|
|
|
struct sandbox_state *state = state_get_current();
|
|
|
|
|
|
|
|
gd->arch.ram_buf = state->ram_buf;
|
|
|
|
gd->ram_size = state->ram_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 spl_boot_device(void)
|
|
|
|
{
|
|
|
|
return BOOT_DEVICE_BOARD;
|
|
|
|
}
|
|
|
|
|
2016-09-25 00:20:13 +00:00
|
|
|
static int spl_board_load_image(struct spl_image_info *spl_image,
|
|
|
|
struct spl_boot_device *bootdev)
|
2016-07-04 17:57:51 +00:00
|
|
|
{
|
|
|
|
char fname[256];
|
|
|
|
int ret;
|
|
|
|
|
2021-07-05 22:32:45 +00:00
|
|
|
ret = sandbox_find_next_phase(fname, sizeof(fname), false);
|
2016-11-30 22:30:56 +00:00
|
|
|
if (ret) {
|
|
|
|
printf("(%s not found, error %d)\n", fname, ret);
|
2016-07-04 17:57:51 +00:00
|
|
|
return ret;
|
2016-11-30 22:30:56 +00:00
|
|
|
}
|
2016-07-04 17:57:51 +00:00
|
|
|
|
2021-02-06 16:57:33 +00:00
|
|
|
/*
|
|
|
|
* Set up spl_image to boot from jump_to_image_no_args(). Allocate this
|
|
|
|
* outsdide the RAM buffer (i.e. don't use strdup()).
|
|
|
|
*/
|
|
|
|
spl_image->arg = os_malloc(strlen(fname) + 1);
|
2018-11-16 01:44:08 +00:00
|
|
|
if (!spl_image->arg)
|
2021-02-06 16:57:33 +00:00
|
|
|
return log_msg_ret("exec", -ENOMEM);
|
|
|
|
strcpy(spl_image->arg, fname);
|
2018-11-16 01:44:08 +00:00
|
|
|
|
|
|
|
return 0;
|
2016-07-04 17:57:51 +00:00
|
|
|
}
|
2019-05-18 17:59:45 +00:00
|
|
|
SPL_LOAD_IMAGE_METHOD("sandbox", 9, BOOT_DEVICE_BOARD, spl_board_load_image);
|
2016-07-04 17:57:55 +00:00
|
|
|
|
|
|
|
void spl_board_init(void)
|
|
|
|
{
|
2018-11-16 01:44:01 +00:00
|
|
|
struct sandbox_state *state = state_get_current();
|
|
|
|
|
2016-07-04 17:57:55 +00:00
|
|
|
preloader_console_init();
|
2020-10-26 02:38:28 +00:00
|
|
|
|
|
|
|
if (state->run_unittests) {
|
2021-03-08 00:35:12 +00:00
|
|
|
struct unit_test *tests = UNIT_TEST_ALL_START();
|
|
|
|
const int count = UNIT_TEST_ALL_COUNT();
|
2020-10-26 02:38:28 +00:00
|
|
|
int ret;
|
|
|
|
|
2021-03-08 00:35:12 +00:00
|
|
|
ret = ut_run_list("spl", NULL, tests, count,
|
|
|
|
state->select_unittests);
|
2020-10-26 02:38:28 +00:00
|
|
|
/* continue execution into U-Boot */
|
|
|
|
}
|
2016-07-04 17:57:55 +00:00
|
|
|
}
|
2018-11-16 01:44:08 +00:00
|
|
|
|
|
|
|
void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
|
|
|
|
{
|
|
|
|
const char *fname = spl_image->arg;
|
|
|
|
|
2018-11-24 04:29:25 +00:00
|
|
|
if (fname) {
|
|
|
|
os_fd_restore();
|
|
|
|
os_spl_to_uboot(fname);
|
|
|
|
} else {
|
|
|
|
printf("No filename provided for U-Boot\n");
|
|
|
|
}
|
2018-11-16 01:44:08 +00:00
|
|
|
hang();
|
|
|
|
}
|
2019-09-25 14:11:18 +00:00
|
|
|
|
|
|
|
int handoff_arch_save(struct spl_handoff *ho)
|
|
|
|
{
|
|
|
|
ho->arch.magic = TEST_HANDOFF_MAGIC;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|