2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2002-11-18 00:14:45 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2002
|
|
|
|
* Sysgo Real-Time Solutions, GmbH <www.elinos.com>
|
|
|
|
* Marius Groeger <mgroeger@sysgo.de>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-05-10 17:40:00 +00:00
|
|
|
#include <bootstage.h>
|
2002-11-18 00:14:45 +00:00
|
|
|
#include <command.h>
|
2023-03-19 19:30:09 +00:00
|
|
|
#include <efi.h>
|
2019-12-28 17:45:07 +00:00
|
|
|
#include <hang.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2017-04-24 07:48:03 +00:00
|
|
|
#include <dm/device.h>
|
|
|
|
#include <dm/root.h>
|
2014-10-10 14:21:56 +00:00
|
|
|
#include <errno.h>
|
2014-10-20 03:11:20 +00:00
|
|
|
#include <fdt_support.h>
|
2002-11-18 00:14:45 +00:00
|
|
|
#include <image.h>
|
2009-04-04 10:49:11 +00:00
|
|
|
#include <u-boot/zlib.h>
|
2011-12-05 12:09:26 +00:00
|
|
|
#include <asm/bootparam.h>
|
2014-10-10 14:21:58 +00:00
|
|
|
#include <asm/cpu.h>
|
2002-11-18 00:14:45 +00:00
|
|
|
#include <asm/byteorder.h>
|
|
|
|
#include <asm/zimage.h>
|
2014-10-20 03:11:20 +00:00
|
|
|
#ifdef CONFIG_SYS_COREBOOT
|
|
|
|
#include <asm/arch/timestamp.h>
|
|
|
|
#endif
|
2002-11-18 00:14:45 +00:00
|
|
|
|
2015-07-31 15:31:31 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2011-12-05 12:09:26 +00:00
|
|
|
#define COMMAND_LINE_OFFSET 0x9000
|
|
|
|
|
2014-10-20 03:11:20 +00:00
|
|
|
void bootm_announce_and_cleanup(void)
|
|
|
|
{
|
|
|
|
printf("\nStarting kernel ...\n\n");
|
|
|
|
|
|
|
|
#ifdef CONFIG_SYS_COREBOOT
|
2021-03-15 05:00:20 +00:00
|
|
|
timestamp_add_now(TS_START_KERNEL);
|
2014-10-20 03:11:20 +00:00
|
|
|
#endif
|
|
|
|
bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
|
2023-02-05 22:36:20 +00:00
|
|
|
#if IS_ENABLED(CONFIG_BOOTSTAGE_REPORT)
|
2014-10-20 03:11:20 +00:00
|
|
|
bootstage_report();
|
2008-03-12 09:33:00 +00:00
|
|
|
#endif
|
2017-04-24 07:48:03 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Call remove function of all devices with a removal flag set.
|
|
|
|
* This may be useful for last-stage operations, like cancelling
|
|
|
|
* of DMA operation or releasing device internal buffers.
|
|
|
|
*/
|
|
|
|
dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);
|
2014-10-20 03:11:20 +00:00
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2014-10-20 03:11:20 +00:00
|
|
|
#if defined(CONFIG_OF_LIBFDT) && !defined(CONFIG_OF_NO_KERNEL)
|
|
|
|
int arch_fixup_memory_node(void *blob)
|
|
|
|
{
|
2020-06-26 06:13:33 +00:00
|
|
|
struct bd_info *bd = gd->bd;
|
2014-10-20 03:11:20 +00:00
|
|
|
int bank;
|
|
|
|
u64 start[CONFIG_NR_DRAM_BANKS];
|
|
|
|
u64 size[CONFIG_NR_DRAM_BANKS];
|
|
|
|
|
|
|
|
for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
|
|
|
|
start[bank] = bd->bi_dram[bank].start;
|
|
|
|
size[bank] = bd->bi_dram[bank].size;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fdt_fixup_memory_banks(blob, start, size, CONFIG_NR_DRAM_BANKS);
|
|
|
|
}
|
|
|
|
#endif
|
bootm: Add subcommands
Add the ability to break the steps of the bootm command into several
subcommands: start, loados, ramdisk, fdt, bdt, cmdline, prep, go.
This allows us to do things like manipulate device trees before
they are passed to a booting kernel or setup memory for a secondary
core in multicore situations.
Not all OS types support all subcommands (currently only start, loados,
ramdisk, fdt, and go are supported).
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
2008-10-21 22:25:45 +00:00
|
|
|
|
2014-10-20 03:11:20 +00:00
|
|
|
/* Subcommand: PREP */
|
2022-09-07 02:26:50 +00:00
|
|
|
static int boot_prep_linux(struct bootm_headers *images)
|
2014-10-20 03:11:20 +00:00
|
|
|
{
|
|
|
|
char *cmd_line_dest = NULL;
|
2022-09-07 02:26:52 +00:00
|
|
|
struct legacy_img_hdr *hdr;
|
2014-10-20 03:11:20 +00:00
|
|
|
int is_zimage = 0;
|
|
|
|
void *data = NULL;
|
|
|
|
size_t len;
|
|
|
|
int ret;
|
|
|
|
|
2023-02-05 22:40:13 +00:00
|
|
|
if (CONFIG_IS_ENABLED(OF_LIBFDT) && IS_ENABLED(CONFIG_LMB) && images->ft_len) {
|
2014-10-20 03:11:20 +00:00
|
|
|
debug("using: FDT\n");
|
|
|
|
if (image_setup_linux(images)) {
|
|
|
|
puts("FDT creation failed! hanging...");
|
|
|
|
hang();
|
|
|
|
}
|
|
|
|
}
|
2022-07-07 08:45:37 +00:00
|
|
|
|
2008-02-04 07:28:09 +00:00
|
|
|
if (images->legacy_hdr_valid) {
|
|
|
|
hdr = images->legacy_hdr_os;
|
2011-11-08 02:33:15 +00:00
|
|
|
if (image_check_type(hdr, IH_TYPE_MULTI)) {
|
2014-10-20 03:11:20 +00:00
|
|
|
ulong os_data, os_len;
|
|
|
|
|
2008-02-04 07:28:09 +00:00
|
|
|
/* if multi-part image, we need to get first subimage */
|
2011-11-08 02:33:15 +00:00
|
|
|
image_multi_getimg(hdr, 0, &os_data, &os_len);
|
2014-10-20 03:11:20 +00:00
|
|
|
data = (void *)os_data;
|
|
|
|
len = os_len;
|
2008-02-04 07:28:09 +00:00
|
|
|
} else {
|
|
|
|
/* otherwise get image data */
|
2014-10-20 03:11:20 +00:00
|
|
|
data = (void *)image_get_data(hdr);
|
|
|
|
len = image_get_data_size(hdr);
|
2008-02-04 07:28:09 +00:00
|
|
|
}
|
2014-10-20 03:11:20 +00:00
|
|
|
is_zimage = 1;
|
2008-02-04 07:28:09 +00:00
|
|
|
#if defined(CONFIG_FIT)
|
2017-11-23 17:59:45 +00:00
|
|
|
} else if (images->fit_uname_os && is_zimage) {
|
2011-11-08 02:33:15 +00:00
|
|
|
ret = fit_image_get_data(images->fit_hdr_os,
|
2014-10-20 03:11:20 +00:00
|
|
|
images->fit_noffset_os,
|
|
|
|
(const void **)&data, &len);
|
2008-03-12 09:33:00 +00:00
|
|
|
if (ret) {
|
2011-11-08 02:33:15 +00:00
|
|
|
puts("Can't get image data/size!\n");
|
2008-03-12 09:33:00 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2014-10-20 03:11:20 +00:00
|
|
|
is_zimage = 1;
|
2008-02-04 07:28:09 +00:00
|
|
|
#endif
|
2006-07-21 09:30:18 +00:00
|
|
|
}
|
|
|
|
|
2014-10-20 03:11:20 +00:00
|
|
|
if (is_zimage) {
|
2014-10-10 14:21:56 +00:00
|
|
|
ulong load_address;
|
2014-10-20 03:11:20 +00:00
|
|
|
char *base_ptr;
|
2002-11-18 00:14:45 +00:00
|
|
|
|
2014-10-20 03:11:20 +00:00
|
|
|
base_ptr = (char *)load_zimage(data, len, &load_address);
|
2018-10-11 05:44:42 +00:00
|
|
|
if (!base_ptr) {
|
|
|
|
puts("## Kernel loading failed ...\n");
|
|
|
|
goto error;
|
|
|
|
}
|
2014-10-10 14:21:56 +00:00
|
|
|
images->os.load = load_address;
|
2014-10-20 03:11:20 +00:00
|
|
|
cmd_line_dest = base_ptr + COMMAND_LINE_OFFSET;
|
|
|
|
images->ep = (ulong)base_ptr;
|
|
|
|
} else if (images->ep) {
|
|
|
|
cmd_line_dest = (void *)images->ep + COMMAND_LINE_OFFSET;
|
|
|
|
} else {
|
2014-10-10 14:21:59 +00:00
|
|
|
printf("## Kernel loading failed (missing x86 kernel setup) ...\n");
|
2008-03-12 09:33:00 +00:00
|
|
|
goto error;
|
2011-12-05 12:09:26 +00:00
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2014-10-20 03:11:20 +00:00
|
|
|
printf("Setup at %#08lx\n", images->ep);
|
|
|
|
ret = setup_zimage((void *)images->ep, cmd_line_dest,
|
2011-12-05 12:09:26 +00:00
|
|
|
0, images->rd_start,
|
2020-09-05 20:50:51 +00:00
|
|
|
images->rd_end - images->rd_start, 0);
|
2014-10-20 03:11:20 +00:00
|
|
|
|
|
|
|
if (ret) {
|
2011-12-05 12:09:26 +00:00
|
|
|
printf("## Setting up boot parameters failed ...\n");
|
2014-10-20 03:11:20 +00:00
|
|
|
return 1;
|
2002-11-18 00:14:45 +00:00
|
|
|
}
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2014-10-20 03:11:20 +00:00
|
|
|
return 0;
|
2002-11-18 00:14:45 +00:00
|
|
|
|
2008-03-12 09:33:00 +00:00
|
|
|
error:
|
2008-08-15 13:24:45 +00:00
|
|
|
return 1;
|
2003-06-27 21:31:46 +00:00
|
|
|
}
|
2014-10-20 03:11:20 +00:00
|
|
|
|
2023-03-19 19:30:08 +00:00
|
|
|
int boot_linux_kernel(ulong setup_base, ulong entry, bool image_64bit)
|
2014-10-10 14:21:56 +00:00
|
|
|
{
|
|
|
|
bootm_announce_and_cleanup();
|
|
|
|
|
|
|
|
#ifdef CONFIG_SYS_COREBOOT
|
|
|
|
timestamp_add_now(TS_U_BOOT_START_KERNEL);
|
|
|
|
#endif
|
2023-03-19 19:30:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Exit EFI boot services just before jumping, after all console
|
|
|
|
* output, since the console won't be available afterwards.
|
|
|
|
*/
|
|
|
|
if (IS_ENABLED(CONFIG_EFI_APP)) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = efi_store_memory_map(efi_get_priv());
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
printf("Exiting EFI boot services\n");
|
|
|
|
ret = efi_call_exit_boot_services();
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-10-10 14:21:56 +00:00
|
|
|
if (image_64bit) {
|
2014-10-10 14:21:58 +00:00
|
|
|
if (!cpu_has_64bit()) {
|
|
|
|
puts("Cannot boot 64-bit kernel on 32-bit machine\n");
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
2023-03-19 19:30:08 +00:00
|
|
|
/*
|
|
|
|
* At present 64-bit U-Boot only supports booting a 64-bit
|
2017-01-16 14:04:10 +00:00
|
|
|
* kernel.
|
2023-03-19 19:30:08 +00:00
|
|
|
*
|
|
|
|
* TODO(sjg@chromium.org): Support booting 32-bit kernels from
|
|
|
|
* 64-bit U-Boot
|
2017-01-16 14:04:10 +00:00
|
|
|
*/
|
2023-03-19 19:30:08 +00:00
|
|
|
if (CONFIG_IS_ENABLED(X86_64)) {
|
|
|
|
typedef void (*h_func)(ulong zero, ulong setup);
|
|
|
|
h_func func;
|
|
|
|
|
|
|
|
/* jump to Linux with rdi=0, rsi=setup_base */
|
|
|
|
func = (h_func)entry;
|
|
|
|
func(0, setup_base);
|
|
|
|
} else {
|
|
|
|
return cpu_jump_to_64bit(setup_base, entry);
|
|
|
|
}
|
2014-10-10 14:21:56 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Set %ebx, %ebp, and %edi to 0, %esi to point to the
|
|
|
|
* boot_params structure, and then jump to the kernel. We
|
|
|
|
* assume that %cs is 0x10, 4GB flat, and read/execute, and
|
|
|
|
* the data segments are 0x18, 4GB flat, and read/write.
|
2016-02-06 03:30:11 +00:00
|
|
|
* U-Boot is setting them up that way for itself in
|
2014-10-10 14:21:56 +00:00
|
|
|
* arch/i386/cpu/cpu.c.
|
2015-08-04 18:34:00 +00:00
|
|
|
*
|
2021-12-29 18:57:38 +00:00
|
|
|
* Note: this is incomplete for EFI kernels!
|
|
|
|
*
|
|
|
|
* This can boot a kernel while running as an EFI application,
|
|
|
|
* but if the kernel requires EFI support then that support needs
|
|
|
|
* to be enabled first (see EFI_LOADER). Also the EFI information
|
|
|
|
* must enabled with setup_efi_info(). See setup_zimage() for
|
|
|
|
* how this is done with the stub.
|
2014-10-10 14:21:56 +00:00
|
|
|
*/
|
|
|
|
__asm__ __volatile__ (
|
|
|
|
"movl $0, %%ebp\n"
|
|
|
|
"cli\n"
|
|
|
|
"jmp *%[kernel_entry]\n"
|
2023-03-19 19:30:08 +00:00
|
|
|
:: [kernel_entry]"a"(entry),
|
2014-10-10 14:21:56 +00:00
|
|
|
[boot_params] "S"(setup_base),
|
|
|
|
"b"(0), "D"(0)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We can't get to here */
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
2014-10-20 03:11:20 +00:00
|
|
|
/* Subcommand: GO */
|
2022-09-07 02:26:50 +00:00
|
|
|
static int boot_jump_linux(struct bootm_headers *images)
|
2014-10-20 03:11:20 +00:00
|
|
|
{
|
|
|
|
debug("## Transferring control to Linux (at address %08lx, kernel %08lx) ...\n",
|
|
|
|
images->ep, images->os.load);
|
|
|
|
|
2014-10-10 14:21:58 +00:00
|
|
|
return boot_linux_kernel(images->ep, images->os.load,
|
|
|
|
images->os.arch == IH_ARCH_X86_64);
|
2014-10-20 03:11:20 +00:00
|
|
|
}
|
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
int do_bootm_linux(int flag, int argc, char *const argv[],
|
2022-09-07 02:26:50 +00:00
|
|
|
struct bootm_headers *images)
|
2014-10-20 03:11:20 +00:00
|
|
|
{
|
|
|
|
/* No need for those on x86 */
|
|
|
|
if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (flag & BOOTM_STATE_OS_PREP)
|
|
|
|
return boot_prep_linux(images);
|
|
|
|
|
2014-10-10 14:21:56 +00:00
|
|
|
if (flag & BOOTM_STATE_OS_GO)
|
|
|
|
return boot_jump_linux(images);
|
2014-10-20 03:11:20 +00:00
|
|
|
|
|
|
|
return boot_jump_linux(images);
|
|
|
|
}
|
2021-09-10 20:47:18 +00:00
|
|
|
|
|
|
|
static ulong get_sp(void)
|
|
|
|
{
|
|
|
|
ulong ret;
|
|
|
|
|
|
|
|
#if CONFIG_IS_ENABLED(X86_64)
|
2023-07-16 03:38:43 +00:00
|
|
|
asm("mov %%rsp, %0" : "=r"(ret) : );
|
2021-09-10 20:47:18 +00:00
|
|
|
#else
|
|
|
|
asm("mov %%esp, %0" : "=r"(ret) : );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void arch_lmb_reserve(struct lmb *lmb)
|
|
|
|
{
|
|
|
|
arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 4096);
|
|
|
|
}
|