Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | e961a66 | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016 Google, Inc |
Simon Glass | e961a66 | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
Simon Glass | db41d65 | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 8 | #include <hang.h> |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 9 | #include <init.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Simon Glass | e961a66 | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 11 | #include <os.h> |
Simon Glass | a091a8f | 2016-07-04 11:57:55 -0600 | [diff] [blame] | 12 | #include <spl.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Simon Glass | e961a66 | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 14 | #include <asm/spl.h> |
| 15 | #include <asm/state.h> |
Simon Glass | b25ff5c | 2020-10-25 20:38:28 -0600 | [diff] [blame] | 16 | #include <test/test.h> |
Simon Glass | e961a66 | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 17 | |
| 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
Simon Glass | 912dcb1 | 2019-05-18 11:59:46 -0600 | [diff] [blame] | 20 | /* SPL / TPL init function */ |
Simon Glass | e961a66 | 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 | 2a2ee2a | 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 | e961a66 | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 36 | { |
| 37 | char fname[256]; |
| 38 | int ret; |
| 39 | |
| 40 | ret = os_find_u_boot(fname, sizeof(fname)); |
Simon Glass | f831b8e | 2016-11-30 15:30:56 -0700 | [diff] [blame] | 41 | if (ret) { |
| 42 | printf("(%s not found, error %d)\n", fname, ret); |
Simon Glass | e961a66 | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 43 | return ret; |
Simon Glass | f831b8e | 2016-11-30 15:30:56 -0700 | [diff] [blame] | 44 | } |
Simon Glass | e961a66 | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 45 | |
Simon Glass | b308d9f | 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 | 27028f1 | 2018-11-15 18:44:08 -0700 | [diff] [blame] | 51 | if (!spl_image->arg) |
Simon Glass | b308d9f | 2021-02-06 09:57:33 -0700 | [diff] [blame] | 52 | return log_msg_ret("exec", -ENOMEM); |
| 53 | strcpy(spl_image->arg, fname); |
Simon Glass | 27028f1 | 2018-11-15 18:44:08 -0700 | [diff] [blame] | 54 | |
| 55 | return 0; |
Simon Glass | e961a66 | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 56 | } |
Simon Glass | 3f2f5cf | 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 | a091a8f | 2016-07-04 11:57:55 -0600 | [diff] [blame] | 58 | |
| 59 | void spl_board_init(void) |
| 60 | { |
Simon Glass | 1ca910b | 2018-11-15 18:44:01 -0700 | [diff] [blame] | 61 | struct sandbox_state *state = state_get_current(); |
Simon Glass | 1ca910b | 2018-11-15 18:44:01 -0700 | [diff] [blame] | 62 | |
Simon Glass | a091a8f | 2016-07-04 11:57:55 -0600 | [diff] [blame] | 63 | preloader_console_init(); |
Simon Glass | b25ff5c | 2020-10-25 20:38:28 -0600 | [diff] [blame] | 64 | |
| 65 | if (state->run_unittests) { |
| 66 | int ret; |
| 67 | |
Simon Glass | 409f4a2 | 2021-03-07 17:34:46 -0700 | [diff] [blame] | 68 | ret = dm_test_run(state->select_unittests); |
Simon Glass | b25ff5c | 2020-10-25 20:38:28 -0600 | [diff] [blame] | 69 | /* continue execution into U-Boot */ |
| 70 | } |
Simon Glass | a091a8f | 2016-07-04 11:57:55 -0600 | [diff] [blame] | 71 | } |
Simon Glass | 27028f1 | 2018-11-15 18:44:08 -0700 | [diff] [blame] | 72 | |
| 73 | void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) |
| 74 | { |
| 75 | const char *fname = spl_image->arg; |
| 76 | |
Simon Glass | 12efc93 | 2018-11-23 21:29:25 -0700 | [diff] [blame] | 77 | 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 Glass | 27028f1 | 2018-11-15 18:44:08 -0700 | [diff] [blame] | 83 | hang(); |
| 84 | } |
Simon Glass | 366291a | 2019-09-25 08:11:18 -0600 | [diff] [blame] | 85 | |
| 86 | int handoff_arch_save(struct spl_handoff *ho) |
| 87 | { |
| 88 | ho->arch.magic = TEST_HANDOFF_MAGIC; |
| 89 | |
| 90 | return 0; |
| 91 | } |