Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | a7e2d4d | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016 Google, Inc |
Simon Glass | a7e2d4d | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
Simon Glass | f11478f | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 8 | #include <hang.h> |
Simon Glass | 9ee7b73 | 2022-02-28 15:13:46 -0700 | [diff] [blame^] | 9 | #include <handoff.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 10 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Simon Glass | a7e2d4d | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 12 | #include <os.h> |
Simon Glass | 4e9c131 | 2016-07-04 11:57:55 -0600 | [diff] [blame] | 13 | #include <spl.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 14 | #include <asm/global_data.h> |
Simon Glass | a7e2d4d | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 15 | #include <asm/spl.h> |
| 16 | #include <asm/state.h> |
Simon Glass | 1ef74ab | 2021-03-07 17:35:12 -0700 | [diff] [blame] | 17 | #include <test/ut.h> |
Simon Glass | a7e2d4d | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 18 | |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
Simon Glass | 1cd0600 | 2021-07-05 16:32:45 -0600 | [diff] [blame] | 21 | int sandbox_find_next_phase(char *fname, int maxlen, bool use_img) |
| 22 | { |
| 23 | const char *cur_prefix, *next_prefix; |
| 24 | int ret; |
| 25 | |
| 26 | cur_prefix = spl_phase_prefix(spl_phase()); |
| 27 | next_prefix = spl_phase_prefix(spl_next_phase()); |
| 28 | ret = os_find_u_boot(fname, maxlen, use_img, cur_prefix, next_prefix); |
| 29 | if (ret) |
| 30 | return log_msg_ret("find", ret); |
| 31 | |
| 32 | return 0; |
| 33 | } |
| 34 | |
Simon Glass | e55cc06 | 2019-05-18 11:59:46 -0600 | [diff] [blame] | 35 | /* SPL / TPL init function */ |
Simon Glass | a7e2d4d | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 36 | void board_init_f(ulong flag) |
| 37 | { |
| 38 | struct sandbox_state *state = state_get_current(); |
| 39 | |
| 40 | gd->arch.ram_buf = state->ram_buf; |
| 41 | gd->ram_size = state->ram_size; |
| 42 | } |
| 43 | |
| 44 | u32 spl_boot_device(void) |
| 45 | { |
| 46 | return BOOT_DEVICE_BOARD; |
| 47 | } |
| 48 | |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 49 | static int spl_board_load_image(struct spl_image_info *spl_image, |
| 50 | struct spl_boot_device *bootdev) |
Simon Glass | a7e2d4d | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 51 | { |
| 52 | char fname[256]; |
| 53 | int ret; |
| 54 | |
Simon Glass | 1cd0600 | 2021-07-05 16:32:45 -0600 | [diff] [blame] | 55 | ret = sandbox_find_next_phase(fname, sizeof(fname), false); |
Simon Glass | e8845d2 | 2016-11-30 15:30:56 -0700 | [diff] [blame] | 56 | if (ret) { |
| 57 | printf("(%s not found, error %d)\n", fname, ret); |
Simon Glass | a7e2d4d | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 58 | return ret; |
Simon Glass | e8845d2 | 2016-11-30 15:30:56 -0700 | [diff] [blame] | 59 | } |
Simon Glass | a7e2d4d | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 60 | |
Simon Glass | edd094e | 2021-02-06 09:57:33 -0700 | [diff] [blame] | 61 | /* |
| 62 | * Set up spl_image to boot from jump_to_image_no_args(). Allocate this |
| 63 | * outsdide the RAM buffer (i.e. don't use strdup()). |
| 64 | */ |
| 65 | spl_image->arg = os_malloc(strlen(fname) + 1); |
Simon Glass | cca2552 | 2018-11-15 18:44:08 -0700 | [diff] [blame] | 66 | if (!spl_image->arg) |
Simon Glass | edd094e | 2021-02-06 09:57:33 -0700 | [diff] [blame] | 67 | return log_msg_ret("exec", -ENOMEM); |
| 68 | strcpy(spl_image->arg, fname); |
Simon Glass | cca2552 | 2018-11-15 18:44:08 -0700 | [diff] [blame] | 69 | |
| 70 | return 0; |
Simon Glass | a7e2d4d | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 71 | } |
Simon Glass | fb9128d | 2019-05-18 11:59:45 -0600 | [diff] [blame] | 72 | SPL_LOAD_IMAGE_METHOD("sandbox", 9, BOOT_DEVICE_BOARD, spl_board_load_image); |
Simon Glass | 4e9c131 | 2016-07-04 11:57:55 -0600 | [diff] [blame] | 73 | |
| 74 | void spl_board_init(void) |
| 75 | { |
Simon Glass | b5dfea8 | 2018-11-15 18:44:01 -0700 | [diff] [blame] | 76 | struct sandbox_state *state = state_get_current(); |
Simon Glass | b5dfea8 | 2018-11-15 18:44:01 -0700 | [diff] [blame] | 77 | |
Simon Glass | 4e9c131 | 2016-07-04 11:57:55 -0600 | [diff] [blame] | 78 | preloader_console_init(); |
Simon Glass | a4e289b | 2020-10-25 20:38:28 -0600 | [diff] [blame] | 79 | |
| 80 | if (state->run_unittests) { |
Simon Glass | 1ef74ab | 2021-03-07 17:35:12 -0700 | [diff] [blame] | 81 | struct unit_test *tests = UNIT_TEST_ALL_START(); |
| 82 | const int count = UNIT_TEST_ALL_COUNT(); |
Simon Glass | a4e289b | 2020-10-25 20:38:28 -0600 | [diff] [blame] | 83 | int ret; |
| 84 | |
Simon Glass | 1ef74ab | 2021-03-07 17:35:12 -0700 | [diff] [blame] | 85 | ret = ut_run_list("spl", NULL, tests, count, |
| 86 | state->select_unittests); |
Simon Glass | a4e289b | 2020-10-25 20:38:28 -0600 | [diff] [blame] | 87 | /* continue execution into U-Boot */ |
| 88 | } |
Simon Glass | 4e9c131 | 2016-07-04 11:57:55 -0600 | [diff] [blame] | 89 | } |
Simon Glass | cca2552 | 2018-11-15 18:44:08 -0700 | [diff] [blame] | 90 | |
| 91 | void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) |
| 92 | { |
| 93 | const char *fname = spl_image->arg; |
| 94 | |
Simon Glass | 38c2eae | 2018-11-23 21:29:25 -0700 | [diff] [blame] | 95 | if (fname) { |
| 96 | os_fd_restore(); |
| 97 | os_spl_to_uboot(fname); |
| 98 | } else { |
| 99 | printf("No filename provided for U-Boot\n"); |
| 100 | } |
Simon Glass | cca2552 | 2018-11-15 18:44:08 -0700 | [diff] [blame] | 101 | hang(); |
| 102 | } |
Simon Glass | c5d2720 | 2019-09-25 08:11:18 -0600 | [diff] [blame] | 103 | |
| 104 | int handoff_arch_save(struct spl_handoff *ho) |
| 105 | { |
| 106 | ho->arch.magic = TEST_HANDOFF_MAGIC; |
| 107 | |
| 108 | return 0; |
| 109 | } |