blob: 3779d58c3fec953f71b6c00e94517902fbf7766e [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 Glassa4e289b2020-10-25 20:38:28 -060016#include <test/test.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
40 ret = os_find_u_boot(fname, sizeof(fname));
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) {
66 int ret;
67
Simon Glassa1add9d2021-03-07 17:34:46 -070068 ret = dm_test_run(state->select_unittests);
Simon Glassa4e289b2020-10-25 20:38:28 -060069 /* continue execution into U-Boot */
70 }
Simon Glass4e9c1312016-07-04 11:57:55 -060071}
Simon Glasscca25522018-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 Glass38c2eae2018-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 Glasscca25522018-11-15 18:44:08 -070083 hang();
84}
Simon Glassc5d27202019-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}