]> git.proxmox.com Git - mirror_qemu.git/blame - include/hw/loader.h
Sort the fw_cfg file list
[mirror_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);
a8170e5e 17int load_image_targphys(const char *filename, hwaddr,
80a2ba3d 18 uint64_t max_sz);
76151cac
PM
19/**
20 * load_image_mr: load an image into a memory region
21 * @filename: Path to the image file
22 * @mr: Memory Region to load into
23 *
24 * Load the specified file into the memory region.
25 * The file loaded is registered as a ROM, so its contents will be
26 * reinstated whenever the system is reset.
27 * If the file is larger than the memory region's size the call will fail.
28 * Returns -1 on failure, or the size of the file.
29 */
30int load_image_mr(const char *filename, MemoryRegion *mr);
7d48a0f7
LE
31
32/* This is the limit on the maximum uncompressed image size that
33 * load_image_gzipped_buffer() and load_image_gzipped() will read. It prevents
34 * g_malloc() in those functions from allocating a huge amount of memory.
35 */
36#define LOAD_IMAGE_MAX_GUNZIP_BYTES (256 << 20)
37
38int load_image_gzipped_buffer(const char *filename, uint64_t max_sz,
39 uint8_t **buffer);
235e74af 40int load_image_gzipped(const char *filename, hwaddr addr, uint64_t max_sz);
18674b26
AK
41
42#define ELF_LOAD_FAILED -1
43#define ELF_LOAD_NOT_ELF -2
44#define ELF_LOAD_WRONG_ARCH -3
45#define ELF_LOAD_WRONG_ENDIAN -4
46const char *load_elf_strerror(int error);
140b7ce5
PC
47
48/** load_elf:
49 * @filename: Path of ELF file
50 * @translate_fn: optional function to translate load addresses
51 * @translate_opaque: opaque data passed to @translate_fn
52 * @pentry: Populated with program entry point. Ignored if NULL.
53 * @lowaddr: Populated with lowest loaded address. Ignored if NULL.
54 * @highaddr: Populated with highest loaded address. Ignored if NULL.
55 * @bigendian: Expected ELF endianness. 0 for LE otherwise BE
56 * @elf_machine: Expected ELF machine type
57 * @clear_lsb: Set to mask off LSB of addresses (Some architectures use
58 * this for non-address data)
7ef295ea
PC
59 * @data_swab: Set to order of byte swapping for data. 0 for no swap, 1
60 * for swapping bytes within halfwords, 2 for bytes within
61 * words and 3 for within doublewords.
140b7ce5
PC
62 *
63 * Load an ELF file's contents to the emulated system's address space.
64 * Clients may optionally specify a callback to perform address
65 * translations. @pentry, @lowaddr and @highaddr are optional pointers
66 * which will be populated with various load information. @bigendian and
67 * @elf_machine give the expected endianness and machine for the ELF the
68 * load will fail if the target ELF does not match. Some architectures
69 * have some architecture-specific behaviours that come into effect when
70 * their particular values for @elf_machine are set.
71 */
72
409dbce5
AJ
73int load_elf(const char *filename, uint64_t (*translate_fn)(void *, uint64_t),
74 void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr,
75 uint64_t *highaddr, int big_endian, int elf_machine,
7ef295ea 76 int clear_lsb, int data_swab);
04ae712a
PC
77
78/** load_elf_hdr:
79 * @filename: Path of ELF file
80 * @hdr: Buffer to populate with header data. Header data will not be
81 * filled if set to NULL.
82 * @is64: Set to true if the ELF is 64bit. Ignored if set to NULL
83 * @errp: Populated with an error in failure cases
84 *
85 * Inspect an ELF file's header. Read its full header contents into a
86 * buffer and/or determine if the ELF is 64bit.
87 */
88void load_elf_hdr(const char *filename, void *hdr, bool *is64, Error **errp);
89
a8170e5e
AK
90int load_aout(const char *filename, hwaddr addr, int max_sz,
91 int bswap_needed, hwaddr target_page_size);
92int load_uimage(const char *filename, hwaddr *ep,
25bda50a
MF
93 hwaddr *loadaddr, int *is_linux,
94 uint64_t (*translate_fn)(void *, uint64_t),
95 void *translate_opaque);
ca20cf32 96
84aee0de
SB
97/**
98 * load_ramdisk:
99 * @filename: Path to the ramdisk image
100 * @addr: Memory address to load the ramdisk to
101 * @max_sz: Maximum allowed ramdisk size (for non-u-boot ramdisks)
102 *
103 * Load a ramdisk image with U-Boot header to the specified memory
104 * address.
105 *
106 * Returns the size of the loaded image on success, -1 otherwise.
107 */
108int load_ramdisk(const char *filename, hwaddr addr, uint64_t max_sz);
109
725e14e9 110ssize_t read_targphys(const char *name,
a8170e5e 111 int fd, hwaddr dst_addr, size_t nbytes);
3c178e72 112void pstrcpy_targphys(const char *name,
a8170e5e 113 hwaddr dest, int buf_size,
ca20cf32 114 const char *source);
45a50b16 115
ac41881b 116extern bool option_rom_has_mr;
98bc3ab0 117extern bool rom_file_has_mr;
bdb5ee30
GH
118
119int rom_add_file(const char *file, const char *fw_dir,
ac41881b 120 hwaddr addr, int32_t bootindex,
76151cac 121 bool option_rom, MemoryRegion *mr);
339240b5
PB
122MemoryRegion *rom_add_blob(const char *name, const void *blob, size_t len,
123 size_t max_len, hwaddr addr,
124 const char *fw_file_name,
125 FWCfgReadCallback fw_callback,
126 void *callback_opaque);
d60fa42e
FC
127int rom_add_elf_program(const char *name, void *data, size_t datasize,
128 size_t romsize, hwaddr addr);
6b3f7f63 129int rom_check_and_register_reset(void);
a88b362c 130void rom_set_fw(FWCfgState *f);
bab47d9a
GH
131void rom_set_order_override(int order);
132void rom_reset_order_override(void);
a8170e5e
AK
133int rom_copy(uint8_t *dest, hwaddr addr, size_t size);
134void *rom_ptr(hwaddr addr);
1ce6be24 135void hmp_info_roms(Monitor *mon, const QDict *qdict);
45a50b16 136
2e55e842 137#define rom_add_file_fixed(_f, _a, _i) \
76151cac 138 rom_add_file(_f, NULL, _a, _i, false, NULL)
45a50b16 139#define rom_add_blob_fixed(_f, _b, _l, _a) \
a1666142 140 rom_add_blob(_f, _b, _l, _l, _a, NULL, NULL, NULL)
76151cac 141#define rom_add_file_mr(_f, _mr, _i) \
f09f9bd9 142 rom_add_file(_f, NULL, 0, _i, false, _mr)
45a50b16
GH
143
144#define PC_ROM_MIN_VGA 0xc0000
145#define PC_ROM_MIN_OPTION 0xc8000
146#define PC_ROM_MAX 0xe0000
147#define PC_ROM_ALIGN 0x800
148#define PC_ROM_SIZE (PC_ROM_MAX - PC_ROM_MIN_VGA)
149
de2aff17 150int rom_add_vga(const char *file);
2e55e842 151int rom_add_option(const char *file, int32_t bootindex);
45a50b16 152
ca20cf32 153#endif