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>
|
2019-12-28 17:45:07 +00:00
|
|
|
#include <hang.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.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
|
|
|
|
timestamp_add_now(TS_U_BOOT_START_KERNEL);
|
|
|
|
#endif
|
|
|
|
bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
|
2019-04-26 03:59:07 +00:00
|
|
|
#if CONFIG_IS_ENABLED(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 */
|
|
|
|
static int boot_prep_linux(bootm_headers_t *images)
|
|
|
|
{
|
|
|
|
char *cmd_line_dest = NULL;
|
|
|
|
image_header_t *hdr;
|
|
|
|
int is_zimage = 0;
|
|
|
|
void *data = NULL;
|
|
|
|
size_t len;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
#ifdef CONFIG_OF_LIBFDT
|
|
|
|
if (images->ft_len) {
|
|
|
|
debug("using: FDT\n");
|
|
|
|
if (image_setup_linux(images)) {
|
|
|
|
puts("FDT creation failed! hanging...");
|
|
|
|
hang();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
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
|
|
|
|
2014-10-10 14:21:56 +00:00
|
|
|
int boot_linux_kernel(ulong setup_base, ulong load_address, bool image_64bit)
|
|
|
|
{
|
|
|
|
bootm_announce_and_cleanup();
|
|
|
|
|
|
|
|
#ifdef CONFIG_SYS_COREBOOT
|
|
|
|
timestamp_add_now(TS_U_BOOT_START_KERNEL);
|
|
|
|
#endif
|
|
|
|
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;
|
|
|
|
}
|
2017-01-16 14:04:10 +00:00
|
|
|
/* At present 64-bit U-Boot does not support booting a
|
|
|
|
* kernel.
|
|
|
|
* TODO(sjg@chromium.org): Support booting both 32-bit and
|
|
|
|
* 64-bit kernels from 64-bit U-Boot.
|
|
|
|
*/
|
|
|
|
#if !CONFIG_IS_ENABLED(X86_64)
|
2014-10-10 14:21:58 +00:00
|
|
|
return cpu_jump_to_64bit(setup_base, load_address);
|
2017-01-16 14:04:10 +00:00
|
|
|
#endif
|
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
|
|
|
*
|
|
|
|
* Note that we cannot currently boot a kernel while running as
|
|
|
|
* an EFI application. Please use the payload option for that.
|
2014-10-10 14:21:56 +00:00
|
|
|
*/
|
2015-08-04 18:34:00 +00:00
|
|
|
#ifndef CONFIG_EFI_APP
|
2014-10-10 14:21:56 +00:00
|
|
|
__asm__ __volatile__ (
|
|
|
|
"movl $0, %%ebp\n"
|
|
|
|
"cli\n"
|
|
|
|
"jmp *%[kernel_entry]\n"
|
|
|
|
:: [kernel_entry]"a"(load_address),
|
|
|
|
[boot_params] "S"(setup_base),
|
|
|
|
"b"(0), "D"(0)
|
|
|
|
);
|
2015-08-04 18:34:00 +00:00
|
|
|
#endif
|
2014-10-10 14:21:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We can't get to here */
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
2014-10-20 03:11:20 +00:00
|
|
|
/* Subcommand: GO */
|
|
|
|
static int boot_jump_linux(bootm_headers_t *images)
|
|
|
|
{
|
|
|
|
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[],
|
|
|
|
bootm_headers_t *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);
|
|
|
|
}
|