blob: 3779d58c3fec953f71b6c00e94517902fbf7766e [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 Glass691d7192020-05-10 11:40:02 -06009#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060010#include <log.h>
Simon Glasse961a662016-07-04 11:57:51 -060011#include <os.h>
Simon Glassa091a8f2016-07-04 11:57:55 -060012#include <spl.h>
Simon Glass401d1c42020-10-30 21:38:53 -060013#include <asm/global_data.h>
Simon Glasse961a662016-07-04 11:57:51 -060014#include <asm/spl.h>
15#include <asm/state.h>
Simon Glassb25ff5c2020-10-25 20:38:28 -060016#include <test/test.h>
Simon Glasse961a662016-07-04 11:57:51 -060017
18DECLARE_GLOBAL_DATA_PTR;
19
Simon Glass912dcb12019-05-18 11:59:46 -060020/* SPL / TPL init function */
Simon Glasse961a662016-07-04 11:57:51 -060021void board_init_f(ulong flag)
22{
23 struct sandbox_state *state = state_get_current();
24
25 gd->arch.ram_buf = state->ram_buf;
26 gd->ram_size = state->ram_size;
27}
28
29u32 spl_boot_device(void)
30{
31 return BOOT_DEVICE_BOARD;
32}
33
Simon Glass2a2ee2a2016-09-24 18:20:13 -060034static int spl_board_load_image(struct spl_image_info *spl_image,
35 struct spl_boot_device *bootdev)
Simon Glasse961a662016-07-04 11:57:51 -060036{
37 char fname[256];
38 int ret;
39
40 ret = os_find_u_boot(fname, sizeof(fname));
Simon Glassf831b8e2016-11-30 15:30:56 -070041 if (ret) {
42 printf("(%s not found, error %d)\n", fname, ret);
Simon Glasse961a662016-07-04 11:57:51 -060043 return ret;
Simon Glassf831b8e2016-11-30 15:30:56 -070044 }
Simon Glasse961a662016-07-04 11:57:51 -060045
Simon Glassb308d9f2021-02-06 09:57:33 -070046 /*
47 * Set up spl_image to boot from jump_to_image_no_args(). Allocate this
48 * outsdide the RAM buffer (i.e. don't use strdup()).
49 */
50 spl_image->arg = os_malloc(strlen(fname) + 1);
Simon Glass27028f12018-11-15 18:44:08 -070051 if (!spl_image->arg)
Simon Glassb308d9f2021-02-06 09:57:33 -070052 return log_msg_ret("exec", -ENOMEM);
53 strcpy(spl_image->arg, fname);
Simon Glass27028f12018-11-15 18:44:08 -070054
55 return 0;
Simon Glasse961a662016-07-04 11:57:51 -060056}
Simon Glass3f2f5cf2019-05-18 11:59:45 -060057SPL_LOAD_IMAGE_METHOD("sandbox", 9, BOOT_DEVICE_BOARD, spl_board_load_image);
Simon Glassa091a8f2016-07-04 11:57:55 -060058
59void spl_board_init(void)
60{
Simon Glass1ca910b2018-11-15 18:44:01 -070061 struct sandbox_state *state = state_get_current();
Simon Glass1ca910b2018-11-15 18:44:01 -070062
Simon Glassa091a8f2016-07-04 11:57:55 -060063 preloader_console_init();
Simon Glassb25ff5c2020-10-25 20:38:28 -060064
65 if (state->run_unittests) {
66 int ret;
67
Simon Glass409f4a22021-03-07 17:34:46 -070068 ret = dm_test_run(state->select_unittests);
Simon Glassb25ff5c2020-10-25 20:38:28 -060069 /* continue execution into U-Boot */
70 }
Simon Glassa091a8f2016-07-04 11:57:55 -060071}
Simon Glass27028f12018-11-15 18:44:08 -070072
73void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
74{
75 const char *fname = spl_image->arg;
76
Simon Glass12efc932018-11-23 21:29:25 -070077 if (fname) {
78 os_fd_restore();
79 os_spl_to_uboot(fname);
80 } else {
81 printf("No filename provided for U-Boot\n");
82 }
Simon Glass27028f12018-11-15 18:44:08 -070083 hang();
84}
Simon Glass366291a2019-09-25 08:11:18 -060085
86int handoff_arch_save(struct spl_handoff *ho)
87{
88 ho->arch.magic = TEST_HANDOFF_MAGIC;
89
90 return 0;
91}