blob: 11af9e2fb9cf181530c32c9fa369a762806c1847 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Schwarz6a597b92012-03-15 04:01:45 +00002/* 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 *
wdenkc6097192002-11-03 00:24:07 +00007 * (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)
wdenkc6097192002-11-03 00:24:07 +000012 */
13
14#include <common.h>
Simon Glass1ea97892020-05-10 11:40:00 -060015#include <bootstage.h>
wdenkc6097192002-11-03 00:24:07 +000016#include <command.h>
Simon Glass370382c2019-11-14 12:57:35 -070017#include <cpu_func.h>
Simon Glass11c89f32017-05-17 17:18:03 -060018#include <dm.h>
Simon Glassf11478f2019-12-28 10:45:07 -070019#include <hang.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060020#include <lmb.h>
Simon Glass0f2af882020-05-10 11:40:05 -060021#include <log.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060022#include <asm/global_data.h>
Stefan Roese8ab5a1b2017-03-20 12:51:50 +010023#include <dm/root.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -060024#include <env.h>
wdenkc6097192002-11-03 00:24:07 +000025#include <image.h>
Jean-Christophe PLAGNIOL-VILLARD6bb94492009-04-04 12:49:11 +020026#include <u-boot/zlib.h>
wdenkc6097192002-11-03 00:24:07 +000027#include <asm/byteorder.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090028#include <linux/libfdt.h>
Joe Hershberger65b905b2015-03-22 17:08:59 -050029#include <mapmem.h>
John Rigbyab51f1e2010-10-13 13:57:36 -060030#include <fdt_support.h>
Simon Schwarz6a597b92012-03-15 04:01:45 +000031#include <asm/bootm.h>
Marc Zyngier855ca662014-07-12 14:24:03 +010032#include <asm/secure.h>
Pali Rohár5ebe4f12012-10-19 02:00:04 +000033#include <linux/compiler.h>
Eric Nelsonb7c236b2014-09-30 15:40:01 -070034#include <bootm.h>
35#include <vxworks.h>
Simon Glass274e0b02020-05-10 11:39:56 -060036#include <asm/cache.h>
wdenkc6097192002-11-03 00:24:07 +000037
Jan Kiszkaac31b5a2015-04-21 07:18:24 +020038#ifdef CONFIG_ARMV7_NONSEC
Andre Przywarafe7d9252013-09-19 18:06:43 +020039#include <asm/armv7.h>
40#endif
Simon Glass30db7742017-05-17 08:22:59 -060041#include <asm/setup.h>
Andre Przywarafe7d9252013-09-19 18:06:43 +020042
Wolfgang Denk6405a152006-03-31 18:32:53 +020043DECLARE_GLOBAL_DATA_PTR;
44
wdenkc6097192002-11-03 00:24:07 +000045static struct tag *params;
John Rigbyab51f1e2010-10-13 13:57:36 -060046
Simon Schwarz6a597b92012-03-15 04:01:45 +000047static ulong get_sp(void)
48{
49 ulong ret;
50
51 asm("mov %0, sp" : "=r"(ret) : );
52 return ret;
53}
54
John Rigbyab51f1e2010-10-13 13:57:36 -060055void arch_lmb_reserve(struct lmb *lmb)
56{
Stephen Warren1a0b8052018-01-05 13:04:54 -070057 ulong sp, bank_end;
58 int bank;
John Rigbyab51f1e2010-10-13 13:57:36 -060059
60 /*
61 * Booting a (Linux) kernel image
62 *
63 * Allocate space for command line and board info - the
64 * address should be as high as possible within the reach of
65 * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
66 * memory, which means far enough below the current stack
67 * pointer.
68 */
69 sp = get_sp();
70 debug("## Current stack ends at 0x%08lx ", sp);
71
Rob Herring13137f32012-06-28 03:54:11 +000072 /* adjust sp by 4K to be safe */
73 sp -= 4096;
Stephen Warren1a0b8052018-01-05 13:04:54 -070074 for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
Simon Goldschmidtfeaab8e2019-01-14 22:38:23 +010075 if (!gd->bd->bi_dram[bank].size ||
76 sp < gd->bd->bi_dram[bank].start)
Stephen Warren1a0b8052018-01-05 13:04:54 -070077 continue;
Simon Goldschmidtfeaab8e2019-01-14 22:38:23 +010078 /* Watch out for RAM at end of address space! */
Stephen Warren1a0b8052018-01-05 13:04:54 -070079 bank_end = gd->bd->bi_dram[bank].start +
Simon Goldschmidtfeaab8e2019-01-14 22:38:23 +010080 gd->bd->bi_dram[bank].size - 1;
81 if (sp > bank_end)
Stephen Warren1a0b8052018-01-05 13:04:54 -070082 continue;
Patrice Chotard49bd67e2020-02-13 19:29:50 +010083 if (bank_end > gd->ram_top)
84 bank_end = gd->ram_top - 1;
85
Simon Goldschmidtfeaab8e2019-01-14 22:38:23 +010086 lmb_reserve(lmb, sp, bank_end - sp + 1);
Stephen Warren1a0b8052018-01-05 13:04:54 -070087 break;
88 }
John Rigbyab51f1e2010-10-13 13:57:36 -060089}
90
Alexander Graf2ebeb442016-11-17 01:02:57 +010091__weak void board_quiesce_devices(void)
92{
93}
94
Simon Glass3c26c582013-06-19 21:15:10 -070095/**
96 * announce_and_cleanup() - Print message and prepare for kernel boot
97 *
98 * @fake: non-zero to do everything except actually boot
99 */
100static void announce_and_cleanup(int fake)
John Rigbyab51f1e2010-10-13 13:57:36 -0600101{
Simon Schwarz6a597b92012-03-15 04:01:45 +0000102 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
Simon Glass0fa36a42012-09-28 08:56:37 +0000103#ifdef CONFIG_BOOTSTAGE_FDT
Mela Custodio5625c8b2014-02-20 00:16:56 +0900104 bootstage_fdt_add_report();
Simon Glass0fa36a42012-09-28 08:56:37 +0000105#endif
Simon Schwarz6a597b92012-03-15 04:01:45 +0000106#ifdef CONFIG_BOOTSTAGE_REPORT
107 bootstage_report();
108#endif
Wolfgang Denk20ec3672008-09-08 23:26:22 +0200109
Simon Schwarz6a597b92012-03-15 04:01:45 +0000110#ifdef CONFIG_USB_DEVICE
111 udc_disconnect();
John Rigbyab51f1e2010-10-13 13:57:36 -0600112#endif
Alexander Graf2ebeb442016-11-17 01:02:57 +0100113
114 board_quiesce_devices();
115
Keerthy79a7cb12019-02-20 18:17:22 +0530116 printf("\nStarting kernel ...%s\n\n", fake ?
117 "(fake run for tracing)" : "");
Stefan Roese8ab5a1b2017-03-20 12:51:50 +0100118 /*
119 * Call remove function of all devices with a removal flag set.
120 * This may be useful for last-stage operations, like cancelling
121 * of DMA operation or releasing device internal buffers.
122 */
Simon Glass8ae87442021-01-24 14:32:47 -0700123 dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL | DM_REMOVE_NON_VITAL);
124
125 /* Remove all active vital devices next */
Stefan Roese8ab5a1b2017-03-20 12:51:50 +0100126 dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);
127
Simon Schwarz6a597b92012-03-15 04:01:45 +0000128 cleanup_before_linux();
129}
wdenkc6097192002-11-03 00:24:07 +0000130
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900131static void setup_start_tag (struct bd_info *bd)
wdenkc6097192002-11-03 00:24:07 +0000132{
Simon Schwarz6a597b92012-03-15 04:01:45 +0000133 params = (struct tag *)bd->bi_boot_params;
wdenkc6097192002-11-03 00:24:07 +0000134
wdenk86765902003-12-06 23:55:10 +0000135 params->hdr.tag = ATAG_CORE;
136 params->hdr.size = tag_size (tag_core);
wdenkc6097192002-11-03 00:24:07 +0000137
wdenk86765902003-12-06 23:55:10 +0000138 params->u.core.flags = 0;
139 params->u.core.pagesize = 0;
140 params->u.core.rootdev = 0;
wdenkc6097192002-11-03 00:24:07 +0000141
wdenk86765902003-12-06 23:55:10 +0000142 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000143}
wdenkc6097192002-11-03 00:24:07 +0000144
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900145static void setup_memory_tags(struct bd_info *bd)
wdenkc6097192002-11-03 00:24:07 +0000146{
wdenk86765902003-12-06 23:55:10 +0000147 int i;
wdenkc6097192002-11-03 00:24:07 +0000148
wdenk86765902003-12-06 23:55:10 +0000149 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
150 params->hdr.tag = ATAG_MEM;
151 params->hdr.size = tag_size (tag_mem32);
wdenkc6097192002-11-03 00:24:07 +0000152
wdenk86765902003-12-06 23:55:10 +0000153 params->u.mem.start = bd->bi_dram[i].start;
154 params->u.mem.size = bd->bi_dram[i].size;
wdenkc6097192002-11-03 00:24:07 +0000155
wdenk86765902003-12-06 23:55:10 +0000156 params = tag_next (params);
157 }
wdenkc6097192002-11-03 00:24:07 +0000158}
wdenkc6097192002-11-03 00:24:07 +0000159
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900160static void setup_commandline_tag(struct bd_info *bd, char *commandline)
wdenkc6097192002-11-03 00:24:07 +0000161{
wdenk86765902003-12-06 23:55:10 +0000162 char *p;
wdenkc6097192002-11-03 00:24:07 +0000163
wdenkf16b5162004-03-23 21:43:07 +0000164 if (!commandline)
165 return;
166
wdenk86765902003-12-06 23:55:10 +0000167 /* eat leading white space */
168 for (p = commandline; *p == ' '; p++);
wdenkc6097192002-11-03 00:24:07 +0000169
wdenk86765902003-12-06 23:55:10 +0000170 /* skip non-existent command lines so the kernel will still
171 * use its default command line.
172 */
173 if (*p == '\0')
174 return;
wdenkc6097192002-11-03 00:24:07 +0000175
wdenk86765902003-12-06 23:55:10 +0000176 params->hdr.tag = ATAG_CMDLINE;
177 params->hdr.size =
178 (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2;
wdenkc6097192002-11-03 00:24:07 +0000179
wdenk86765902003-12-06 23:55:10 +0000180 strcpy (params->u.cmdline.cmdline, p);
wdenkc6097192002-11-03 00:24:07 +0000181
wdenk86765902003-12-06 23:55:10 +0000182 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000183}
wdenkc6097192002-11-03 00:24:07 +0000184
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900185static void setup_initrd_tag(struct bd_info *bd, ulong initrd_start,
186 ulong initrd_end)
wdenkc6097192002-11-03 00:24:07 +0000187{
wdenk86765902003-12-06 23:55:10 +0000188 /* an ATAG_INITRD node tells the kernel where the compressed
189 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
190 */
wdenk19c8fb72004-04-18 22:26:17 +0000191 params->hdr.tag = ATAG_INITRD2;
wdenk86765902003-12-06 23:55:10 +0000192 params->hdr.size = tag_size (tag_initrd);
wdenkc6097192002-11-03 00:24:07 +0000193
wdenk86765902003-12-06 23:55:10 +0000194 params->u.initrd.start = initrd_start;
195 params->u.initrd.size = initrd_end - initrd_start;
wdenkc6097192002-11-03 00:24:07 +0000196
wdenk86765902003-12-06 23:55:10 +0000197 params = tag_next (params);
wdenkc6097192002-11-03 00:24:07 +0000198}
wdenkc6097192002-11-03 00:24:07 +0000199
Simon Glass50ad2212013-05-08 08:06:02 +0000200static void setup_serial_tag(struct tag **tmp)
wdenka21ad7b2005-05-19 22:39:42 +0000201{
202 struct tag *params = *tmp;
203 struct tag_serialnr serialnr;
wdenka21ad7b2005-05-19 22:39:42 +0000204
205 get_board_serial(&serialnr);
206 params->hdr.tag = ATAG_SERIAL;
207 params->hdr.size = tag_size (tag_serialnr);
208 params->u.serialnr.low = serialnr.low;
209 params->u.serialnr.high= serialnr.high;
210 params = tag_next (params);
211 *tmp = params;
212}
wdenka21ad7b2005-05-19 22:39:42 +0000213
Simon Glass50ad2212013-05-08 08:06:02 +0000214static void setup_revision_tag(struct tag **in_params)
wdenkcb99da52005-01-12 00:15:14 +0000215{
216 u32 rev = 0;
wdenkcb99da52005-01-12 00:15:14 +0000217
218 rev = get_board_rev();
wdenkcb99da52005-01-12 00:15:14 +0000219 params->hdr.tag = ATAG_REVISION;
220 params->hdr.size = tag_size (tag_revision);
221 params->u.revision.rev = rev;
222 params = tag_next (params);
223}
wdenkcb99da52005-01-12 00:15:14 +0000224
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900225static void setup_end_tag(struct bd_info *bd)
wdenkc6097192002-11-03 00:24:07 +0000226{
wdenk86765902003-12-06 23:55:10 +0000227 params->hdr.tag = ATAG_NONE;
228 params->hdr.size = 0;
wdenkc6097192002-11-03 00:24:07 +0000229}
Simon Schwarz6a597b92012-03-15 04:01:45 +0000230
Pali Rohár5ebe4f12012-10-19 02:00:04 +0000231__weak void setup_board_tags(struct tag **in_params) {}
232
Marc Zyngier855ca662014-07-12 14:24:03 +0100233#ifdef CONFIG_ARM64
Andre Przywarafe7d9252013-09-19 18:06:43 +0200234static void do_nonsec_virt_switch(void)
235{
David Feng85fd5f12013-12-14 11:47:35 +0800236 smp_kick_all_cpus();
York Sun1ce575f2015-01-06 13:18:42 -0800237 dcache_disable(); /* flush cache before swtiching to EL2 */
Andre Przywarafe7d9252013-09-19 18:06:43 +0200238}
Marc Zyngier855ca662014-07-12 14:24:03 +0100239#endif
Andre Przywarafe7d9252013-09-19 18:06:43 +0200240
Lokesh Vutlab1f1b232019-10-07 13:52:15 +0530241__weak void board_prep_linux(bootm_headers_t *images) { }
242
Simon Schwarz6a597b92012-03-15 04:01:45 +0000243/* Subcommand: PREP */
244static void boot_prep_linux(bootm_headers_t *images)
245{
Simon Glass64b723f2017-08-03 12:22:12 -0600246 char *commandline = env_get("bootargs");
Simon Schwarz6a597b92012-03-15 04:01:45 +0000247
Simon Glass50ad2212013-05-08 08:06:02 +0000248 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len) {
Simon Schwarz6a597b92012-03-15 04:01:45 +0000249#ifdef CONFIG_OF_LIBFDT
Simon Schwarz6a597b92012-03-15 04:01:45 +0000250 debug("using: FDT\n");
Simon Glass653909f2013-05-08 08:06:03 +0000251 if (image_setup_linux(images)) {
Simon Schwarz6a597b92012-03-15 04:01:45 +0000252 printf("FDT creation failed! hanging...");
253 hang();
254 }
Simon Schwarz6a597b92012-03-15 04:01:45 +0000255#endif
Simon Glass50ad2212013-05-08 08:06:02 +0000256 } else if (BOOTM_ENABLE_TAGS) {
Simon Schwarz6a597b92012-03-15 04:01:45 +0000257 debug("using: ATAGS\n");
258 setup_start_tag(gd->bd);
Simon Glass50ad2212013-05-08 08:06:02 +0000259 if (BOOTM_ENABLE_SERIAL_TAG)
260 setup_serial_tag(&params);
261 if (BOOTM_ENABLE_CMDLINE_TAG)
262 setup_commandline_tag(gd->bd, commandline);
263 if (BOOTM_ENABLE_REVISION_TAG)
264 setup_revision_tag(&params);
265 if (BOOTM_ENABLE_MEMORY_TAGS)
266 setup_memory_tags(gd->bd);
267 if (BOOTM_ENABLE_INITRD_TAG) {
Jeffy Chen113094e2016-01-14 10:19:36 +0800268 /*
269 * In boot_ramdisk_high(), it may relocate ramdisk to
270 * a specified location. And set images->initrd_start &
271 * images->initrd_end to relocated ramdisk's start/end
272 * addresses. So use them instead of images->rd_start &
273 * images->rd_end when possible.
274 */
275 if (images->initrd_start && images->initrd_end) {
276 setup_initrd_tag(gd->bd, images->initrd_start,
277 images->initrd_end);
278 } else if (images->rd_start && images->rd_end) {
Simon Glass50ad2212013-05-08 08:06:02 +0000279 setup_initrd_tag(gd->bd, images->rd_start,
280 images->rd_end);
281 }
282 }
Pali Rohár5ebe4f12012-10-19 02:00:04 +0000283 setup_board_tags(&params);
Simon Schwarz6a597b92012-03-15 04:01:45 +0000284 setup_end_tag(gd->bd);
Simon Glass50ad2212013-05-08 08:06:02 +0000285 } else {
Simon Schwarz6a597b92012-03-15 04:01:45 +0000286 printf("FDT and ATAGS support not compiled in - hanging\n");
287 hang();
Simon Schwarz6a597b92012-03-15 04:01:45 +0000288 }
Lokesh Vutlab1f1b232019-10-07 13:52:15 +0530289
290 board_prep_linux(images);
Simon Schwarz6a597b92012-03-15 04:01:45 +0000291}
292
Jon Medhurst \(Tixy\)413ca3d2016-06-23 13:37:32 +0100293__weak bool armv7_boot_nonsec_default(void)
Hans de Goede63fb5482014-11-14 09:34:31 +0100294{
Hans de Goede63fb5482014-11-14 09:34:31 +0100295#ifdef CONFIG_ARMV7_BOOT_SEC_DEFAULT
Jon Medhurst \(Tixy\)413ca3d2016-06-23 13:37:32 +0100296 return false;
Hans de Goede63fb5482014-11-14 09:34:31 +0100297#else
Jon Medhurst \(Tixy\)413ca3d2016-06-23 13:37:32 +0100298 return true;
Hans de Goede63fb5482014-11-14 09:34:31 +0100299#endif
Jon Medhurst \(Tixy\)413ca3d2016-06-23 13:37:32 +0100300}
301
302#ifdef CONFIG_ARMV7_NONSEC
303bool armv7_boot_nonsec(void)
304{
Simon Glass64b723f2017-08-03 12:22:12 -0600305 char *s = env_get("bootm_boot_mode");
Jon Medhurst \(Tixy\)413ca3d2016-06-23 13:37:32 +0100306 bool nonsec = armv7_boot_nonsec_default();
Hans de Goede63fb5482014-11-14 09:34:31 +0100307
308 if (s && !strcmp(s, "sec"))
309 nonsec = false;
310
311 if (s && !strcmp(s, "nonsec"))
312 nonsec = true;
313
314 return nonsec;
315}
316#endif
317
Alison Wang73818d52016-11-10 10:49:03 +0800318#ifdef CONFIG_ARM64
Alison Wang876c7e12016-11-10 10:49:04 +0800319__weak void update_os_arch_secondary_cores(uint8_t os_arch)
320{
321}
322
Alison Wang73818d52016-11-10 10:49:03 +0800323#ifdef CONFIG_ARMV8_SWITCH_TO_EL1
324static void switch_to_el1(void)
325{
326 if ((IH_ARCH_DEFAULT == IH_ARCH_ARM64) &&
327 (images.os.arch == IH_ARCH_ARM))
328 armv8_switch_to_el1(0, (u64)gd->bd->bi_arch_number,
Alison Wangeb2088d2017-01-17 09:39:17 +0800329 (u64)images.ft_addr, 0,
Alison Wang73818d52016-11-10 10:49:03 +0800330 (u64)images.ep,
331 ES_TO_AARCH32);
332 else
Alison Wangeb2088d2017-01-17 09:39:17 +0800333 armv8_switch_to_el1((u64)images.ft_addr, 0, 0, 0,
Alison Wang73818d52016-11-10 10:49:03 +0800334 images.ep,
335 ES_TO_AARCH64);
336}
337#endif
338#endif
339
Simon Schwarz6a597b92012-03-15 04:01:45 +0000340/* Subcommand: GO */
Simon Glass3c26c582013-06-19 21:15:10 -0700341static void boot_jump_linux(bootm_headers_t *images, int flag)
Simon Schwarz6a597b92012-03-15 04:01:45 +0000342{
David Feng85fd5f12013-12-14 11:47:35 +0800343#ifdef CONFIG_ARM64
Tom Rini67d604e2014-08-14 06:42:35 -0400344 void (*kernel_entry)(void *fdt_addr, void *res0, void *res1,
345 void *res2);
David Feng85fd5f12013-12-14 11:47:35 +0800346 int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
347
Tom Rini67d604e2014-08-14 06:42:35 -0400348 kernel_entry = (void (*)(void *fdt_addr, void *res0, void *res1,
349 void *res2))images->ep;
David Feng85fd5f12013-12-14 11:47:35 +0800350
351 debug("## Transferring control to Linux (at address %lx)...\n",
352 (ulong) kernel_entry);
353 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
354
355 announce_and_cleanup(fake);
356
Marc Zyngier915a09e2014-07-12 14:23:58 +0100357 if (!fake) {
macro.wave.z@gmail.com05725ed2016-12-08 11:58:25 +0800358#ifdef CONFIG_ARMV8_PSCI
359 armv8_setup_psci();
360#endif
Marc Zyngier915a09e2014-07-12 14:23:58 +0100361 do_nonsec_virt_switch();
Alison Wang73818d52016-11-10 10:49:03 +0800362
Alison Wang876c7e12016-11-10 10:49:04 +0800363 update_os_arch_secondary_cores(images->os.arch);
364
Alison Wang73818d52016-11-10 10:49:03 +0800365#ifdef CONFIG_ARMV8_SWITCH_TO_EL1
Alison Wangeb2088d2017-01-17 09:39:17 +0800366 armv8_switch_to_el2((u64)images->ft_addr, 0, 0, 0,
Alison Wang73818d52016-11-10 10:49:03 +0800367 (u64)switch_to_el1, ES_TO_AARCH64);
368#else
369 if ((IH_ARCH_DEFAULT == IH_ARCH_ARM64) &&
370 (images->os.arch == IH_ARCH_ARM))
371 armv8_switch_to_el2(0, (u64)gd->bd->bi_arch_number,
Alison Wangeb2088d2017-01-17 09:39:17 +0800372 (u64)images->ft_addr, 0,
Alison Wang73818d52016-11-10 10:49:03 +0800373 (u64)images->ep,
374 ES_TO_AARCH32);
375 else
Alison Wangeb2088d2017-01-17 09:39:17 +0800376 armv8_switch_to_el2((u64)images->ft_addr, 0, 0, 0,
Alison Wang73818d52016-11-10 10:49:03 +0800377 images->ep,
378 ES_TO_AARCH64);
379#endif
Marc Zyngier915a09e2014-07-12 14:23:58 +0100380 }
David Feng85fd5f12013-12-14 11:47:35 +0800381#else
Simon Schwarz6a597b92012-03-15 04:01:45 +0000382 unsigned long machid = gd->bd->bi_arch_number;
383 char *s;
384 void (*kernel_entry)(int zero, int arch, uint params);
Stephen Warrenc570fba2012-04-19 11:34:00 +0000385 unsigned long r2;
Simon Glass3c26c582013-06-19 21:15:10 -0700386 int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
Simon Schwarz6a597b92012-03-15 04:01:45 +0000387
388 kernel_entry = (void (*)(int, int, uint))images->ep;
Patrice Chotardffb3c0b2017-04-25 11:07:46 +0200389#ifdef CONFIG_CPU_V7M
390 ulong addr = (ulong)kernel_entry | 1;
391 kernel_entry = (void *)addr;
392#endif
Simon Glass64b723f2017-08-03 12:22:12 -0600393 s = env_get("machid");
Simon Schwarz6a597b92012-03-15 04:01:45 +0000394 if (s) {
Peng Fanc4485e72015-11-24 16:54:20 +0800395 if (strict_strtoul(s, 16, &machid) < 0) {
396 debug("strict_strtoul failed!\n");
397 return;
398 }
Simon Schwarz6a597b92012-03-15 04:01:45 +0000399 printf("Using machid 0x%lx from environment\n", machid);
400 }
401
402 debug("## Transferring control to Linux (at address %08lx)" \
403 "...\n", (ulong) kernel_entry);
404 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
Simon Glass3c26c582013-06-19 21:15:10 -0700405 announce_and_cleanup(fake);
Stephen Warrenc570fba2012-04-19 11:34:00 +0000406
Simon Glass50ad2212013-05-08 08:06:02 +0000407 if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len)
Stephen Warrenc570fba2012-04-19 11:34:00 +0000408 r2 = (unsigned long)images->ft_addr;
409 else
Stephen Warrenc570fba2012-04-19 11:34:00 +0000410 r2 = gd->bd->bi_boot_params;
411
Marc Zyngier915a09e2014-07-12 14:23:58 +0100412 if (!fake) {
Jan Kiszkaac31b5a2015-04-21 07:18:24 +0200413#ifdef CONFIG_ARMV7_NONSEC
Ian Campbell68bc8f52014-12-21 09:45:11 +0000414 if (armv7_boot_nonsec()) {
Hans de Goede63fb5482014-11-14 09:34:31 +0100415 armv7_init_nonsec();
416 secure_ram_addr(_do_nonsec_entry)(kernel_entry,
417 0, machid, r2);
418 } else
Marc Zyngier855ca662014-07-12 14:24:03 +0100419#endif
Hans de Goede63fb5482014-11-14 09:34:31 +0100420 kernel_entry(0, machid, r2);
Marc Zyngier915a09e2014-07-12 14:23:58 +0100421 }
David Feng85fd5f12013-12-14 11:47:35 +0800422#endif
Simon Schwarz6a597b92012-03-15 04:01:45 +0000423}
424
425/* Main Entry point for arm bootm implementation
426 *
427 * Modeled after the powerpc implementation
428 * DIFFERENCE: Instead of calling prep and go at the end
429 * they are called if subcommand is equal 0.
430 */
Simon Glassed38aef2020-05-10 11:40:03 -0600431int do_bootm_linux(int flag, int argc, char *const argv[],
Eric Nelsonb7c236b2014-09-30 15:40:01 -0700432 bootm_headers_t *images)
Simon Schwarz6a597b92012-03-15 04:01:45 +0000433{
434 /* No need for those on ARM */
435 if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE)
436 return -1;
437
438 if (flag & BOOTM_STATE_OS_PREP) {
439 boot_prep_linux(images);
440 return 0;
441 }
442
Simon Glass3c26c582013-06-19 21:15:10 -0700443 if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
444 boot_jump_linux(images, flag);
Simon Schwarz6a597b92012-03-15 04:01:45 +0000445 return 0;
446 }
447
448 boot_prep_linux(images);
Simon Glass3c26c582013-06-19 21:15:10 -0700449 boot_jump_linux(images, flag);
Simon Schwarz6a597b92012-03-15 04:01:45 +0000450 return 0;
John Rigbyab51f1e2010-10-13 13:57:36 -0600451}
Marek Vasutcf41a9b2012-03-14 21:52:45 +0000452
Miao Yan1bd54562013-11-28 17:51:38 +0800453#if defined(CONFIG_BOOTM_VXWORKS)
454void boot_prep_vxworks(bootm_headers_t *images)
455{
456#if defined(CONFIG_OF_LIBFDT)
457 int off;
458
459 if (images->ft_addr) {
460 off = fdt_path_offset(images->ft_addr, "/memory");
Hannes Schmelzer64fabcc2018-05-04 10:49:11 +0200461 if (off > 0) {
Ma Haijun62358242014-07-12 14:24:06 +0100462 if (arch_fixup_fdt(images->ft_addr))
Miao Yan1bd54562013-11-28 17:51:38 +0800463 puts("## WARNING: fixup memory failed!\n");
464 }
465 }
466#endif
467 cleanup_before_linux();
468}
469void boot_jump_vxworks(bootm_headers_t *images)
470{
Vasyl Vavrychuk70b551c2018-04-10 12:36:36 +0300471#if defined(CONFIG_ARM64) && defined(CONFIG_ARMV8_PSCI)
472 armv8_setup_psci();
473 smp_kick_all_cpus();
474#endif
475
Miao Yan1bd54562013-11-28 17:51:38 +0800476 /* ARM VxWorks requires device tree physical address to be passed */
477 ((void (*)(void *))images->ep)(images->ft_addr);
478}
479#endif