2 * (C) Copyright 2000-2009
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
15 DECLARE_GLOBAL_DATA_PTR;
17 /* See Documentation/arm64/booting.txt in the Linux kernel */
19 uint32_t code0; /* Executable code */
20 uint32_t code1; /* Executable code */
21 uint64_t text_offset; /* Image load offset, LE */
22 uint64_t image_size; /* Effective Image size, LE */
23 uint64_t res1; /* reserved */
24 uint64_t res2; /* reserved */
25 uint64_t res3; /* reserved */
26 uint64_t res4; /* reserved */
27 uint32_t magic; /* Magic number */
31 #define LINUX_ARM64_IMAGE_MAGIC 0x644d5241
33 static int booti_setup(bootm_headers_t *images)
35 struct Image_header *ih;
39 ih = (struct Image_header *)map_sysmem(images->ep, 0);
41 if (ih->magic != le32_to_cpu(LINUX_ARM64_IMAGE_MAGIC)) {
42 puts("Bad Linux ARM64 Image magic!\n");
46 if (ih->image_size == 0) {
47 puts("Image lacks image_size field, assuming 16MiB\n");
48 image_size = 16 << 20;
50 image_size = le64_to_cpu(ih->image_size);
54 * If we are not at the correct run-time location, set the new
55 * correct location and then move the image there.
57 dst = gd->bd->bi_dram[0].start + le64_to_cpu(ih->text_offset);
61 if (images->ep != dst) {
64 debug("Moving Image from 0x%lx to 0x%llx\n", images->ep, dst);
66 src = (void *)images->ep;
68 memmove((void *)dst, src, image_size);
75 * Image booting support
77 static int booti_start(cmd_tbl_t *cmdtp, int flag, int argc,
78 char * const argv[], bootm_headers_t *images)
81 struct Image_header *ih;
83 ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
86 /* Setup Linux kernel Image entry point */
88 images->ep = load_addr;
89 debug("* kernel: default image load address = 0x%08lx\n",
92 images->ep = simple_strtoul(argv[0], NULL, 16);
93 debug("* kernel: cmdline image address = 0x%08lx\n",
97 ret = booti_setup(images);
101 ih = (struct Image_header *)map_sysmem(images->ep, 0);
103 lmb_reserve(&images->lmb, images->ep, le32_to_cpu(ih->image_size));
108 * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
109 * have a header that provide this informaiton.
111 if (bootm_find_images(flag, argc, argv))
117 int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
121 /* Consume 'booti' */
124 if (booti_start(cmdtp, flag, argc, argv, &images))
128 * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
129 * disable interrupts ourselves
131 bootm_disable_interrupts();
133 images.os.os = IH_OS_LINUX;
134 ret = do_bootm_states(cmdtp, flag, argc, argv,
135 BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
142 #ifdef CONFIG_SYS_LONGHELP
143 static char booti_help_text[] =
144 "[addr [initrd[:size]] [fdt]]\n"
145 " - boot arm64 Linux Image stored in memory\n"
146 "\tThe argument 'initrd' is optional and specifies the address\n"
147 "\tof an initrd in memory. The optional parameter ':size' allows\n"
148 "\tspecifying the size of a RAW initrd.\n"
149 #if defined(CONFIG_OF_LIBFDT)
150 "\tSince booting a Linux kernel requires a flat device-tree, a\n"
151 "\tthird argument providing the address of the device-tree blob\n"
152 "\tis required. To boot a kernel with a device-tree blob but\n"
153 "\twithout an initrd image, use a '-' for the initrd argument.\n"
159 booti, CONFIG_SYS_MAXARGS, 1, do_booti,
160 "boot arm64 Linux Image image from memory", booti_help_text