Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Alexey Brodkin | b628c01 | 2014-02-04 12:56:15 +0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2013-2014 Synopsys, Inc. All rights reserved. |
Alexey Brodkin | b628c01 | 2014-02-04 12:56:15 +0400 | [diff] [blame] | 4 | */ |
| 5 | |
Simon Glass | 1ea9789 | 2020-05-10 11:40:00 -0600 | [diff] [blame] | 6 | #include <bootstage.h> |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 7 | #include <env.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 8 | #include <image.h> |
Simon Glass | 8f3f761 | 2019-11-14 12:57:42 -0700 | [diff] [blame] | 9 | #include <irq_func.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Eugeniy Paltsev | 67fd56a | 2018-03-21 15:59:02 +0300 | [diff] [blame] | 11 | #include <asm/cache.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Alexey Brodkin | b628c01 | 2014-02-04 12:56:15 +0400 | [diff] [blame] | 13 | |
| 14 | DECLARE_GLOBAL_DATA_PTR; |
| 15 | |
Alexey Brodkin | b628c01 | 2014-02-04 12:56:15 +0400 | [diff] [blame] | 16 | static int cleanup_before_linux(void) |
| 17 | { |
| 18 | disable_interrupts(); |
Eugeniy Paltsev | 67fd56a | 2018-03-21 15:59:02 +0300 | [diff] [blame] | 19 | sync_n_cleanup_cache_all(); |
Alexey Brodkin | b628c01 | 2014-02-04 12:56:15 +0400 | [diff] [blame] | 20 | |
| 21 | return 0; |
| 22 | } |
| 23 | |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 24 | __weak int board_prep_linux(struct bootm_headers *images) { return 0; } |
Eugeniy Paltsev | 01f45cc | 2018-03-23 15:35:03 +0300 | [diff] [blame] | 25 | |
Alexey Brodkin | b628c01 | 2014-02-04 12:56:15 +0400 | [diff] [blame] | 26 | /* Subcommand: PREP */ |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 27 | static int boot_prep_linux(struct bootm_headers *images) |
Alexey Brodkin | b628c01 | 2014-02-04 12:56:15 +0400 | [diff] [blame] | 28 | { |
Eugeniy Paltsev | 01f45cc | 2018-03-23 15:35:03 +0300 | [diff] [blame] | 29 | int ret; |
| 30 | |
Simon Glass | ae7ed57 | 2023-02-05 15:40:13 -0700 | [diff] [blame] | 31 | if (IS_ENABLED(CONFIG_LMB)) { |
Ashok Reddy Soma | 8aaae3d | 2022-07-07 10:45:37 +0200 | [diff] [blame] | 32 | ret = image_setup_linux(images); |
| 33 | if (ret) |
| 34 | return ret; |
| 35 | } |
Eugeniy Paltsev | 01f45cc | 2018-03-23 15:35:03 +0300 | [diff] [blame] | 36 | |
| 37 | return board_prep_linux(images); |
Alexey Brodkin | b628c01 | 2014-02-04 12:56:15 +0400 | [diff] [blame] | 38 | } |
| 39 | |
Eugeniy Paltsev | 01f45cc | 2018-03-23 15:35:03 +0300 | [diff] [blame] | 40 | /* Generic implementation for single core CPU */ |
| 41 | __weak void board_jump_and_run(ulong entry, int zero, int arch, uint params) |
| 42 | { |
| 43 | void (*kernel_entry)(int zero, int arch, uint params); |
| 44 | |
| 45 | kernel_entry = (void (*)(int, int, uint))entry; |
| 46 | |
| 47 | kernel_entry(zero, arch, params); |
| 48 | } |
Alexey Brodkin | cf9cafd | 2015-04-13 13:37:05 +0300 | [diff] [blame] | 49 | |
Alexey Brodkin | b628c01 | 2014-02-04 12:56:15 +0400 | [diff] [blame] | 50 | /* Subcommand: GO */ |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 51 | static void boot_jump_linux(struct bootm_headers *images, int flag) |
Alexey Brodkin | b628c01 | 2014-02-04 12:56:15 +0400 | [diff] [blame] | 52 | { |
Eugeniy Paltsev | 01f45cc | 2018-03-23 15:35:03 +0300 | [diff] [blame] | 53 | ulong kernel_entry; |
Alexey Brodkin | b628c01 | 2014-02-04 12:56:15 +0400 | [diff] [blame] | 54 | unsigned int r0, r2; |
| 55 | int fake = (flag & BOOTM_STATE_OS_FAKE_GO); |
| 56 | |
Eugeniy Paltsev | 01f45cc | 2018-03-23 15:35:03 +0300 | [diff] [blame] | 57 | kernel_entry = images->ep; |
Alexey Brodkin | b628c01 | 2014-02-04 12:56:15 +0400 | [diff] [blame] | 58 | |
| 59 | debug("## Transferring control to Linux (at address %08lx)...\n", |
Eugeniy Paltsev | 01f45cc | 2018-03-23 15:35:03 +0300 | [diff] [blame] | 60 | kernel_entry); |
Alexey Brodkin | b628c01 | 2014-02-04 12:56:15 +0400 | [diff] [blame] | 61 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 62 | |
| 63 | printf("\nStarting kernel ...%s\n\n", fake ? |
| 64 | "(fake run for tracing)" : ""); |
| 65 | bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel"); |
| 66 | |
Simon Glass | 85c057e | 2021-09-25 19:43:21 -0600 | [diff] [blame] | 67 | if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) { |
Alexey Brodkin | b628c01 | 2014-02-04 12:56:15 +0400 | [diff] [blame] | 68 | r0 = 2; |
| 69 | r2 = (unsigned int)images->ft_addr; |
| 70 | } else { |
| 71 | r0 = 1; |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 72 | r2 = (unsigned int)env_get("bootargs"); |
Alexey Brodkin | b628c01 | 2014-02-04 12:56:15 +0400 | [diff] [blame] | 73 | } |
| 74 | |
Eugeniy Paltsev | 01f45cc | 2018-03-23 15:35:03 +0300 | [diff] [blame] | 75 | cleanup_before_linux(); |
| 76 | |
| 77 | if (!fake) |
| 78 | board_jump_and_run(kernel_entry, r0, 0, r2); |
Alexey Brodkin | b628c01 | 2014-02-04 12:56:15 +0400 | [diff] [blame] | 79 | } |
| 80 | |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 81 | int do_bootm_linux(int flag, int argc, char *argv[], struct bootm_headers *images) |
Alexey Brodkin | b628c01 | 2014-02-04 12:56:15 +0400 | [diff] [blame] | 82 | { |
| 83 | /* No need for those on ARC */ |
| 84 | if ((flag & BOOTM_STATE_OS_BD_T) || (flag & BOOTM_STATE_OS_CMDLINE)) |
| 85 | return -1; |
| 86 | |
Eugeniy Paltsev | 01f45cc | 2018-03-23 15:35:03 +0300 | [diff] [blame] | 87 | if (flag & BOOTM_STATE_OS_PREP) |
| 88 | return boot_prep_linux(images); |
Alexey Brodkin | b628c01 | 2014-02-04 12:56:15 +0400 | [diff] [blame] | 89 | |
| 90 | if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) { |
| 91 | boot_jump_linux(images, flag); |
| 92 | return 0; |
| 93 | } |
| 94 | |
Eugeniy Paltsev | 01f45cc | 2018-03-23 15:35:03 +0300 | [diff] [blame] | 95 | return -1; |
Alexey Brodkin | b628c01 | 2014-02-04 12:56:15 +0400 | [diff] [blame] | 96 | } |