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 | a7e2d4d | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 13 | #include <asm/spl.h> |
| 14 | #include <asm/state.h> |
Simon Glass | a4e289b | 2020-10-25 20:38:28 -0600 | [diff] [blame] | 15 | #include <test/test.h> |
Simon Glass | a7e2d4d | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 16 | |
| 17 | DECLARE_GLOBAL_DATA_PTR; |
| 18 | |
Simon Glass | e55cc06 | 2019-05-18 11:59:46 -0600 | [diff] [blame] | 19 | /* SPL / TPL init function */ |
Simon Glass | a7e2d4d | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 20 | void board_init_f(ulong flag) |
| 21 | { |
| 22 | struct sandbox_state *state = state_get_current(); |
| 23 | |
| 24 | gd->arch.ram_buf = state->ram_buf; |
| 25 | gd->ram_size = state->ram_size; |
| 26 | } |
| 27 | |
| 28 | u32 spl_boot_device(void) |
| 29 | { |
| 30 | return BOOT_DEVICE_BOARD; |
| 31 | } |
| 32 | |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 33 | static int spl_board_load_image(struct spl_image_info *spl_image, |
| 34 | struct spl_boot_device *bootdev) |
Simon Glass | a7e2d4d | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 35 | { |
| 36 | char fname[256]; |
| 37 | int ret; |
| 38 | |
| 39 | ret = os_find_u_boot(fname, sizeof(fname)); |
Simon Glass | e8845d2 | 2016-11-30 15:30:56 -0700 | [diff] [blame] | 40 | if (ret) { |
| 41 | printf("(%s not found, error %d)\n", fname, ret); |
Simon Glass | a7e2d4d | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 42 | return ret; |
Simon Glass | e8845d2 | 2016-11-30 15:30:56 -0700 | [diff] [blame] | 43 | } |
Simon Glass | a7e2d4d | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 44 | |
Simon Glass | cca2552 | 2018-11-15 18:44:08 -0700 | [diff] [blame] | 45 | /* Set up spl_image to boot from jump_to_image_no_args() */ |
| 46 | spl_image->arg = strdup(fname); |
| 47 | if (!spl_image->arg) |
| 48 | return log_msg_ret("Setup exec filename", -ENOMEM); |
| 49 | |
| 50 | return 0; |
Simon Glass | a7e2d4d | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 51 | } |
Simon Glass | fb9128d | 2019-05-18 11:59:45 -0600 | [diff] [blame] | 52 | 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] | 53 | |
| 54 | void spl_board_init(void) |
| 55 | { |
Simon Glass | b5dfea8 | 2018-11-15 18:44:01 -0700 | [diff] [blame] | 56 | struct sandbox_state *state = state_get_current(); |
Simon Glass | b5dfea8 | 2018-11-15 18:44:01 -0700 | [diff] [blame] | 57 | |
Simon Glass | 4e9c131 | 2016-07-04 11:57:55 -0600 | [diff] [blame] | 58 | preloader_console_init(); |
Simon Glass | a4e289b | 2020-10-25 20:38:28 -0600 | [diff] [blame] | 59 | |
| 60 | if (state->run_unittests) { |
| 61 | int ret; |
| 62 | |
Simon Glass | eff9658 | 2020-10-25 20:38:33 -0600 | [diff] [blame] | 63 | ret = dm_test_main(state->select_unittests); |
Simon Glass | a4e289b | 2020-10-25 20:38:28 -0600 | [diff] [blame] | 64 | /* continue execution into U-Boot */ |
| 65 | } |
Simon Glass | 4e9c131 | 2016-07-04 11:57:55 -0600 | [diff] [blame] | 66 | } |
Simon Glass | cca2552 | 2018-11-15 18:44:08 -0700 | [diff] [blame] | 67 | |
| 68 | void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image) |
| 69 | { |
| 70 | const char *fname = spl_image->arg; |
| 71 | |
Simon Glass | 38c2eae | 2018-11-23 21:29:25 -0700 | [diff] [blame] | 72 | if (fname) { |
| 73 | os_fd_restore(); |
| 74 | os_spl_to_uboot(fname); |
| 75 | } else { |
| 76 | printf("No filename provided for U-Boot\n"); |
| 77 | } |
Simon Glass | cca2552 | 2018-11-15 18:44:08 -0700 | [diff] [blame] | 78 | hang(); |
| 79 | } |
Simon Glass | c5d2720 | 2019-09-25 08:11:18 -0600 | [diff] [blame] | 80 | |
| 81 | int handoff_arch_save(struct spl_handoff *ho) |
| 82 | { |
| 83 | ho->arch.magic = TEST_HANDOFF_MAGIC; |
| 84 | |
| 85 | return 0; |
| 86 | } |