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 | |
| 10 | #include <common.h> |
| 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> |
Jean-Christophe PLAGNIOL-VILLARD | a31e091 | 2009-04-04 12:49:11 +0200 | [diff] [blame] | 17 | #include <u-boot/zlib.h> |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 18 | #include <asm/byteorder.h> |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 19 | |
Michal Simek | 6131a36 | 2019-09-25 10:45:51 +0200 | [diff] [blame] | 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
| 22 | static ulong get_sp(void) |
| 23 | { |
| 24 | ulong ret; |
| 25 | |
| 26 | asm("addik %0, r1, 0" : "=r"(ret) : ); |
| 27 | return ret; |
| 28 | } |
| 29 | |
| 30 | void arch_lmb_reserve(struct lmb *lmb) |
| 31 | { |
| 32 | ulong sp, bank_end; |
| 33 | int bank; |
| 34 | |
| 35 | /* |
| 36 | * Booting a (Linux) kernel image |
| 37 | * |
| 38 | * Allocate space for command line and board info - the |
| 39 | * address should be as high as possible within the reach of |
| 40 | * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused |
| 41 | * memory, which means far enough below the current stack |
| 42 | * pointer. |
| 43 | */ |
| 44 | sp = get_sp(); |
| 45 | debug("## Current stack ends at 0x%08lx ", sp); |
| 46 | |
| 47 | /* adjust sp by 4K to be safe */ |
| 48 | sp -= 4096; |
| 49 | for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) { |
| 50 | if (sp < gd->bd->bi_dram[bank].start) |
| 51 | continue; |
| 52 | bank_end = gd->bd->bi_dram[bank].start + |
| 53 | gd->bd->bi_dram[bank].size; |
| 54 | if (sp >= bank_end) |
| 55 | continue; |
| 56 | lmb_reserve(lmb, sp, bank_end - sp); |
| 57 | break; |
| 58 | } |
| 59 | } |
| 60 | |
Michal Simek | 0905046 | 2019-09-25 09:47:02 +0200 | [diff] [blame] | 61 | static void boot_jump_linux(bootm_headers_t *images, int flag) |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 62 | { |
Michal Simek | 0905046 | 2019-09-25 09:47:02 +0200 | [diff] [blame] | 63 | void (*thekernel)(char *cmdline, ulong rd, ulong dt); |
| 64 | ulong dt = (ulong)images->ft_addr; |
| 65 | ulong rd_start = images->initrd_start; |
| 66 | ulong cmdline = images->cmdline_start; |
| 67 | int fake = (flag & BOOTM_STATE_OS_FAKE_GO); |
Arun Bhanu | 398b1d5 | 2010-04-15 18:27:17 +0800 | [diff] [blame] | 68 | |
Michal Simek | 1e71fa4 | 2013-05-02 12:51:48 +0200 | [diff] [blame] | 69 | thekernel = (void (*)(char *, ulong, ulong))images->ep; |
Arun Bhanu | 398b1d5 | 2010-04-15 18:27:17 +0800 | [diff] [blame] | 70 | |
Michal Simek | f3035cf | 2019-10-17 13:16:56 +0200 | [diff] [blame] | 71 | debug("## Transferring control to Linux (at address 0x%08lx) ", |
| 72 | (ulong)thekernel); |
| 73 | debug("cmdline 0x%08lx, ramdisk 0x%08lx, FDT 0x%08lx...\n", |
| 74 | cmdline, rd_start, dt); |
| 75 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 76 | |
| 77 | printf("\nStarting kernel ...%s\n\n", fake ? |
| 78 | "(fake run for tracing)" : ""); |
| 79 | bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel"); |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 80 | |
Michal Simek | 9b4d905 | 2010-04-16 12:01:32 +0200 | [diff] [blame] | 81 | #ifdef XILINX_USE_DCACHE |
Michal Simek | 9b4d905 | 2010-04-16 12:01:32 +0200 | [diff] [blame] | 82 | flush_cache(0, XILINX_DCACHE_BYTE_SIZE); |
Michal Simek | 9b4d905 | 2010-04-16 12:01:32 +0200 | [diff] [blame] | 83 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | a3a08c0 | 2008-09-10 22:48:09 +0200 | [diff] [blame] | 84 | |
Michal Simek | 0905046 | 2019-09-25 09:47:02 +0200 | [diff] [blame] | 85 | if (!fake) { |
| 86 | /* |
| 87 | * Linux Kernel Parameters (passing device tree): |
| 88 | * r5: pointer to command line |
| 89 | * r6: pointer to ramdisk |
| 90 | * r7: pointer to the fdt, followed by the board info data |
| 91 | */ |
| 92 | thekernel((char *)cmdline, rd_start, dt); |
| 93 | /* does not return */ |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | static void boot_prep_linux(bootm_headers_t *images) |
| 98 | { |
| 99 | if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) { |
Michal Simek | 4ab8d63 | 2019-10-17 14:12:48 +0200 | [diff] [blame] | 100 | debug("using: FDT\n"); |
Michal Simek | 0905046 | 2019-09-25 09:47:02 +0200 | [diff] [blame] | 101 | if (image_setup_linux(images)) { |
| 102 | printf("FDT creation failed! hanging..."); |
| 103 | hang(); |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | int do_bootm_linux(int flag, int argc, char * const argv[], |
| 109 | bootm_headers_t *images) |
| 110 | { |
| 111 | images->cmdline_start = (ulong)env_get("bootargs"); |
| 112 | |
| 113 | /* cmdline init is the part of 'prep' and nothing to do for 'bdt' */ |
| 114 | if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE) |
| 115 | return -1; |
| 116 | |
| 117 | if (flag & BOOTM_STATE_OS_PREP) { |
| 118 | boot_prep_linux(images); |
| 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) { |
| 123 | boot_jump_linux(images, flag); |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | boot_prep_linux(images); |
| 128 | boot_jump_linux(images, flag); |
Kumar Gala | 40d7e99 | 2008-08-15 08:24:45 -0500 | [diff] [blame] | 129 | return 1; |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 130 | } |