Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 2 | /* |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 3 | * (C) Copyright 2007 Michal Simek |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 4 | * (C) Copyright 2004 Atmark Techno, Inc. |
| 5 | * |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 6 | * Michal SIMEK <monstr@monstr.eu> |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 7 | * Yasushi SHOJI <yashi@atmark-techno.com> |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Simon Glass | 1ea9789 | 2020-05-10 11:40:00 -0600 | [diff] [blame] | 11 | #include <bootstage.h> |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 12 | #include <command.h> |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 13 | #include <cpu_func.h> |
Simon Glass | 0af6e2d | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 14 | #include <env.h> |
Simon Glass | e3ee2fb | 2016-02-22 22:55:43 -0700 | [diff] [blame] | 15 | #include <fdt_support.h> |
Simon Glass | f11478f | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 16 | #include <hang.h> |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 17 | #include <image.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 18 | #include <lmb.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 19 | #include <log.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 20 | #include <asm/cache.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 21 | #include <asm/global_data.h> |
Jean-Christophe PLAGNIOL-VILLARD | 6bb9449 | 2009-04-04 12:49:11 +0200 | [diff] [blame] | 22 | #include <u-boot/zlib.h> |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 23 | #include <asm/byteorder.h> |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 24 | |
Michal Simek | 040872e | 2019-09-25 10:45:51 +0200 | [diff] [blame] | 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 | { |
Marek Vasut | d0dd68f | 2021-09-10 22:47:10 +0200 | [diff] [blame] | 37 | arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 4096); |
Michal Simek | 040872e | 2019-09-25 10:45:51 +0200 | [diff] [blame] | 38 | } |
| 39 | |
Michal Simek | e37afb5 | 2019-09-25 09:47:02 +0200 | [diff] [blame] | 40 | static void boot_jump_linux(bootm_headers_t *images, int flag) |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 41 | { |
Michal Simek | e37afb5 | 2019-09-25 09:47:02 +0200 | [diff] [blame] | 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); |
Arun Bhanu | 2304c05 | 2010-04-15 18:27:17 +0800 | [diff] [blame] | 47 | |
Michal Simek | c78ce29 | 2013-05-02 12:51:48 +0200 | [diff] [blame] | 48 | thekernel = (void (*)(char *, ulong, ulong))images->ep; |
Arun Bhanu | 2304c05 | 2010-04-15 18:27:17 +0800 | [diff] [blame] | 49 | |
Michal Simek | 1facc8f | 2019-10-17 13:16:56 +0200 | [diff] [blame] | 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"); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 59 | |
Michal Simek | 80c42c7 | 2010-04-16 12:01:32 +0200 | [diff] [blame] | 60 | #ifdef XILINX_USE_DCACHE |
Michal Simek | 80c42c7 | 2010-04-16 12:01:32 +0200 | [diff] [blame] | 61 | flush_cache(0, XILINX_DCACHE_BYTE_SIZE); |
Michal Simek | 80c42c7 | 2010-04-16 12:01:32 +0200 | [diff] [blame] | 62 | #endif |
Michal Simek | e37afb5 | 2019-09-25 09:47:02 +0200 | [diff] [blame] | 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 | { |
Simon Glass | 85c057e | 2021-09-25 19:43:21 -0600 | [diff] [blame] | 78 | if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) { |
Michal Simek | 4bbe2ac | 2019-10-17 14:12:48 +0200 | [diff] [blame] | 79 | debug("using: FDT\n"); |
Michal Simek | e37afb5 | 2019-09-25 09:47:02 +0200 | [diff] [blame] | 80 | if (image_setup_linux(images)) { |
| 81 | printf("FDT creation failed! hanging..."); |
| 82 | hang(); |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 87 | int do_bootm_linux(int flag, int argc, char *const argv[], |
Michal Simek | e37afb5 | 2019-09-25 09:47:02 +0200 | [diff] [blame] | 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 | } |
Jean-Christophe PLAGNIOL-VILLARD | 7ed7a27 | 2008-09-10 22:48:09 +0200 | [diff] [blame] | 105 | |
Michal Simek | e37afb5 | 2019-09-25 09:47:02 +0200 | [diff] [blame] | 106 | boot_prep_linux(images); |
| 107 | boot_jump_linux(images, flag); |
Kumar Gala | 48626aa | 2008-08-15 08:24:45 -0500 | [diff] [blame] | 108 | return 1; |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 109 | } |