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