common: Move hang() to the same header as panic()
[platform/kernel/u-boot.git] / arch / sandbox / cpu / spl.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2016 Google, Inc
4  */
5
6 #include <common.h>
7 #include <dm.h>
8 #include <hang.h>
9 #include <os.h>
10 #include <spl.h>
11 #include <asm/spl.h>
12 #include <asm/state.h>
13
14 DECLARE_GLOBAL_DATA_PTR;
15
16 /* SPL / TPL init function */
17 void board_init_f(ulong flag)
18 {
19         struct sandbox_state *state = state_get_current();
20
21         gd->arch.ram_buf = state->ram_buf;
22         gd->ram_size = state->ram_size;
23 }
24
25 u32 spl_boot_device(void)
26 {
27         return BOOT_DEVICE_BOARD;
28 }
29
30 static int spl_board_load_image(struct spl_image_info *spl_image,
31                                 struct spl_boot_device *bootdev)
32 {
33         char fname[256];
34         int ret;
35
36         ret = os_find_u_boot(fname, sizeof(fname));
37         if (ret) {
38                 printf("(%s not found, error %d)\n", fname, ret);
39                 return ret;
40         }
41
42         /* Set up spl_image to boot from jump_to_image_no_args() */
43         spl_image->arg = strdup(fname);
44         if (!spl_image->arg)
45                 return log_msg_ret("Setup exec filename", -ENOMEM);
46
47         return 0;
48 }
49 SPL_LOAD_IMAGE_METHOD("sandbox", 9, BOOT_DEVICE_BOARD, spl_board_load_image);
50
51 void spl_board_init(void)
52 {
53         struct sandbox_state *state = state_get_current();
54         struct udevice *dev;
55
56         preloader_console_init();
57         if (state->show_of_platdata) {
58                 /*
59                  * Scan all the devices so that we can output their platform
60                  * data. See sandbox_spl_probe().
61                  */
62                 printf("Scanning misc devices\n");
63                 for (uclass_first_device(UCLASS_MISC, &dev);
64                      dev;
65                      uclass_next_device(&dev))
66                         ;
67         }
68 }
69
70 void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
71 {
72         const char *fname = spl_image->arg;
73
74         if (fname) {
75                 os_fd_restore();
76                 os_spl_to_uboot(fname);
77         } else {
78                 printf("No filename provided for U-Boot\n");
79         }
80         hang();
81 }
82
83 int handoff_arch_save(struct spl_handoff *ho)
84 {
85         ho->arch.magic = TEST_HANDOFF_MAGIC;
86
87         return 0;
88 }