blob: f82b0d3de16138c88f6b4917a4e8a0f379b0bdf0 [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 Glasse55cc062019-05-18 11:59:46 -060020/* SPL / TPL init function */
Simon Glassa7e2d4d2016-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 Glassee306792016-09-24 18:20:13 -060034static int spl_board_load_image(struct spl_image_info *spl_image,
35 struct spl_boot_device *bootdev)
Simon Glassa7e2d4d2016-07-04 11:57:51 -060036{
37 char fname[256];
38 int ret;
39
Simon Glassb90e4872021-03-07 17:35:13 -070040 ret = os_find_u_boot(fname, sizeof(fname), false);
Simon Glasse8845d22016-11-30 15:30:56 -070041 if (ret) {
42 printf("(%s not found, error %d)\n", fname, ret);
Simon Glassa7e2d4d2016-07-04 11:57:51 -060043 return ret;
Simon Glasse8845d22016-11-30 15:30:56 -070044 }
Simon Glassa7e2d4d2016-07-04 11:57:51 -060045
Simon Glassedd094e2021-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 Glasscca25522018-11-15 18:44:08 -070051 if (!spl_image->arg)
Simon Glassedd094e2021-02-06 09:57:33 -070052 return log_msg_ret("exec", -ENOMEM);
53 strcpy(spl_image->arg, fname);
Simon Glasscca25522018-11-15 18:44:08 -070054
55 return 0;
Simon Glassa7e2d4d2016-07-04 11:57:51 -060056}
Simon Glassfb9128d2019-05-18 11:59:45 -060057SPL_LOAD_IMAGE_METHOD("sandbox", 9, BOOT_DEVICE_BOARD, spl_board_load_image);
Simon Glass4e9c1312016-07-04 11:57:55 -060058
59void spl_board_init(void)
60{
Simon Glassb5dfea82018-11-15 18:44:01 -070061 struct sandbox_state *state = state_get_current();
Simon Glassb5dfea82018-11-15 18:44:01 -070062
Simon Glass4e9c1312016-07-04 11:57:55 -060063 preloader_console_init();
Simon Glassa4e289b2020-10-25 20:38:28 -060064
65 if (state->run_unittests) {
Simon Glass1ef74ab2021-03-07 17:35:12 -070066 struct unit_test *tests = UNIT_TEST_ALL_START();
67 const int count = UNIT_TEST_ALL_COUNT();
Simon Glassa4e289b2020-10-25 20:38:28 -060068 int ret;
69
Simon Glass1ef74ab2021-03-07 17:35:12 -070070 ret = ut_run_list("spl", NULL, tests, count,
71 state->select_unittests);
Simon Glassa4e289b2020-10-25 20:38:28 -060072 /* continue execution into U-Boot */
73 }
Simon Glass4e9c1312016-07-04 11:57:55 -060074}
Simon Glasscca25522018-11-15 18:44:08 -070075
76void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
77{
78 const char *fname = spl_image->arg;
79
Simon Glass38c2eae2018-11-23 21:29:25 -070080 if (fname) {
81 os_fd_restore();
82 os_spl_to_uboot(fname);
83 } else {
84 printf("No filename provided for U-Boot\n");
85 }
Simon Glasscca25522018-11-15 18:44:08 -070086 hang();
87}
Simon Glassc5d27202019-09-25 08:11:18 -060088
89int handoff_arch_save(struct spl_handoff *ho)
90{
91 ho->arch.magic = TEST_HANDOFF_MAGIC;
92
93 return 0;
94}