Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2011 Andes Technology Corporation |
| 4 | * Shawn Lin, Andes Technology Corporation <nobuhiro@andestech.com> |
| 5 | * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com> |
| 6 | * Rick Chen, Andes Technology Corporation <rick@andestech.com> |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <command.h> |
Lukas Auer | c3b1a99 | 2018-11-22 11:26:32 +0100 | [diff] [blame] | 11 | #include <dm.h> |
Simon Glass | 807765b | 2019-12-28 10:44:54 -0700 | [diff] [blame] | 12 | #include <fdt_support.h> |
Simon Glass | db41d65 | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 13 | #include <hang.h> |
Lukas Auer | c3b1a99 | 2018-11-22 11:26:32 +0100 | [diff] [blame] | 14 | #include <dm/root.h> |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 15 | #include <image.h> |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 16 | #include <asm/byteorder.h> |
Bin Meng | ed49ba4 | 2018-09-26 06:55:16 -0700 | [diff] [blame] | 17 | #include <asm/csr.h> |
Lukas Auer | f28ad25 | 2019-03-17 19:28:38 +0100 | [diff] [blame] | 18 | #include <asm/smp.h> |
Bin Meng | b1893a9 | 2018-10-15 02:20:59 -0700 | [diff] [blame] | 19 | #include <dm/device.h> |
| 20 | #include <dm/root.h> |
| 21 | #include <u-boot/zlib.h> |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 22 | |
| 23 | DECLARE_GLOBAL_DATA_PTR; |
| 24 | |
Alexander Graf | b66babd | 2018-04-23 07:59:46 +0200 | [diff] [blame] | 25 | __weak void board_quiesce_devices(void) |
| 26 | { |
| 27 | } |
| 28 | |
Lukas Auer | c3b1a99 | 2018-11-22 11:26:32 +0100 | [diff] [blame] | 29 | /** |
| 30 | * announce_and_cleanup() - Print message and prepare for kernel boot |
| 31 | * |
| 32 | * @fake: non-zero to do everything except actually boot |
| 33 | */ |
| 34 | static void announce_and_cleanup(int fake) |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 35 | { |
Lukas Auer | c3b1a99 | 2018-11-22 11:26:32 +0100 | [diff] [blame] | 36 | printf("\nStarting kernel ...%s\n\n", fake ? |
| 37 | "(fake run for tracing)" : ""); |
| 38 | bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel"); |
| 39 | #ifdef CONFIG_BOOTSTAGE_FDT |
| 40 | bootstage_fdt_add_report(); |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 41 | #endif |
Lukas Auer | c3b1a99 | 2018-11-22 11:26:32 +0100 | [diff] [blame] | 42 | #ifdef CONFIG_BOOTSTAGE_REPORT |
| 43 | bootstage_report(); |
| 44 | #endif |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 45 | |
Lukas Auer | c3b1a99 | 2018-11-22 11:26:32 +0100 | [diff] [blame] | 46 | #ifdef CONFIG_USB_DEVICE |
| 47 | udc_disconnect(); |
| 48 | #endif |
| 49 | |
| 50 | board_quiesce_devices(); |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 51 | |
Bin Meng | b1893a9 | 2018-10-15 02:20:59 -0700 | [diff] [blame] | 52 | /* |
| 53 | * Call remove function of all devices with a removal flag set. |
| 54 | * This may be useful for last-stage operations, like cancelling |
| 55 | * of DMA operation or releasing device internal buffers. |
| 56 | */ |
| 57 | dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL); |
| 58 | |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 59 | cleanup_before_linux(); |
Lukas Auer | c3b1a99 | 2018-11-22 11:26:32 +0100 | [diff] [blame] | 60 | } |
Bin Meng | ed49ba4 | 2018-09-26 06:55:16 -0700 | [diff] [blame] | 61 | |
Lukas Auer | c3b1a99 | 2018-11-22 11:26:32 +0100 | [diff] [blame] | 62 | static void boot_prep_linux(bootm_headers_t *images) |
| 63 | { |
| 64 | if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) { |
| 65 | #ifdef CONFIG_OF_LIBFDT |
| 66 | debug("using: FDT\n"); |
| 67 | if (image_setup_linux(images)) { |
| 68 | printf("FDT creation failed! hanging..."); |
| 69 | hang(); |
| 70 | } |
| 71 | #endif |
| 72 | } else { |
| 73 | printf("Device tree not found or missing FDT support\n"); |
| 74 | hang(); |
| 75 | } |
| 76 | } |
Rick Chen | 22b7e6f | 2018-03-13 14:59:41 +0800 | [diff] [blame] | 77 | |
Lukas Auer | c3b1a99 | 2018-11-22 11:26:32 +0100 | [diff] [blame] | 78 | static void boot_jump_linux(bootm_headers_t *images, int flag) |
| 79 | { |
| 80 | void (*kernel)(ulong hart, void *dtb); |
| 81 | int fake = (flag & BOOTM_STATE_OS_FAKE_GO); |
Lukas Auer | f28ad25 | 2019-03-17 19:28:38 +0100 | [diff] [blame] | 82 | #ifdef CONFIG_SMP |
| 83 | int ret; |
| 84 | #endif |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 85 | |
Lukas Auer | c3b1a99 | 2018-11-22 11:26:32 +0100 | [diff] [blame] | 86 | kernel = (void (*)(ulong, void *))images->ep; |
| 87 | |
| 88 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 89 | |
Bin Meng | 08337cd | 2018-12-21 07:13:41 -0800 | [diff] [blame] | 90 | debug("## Transferring control to kernel (at address %08lx) ...\n", |
Lukas Auer | c3b1a99 | 2018-11-22 11:26:32 +0100 | [diff] [blame] | 91 | (ulong)kernel); |
| 92 | |
| 93 | announce_and_cleanup(fake); |
| 94 | |
| 95 | if (!fake) { |
Lukas Auer | f28ad25 | 2019-03-17 19:28:38 +0100 | [diff] [blame] | 96 | if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) { |
| 97 | #ifdef CONFIG_SMP |
| 98 | ret = smp_call_function(images->ep, |
Lukas Auer | 90ae281 | 2019-12-08 23:28:51 +0100 | [diff] [blame] | 99 | (ulong)images->ft_addr, 0, 0); |
Lukas Auer | f28ad25 | 2019-03-17 19:28:38 +0100 | [diff] [blame] | 100 | if (ret) |
| 101 | hang(); |
| 102 | #endif |
Bin Meng | 3c85099 | 2018-12-12 06:12:46 -0800 | [diff] [blame] | 103 | kernel(gd->arch.boot_hart, images->ft_addr); |
Lukas Auer | f28ad25 | 2019-03-17 19:28:38 +0100 | [diff] [blame] | 104 | } |
Lukas Auer | c3b1a99 | 2018-11-22 11:26:32 +0100 | [diff] [blame] | 105 | } |
| 106 | } |
| 107 | |
| 108 | int do_bootm_linux(int flag, int argc, char * const argv[], |
| 109 | bootm_headers_t *images) |
| 110 | { |
| 111 | /* No need for those on RISC-V */ |
| 112 | if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE) |
| 113 | return -1; |
| 114 | |
| 115 | if (flag & BOOTM_STATE_OS_PREP) { |
| 116 | boot_prep_linux(images); |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) { |
| 121 | boot_jump_linux(images, flag); |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | boot_prep_linux(images); |
| 126 | boot_jump_linux(images, flag); |
| 127 | return 0; |
Rick Chen | 8bbb290 | 2017-12-26 13:55:49 +0800 | [diff] [blame] | 128 | } |
Bin Meng | 08337cd | 2018-12-21 07:13:41 -0800 | [diff] [blame] | 129 | |
| 130 | int do_bootm_vxworks(int flag, int argc, char * const argv[], |
| 131 | bootm_headers_t *images) |
| 132 | { |
| 133 | return do_bootm_linux(flag, argc, argv, images); |
| 134 | } |