Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 2 | /* Copyright (C) 2011 |
| 3 | * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de> |
| 4 | * - Added prep subcommand support |
| 5 | * - Reorganized source - modeled after powerpc version |
| 6 | * |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 7 | * (C) Copyright 2002 |
| 8 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 9 | * Marius Groeger <mgroeger@sysgo.de> |
| 10 | * |
| 11 | * Copyright (C) 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <common.h> |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 15 | #include <bootm.h> |
Simon Glass | 1ea9789 | 2020-05-10 11:40:00 -0600 | [diff] [blame] | 16 | #include <bootstage.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 17 | #include <command.h> |
Simon Glass | 370382c | 2019-11-14 12:57:35 -0700 | [diff] [blame] | 18 | #include <cpu_func.h> |
Simon Glass | 11c89f3 | 2017-05-17 17:18:03 -0600 | [diff] [blame] | 19 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 20 | #include <log.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 21 | #include <asm/global_data.h> |
Stefan Roese | 8ab5a1b | 2017-03-20 12:51:50 +0100 | [diff] [blame] | 22 | #include <dm/root.h> |
Simon Glass | 0af6e2d | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 23 | #include <env.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 24 | #include <image.h> |
Jean-Christophe PLAGNIOL-VILLARD | 6bb9449 | 2009-04-04 12:49:11 +0200 | [diff] [blame] | 25 | #include <u-boot/zlib.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 26 | #include <asm/byteorder.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 27 | #include <linux/libfdt.h> |
Joe Hershberger | 65b905b | 2015-03-22 17:08:59 -0500 | [diff] [blame] | 28 | #include <mapmem.h> |
John Rigby | ab51f1e | 2010-10-13 13:57:36 -0600 | [diff] [blame] | 29 | #include <fdt_support.h> |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 30 | #include <asm/bootm.h> |
Marc Zyngier | 855ca66 | 2014-07-12 14:24:03 +0100 | [diff] [blame] | 31 | #include <asm/secure.h> |
Pali Rohár | 5ebe4f1 | 2012-10-19 02:00:04 +0000 | [diff] [blame] | 32 | #include <linux/compiler.h> |
Eric Nelson | b7c236b | 2014-09-30 15:40:01 -0700 | [diff] [blame] | 33 | #include <bootm.h> |
| 34 | #include <vxworks.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 35 | #include <asm/cache.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 36 | |
Jan Kiszka | ac31b5a | 2015-04-21 07:18:24 +0200 | [diff] [blame] | 37 | #ifdef CONFIG_ARMV7_NONSEC |
Andre Przywara | fe7d925 | 2013-09-19 18:06:43 +0200 | [diff] [blame] | 38 | #include <asm/armv7.h> |
| 39 | #endif |
Simon Glass | 30db774 | 2017-05-17 08:22:59 -0600 | [diff] [blame] | 40 | #include <asm/setup.h> |
Andre Przywara | fe7d925 | 2013-09-19 18:06:43 +0200 | [diff] [blame] | 41 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 42 | DECLARE_GLOBAL_DATA_PTR; |
| 43 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 44 | static struct tag *params; |
John Rigby | ab51f1e | 2010-10-13 13:57:36 -0600 | [diff] [blame] | 45 | |
Alexander Graf | 2ebeb44 | 2016-11-17 01:02:57 +0100 | [diff] [blame] | 46 | __weak void board_quiesce_devices(void) |
| 47 | { |
| 48 | } |
| 49 | |
Simon Glass | 3c26c58 | 2013-06-19 21:15:10 -0700 | [diff] [blame] | 50 | /** |
| 51 | * announce_and_cleanup() - Print message and prepare for kernel boot |
| 52 | * |
| 53 | * @fake: non-zero to do everything except actually boot |
| 54 | */ |
| 55 | static void announce_and_cleanup(int fake) |
John Rigby | ab51f1e | 2010-10-13 13:57:36 -0600 | [diff] [blame] | 56 | { |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 57 | bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel"); |
Simon Glass | 0fa36a4 | 2012-09-28 08:56:37 +0000 | [diff] [blame] | 58 | #ifdef CONFIG_BOOTSTAGE_FDT |
Mela Custodio | 5625c8b | 2014-02-20 00:16:56 +0900 | [diff] [blame] | 59 | bootstage_fdt_add_report(); |
Simon Glass | 0fa36a4 | 2012-09-28 08:56:37 +0000 | [diff] [blame] | 60 | #endif |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 61 | #ifdef CONFIG_BOOTSTAGE_REPORT |
| 62 | bootstage_report(); |
| 63 | #endif |
Wolfgang Denk | 20ec367 | 2008-09-08 23:26:22 +0200 | [diff] [blame] | 64 | |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 65 | #ifdef CONFIG_USB_DEVICE |
| 66 | udc_disconnect(); |
John Rigby | ab51f1e | 2010-10-13 13:57:36 -0600 | [diff] [blame] | 67 | #endif |
Alexander Graf | 2ebeb44 | 2016-11-17 01:02:57 +0100 | [diff] [blame] | 68 | |
| 69 | board_quiesce_devices(); |
| 70 | |
Keerthy | 79a7cb1 | 2019-02-20 18:17:22 +0530 | [diff] [blame] | 71 | printf("\nStarting kernel ...%s\n\n", fake ? |
| 72 | "(fake run for tracing)" : ""); |
Stefan Roese | 8ab5a1b | 2017-03-20 12:51:50 +0100 | [diff] [blame] | 73 | /* |
| 74 | * Call remove function of all devices with a removal flag set. |
| 75 | * This may be useful for last-stage operations, like cancelling |
| 76 | * of DMA operation or releasing device internal buffers. |
| 77 | */ |
Simon Glass | 8ae8744 | 2021-01-24 14:32:47 -0700 | [diff] [blame] | 78 | dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL | DM_REMOVE_NON_VITAL); |
| 79 | |
| 80 | /* Remove all active vital devices next */ |
Stefan Roese | 8ab5a1b | 2017-03-20 12:51:50 +0100 | [diff] [blame] | 81 | dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL); |
| 82 | |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 83 | cleanup_before_linux(); |
| 84 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 85 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 86 | static void setup_start_tag (struct bd_info *bd) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 87 | { |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 88 | params = (struct tag *)bd->bi_boot_params; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 89 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 90 | params->hdr.tag = ATAG_CORE; |
| 91 | params->hdr.size = tag_size (tag_core); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 92 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 93 | params->u.core.flags = 0; |
| 94 | params->u.core.pagesize = 0; |
| 95 | params->u.core.rootdev = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 96 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 97 | params = tag_next (params); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 98 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 99 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 100 | static void setup_memory_tags(struct bd_info *bd) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 101 | { |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 102 | int i; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 103 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 104 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
| 105 | params->hdr.tag = ATAG_MEM; |
| 106 | params->hdr.size = tag_size (tag_mem32); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 107 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 108 | params->u.mem.start = bd->bi_dram[i].start; |
| 109 | params->u.mem.size = bd->bi_dram[i].size; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 110 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 111 | params = tag_next (params); |
| 112 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 113 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 114 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 115 | static void setup_commandline_tag(struct bd_info *bd, char *commandline) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 116 | { |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 117 | char *p; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 118 | |
wdenk | f16b516 | 2004-03-23 21:43:07 +0000 | [diff] [blame] | 119 | if (!commandline) |
| 120 | return; |
| 121 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 122 | /* eat leading white space */ |
| 123 | for (p = commandline; *p == ' '; p++); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 124 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 125 | /* skip non-existent command lines so the kernel will still |
| 126 | * use its default command line. |
| 127 | */ |
| 128 | if (*p == '\0') |
| 129 | return; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 130 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 131 | params->hdr.tag = ATAG_CMDLINE; |
| 132 | params->hdr.size = |
| 133 | (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 134 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 135 | strcpy (params->u.cmdline.cmdline, p); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 136 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 137 | params = tag_next (params); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 138 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 139 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 140 | static void setup_initrd_tag(struct bd_info *bd, ulong initrd_start, |
| 141 | ulong initrd_end) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 142 | { |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 143 | /* an ATAG_INITRD node tells the kernel where the compressed |
| 144 | * ramdisk can be found. ATAG_RDIMG is a better name, actually. |
| 145 | */ |
wdenk | 19c8fb7 | 2004-04-18 22:26:17 +0000 | [diff] [blame] | 146 | params->hdr.tag = ATAG_INITRD2; |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 147 | params->hdr.size = tag_size (tag_initrd); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 148 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 149 | params->u.initrd.start = initrd_start; |
| 150 | params->u.initrd.size = initrd_end - initrd_start; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 151 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 152 | params = tag_next (params); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 153 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 154 | |
Simon Glass | 50ad221 | 2013-05-08 08:06:02 +0000 | [diff] [blame] | 155 | static void setup_serial_tag(struct tag **tmp) |
wdenk | a21ad7b | 2005-05-19 22:39:42 +0000 | [diff] [blame] | 156 | { |
| 157 | struct tag *params = *tmp; |
| 158 | struct tag_serialnr serialnr; |
wdenk | a21ad7b | 2005-05-19 22:39:42 +0000 | [diff] [blame] | 159 | |
| 160 | get_board_serial(&serialnr); |
| 161 | params->hdr.tag = ATAG_SERIAL; |
| 162 | params->hdr.size = tag_size (tag_serialnr); |
| 163 | params->u.serialnr.low = serialnr.low; |
| 164 | params->u.serialnr.high= serialnr.high; |
| 165 | params = tag_next (params); |
| 166 | *tmp = params; |
| 167 | } |
wdenk | a21ad7b | 2005-05-19 22:39:42 +0000 | [diff] [blame] | 168 | |
Simon Glass | 50ad221 | 2013-05-08 08:06:02 +0000 | [diff] [blame] | 169 | static void setup_revision_tag(struct tag **in_params) |
wdenk | cb99da5 | 2005-01-12 00:15:14 +0000 | [diff] [blame] | 170 | { |
| 171 | u32 rev = 0; |
wdenk | cb99da5 | 2005-01-12 00:15:14 +0000 | [diff] [blame] | 172 | |
| 173 | rev = get_board_rev(); |
wdenk | cb99da5 | 2005-01-12 00:15:14 +0000 | [diff] [blame] | 174 | params->hdr.tag = ATAG_REVISION; |
| 175 | params->hdr.size = tag_size (tag_revision); |
| 176 | params->u.revision.rev = rev; |
| 177 | params = tag_next (params); |
| 178 | } |
wdenk | cb99da5 | 2005-01-12 00:15:14 +0000 | [diff] [blame] | 179 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 180 | static void setup_end_tag(struct bd_info *bd) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 181 | { |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 182 | params->hdr.tag = ATAG_NONE; |
| 183 | params->hdr.size = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 184 | } |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 185 | |
Pali Rohár | 5ebe4f1 | 2012-10-19 02:00:04 +0000 | [diff] [blame] | 186 | __weak void setup_board_tags(struct tag **in_params) {} |
| 187 | |
Marc Zyngier | 855ca66 | 2014-07-12 14:24:03 +0100 | [diff] [blame] | 188 | #ifdef CONFIG_ARM64 |
Andre Przywara | fe7d925 | 2013-09-19 18:06:43 +0200 | [diff] [blame] | 189 | static void do_nonsec_virt_switch(void) |
| 190 | { |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 191 | smp_kick_all_cpus(); |
York Sun | 1ce575f | 2015-01-06 13:18:42 -0800 | [diff] [blame] | 192 | dcache_disable(); /* flush cache before swtiching to EL2 */ |
Andre Przywara | fe7d925 | 2013-09-19 18:06:43 +0200 | [diff] [blame] | 193 | } |
Marc Zyngier | 855ca66 | 2014-07-12 14:24:03 +0100 | [diff] [blame] | 194 | #endif |
Andre Przywara | fe7d925 | 2013-09-19 18:06:43 +0200 | [diff] [blame] | 195 | |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 196 | __weak void board_prep_linux(struct bootm_headers *images) { } |
Lokesh Vutla | b1f1b23 | 2019-10-07 13:52:15 +0530 | [diff] [blame] | 197 | |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 198 | /* Subcommand: PREP */ |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 199 | static void boot_prep_linux(struct bootm_headers *images) |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 200 | { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 201 | char *commandline = env_get("bootargs"); |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 202 | |
Simon Glass | ae7ed57 | 2023-02-05 15:40:13 -0700 | [diff] [blame] | 203 | if (CONFIG_IS_ENABLED(OF_LIBFDT) && IS_ENABLED(CONFIG_LMB) && images->ft_len) { |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 204 | debug("using: FDT\n"); |
Simon Glass | 653909f | 2013-05-08 08:06:03 +0000 | [diff] [blame] | 205 | if (image_setup_linux(images)) { |
Heinrich Schuchardt | e3550d5 | 2021-02-17 12:55:54 +0100 | [diff] [blame] | 206 | panic("FDT creation failed!"); |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 207 | } |
Simon Glass | 50ad221 | 2013-05-08 08:06:02 +0000 | [diff] [blame] | 208 | } else if (BOOTM_ENABLE_TAGS) { |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 209 | debug("using: ATAGS\n"); |
| 210 | setup_start_tag(gd->bd); |
Simon Glass | 50ad221 | 2013-05-08 08:06:02 +0000 | [diff] [blame] | 211 | if (BOOTM_ENABLE_SERIAL_TAG) |
| 212 | setup_serial_tag(¶ms); |
| 213 | if (BOOTM_ENABLE_CMDLINE_TAG) |
| 214 | setup_commandline_tag(gd->bd, commandline); |
| 215 | if (BOOTM_ENABLE_REVISION_TAG) |
| 216 | setup_revision_tag(¶ms); |
| 217 | if (BOOTM_ENABLE_MEMORY_TAGS) |
| 218 | setup_memory_tags(gd->bd); |
| 219 | if (BOOTM_ENABLE_INITRD_TAG) { |
Jeffy Chen | 113094e | 2016-01-14 10:19:36 +0800 | [diff] [blame] | 220 | /* |
| 221 | * In boot_ramdisk_high(), it may relocate ramdisk to |
| 222 | * a specified location. And set images->initrd_start & |
| 223 | * images->initrd_end to relocated ramdisk's start/end |
| 224 | * addresses. So use them instead of images->rd_start & |
| 225 | * images->rd_end when possible. |
| 226 | */ |
| 227 | if (images->initrd_start && images->initrd_end) { |
| 228 | setup_initrd_tag(gd->bd, images->initrd_start, |
| 229 | images->initrd_end); |
| 230 | } else if (images->rd_start && images->rd_end) { |
Simon Glass | 50ad221 | 2013-05-08 08:06:02 +0000 | [diff] [blame] | 231 | setup_initrd_tag(gd->bd, images->rd_start, |
| 232 | images->rd_end); |
| 233 | } |
| 234 | } |
Pali Rohár | 5ebe4f1 | 2012-10-19 02:00:04 +0000 | [diff] [blame] | 235 | setup_board_tags(¶ms); |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 236 | setup_end_tag(gd->bd); |
Simon Glass | 50ad221 | 2013-05-08 08:06:02 +0000 | [diff] [blame] | 237 | } else { |
Heinrich Schuchardt | e3550d5 | 2021-02-17 12:55:54 +0100 | [diff] [blame] | 238 | panic("FDT and ATAGS support not compiled in\n"); |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 239 | } |
Lokesh Vutla | b1f1b23 | 2019-10-07 13:52:15 +0530 | [diff] [blame] | 240 | |
| 241 | board_prep_linux(images); |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Jon Medhurst \(Tixy\) | 413ca3d | 2016-06-23 13:37:32 +0100 | [diff] [blame] | 244 | __weak bool armv7_boot_nonsec_default(void) |
Hans de Goede | 63fb548 | 2014-11-14 09:34:31 +0100 | [diff] [blame] | 245 | { |
Hans de Goede | 63fb548 | 2014-11-14 09:34:31 +0100 | [diff] [blame] | 246 | #ifdef CONFIG_ARMV7_BOOT_SEC_DEFAULT |
Jon Medhurst \(Tixy\) | 413ca3d | 2016-06-23 13:37:32 +0100 | [diff] [blame] | 247 | return false; |
Hans de Goede | 63fb548 | 2014-11-14 09:34:31 +0100 | [diff] [blame] | 248 | #else |
Jon Medhurst \(Tixy\) | 413ca3d | 2016-06-23 13:37:32 +0100 | [diff] [blame] | 249 | return true; |
Hans de Goede | 63fb548 | 2014-11-14 09:34:31 +0100 | [diff] [blame] | 250 | #endif |
Jon Medhurst \(Tixy\) | 413ca3d | 2016-06-23 13:37:32 +0100 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | #ifdef CONFIG_ARMV7_NONSEC |
| 254 | bool armv7_boot_nonsec(void) |
| 255 | { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 256 | char *s = env_get("bootm_boot_mode"); |
Jon Medhurst \(Tixy\) | 413ca3d | 2016-06-23 13:37:32 +0100 | [diff] [blame] | 257 | bool nonsec = armv7_boot_nonsec_default(); |
Hans de Goede | 63fb548 | 2014-11-14 09:34:31 +0100 | [diff] [blame] | 258 | |
| 259 | if (s && !strcmp(s, "sec")) |
| 260 | nonsec = false; |
| 261 | |
| 262 | if (s && !strcmp(s, "nonsec")) |
| 263 | nonsec = true; |
| 264 | |
| 265 | return nonsec; |
| 266 | } |
| 267 | #endif |
| 268 | |
Alison Wang | 73818d5 | 2016-11-10 10:49:03 +0800 | [diff] [blame] | 269 | #ifdef CONFIG_ARM64 |
Alison Wang | 876c7e1 | 2016-11-10 10:49:04 +0800 | [diff] [blame] | 270 | __weak void update_os_arch_secondary_cores(uint8_t os_arch) |
| 271 | { |
| 272 | } |
| 273 | |
Tom Rini | 3a6d453 | 2021-09-03 10:40:28 -0400 | [diff] [blame] | 274 | #ifdef CONFIG_ARMV8_SWITCH_TO_EL1 |
Alison Wang | 73818d5 | 2016-11-10 10:49:03 +0800 | [diff] [blame] | 275 | static void switch_to_el1(void) |
| 276 | { |
| 277 | if ((IH_ARCH_DEFAULT == IH_ARCH_ARM64) && |
| 278 | (images.os.arch == IH_ARCH_ARM)) |
| 279 | armv8_switch_to_el1(0, (u64)gd->bd->bi_arch_number, |
Alison Wang | eb2088d | 2017-01-17 09:39:17 +0800 | [diff] [blame] | 280 | (u64)images.ft_addr, 0, |
Alison Wang | 73818d5 | 2016-11-10 10:49:03 +0800 | [diff] [blame] | 281 | (u64)images.ep, |
| 282 | ES_TO_AARCH32); |
| 283 | else |
Alison Wang | eb2088d | 2017-01-17 09:39:17 +0800 | [diff] [blame] | 284 | armv8_switch_to_el1((u64)images.ft_addr, 0, 0, 0, |
Alison Wang | 73818d5 | 2016-11-10 10:49:03 +0800 | [diff] [blame] | 285 | images.ep, |
| 286 | ES_TO_AARCH64); |
| 287 | } |
| 288 | #endif |
Tom Rini | 3a6d453 | 2021-09-03 10:40:28 -0400 | [diff] [blame] | 289 | #endif |
Alison Wang | 73818d5 | 2016-11-10 10:49:03 +0800 | [diff] [blame] | 290 | |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 291 | /* Subcommand: GO */ |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 292 | static void boot_jump_linux(struct bootm_headers *images, int flag) |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 293 | { |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 294 | #ifdef CONFIG_ARM64 |
Tom Rini | 67d604e | 2014-08-14 06:42:35 -0400 | [diff] [blame] | 295 | void (*kernel_entry)(void *fdt_addr, void *res0, void *res1, |
| 296 | void *res2); |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 297 | int fake = (flag & BOOTM_STATE_OS_FAKE_GO); |
| 298 | |
Tom Rini | 67d604e | 2014-08-14 06:42:35 -0400 | [diff] [blame] | 299 | kernel_entry = (void (*)(void *fdt_addr, void *res0, void *res1, |
| 300 | void *res2))images->ep; |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 301 | |
| 302 | debug("## Transferring control to Linux (at address %lx)...\n", |
| 303 | (ulong) kernel_entry); |
| 304 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 305 | |
| 306 | announce_and_cleanup(fake); |
| 307 | |
Marc Zyngier | 915a09e | 2014-07-12 14:23:58 +0100 | [diff] [blame] | 308 | if (!fake) { |
macro.wave.z@gmail.com | 05725ed | 2016-12-08 11:58:25 +0800 | [diff] [blame] | 309 | #ifdef CONFIG_ARMV8_PSCI |
| 310 | armv8_setup_psci(); |
| 311 | #endif |
Marc Zyngier | 915a09e | 2014-07-12 14:23:58 +0100 | [diff] [blame] | 312 | do_nonsec_virt_switch(); |
Alison Wang | 73818d5 | 2016-11-10 10:49:03 +0800 | [diff] [blame] | 313 | |
Alison Wang | 876c7e1 | 2016-11-10 10:49:04 +0800 | [diff] [blame] | 314 | update_os_arch_secondary_cores(images->os.arch); |
| 315 | |
Peter Hoyes | a673266 | 2021-08-19 16:53:13 +0100 | [diff] [blame] | 316 | #ifdef CONFIG_ARMV8_SWITCH_TO_EL1 |
Tom Rini | 3a6d453 | 2021-09-03 10:40:28 -0400 | [diff] [blame] | 317 | armv8_switch_to_el2((u64)images->ft_addr, 0, 0, 0, |
| 318 | (u64)switch_to_el1, ES_TO_AARCH64); |
| 319 | #else |
| 320 | if ((IH_ARCH_DEFAULT == IH_ARCH_ARM64) && |
| 321 | (images->os.arch == IH_ARCH_ARM)) |
| 322 | armv8_switch_to_el2(0, (u64)gd->bd->bi_arch_number, |
| 323 | (u64)images->ft_addr, 0, |
| 324 | (u64)images->ep, |
| 325 | ES_TO_AARCH32); |
| 326 | else |
Peter Hoyes | a673266 | 2021-08-19 16:53:13 +0100 | [diff] [blame] | 327 | armv8_switch_to_el2((u64)images->ft_addr, 0, 0, 0, |
Tom Rini | 3a6d453 | 2021-09-03 10:40:28 -0400 | [diff] [blame] | 328 | images->ep, |
| 329 | ES_TO_AARCH64); |
| 330 | #endif |
Marc Zyngier | 915a09e | 2014-07-12 14:23:58 +0100 | [diff] [blame] | 331 | } |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 332 | #else |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 333 | unsigned long machid = gd->bd->bi_arch_number; |
| 334 | char *s; |
| 335 | void (*kernel_entry)(int zero, int arch, uint params); |
Stephen Warren | c570fba | 2012-04-19 11:34:00 +0000 | [diff] [blame] | 336 | unsigned long r2; |
Simon Glass | 3c26c58 | 2013-06-19 21:15:10 -0700 | [diff] [blame] | 337 | int fake = (flag & BOOTM_STATE_OS_FAKE_GO); |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 338 | |
| 339 | kernel_entry = (void (*)(int, int, uint))images->ep; |
Patrice Chotard | ffb3c0b | 2017-04-25 11:07:46 +0200 | [diff] [blame] | 340 | #ifdef CONFIG_CPU_V7M |
| 341 | ulong addr = (ulong)kernel_entry | 1; |
| 342 | kernel_entry = (void *)addr; |
| 343 | #endif |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 344 | s = env_get("machid"); |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 345 | if (s) { |
Peng Fan | c4485e7 | 2015-11-24 16:54:20 +0800 | [diff] [blame] | 346 | if (strict_strtoul(s, 16, &machid) < 0) { |
| 347 | debug("strict_strtoul failed!\n"); |
| 348 | return; |
| 349 | } |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 350 | printf("Using machid 0x%lx from environment\n", machid); |
| 351 | } |
| 352 | |
| 353 | debug("## Transferring control to Linux (at address %08lx)" \ |
| 354 | "...\n", (ulong) kernel_entry); |
| 355 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
Simon Glass | 3c26c58 | 2013-06-19 21:15:10 -0700 | [diff] [blame] | 356 | announce_and_cleanup(fake); |
Stephen Warren | c570fba | 2012-04-19 11:34:00 +0000 | [diff] [blame] | 357 | |
Simon Glass | 85c057e | 2021-09-25 19:43:21 -0600 | [diff] [blame] | 358 | if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) |
Stephen Warren | c570fba | 2012-04-19 11:34:00 +0000 | [diff] [blame] | 359 | r2 = (unsigned long)images->ft_addr; |
| 360 | else |
Stephen Warren | c570fba | 2012-04-19 11:34:00 +0000 | [diff] [blame] | 361 | r2 = gd->bd->bi_boot_params; |
| 362 | |
Marc Zyngier | 915a09e | 2014-07-12 14:23:58 +0100 | [diff] [blame] | 363 | if (!fake) { |
Jan Kiszka | ac31b5a | 2015-04-21 07:18:24 +0200 | [diff] [blame] | 364 | #ifdef CONFIG_ARMV7_NONSEC |
Ian Campbell | 68bc8f5 | 2014-12-21 09:45:11 +0000 | [diff] [blame] | 365 | if (armv7_boot_nonsec()) { |
Hans de Goede | 63fb548 | 2014-11-14 09:34:31 +0100 | [diff] [blame] | 366 | armv7_init_nonsec(); |
| 367 | secure_ram_addr(_do_nonsec_entry)(kernel_entry, |
| 368 | 0, machid, r2); |
| 369 | } else |
Marc Zyngier | 855ca66 | 2014-07-12 14:24:03 +0100 | [diff] [blame] | 370 | #endif |
Hans de Goede | 63fb548 | 2014-11-14 09:34:31 +0100 | [diff] [blame] | 371 | kernel_entry(0, machid, r2); |
Marc Zyngier | 915a09e | 2014-07-12 14:23:58 +0100 | [diff] [blame] | 372 | } |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 373 | #endif |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | /* Main Entry point for arm bootm implementation |
| 377 | * |
| 378 | * Modeled after the powerpc implementation |
| 379 | * DIFFERENCE: Instead of calling prep and go at the end |
| 380 | * they are called if subcommand is equal 0. |
| 381 | */ |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 382 | int do_bootm_linux(int flag, struct bootm_info *bmi) |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 383 | { |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 384 | struct bootm_headers *images = bmi->images; |
| 385 | |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 386 | /* No need for those on ARM */ |
| 387 | if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE) |
| 388 | return -1; |
| 389 | |
| 390 | if (flag & BOOTM_STATE_OS_PREP) { |
| 391 | boot_prep_linux(images); |
| 392 | return 0; |
| 393 | } |
| 394 | |
Simon Glass | 3c26c58 | 2013-06-19 21:15:10 -0700 | [diff] [blame] | 395 | if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) { |
| 396 | boot_jump_linux(images, flag); |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 397 | return 0; |
| 398 | } |
| 399 | |
| 400 | boot_prep_linux(images); |
Simon Glass | 3c26c58 | 2013-06-19 21:15:10 -0700 | [diff] [blame] | 401 | boot_jump_linux(images, flag); |
Simon Schwarz | 6a597b9 | 2012-03-15 04:01:45 +0000 | [diff] [blame] | 402 | return 0; |
John Rigby | ab51f1e | 2010-10-13 13:57:36 -0600 | [diff] [blame] | 403 | } |
Marek Vasut | cf41a9b | 2012-03-14 21:52:45 +0000 | [diff] [blame] | 404 | |
Miao Yan | 1bd5456 | 2013-11-28 17:51:38 +0800 | [diff] [blame] | 405 | #if defined(CONFIG_BOOTM_VXWORKS) |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 406 | void boot_prep_vxworks(struct bootm_headers *images) |
Miao Yan | 1bd5456 | 2013-11-28 17:51:38 +0800 | [diff] [blame] | 407 | { |
| 408 | #if defined(CONFIG_OF_LIBFDT) |
| 409 | int off; |
| 410 | |
| 411 | if (images->ft_addr) { |
| 412 | off = fdt_path_offset(images->ft_addr, "/memory"); |
Hannes Schmelzer | 64fabcc | 2018-05-04 10:49:11 +0200 | [diff] [blame] | 413 | if (off > 0) { |
Ma Haijun | 6235824 | 2014-07-12 14:24:06 +0100 | [diff] [blame] | 414 | if (arch_fixup_fdt(images->ft_addr)) |
Miao Yan | 1bd5456 | 2013-11-28 17:51:38 +0800 | [diff] [blame] | 415 | puts("## WARNING: fixup memory failed!\n"); |
| 416 | } |
| 417 | } |
| 418 | #endif |
| 419 | cleanup_before_linux(); |
| 420 | } |
Simon Glass | df00afa | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 421 | |
| 422 | void boot_jump_vxworks(struct bootm_headers *images) |
Miao Yan | 1bd5456 | 2013-11-28 17:51:38 +0800 | [diff] [blame] | 423 | { |
Vasyl Vavrychuk | 70b551c | 2018-04-10 12:36:36 +0300 | [diff] [blame] | 424 | #if defined(CONFIG_ARM64) && defined(CONFIG_ARMV8_PSCI) |
| 425 | armv8_setup_psci(); |
| 426 | smp_kick_all_cpus(); |
| 427 | #endif |
| 428 | |
Miao Yan | 1bd5456 | 2013-11-28 17:51:38 +0800 | [diff] [blame] | 429 | /* ARM VxWorks requires device tree physical address to be passed */ |
| 430 | ((void (*)(void *))images->ep)(images->ft_addr); |
| 431 | } |
| 432 | #endif |