blob: 841eff10d139641337de01a1aac061ed9105e56c [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>
11#include <lmb.h>
12#include <mapmem.h>
Masahiro Yamada28085762017-03-09 16:28:25 +090013#include <linux/kernel.h>
14#include <linux/sizes.h>
Tom Rini5db28902016-08-12 08:31:15 -040015
Tom Rini5db28902016-08-12 08:31:15 -040016/*
17 * Image booting support
18 */
19static int booti_start(cmd_tbl_t *cmdtp, int flag, int argc,
20 char * const argv[], bootm_headers_t *images)
21{
22 int ret;
Bin Chen6808ef92018-01-27 16:59:09 +110023 ulong ld;
24 ulong relocated_addr;
25 ulong image_size;
Tom Rini5db28902016-08-12 08:31:15 -040026
27 ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
28 images, 1);
29
30 /* Setup Linux kernel Image entry point */
31 if (!argc) {
Bin Chen6808ef92018-01-27 16:59:09 +110032 ld = load_addr;
Tom Rini5db28902016-08-12 08:31:15 -040033 debug("* kernel: default image load address = 0x%08lx\n",
34 load_addr);
35 } else {
Bin Chen6808ef92018-01-27 16:59:09 +110036 ld = simple_strtoul(argv[0], NULL, 16);
Masahiro Yamadabf14d9a2018-02-13 12:10:02 +090037 debug("* kernel: cmdline image address = 0x%08lx\n", ld);
Tom Rini5db28902016-08-12 08:31:15 -040038 }
39
Marek Vasut7f13b372018-06-13 06:13:32 +020040 ret = booti_setup(ld, &relocated_addr, &image_size, false);
Tom Rini5db28902016-08-12 08:31:15 -040041 if (ret != 0)
42 return 1;
43
Bin Chen6808ef92018-01-27 16:59:09 +110044 /* Handle BOOTM_STATE_LOADOS */
45 if (relocated_addr != ld) {
46 debug("Moving Image from 0x%lx to 0x%lx\n", ld, relocated_addr);
47 memmove((void *)relocated_addr, (void *)ld, image_size);
48 }
Tom Rini5db28902016-08-12 08:31:15 -040049
Bin Chen6808ef92018-01-27 16:59:09 +110050 images->ep = relocated_addr;
Lokesh Vutla683cdd62019-10-07 13:52:16 +053051 images->os.start = relocated_addr;
52 images->os.end = relocated_addr + image_size;
53
Bin Chen6808ef92018-01-27 16:59:09 +110054 lmb_reserve(&images->lmb, images->ep, le32_to_cpu(image_size));
Tom Rini5db28902016-08-12 08:31:15 -040055
56 /*
57 * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
58 * have a header that provide this informaiton.
59 */
60 if (bootm_find_images(flag, argc, argv))
61 return 1;
62
63 return 0;
64}
65
66int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
67{
68 int ret;
69
70 /* Consume 'booti' */
71 argc--; argv++;
72
73 if (booti_start(cmdtp, flag, argc, argv, &images))
74 return 1;
75
76 /*
77 * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
78 * disable interrupts ourselves
79 */
80 bootm_disable_interrupts();
81
82 images.os.os = IH_OS_LINUX;
Atish Patra3cedc972019-05-06 17:49:39 -070083#ifdef CONFIG_RISCV_SMODE
84 images.os.arch = IH_ARCH_RISCV;
85#elif CONFIG_ARM64
Scott Wood0fff19a2017-01-26 16:55:44 -060086 images.os.arch = IH_ARCH_ARM64;
Atish Patra3cedc972019-05-06 17:49:39 -070087#endif
Tom Rini5db28902016-08-12 08:31:15 -040088 ret = do_bootm_states(cmdtp, flag, argc, argv,
Cédric Schieli4943dc22017-01-23 16:51:45 +010089#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
90 BOOTM_STATE_RAMDISK |
91#endif
Tom Rini5db28902016-08-12 08:31:15 -040092 BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
93 BOOTM_STATE_OS_GO,
94 &images, 1);
95
96 return ret;
97}
98
99#ifdef CONFIG_SYS_LONGHELP
100static char booti_help_text[] =
101 "[addr [initrd[:size]] [fdt]]\n"
Atish Patra3cedc972019-05-06 17:49:39 -0700102 " - boot Linux 'Image' stored at 'addr'\n"
Tom Rini5db28902016-08-12 08:31:15 -0400103 "\tThe argument 'initrd' is optional and specifies the address\n"
104 "\tof an initrd in memory. The optional parameter ':size' allows\n"
105 "\tspecifying the size of a RAW initrd.\n"
106#if defined(CONFIG_OF_LIBFDT)
107 "\tSince booting a Linux kernel requires a flat device-tree, a\n"
108 "\tthird argument providing the address of the device-tree blob\n"
109 "\tis required. To boot a kernel with a device-tree blob but\n"
110 "\twithout an initrd image, use a '-' for the initrd argument.\n"
111#endif
112 "";
113#endif
114
115U_BOOT_CMD(
116 booti, CONFIG_SYS_MAXARGS, 1, do_booti,
Atish Patra3cedc972019-05-06 17:49:39 -0700117 "boot Linux kernel 'Image' format from memory", booti_help_text
Tom Rini5db28902016-08-12 08:31:15 -0400118);