blob: 9a77da15619c160d43ea3f41ca43c6814b59b8b4 [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 Glassa7e2d4d2016-07-04 11:57:51 -060013#include <asm/spl.h>
14#include <asm/state.h>
Simon Glassa4e289b2020-10-25 20:38:28 -060015#include <test/test.h>
Simon Glassa7e2d4d2016-07-04 11:57:51 -060016
17DECLARE_GLOBAL_DATA_PTR;
18
Simon Glasse55cc062019-05-18 11:59:46 -060019/* SPL / TPL init function */
Simon Glassa7e2d4d2016-07-04 11:57:51 -060020void board_init_f(ulong flag)
21{
22 struct sandbox_state *state = state_get_current();
23
24 gd->arch.ram_buf = state->ram_buf;
25 gd->ram_size = state->ram_size;
26}
27
28u32 spl_boot_device(void)
29{
30 return BOOT_DEVICE_BOARD;
31}
32
Simon Glassee306792016-09-24 18:20:13 -060033static int spl_board_load_image(struct spl_image_info *spl_image,
34 struct spl_boot_device *bootdev)
Simon Glassa7e2d4d2016-07-04 11:57:51 -060035{
36 char fname[256];
37 int ret;
38
39 ret = os_find_u_boot(fname, sizeof(fname));
Simon Glasse8845d22016-11-30 15:30:56 -070040 if (ret) {
41 printf("(%s not found, error %d)\n", fname, ret);
Simon Glassa7e2d4d2016-07-04 11:57:51 -060042 return ret;
Simon Glasse8845d22016-11-30 15:30:56 -070043 }
Simon Glassa7e2d4d2016-07-04 11:57:51 -060044
Simon Glasscca25522018-11-15 18:44:08 -070045 /* Set up spl_image to boot from jump_to_image_no_args() */
46 spl_image->arg = strdup(fname);
47 if (!spl_image->arg)
48 return log_msg_ret("Setup exec filename", -ENOMEM);
49
50 return 0;
Simon Glassa7e2d4d2016-07-04 11:57:51 -060051}
Simon Glassfb9128d2019-05-18 11:59:45 -060052SPL_LOAD_IMAGE_METHOD("sandbox", 9, BOOT_DEVICE_BOARD, spl_board_load_image);
Simon Glass4e9c1312016-07-04 11:57:55 -060053
54void spl_board_init(void)
55{
Simon Glassb5dfea82018-11-15 18:44:01 -070056 struct sandbox_state *state = state_get_current();
Simon Glassb5dfea82018-11-15 18:44:01 -070057
Simon Glass4e9c1312016-07-04 11:57:55 -060058 preloader_console_init();
Simon Glassa4e289b2020-10-25 20:38:28 -060059
60 if (state->run_unittests) {
61 int ret;
62
Simon Glasseff96582020-10-25 20:38:33 -060063 ret = dm_test_main(state->select_unittests);
Simon Glassa4e289b2020-10-25 20:38:28 -060064 /* continue execution into U-Boot */
65 }
Simon Glass4e9c1312016-07-04 11:57:55 -060066}
Simon Glasscca25522018-11-15 18:44:08 -070067
68void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
69{
70 const char *fname = spl_image->arg;
71
Simon Glass38c2eae2018-11-23 21:29:25 -070072 if (fname) {
73 os_fd_restore();
74 os_spl_to_uboot(fname);
75 } else {
76 printf("No filename provided for U-Boot\n");
77 }
Simon Glasscca25522018-11-15 18:44:08 -070078 hang();
79}
Simon Glassc5d27202019-09-25 08:11:18 -060080
81int handoff_arch_save(struct spl_handoff *ho)
82{
83 ho->arch.magic = TEST_HANDOFF_MAGIC;
84
85 return 0;
86}