2
0

boot.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. * ARM kernel loader.
  3. *
  4. * Copyright (c) 2006 CodeSourcery.
  5. * Written by Paul Brook
  6. *
  7. * This code is licensed under the LGPL.
  8. *
  9. */
  10. #ifndef HW_ARM_BOOT_H
  11. #define HW_ARM_BOOT_H
  12. #include "target/arm/cpu-qom.h"
  13. #include "qemu/notify.h"
  14. typedef enum {
  15. ARM_ENDIANNESS_UNKNOWN = 0,
  16. ARM_ENDIANNESS_LE,
  17. ARM_ENDIANNESS_BE8,
  18. ARM_ENDIANNESS_BE32,
  19. } arm_endianness;
  20. /**
  21. * armv7m_load_kernel:
  22. * @cpu: CPU
  23. * @kernel_filename: file to load
  24. * @mem_base: base address to load image at (should be where the
  25. * CPU expects to find its vector table on reset)
  26. * @mem_size: mem_size: maximum image size to load
  27. *
  28. * Load the guest image for an ARMv7M system. This must be called by
  29. * any ARMv7M board. (This is necessary to ensure that the CPU resets
  30. * correctly on system reset, as well as for kernel loading.)
  31. */
  32. void armv7m_load_kernel(ARMCPU *cpu, const char *kernel_filename,
  33. hwaddr mem_base, int mem_size);
  34. /* arm_boot.c */
  35. struct arm_boot_info {
  36. uint64_t ram_size;
  37. const char *kernel_filename;
  38. const char *kernel_cmdline;
  39. const char *initrd_filename;
  40. const char *dtb_filename;
  41. hwaddr loader_start;
  42. hwaddr dtb_start;
  43. hwaddr dtb_limit;
  44. /* If set to True, arm_load_kernel() will not load DTB.
  45. * It allows board to load DTB manually later.
  46. * (default: False)
  47. */
  48. bool skip_dtb_autoload;
  49. /* multicore boards that use the default secondary core boot functions
  50. * need to put the address of the secondary boot code, the boot reg,
  51. * and the GIC address in the next 3 values, respectively. boards that
  52. * have their own boot functions can use these values as they want.
  53. */
  54. hwaddr smp_loader_start;
  55. hwaddr smp_bootreg_addr;
  56. hwaddr gic_cpu_if_addr;
  57. int board_id;
  58. /* ARM machines that support the ARM Security Extensions use this field to
  59. * control whether Linux is booted as secure(true) or non-secure(false).
  60. */
  61. bool secure_boot;
  62. int (*atag_board)(const struct arm_boot_info *info, void *p);
  63. /* multicore boards that use the default secondary core boot functions
  64. * can ignore these two function calls. If the default functions won't
  65. * work, then write_secondary_boot() should write a suitable blob of
  66. * code mimicking the secondary CPU startup process used by the board's
  67. * boot loader/boot ROM code, and secondary_cpu_reset_hook() should
  68. * perform any necessary CPU reset handling and set the PC for the
  69. * secondary CPUs to point at this boot blob.
  70. *
  71. * These hooks won't be called if secondary CPUs are booting via
  72. * emulated PSCI (see psci_conduit below).
  73. */
  74. void (*write_secondary_boot)(ARMCPU *cpu,
  75. const struct arm_boot_info *info);
  76. void (*secondary_cpu_reset_hook)(ARMCPU *cpu,
  77. const struct arm_boot_info *info);
  78. /* if a board is able to create a dtb without a dtb file then it
  79. * sets get_dtb. This will only be used if no dtb file is provided
  80. * by the user. On success, sets *size to the length of the created
  81. * dtb, and returns a pointer to it. (The caller must free this memory
  82. * with g_free() when it has finished with it.) On failure, returns NULL.
  83. */
  84. void *(*get_dtb)(const struct arm_boot_info *info, int *size);
  85. /* if a board needs to be able to modify a device tree provided by
  86. * the user it should implement this hook.
  87. */
  88. void (*modify_dtb)(const struct arm_boot_info *info, void *fdt);
  89. /*
  90. * If a board wants to use the QEMU emulated-firmware PSCI support,
  91. * it should set this to QEMU_PSCI_CONDUIT_HVC or QEMU_PSCI_CONDUIT_SMC
  92. * as appropriate. arm_load_kernel() will set the psci-conduit and
  93. * start-powered-off properties on the CPUs accordingly.
  94. * Note that if the guest image is started at the same exception level
  95. * as the conduit specifies calls should go to (eg guest firmware booted
  96. * to EL3) then PSCI will not be enabled.
  97. */
  98. int psci_conduit;
  99. /* Used internally by arm_boot.c */
  100. int is_linux;
  101. hwaddr initrd_start;
  102. hwaddr initrd_size;
  103. hwaddr entry;
  104. /* Boot firmware has been loaded, typically at address 0, with -bios or
  105. * -pflash. It also implies that fw_cfg_find() will succeed.
  106. */
  107. bool firmware_loaded;
  108. /* Address at which board specific loader/setup code exists. If enabled,
  109. * this code-blob will run before anything else. It must return to the
  110. * caller via the link register. There is no stack set up. Enabled by
  111. * defining write_board_setup, which is responsible for loading the blob
  112. * to the specified address.
  113. */
  114. hwaddr board_setup_addr;
  115. void (*write_board_setup)(ARMCPU *cpu,
  116. const struct arm_boot_info *info);
  117. /*
  118. * If set, the board specific loader/setup blob will be run from secure
  119. * mode, regardless of secure_boot. The blob becomes responsible for
  120. * changing to non-secure state if implementing a non-secure boot,
  121. * including setting up EL3/Secure registers such as the NSACR as
  122. * required by the Linux booting ABI before the switch to non-secure.
  123. */
  124. bool secure_board_setup;
  125. arm_endianness endianness;
  126. };
  127. /**
  128. * arm_load_kernel - Loads memory with everything needed to boot
  129. *
  130. * @cpu: handle to the first CPU object
  131. * @info: handle to the boot info struct
  132. * Registers a machine init done notifier that copies to memory
  133. * everything needed to boot, depending on machine and user options:
  134. * kernel image, boot loaders, initrd, dtb. Also registers the CPU
  135. * reset handler.
  136. *
  137. * In case the machine file supports the platform bus device and its
  138. * dynamically instantiable sysbus devices, this function must be called
  139. * before sysbus-fdt arm_register_platform_bus_fdt_creator. Indeed the
  140. * machine init done notifiers are called in registration reverse order.
  141. */
  142. void arm_load_kernel(ARMCPU *cpu, MachineState *ms, struct arm_boot_info *info);
  143. AddressSpace *arm_boot_address_space(ARMCPU *cpu,
  144. const struct arm_boot_info *info);
  145. /**
  146. * arm_load_dtb() - load a device tree binary image into memory
  147. * @addr: the address to load the image at
  148. * @binfo: struct describing the boot environment
  149. * @addr_limit: upper limit of the available memory area at @addr
  150. * @as: address space to load image to
  151. * @cpu: ARM CPU object
  152. *
  153. * Load a device tree supplied by the machine or by the user with the
  154. * '-dtb' command line option, and put it at offset @addr in target
  155. * memory.
  156. *
  157. * If @addr_limit contains a meaningful value (i.e., it is strictly greater
  158. * than @addr), the device tree is only loaded if its size does not exceed
  159. * the limit.
  160. *
  161. * Returns: the size of the device tree image on success,
  162. * 0 if the image size exceeds the limit,
  163. * -1 on errors.
  164. *
  165. * Note: Must not be called unless have_dtb(binfo) is true.
  166. */
  167. int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
  168. hwaddr addr_limit, AddressSpace *as, MachineState *ms,
  169. ARMCPU *cpu);
  170. /* Write a secure board setup routine with a dummy handler for SMCs */
  171. void arm_write_secure_board_setup_dummy_smc(ARMCPU *cpu,
  172. const struct arm_boot_info *info,
  173. hwaddr mvbar_addr);
  174. typedef enum {
  175. FIXUP_NONE = 0, /* do nothing */
  176. FIXUP_TERMINATOR, /* end of insns */
  177. FIXUP_BOARDID, /* overwrite with board ID number */
  178. FIXUP_BOARD_SETUP, /* overwrite with board specific setup code address */
  179. FIXUP_ARGPTR_LO, /* overwrite with pointer to kernel args */
  180. FIXUP_ARGPTR_HI, /* overwrite with pointer to kernel args (high half) */
  181. FIXUP_ENTRYPOINT_LO, /* overwrite with kernel entry point */
  182. FIXUP_ENTRYPOINT_HI, /* overwrite with kernel entry point (high half) */
  183. FIXUP_GIC_CPU_IF, /* overwrite with GIC CPU interface address */
  184. FIXUP_BOOTREG, /* overwrite with boot register address */
  185. FIXUP_DSB, /* overwrite with correct DSB insn for cpu */
  186. FIXUP_MAX,
  187. } FixupType;
  188. typedef struct ARMInsnFixup {
  189. uint32_t insn;
  190. FixupType fixup;
  191. } ARMInsnFixup;
  192. /**
  193. * arm_write_bootloader - write a bootloader to guest memory
  194. * @name: name of the bootloader blob
  195. * @as: AddressSpace to write the bootloader
  196. * @addr: guest address to write it
  197. * @insns: the blob to be loaded
  198. * @fixupcontext: context to be used for any fixups in @insns
  199. *
  200. * Write a bootloader to guest memory at address @addr in the address
  201. * space @as. @name is the name to use for the resulting ROM blob, so
  202. * it should be unique in the system and reasonably identifiable for debugging.
  203. *
  204. * @insns must be an array of ARMInsnFixup structs, each of which has
  205. * one 32-bit value to be written to the guest memory, and a fixup to be
  206. * applied to the value. FIXUP_NONE (do nothing) is value 0, so effectively
  207. * the fixup is optional when writing a struct initializer.
  208. * The final entry in the array must be { 0, FIXUP_TERMINATOR }.
  209. *
  210. * All other supported fixup types have the semantics "ignore insn
  211. * and instead use the value from the array element @fixupcontext[fixup]".
  212. * The caller should therefore provide @fixupcontext as an array of
  213. * size FIXUP_MAX whose elements have been initialized for at least
  214. * the entries that @insns refers to.
  215. */
  216. void arm_write_bootloader(const char *name,
  217. AddressSpace *as, hwaddr addr,
  218. const ARMInsnFixup *insns,
  219. const uint32_t *fixupcontext);
  220. #endif /* HW_ARM_BOOT_H */