]> Git Repo - qemu.git/blame - include/hw/loader.h
ppc/xics: simplify prototype of xics_spapr_init()
[qemu.git] / include / hw / loader.h
CommitLineData
ca20cf32
BS
1#ifndef LOADER_H
2#define LOADER_H
84f2d0ea 3#include "qapi/qmp/qdict.h"
a88b362c 4#include "hw/nvram/fw_cfg.h"
ca20cf32
BS
5
6/* loader.c */
a1483f88
MT
7/**
8 * get_image_size: retrieve size of an image file
9 * @filename: Path to the image file
10 *
11 * Returns the size of the image file on success, -1 otherwise.
12 * On error, errno is also set as appropriate.
13 */
ca20cf32
BS
14int get_image_size(const char *filename);
15int load_image(const char *filename, uint8_t *addr); /* deprecated */
ea87616d 16ssize_t load_image_size(const char *filename, void *addr, size_t size);
93ffc7c7
AF
17
18/**load_image_targphys_as:
19 * @filename: Path to the image file
20 * @addr: Address to load the image to
21 * @max_sz: The maximum size of the image to load
22 * @as: The AddressSpace to load the ELF to. The value of address_space_memory
23 * is used if nothing is supplied here.
24 *
25 * Load a fixed image into memory.
26 *
27 * Returns the size of the loaded image on success, -1 otherwise.
28 */
29int load_image_targphys_as(const char *filename,
30 hwaddr addr, uint64_t max_sz, AddressSpace *as);
31
32/** load_image_targphys:
33 * Same as load_image_targphys_as(), but doesn't allow the caller to specify
34 * an AddressSpace.
35 */
a8170e5e 36int load_image_targphys(const char *filename, hwaddr,
80a2ba3d 37 uint64_t max_sz);
93ffc7c7 38
76151cac
PM
39/**
40 * load_image_mr: load an image into a memory region
41 * @filename: Path to the image file
42 * @mr: Memory Region to load into
43 *
44 * Load the specified file into the memory region.
45 * The file loaded is registered as a ROM, so its contents will be
46 * reinstated whenever the system is reset.
47 * If the file is larger than the memory region's size the call will fail.
48 * Returns -1 on failure, or the size of the file.
49 */
50int load_image_mr(const char *filename, MemoryRegion *mr);
7d48a0f7
LE
51
52/* This is the limit on the maximum uncompressed image size that
53 * load_image_gzipped_buffer() and load_image_gzipped() will read. It prevents
54 * g_malloc() in those functions from allocating a huge amount of memory.
55 */
56#define LOAD_IMAGE_MAX_GUNZIP_BYTES (256 << 20)
57
58int load_image_gzipped_buffer(const char *filename, uint64_t max_sz,
59 uint8_t **buffer);
235e74af 60int load_image_gzipped(const char *filename, hwaddr addr, uint64_t max_sz);
18674b26
AK
61
62#define ELF_LOAD_FAILED -1
63#define ELF_LOAD_NOT_ELF -2
64#define ELF_LOAD_WRONG_ARCH -3
65#define ELF_LOAD_WRONG_ENDIAN -4
66const char *load_elf_strerror(int error);
140b7ce5 67
34f1b23f 68/** load_elf_ram:
140b7ce5
PC
69 * @filename: Path of ELF file
70 * @translate_fn: optional function to translate load addresses
71 * @translate_opaque: opaque data passed to @translate_fn
72 * @pentry: Populated with program entry point. Ignored if NULL.
73 * @lowaddr: Populated with lowest loaded address. Ignored if NULL.
74 * @highaddr: Populated with highest loaded address. Ignored if NULL.
75 * @bigendian: Expected ELF endianness. 0 for LE otherwise BE
76 * @elf_machine: Expected ELF machine type
77 * @clear_lsb: Set to mask off LSB of addresses (Some architectures use
78 * this for non-address data)
7ef295ea
PC
79 * @data_swab: Set to order of byte swapping for data. 0 for no swap, 1
80 * for swapping bytes within halfwords, 2 for bytes within
81 * words and 3 for within doublewords.
70bb1d16
AF
82 * @as: The AddressSpace to load the ELF to. The value of address_space_memory
83 * is used if nothing is supplied here.
34f1b23f 84 * @load_rom : Load ELF binary as ROM
140b7ce5
PC
85 *
86 * Load an ELF file's contents to the emulated system's address space.
87 * Clients may optionally specify a callback to perform address
88 * translations. @pentry, @lowaddr and @highaddr are optional pointers
89 * which will be populated with various load information. @bigendian and
90 * @elf_machine give the expected endianness and machine for the ELF the
91 * load will fail if the target ELF does not match. Some architectures
92 * have some architecture-specific behaviours that come into effect when
93 * their particular values for @elf_machine are set.
8cf6e9da
AF
94 * If @elf_machine is EM_NONE then the machine type will be read from the
95 * ELF header and no checks will be carried out against the machine type.
140b7ce5 96 */
34f1b23f
FA
97int load_elf_ram(const char *filename,
98 uint64_t (*translate_fn)(void *, uint64_t),
99 void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr,
100 uint64_t *highaddr, int big_endian, int elf_machine,
101 int clear_lsb, int data_swab, AddressSpace *as,
102 bool load_rom);
103
104/** load_elf_as:
105 * Same as load_elf_ram(), but always loads the elf as ROM
106 */
70bb1d16
AF
107int load_elf_as(const char *filename,
108 uint64_t (*translate_fn)(void *, uint64_t),
109 void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr,
110 uint64_t *highaddr, int big_endian, int elf_machine,
111 int clear_lsb, int data_swab, AddressSpace *as);
140b7ce5 112
70bb1d16
AF
113/** load_elf:
114 * Same as load_elf_as(), but doesn't allow the caller to specify an
115 * AddressSpace.
116 */
409dbce5
AJ
117int load_elf(const char *filename, uint64_t (*translate_fn)(void *, uint64_t),
118 void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr,
119 uint64_t *highaddr, int big_endian, int elf_machine,
7ef295ea 120 int clear_lsb, int data_swab);
04ae712a
PC
121
122/** load_elf_hdr:
123 * @filename: Path of ELF file
124 * @hdr: Buffer to populate with header data. Header data will not be
125 * filled if set to NULL.
126 * @is64: Set to true if the ELF is 64bit. Ignored if set to NULL
127 * @errp: Populated with an error in failure cases
128 *
129 * Inspect an ELF file's header. Read its full header contents into a
130 * buffer and/or determine if the ELF is 64bit.
131 */
132void load_elf_hdr(const char *filename, void *hdr, bool *is64, Error **errp);
133
a8170e5e
AK
134int load_aout(const char *filename, hwaddr addr, int max_sz,
135 int bswap_needed, hwaddr target_page_size);
5e774eb3
AF
136
137/** load_uimage_as:
138 * @filename: Path of uimage file
139 * @ep: Populated with program entry point. Ignored if NULL.
140 * @loadaddr: Populated with the load address. Ignored if NULL.
141 * @is_linux: Is set to true if the image loaded is Linux. Ignored if NULL.
142 * @translate_fn: optional function to translate load addresses
143 * @translate_opaque: opaque data passed to @translate_fn
144 * @as: The AddressSpace to load the ELF to. The value of address_space_memory
145 * is used if nothing is supplied here.
146 *
147 * Loads a u-boot image into memory.
148 *
149 * Returns the size of the loaded image on success, -1 otherwise.
150 */
151int load_uimage_as(const char *filename, hwaddr *ep,
152 hwaddr *loadaddr, int *is_linux,
153 uint64_t (*translate_fn)(void *, uint64_t),
154 void *translate_opaque, AddressSpace *as);
155
156/** load_uimage:
157 * Same as load_uimage_as(), but doesn't allow the caller to specify an
158 * AddressSpace.
159 */
a8170e5e 160int load_uimage(const char *filename, hwaddr *ep,
25bda50a
MF
161 hwaddr *loadaddr, int *is_linux,
162 uint64_t (*translate_fn)(void *, uint64_t),
163 void *translate_opaque);
ca20cf32 164
84aee0de
SB
165/**
166 * load_ramdisk:
167 * @filename: Path to the ramdisk image
168 * @addr: Memory address to load the ramdisk to
169 * @max_sz: Maximum allowed ramdisk size (for non-u-boot ramdisks)
170 *
171 * Load a ramdisk image with U-Boot header to the specified memory
172 * address.
173 *
174 * Returns the size of the loaded image on success, -1 otherwise.
175 */
176int load_ramdisk(const char *filename, hwaddr addr, uint64_t max_sz);
177
51b58561
PB
178ssize_t gunzip(void *dst, size_t dstlen, uint8_t *src, size_t srclen);
179
725e14e9 180ssize_t read_targphys(const char *name,
a8170e5e 181 int fd, hwaddr dst_addr, size_t nbytes);
3c178e72 182void pstrcpy_targphys(const char *name,
a8170e5e 183 hwaddr dest, int buf_size,
ca20cf32 184 const char *source);
45a50b16 185
ac41881b 186extern bool option_rom_has_mr;
98bc3ab0 187extern bool rom_file_has_mr;
bdb5ee30
GH
188
189int rom_add_file(const char *file, const char *fw_dir,
ac41881b 190 hwaddr addr, int32_t bootindex,
3e76099a 191 bool option_rom, MemoryRegion *mr, AddressSpace *as);
339240b5
PB
192MemoryRegion *rom_add_blob(const char *name, const void *blob, size_t len,
193 size_t max_len, hwaddr addr,
194 const char *fw_file_name,
195 FWCfgReadCallback fw_callback,
baf2d5bf
MT
196 void *callback_opaque, AddressSpace *as,
197 bool read_only);
d60fa42e 198int rom_add_elf_program(const char *name, void *data, size_t datasize,
3e76099a 199 size_t romsize, hwaddr addr, AddressSpace *as);
6b3f7f63 200int rom_check_and_register_reset(void);
a88b362c 201void rom_set_fw(FWCfgState *f);
bab47d9a
GH
202void rom_set_order_override(int order);
203void rom_reset_order_override(void);
a8170e5e
AK
204int rom_copy(uint8_t *dest, hwaddr addr, size_t size);
205void *rom_ptr(hwaddr addr);
1ce6be24 206void hmp_info_roms(Monitor *mon, const QDict *qdict);
45a50b16 207
2e55e842 208#define rom_add_file_fixed(_f, _a, _i) \
3e76099a 209 rom_add_file(_f, NULL, _a, _i, false, NULL, NULL)
45a50b16 210#define rom_add_blob_fixed(_f, _b, _l, _a) \
baf2d5bf 211 rom_add_blob(_f, _b, _l, _l, _a, NULL, NULL, NULL, NULL, true)
76151cac 212#define rom_add_file_mr(_f, _mr, _i) \
3e76099a
AF
213 rom_add_file(_f, NULL, 0, _i, false, _mr, NULL)
214#define rom_add_file_as(_f, _as, _i) \
215 rom_add_file(_f, NULL, 0, _i, false, NULL, _as)
93ffc7c7
AF
216#define rom_add_file_fixed_as(_f, _a, _i, _as) \
217 rom_add_file(_f, NULL, _a, _i, false, NULL, _as)
5e774eb3 218#define rom_add_blob_fixed_as(_f, _b, _l, _a, _as) \
baf2d5bf 219 rom_add_blob(_f, _b, _l, _l, _a, NULL, NULL, NULL, _as, true)
45a50b16
GH
220
221#define PC_ROM_MIN_VGA 0xc0000
222#define PC_ROM_MIN_OPTION 0xc8000
223#define PC_ROM_MAX 0xe0000
224#define PC_ROM_ALIGN 0x800
225#define PC_ROM_SIZE (PC_ROM_MAX - PC_ROM_MIN_VGA)
226
de2aff17 227int rom_add_vga(const char *file);
2e55e842 228int rom_add_option(const char *file, int32_t bootindex);
45a50b16 229
51b58561
PB
230/* This is the usual maximum in uboot, so if a uImage overflows this, it would
231 * overflow on real hardware too. */
232#define UBOOT_MAX_GUNZIP_BYTES (64 << 20)
233
ca20cf32 234#endif
This page took 0.595333 seconds and 4 git commands to generate.