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 | e55cc06 | 2019-05-18 11:59:46 -0600 | [diff] [blame] | 20 | /* SPL / TPL init function */ |
Simon Glass | a7e2d4d | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 21 | void 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 | |
| 29 | u32 spl_boot_device(void) |
| 30 | { |
| 31 | return BOOT_DEVICE_BOARD; |
| 32 | } |
| 33 | |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 34 | static int spl_board_load_image(struct spl_image_info *spl_image, |
| 35 | struct spl_boot_device *bootdev) |
Simon Glass | a7e2d4d | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 36 | { |
| 37 | char fname[256]; |
| 38 | int ret; |
| 39 | |
Simon Glass | b90e487 | 2021-03-07 17:35:13 -0700 | [diff] [blame] | 40 | ret = os_find_u_boot(fname, sizeof(fname), false); |
Simon Glass | e8845d2 | 2016-11-30 15:30:56 -0700 | [diff] [blame] | 41 | if (ret) { |
| 42 | printf("(%s not found, error %d)\n", fname, ret); |
Simon Glass | a7e2d4d | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 43 | return ret; |
Simon Glass | e8845d2 | 2016-11-30 15:30:56 -0700 | [diff] [blame] | 44 | } |
Simon Glass | a7e2d4d | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 45 | |
Simon Glass | edd094e | 2021-02-06 09:57:33 -0700 | [diff] [blame] | 46 | /* |
| 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 Glass | cca2552 | 2018-11-15 18:44:08 -0700 | [diff] [blame] | 51 | if (!spl_image->arg) |
Simon Glass | edd094e | 2021-02-06 09:57:33 -0700 | [diff] [blame] | 52 | return log_msg_ret("exec", -ENOMEM); |
| 53 | strcpy(spl_image->arg, fname); |
Simon Glass | cca2552 | 2018-11-15 18:44:08 -0700 | [diff] [blame] | 54 | |
| 55 | return 0; |
Simon Glass | a7e2d4d | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 56 | } |
Simon Glass | fb9128d | 2019-05-18 11:59:45 -0600 | [diff] [blame] | 57 | 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] | 58 | |
| 59 | void spl_board_init(void) |
| 60 | { |
Simon Glass | b5dfea8 | 2018-11-15 18:44:01 -0700 | [diff] [blame] | 61 | struct sandbox_state *state = state_get_current(); |
Simon Glass | b5dfea8 | 2018-11-15 18:44:01 -0700 | [diff] [blame] | 62 | |
Simon Glass | 4e9c131 | 2016-07-04 11:57:55 -0600 | [diff] [blame] | 63 | preloader_console_init(); |
Simon Glass | a4e289b | 2020-10-25 20:38:28 -0600 | [diff] [blame] | 64 | |
| 65 | if (state->run_unittests) { |
Simon Glass | 1ef74ab | 2021-03-07 17:35:12 -0700 | [diff] [blame] | 66 | struct unit_test *tests = UNIT_TEST_ALL_START(); |
| 67 | const int count = UNIT_TEST_ALL_COUNT(); |
Simon Glass | a4e289b | 2020-10-25 20:38:28 -0600 | [diff] [blame] | 68 | int ret; |
| 69 | |
Simon Glass | 1ef74ab | 2021-03-07 17:35:12 -0700 | [diff] [blame] | 70 | ret = ut_run_list("spl", NULL, tests, count, |
| 71 | state->select_unittests); |
Simon Glass | a4e289b | 2020-10-25 20:38:28 -0600 | [diff] [blame] | 72 | /* continue execution into U-Boot */ |
| 73 | } |
Simon Glass | 4e9c131 | 2016-07-04 11:57:55 -0600 | [diff] [blame] | 74 | } |
Simon Glass | cca2552 | 2018-11-15 18:44:08 -0700 | [diff] [blame] | 75 | |
| 76 | void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) |
| 77 | { |
| 78 | const char *fname = spl_image->arg; |
| 79 | |
Simon Glass | 38c2eae | 2018-11-23 21:29:25 -0700 | [diff] [blame] | 80 | 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 Glass | cca2552 | 2018-11-15 18:44:08 -0700 | [diff] [blame] | 86 | hang(); |
| 87 | } |
Simon Glass | c5d2720 | 2019-09-25 08:11:18 -0600 | [diff] [blame] | 88 | |
| 89 | int handoff_arch_save(struct spl_handoff *ho) |
| 90 | { |
| 91 | ho->arch.magic = TEST_HANDOFF_MAGIC; |
| 92 | |
| 93 | return 0; |
| 94 | } |