blob: de5058236e0a03dbad1e0706b124499d75edfb93 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Tom Rini5db28902016-08-12 08:31:15 -04002/*
3 * (C) Copyright 2000-2009
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Tom Rini5db28902016-08-12 08:31:15 -04005 */
6
7#include <common.h>
8#include <bootm.h>
9#include <command.h>
10#include <image.h>
Simon Glass36bf4462019-11-14 12:57:42 -070011#include <irq_func.h>
Tom Rini5db28902016-08-12 08:31:15 -040012#include <lmb.h>
13#include <mapmem.h>
Masahiro Yamada28085762017-03-09 16:28:25 +090014#include <linux/kernel.h>
15#include <linux/sizes.h>
Tom Rini5db28902016-08-12 08:31:15 -040016
Tom Rini5db28902016-08-12 08:31:15 -040017/*
18 * Image booting support
19 */
20static int booti_start(cmd_tbl_t *cmdtp, int flag, int argc,
21 char * const argv[], bootm_headers_t *images)
22{
23 int ret;
Bin Chen6808ef92018-01-27 16:59:09 +110024 ulong ld;
25 ulong relocated_addr;
26 ulong image_size;
Tom Rini5db28902016-08-12 08:31:15 -040027
28 ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
29 images, 1);
30
31 /* Setup Linux kernel Image entry point */
32 if (!argc) {
Simon Glassbb872dd2019-12-28 10:45:02 -070033 ld = image_load_addr;
Tom Rini5db28902016-08-12 08:31:15 -040034 debug("* kernel: default image load address = 0x%08lx\n",
Simon Glassbb872dd2019-12-28 10:45:02 -070035 image_load_addr);
Tom Rini5db28902016-08-12 08:31:15 -040036 } else {
Bin Chen6808ef92018-01-27 16:59:09 +110037 ld = simple_strtoul(argv[0], NULL, 16);
Masahiro Yamadabf14d9a2018-02-13 12:10:02 +090038 debug("* kernel: cmdline image address = 0x%08lx\n", ld);
Tom Rini5db28902016-08-12 08:31:15 -040039 }
40
Marek Vasut7f13b372018-06-13 06:13:32 +020041 ret = booti_setup(ld, &relocated_addr, &image_size, false);
Tom Rini5db28902016-08-12 08:31:15 -040042 if (ret != 0)
43 return 1;
44
Bin Chen6808ef92018-01-27 16:59:09 +110045 /* Handle BOOTM_STATE_LOADOS */
46 if (relocated_addr != ld) {
47 debug("Moving Image from 0x%lx to 0x%lx\n", ld, relocated_addr);
48 memmove((void *)relocated_addr, (void *)ld, image_size);
49 }
Tom Rini5db28902016-08-12 08:31:15 -040050
Bin Chen6808ef92018-01-27 16:59:09 +110051 images->ep = relocated_addr;
Lokesh Vutla683cdd62019-10-07 13:52:16 +053052 images->os.start = relocated_addr;
53 images->os.end = relocated_addr + image_size;
54
Bin Chen6808ef92018-01-27 16:59:09 +110055 lmb_reserve(&images->lmb, images->ep, le32_to_cpu(image_size));
Tom Rini5db28902016-08-12 08:31:15 -040056
57 /*
58 * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
59 * have a header that provide this informaiton.
60 */
61 if (bootm_find_images(flag, argc, argv))
62 return 1;
63
64 return 0;
65}
66
67int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
68{
69 int ret;
70
71 /* Consume 'booti' */
72 argc--; argv++;
73
74 if (booti_start(cmdtp, flag, argc, argv, &images))
75 return 1;
76
77 /*
78 * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
79 * disable interrupts ourselves
80 */
81 bootm_disable_interrupts();
82
83 images.os.os = IH_OS_LINUX;
Atish Patra3cedc972019-05-06 17:49:39 -070084#ifdef CONFIG_RISCV_SMODE
85 images.os.arch = IH_ARCH_RISCV;
86#elif CONFIG_ARM64
Scott Wood0fff19a2017-01-26 16:55:44 -060087 images.os.arch = IH_ARCH_ARM64;
Atish Patra3cedc972019-05-06 17:49:39 -070088#endif
Tom Rini5db28902016-08-12 08:31:15 -040089 ret = do_bootm_states(cmdtp, flag, argc, argv,
Cédric Schieli4943dc22017-01-23 16:51:45 +010090#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
91 BOOTM_STATE_RAMDISK |
92#endif
Tom Rini5db28902016-08-12 08:31:15 -040093 BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
94 BOOTM_STATE_OS_GO,
95 &images, 1);
96
97 return ret;
98}
99
100#ifdef CONFIG_SYS_LONGHELP
101static char booti_help_text[] =
102 "[addr [initrd[:size]] [fdt]]\n"
Atish Patra3cedc972019-05-06 17:49:39 -0700103 " - boot Linux 'Image' stored at 'addr'\n"
Tom Rini5db28902016-08-12 08:31:15 -0400104 "\tThe argument 'initrd' is optional and specifies the address\n"
105 "\tof an initrd in memory. The optional parameter ':size' allows\n"
106 "\tspecifying the size of a RAW initrd.\n"
107#if defined(CONFIG_OF_LIBFDT)
108 "\tSince booting a Linux kernel requires a flat device-tree, a\n"
109 "\tthird argument providing the address of the device-tree blob\n"
110 "\tis required. To boot a kernel with a device-tree blob but\n"
111 "\twithout an initrd image, use a '-' for the initrd argument.\n"
112#endif
113 "";
114#endif
115
116U_BOOT_CMD(
117 booti, CONFIG_SYS_MAXARGS, 1, do_booti,
Atish Patra3cedc972019-05-06 17:49:39 -0700118 "boot Linux kernel 'Image' format from memory", booti_help_text
Tom Rini5db28902016-08-12 08:31:15 -0400119);