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