Merge tag 'u-boot-imx-20211020' of https://source.denx.de/u-boot/custodians/u-boot-imx
[platform/kernel/u-boot.git] / arch / microblaze / lib / bootm.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2007 Michal Simek
4  * (C) Copyright 2004 Atmark Techno, Inc.
5  *
6  * Michal  SIMEK <monstr@monstr.eu>
7  * Yasushi SHOJI <yashi@atmark-techno.com>
8  */
9
10 #include <common.h>
11 #include <bootstage.h>
12 #include <command.h>
13 #include <cpu_func.h>
14 #include <env.h>
15 #include <fdt_support.h>
16 #include <hang.h>
17 #include <image.h>
18 #include <lmb.h>
19 #include <log.h>
20 #include <asm/cache.h>
21 #include <asm/global_data.h>
22 #include <u-boot/zlib.h>
23 #include <asm/byteorder.h>
24
25 DECLARE_GLOBAL_DATA_PTR;
26
27 static ulong get_sp(void)
28 {
29         ulong ret;
30
31         asm("addik %0, r1, 0" : "=r"(ret) : );
32         return ret;
33 }
34
35 void arch_lmb_reserve(struct lmb *lmb)
36 {
37         arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 4096);
38 }
39
40 static void boot_jump_linux(bootm_headers_t *images, int flag)
41 {
42         void (*thekernel)(char *cmdline, ulong rd, ulong dt);
43         ulong dt = (ulong)images->ft_addr;
44         ulong rd_start = images->initrd_start;
45         ulong cmdline = images->cmdline_start;
46         int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
47
48         thekernel = (void (*)(char *, ulong, ulong))images->ep;
49
50         debug("## Transferring control to Linux (at address 0x%08lx) ",
51               (ulong)thekernel);
52         debug("cmdline 0x%08lx, ramdisk 0x%08lx, FDT 0x%08lx...\n",
53               cmdline, rd_start, dt);
54         bootstage_mark(BOOTSTAGE_ID_RUN_OS);
55
56         printf("\nStarting kernel ...%s\n\n", fake ?
57                "(fake run for tracing)" : "");
58         bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
59
60 #ifdef XILINX_USE_DCACHE
61         flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
62 #endif
63
64         if (!fake) {
65                 /*
66                  * Linux Kernel Parameters (passing device tree):
67                  * r5: pointer to command line
68                  * r6: pointer to ramdisk
69                  * r7: pointer to the fdt, followed by the board info data
70                  */
71                 thekernel((char *)cmdline, rd_start, dt);
72                 /* does not return */
73         }
74 }
75
76 static void boot_prep_linux(bootm_headers_t *images)
77 {
78         if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) {
79                 debug("using: FDT\n");
80                 if (image_setup_linux(images)) {
81                         printf("FDT creation failed! hanging...");
82                         hang();
83                 }
84         }
85 }
86
87 int do_bootm_linux(int flag, int argc, char *const argv[],
88                    bootm_headers_t *images)
89 {
90         images->cmdline_start = (ulong)env_get("bootargs");
91
92         /* cmdline init is the part of 'prep' and nothing to do for 'bdt' */
93         if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE)
94                 return -1;
95
96         if (flag & BOOTM_STATE_OS_PREP) {
97                 boot_prep_linux(images);
98                 return 0;
99         }
100
101         if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
102                 boot_jump_linux(images, flag);
103                 return 0;
104         }
105
106         boot_prep_linux(images);
107         boot_jump_linux(images, flag);
108         return 1;
109 }