187ecb68bSpbrook /* 212ec8bd5SPeter Maydell * ARM kernel loader. 387ecb68bSpbrook * 487ecb68bSpbrook * Copyright (c) 2006 CodeSourcery. 587ecb68bSpbrook * Written by Paul Brook 687ecb68bSpbrook * 78e31bf38SMatthew Fernandez * This code is licensed under the LGPL. 887ecb68bSpbrook * 987ecb68bSpbrook */ 1087ecb68bSpbrook 1112ec8bd5SPeter Maydell #ifndef HW_ARM_BOOT_H 1212ec8bd5SPeter Maydell #define HW_ARM_BOOT_H 1387ecb68bSpbrook 14fcf5ef2aSThomas Huth #include "target/arm/cpu-qom.h" 15ac9d32e3SEric Auger #include "qemu/notify.h" 167d6f78cfSAvi Kivity 179776f636SPeter Crosthwaite typedef enum { 189776f636SPeter Crosthwaite ARM_ENDIANNESS_UNKNOWN = 0, 199776f636SPeter Crosthwaite ARM_ENDIANNESS_LE, 209776f636SPeter Crosthwaite ARM_ENDIANNESS_BE8, 219776f636SPeter Crosthwaite ARM_ENDIANNESS_BE32, 229776f636SPeter Crosthwaite } arm_endianness; 239776f636SPeter Crosthwaite 243651c285SPeter Maydell /** 253651c285SPeter Maydell * armv7m_load_kernel: 263651c285SPeter Maydell * @cpu: CPU 273651c285SPeter Maydell * @kernel_filename: file to load 283651c285SPeter Maydell * @mem_size: mem_size: maximum image size to load 293651c285SPeter Maydell * 303651c285SPeter Maydell * Load the guest image for an ARMv7M system. This must be called by 3138d81dafSPeter Maydell * any ARMv7M board. (This is necessary to ensure that the CPU resets 3238d81dafSPeter Maydell * correctly on system reset, as well as for kernel loading.) 333651c285SPeter Maydell */ 343651c285SPeter Maydell void armv7m_load_kernel(ARMCPU *cpu, const char *kernel_filename, int mem_size); 3587ecb68bSpbrook 3687ecb68bSpbrook /* arm_boot.c */ 37f93eb9ffSbalrog struct arm_boot_info { 38de841deaSPeter Maydell uint64_t ram_size; 39f93eb9ffSbalrog const char *kernel_filename; 40f93eb9ffSbalrog const char *kernel_cmdline; 41f93eb9ffSbalrog const char *initrd_filename; 42412beee6SGrant Likely const char *dtb_filename; 43a8170e5eSAvi Kivity hwaddr loader_start; 443b77f6c3SIgor Mammedov hwaddr dtb_start; 453b77f6c3SIgor Mammedov hwaddr dtb_limit; 463b77f6c3SIgor Mammedov /* If set to True, arm_load_kernel() will not load DTB. 473b77f6c3SIgor Mammedov * It allows board to load DTB manually later. 483b77f6c3SIgor Mammedov * (default: False) 493b77f6c3SIgor Mammedov */ 503b77f6c3SIgor Mammedov bool skip_dtb_autoload; 519d5ba9bfSMark Langsdorf /* multicore boards that use the default secondary core boot functions 529d5ba9bfSMark Langsdorf * need to put the address of the secondary boot code, the boot reg, 539d5ba9bfSMark Langsdorf * and the GIC address in the next 3 values, respectively. boards that 549d5ba9bfSMark Langsdorf * have their own boot functions can use these values as they want. 559d5ba9bfSMark Langsdorf */ 56a8170e5eSAvi Kivity hwaddr smp_loader_start; 57a8170e5eSAvi Kivity hwaddr smp_bootreg_addr; 58a8170e5eSAvi Kivity hwaddr gic_cpu_if_addr; 59f93eb9ffSbalrog int nb_cpus; 60f93eb9ffSbalrog int board_id; 61c8e829b7SGreg Bellows /* ARM machines that support the ARM Security Extensions use this field to 62c8e829b7SGreg Bellows * control whether Linux is booted as secure(true) or non-secure(false). 63c8e829b7SGreg Bellows */ 64c8e829b7SGreg Bellows bool secure_boot; 65462a8bc6SStefan Weil int (*atag_board)(const struct arm_boot_info *info, void *p); 669d5ba9bfSMark Langsdorf /* multicore boards that use the default secondary core boot functions 679d5ba9bfSMark Langsdorf * can ignore these two function calls. If the default functions won't 689d5ba9bfSMark Langsdorf * work, then write_secondary_boot() should write a suitable blob of 699b574c29SAndreas Färber * code mimicking the secondary CPU startup process used by the board's 709d5ba9bfSMark Langsdorf * boot loader/boot ROM code, and secondary_cpu_reset_hook() should 719b574c29SAndreas Färber * perform any necessary CPU reset handling and set the PC for the 729d5ba9bfSMark Langsdorf * secondary CPUs to point at this boot blob. 739d5ba9bfSMark Langsdorf */ 749543b0cdSAndreas Färber void (*write_secondary_boot)(ARMCPU *cpu, 759d5ba9bfSMark Langsdorf const struct arm_boot_info *info); 765d309320SAndreas Färber void (*secondary_cpu_reset_hook)(ARMCPU *cpu, 779d5ba9bfSMark Langsdorf const struct arm_boot_info *info); 780fb79851SJohn Rigby /* if a board is able to create a dtb without a dtb file then it 790fb79851SJohn Rigby * sets get_dtb. This will only be used if no dtb file is provided 800fb79851SJohn Rigby * by the user. On success, sets *size to the length of the created 810fb79851SJohn Rigby * dtb, and returns a pointer to it. (The caller must free this memory 820fb79851SJohn Rigby * with g_free() when it has finished with it.) On failure, returns NULL. 830fb79851SJohn Rigby */ 840fb79851SJohn Rigby void *(*get_dtb)(const struct arm_boot_info *info, int *size); 853b1cceb8SPeter Maydell /* if a board needs to be able to modify a device tree provided by 863b1cceb8SPeter Maydell * the user it should implement this hook. 873b1cceb8SPeter Maydell */ 883b1cceb8SPeter Maydell void (*modify_dtb)(const struct arm_boot_info *info, void *fdt); 89f2d74978SPaul Brook /* Used internally by arm_boot.c */ 90f2d74978SPaul Brook int is_linux; 91fc53b7d4SPeter Maydell hwaddr initrd_start; 92a8170e5eSAvi Kivity hwaddr initrd_size; 93a8170e5eSAvi Kivity hwaddr entry; 9407abe45cSLaszlo Ersek 9507abe45cSLaszlo Ersek /* Boot firmware has been loaded, typically at address 0, with -bios or 9607abe45cSLaszlo Ersek * -pflash. It also implies that fw_cfg_find() will succeed. 9707abe45cSLaszlo Ersek */ 9807abe45cSLaszlo Ersek bool firmware_loaded; 9910b8ec73SPeter Crosthwaite 10010b8ec73SPeter Crosthwaite /* Address at which board specific loader/setup code exists. If enabled, 10110b8ec73SPeter Crosthwaite * this code-blob will run before anything else. It must return to the 10210b8ec73SPeter Crosthwaite * caller via the link register. There is no stack set up. Enabled by 10310b8ec73SPeter Crosthwaite * defining write_board_setup, which is responsible for loading the blob 10410b8ec73SPeter Crosthwaite * to the specified address. 10510b8ec73SPeter Crosthwaite */ 10610b8ec73SPeter Crosthwaite hwaddr board_setup_addr; 10710b8ec73SPeter Crosthwaite void (*write_board_setup)(ARMCPU *cpu, 10810b8ec73SPeter Crosthwaite const struct arm_boot_info *info); 109baf6b681SPeter Crosthwaite 110baf6b681SPeter Crosthwaite /* If set, the board specific loader/setup blob will be run from secure 111baf6b681SPeter Crosthwaite * mode, regardless of secure_boot. The blob becomes responsible for 112baf6b681SPeter Crosthwaite * changing to non-secure state if implementing a non-secure boot 113baf6b681SPeter Crosthwaite */ 114baf6b681SPeter Crosthwaite bool secure_board_setup; 1159776f636SPeter Crosthwaite 1169776f636SPeter Crosthwaite arm_endianness endianness; 117f93eb9ffSbalrog }; 118ac9d32e3SEric Auger 119ac9d32e3SEric Auger /** 120ac9d32e3SEric Auger * arm_load_kernel - Loads memory with everything needed to boot 121ac9d32e3SEric Auger * 122ac9d32e3SEric Auger * @cpu: handle to the first CPU object 123ac9d32e3SEric Auger * @info: handle to the boot info struct 124ac9d32e3SEric Auger * Registers a machine init done notifier that copies to memory 125ac9d32e3SEric Auger * everything needed to boot, depending on machine and user options: 126ac9d32e3SEric Auger * kernel image, boot loaders, initrd, dtb. Also registers the CPU 127ac9d32e3SEric Auger * reset handler. 128ac9d32e3SEric Auger * 129ac9d32e3SEric Auger * In case the machine file supports the platform bus device and its 130ac9d32e3SEric Auger * dynamically instantiable sysbus devices, this function must be called 131ac9d32e3SEric Auger * before sysbus-fdt arm_register_platform_bus_fdt_creator. Indeed the 132ac9d32e3SEric Auger * machine init done notifiers are called in registration reverse order. 133ac9d32e3SEric Auger */ 134*2744ece8STao Xu void arm_load_kernel(ARMCPU *cpu, MachineState *ms, struct arm_boot_info *info); 13587ecb68bSpbrook 1363b77f6c3SIgor Mammedov AddressSpace *arm_boot_address_space(ARMCPU *cpu, 1373b77f6c3SIgor Mammedov const struct arm_boot_info *info); 1383b77f6c3SIgor Mammedov 1393b77f6c3SIgor Mammedov /** 1403b77f6c3SIgor Mammedov * arm_load_dtb() - load a device tree binary image into memory 1413b77f6c3SIgor Mammedov * @addr: the address to load the image at 1423b77f6c3SIgor Mammedov * @binfo: struct describing the boot environment 1433b77f6c3SIgor Mammedov * @addr_limit: upper limit of the available memory area at @addr 1443b77f6c3SIgor Mammedov * @as: address space to load image to 1453b77f6c3SIgor Mammedov * 1463b77f6c3SIgor Mammedov * Load a device tree supplied by the machine or by the user with the 1473b77f6c3SIgor Mammedov * '-dtb' command line option, and put it at offset @addr in target 1483b77f6c3SIgor Mammedov * memory. 1493b77f6c3SIgor Mammedov * 1503b77f6c3SIgor Mammedov * If @addr_limit contains a meaningful value (i.e., it is strictly greater 1513b77f6c3SIgor Mammedov * than @addr), the device tree is only loaded if its size does not exceed 1523b77f6c3SIgor Mammedov * the limit. 1533b77f6c3SIgor Mammedov * 1543b77f6c3SIgor Mammedov * Returns: the size of the device tree image on success, 1553b77f6c3SIgor Mammedov * 0 if the image size exceeds the limit, 1563b77f6c3SIgor Mammedov * -1 on errors. 1573b77f6c3SIgor Mammedov * 1583b77f6c3SIgor Mammedov * Note: Must not be called unless have_dtb(binfo) is true. 1593b77f6c3SIgor Mammedov */ 1603b77f6c3SIgor Mammedov int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo, 161*2744ece8STao Xu hwaddr addr_limit, AddressSpace *as, MachineState *ms); 1623b77f6c3SIgor Mammedov 163716536a9SAndrew Baumann /* Write a secure board setup routine with a dummy handler for SMCs */ 164716536a9SAndrew Baumann void arm_write_secure_board_setup_dummy_smc(ARMCPU *cpu, 165716536a9SAndrew Baumann const struct arm_boot_info *info, 166716536a9SAndrew Baumann hwaddr mvbar_addr); 167716536a9SAndrew Baumann 16812ec8bd5SPeter Maydell #endif /* HW_ARM_BOOT_H */ 169