blob: f1e607ae0ddf0820db50fa049b98c8d2de6d0958 [file] [log] [blame]
Tom Rini36f067f2016-08-12 08:31:15 -04001/*
2 * (C) Copyright 2000-2009
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <bootm.h>
10#include <command.h>
11#include <image.h>
12#include <lmb.h>
13#include <mapmem.h>
Masahiro Yamada56c4ed62017-03-09 16:28:25 +090014#include <linux/kernel.h>
15#include <linux/sizes.h>
Tom Rini36f067f2016-08-12 08:31:15 -040016
Tom Rini36f067f2016-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 Chendac184b2018-01-27 16:59:09 +110024 ulong ld;
25 ulong relocated_addr;
26 ulong image_size;
Tom Rini36f067f2016-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) {
Bin Chendac184b2018-01-27 16:59:09 +110033 ld = load_addr;
Tom Rini36f067f2016-08-12 08:31:15 -040034 debug("* kernel: default image load address = 0x%08lx\n",
35 load_addr);
36 } else {
Bin Chendac184b2018-01-27 16:59:09 +110037 ld = simple_strtoul(argv[0], NULL, 16);
Masahiro Yamada76913252018-02-13 12:10:02 +090038 debug("* kernel: cmdline image address = 0x%08lx\n", ld);
Tom Rini36f067f2016-08-12 08:31:15 -040039 }
40
Bin Chendac184b2018-01-27 16:59:09 +110041 ret = booti_setup(ld, &relocated_addr, &image_size);
Tom Rini36f067f2016-08-12 08:31:15 -040042 if (ret != 0)
43 return 1;
44
Bin Chendac184b2018-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 Rini36f067f2016-08-12 08:31:15 -040050
Bin Chendac184b2018-01-27 16:59:09 +110051 images->ep = relocated_addr;
52 lmb_reserve(&images->lmb, images->ep, le32_to_cpu(image_size));
Tom Rini36f067f2016-08-12 08:31:15 -040053
54 /*
55 * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
56 * have a header that provide this informaiton.
57 */
58 if (bootm_find_images(flag, argc, argv))
59 return 1;
60
61 return 0;
62}
63
64int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
65{
66 int ret;
67
68 /* Consume 'booti' */
69 argc--; argv++;
70
71 if (booti_start(cmdtp, flag, argc, argv, &images))
72 return 1;
73
74 /*
75 * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
76 * disable interrupts ourselves
77 */
78 bootm_disable_interrupts();
79
80 images.os.os = IH_OS_LINUX;
Scott Wood4ba6a862017-01-26 16:55:44 -060081 images.os.arch = IH_ARCH_ARM64;
Tom Rini36f067f2016-08-12 08:31:15 -040082 ret = do_bootm_states(cmdtp, flag, argc, argv,
Cédric Schieli80d5e6b2017-01-23 16:51:45 +010083#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
84 BOOTM_STATE_RAMDISK |
85#endif
Tom Rini36f067f2016-08-12 08:31:15 -040086 BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
87 BOOTM_STATE_OS_GO,
88 &images, 1);
89
90 return ret;
91}
92
93#ifdef CONFIG_SYS_LONGHELP
94static char booti_help_text[] =
95 "[addr [initrd[:size]] [fdt]]\n"
96 " - boot arm64 Linux Image stored in memory\n"
97 "\tThe argument 'initrd' is optional and specifies the address\n"
98 "\tof an initrd in memory. The optional parameter ':size' allows\n"
99 "\tspecifying the size of a RAW initrd.\n"
100#if defined(CONFIG_OF_LIBFDT)
101 "\tSince booting a Linux kernel requires a flat device-tree, a\n"
102 "\tthird argument providing the address of the device-tree blob\n"
103 "\tis required. To boot a kernel with a device-tree blob but\n"
104 "\twithout an initrd image, use a '-' for the initrd argument.\n"
105#endif
106 "";
107#endif
108
109U_BOOT_CMD(
110 booti, CONFIG_SYS_MAXARGS, 1, do_booti,
111 "boot arm64 Linux Image image from memory", booti_help_text
112);