xref: /openbmc/qemu/hw/arm/boot.c (revision 3f0b59070c89f2261ff5961980ff5203b0c6bea9)
153018216SPaolo Bonzini /*
253018216SPaolo Bonzini  * ARM kernel loader.
353018216SPaolo Bonzini  *
453018216SPaolo Bonzini  * Copyright (c) 2006-2007 CodeSourcery.
553018216SPaolo Bonzini  * Written by Paul Brook
653018216SPaolo Bonzini  *
753018216SPaolo Bonzini  * This code is licensed under the GPL.
853018216SPaolo Bonzini  */
953018216SPaolo Bonzini 
1012b16722SPeter Maydell #include "qemu/osdep.h"
11a8d25326SMarkus Armbruster #include "qemu-common.h"
12c0dbca36SAlistair Francis #include "qemu/error-report.h"
13da34e65cSMarkus Armbruster #include "qapi/error.h"
14b77257d7SGuenter Roeck #include <libfdt.h>
1512ec8bd5SPeter Maydell #include "hw/arm/boot.h"
16d8b1ae42SPeter Maydell #include "hw/arm/linux-boot-if.h"
17baf6b681SPeter Crosthwaite #include "sysemu/kvm.h"
1853018216SPaolo Bonzini #include "sysemu/sysemu.h"
199695200aSShannon Zhao #include "sysemu/numa.h"
202744ece8STao Xu #include "hw/boards.h"
2171e8a915SMarkus Armbruster #include "sysemu/reset.h"
2253018216SPaolo Bonzini #include "hw/loader.h"
2353018216SPaolo Bonzini #include "elf.h"
2453018216SPaolo Bonzini #include "sysemu/device_tree.h"
2553018216SPaolo Bonzini #include "qemu/config-file.h"
26922a01a0SMarkus Armbruster #include "qemu/option.h"
272198a121SEdgar E. Iglesias #include "exec/address-spaces.h"
28ea358872SStewart Hildebrand #include "qemu/units.h"
2953018216SPaolo Bonzini 
304d9ebf75SMian M. Hamayun /* Kernel boot protocol is specified in the kernel docs
314d9ebf75SMian M. Hamayun  * Documentation/arm/Booting and Documentation/arm64/booting.txt
324d9ebf75SMian M. Hamayun  * They have different preferred image load offsets from system RAM base.
334d9ebf75SMian M. Hamayun  */
3453018216SPaolo Bonzini #define KERNEL_ARGS_ADDR   0x100
35f831f955SNick Hudson #define KERNEL_NOLOAD_ADDR 0x02000000
3653018216SPaolo Bonzini #define KERNEL_LOAD_ADDR   0x00010000
374d9ebf75SMian M. Hamayun #define KERNEL64_LOAD_ADDR 0x00080000
3853018216SPaolo Bonzini 
3968115ed5SArd Biesheuvel #define ARM64_TEXT_OFFSET_OFFSET    8
4068115ed5SArd Biesheuvel #define ARM64_MAGIC_OFFSET          56
4168115ed5SArd Biesheuvel 
42ea358872SStewart Hildebrand #define BOOTLOADER_MAX_SIZE         (4 * KiB)
43ea358872SStewart Hildebrand 
443b77f6c3SIgor Mammedov AddressSpace *arm_boot_address_space(ARMCPU *cpu,
459f43d4c3SPeter Maydell                                      const struct arm_boot_info *info)
469f43d4c3SPeter Maydell {
479f43d4c3SPeter Maydell     /* Return the address space to use for bootloader reads and writes.
489f43d4c3SPeter Maydell      * We prefer the secure address space if the CPU has it and we're
499f43d4c3SPeter Maydell      * going to boot the guest into it.
509f43d4c3SPeter Maydell      */
519f43d4c3SPeter Maydell     int asidx;
529f43d4c3SPeter Maydell     CPUState *cs = CPU(cpu);
539f43d4c3SPeter Maydell 
549f43d4c3SPeter Maydell     if (arm_feature(&cpu->env, ARM_FEATURE_EL3) && info->secure_boot) {
559f43d4c3SPeter Maydell         asidx = ARMASIdx_S;
569f43d4c3SPeter Maydell     } else {
579f43d4c3SPeter Maydell         asidx = ARMASIdx_NS;
589f43d4c3SPeter Maydell     }
599f43d4c3SPeter Maydell 
609f43d4c3SPeter Maydell     return cpu_get_address_space(cs, asidx);
619f43d4c3SPeter Maydell }
629f43d4c3SPeter Maydell 
6347b1da81SPeter Maydell typedef enum {
6447b1da81SPeter Maydell     FIXUP_NONE = 0,     /* do nothing */
6547b1da81SPeter Maydell     FIXUP_TERMINATOR,   /* end of insns */
6647b1da81SPeter Maydell     FIXUP_BOARDID,      /* overwrite with board ID number */
6710b8ec73SPeter Crosthwaite     FIXUP_BOARD_SETUP,  /* overwrite with board specific setup code address */
68751ebc13SRicardo Perez Blanco     FIXUP_ARGPTR_LO,    /* overwrite with pointer to kernel args */
69751ebc13SRicardo Perez Blanco     FIXUP_ARGPTR_HI,    /* overwrite with pointer to kernel args (high half) */
70751ebc13SRicardo Perez Blanco     FIXUP_ENTRYPOINT_LO, /* overwrite with kernel entry point */
71751ebc13SRicardo Perez Blanco     FIXUP_ENTRYPOINT_HI, /* overwrite with kernel entry point (high half) */
7247b1da81SPeter Maydell     FIXUP_GIC_CPU_IF,   /* overwrite with GIC CPU interface address */
7347b1da81SPeter Maydell     FIXUP_BOOTREG,      /* overwrite with boot register address */
7447b1da81SPeter Maydell     FIXUP_DSB,          /* overwrite with correct DSB insn for cpu */
7547b1da81SPeter Maydell     FIXUP_MAX,
7647b1da81SPeter Maydell } FixupType;
7747b1da81SPeter Maydell 
7847b1da81SPeter Maydell typedef struct ARMInsnFixup {
7947b1da81SPeter Maydell     uint32_t insn;
8047b1da81SPeter Maydell     FixupType fixup;
8147b1da81SPeter Maydell } ARMInsnFixup;
8247b1da81SPeter Maydell 
834d9ebf75SMian M. Hamayun static const ARMInsnFixup bootloader_aarch64[] = {
844d9ebf75SMian M. Hamayun     { 0x580000c0 }, /* ldr x0, arg ; Load the lower 32-bits of DTB */
854d9ebf75SMian M. Hamayun     { 0xaa1f03e1 }, /* mov x1, xzr */
864d9ebf75SMian M. Hamayun     { 0xaa1f03e2 }, /* mov x2, xzr */
874d9ebf75SMian M. Hamayun     { 0xaa1f03e3 }, /* mov x3, xzr */
884d9ebf75SMian M. Hamayun     { 0x58000084 }, /* ldr x4, entry ; Load the lower 32-bits of kernel entry */
894d9ebf75SMian M. Hamayun     { 0xd61f0080 }, /* br x4      ; Jump to the kernel entry point */
90751ebc13SRicardo Perez Blanco     { 0, FIXUP_ARGPTR_LO }, /* arg: .word @DTB Lower 32-bits */
91751ebc13SRicardo Perez Blanco     { 0, FIXUP_ARGPTR_HI}, /* .word @DTB Higher 32-bits */
92751ebc13SRicardo Perez Blanco     { 0, FIXUP_ENTRYPOINT_LO }, /* entry: .word @Kernel Entry Lower 32-bits */
93751ebc13SRicardo Perez Blanco     { 0, FIXUP_ENTRYPOINT_HI }, /* .word @Kernel Entry Higher 32-bits */
944d9ebf75SMian M. Hamayun     { 0, FIXUP_TERMINATOR }
954d9ebf75SMian M. Hamayun };
964d9ebf75SMian M. Hamayun 
9710b8ec73SPeter Crosthwaite /* A very small bootloader: call the board-setup code (if needed),
9810b8ec73SPeter Crosthwaite  * set r0-r2, then jump to the kernel.
9910b8ec73SPeter Crosthwaite  * If we're not calling boot setup code then we don't copy across
10010b8ec73SPeter Crosthwaite  * the first BOOTLOADER_NO_BOARD_SETUP_OFFSET insns in this array.
10110b8ec73SPeter Crosthwaite  */
10210b8ec73SPeter Crosthwaite 
10347b1da81SPeter Maydell static const ARMInsnFixup bootloader[] = {
104b4850e5aSSylvain Garrigues     { 0xe28fe004 }, /* add     lr, pc, #4 */
10510b8ec73SPeter Crosthwaite     { 0xe51ff004 }, /* ldr     pc, [pc, #-4] */
10610b8ec73SPeter Crosthwaite     { 0, FIXUP_BOARD_SETUP },
10710b8ec73SPeter Crosthwaite #define BOOTLOADER_NO_BOARD_SETUP_OFFSET 3
10847b1da81SPeter Maydell     { 0xe3a00000 }, /* mov     r0, #0 */
10947b1da81SPeter Maydell     { 0xe59f1004 }, /* ldr     r1, [pc, #4] */
11047b1da81SPeter Maydell     { 0xe59f2004 }, /* ldr     r2, [pc, #4] */
11147b1da81SPeter Maydell     { 0xe59ff004 }, /* ldr     pc, [pc, #4] */
11247b1da81SPeter Maydell     { 0, FIXUP_BOARDID },
113751ebc13SRicardo Perez Blanco     { 0, FIXUP_ARGPTR_LO },
114751ebc13SRicardo Perez Blanco     { 0, FIXUP_ENTRYPOINT_LO },
11547b1da81SPeter Maydell     { 0, FIXUP_TERMINATOR }
11653018216SPaolo Bonzini };
11753018216SPaolo Bonzini 
11853018216SPaolo Bonzini /* Handling for secondary CPU boot in a multicore system.
11953018216SPaolo Bonzini  * Unlike the uniprocessor/primary CPU boot, this is platform
12053018216SPaolo Bonzini  * dependent. The default code here is based on the secondary
12153018216SPaolo Bonzini  * CPU boot protocol used on realview/vexpress boards, with
12253018216SPaolo Bonzini  * some parameterisation to increase its flexibility.
12353018216SPaolo Bonzini  * QEMU platform models for which this code is not appropriate
12453018216SPaolo Bonzini  * should override write_secondary_boot and secondary_cpu_reset_hook
12553018216SPaolo Bonzini  * instead.
12653018216SPaolo Bonzini  *
12753018216SPaolo Bonzini  * This code enables the interrupt controllers for the secondary
12853018216SPaolo Bonzini  * CPUs and then puts all the secondary CPUs into a loop waiting
12953018216SPaolo Bonzini  * for an interprocessor interrupt and polling a configurable
13053018216SPaolo Bonzini  * location for the kernel secondary CPU entry point.
13153018216SPaolo Bonzini  */
13253018216SPaolo Bonzini #define DSB_INSN 0xf57ff04f
13353018216SPaolo Bonzini #define CP15_DSB_INSN 0xee070f9a /* mcr cp15, 0, r0, c7, c10, 4 */
13453018216SPaolo Bonzini 
13547b1da81SPeter Maydell static const ARMInsnFixup smpboot[] = {
13647b1da81SPeter Maydell     { 0xe59f2028 }, /* ldr r2, gic_cpu_if */
13747b1da81SPeter Maydell     { 0xe59f0028 }, /* ldr r0, bootreg_addr */
13847b1da81SPeter Maydell     { 0xe3a01001 }, /* mov r1, #1 */
13947b1da81SPeter Maydell     { 0xe5821000 }, /* str r1, [r2] - set GICC_CTLR.Enable */
14047b1da81SPeter Maydell     { 0xe3a010ff }, /* mov r1, #0xff */
14147b1da81SPeter Maydell     { 0xe5821004 }, /* str r1, [r2, 4] - set GIC_PMR.Priority to 0xff */
14247b1da81SPeter Maydell     { 0, FIXUP_DSB },   /* dsb */
14347b1da81SPeter Maydell     { 0xe320f003 }, /* wfi */
14447b1da81SPeter Maydell     { 0xe5901000 }, /* ldr     r1, [r0] */
14547b1da81SPeter Maydell     { 0xe1110001 }, /* tst     r1, r1 */
14647b1da81SPeter Maydell     { 0x0afffffb }, /* beq     <wfi> */
14747b1da81SPeter Maydell     { 0xe12fff11 }, /* bx      r1 */
14847b1da81SPeter Maydell     { 0, FIXUP_GIC_CPU_IF }, /* gic_cpu_if: .word 0x.... */
14947b1da81SPeter Maydell     { 0, FIXUP_BOOTREG }, /* bootreg_addr: .word 0x.... */
15047b1da81SPeter Maydell     { 0, FIXUP_TERMINATOR }
15153018216SPaolo Bonzini };
15253018216SPaolo Bonzini 
15347b1da81SPeter Maydell static void write_bootloader(const char *name, hwaddr addr,
1549f43d4c3SPeter Maydell                              const ARMInsnFixup *insns, uint32_t *fixupcontext,
1559f43d4c3SPeter Maydell                              AddressSpace *as)
15647b1da81SPeter Maydell {
15747b1da81SPeter Maydell     /* Fix up the specified bootloader fragment and write it into
15847b1da81SPeter Maydell      * guest memory using rom_add_blob_fixed(). fixupcontext is
15947b1da81SPeter Maydell      * an array giving the values to write in for the fixup types
16047b1da81SPeter Maydell      * which write a value into the code array.
16147b1da81SPeter Maydell      */
16247b1da81SPeter Maydell     int i, len;
16347b1da81SPeter Maydell     uint32_t *code;
16447b1da81SPeter Maydell 
16547b1da81SPeter Maydell     len = 0;
16647b1da81SPeter Maydell     while (insns[len].fixup != FIXUP_TERMINATOR) {
16747b1da81SPeter Maydell         len++;
16847b1da81SPeter Maydell     }
16947b1da81SPeter Maydell 
17047b1da81SPeter Maydell     code = g_new0(uint32_t, len);
17147b1da81SPeter Maydell 
17247b1da81SPeter Maydell     for (i = 0; i < len; i++) {
17347b1da81SPeter Maydell         uint32_t insn = insns[i].insn;
17447b1da81SPeter Maydell         FixupType fixup = insns[i].fixup;
17547b1da81SPeter Maydell 
17647b1da81SPeter Maydell         switch (fixup) {
17747b1da81SPeter Maydell         case FIXUP_NONE:
17847b1da81SPeter Maydell             break;
17947b1da81SPeter Maydell         case FIXUP_BOARDID:
18010b8ec73SPeter Crosthwaite         case FIXUP_BOARD_SETUP:
181751ebc13SRicardo Perez Blanco         case FIXUP_ARGPTR_LO:
182751ebc13SRicardo Perez Blanco         case FIXUP_ARGPTR_HI:
183751ebc13SRicardo Perez Blanco         case FIXUP_ENTRYPOINT_LO:
184751ebc13SRicardo Perez Blanco         case FIXUP_ENTRYPOINT_HI:
18547b1da81SPeter Maydell         case FIXUP_GIC_CPU_IF:
18647b1da81SPeter Maydell         case FIXUP_BOOTREG:
18747b1da81SPeter Maydell         case FIXUP_DSB:
18847b1da81SPeter Maydell             insn = fixupcontext[fixup];
18947b1da81SPeter Maydell             break;
19047b1da81SPeter Maydell         default:
19147b1da81SPeter Maydell             abort();
19247b1da81SPeter Maydell         }
19347b1da81SPeter Maydell         code[i] = tswap32(insn);
19447b1da81SPeter Maydell     }
19547b1da81SPeter Maydell 
196ea358872SStewart Hildebrand     assert((len * sizeof(uint32_t)) < BOOTLOADER_MAX_SIZE);
197ea358872SStewart Hildebrand 
1989f43d4c3SPeter Maydell     rom_add_blob_fixed_as(name, code, len * sizeof(uint32_t), addr, as);
19947b1da81SPeter Maydell 
20047b1da81SPeter Maydell     g_free(code);
20147b1da81SPeter Maydell }
20247b1da81SPeter Maydell 
20353018216SPaolo Bonzini static void default_write_secondary(ARMCPU *cpu,
20453018216SPaolo Bonzini                                     const struct arm_boot_info *info)
20553018216SPaolo Bonzini {
20647b1da81SPeter Maydell     uint32_t fixupcontext[FIXUP_MAX];
2079f43d4c3SPeter Maydell     AddressSpace *as = arm_boot_address_space(cpu, info);
20847b1da81SPeter Maydell 
20947b1da81SPeter Maydell     fixupcontext[FIXUP_GIC_CPU_IF] = info->gic_cpu_if_addr;
21047b1da81SPeter Maydell     fixupcontext[FIXUP_BOOTREG] = info->smp_bootreg_addr;
21147b1da81SPeter Maydell     if (arm_feature(&cpu->env, ARM_FEATURE_V7)) {
21247b1da81SPeter Maydell         fixupcontext[FIXUP_DSB] = DSB_INSN;
21347b1da81SPeter Maydell     } else {
21447b1da81SPeter Maydell         fixupcontext[FIXUP_DSB] = CP15_DSB_INSN;
21553018216SPaolo Bonzini     }
21647b1da81SPeter Maydell 
21747b1da81SPeter Maydell     write_bootloader("smpboot", info->smp_loader_start,
2189f43d4c3SPeter Maydell                      smpboot, fixupcontext, as);
21953018216SPaolo Bonzini }
22053018216SPaolo Bonzini 
221716536a9SAndrew Baumann void arm_write_secure_board_setup_dummy_smc(ARMCPU *cpu,
222716536a9SAndrew Baumann                                             const struct arm_boot_info *info,
223716536a9SAndrew Baumann                                             hwaddr mvbar_addr)
224716536a9SAndrew Baumann {
2259f43d4c3SPeter Maydell     AddressSpace *as = arm_boot_address_space(cpu, info);
226716536a9SAndrew Baumann     int n;
227716536a9SAndrew Baumann     uint32_t mvbar_blob[] = {
228716536a9SAndrew Baumann         /* mvbar_addr: secure monitor vectors
229716536a9SAndrew Baumann          * Default unimplemented and unused vectors to spin. Makes it
230716536a9SAndrew Baumann          * easier to debug (as opposed to the CPU running away).
231716536a9SAndrew Baumann          */
232716536a9SAndrew Baumann         0xeafffffe, /* (spin) */
233716536a9SAndrew Baumann         0xeafffffe, /* (spin) */
234716536a9SAndrew Baumann         0xe1b0f00e, /* movs pc, lr ;SMC exception return */
235716536a9SAndrew Baumann         0xeafffffe, /* (spin) */
236716536a9SAndrew Baumann         0xeafffffe, /* (spin) */
237716536a9SAndrew Baumann         0xeafffffe, /* (spin) */
238716536a9SAndrew Baumann         0xeafffffe, /* (spin) */
239716536a9SAndrew Baumann         0xeafffffe, /* (spin) */
240716536a9SAndrew Baumann     };
241716536a9SAndrew Baumann     uint32_t board_setup_blob[] = {
242716536a9SAndrew Baumann         /* board setup addr */
24345c078f1SClement Deschamps         0xee110f51, /* mrc     p15, 0, r0, c1, c1, 2  ;read NSACR */
24445c078f1SClement Deschamps         0xe3800b03, /* orr     r0, #0xc00             ;set CP11, CP10 */
24545c078f1SClement Deschamps         0xee010f51, /* mcr     p15, 0, r0, c1, c1, 2  ;write NSACR */
246716536a9SAndrew Baumann         0xe3a00e00 + (mvbar_addr >> 4), /* mov r0, #mvbar_addr */
247716536a9SAndrew Baumann         0xee0c0f30, /* mcr     p15, 0, r0, c12, c0, 1 ;set MVBAR */
248716536a9SAndrew Baumann         0xee110f11, /* mrc     p15, 0, r0, c1 , c1, 0 ;read SCR */
249716536a9SAndrew Baumann         0xe3800031, /* orr     r0, #0x31              ;enable AW, FW, NS */
250716536a9SAndrew Baumann         0xee010f11, /* mcr     p15, 0, r0, c1, c1, 0  ;write SCR */
251716536a9SAndrew Baumann         0xe1a0100e, /* mov     r1, lr                 ;save LR across SMC */
252716536a9SAndrew Baumann         0xe1600070, /* smc     #0                     ;call monitor to flush SCR */
253716536a9SAndrew Baumann         0xe1a0f001, /* mov     pc, r1                 ;return */
254716536a9SAndrew Baumann     };
255716536a9SAndrew Baumann 
256716536a9SAndrew Baumann     /* check that mvbar_addr is correctly aligned and relocatable (using MOV) */
257716536a9SAndrew Baumann     assert((mvbar_addr & 0x1f) == 0 && (mvbar_addr >> 4) < 0x100);
258716536a9SAndrew Baumann 
259716536a9SAndrew Baumann     /* check that these blobs don't overlap */
260716536a9SAndrew Baumann     assert((mvbar_addr + sizeof(mvbar_blob) <= info->board_setup_addr)
261716536a9SAndrew Baumann           || (info->board_setup_addr + sizeof(board_setup_blob) <= mvbar_addr));
262716536a9SAndrew Baumann 
263716536a9SAndrew Baumann     for (n = 0; n < ARRAY_SIZE(mvbar_blob); n++) {
264716536a9SAndrew Baumann         mvbar_blob[n] = tswap32(mvbar_blob[n]);
265716536a9SAndrew Baumann     }
2669f43d4c3SPeter Maydell     rom_add_blob_fixed_as("board-setup-mvbar", mvbar_blob, sizeof(mvbar_blob),
2679f43d4c3SPeter Maydell                           mvbar_addr, as);
268716536a9SAndrew Baumann 
269716536a9SAndrew Baumann     for (n = 0; n < ARRAY_SIZE(board_setup_blob); n++) {
270716536a9SAndrew Baumann         board_setup_blob[n] = tswap32(board_setup_blob[n]);
271716536a9SAndrew Baumann     }
2729f43d4c3SPeter Maydell     rom_add_blob_fixed_as("board-setup", board_setup_blob,
2739f43d4c3SPeter Maydell                           sizeof(board_setup_blob), info->board_setup_addr, as);
274716536a9SAndrew Baumann }
275716536a9SAndrew Baumann 
27653018216SPaolo Bonzini static void default_reset_secondary(ARMCPU *cpu,
27753018216SPaolo Bonzini                                     const struct arm_boot_info *info)
27853018216SPaolo Bonzini {
2799f43d4c3SPeter Maydell     AddressSpace *as = arm_boot_address_space(cpu, info);
2804df81c6eSPeter Crosthwaite     CPUState *cs = CPU(cpu);
28153018216SPaolo Bonzini 
2829f43d4c3SPeter Maydell     address_space_stl_notdirty(as, info->smp_bootreg_addr,
28342874d3aSPeter Maydell                                0, MEMTXATTRS_UNSPECIFIED, NULL);
2844df81c6eSPeter Crosthwaite     cpu_set_pc(cs, info->smp_loader_start);
28553018216SPaolo Bonzini }
28653018216SPaolo Bonzini 
28783bfffecSPeter Maydell static inline bool have_dtb(const struct arm_boot_info *info)
28883bfffecSPeter Maydell {
28983bfffecSPeter Maydell     return info->dtb_filename || info->get_dtb;
29083bfffecSPeter Maydell }
29183bfffecSPeter Maydell 
29253018216SPaolo Bonzini #define WRITE_WORD(p, value) do { \
2939f43d4c3SPeter Maydell     address_space_stl_notdirty(as, p, value, \
29442874d3aSPeter Maydell                                MEMTXATTRS_UNSPECIFIED, NULL);  \
29553018216SPaolo Bonzini     p += 4;                       \
29653018216SPaolo Bonzini } while (0)
29753018216SPaolo Bonzini 
2989f43d4c3SPeter Maydell static void set_kernel_args(const struct arm_boot_info *info, AddressSpace *as)
29953018216SPaolo Bonzini {
30053018216SPaolo Bonzini     int initrd_size = info->initrd_size;
30153018216SPaolo Bonzini     hwaddr base = info->loader_start;
30253018216SPaolo Bonzini     hwaddr p;
30353018216SPaolo Bonzini 
30453018216SPaolo Bonzini     p = base + KERNEL_ARGS_ADDR;
30553018216SPaolo Bonzini     /* ATAG_CORE */
30653018216SPaolo Bonzini     WRITE_WORD(p, 5);
30753018216SPaolo Bonzini     WRITE_WORD(p, 0x54410001);
30853018216SPaolo Bonzini     WRITE_WORD(p, 1);
30953018216SPaolo Bonzini     WRITE_WORD(p, 0x1000);
31053018216SPaolo Bonzini     WRITE_WORD(p, 0);
31153018216SPaolo Bonzini     /* ATAG_MEM */
31253018216SPaolo Bonzini     /* TODO: handle multiple chips on one ATAG list */
31353018216SPaolo Bonzini     WRITE_WORD(p, 4);
31453018216SPaolo Bonzini     WRITE_WORD(p, 0x54410002);
31553018216SPaolo Bonzini     WRITE_WORD(p, info->ram_size);
31653018216SPaolo Bonzini     WRITE_WORD(p, info->loader_start);
31753018216SPaolo Bonzini     if (initrd_size) {
31853018216SPaolo Bonzini         /* ATAG_INITRD2 */
31953018216SPaolo Bonzini         WRITE_WORD(p, 4);
32053018216SPaolo Bonzini         WRITE_WORD(p, 0x54420005);
32153018216SPaolo Bonzini         WRITE_WORD(p, info->initrd_start);
32253018216SPaolo Bonzini         WRITE_WORD(p, initrd_size);
32353018216SPaolo Bonzini     }
32453018216SPaolo Bonzini     if (info->kernel_cmdline && *info->kernel_cmdline) {
32553018216SPaolo Bonzini         /* ATAG_CMDLINE */
32653018216SPaolo Bonzini         int cmdline_size;
32753018216SPaolo Bonzini 
32853018216SPaolo Bonzini         cmdline_size = strlen(info->kernel_cmdline);
3299f43d4c3SPeter Maydell         address_space_write(as, p + 8, MEMTXATTRS_UNSPECIFIED,
330b7cbebf2SPhilippe Mathieu-Daudé                             info->kernel_cmdline, cmdline_size + 1);
33153018216SPaolo Bonzini         cmdline_size = (cmdline_size >> 2) + 1;
33253018216SPaolo Bonzini         WRITE_WORD(p, cmdline_size + 2);
33353018216SPaolo Bonzini         WRITE_WORD(p, 0x54410009);
33453018216SPaolo Bonzini         p += cmdline_size * 4;
33553018216SPaolo Bonzini     }
33653018216SPaolo Bonzini     if (info->atag_board) {
33753018216SPaolo Bonzini         /* ATAG_BOARD */
33853018216SPaolo Bonzini         int atag_board_len;
33953018216SPaolo Bonzini         uint8_t atag_board_buf[0x1000];
34053018216SPaolo Bonzini 
34153018216SPaolo Bonzini         atag_board_len = (info->atag_board(info, atag_board_buf) + 3) & ~3;
34253018216SPaolo Bonzini         WRITE_WORD(p, (atag_board_len + 8) >> 2);
34353018216SPaolo Bonzini         WRITE_WORD(p, 0x414f4d50);
3449f43d4c3SPeter Maydell         address_space_write(as, p, MEMTXATTRS_UNSPECIFIED,
3459f43d4c3SPeter Maydell                             atag_board_buf, atag_board_len);
34653018216SPaolo Bonzini         p += atag_board_len;
34753018216SPaolo Bonzini     }
34853018216SPaolo Bonzini     /* ATAG_END */
34953018216SPaolo Bonzini     WRITE_WORD(p, 0);
35053018216SPaolo Bonzini     WRITE_WORD(p, 0);
35153018216SPaolo Bonzini }
35253018216SPaolo Bonzini 
3539f43d4c3SPeter Maydell static void set_kernel_args_old(const struct arm_boot_info *info,
3549f43d4c3SPeter Maydell                                 AddressSpace *as)
35553018216SPaolo Bonzini {
35653018216SPaolo Bonzini     hwaddr p;
35753018216SPaolo Bonzini     const char *s;
35853018216SPaolo Bonzini     int initrd_size = info->initrd_size;
35953018216SPaolo Bonzini     hwaddr base = info->loader_start;
36053018216SPaolo Bonzini 
36153018216SPaolo Bonzini     /* see linux/include/asm-arm/setup.h */
36253018216SPaolo Bonzini     p = base + KERNEL_ARGS_ADDR;
36353018216SPaolo Bonzini     /* page_size */
36453018216SPaolo Bonzini     WRITE_WORD(p, 4096);
36553018216SPaolo Bonzini     /* nr_pages */
36653018216SPaolo Bonzini     WRITE_WORD(p, info->ram_size / 4096);
36753018216SPaolo Bonzini     /* ramdisk_size */
36853018216SPaolo Bonzini     WRITE_WORD(p, 0);
36953018216SPaolo Bonzini #define FLAG_READONLY	1
37053018216SPaolo Bonzini #define FLAG_RDLOAD	4
37153018216SPaolo Bonzini #define FLAG_RDPROMPT	8
37253018216SPaolo Bonzini     /* flags */
37353018216SPaolo Bonzini     WRITE_WORD(p, FLAG_READONLY | FLAG_RDLOAD | FLAG_RDPROMPT);
37453018216SPaolo Bonzini     /* rootdev */
37553018216SPaolo Bonzini     WRITE_WORD(p, (31 << 8) | 0);	/* /dev/mtdblock0 */
37653018216SPaolo Bonzini     /* video_num_cols */
37753018216SPaolo Bonzini     WRITE_WORD(p, 0);
37853018216SPaolo Bonzini     /* video_num_rows */
37953018216SPaolo Bonzini     WRITE_WORD(p, 0);
38053018216SPaolo Bonzini     /* video_x */
38153018216SPaolo Bonzini     WRITE_WORD(p, 0);
38253018216SPaolo Bonzini     /* video_y */
38353018216SPaolo Bonzini     WRITE_WORD(p, 0);
38453018216SPaolo Bonzini     /* memc_control_reg */
38553018216SPaolo Bonzini     WRITE_WORD(p, 0);
38653018216SPaolo Bonzini     /* unsigned char sounddefault */
38753018216SPaolo Bonzini     /* unsigned char adfsdrives */
38853018216SPaolo Bonzini     /* unsigned char bytes_per_char_h */
38953018216SPaolo Bonzini     /* unsigned char bytes_per_char_v */
39053018216SPaolo Bonzini     WRITE_WORD(p, 0);
39153018216SPaolo Bonzini     /* pages_in_bank[4] */
39253018216SPaolo Bonzini     WRITE_WORD(p, 0);
39353018216SPaolo Bonzini     WRITE_WORD(p, 0);
39453018216SPaolo Bonzini     WRITE_WORD(p, 0);
39553018216SPaolo Bonzini     WRITE_WORD(p, 0);
39653018216SPaolo Bonzini     /* pages_in_vram */
39753018216SPaolo Bonzini     WRITE_WORD(p, 0);
39853018216SPaolo Bonzini     /* initrd_start */
39953018216SPaolo Bonzini     if (initrd_size) {
40053018216SPaolo Bonzini         WRITE_WORD(p, info->initrd_start);
40153018216SPaolo Bonzini     } else {
40253018216SPaolo Bonzini         WRITE_WORD(p, 0);
40353018216SPaolo Bonzini     }
40453018216SPaolo Bonzini     /* initrd_size */
40553018216SPaolo Bonzini     WRITE_WORD(p, initrd_size);
40653018216SPaolo Bonzini     /* rd_start */
40753018216SPaolo Bonzini     WRITE_WORD(p, 0);
40853018216SPaolo Bonzini     /* system_rev */
40953018216SPaolo Bonzini     WRITE_WORD(p, 0);
41053018216SPaolo Bonzini     /* system_serial_low */
41153018216SPaolo Bonzini     WRITE_WORD(p, 0);
41253018216SPaolo Bonzini     /* system_serial_high */
41353018216SPaolo Bonzini     WRITE_WORD(p, 0);
41453018216SPaolo Bonzini     /* mem_fclk_21285 */
41553018216SPaolo Bonzini     WRITE_WORD(p, 0);
41653018216SPaolo Bonzini     /* zero unused fields */
41753018216SPaolo Bonzini     while (p < base + KERNEL_ARGS_ADDR + 256 + 1024) {
41853018216SPaolo Bonzini         WRITE_WORD(p, 0);
41953018216SPaolo Bonzini     }
42053018216SPaolo Bonzini     s = info->kernel_cmdline;
42153018216SPaolo Bonzini     if (s) {
422b7cbebf2SPhilippe Mathieu-Daudé         address_space_write(as, p, MEMTXATTRS_UNSPECIFIED, s, strlen(s) + 1);
42353018216SPaolo Bonzini     } else {
42453018216SPaolo Bonzini         WRITE_WORD(p, 0);
42553018216SPaolo Bonzini     }
42653018216SPaolo Bonzini }
42753018216SPaolo Bonzini 
428f08ced69SShameer Kolothum static int fdt_add_memory_node(void *fdt, uint32_t acells, hwaddr mem_base,
429f08ced69SShameer Kolothum                                uint32_t scells, hwaddr mem_len,
430f08ced69SShameer Kolothum                                int numa_node_id)
431f08ced69SShameer Kolothum {
432f08ced69SShameer Kolothum     char *nodename;
433f08ced69SShameer Kolothum     int ret;
434f08ced69SShameer Kolothum 
435f08ced69SShameer Kolothum     nodename = g_strdup_printf("/memory@%" PRIx64, mem_base);
436f08ced69SShameer Kolothum     qemu_fdt_add_subnode(fdt, nodename);
437f08ced69SShameer Kolothum     qemu_fdt_setprop_string(fdt, nodename, "device_type", "memory");
438f08ced69SShameer Kolothum     ret = qemu_fdt_setprop_sized_cells(fdt, nodename, "reg", acells, mem_base,
439f08ced69SShameer Kolothum                                        scells, mem_len);
440f08ced69SShameer Kolothum     if (ret < 0) {
441f08ced69SShameer Kolothum         goto out;
442f08ced69SShameer Kolothum     }
443f08ced69SShameer Kolothum 
444f08ced69SShameer Kolothum     /* only set the NUMA ID if it is specified */
445f08ced69SShameer Kolothum     if (numa_node_id >= 0) {
446f08ced69SShameer Kolothum         ret = qemu_fdt_setprop_cell(fdt, nodename,
447f08ced69SShameer Kolothum                                     "numa-node-id", numa_node_id);
448f08ced69SShameer Kolothum     }
449f08ced69SShameer Kolothum out:
450f08ced69SShameer Kolothum     g_free(nodename);
451f08ced69SShameer Kolothum     return ret;
452f08ced69SShameer Kolothum }
453f08ced69SShameer Kolothum 
4544cbca7d9SAndrey Smirnov static void fdt_add_psci_node(void *fdt)
4554cbca7d9SAndrey Smirnov {
4564cbca7d9SAndrey Smirnov     uint32_t cpu_suspend_fn;
4574cbca7d9SAndrey Smirnov     uint32_t cpu_off_fn;
4584cbca7d9SAndrey Smirnov     uint32_t cpu_on_fn;
4594cbca7d9SAndrey Smirnov     uint32_t migrate_fn;
4604cbca7d9SAndrey Smirnov     ARMCPU *armcpu = ARM_CPU(qemu_get_cpu(0));
4614cbca7d9SAndrey Smirnov     const char *psci_method;
4624cbca7d9SAndrey Smirnov     int64_t psci_conduit;
463c39770cdSAndrey Smirnov     int rc;
4644cbca7d9SAndrey Smirnov 
4654cbca7d9SAndrey Smirnov     psci_conduit = object_property_get_int(OBJECT(armcpu),
4664cbca7d9SAndrey Smirnov                                            "psci-conduit",
4674cbca7d9SAndrey Smirnov                                            &error_abort);
4684cbca7d9SAndrey Smirnov     switch (psci_conduit) {
4694cbca7d9SAndrey Smirnov     case QEMU_PSCI_CONDUIT_DISABLED:
4704cbca7d9SAndrey Smirnov         return;
4714cbca7d9SAndrey Smirnov     case QEMU_PSCI_CONDUIT_HVC:
4724cbca7d9SAndrey Smirnov         psci_method = "hvc";
4734cbca7d9SAndrey Smirnov         break;
4744cbca7d9SAndrey Smirnov     case QEMU_PSCI_CONDUIT_SMC:
4754cbca7d9SAndrey Smirnov         psci_method = "smc";
4764cbca7d9SAndrey Smirnov         break;
4774cbca7d9SAndrey Smirnov     default:
4784cbca7d9SAndrey Smirnov         g_assert_not_reached();
4794cbca7d9SAndrey Smirnov     }
4804cbca7d9SAndrey Smirnov 
481c39770cdSAndrey Smirnov     /*
482c39770cdSAndrey Smirnov      * If /psci node is present in provided DTB, assume that no fixup
483c39770cdSAndrey Smirnov      * is necessary and all PSCI configuration should be taken as-is
484c39770cdSAndrey Smirnov      */
485c39770cdSAndrey Smirnov     rc = fdt_path_offset(fdt, "/psci");
486c39770cdSAndrey Smirnov     if (rc >= 0) {
487c39770cdSAndrey Smirnov         return;
488c39770cdSAndrey Smirnov     }
489c39770cdSAndrey Smirnov 
4904cbca7d9SAndrey Smirnov     qemu_fdt_add_subnode(fdt, "/psci");
4914cbca7d9SAndrey Smirnov     if (armcpu->psci_version == 2) {
4924cbca7d9SAndrey Smirnov         const char comp[] = "arm,psci-0.2\0arm,psci";
4934cbca7d9SAndrey Smirnov         qemu_fdt_setprop(fdt, "/psci", "compatible", comp, sizeof(comp));
4944cbca7d9SAndrey Smirnov 
4954cbca7d9SAndrey Smirnov         cpu_off_fn = QEMU_PSCI_0_2_FN_CPU_OFF;
4964cbca7d9SAndrey Smirnov         if (arm_feature(&armcpu->env, ARM_FEATURE_AARCH64)) {
4974cbca7d9SAndrey Smirnov             cpu_suspend_fn = QEMU_PSCI_0_2_FN64_CPU_SUSPEND;
4984cbca7d9SAndrey Smirnov             cpu_on_fn = QEMU_PSCI_0_2_FN64_CPU_ON;
4994cbca7d9SAndrey Smirnov             migrate_fn = QEMU_PSCI_0_2_FN64_MIGRATE;
5004cbca7d9SAndrey Smirnov         } else {
5014cbca7d9SAndrey Smirnov             cpu_suspend_fn = QEMU_PSCI_0_2_FN_CPU_SUSPEND;
5024cbca7d9SAndrey Smirnov             cpu_on_fn = QEMU_PSCI_0_2_FN_CPU_ON;
5034cbca7d9SAndrey Smirnov             migrate_fn = QEMU_PSCI_0_2_FN_MIGRATE;
5044cbca7d9SAndrey Smirnov         }
5054cbca7d9SAndrey Smirnov     } else {
5064cbca7d9SAndrey Smirnov         qemu_fdt_setprop_string(fdt, "/psci", "compatible", "arm,psci");
5074cbca7d9SAndrey Smirnov 
5084cbca7d9SAndrey Smirnov         cpu_suspend_fn = QEMU_PSCI_0_1_FN_CPU_SUSPEND;
5094cbca7d9SAndrey Smirnov         cpu_off_fn = QEMU_PSCI_0_1_FN_CPU_OFF;
5104cbca7d9SAndrey Smirnov         cpu_on_fn = QEMU_PSCI_0_1_FN_CPU_ON;
5114cbca7d9SAndrey Smirnov         migrate_fn = QEMU_PSCI_0_1_FN_MIGRATE;
5124cbca7d9SAndrey Smirnov     }
5134cbca7d9SAndrey Smirnov 
5144cbca7d9SAndrey Smirnov     /* We adopt the PSCI spec's nomenclature, and use 'conduit' to refer
5154cbca7d9SAndrey Smirnov      * to the instruction that should be used to invoke PSCI functions.
5164cbca7d9SAndrey Smirnov      * However, the device tree binding uses 'method' instead, so that is
5174cbca7d9SAndrey Smirnov      * what we should use here.
5184cbca7d9SAndrey Smirnov      */
5194cbca7d9SAndrey Smirnov     qemu_fdt_setprop_string(fdt, "/psci", "method", psci_method);
5204cbca7d9SAndrey Smirnov 
5214cbca7d9SAndrey Smirnov     qemu_fdt_setprop_cell(fdt, "/psci", "cpu_suspend", cpu_suspend_fn);
5224cbca7d9SAndrey Smirnov     qemu_fdt_setprop_cell(fdt, "/psci", "cpu_off", cpu_off_fn);
5234cbca7d9SAndrey Smirnov     qemu_fdt_setprop_cell(fdt, "/psci", "cpu_on", cpu_on_fn);
5244cbca7d9SAndrey Smirnov     qemu_fdt_setprop_cell(fdt, "/psci", "migrate", migrate_fn);
5254cbca7d9SAndrey Smirnov }
5264cbca7d9SAndrey Smirnov 
5273b77f6c3SIgor Mammedov int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
5282744ece8STao Xu                  hwaddr addr_limit, AddressSpace *as, MachineState *ms)
52953018216SPaolo Bonzini {
53053018216SPaolo Bonzini     void *fdt = NULL;
531e2eb3d29SEric Auger     int size, rc, n = 0;
53270976c41SPeter Maydell     uint32_t acells, scells;
5339695200aSShannon Zhao     unsigned int i;
5349695200aSShannon Zhao     hwaddr mem_base, mem_len;
535e2eb3d29SEric Auger     char **node_path;
536e2eb3d29SEric Auger     Error *err = NULL;
53753018216SPaolo Bonzini 
5380fb79851SJohn Rigby     if (binfo->dtb_filename) {
5390fb79851SJohn Rigby         char *filename;
54053018216SPaolo Bonzini         filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, binfo->dtb_filename);
54153018216SPaolo Bonzini         if (!filename) {
54253018216SPaolo Bonzini             fprintf(stderr, "Couldn't open dtb file %s\n", binfo->dtb_filename);
543c23045deSPeter Maydell             goto fail;
54453018216SPaolo Bonzini         }
54553018216SPaolo Bonzini 
54653018216SPaolo Bonzini         fdt = load_device_tree(filename, &size);
54753018216SPaolo Bonzini         if (!fdt) {
54853018216SPaolo Bonzini             fprintf(stderr, "Couldn't open dtb file %s\n", filename);
54953018216SPaolo Bonzini             g_free(filename);
550c23045deSPeter Maydell             goto fail;
55153018216SPaolo Bonzini         }
55253018216SPaolo Bonzini         g_free(filename);
553a554ecb4Szhanghailiang     } else {
5540fb79851SJohn Rigby         fdt = binfo->get_dtb(binfo, &size);
5550fb79851SJohn Rigby         if (!fdt) {
5560fb79851SJohn Rigby             fprintf(stderr, "Board was unable to create a dtb blob\n");
5570fb79851SJohn Rigby             goto fail;
5580fb79851SJohn Rigby         }
5590fb79851SJohn Rigby     }
56053018216SPaolo Bonzini 
561fee8ea12SArd Biesheuvel     if (addr_limit > addr && size > (addr_limit - addr)) {
562fee8ea12SArd Biesheuvel         /* Installing the device tree blob at addr would exceed addr_limit.
563fee8ea12SArd Biesheuvel          * Whether this constitutes failure is up to the caller to decide,
564fee8ea12SArd Biesheuvel          * so just return 0 as size, i.e., no error.
565fee8ea12SArd Biesheuvel          */
566fee8ea12SArd Biesheuvel         g_free(fdt);
567fee8ea12SArd Biesheuvel         return 0;
568fee8ea12SArd Biesheuvel     }
569fee8ea12SArd Biesheuvel 
57058e71097SEric Auger     acells = qemu_fdt_getprop_cell(fdt, "/", "#address-cells",
57158e71097SEric Auger                                    NULL, &error_fatal);
57258e71097SEric Auger     scells = qemu_fdt_getprop_cell(fdt, "/", "#size-cells",
57358e71097SEric Auger                                    NULL, &error_fatal);
57453018216SPaolo Bonzini     if (acells == 0 || scells == 0) {
57553018216SPaolo Bonzini         fprintf(stderr, "dtb file invalid (#address-cells or #size-cells 0)\n");
576c23045deSPeter Maydell         goto fail;
57753018216SPaolo Bonzini     }
57853018216SPaolo Bonzini 
579e4e34855SPhilippe Mathieu-Daudé     if (scells < 2 && binfo->ram_size >= 4 * GiB) {
58070976c41SPeter Maydell         /* This is user error so deserves a friendlier error message
58170976c41SPeter Maydell          * than the failure of setprop_sized_cells would provide
58270976c41SPeter Maydell          */
58353018216SPaolo Bonzini         fprintf(stderr, "qemu: dtb file not compatible with "
58453018216SPaolo Bonzini                 "RAM size > 4GB\n");
585c23045deSPeter Maydell         goto fail;
58653018216SPaolo Bonzini     }
58753018216SPaolo Bonzini 
588e2eb3d29SEric Auger     /* nop all root nodes matching /memory or /memory@unit-address */
589e2eb3d29SEric Auger     node_path = qemu_fdt_node_unit_path(fdt, "memory", &err);
590e2eb3d29SEric Auger     if (err) {
591e2eb3d29SEric Auger         error_report_err(err);
592e2eb3d29SEric Auger         goto fail;
593e2eb3d29SEric Auger     }
594e2eb3d29SEric Auger     while (node_path[n]) {
595e2eb3d29SEric Auger         if (g_str_has_prefix(node_path[n], "/memory")) {
596e2eb3d29SEric Auger             qemu_fdt_nop_node(fdt, node_path[n]);
597e2eb3d29SEric Auger         }
598e2eb3d29SEric Auger         n++;
599e2eb3d29SEric Auger     }
600e2eb3d29SEric Auger     g_strfreev(node_path);
601e2eb3d29SEric Auger 
602aa570207STao Xu     if (ms->numa_state != NULL && ms->numa_state->num_nodes > 0) {
6039695200aSShannon Zhao         mem_base = binfo->loader_start;
604aa570207STao Xu         for (i = 0; i < ms->numa_state->num_nodes; i++) {
6057e721e7bSTao Xu             mem_len = ms->numa_state->nodes[i].node_mem;
606f08ced69SShameer Kolothum             rc = fdt_add_memory_node(fdt, acells, mem_base,
607f08ced69SShameer Kolothum                                      scells, mem_len, i);
6089695200aSShannon Zhao             if (rc < 0) {
609f08ced69SShameer Kolothum                 fprintf(stderr, "couldn't add /memory@%"PRIx64" node\n",
610f08ced69SShameer Kolothum                         mem_base);
6119695200aSShannon Zhao                 goto fail;
6129695200aSShannon Zhao             }
6139695200aSShannon Zhao 
6149695200aSShannon Zhao             mem_base += mem_len;
6159695200aSShannon Zhao         }
6169695200aSShannon Zhao     } else {
617f08ced69SShameer Kolothum         rc = fdt_add_memory_node(fdt, acells, binfo->loader_start,
618f08ced69SShameer Kolothum                                  scells, binfo->ram_size, -1);
61953018216SPaolo Bonzini         if (rc < 0) {
620f08ced69SShameer Kolothum             fprintf(stderr, "couldn't add /memory@%"PRIx64" node\n",
621f08ced69SShameer Kolothum                     binfo->loader_start);
622c23045deSPeter Maydell             goto fail;
62353018216SPaolo Bonzini         }
6249695200aSShannon Zhao     }
62553018216SPaolo Bonzini 
626b77257d7SGuenter Roeck     rc = fdt_path_offset(fdt, "/chosen");
627b77257d7SGuenter Roeck     if (rc < 0) {
628b77257d7SGuenter Roeck         qemu_fdt_add_subnode(fdt, "/chosen");
629b77257d7SGuenter Roeck     }
630b77257d7SGuenter Roeck 
6312744ece8STao Xu     if (ms->kernel_cmdline && *ms->kernel_cmdline) {
6325a4348d1SPeter Crosthwaite         rc = qemu_fdt_setprop_string(fdt, "/chosen", "bootargs",
6332744ece8STao Xu                                      ms->kernel_cmdline);
63453018216SPaolo Bonzini         if (rc < 0) {
63553018216SPaolo Bonzini             fprintf(stderr, "couldn't set /chosen/bootargs\n");
636c23045deSPeter Maydell             goto fail;
63753018216SPaolo Bonzini         }
63853018216SPaolo Bonzini     }
63953018216SPaolo Bonzini 
64053018216SPaolo Bonzini     if (binfo->initrd_size) {
6415a4348d1SPeter Crosthwaite         rc = qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-start",
64253018216SPaolo Bonzini                                    binfo->initrd_start);
64353018216SPaolo Bonzini         if (rc < 0) {
64453018216SPaolo Bonzini             fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n");
645c23045deSPeter Maydell             goto fail;
64653018216SPaolo Bonzini         }
64753018216SPaolo Bonzini 
6485a4348d1SPeter Crosthwaite         rc = qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-end",
64953018216SPaolo Bonzini                                    binfo->initrd_start + binfo->initrd_size);
65053018216SPaolo Bonzini         if (rc < 0) {
65153018216SPaolo Bonzini             fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");
652c23045deSPeter Maydell             goto fail;
65353018216SPaolo Bonzini         }
65453018216SPaolo Bonzini     }
6553b1cceb8SPeter Maydell 
6564cbca7d9SAndrey Smirnov     fdt_add_psci_node(fdt);
6574cbca7d9SAndrey Smirnov 
6583b1cceb8SPeter Maydell     if (binfo->modify_dtb) {
6593b1cceb8SPeter Maydell         binfo->modify_dtb(binfo, fdt);
6603b1cceb8SPeter Maydell     }
6613b1cceb8SPeter Maydell 
6625a4348d1SPeter Crosthwaite     qemu_fdt_dumpdtb(fdt, size);
66353018216SPaolo Bonzini 
6644c4bf654SArd Biesheuvel     /* Put the DTB into the memory map as a ROM image: this will ensure
6654c4bf654SArd Biesheuvel      * the DTB is copied again upon reset, even if addr points into RAM.
6664c4bf654SArd Biesheuvel      */
6679f43d4c3SPeter Maydell     rom_add_blob_fixed_as("dtb", fdt, size, addr, as);
66853018216SPaolo Bonzini 
669c23045deSPeter Maydell     g_free(fdt);
670c23045deSPeter Maydell 
671fee8ea12SArd Biesheuvel     return size;
672c23045deSPeter Maydell 
673c23045deSPeter Maydell fail:
674c23045deSPeter Maydell     g_free(fdt);
675c23045deSPeter Maydell     return -1;
67653018216SPaolo Bonzini }
67753018216SPaolo Bonzini 
67853018216SPaolo Bonzini static void do_cpu_reset(void *opaque)
67953018216SPaolo Bonzini {
68053018216SPaolo Bonzini     ARMCPU *cpu = opaque;
6814df81c6eSPeter Crosthwaite     CPUState *cs = CPU(cpu);
68253018216SPaolo Bonzini     CPUARMState *env = &cpu->env;
68353018216SPaolo Bonzini     const struct arm_boot_info *info = env->boot_info;
68453018216SPaolo Bonzini 
6854df81c6eSPeter Crosthwaite     cpu_reset(cs);
68653018216SPaolo Bonzini     if (info) {
68753018216SPaolo Bonzini         if (!info->is_linux) {
6889776f636SPeter Crosthwaite             int i;
68953018216SPaolo Bonzini             /* Jump to the entry point.  */
6904df81c6eSPeter Crosthwaite             uint64_t entry = info->entry;
6914df81c6eSPeter Crosthwaite 
6929776f636SPeter Crosthwaite             switch (info->endianness) {
6939776f636SPeter Crosthwaite             case ARM_ENDIANNESS_LE:
6949776f636SPeter Crosthwaite                 env->cp15.sctlr_el[1] &= ~SCTLR_E0E;
6959776f636SPeter Crosthwaite                 for (i = 1; i < 4; ++i) {
6969776f636SPeter Crosthwaite                     env->cp15.sctlr_el[i] &= ~SCTLR_EE;
6979776f636SPeter Crosthwaite                 }
6989776f636SPeter Crosthwaite                 env->uncached_cpsr &= ~CPSR_E;
6999776f636SPeter Crosthwaite                 break;
7009776f636SPeter Crosthwaite             case ARM_ENDIANNESS_BE8:
7019776f636SPeter Crosthwaite                 env->cp15.sctlr_el[1] |= SCTLR_E0E;
7029776f636SPeter Crosthwaite                 for (i = 1; i < 4; ++i) {
7039776f636SPeter Crosthwaite                     env->cp15.sctlr_el[i] |= SCTLR_EE;
7049776f636SPeter Crosthwaite                 }
7059776f636SPeter Crosthwaite                 env->uncached_cpsr |= CPSR_E;
7069776f636SPeter Crosthwaite                 break;
7079776f636SPeter Crosthwaite             case ARM_ENDIANNESS_BE32:
7089776f636SPeter Crosthwaite                 env->cp15.sctlr_el[1] |= SCTLR_B;
7099776f636SPeter Crosthwaite                 break;
7109776f636SPeter Crosthwaite             case ARM_ENDIANNESS_UNKNOWN:
7119776f636SPeter Crosthwaite                 break; /* Board's decision */
7129776f636SPeter Crosthwaite             default:
7139776f636SPeter Crosthwaite                 g_assert_not_reached();
7149776f636SPeter Crosthwaite             }
7159776f636SPeter Crosthwaite 
7164df81c6eSPeter Crosthwaite             cpu_set_pc(cs, entry);
71753018216SPaolo Bonzini         } else {
718c8e829b7SGreg Bellows             /* If we are booting Linux then we need to check whether we are
719c8e829b7SGreg Bellows              * booting into secure or non-secure state and adjust the state
720c8e829b7SGreg Bellows              * accordingly.  Out of reset, ARM is defined to be in secure state
721c8e829b7SGreg Bellows              * (SCR.NS = 0), we change that here if non-secure boot has been
722c8e829b7SGreg Bellows              * requested.
723c8e829b7SGreg Bellows              */
7245097227cSGreg Bellows             if (arm_feature(env, ARM_FEATURE_EL3)) {
7255097227cSGreg Bellows                 /* AArch64 is defined to come out of reset into EL3 if enabled.
7265097227cSGreg Bellows                  * If we are booting Linux then we need to adjust our EL as
7275097227cSGreg Bellows                  * Linux expects us to be in EL2 or EL1.  AArch32 resets into
7285097227cSGreg Bellows                  * SVC, which Linux expects, so no privilege/exception level to
7295097227cSGreg Bellows                  * adjust.
7305097227cSGreg Bellows                  */
7315097227cSGreg Bellows                 if (env->aarch64) {
73248d21a57SEdgar E. Iglesias                     env->cp15.scr_el3 |= SCR_RW;
7335097227cSGreg Bellows                     if (arm_feature(env, ARM_FEATURE_EL2)) {
73448d21a57SEdgar E. Iglesias                         env->cp15.hcr_el2 |= HCR_RW;
7355097227cSGreg Bellows                         env->pstate = PSTATE_MODE_EL2h;
7365097227cSGreg Bellows                     } else {
7375097227cSGreg Bellows                         env->pstate = PSTATE_MODE_EL1h;
7385097227cSGreg Bellows                     }
73924ac0d30SRichard Henderson                     if (cpu_isar_feature(aa64_pauth, cpu)) {
74024ac0d30SRichard Henderson                         env->cp15.scr_el3 |= SCR_API | SCR_APK;
74124ac0d30SRichard Henderson                     }
7427ad01d78SRichard Henderson                     if (cpu_isar_feature(aa64_mte, cpu)) {
7437ad01d78SRichard Henderson                         env->cp15.scr_el3 |= SCR_ATA;
7447ad01d78SRichard Henderson                     }
745*3f0b5907SRémi Denis-Courmont                     if (cpu_isar_feature(aa64_sve, cpu)) {
746*3f0b5907SRémi Denis-Courmont                         env->cp15.cptr_el[3] |= CPTR_EZ;
747*3f0b5907SRémi Denis-Courmont                     }
74843118f43SPeter Maydell                     /* AArch64 kernels never boot in secure mode */
74943118f43SPeter Maydell                     assert(!info->secure_boot);
75043118f43SPeter Maydell                     /* This hook is only supported for AArch32 currently:
75143118f43SPeter Maydell                      * bootloader_aarch64[] will not call the hook, and
75243118f43SPeter Maydell                      * the code above has already dropped us into EL2 or EL1.
75343118f43SPeter Maydell                      */
75443118f43SPeter Maydell                     assert(!info->secure_board_setup);
7555097227cSGreg Bellows                 }
7565097227cSGreg Bellows 
757bda816f0SPeter Maydell                 if (arm_feature(env, ARM_FEATURE_EL2)) {
758bda816f0SPeter Maydell                     /* If we have EL2 then Linux expects the HVC insn to work */
759bda816f0SPeter Maydell                     env->cp15.scr_el3 |= SCR_HCE;
760bda816f0SPeter Maydell                 }
761bda816f0SPeter Maydell 
7625097227cSGreg Bellows                 /* Set to non-secure if not a secure boot */
763baf6b681SPeter Crosthwaite                 if (!info->secure_boot &&
764baf6b681SPeter Crosthwaite                     (cs != first_cpu || !info->secure_board_setup)) {
7655097227cSGreg Bellows                     /* Linux expects non-secure state */
766c8e829b7SGreg Bellows                     env->cp15.scr_el3 |= SCR_NS;
767ece628fcSPeter Maydell                     /* Set NSACR.{CP11,CP10} so NS can access the FPU */
768ece628fcSPeter Maydell                     env->cp15.nsacr |= 3 << 10;
769c8e829b7SGreg Bellows                 }
7705097227cSGreg Bellows             }
771c8e829b7SGreg Bellows 
772299953b9SPeter Maydell             if (!env->aarch64 && !info->secure_boot &&
773299953b9SPeter Maydell                 arm_feature(env, ARM_FEATURE_EL2)) {
774299953b9SPeter Maydell                 /*
775299953b9SPeter Maydell                  * This is an AArch32 boot not to Secure state, and
776299953b9SPeter Maydell                  * we have Hyp mode available, so boot the kernel into
777299953b9SPeter Maydell                  * Hyp mode. This is not how the CPU comes out of reset,
778299953b9SPeter Maydell                  * so we need to manually put it there.
779299953b9SPeter Maydell                  */
780299953b9SPeter Maydell                 cpsr_write(env, ARM_CPU_MODE_HYP, CPSR_M, CPSRWriteRaw);
781299953b9SPeter Maydell             }
782299953b9SPeter Maydell 
7834df81c6eSPeter Crosthwaite             if (cs == first_cpu) {
7849f43d4c3SPeter Maydell                 AddressSpace *as = arm_boot_address_space(cpu, info);
7859f43d4c3SPeter Maydell 
7864df81c6eSPeter Crosthwaite                 cpu_set_pc(cs, info->loader_start);
7874d9ebf75SMian M. Hamayun 
78883bfffecSPeter Maydell                 if (!have_dtb(info)) {
78953018216SPaolo Bonzini                     if (old_param) {
7909f43d4c3SPeter Maydell                         set_kernel_args_old(info, as);
79153018216SPaolo Bonzini                     } else {
7929f43d4c3SPeter Maydell                         set_kernel_args(info, as);
79353018216SPaolo Bonzini                     }
79453018216SPaolo Bonzini                 }
79553018216SPaolo Bonzini             } else {
79653018216SPaolo Bonzini                 info->secondary_cpu_reset_hook(cpu, info);
79753018216SPaolo Bonzini             }
79853018216SPaolo Bonzini         }
79998be6b7dSEdgar E. Iglesias         arm_rebuild_hflags(env);
80053018216SPaolo Bonzini     }
80153018216SPaolo Bonzini }
80253018216SPaolo Bonzini 
80307abe45cSLaszlo Ersek /**
80407abe45cSLaszlo Ersek  * load_image_to_fw_cfg() - Load an image file into an fw_cfg entry identified
80507abe45cSLaszlo Ersek  *                          by key.
80607abe45cSLaszlo Ersek  * @fw_cfg:         The firmware config instance to store the data in.
80707abe45cSLaszlo Ersek  * @size_key:       The firmware config key to store the size of the loaded
80807abe45cSLaszlo Ersek  *                  data under, with fw_cfg_add_i32().
80907abe45cSLaszlo Ersek  * @data_key:       The firmware config key to store the loaded data under,
81007abe45cSLaszlo Ersek  *                  with fw_cfg_add_bytes().
81107abe45cSLaszlo Ersek  * @image_name:     The name of the image file to load. If it is NULL, the
81207abe45cSLaszlo Ersek  *                  function returns without doing anything.
81307abe45cSLaszlo Ersek  * @try_decompress: Whether the image should be decompressed (gunzipped) before
81407abe45cSLaszlo Ersek  *                  adding it to fw_cfg. If decompression fails, the image is
81507abe45cSLaszlo Ersek  *                  loaded as-is.
81607abe45cSLaszlo Ersek  *
81707abe45cSLaszlo Ersek  * In case of failure, the function prints an error message to stderr and the
81807abe45cSLaszlo Ersek  * process exits with status 1.
81907abe45cSLaszlo Ersek  */
82007abe45cSLaszlo Ersek static void load_image_to_fw_cfg(FWCfgState *fw_cfg, uint16_t size_key,
82107abe45cSLaszlo Ersek                                  uint16_t data_key, const char *image_name,
82207abe45cSLaszlo Ersek                                  bool try_decompress)
82307abe45cSLaszlo Ersek {
82407abe45cSLaszlo Ersek     size_t size = -1;
82507abe45cSLaszlo Ersek     uint8_t *data;
82607abe45cSLaszlo Ersek 
82707abe45cSLaszlo Ersek     if (image_name == NULL) {
82807abe45cSLaszlo Ersek         return;
82907abe45cSLaszlo Ersek     }
83007abe45cSLaszlo Ersek 
83107abe45cSLaszlo Ersek     if (try_decompress) {
83207abe45cSLaszlo Ersek         size = load_image_gzipped_buffer(image_name,
83307abe45cSLaszlo Ersek                                          LOAD_IMAGE_MAX_GUNZIP_BYTES, &data);
83407abe45cSLaszlo Ersek     }
83507abe45cSLaszlo Ersek 
83607abe45cSLaszlo Ersek     if (size == (size_t)-1) {
83707abe45cSLaszlo Ersek         gchar *contents;
83807abe45cSLaszlo Ersek         gsize length;
83907abe45cSLaszlo Ersek 
84007abe45cSLaszlo Ersek         if (!g_file_get_contents(image_name, &contents, &length, NULL)) {
841c0dbca36SAlistair Francis             error_report("failed to load \"%s\"", image_name);
84207abe45cSLaszlo Ersek             exit(1);
84307abe45cSLaszlo Ersek         }
84407abe45cSLaszlo Ersek         size = length;
84507abe45cSLaszlo Ersek         data = (uint8_t *)contents;
84607abe45cSLaszlo Ersek     }
84707abe45cSLaszlo Ersek 
84807abe45cSLaszlo Ersek     fw_cfg_add_i32(fw_cfg, size_key, size);
84907abe45cSLaszlo Ersek     fw_cfg_add_bytes(fw_cfg, data_key, data, size);
85007abe45cSLaszlo Ersek }
85107abe45cSLaszlo Ersek 
852d8b1ae42SPeter Maydell static int do_arm_linux_init(Object *obj, void *opaque)
853d8b1ae42SPeter Maydell {
854d8b1ae42SPeter Maydell     if (object_dynamic_cast(obj, TYPE_ARM_LINUX_BOOT_IF)) {
855d8b1ae42SPeter Maydell         ARMLinuxBootIf *albif = ARM_LINUX_BOOT_IF(obj);
856d8b1ae42SPeter Maydell         ARMLinuxBootIfClass *albifc = ARM_LINUX_BOOT_IF_GET_CLASS(obj);
857d8b1ae42SPeter Maydell         struct arm_boot_info *info = opaque;
858d8b1ae42SPeter Maydell 
859d8b1ae42SPeter Maydell         if (albifc->arm_linux_init) {
860d8b1ae42SPeter Maydell             albifc->arm_linux_init(albif, info->secure_boot);
861d8b1ae42SPeter Maydell         }
862d8b1ae42SPeter Maydell     }
863d8b1ae42SPeter Maydell     return 0;
864d8b1ae42SPeter Maydell }
865d8b1ae42SPeter Maydell 
866a3f0ecfdSAdam Lackorzynski static int64_t arm_load_elf(struct arm_boot_info *info, uint64_t *pentry,
8679776f636SPeter Crosthwaite                             uint64_t *lowaddr, uint64_t *highaddr,
8689f43d4c3SPeter Maydell                             int elf_machine, AddressSpace *as)
8699776f636SPeter Crosthwaite {
8709776f636SPeter Crosthwaite     bool elf_is64;
8719776f636SPeter Crosthwaite     union {
8729776f636SPeter Crosthwaite         Elf32_Ehdr h32;
8739776f636SPeter Crosthwaite         Elf64_Ehdr h64;
8749776f636SPeter Crosthwaite     } elf_header;
8759776f636SPeter Crosthwaite     int data_swab = 0;
8769776f636SPeter Crosthwaite     bool big_endian;
877a3f0ecfdSAdam Lackorzynski     int64_t ret = -1;
8789776f636SPeter Crosthwaite     Error *err = NULL;
8799776f636SPeter Crosthwaite 
8809776f636SPeter Crosthwaite 
8819776f636SPeter Crosthwaite     load_elf_hdr(info->kernel_filename, &elf_header, &elf_is64, &err);
8829776f636SPeter Crosthwaite     if (err) {
88336f876ceSMarc-André Lureau         error_free(err);
8849776f636SPeter Crosthwaite         return ret;
8859776f636SPeter Crosthwaite     }
8869776f636SPeter Crosthwaite 
8879776f636SPeter Crosthwaite     if (elf_is64) {
8889776f636SPeter Crosthwaite         big_endian = elf_header.h64.e_ident[EI_DATA] == ELFDATA2MSB;
8899776f636SPeter Crosthwaite         info->endianness = big_endian ? ARM_ENDIANNESS_BE8
8909776f636SPeter Crosthwaite                                       : ARM_ENDIANNESS_LE;
8919776f636SPeter Crosthwaite     } else {
8929776f636SPeter Crosthwaite         big_endian = elf_header.h32.e_ident[EI_DATA] == ELFDATA2MSB;
8939776f636SPeter Crosthwaite         if (big_endian) {
8949776f636SPeter Crosthwaite             if (bswap32(elf_header.h32.e_flags) & EF_ARM_BE8) {
8959776f636SPeter Crosthwaite                 info->endianness = ARM_ENDIANNESS_BE8;
8969776f636SPeter Crosthwaite             } else {
8979776f636SPeter Crosthwaite                 info->endianness = ARM_ENDIANNESS_BE32;
8989776f636SPeter Crosthwaite                 /* In BE32, the CPU has a different view of the per-byte
8999776f636SPeter Crosthwaite                  * address map than the rest of the system. BE32 ELF files
9009776f636SPeter Crosthwaite                  * are organised such that they can be programmed through
9019776f636SPeter Crosthwaite                  * the CPU's per-word byte-reversed view of the world. QEMU
9029776f636SPeter Crosthwaite                  * however loads ELF files independently of the CPU. So
9039776f636SPeter Crosthwaite                  * tell the ELF loader to byte reverse the data for us.
9049776f636SPeter Crosthwaite                  */
9059776f636SPeter Crosthwaite                 data_swab = 2;
9069776f636SPeter Crosthwaite             }
9079776f636SPeter Crosthwaite         } else {
9089776f636SPeter Crosthwaite             info->endianness = ARM_ENDIANNESS_LE;
9099776f636SPeter Crosthwaite         }
9109776f636SPeter Crosthwaite     }
9119776f636SPeter Crosthwaite 
9124366e1dbSLiam Merwick     ret = load_elf_as(info->kernel_filename, NULL, NULL, NULL,
9136cdda0ffSAleksandar Markovic                       pentry, lowaddr, highaddr, NULL, big_endian, elf_machine,
9149f43d4c3SPeter Maydell                       1, data_swab, as);
9159776f636SPeter Crosthwaite     if (ret <= 0) {
9169776f636SPeter Crosthwaite         /* The header loaded but the image didn't */
9179776f636SPeter Crosthwaite         exit(1);
9189776f636SPeter Crosthwaite     }
9199776f636SPeter Crosthwaite 
9209776f636SPeter Crosthwaite     return ret;
9219776f636SPeter Crosthwaite }
9229776f636SPeter Crosthwaite 
92368115ed5SArd Biesheuvel static uint64_t load_aarch64_image(const char *filename, hwaddr mem_base,
9249f43d4c3SPeter Maydell                                    hwaddr *entry, AddressSpace *as)
92568115ed5SArd Biesheuvel {
92668115ed5SArd Biesheuvel     hwaddr kernel_load_offset = KERNEL64_LOAD_ADDR;
9275e6dbe1eSPeter Maydell     uint64_t kernel_size = 0;
92868115ed5SArd Biesheuvel     uint8_t *buffer;
92968115ed5SArd Biesheuvel     int size;
93068115ed5SArd Biesheuvel 
93168115ed5SArd Biesheuvel     /* On aarch64, it's the bootloader's job to uncompress the kernel. */
93268115ed5SArd Biesheuvel     size = load_image_gzipped_buffer(filename, LOAD_IMAGE_MAX_GUNZIP_BYTES,
93368115ed5SArd Biesheuvel                                      &buffer);
93468115ed5SArd Biesheuvel 
93568115ed5SArd Biesheuvel     if (size < 0) {
93668115ed5SArd Biesheuvel         gsize len;
93768115ed5SArd Biesheuvel 
93868115ed5SArd Biesheuvel         /* Load as raw file otherwise */
93968115ed5SArd Biesheuvel         if (!g_file_get_contents(filename, (char **)&buffer, &len, NULL)) {
94068115ed5SArd Biesheuvel             return -1;
94168115ed5SArd Biesheuvel         }
94268115ed5SArd Biesheuvel         size = len;
94368115ed5SArd Biesheuvel     }
94468115ed5SArd Biesheuvel 
94568115ed5SArd Biesheuvel     /* check the arm64 magic header value -- very old kernels may not have it */
94627640407SMarc-André Lureau     if (size > ARM64_MAGIC_OFFSET + 4 &&
94727640407SMarc-André Lureau         memcmp(buffer + ARM64_MAGIC_OFFSET, "ARM\x64", 4) == 0) {
94868115ed5SArd Biesheuvel         uint64_t hdrvals[2];
94968115ed5SArd Biesheuvel 
95068115ed5SArd Biesheuvel         /* The arm64 Image header has text_offset and image_size fields at 8 and
95168115ed5SArd Biesheuvel          * 16 bytes into the Image header, respectively. The text_offset field
95268115ed5SArd Biesheuvel          * is only valid if the image_size is non-zero.
95368115ed5SArd Biesheuvel          */
95468115ed5SArd Biesheuvel         memcpy(&hdrvals, buffer + ARM64_TEXT_OFFSET_OFFSET, sizeof(hdrvals));
9555e6dbe1eSPeter Maydell 
9565e6dbe1eSPeter Maydell         kernel_size = le64_to_cpu(hdrvals[1]);
9575e6dbe1eSPeter Maydell 
9585e6dbe1eSPeter Maydell         if (kernel_size != 0) {
95968115ed5SArd Biesheuvel             kernel_load_offset = le64_to_cpu(hdrvals[0]);
960ea358872SStewart Hildebrand 
961ea358872SStewart Hildebrand             /*
962ea358872SStewart Hildebrand              * We write our startup "bootloader" at the very bottom of RAM,
963ea358872SStewart Hildebrand              * so that bit can't be used for the image. Luckily the Image
964ea358872SStewart Hildebrand              * format specification is that the image requests only an offset
965ea358872SStewart Hildebrand              * from a 2MB boundary, not an absolute load address. So if the
966ea358872SStewart Hildebrand              * image requests an offset that might mean it overlaps with the
967ea358872SStewart Hildebrand              * bootloader, we can just load it starting at 2MB+offset rather
968ea358872SStewart Hildebrand              * than 0MB + offset.
969ea358872SStewart Hildebrand              */
970ea358872SStewart Hildebrand             if (kernel_load_offset < BOOTLOADER_MAX_SIZE) {
971ea358872SStewart Hildebrand                 kernel_load_offset += 2 * MiB;
972ea358872SStewart Hildebrand             }
97368115ed5SArd Biesheuvel         }
97468115ed5SArd Biesheuvel     }
97568115ed5SArd Biesheuvel 
9765e6dbe1eSPeter Maydell     /*
9775e6dbe1eSPeter Maydell      * Kernels before v3.17 don't populate the image_size field, and
9785e6dbe1eSPeter Maydell      * raw images have no header. For those our best guess at the size
9795e6dbe1eSPeter Maydell      * is the size of the Image file itself.
9805e6dbe1eSPeter Maydell      */
9815e6dbe1eSPeter Maydell     if (kernel_size == 0) {
9825e6dbe1eSPeter Maydell         kernel_size = size;
9835e6dbe1eSPeter Maydell     }
9845e6dbe1eSPeter Maydell 
98568115ed5SArd Biesheuvel     *entry = mem_base + kernel_load_offset;
9869f43d4c3SPeter Maydell     rom_add_blob_fixed_as(filename, buffer, size, *entry, as);
98768115ed5SArd Biesheuvel 
98868115ed5SArd Biesheuvel     g_free(buffer);
98968115ed5SArd Biesheuvel 
9905e6dbe1eSPeter Maydell     return kernel_size;
99168115ed5SArd Biesheuvel }
99268115ed5SArd Biesheuvel 
993d33774eeSPeter Maydell static void arm_setup_direct_kernel_boot(ARMCPU *cpu,
994d33774eeSPeter Maydell                                          struct arm_boot_info *info)
99553018216SPaolo Bonzini {
996d33774eeSPeter Maydell     /* Set up for a direct boot of a kernel image file. */
997c6faa758SArd Biesheuvel     CPUState *cs;
998d33774eeSPeter Maydell     AddressSpace *as = arm_boot_address_space(cpu, info);
99953018216SPaolo Bonzini     int kernel_size;
100053018216SPaolo Bonzini     int initrd_size;
100153018216SPaolo Bonzini     int is_linux = 0;
1002d5fef92fSPeter Maydell     uint64_t elf_entry;
1003d5fef92fSPeter Maydell     /* Addresses of first byte used and first byte not used by the image */
100467505c11SPeter Maydell     uint64_t image_low_addr = 0, image_high_addr = 0;
1005da0af40dSPeter Maydell     int elf_machine;
100668115ed5SArd Biesheuvel     hwaddr entry;
10074d9ebf75SMian M. Hamayun     static const ARMInsnFixup *primary_loader;
1008e70af24bSPeter Maydell     uint64_t ram_end = info->loader_start + info->ram_size;
100953018216SPaolo Bonzini 
10104d9ebf75SMian M. Hamayun     if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
10114d9ebf75SMian M. Hamayun         primary_loader = bootloader_aarch64;
1012da0af40dSPeter Maydell         elf_machine = EM_AARCH64;
10134d9ebf75SMian M. Hamayun     } else {
10144d9ebf75SMian M. Hamayun         primary_loader = bootloader;
101510b8ec73SPeter Crosthwaite         if (!info->write_board_setup) {
101610b8ec73SPeter Crosthwaite             primary_loader += BOOTLOADER_NO_BOARD_SETUP_OFFSET;
101710b8ec73SPeter Crosthwaite         }
1018da0af40dSPeter Maydell         elf_machine = EM_ARM;
10194d9ebf75SMian M. Hamayun     }
10204d9ebf75SMian M. Hamayun 
102153018216SPaolo Bonzini     if (!info->secondary_cpu_reset_hook) {
102253018216SPaolo Bonzini         info->secondary_cpu_reset_hook = default_reset_secondary;
102353018216SPaolo Bonzini     }
102453018216SPaolo Bonzini     if (!info->write_secondary_boot) {
102553018216SPaolo Bonzini         info->write_secondary_boot = default_write_secondary;
102653018216SPaolo Bonzini     }
102753018216SPaolo Bonzini 
102853018216SPaolo Bonzini     if (info->nb_cpus == 0)
102953018216SPaolo Bonzini         info->nb_cpus = 1;
103053018216SPaolo Bonzini 
103153018216SPaolo Bonzini     /* Assume that raw images are linux kernels, and ELF images are not.  */
1032d5fef92fSPeter Maydell     kernel_size = arm_load_elf(info, &elf_entry, &image_low_addr,
1033d5fef92fSPeter Maydell                                &image_high_addr, elf_machine, as);
103492df8450SArd Biesheuvel     if (kernel_size > 0 && have_dtb(info)) {
1035c3a42358SPeter Maydell         /*
1036c3a42358SPeter Maydell          * If there is still some room left at the base of RAM, try and put
103792df8450SArd Biesheuvel          * the DTB there like we do for images loaded with -bios or -pflash.
103892df8450SArd Biesheuvel          */
1039d5fef92fSPeter Maydell         if (image_low_addr > info->loader_start
1040d5fef92fSPeter Maydell             || image_high_addr < info->loader_start) {
1041c3a42358SPeter Maydell             /*
1042d5fef92fSPeter Maydell              * Set image_low_addr as address limit for arm_load_dtb if it may be
104392df8450SArd Biesheuvel              * pointing into RAM, otherwise pass '0' (no limit)
104492df8450SArd Biesheuvel              */
1045d5fef92fSPeter Maydell             if (image_low_addr < info->loader_start) {
1046d5fef92fSPeter Maydell                 image_low_addr = 0;
104792df8450SArd Biesheuvel             }
10483b77f6c3SIgor Mammedov             info->dtb_start = info->loader_start;
1049d5fef92fSPeter Maydell             info->dtb_limit = image_low_addr;
105092df8450SArd Biesheuvel         }
105192df8450SArd Biesheuvel     }
105253018216SPaolo Bonzini     entry = elf_entry;
105353018216SPaolo Bonzini     if (kernel_size < 0) {
1054f831f955SNick Hudson         uint64_t loadaddr = info->loader_start + KERNEL_NOLOAD_ADDR;
1055f831f955SNick Hudson         kernel_size = load_uimage_as(info->kernel_filename, &entry, &loadaddr,
10569f43d4c3SPeter Maydell                                      &is_linux, NULL, NULL, as);
105767505c11SPeter Maydell         if (kernel_size >= 0) {
105867505c11SPeter Maydell             image_low_addr = loadaddr;
105967505c11SPeter Maydell             image_high_addr = image_low_addr + kernel_size;
106067505c11SPeter Maydell         }
106153018216SPaolo Bonzini     }
10626f5d3cbeSRichard W.M. Jones     if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64) && kernel_size < 0) {
106368115ed5SArd Biesheuvel         kernel_size = load_aarch64_image(info->kernel_filename,
10649f43d4c3SPeter Maydell                                          info->loader_start, &entry, as);
10656f5d3cbeSRichard W.M. Jones         is_linux = 1;
106667505c11SPeter Maydell         if (kernel_size >= 0) {
106767505c11SPeter Maydell             image_low_addr = entry;
106867505c11SPeter Maydell             image_high_addr = image_low_addr + kernel_size;
106967505c11SPeter Maydell         }
107068115ed5SArd Biesheuvel     } else if (kernel_size < 0) {
107168115ed5SArd Biesheuvel         /* 32-bit ARM */
107268115ed5SArd Biesheuvel         entry = info->loader_start + KERNEL_LOAD_ADDR;
10739f43d4c3SPeter Maydell         kernel_size = load_image_targphys_as(info->kernel_filename, entry,
1074e70af24bSPeter Maydell                                              ram_end - KERNEL_LOAD_ADDR, as);
107553018216SPaolo Bonzini         is_linux = 1;
107667505c11SPeter Maydell         if (kernel_size >= 0) {
107767505c11SPeter Maydell             image_low_addr = entry;
107867505c11SPeter Maydell             image_high_addr = image_low_addr + kernel_size;
107967505c11SPeter Maydell         }
108053018216SPaolo Bonzini     }
108153018216SPaolo Bonzini     if (kernel_size < 0) {
1082c0dbca36SAlistair Francis         error_report("could not load kernel '%s'", info->kernel_filename);
108353018216SPaolo Bonzini         exit(1);
108453018216SPaolo Bonzini     }
1085852dc64dSPeter Maydell 
1086852dc64dSPeter Maydell     if (kernel_size > info->ram_size) {
1087852dc64dSPeter Maydell         error_report("kernel '%s' is too large to fit in RAM "
1088852dc64dSPeter Maydell                      "(kernel size %d, RAM size %" PRId64 ")",
1089852dc64dSPeter Maydell                      info->kernel_filename, kernel_size, info->ram_size);
1090852dc64dSPeter Maydell         exit(1);
1091852dc64dSPeter Maydell     }
1092852dc64dSPeter Maydell 
109353018216SPaolo Bonzini     info->entry = entry;
1094e6b2b20dSPeter Maydell 
1095e6b2b20dSPeter Maydell     /*
1096e6b2b20dSPeter Maydell      * We want to put the initrd far enough into RAM that when the
1097e6b2b20dSPeter Maydell      * kernel is uncompressed it will not clobber the initrd. However
1098e6b2b20dSPeter Maydell      * on boards without much RAM we must ensure that we still leave
1099e6b2b20dSPeter Maydell      * enough room for a decent sized initrd, and on boards with large
1100e6b2b20dSPeter Maydell      * amounts of RAM we must avoid the initrd being so far up in RAM
1101e6b2b20dSPeter Maydell      * that it is outside lowmem and inaccessible to the kernel.
1102e6b2b20dSPeter Maydell      * So for boards with less  than 256MB of RAM we put the initrd
1103e6b2b20dSPeter Maydell      * halfway into RAM, and for boards with 256MB of RAM or more we put
1104e6b2b20dSPeter Maydell      * the initrd at 128MB.
1105e6b2b20dSPeter Maydell      * We also refuse to put the initrd somewhere that will definitely
1106e6b2b20dSPeter Maydell      * overlay the kernel we just loaded, though for kernel formats which
1107e6b2b20dSPeter Maydell      * don't tell us their exact size (eg self-decompressing 32-bit kernels)
1108e6b2b20dSPeter Maydell      * we might still make a bad choice here.
1109e6b2b20dSPeter Maydell      */
1110e6b2b20dSPeter Maydell     info->initrd_start = info->loader_start +
1111e4e34855SPhilippe Mathieu-Daudé         MIN(info->ram_size / 2, 128 * MiB);
111267505c11SPeter Maydell     if (image_high_addr) {
111367505c11SPeter Maydell         info->initrd_start = MAX(info->initrd_start, image_high_addr);
111467505c11SPeter Maydell     }
1115e6b2b20dSPeter Maydell     info->initrd_start = TARGET_PAGE_ALIGN(info->initrd_start);
1116e6b2b20dSPeter Maydell 
111753018216SPaolo Bonzini     if (is_linux) {
111847b1da81SPeter Maydell         uint32_t fixupcontext[FIXUP_MAX];
111947b1da81SPeter Maydell 
112053018216SPaolo Bonzini         if (info->initrd_filename) {
1121852dc64dSPeter Maydell 
1122852dc64dSPeter Maydell             if (info->initrd_start >= ram_end) {
1123852dc64dSPeter Maydell                 error_report("not enough space after kernel to load initrd");
1124852dc64dSPeter Maydell                 exit(1);
1125852dc64dSPeter Maydell             }
1126852dc64dSPeter Maydell 
11279f43d4c3SPeter Maydell             initrd_size = load_ramdisk_as(info->initrd_filename,
1128fd76663eSSoren Brinkmann                                           info->initrd_start,
1129e70af24bSPeter Maydell                                           ram_end - info->initrd_start, as);
1130fd76663eSSoren Brinkmann             if (initrd_size < 0) {
11319f43d4c3SPeter Maydell                 initrd_size = load_image_targphys_as(info->initrd_filename,
113253018216SPaolo Bonzini                                                      info->initrd_start,
1133e70af24bSPeter Maydell                                                      ram_end -
11349f43d4c3SPeter Maydell                                                      info->initrd_start,
11359f43d4c3SPeter Maydell                                                      as);
1136fd76663eSSoren Brinkmann             }
113753018216SPaolo Bonzini             if (initrd_size < 0) {
1138c0dbca36SAlistair Francis                 error_report("could not load initrd '%s'",
113953018216SPaolo Bonzini                              info->initrd_filename);
114053018216SPaolo Bonzini                 exit(1);
114153018216SPaolo Bonzini             }
1142b48b0640SAndrew Jones             if (info->initrd_start + initrd_size > ram_end) {
1143852dc64dSPeter Maydell                 error_report("could not load initrd '%s': "
1144852dc64dSPeter Maydell                              "too big to fit into RAM after the kernel",
1145852dc64dSPeter Maydell                              info->initrd_filename);
1146b48b0640SAndrew Jones                 exit(1);
1147852dc64dSPeter Maydell             }
114853018216SPaolo Bonzini         } else {
114953018216SPaolo Bonzini             initrd_size = 0;
115053018216SPaolo Bonzini         }
115153018216SPaolo Bonzini         info->initrd_size = initrd_size;
115253018216SPaolo Bonzini 
115347b1da81SPeter Maydell         fixupcontext[FIXUP_BOARDID] = info->board_id;
115410b8ec73SPeter Crosthwaite         fixupcontext[FIXUP_BOARD_SETUP] = info->board_setup_addr;
115553018216SPaolo Bonzini 
1156c3a42358SPeter Maydell         /*
1157c3a42358SPeter Maydell          * for device tree boot, we pass the DTB directly in r2. Otherwise
115853018216SPaolo Bonzini          * we point to the kernel args.
115953018216SPaolo Bonzini          */
116083bfffecSPeter Maydell         if (have_dtb(info)) {
116176e2aef3SAlexander Graf             hwaddr align;
116276e2aef3SAlexander Graf 
116376e2aef3SAlexander Graf             if (elf_machine == EM_AARCH64) {
116476e2aef3SAlexander Graf                 /*
116576e2aef3SAlexander Graf                  * Some AArch64 kernels on early bootup map the fdt region as
116676e2aef3SAlexander Graf                  *
116776e2aef3SAlexander Graf                  *   [ ALIGN_DOWN(fdt, 2MB) ... ALIGN_DOWN(fdt, 2MB) + 2MB ]
116876e2aef3SAlexander Graf                  *
116976e2aef3SAlexander Graf                  * Let's play safe and prealign it to 2MB to give us some space.
117053018216SPaolo Bonzini                  */
1171e4e34855SPhilippe Mathieu-Daudé                 align = 2 * MiB;
117276e2aef3SAlexander Graf             } else {
117376e2aef3SAlexander Graf                 /*
117476e2aef3SAlexander Graf                  * Some 32bit kernels will trash anything in the 4K page the
117576e2aef3SAlexander Graf                  * initrd ends in, so make sure the DTB isn't caught up in that.
117676e2aef3SAlexander Graf                  */
1177e4e34855SPhilippe Mathieu-Daudé                 align = 4 * KiB;
117876e2aef3SAlexander Graf             }
117976e2aef3SAlexander Graf 
118076e2aef3SAlexander Graf             /* Place the DTB after the initrd in memory with alignment. */
11813b77f6c3SIgor Mammedov             info->dtb_start = QEMU_ALIGN_UP(info->initrd_start + initrd_size,
11823b77f6c3SIgor Mammedov                                            align);
1183852dc64dSPeter Maydell             if (info->dtb_start >= ram_end) {
1184852dc64dSPeter Maydell                 error_report("Not enough space for DTB after kernel/initrd");
1185852dc64dSPeter Maydell                 exit(1);
1186852dc64dSPeter Maydell             }
1187751ebc13SRicardo Perez Blanco             fixupcontext[FIXUP_ARGPTR_LO] = info->dtb_start;
1188751ebc13SRicardo Perez Blanco             fixupcontext[FIXUP_ARGPTR_HI] = info->dtb_start >> 32;
118953018216SPaolo Bonzini         } else {
1190751ebc13SRicardo Perez Blanco             fixupcontext[FIXUP_ARGPTR_LO] =
1191751ebc13SRicardo Perez Blanco                 info->loader_start + KERNEL_ARGS_ADDR;
1192751ebc13SRicardo Perez Blanco             fixupcontext[FIXUP_ARGPTR_HI] =
1193751ebc13SRicardo Perez Blanco                 (info->loader_start + KERNEL_ARGS_ADDR) >> 32;
1194e4e34855SPhilippe Mathieu-Daudé             if (info->ram_size >= 4 * GiB) {
1195c0dbca36SAlistair Francis                 error_report("RAM size must be less than 4GB to boot"
119653018216SPaolo Bonzini                              " Linux kernel using ATAGS (try passing a device tree"
1197c0dbca36SAlistair Francis                              " using -dtb)");
119853018216SPaolo Bonzini                 exit(1);
119953018216SPaolo Bonzini             }
120053018216SPaolo Bonzini         }
1201751ebc13SRicardo Perez Blanco         fixupcontext[FIXUP_ENTRYPOINT_LO] = entry;
1202751ebc13SRicardo Perez Blanco         fixupcontext[FIXUP_ENTRYPOINT_HI] = entry >> 32;
120347b1da81SPeter Maydell 
120447b1da81SPeter Maydell         write_bootloader("bootloader", info->loader_start,
12059f43d4c3SPeter Maydell                          primary_loader, fixupcontext, as);
120647b1da81SPeter Maydell 
120753018216SPaolo Bonzini         if (info->nb_cpus > 1) {
120853018216SPaolo Bonzini             info->write_secondary_boot(cpu, info);
120953018216SPaolo Bonzini         }
121010b8ec73SPeter Crosthwaite         if (info->write_board_setup) {
121110b8ec73SPeter Crosthwaite             info->write_board_setup(cpu, info);
121210b8ec73SPeter Crosthwaite         }
1213d8b1ae42SPeter Maydell 
1214c3a42358SPeter Maydell         /*
1215c3a42358SPeter Maydell          * Notify devices which need to fake up firmware initialization
1216d8b1ae42SPeter Maydell          * that we're doing a direct kernel boot.
1217d8b1ae42SPeter Maydell          */
1218d8b1ae42SPeter Maydell         object_child_foreach_recursive(object_get_root(),
1219d8b1ae42SPeter Maydell                                        do_arm_linux_init, info);
122053018216SPaolo Bonzini     }
122153018216SPaolo Bonzini     info->is_linux = is_linux;
122253018216SPaolo Bonzini 
12230c949276SIgor Mammedov     for (cs = first_cpu; cs; cs = CPU_NEXT(cs)) {
1224c6faa758SArd Biesheuvel         ARM_CPU(cs)->env.boot_info = info;
122553018216SPaolo Bonzini     }
1226d33774eeSPeter Maydell }
1227d33774eeSPeter Maydell 
12284c0f2687SPeter Maydell static void arm_setup_firmware_boot(ARMCPU *cpu, struct arm_boot_info *info)
1229d33774eeSPeter Maydell {
12304c0f2687SPeter Maydell     /* Set up for booting firmware (which might load a kernel via fw_cfg) */
1231d33774eeSPeter Maydell 
1232d33774eeSPeter Maydell     if (have_dtb(info)) {
1233d33774eeSPeter Maydell         /*
1234d33774eeSPeter Maydell          * If we have a device tree blob, but no kernel to supply it to (or
1235d33774eeSPeter Maydell          * the kernel is supposed to be loaded by the bootloader), copy the
1236d33774eeSPeter Maydell          * DTB to the base of RAM for the bootloader to pick up.
1237d33774eeSPeter Maydell          */
1238d33774eeSPeter Maydell         info->dtb_start = info->loader_start;
1239d33774eeSPeter Maydell     }
1240d33774eeSPeter Maydell 
1241d33774eeSPeter Maydell     if (info->kernel_filename) {
1242d33774eeSPeter Maydell         FWCfgState *fw_cfg;
1243d33774eeSPeter Maydell         bool try_decompressing_kernel;
1244d33774eeSPeter Maydell 
1245d33774eeSPeter Maydell         fw_cfg = fw_cfg_find();
1246d33774eeSPeter Maydell         try_decompressing_kernel = arm_feature(&cpu->env,
1247d33774eeSPeter Maydell                                                ARM_FEATURE_AARCH64);
1248d33774eeSPeter Maydell 
1249d33774eeSPeter Maydell         /*
1250d33774eeSPeter Maydell          * Expose the kernel, the command line, and the initrd in fw_cfg.
1251d33774eeSPeter Maydell          * We don't process them here at all, it's all left to the
1252d33774eeSPeter Maydell          * firmware.
1253d33774eeSPeter Maydell          */
1254d33774eeSPeter Maydell         load_image_to_fw_cfg(fw_cfg,
1255d33774eeSPeter Maydell                              FW_CFG_KERNEL_SIZE, FW_CFG_KERNEL_DATA,
1256d33774eeSPeter Maydell                              info->kernel_filename,
1257d33774eeSPeter Maydell                              try_decompressing_kernel);
1258d33774eeSPeter Maydell         load_image_to_fw_cfg(fw_cfg,
1259d33774eeSPeter Maydell                              FW_CFG_INITRD_SIZE, FW_CFG_INITRD_DATA,
1260d33774eeSPeter Maydell                              info->initrd_filename, false);
1261d33774eeSPeter Maydell 
1262d33774eeSPeter Maydell         if (info->kernel_cmdline) {
1263d33774eeSPeter Maydell             fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,
1264d33774eeSPeter Maydell                            strlen(info->kernel_cmdline) + 1);
1265d33774eeSPeter Maydell             fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA,
1266d33774eeSPeter Maydell                               info->kernel_cmdline);
1267d33774eeSPeter Maydell         }
1268d33774eeSPeter Maydell     }
1269d33774eeSPeter Maydell 
1270d33774eeSPeter Maydell     /*
1271d33774eeSPeter Maydell      * We will start from address 0 (typically a boot ROM image) in the
12722a5bdfc8SPeter Maydell      * same way as hardware. Leave env->boot_info NULL, so that
12732a5bdfc8SPeter Maydell      * do_cpu_reset() knows it does not need to alter the PC on reset.
1274d33774eeSPeter Maydell      */
12754c0f2687SPeter Maydell }
12764c0f2687SPeter Maydell 
12772744ece8STao Xu void arm_load_kernel(ARMCPU *cpu, MachineState *ms, struct arm_boot_info *info)
12784c0f2687SPeter Maydell {
12794c0f2687SPeter Maydell     CPUState *cs;
12804c0f2687SPeter Maydell     AddressSpace *as = arm_boot_address_space(cpu, info);
12814c0f2687SPeter Maydell 
12824c0f2687SPeter Maydell     /*
12834c0f2687SPeter Maydell      * CPU objects (unlike devices) are not automatically reset on system
12844c0f2687SPeter Maydell      * reset, so we must always register a handler to do so. If we're
12854c0f2687SPeter Maydell      * actually loading a kernel, the handler is also responsible for
12864c0f2687SPeter Maydell      * arranging that we start it correctly.
12874c0f2687SPeter Maydell      */
12884c0f2687SPeter Maydell     for (cs = first_cpu; cs; cs = CPU_NEXT(cs)) {
12894c0f2687SPeter Maydell         qemu_register_reset(do_cpu_reset, ARM_CPU(cs));
12904c0f2687SPeter Maydell     }
12914c0f2687SPeter Maydell 
12924c0f2687SPeter Maydell     /*
12934c0f2687SPeter Maydell      * The board code is not supposed to set secure_board_setup unless
12944c0f2687SPeter Maydell      * running its code in secure mode is actually possible, and KVM
12954c0f2687SPeter Maydell      * doesn't support secure.
12964c0f2687SPeter Maydell      */
12974c0f2687SPeter Maydell     assert(!(info->secure_board_setup && kvm_enabled()));
12982744ece8STao Xu     info->kernel_filename = ms->kernel_filename;
12992744ece8STao Xu     info->kernel_cmdline = ms->kernel_cmdline;
13002744ece8STao Xu     info->initrd_filename = ms->initrd_filename;
13014c0f2687SPeter Maydell     info->dtb_filename = qemu_opt_get(qemu_get_machine_opts(), "dtb");
13024c0f2687SPeter Maydell     info->dtb_limit = 0;
13034c0f2687SPeter Maydell 
13044c0f2687SPeter Maydell     /* Load the kernel.  */
13054c0f2687SPeter Maydell     if (!info->kernel_filename || info->firmware_loaded) {
13064c0f2687SPeter Maydell         arm_setup_firmware_boot(cpu, info);
1307d33774eeSPeter Maydell     } else {
1308d33774eeSPeter Maydell         arm_setup_direct_kernel_boot(cpu, info);
1309d33774eeSPeter Maydell     }
131063a183edSEric Auger 
13113b77f6c3SIgor Mammedov     if (!info->skip_dtb_autoload && have_dtb(info)) {
13122744ece8STao Xu         if (arm_load_dtb(info->dtb_start, info, info->dtb_limit, as, ms) < 0) {
13133b77f6c3SIgor Mammedov             exit(1);
13143b77f6c3SIgor Mammedov         }
13153b77f6c3SIgor Mammedov     }
1316ac9d32e3SEric Auger }
1317d8b1ae42SPeter Maydell 
1318d8b1ae42SPeter Maydell static const TypeInfo arm_linux_boot_if_info = {
1319d8b1ae42SPeter Maydell     .name = TYPE_ARM_LINUX_BOOT_IF,
1320d8b1ae42SPeter Maydell     .parent = TYPE_INTERFACE,
1321d8b1ae42SPeter Maydell     .class_size = sizeof(ARMLinuxBootIfClass),
1322d8b1ae42SPeter Maydell };
1323d8b1ae42SPeter Maydell 
1324d8b1ae42SPeter Maydell static void arm_linux_boot_register_types(void)
1325d8b1ae42SPeter Maydell {
1326d8b1ae42SPeter Maydell     type_register_static(&arm_linux_boot_if_info);
1327d8b1ae42SPeter Maydell }
1328d8b1ae42SPeter Maydell 
1329d8b1ae42SPeter Maydell type_init(arm_linux_boot_register_types)
1330