blob: 0be786cb6bfb4c08b34e54973849344915d7e910 [file] [log] [blame]
Tom Rini5db28902016-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 Yamada28085762017-03-09 16:28:25 +090014#include <linux/kernel.h>
15#include <linux/sizes.h>
Tom Rini5db28902016-08-12 08:31:15 -040016
17DECLARE_GLOBAL_DATA_PTR;
18
Tom Rini5db28902016-08-12 08:31:15 -040019/*
20 * Image booting support
21 */
22static int booti_start(cmd_tbl_t *cmdtp, int flag, int argc,
23 char * const argv[], bootm_headers_t *images)
24{
25 int ret;
Bin Chen6808ef92018-01-27 16:59:09 +110026 ulong ld;
27 ulong relocated_addr;
28 ulong image_size;
Tom Rini5db28902016-08-12 08:31:15 -040029
30 ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
31 images, 1);
32
33 /* Setup Linux kernel Image entry point */
34 if (!argc) {
Bin Chen6808ef92018-01-27 16:59:09 +110035 ld = load_addr;
Tom Rini5db28902016-08-12 08:31:15 -040036 debug("* kernel: default image load address = 0x%08lx\n",
37 load_addr);
38 } else {
Bin Chen6808ef92018-01-27 16:59:09 +110039 ld = simple_strtoul(argv[0], NULL, 16);
Tom Rini5db28902016-08-12 08:31:15 -040040 debug("* kernel: cmdline image address = 0x%08lx\n",
41 images->ep);
42 }
43
Bin Chen6808ef92018-01-27 16:59:09 +110044 ret = booti_setup(ld, &relocated_addr, &image_size);
Tom Rini5db28902016-08-12 08:31:15 -040045 if (ret != 0)
46 return 1;
47
Bin Chen6808ef92018-01-27 16:59:09 +110048 /* Handle BOOTM_STATE_LOADOS */
49 if (relocated_addr != ld) {
50 debug("Moving Image from 0x%lx to 0x%lx\n", ld, relocated_addr);
51 memmove((void *)relocated_addr, (void *)ld, image_size);
52 }
Tom Rini5db28902016-08-12 08:31:15 -040053
Bin Chen6808ef92018-01-27 16:59:09 +110054 images->ep = relocated_addr;
55 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;
Scott Wood0fff19a2017-01-26 16:55:44 -060084 images.os.arch = IH_ARCH_ARM64;
Tom Rini5db28902016-08-12 08:31:15 -040085 ret = do_bootm_states(cmdtp, flag, argc, argv,
Cédric Schieli4943dc22017-01-23 16:51:45 +010086#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
87 BOOTM_STATE_RAMDISK |
88#endif
Tom Rini5db28902016-08-12 08:31:15 -040089 BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
90 BOOTM_STATE_OS_GO,
91 &images, 1);
92
93 return ret;
94}
95
96#ifdef CONFIG_SYS_LONGHELP
97static char booti_help_text[] =
98 "[addr [initrd[:size]] [fdt]]\n"
99 " - boot arm64 Linux Image stored in memory\n"
100 "\tThe argument 'initrd' is optional and specifies the address\n"
101 "\tof an initrd in memory. The optional parameter ':size' allows\n"
102 "\tspecifying the size of a RAW initrd.\n"
103#if defined(CONFIG_OF_LIBFDT)
104 "\tSince booting a Linux kernel requires a flat device-tree, a\n"
105 "\tthird argument providing the address of the device-tree blob\n"
106 "\tis required. To boot a kernel with a device-tree blob but\n"
107 "\twithout an initrd image, use a '-' for the initrd argument.\n"
108#endif
109 "";
110#endif
111
112U_BOOT_CMD(
113 booti, CONFIG_SYS_MAXARGS, 1, do_booti,
114 "boot arm64 Linux Image image from memory", booti_help_text
115);