xref: /openbmc/u-boot/arch/sandbox/cpu/spl.c (revision 2a055ea53260ac8addeeb94eb671172844bc9106)
183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2e961a66dSSimon Glass /*
3e961a66dSSimon Glass  * Copyright (c) 2016 Google, Inc
4e961a66dSSimon Glass  */
5e961a66dSSimon Glass 
6e961a66dSSimon Glass #include <common.h>
7e961a66dSSimon Glass #include <dm.h>
8e961a66dSSimon Glass #include <os.h>
9a091a8f0SSimon Glass #include <spl.h>
10e961a66dSSimon Glass #include <asm/spl.h>
11e961a66dSSimon Glass #include <asm/state.h>
12e961a66dSSimon Glass 
13e961a66dSSimon Glass DECLARE_GLOBAL_DATA_PTR;
14e961a66dSSimon Glass 
board_init_f(ulong flag)15e961a66dSSimon Glass void board_init_f(ulong flag)
16e961a66dSSimon Glass {
17e961a66dSSimon Glass 	struct sandbox_state *state = state_get_current();
18e961a66dSSimon Glass 
19e961a66dSSimon Glass 	gd->arch.ram_buf = state->ram_buf;
20e961a66dSSimon Glass 	gd->ram_size = state->ram_size;
21e961a66dSSimon Glass }
22e961a66dSSimon Glass 
spl_boot_device(void)23e961a66dSSimon Glass u32 spl_boot_device(void)
24e961a66dSSimon Glass {
25e961a66dSSimon Glass 	return BOOT_DEVICE_BOARD;
26e961a66dSSimon Glass }
27e961a66dSSimon Glass 
spl_board_load_image(struct spl_image_info * spl_image,struct spl_boot_device * bootdev)282a2ee2acSSimon Glass static int spl_board_load_image(struct spl_image_info *spl_image,
292a2ee2acSSimon Glass 				struct spl_boot_device *bootdev)
30e961a66dSSimon Glass {
31e961a66dSSimon Glass 	char fname[256];
32e961a66dSSimon Glass 	int ret;
33e961a66dSSimon Glass 
34e961a66dSSimon Glass 	ret = os_find_u_boot(fname, sizeof(fname));
35f831b8e4SSimon Glass 	if (ret) {
36f831b8e4SSimon Glass 		printf("(%s not found, error %d)\n", fname, ret);
37e961a66dSSimon Glass 		return ret;
38f831b8e4SSimon Glass 	}
39e961a66dSSimon Glass 
4027028f18SSimon Glass 	/* Set up spl_image to boot from jump_to_image_no_args() */
4127028f18SSimon Glass 	spl_image->arg = strdup(fname);
4227028f18SSimon Glass 	if (!spl_image->arg)
4327028f18SSimon Glass 		return log_msg_ret("Setup exec filename", -ENOMEM);
4427028f18SSimon Glass 
4527028f18SSimon Glass 	return 0;
46e961a66dSSimon Glass }
47ebc4ef61SSimon Glass SPL_LOAD_IMAGE_METHOD("sandbox", 0, BOOT_DEVICE_BOARD, spl_board_load_image);
48a091a8f0SSimon Glass 
spl_board_init(void)49a091a8f0SSimon Glass void spl_board_init(void)
50a091a8f0SSimon Glass {
511ca910beSSimon Glass 	struct sandbox_state *state = state_get_current();
521ca910beSSimon Glass 	struct udevice *dev;
531ca910beSSimon Glass 
54a091a8f0SSimon Glass 	preloader_console_init();
551ca910beSSimon Glass 	if (state->show_of_platdata) {
561ca910beSSimon Glass 		/*
571ca910beSSimon Glass 		 * Scan all the devices so that we can output their platform
581ca910beSSimon Glass 		 * data. See sandbox_spl_probe().
591ca910beSSimon Glass 		 */
601ca910beSSimon Glass 		printf("Scanning misc devices\n");
611ca910beSSimon Glass 		for (uclass_first_device(UCLASS_MISC, &dev);
621ca910beSSimon Glass 		     dev;
631ca910beSSimon Glass 		     uclass_next_device(&dev))
641ca910beSSimon Glass 			;
651ca910beSSimon Glass 	}
66a091a8f0SSimon Glass }
6727028f18SSimon Glass 
jump_to_image_no_args(struct spl_image_info * spl_image)6827028f18SSimon Glass void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
6927028f18SSimon Glass {
7027028f18SSimon Glass 	const char *fname = spl_image->arg;
7127028f18SSimon Glass 
72*12efc933SSimon Glass 	if (fname) {
7327028f18SSimon Glass 		os_fd_restore();
7427028f18SSimon Glass 		os_spl_to_uboot(fname);
75*12efc933SSimon Glass 	} else {
76*12efc933SSimon Glass 		printf("No filename provided for U-Boot\n");
77*12efc933SSimon Glass 	}
7827028f18SSimon Glass 	hang();
7927028f18SSimon Glass }
80