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