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> |
| 8 | #include <os.h> |
Simon Glass | a091a8f | 2016-07-04 11:57:55 -0600 | [diff] [blame] | 9 | #include <spl.h> |
Simon Glass | e961a66 | 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 | |
| 15 | void board_init_f(ulong flag) |
| 16 | { |
| 17 | struct sandbox_state *state = state_get_current(); |
| 18 | |
| 19 | gd->arch.ram_buf = state->ram_buf; |
| 20 | gd->ram_size = state->ram_size; |
| 21 | } |
| 22 | |
| 23 | u32 spl_boot_device(void) |
| 24 | { |
| 25 | return BOOT_DEVICE_BOARD; |
| 26 | } |
| 27 | |
Simon Glass | 2a2ee2a | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 28 | static int spl_board_load_image(struct spl_image_info *spl_image, |
| 29 | struct spl_boot_device *bootdev) |
Simon Glass | e961a66 | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 30 | { |
| 31 | char fname[256]; |
| 32 | int ret; |
| 33 | |
| 34 | ret = os_find_u_boot(fname, sizeof(fname)); |
Simon Glass | f831b8e | 2016-11-30 15:30:56 -0700 | [diff] [blame] | 35 | if (ret) { |
| 36 | printf("(%s not found, error %d)\n", fname, ret); |
Simon Glass | e961a66 | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 37 | return ret; |
Simon Glass | f831b8e | 2016-11-30 15:30:56 -0700 | [diff] [blame] | 38 | } |
Simon Glass | e961a66 | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 39 | |
Simon Glass | 27028f1 | 2018-11-15 18:44:08 -0700 | [diff] [blame] | 40 | /* Set up spl_image to boot from jump_to_image_no_args() */ |
| 41 | spl_image->arg = strdup(fname); |
| 42 | if (!spl_image->arg) |
| 43 | return log_msg_ret("Setup exec filename", -ENOMEM); |
| 44 | |
| 45 | return 0; |
Simon Glass | e961a66 | 2016-07-04 11:57:51 -0600 | [diff] [blame] | 46 | } |
Simon Glass | ebc4ef6 | 2016-11-30 15:30:50 -0700 | [diff] [blame] | 47 | SPL_LOAD_IMAGE_METHOD("sandbox", 0, BOOT_DEVICE_BOARD, spl_board_load_image); |
Simon Glass | a091a8f | 2016-07-04 11:57:55 -0600 | [diff] [blame] | 48 | |
| 49 | void spl_board_init(void) |
| 50 | { |
Simon Glass | 1ca910b | 2018-11-15 18:44:01 -0700 | [diff] [blame] | 51 | struct sandbox_state *state = state_get_current(); |
| 52 | struct udevice *dev; |
| 53 | |
Simon Glass | a091a8f | 2016-07-04 11:57:55 -0600 | [diff] [blame] | 54 | preloader_console_init(); |
Simon Glass | 1ca910b | 2018-11-15 18:44:01 -0700 | [diff] [blame] | 55 | if (state->show_of_platdata) { |
| 56 | /* |
| 57 | * Scan all the devices so that we can output their platform |
| 58 | * data. See sandbox_spl_probe(). |
| 59 | */ |
| 60 | printf("Scanning misc devices\n"); |
| 61 | for (uclass_first_device(UCLASS_MISC, &dev); |
| 62 | dev; |
| 63 | uclass_next_device(&dev)) |
| 64 | ; |
| 65 | } |
Simon Glass | a091a8f | 2016-07-04 11:57:55 -0600 | [diff] [blame] | 66 | } |
Simon Glass | 27028f1 | 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 | 12efc93 | 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 | 27028f1 | 2018-11-15 18:44:08 -0700 | [diff] [blame] | 78 | hang(); |
| 79 | } |