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