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>
|
2022-02-28 22:13:46 +00:00
|
|
|
#include <handoff.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;
|
|
|
|
}
|
|
|
|
|
2022-04-30 06:56:54 +00:00
|
|
|
/* SPL / TPL / VPL init function */
|
2016-07-04 17:57:51 +00:00
|
|
|
void board_init_f(ulong flag)
|
|
|
|
{
|
|
|
|
struct sandbox_state *state = state_get_current();
|
2022-04-30 06:56:54 +00:00
|
|
|
int ret;
|
2016-07-04 17:57:51 +00:00
|
|
|
|
|
|
|
gd->arch.ram_buf = state->ram_buf;
|
|
|
|
gd->ram_size = state->ram_size;
|
2022-04-30 06:56:54 +00:00
|
|
|
|
|
|
|
ret = spl_early_init();
|
|
|
|
if (ret) {
|
|
|
|
debug("spl_early_init() failed: %d\n", ret);
|
|
|
|
hang();
|
|
|
|
}
|
|
|
|
preloader_console_init();
|
2016-07-04 17:57:51 +00:00
|
|
|
}
|
|
|
|
|
2022-10-21 00:23:01 +00:00
|
|
|
void board_boot_order(u32 *spl_boot_list)
|
2016-07-04 17:57:51 +00:00
|
|
|
{
|
2022-10-21 00:23:10 +00:00
|
|
|
spl_boot_list[0] = BOOT_DEVICE_VBE;
|
|
|
|
spl_boot_list[1] = BOOT_DEVICE_BOARD;
|
2016-07-04 17:57:51 +00:00
|
|
|
}
|
|
|
|
|
2022-10-21 00:23:01 +00:00
|
|
|
static int spl_board_load_file(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);
|
2022-10-21 00:23:01 +00:00
|
|
|
spl_image->flags = SPL_SANDBOXF_ARG_IS_FNAME;
|
2018-11-16 01:44:08 +00:00
|
|
|
|
|
|
|
return 0;
|
2016-07-04 17:57:51 +00:00
|
|
|
}
|
2022-10-21 00:23:08 +00:00
|
|
|
SPL_LOAD_IMAGE_METHOD("sandbox_file", 9, BOOT_DEVICE_BOARD,
|
|
|
|
spl_board_load_file);
|
|
|
|
|
|
|
|
static int load_from_image(struct spl_image_info *spl_image,
|
|
|
|
struct spl_boot_device *bootdev)
|
|
|
|
{
|
|
|
|
struct sandbox_state *state = state_get_current();
|
|
|
|
enum u_boot_phase next_phase;
|
|
|
|
const char *fname;
|
|
|
|
ulong pos, size;
|
|
|
|
int full_size;
|
|
|
|
void *buf;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!IS_ENABLED(CONFIG_SANDBOX_VPL))
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
next_phase = spl_next_phase();
|
|
|
|
pos = spl_get_image_pos();
|
|
|
|
size = spl_get_image_size();
|
|
|
|
if (pos == BINMAN_SYM_MISSING || size == BINMAN_SYM_MISSING) {
|
|
|
|
log_debug("No image found\n");
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
log_info("Reading from pos %lx size %lx\n", pos, size);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up spl_image to boot from jump_to_image_no_args(). Allocate this
|
|
|
|
* outside the RAM buffer (i.e. don't use strdup()).
|
|
|
|
*/
|
|
|
|
fname = state->prog_fname ? state->prog_fname : state->argv[0];
|
|
|
|
ret = os_read_file(fname, &buf, &full_size);
|
|
|
|
if (ret)
|
|
|
|
return log_msg_ret("rd", -ENOMEM);
|
|
|
|
spl_image->flags = SPL_SANDBOXF_ARG_IS_BUF;
|
|
|
|
spl_image->arg = buf;
|
|
|
|
spl_image->offset = pos;
|
|
|
|
spl_image->size = size;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
SPL_LOAD_IMAGE_METHOD("sandbox_image", 7, BOOT_DEVICE_BOARD, load_from_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();
|
|
|
|
|
2023-10-03 00:59:46 +00:00
|
|
|
if (!CONFIG_IS_ENABLED(UNIT_TEST))
|
|
|
|
return;
|
|
|
|
|
2023-10-14 20:48:03 +00:00
|
|
|
/* These are necessary so TFTP can use LMBs to check its load address */
|
|
|
|
gd->bd->bi_dram[0].start = gd->ram_base;
|
|
|
|
gd->bd->bi_dram[0].size = get_effective_memsize();
|
|
|
|
|
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,
|
2022-10-30 01:47:13 +00:00
|
|
|
state->select_unittests, 1, false, NULL);
|
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)
|
|
|
|
{
|
2022-10-21 00:23:01 +00:00
|
|
|
switch (spl_image->flags) {
|
|
|
|
case SPL_SANDBOXF_ARG_IS_FNAME: {
|
|
|
|
const char *fname = spl_image->arg;
|
|
|
|
|
|
|
|
if (fname) {
|
|
|
|
os_fd_restore();
|
|
|
|
os_spl_to_uboot(fname);
|
|
|
|
} else {
|
|
|
|
log_err("No filename provided for U-Boot\n");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-10-21 00:23:08 +00:00
|
|
|
case SPL_SANDBOXF_ARG_IS_BUF: {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = os_jump_to_image(spl_image->arg + spl_image->offset,
|
|
|
|
spl_image->size);
|
|
|
|
if (ret)
|
|
|
|
log_err("Failed to load image\n");
|
|
|
|
break;
|
|
|
|
}
|
2022-10-21 00:23:01 +00:00
|
|
|
default:
|
|
|
|
log_err("Invalid flags\n");
|
|
|
|
break;
|
2018-11-24 04:29:25 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|