Blue Swirl | ca20cf3 | 2009-09-20 14:58:02 +0000 | [diff] [blame] | 1 | #ifndef LOADER_H |
| 2 | #define LOADER_H |
Laszlo Ersek | a88b362 | 2013-04-16 02:24:08 +0200 | [diff] [blame] | 3 | #include "hw/nvram/fw_cfg.h" |
Blue Swirl | ca20cf3 | 2009-09-20 14:58:02 +0000 | [diff] [blame] | 4 | |
| 5 | /* loader.c */ |
Michael S. Tsirkin | a1483f8 | 2014-02-05 21:57:55 +0200 | [diff] [blame] | 6 | /** |
| 7 | * get_image_size: retrieve size of an image file |
| 8 | * @filename: Path to the image file |
| 9 | * |
| 10 | * Returns the size of the image file on success, -1 otherwise. |
| 11 | * On error, errno is also set as appropriate. |
| 12 | */ |
Li Zhijian | f3839fd | 2018-09-13 18:07:13 +0800 | [diff] [blame] | 13 | int64_t get_image_size(const char *filename); |
Peter Maydell | 0619232 | 2018-12-14 13:30:53 +0000 | [diff] [blame] | 14 | /** |
| 15 | * load_image_size: load an image file into specified buffer |
| 16 | * @filename: Path to the image file |
| 17 | * @addr: Buffer to load image into |
| 18 | * @size: Size of buffer in bytes |
| 19 | * |
| 20 | * Load an image file from disk into the specified buffer. |
| 21 | * If the image is larger than the specified buffer, only |
| 22 | * @size bytes are read (this is not considered an error). |
| 23 | * |
| 24 | * Prefer to use the GLib function g_file_get_contents() rather |
| 25 | * than a "get_image_size()/g_malloc()/load_image_size()" sequence. |
| 26 | * |
| 27 | * Returns the number of bytes read, or -1 on error. On error, |
| 28 | * errno is also set as appropriate. |
| 29 | */ |
Benjamin Herrenschmidt | ea87616 | 2014-07-21 13:02:03 +1000 | [diff] [blame] | 30 | ssize_t load_image_size(const char *filename, void *addr, size_t size); |
Alistair Francis | 93ffc7c | 2016-09-22 18:13:08 +0100 | [diff] [blame] | 31 | |
| 32 | /**load_image_targphys_as: |
| 33 | * @filename: Path to the image file |
| 34 | * @addr: Address to load the image to |
| 35 | * @max_sz: The maximum size of the image to load |
| 36 | * @as: The AddressSpace to load the ELF to. The value of address_space_memory |
| 37 | * is used if nothing is supplied here. |
| 38 | * |
| 39 | * Load a fixed image into memory. |
| 40 | * |
| 41 | * Returns the size of the loaded image on success, -1 otherwise. |
| 42 | */ |
Jamie Iles | af97513 | 2021-11-11 14:11:40 +0000 | [diff] [blame] | 43 | ssize_t load_image_targphys_as(const char *filename, |
| 44 | hwaddr addr, uint64_t max_sz, AddressSpace *as); |
Alistair Francis | 93ffc7c | 2016-09-22 18:13:08 +0100 | [diff] [blame] | 45 | |
Su Hang | e4a25ed | 2018-08-16 14:05:28 +0100 | [diff] [blame] | 46 | /**load_targphys_hex_as: |
| 47 | * @filename: Path to the .hex file |
| 48 | * @entry: Store the entry point given by the .hex file |
| 49 | * @as: The AddressSpace to load the .hex file to. The value of |
| 50 | * address_space_memory is used if nothing is supplied here. |
| 51 | * |
| 52 | * Load a fixed .hex file into memory. |
| 53 | * |
| 54 | * Returns the size of the loaded .hex file on success, -1 otherwise. |
| 55 | */ |
Jamie Iles | af97513 | 2021-11-11 14:11:40 +0000 | [diff] [blame] | 56 | ssize_t load_targphys_hex_as(const char *filename, hwaddr *entry, |
| 57 | AddressSpace *as); |
Su Hang | e4a25ed | 2018-08-16 14:05:28 +0100 | [diff] [blame] | 58 | |
Alistair Francis | 93ffc7c | 2016-09-22 18:13:08 +0100 | [diff] [blame] | 59 | /** load_image_targphys: |
| 60 | * Same as load_image_targphys_as(), but doesn't allow the caller to specify |
| 61 | * an AddressSpace. |
| 62 | */ |
Jamie Iles | af97513 | 2021-11-11 14:11:40 +0000 | [diff] [blame] | 63 | ssize_t load_image_targphys(const char *filename, hwaddr, |
| 64 | uint64_t max_sz); |
Alistair Francis | 93ffc7c | 2016-09-22 18:13:08 +0100 | [diff] [blame] | 65 | |
Peter Maydell | 76151ca | 2016-03-04 11:30:17 +0000 | [diff] [blame] | 66 | /** |
| 67 | * load_image_mr: load an image into a memory region |
| 68 | * @filename: Path to the image file |
| 69 | * @mr: Memory Region to load into |
| 70 | * |
| 71 | * Load the specified file into the memory region. |
| 72 | * The file loaded is registered as a ROM, so its contents will be |
| 73 | * reinstated whenever the system is reset. |
| 74 | * If the file is larger than the memory region's size the call will fail. |
| 75 | * Returns -1 on failure, or the size of the file. |
| 76 | */ |
Jamie Iles | af97513 | 2021-11-11 14:11:40 +0000 | [diff] [blame] | 77 | ssize_t load_image_mr(const char *filename, MemoryRegion *mr); |
Laszlo Ersek | 7d48a0f | 2014-12-22 13:11:43 +0100 | [diff] [blame] | 78 | |
| 79 | /* This is the limit on the maximum uncompressed image size that |
| 80 | * load_image_gzipped_buffer() and load_image_gzipped() will read. It prevents |
| 81 | * g_malloc() in those functions from allocating a huge amount of memory. |
| 82 | */ |
| 83 | #define LOAD_IMAGE_MAX_GUNZIP_BYTES (256 << 20) |
| 84 | |
Jamie Iles | af97513 | 2021-11-11 14:11:40 +0000 | [diff] [blame] | 85 | ssize_t load_image_gzipped_buffer(const char *filename, uint64_t max_sz, |
| 86 | uint8_t **buffer); |
| 87 | ssize_t load_image_gzipped(const char *filename, hwaddr addr, uint64_t max_sz); |
Alexey Kardashevskiy | 18674b2 | 2014-02-04 15:04:18 +1100 | [diff] [blame] | 88 | |
| 89 | #define ELF_LOAD_FAILED -1 |
| 90 | #define ELF_LOAD_NOT_ELF -2 |
| 91 | #define ELF_LOAD_WRONG_ARCH -3 |
| 92 | #define ELF_LOAD_WRONG_ENDIAN -4 |
Stefano Garzarella | 41a2635 | 2019-09-10 16:22:23 +0200 | [diff] [blame] | 93 | #define ELF_LOAD_TOO_BIG -5 |
Luc Michel | 8975eb8 | 2021-10-14 21:43:25 +0200 | [diff] [blame] | 94 | const char *load_elf_strerror(ssize_t error); |
Peter Crosthwaite | 140b7ce | 2016-03-04 11:30:21 +0000 | [diff] [blame] | 95 | |
Michael Clark | a2480ff | 2018-03-03 01:31:12 +1300 | [diff] [blame] | 96 | /** load_elf_ram_sym: |
Peter Crosthwaite | 140b7ce | 2016-03-04 11:30:21 +0000 | [diff] [blame] | 97 | * @filename: Path of ELF file |
Liam Merwick | 4366e1d | 2019-01-15 12:18:03 +0000 | [diff] [blame] | 98 | * @elf_note_fn: optional function to parse ELF Note type |
| 99 | * passed via @translate_opaque |
Peter Crosthwaite | 140b7ce | 2016-03-04 11:30:21 +0000 | [diff] [blame] | 100 | * @translate_fn: optional function to translate load addresses |
| 101 | * @translate_opaque: opaque data passed to @translate_fn |
| 102 | * @pentry: Populated with program entry point. Ignored if NULL. |
| 103 | * @lowaddr: Populated with lowest loaded address. Ignored if NULL. |
| 104 | * @highaddr: Populated with highest loaded address. Ignored if NULL. |
Aleksandar Markovic | 6cdda0f | 2020-01-26 23:55:04 +0100 | [diff] [blame] | 105 | * @pflags: Populated with ELF processor-specific flags. Ignore if NULL. |
Peter Crosthwaite | 140b7ce | 2016-03-04 11:30:21 +0000 | [diff] [blame] | 106 | * @bigendian: Expected ELF endianness. 0 for LE otherwise BE |
| 107 | * @elf_machine: Expected ELF machine type |
| 108 | * @clear_lsb: Set to mask off LSB of addresses (Some architectures use |
| 109 | * this for non-address data) |
Peter Crosthwaite | 7ef295e | 2016-03-04 11:30:21 +0000 | [diff] [blame] | 110 | * @data_swab: Set to order of byte swapping for data. 0 for no swap, 1 |
| 111 | * for swapping bytes within halfwords, 2 for bytes within |
| 112 | * words and 3 for within doublewords. |
Alistair Francis | 70bb1d1 | 2016-09-22 18:13:08 +0100 | [diff] [blame] | 113 | * @as: The AddressSpace to load the ELF to. The value of address_space_memory |
| 114 | * is used if nothing is supplied here. |
Farhan Ali | 34f1b23 | 2016-11-07 10:50:30 -0500 | [diff] [blame] | 115 | * @load_rom : Load ELF binary as ROM |
Michael Clark | a2480ff | 2018-03-03 01:31:12 +1300 | [diff] [blame] | 116 | * @sym_cb: Callback function for symbol table entries |
Peter Crosthwaite | 140b7ce | 2016-03-04 11:30:21 +0000 | [diff] [blame] | 117 | * |
| 118 | * Load an ELF file's contents to the emulated system's address space. |
| 119 | * Clients may optionally specify a callback to perform address |
| 120 | * translations. @pentry, @lowaddr and @highaddr are optional pointers |
| 121 | * which will be populated with various load information. @bigendian and |
| 122 | * @elf_machine give the expected endianness and machine for the ELF the |
| 123 | * load will fail if the target ELF does not match. Some architectures |
| 124 | * have some architecture-specific behaviours that come into effect when |
| 125 | * their particular values for @elf_machine are set. |
Alistair Francis | 8cf6e9d | 2016-09-22 18:13:07 +0100 | [diff] [blame] | 126 | * If @elf_machine is EM_NONE then the machine type will be read from the |
| 127 | * ELF header and no checks will be carried out against the machine type. |
Peter Crosthwaite | 140b7ce | 2016-03-04 11:30:21 +0000 | [diff] [blame] | 128 | */ |
Michael Clark | a2480ff | 2018-03-03 01:31:12 +1300 | [diff] [blame] | 129 | typedef void (*symbol_fn_t)(const char *st_name, int st_info, |
| 130 | uint64_t st_value, uint64_t st_size); |
| 131 | |
Luc Michel | 8975eb8 | 2021-10-14 21:43:25 +0200 | [diff] [blame] | 132 | ssize_t load_elf_ram_sym(const char *filename, |
| 133 | uint64_t (*elf_note_fn)(void *, void *, bool), |
| 134 | uint64_t (*translate_fn)(void *, uint64_t), |
| 135 | void *translate_opaque, uint64_t *pentry, |
| 136 | uint64_t *lowaddr, uint64_t *highaddr, |
| 137 | uint32_t *pflags, int big_endian, int elf_machine, |
| 138 | int clear_lsb, int data_swab, |
| 139 | AddressSpace *as, bool load_rom, symbol_fn_t sym_cb); |
Michael Clark | a2480ff | 2018-03-03 01:31:12 +1300 | [diff] [blame] | 140 | |
| 141 | /** load_elf_ram: |
| 142 | * Same as load_elf_ram_sym(), but doesn't allow the caller to specify a |
| 143 | * symbol callback function |
| 144 | */ |
Luc Michel | 8975eb8 | 2021-10-14 21:43:25 +0200 | [diff] [blame] | 145 | ssize_t load_elf_ram(const char *filename, |
| 146 | uint64_t (*elf_note_fn)(void *, void *, bool), |
| 147 | uint64_t (*translate_fn)(void *, uint64_t), |
| 148 | void *translate_opaque, uint64_t *pentry, |
| 149 | uint64_t *lowaddr, uint64_t *highaddr, uint32_t *pflags, |
| 150 | int big_endian, int elf_machine, int clear_lsb, |
| 151 | int data_swab, AddressSpace *as, bool load_rom); |
Farhan Ali | 34f1b23 | 2016-11-07 10:50:30 -0500 | [diff] [blame] | 152 | |
| 153 | /** load_elf_as: |
| 154 | * Same as load_elf_ram(), but always loads the elf as ROM |
| 155 | */ |
Luc Michel | 8975eb8 | 2021-10-14 21:43:25 +0200 | [diff] [blame] | 156 | ssize_t load_elf_as(const char *filename, |
| 157 | uint64_t (*elf_note_fn)(void *, void *, bool), |
| 158 | uint64_t (*translate_fn)(void *, uint64_t), |
| 159 | void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr, |
| 160 | uint64_t *highaddr, uint32_t *pflags, int big_endian, |
| 161 | int elf_machine, int clear_lsb, int data_swab, |
| 162 | AddressSpace *as); |
Peter Crosthwaite | 140b7ce | 2016-03-04 11:30:21 +0000 | [diff] [blame] | 163 | |
Alistair Francis | 70bb1d1 | 2016-09-22 18:13:08 +0100 | [diff] [blame] | 164 | /** load_elf: |
| 165 | * Same as load_elf_as(), but doesn't allow the caller to specify an |
| 166 | * AddressSpace. |
| 167 | */ |
Luc Michel | 8975eb8 | 2021-10-14 21:43:25 +0200 | [diff] [blame] | 168 | ssize_t load_elf(const char *filename, |
| 169 | uint64_t (*elf_note_fn)(void *, void *, bool), |
| 170 | uint64_t (*translate_fn)(void *, uint64_t), |
| 171 | void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr, |
| 172 | uint64_t *highaddr, uint32_t *pflags, int big_endian, |
| 173 | int elf_machine, int clear_lsb, int data_swab); |
Peter Crosthwaite | 04ae712 | 2016-03-04 11:30:21 +0000 | [diff] [blame] | 174 | |
| 175 | /** load_elf_hdr: |
| 176 | * @filename: Path of ELF file |
| 177 | * @hdr: Buffer to populate with header data. Header data will not be |
| 178 | * filled if set to NULL. |
| 179 | * @is64: Set to true if the ELF is 64bit. Ignored if set to NULL |
| 180 | * @errp: Populated with an error in failure cases |
| 181 | * |
| 182 | * Inspect an ELF file's header. Read its full header contents into a |
| 183 | * buffer and/or determine if the ELF is 64bit. |
| 184 | */ |
| 185 | void load_elf_hdr(const char *filename, void *hdr, bool *is64, Error **errp); |
| 186 | |
Jamie Iles | af97513 | 2021-11-11 14:11:40 +0000 | [diff] [blame] | 187 | ssize_t load_aout(const char *filename, hwaddr addr, int max_sz, |
| 188 | int bswap_needed, hwaddr target_page_size); |
Alistair Francis | 5e774eb | 2016-09-22 18:13:08 +0100 | [diff] [blame] | 189 | |
Nick Hudson | f831f95 | 2019-01-07 08:31:50 +0000 | [diff] [blame] | 190 | #define LOAD_UIMAGE_LOADADDR_INVALID (-1) |
| 191 | |
Alistair Francis | 5e774eb | 2016-09-22 18:13:08 +0100 | [diff] [blame] | 192 | /** load_uimage_as: |
| 193 | * @filename: Path of uimage file |
| 194 | * @ep: Populated with program entry point. Ignored if NULL. |
Nick Hudson | f831f95 | 2019-01-07 08:31:50 +0000 | [diff] [blame] | 195 | * @loadaddr: load address if none specified in the image or when loading a |
| 196 | * ramdisk. Populated with the load address. Ignored if NULL or |
| 197 | * LOAD_UIMAGE_LOADADDR_INVALID (images which do not specify a load |
| 198 | * address will not be loadable). |
Alistair Francis | 5e774eb | 2016-09-22 18:13:08 +0100 | [diff] [blame] | 199 | * @is_linux: Is set to true if the image loaded is Linux. Ignored if NULL. |
| 200 | * @translate_fn: optional function to translate load addresses |
| 201 | * @translate_opaque: opaque data passed to @translate_fn |
| 202 | * @as: The AddressSpace to load the ELF to. The value of address_space_memory |
| 203 | * is used if nothing is supplied here. |
| 204 | * |
| 205 | * Loads a u-boot image into memory. |
| 206 | * |
| 207 | * Returns the size of the loaded image on success, -1 otherwise. |
| 208 | */ |
Jamie Iles | af97513 | 2021-11-11 14:11:40 +0000 | [diff] [blame] | 209 | ssize_t load_uimage_as(const char *filename, hwaddr *ep, |
| 210 | hwaddr *loadaddr, int *is_linux, |
| 211 | uint64_t (*translate_fn)(void *, uint64_t), |
| 212 | void *translate_opaque, AddressSpace *as); |
Alistair Francis | 5e774eb | 2016-09-22 18:13:08 +0100 | [diff] [blame] | 213 | |
| 214 | /** load_uimage: |
| 215 | * Same as load_uimage_as(), but doesn't allow the caller to specify an |
| 216 | * AddressSpace. |
| 217 | */ |
Jamie Iles | af97513 | 2021-11-11 14:11:40 +0000 | [diff] [blame] | 218 | ssize_t load_uimage(const char *filename, hwaddr *ep, |
| 219 | hwaddr *loadaddr, int *is_linux, |
| 220 | uint64_t (*translate_fn)(void *, uint64_t), |
| 221 | void *translate_opaque); |
Blue Swirl | ca20cf3 | 2009-09-20 14:58:02 +0000 | [diff] [blame] | 222 | |
Soren Brinkmann | 84aee0d | 2013-07-08 15:40:01 -0700 | [diff] [blame] | 223 | /** |
Peter Maydell | 97df5fe | 2018-03-02 10:45:35 +0000 | [diff] [blame] | 224 | * load_ramdisk_as: |
Soren Brinkmann | 84aee0d | 2013-07-08 15:40:01 -0700 | [diff] [blame] | 225 | * @filename: Path to the ramdisk image |
| 226 | * @addr: Memory address to load the ramdisk to |
| 227 | * @max_sz: Maximum allowed ramdisk size (for non-u-boot ramdisks) |
Peter Maydell | 97df5fe | 2018-03-02 10:45:35 +0000 | [diff] [blame] | 228 | * @as: The AddressSpace to load the ELF to. The value of address_space_memory |
| 229 | * is used if nothing is supplied here. |
Soren Brinkmann | 84aee0d | 2013-07-08 15:40:01 -0700 | [diff] [blame] | 230 | * |
| 231 | * Load a ramdisk image with U-Boot header to the specified memory |
| 232 | * address. |
| 233 | * |
| 234 | * Returns the size of the loaded image on success, -1 otherwise. |
| 235 | */ |
Jamie Iles | af97513 | 2021-11-11 14:11:40 +0000 | [diff] [blame] | 236 | ssize_t load_ramdisk_as(const char *filename, hwaddr addr, uint64_t max_sz, |
| 237 | AddressSpace *as); |
Peter Maydell | 97df5fe | 2018-03-02 10:45:35 +0000 | [diff] [blame] | 238 | |
| 239 | /** |
| 240 | * load_ramdisk: |
| 241 | * Same as load_ramdisk_as(), but doesn't allow the caller to specify |
| 242 | * an AddressSpace. |
| 243 | */ |
Jamie Iles | af97513 | 2021-11-11 14:11:40 +0000 | [diff] [blame] | 244 | ssize_t load_ramdisk(const char *filename, hwaddr addr, uint64_t max_sz); |
Soren Brinkmann | 84aee0d | 2013-07-08 15:40:01 -0700 | [diff] [blame] | 245 | |
Paul Burton | 51b5856 | 2016-09-08 15:51:56 +0100 | [diff] [blame] | 246 | ssize_t gunzip(void *dst, size_t dstlen, uint8_t *src, size_t srclen); |
| 247 | |
Markus Armbruster | 725e14e | 2011-11-16 19:41:56 +0100 | [diff] [blame] | 248 | ssize_t read_targphys(const char *name, |
Avi Kivity | a8170e5 | 2012-10-23 12:30:10 +0200 | [diff] [blame] | 249 | int fd, hwaddr dst_addr, size_t nbytes); |
Gerd Hoffmann | 3c178e7 | 2009-10-07 13:37:06 +0200 | [diff] [blame] | 250 | void pstrcpy_targphys(const char *name, |
Avi Kivity | a8170e5 | 2012-10-23 12:30:10 +0200 | [diff] [blame] | 251 | hwaddr dest, int buf_size, |
Blue Swirl | ca20cf3 | 2009-09-20 14:58:02 +0000 | [diff] [blame] | 252 | const char *source); |
Gerd Hoffmann | 45a50b1 | 2009-10-01 16:42:33 +0200 | [diff] [blame] | 253 | |
Michael S. Tsirkin | ac41881 | 2014-03-06 14:57:09 +0200 | [diff] [blame] | 254 | extern bool option_rom_has_mr; |
Michael S. Tsirkin | 98bc3ab | 2014-03-09 18:42:06 +0200 | [diff] [blame] | 255 | extern bool rom_file_has_mr; |
Gerd Hoffmann | bdb5ee3 | 2010-01-08 15:25:38 +0100 | [diff] [blame] | 256 | |
Jamie Iles | af97513 | 2021-11-11 14:11:40 +0000 | [diff] [blame] | 257 | ssize_t rom_add_file(const char *file, const char *fw_dir, |
| 258 | hwaddr addr, int32_t bootindex, |
| 259 | bool option_rom, MemoryRegion *mr, AddressSpace *as); |
Paolo Bonzini | 339240b | 2015-03-23 10:24:16 +0100 | [diff] [blame] | 260 | MemoryRegion *rom_add_blob(const char *name, const void *blob, size_t len, |
| 261 | size_t max_len, hwaddr addr, |
| 262 | const char *fw_file_name, |
Marc-André Lureau | 6f6f4ae | 2017-08-07 20:16:11 +0200 | [diff] [blame] | 263 | FWCfgCallback fw_callback, |
Michael S. Tsirkin | baf2d5b | 2017-01-12 19:24:14 +0100 | [diff] [blame] | 264 | void *callback_opaque, AddressSpace *as, |
| 265 | bool read_only); |
Stefano Garzarella | fef2889 | 2019-07-24 16:31:03 +0200 | [diff] [blame] | 266 | int rom_add_elf_program(const char *name, GMappedFile *mapped_file, void *data, |
| 267 | size_t datasize, size_t romsize, hwaddr addr, |
| 268 | AddressSpace *as); |
Eric Auger | 6b3f7f6 | 2015-06-16 17:07:54 +0100 | [diff] [blame] | 269 | int rom_check_and_register_reset(void); |
Laszlo Ersek | a88b362 | 2013-04-16 02:24:08 +0200 | [diff] [blame] | 270 | void rom_set_fw(FWCfgState *f); |
Gerd Hoffmann | bab47d9 | 2016-04-07 09:12:58 -0500 | [diff] [blame] | 271 | void rom_set_order_override(int order); |
| 272 | void rom_reset_order_override(void); |
Stefan Hajnoczi | e233604 | 2018-08-16 14:05:28 +0100 | [diff] [blame] | 273 | |
| 274 | /** |
| 275 | * rom_transaction_begin: |
| 276 | * |
| 277 | * Call this before of a series of rom_add_*() calls. Call |
| 278 | * rom_transaction_end() afterwards to commit or abort. These functions are |
| 279 | * useful for undoing a series of rom_add_*() calls if image file loading fails |
| 280 | * partway through. |
| 281 | */ |
| 282 | void rom_transaction_begin(void); |
| 283 | |
| 284 | /** |
| 285 | * rom_transaction_end: |
| 286 | * @commit: true to commit added roms, false to drop added roms |
| 287 | * |
| 288 | * Call this after a series of rom_add_*() calls. See rom_transaction_begin(). |
| 289 | */ |
| 290 | void rom_transaction_end(bool commit); |
| 291 | |
Avi Kivity | a8170e5 | 2012-10-23 12:30:10 +0200 | [diff] [blame] | 292 | int rom_copy(uint8_t *dest, hwaddr addr, size_t size); |
Thomas Huth | 0f0f8b6 | 2018-06-26 11:35:40 +0200 | [diff] [blame] | 293 | void *rom_ptr(hwaddr addr, size_t size); |
Peter Maydell | 1228c45 | 2021-03-18 17:48:22 +0000 | [diff] [blame] | 294 | /** |
| 295 | * rom_ptr_for_as: Return a pointer to ROM blob data for the address |
| 296 | * @as: AddressSpace to look for the ROM blob in |
| 297 | * @addr: Address within @as |
| 298 | * @size: size of data required in bytes |
| 299 | * |
| 300 | * Returns: pointer into the data which backs the matching ROM blob, |
| 301 | * or NULL if no blob covers the address range. |
| 302 | * |
| 303 | * This function looks for a ROM blob which covers the specified range |
| 304 | * of bytes of length @size starting at @addr within the address space |
| 305 | * @as. This is useful for code which runs as part of board |
| 306 | * initialization or CPU reset which wants to read data that is part |
| 307 | * of a user-supplied guest image or other guest memory contents, but |
| 308 | * which runs before the ROM loader's reset function has copied the |
| 309 | * blobs into guest memory. |
| 310 | * |
| 311 | * rom_ptr_for_as() will look not just for blobs loaded directly to |
| 312 | * the specified address, but also for blobs which were loaded to an |
| 313 | * alias of the region at a different location in the AddressSpace. |
| 314 | * In other words, if a machine model has RAM at address 0x0000_0000 |
| 315 | * which is aliased to also appear at 0x1000_0000, rom_ptr_for_as() |
| 316 | * will return the correct data whether the guest image was linked and |
| 317 | * loaded at 0x0000_0000 or 0x1000_0000. Contrast rom_ptr(), which |
| 318 | * will only return data if the image load address is an exact match |
| 319 | * with the queried address. |
| 320 | * |
| 321 | * New code should prefer to use rom_ptr_for_as() instead of |
| 322 | * rom_ptr(). |
| 323 | */ |
| 324 | void *rom_ptr_for_as(AddressSpace *as, hwaddr addr, size_t size); |
Markus Armbruster | 1ce6be2 | 2015-02-06 14:18:24 +0100 | [diff] [blame] | 325 | void hmp_info_roms(Monitor *mon, const QDict *qdict); |
Gerd Hoffmann | 45a50b1 | 2009-10-01 16:42:33 +0200 | [diff] [blame] | 326 | |
Gleb Natapov | 2e55e84 | 2010-12-08 13:35:07 +0200 | [diff] [blame] | 327 | #define rom_add_file_fixed(_f, _a, _i) \ |
Alistair Francis | 3e76099 | 2016-09-22 18:13:08 +0100 | [diff] [blame] | 328 | rom_add_file(_f, NULL, _a, _i, false, NULL, NULL) |
Gerd Hoffmann | 45a50b1 | 2009-10-01 16:42:33 +0200 | [diff] [blame] | 329 | #define rom_add_blob_fixed(_f, _b, _l, _a) \ |
Michael S. Tsirkin | baf2d5b | 2017-01-12 19:24:14 +0100 | [diff] [blame] | 330 | rom_add_blob(_f, _b, _l, _l, _a, NULL, NULL, NULL, NULL, true) |
Peter Maydell | 76151ca | 2016-03-04 11:30:17 +0000 | [diff] [blame] | 331 | #define rom_add_file_mr(_f, _mr, _i) \ |
Alistair Francis | 3e76099 | 2016-09-22 18:13:08 +0100 | [diff] [blame] | 332 | rom_add_file(_f, NULL, 0, _i, false, _mr, NULL) |
| 333 | #define rom_add_file_as(_f, _as, _i) \ |
| 334 | rom_add_file(_f, NULL, 0, _i, false, NULL, _as) |
Alistair Francis | 93ffc7c | 2016-09-22 18:13:08 +0100 | [diff] [blame] | 335 | #define rom_add_file_fixed_as(_f, _a, _i, _as) \ |
| 336 | rom_add_file(_f, NULL, _a, _i, false, NULL, _as) |
Alistair Francis | 5e774eb | 2016-09-22 18:13:08 +0100 | [diff] [blame] | 337 | #define rom_add_blob_fixed_as(_f, _b, _l, _a, _as) \ |
Michael S. Tsirkin | baf2d5b | 2017-01-12 19:24:14 +0100 | [diff] [blame] | 338 | rom_add_blob(_f, _b, _l, _l, _a, NULL, NULL, NULL, _as, true) |
Gerd Hoffmann | 45a50b1 | 2009-10-01 16:42:33 +0200 | [diff] [blame] | 339 | |
Jamie Iles | af97513 | 2021-11-11 14:11:40 +0000 | [diff] [blame] | 340 | ssize_t rom_add_vga(const char *file); |
| 341 | ssize_t rom_add_option(const char *file, int32_t bootindex); |
Gerd Hoffmann | 45a50b1 | 2009-10-01 16:42:33 +0200 | [diff] [blame] | 342 | |
Paul Burton | 51b5856 | 2016-09-08 15:51:56 +0100 | [diff] [blame] | 343 | /* This is the usual maximum in uboot, so if a uImage overflows this, it would |
| 344 | * overflow on real hardware too. */ |
| 345 | #define UBOOT_MAX_GUNZIP_BYTES (64 << 20) |
| 346 | |
Alex Bennée | 5fc983a | 2022-02-25 17:20:20 +0000 | [diff] [blame] | 347 | typedef struct RomGap { |
| 348 | hwaddr base; |
| 349 | size_t size; |
| 350 | } RomGap; |
| 351 | |
| 352 | /** |
| 353 | * rom_find_largest_gap_between: return largest gap between ROMs in given range |
| 354 | * |
| 355 | * Given a range of addresses, this function finds the largest |
| 356 | * contiguous subrange which has no ROMs loaded to it. That is, |
| 357 | * it finds the biggest gap which is free for use for other things. |
| 358 | */ |
| 359 | RomGap rom_find_largest_gap_between(hwaddr base, size_t size); |
| 360 | |
Blue Swirl | ca20cf3 | 2009-09-20 14:58:02 +0000 | [diff] [blame] | 361 | #endif |