Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 2 | /* |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 3 | * (C) Copyright 2007 Michal Simek |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 4 | * (C) Copyright 2004 Atmark Techno, Inc. |
| 5 | * |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 6 | * Michal SIMEK <monstr@monstr.eu> |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 7 | * Yasushi SHOJI <yashi@atmark-techno.com> |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
Simon Glass | 52f2423 | 2020-05-10 11:40:00 -0600 | [diff] [blame] | 10 | #include <bootstage.h> |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 11 | #include <command.h> |
Simon Glass | 1eb69ae | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 12 | #include <cpu_func.h> |
Simon Glass | 7b51b57 | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 13 | #include <env.h> |
Simon Glass | 73223f0 | 2016-02-22 22:55:43 -0700 | [diff] [blame] | 14 | #include <fdt_support.h> |
Simon Glass | db41d65 | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 15 | #include <hang.h> |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 16 | #include <image.h> |
Simon Glass | 4d72caa | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 17 | #include <lmb.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 18 | #include <log.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 19 | #include <asm/cache.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 20 | #include <asm/global_data.h> |
Jean-Christophe PLAGNIOL-VILLARD | a31e091 | 2009-04-04 12:49:11 +0200 | [diff] [blame] | 21 | #include <u-boot/zlib.h> |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 22 | #include <asm/byteorder.h> |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 23 | |
Michal Simek | 6131a36 | 2019-09-25 10:45:51 +0200 | [diff] [blame] | 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
| 26 | static ulong get_sp(void) |
| 27 | { |
| 28 | ulong ret; |
| 29 | |
| 30 | asm("addik %0, r1, 0" : "=r"(ret) : ); |
| 31 | return ret; |
| 32 | } |
| 33 | |
| 34 | void arch_lmb_reserve(struct lmb *lmb) |
| 35 | { |
Marek Vasut | 1f391c3 | 2021-09-10 22:47:10 +0200 | [diff] [blame] | 36 | arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 4096); |
Michal Simek | 6131a36 | 2019-09-25 10:45:51 +0200 | [diff] [blame] | 37 | } |
| 38 | |
Simon Glass | d9d7c20 | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 39 | static void boot_jump_linux(struct bootm_headers *images, int flag) |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 40 | { |
Michal Simek | 0905046 | 2019-09-25 09:47:02 +0200 | [diff] [blame] | 41 | void (*thekernel)(char *cmdline, ulong rd, ulong dt); |
| 42 | ulong dt = (ulong)images->ft_addr; |
| 43 | ulong rd_start = images->initrd_start; |
| 44 | ulong cmdline = images->cmdline_start; |
| 45 | int fake = (flag & BOOTM_STATE_OS_FAKE_GO); |
Arun Bhanu | 398b1d5 | 2010-04-15 18:27:17 +0800 | [diff] [blame] | 46 | |
Michal Simek | 1e71fa4 | 2013-05-02 12:51:48 +0200 | [diff] [blame] | 47 | thekernel = (void (*)(char *, ulong, ulong))images->ep; |
Arun Bhanu | 398b1d5 | 2010-04-15 18:27:17 +0800 | [diff] [blame] | 48 | |
Michal Simek | f3035cf | 2019-10-17 13:16:56 +0200 | [diff] [blame] | 49 | debug("## Transferring control to Linux (at address 0x%08lx) ", |
| 50 | (ulong)thekernel); |
| 51 | debug("cmdline 0x%08lx, ramdisk 0x%08lx, FDT 0x%08lx...\n", |
| 52 | cmdline, rd_start, dt); |
| 53 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 54 | |
| 55 | printf("\nStarting kernel ...%s\n\n", fake ? |
| 56 | "(fake run for tracing)" : ""); |
| 57 | bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel"); |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 58 | |
Ovidiu Panait | b195134 | 2022-05-31 21:14:30 +0300 | [diff] [blame] | 59 | flush_cache_all(); |
Jean-Christophe PLAGNIOL-VILLARD | a3a08c0 | 2008-09-10 22:48:09 +0200 | [diff] [blame] | 60 | |
Michal Simek | 0905046 | 2019-09-25 09:47:02 +0200 | [diff] [blame] | 61 | if (!fake) { |
| 62 | /* |
| 63 | * Linux Kernel Parameters (passing device tree): |
| 64 | * r5: pointer to command line |
| 65 | * r6: pointer to ramdisk |
| 66 | * r7: pointer to the fdt, followed by the board info data |
| 67 | */ |
| 68 | thekernel((char *)cmdline, rd_start, dt); |
| 69 | /* does not return */ |
| 70 | } |
| 71 | } |
| 72 | |
Simon Glass | d9d7c20 | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 73 | static void boot_prep_linux(struct bootm_headers *images) |
Michal Simek | 0905046 | 2019-09-25 09:47:02 +0200 | [diff] [blame] | 74 | { |
Simon Glass | 210af54 | 2023-02-05 15:40:13 -0700 | [diff] [blame] | 75 | if (CONFIG_IS_ENABLED(OF_LIBFDT) && IS_ENABLED(CONFIG_LMB) && images->ft_len) { |
Michal Simek | 4ab8d63 | 2019-10-17 14:12:48 +0200 | [diff] [blame] | 76 | debug("using: FDT\n"); |
Michal Simek | 0905046 | 2019-09-25 09:47:02 +0200 | [diff] [blame] | 77 | if (image_setup_linux(images)) { |
| 78 | printf("FDT creation failed! hanging..."); |
| 79 | hang(); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 84 | int do_bootm_linux(int flag, int argc, char *const argv[], |
Simon Glass | d9d7c20 | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 85 | struct bootm_headers *images) |
Michal Simek | 0905046 | 2019-09-25 09:47:02 +0200 | [diff] [blame] | 86 | { |
| 87 | images->cmdline_start = (ulong)env_get("bootargs"); |
| 88 | |
| 89 | /* cmdline init is the part of 'prep' and nothing to do for 'bdt' */ |
| 90 | if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE) |
| 91 | return -1; |
| 92 | |
| 93 | if (flag & BOOTM_STATE_OS_PREP) { |
| 94 | boot_prep_linux(images); |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) { |
| 99 | boot_jump_linux(images, flag); |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | boot_prep_linux(images); |
| 104 | boot_jump_linux(images, flag); |
Kumar Gala | 40d7e99 | 2008-08-15 08:24:45 -0500 | [diff] [blame] | 105 | return 1; |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 106 | } |