Alexey Brodkin | b628c01 | 2014-02-04 12:56:15 +0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013-2014 Synopsys, Inc. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
Eugeniy Paltsev | 67fd56a | 2018-03-21 15:59:02 +0300 | [diff] [blame^] | 7 | #include <asm/cache.h> |
Alexey Brodkin | b628c01 | 2014-02-04 12:56:15 +0400 | [diff] [blame] | 8 | #include <common.h> |
| 9 | |
| 10 | DECLARE_GLOBAL_DATA_PTR; |
| 11 | |
| 12 | static ulong get_sp(void) |
| 13 | { |
| 14 | ulong ret; |
| 15 | |
| 16 | asm("mov %0, sp" : "=r"(ret) : ); |
| 17 | return ret; |
| 18 | } |
| 19 | |
| 20 | void arch_lmb_reserve(struct lmb *lmb) |
| 21 | { |
| 22 | ulong sp; |
| 23 | |
| 24 | /* |
| 25 | * Booting a (Linux) kernel image |
| 26 | * |
| 27 | * Allocate space for command line and board info - the |
| 28 | * address should be as high as possible within the reach of |
| 29 | * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused |
| 30 | * memory, which means far enough below the current stack |
| 31 | * pointer. |
| 32 | */ |
| 33 | sp = get_sp(); |
| 34 | debug("## Current stack ends at 0x%08lx ", sp); |
| 35 | |
| 36 | /* adjust sp by 4K to be safe */ |
| 37 | sp -= 4096; |
| 38 | lmb_reserve(lmb, sp, (CONFIG_SYS_SDRAM_BASE + gd->ram_size - sp)); |
| 39 | } |
| 40 | |
| 41 | static int cleanup_before_linux(void) |
| 42 | { |
| 43 | disable_interrupts(); |
Eugeniy Paltsev | 67fd56a | 2018-03-21 15:59:02 +0300 | [diff] [blame^] | 44 | sync_n_cleanup_cache_all(); |
Alexey Brodkin | b628c01 | 2014-02-04 12:56:15 +0400 | [diff] [blame] | 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | /* Subcommand: PREP */ |
| 50 | static void boot_prep_linux(bootm_headers_t *images) |
| 51 | { |
| 52 | if (image_setup_linux(images)) |
| 53 | hang(); |
| 54 | } |
| 55 | |
Alexey Brodkin | cf9cafd | 2015-04-13 13:37:05 +0300 | [diff] [blame] | 56 | __weak void smp_set_core_boot_addr(unsigned long addr, int corenr) {} |
| 57 | __weak void smp_kick_all_cpus(void) {} |
| 58 | |
Alexey Brodkin | b628c01 | 2014-02-04 12:56:15 +0400 | [diff] [blame] | 59 | /* Subcommand: GO */ |
| 60 | static void boot_jump_linux(bootm_headers_t *images, int flag) |
| 61 | { |
| 62 | void (*kernel_entry)(int zero, int arch, uint params); |
| 63 | unsigned int r0, r2; |
| 64 | int fake = (flag & BOOTM_STATE_OS_FAKE_GO); |
| 65 | |
| 66 | kernel_entry = (void (*)(int, int, uint))images->ep; |
| 67 | |
| 68 | debug("## Transferring control to Linux (at address %08lx)...\n", |
| 69 | (ulong) kernel_entry); |
| 70 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 71 | |
| 72 | printf("\nStarting kernel ...%s\n\n", fake ? |
| 73 | "(fake run for tracing)" : ""); |
| 74 | bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel"); |
| 75 | |
| 76 | cleanup_before_linux(); |
| 77 | |
| 78 | if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) { |
| 79 | r0 = 2; |
| 80 | r2 = (unsigned int)images->ft_addr; |
| 81 | } else { |
| 82 | r0 = 1; |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 83 | r2 = (unsigned int)env_get("bootargs"); |
Alexey Brodkin | b628c01 | 2014-02-04 12:56:15 +0400 | [diff] [blame] | 84 | } |
| 85 | |
Alexey Brodkin | 04e3029 | 2017-11-17 15:53:20 +0300 | [diff] [blame] | 86 | if (!fake) { |
| 87 | smp_set_core_boot_addr((unsigned long)kernel_entry, -1); |
| 88 | smp_kick_all_cpus(); |
Alexey Brodkin | b628c01 | 2014-02-04 12:56:15 +0400 | [diff] [blame] | 89 | kernel_entry(r0, 0, r2); |
Alexey Brodkin | 04e3029 | 2017-11-17 15:53:20 +0300 | [diff] [blame] | 90 | } |
Alexey Brodkin | b628c01 | 2014-02-04 12:56:15 +0400 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images) |
| 94 | { |
| 95 | /* No need for those on ARC */ |
| 96 | if ((flag & BOOTM_STATE_OS_BD_T) || (flag & BOOTM_STATE_OS_CMDLINE)) |
| 97 | return -1; |
| 98 | |
| 99 | if (flag & BOOTM_STATE_OS_PREP) { |
| 100 | boot_prep_linux(images); |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) { |
| 105 | boot_jump_linux(images, flag); |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | boot_prep_linux(images); |
| 110 | boot_jump_linux(images, flag); |
| 111 | return 0; |
| 112 | } |