2 This program generates a hex array to be manually coppied into
5 The purpose is for the flash device image to be recognize as an ELF.
7 Copyright (c) 2019, Citrix Systems, Inc.
9 SPDX-License-Identifier: BSD-2-Clause-Patent
31 fprintf (file
, "0x%02hhx, ", *(c
++));
35 fprintf (file
, "0x%02hhx,", *c
);
37 fprintf (file
, "0x%02hhx", *c
);
41 /* Format for the XEN_ELFNOTE_PHYS32_ENTRY program segment */
42 #define XEN_ELFNOTE_PHYS32_ENTRY 18
49 } xen_elfnote_phys32_entry
;
51 #define LICENSE_HDR "\
53 # FDF include file that defines a PVH ELF header.\r\n\
55 # Copyright (c) 2022, Intel Corporation. All rights reserved.\r\n\
57 # SPDX-License-Identifier: BSD-2-Clause-Patent\r\n\
70 size_t ovmf_blob_size
= 0x00200000;
71 /* Load OVMF at 1MB when running as PVH guest */
72 uint32_t ovmf_base_address
= 0x00100000;
73 uint32_t ovmfxen_pvh_entry_point
;
74 size_t offset_into_file
= 0;
79 /* Parse the size parameter */
82 param
= strtol (str
, &endptr
, 10);
84 ovmf_blob_size
= (size_t)param
;
88 /* Parse the filepath parameter */
90 file
= fopen (argv
[2], "w");
91 fprintf (file
, LICENSE_HDR
);
94 /* Xen PVH entry point */
95 ovmfxen_pvh_entry_point
= ovmf_base_address
+ ovmf_blob_size
- 0x30;
106 .e_version
= EV_CURRENT
,
107 .e_entry
= ovmfxen_pvh_entry_point
,
108 .e_flags
= R_386_NONE
,
109 .e_ehsize
= sizeof (hdr
),
111 .e_phentsize
= sizeof (Elf64_Phdr
),
113 .e_phentsize
= sizeof (Elf32_Phdr
),
117 offset_into_file
+= sizeof (hdr
);
120 hdr
.e_ident
[EI_CLASS
] = ELFCLASS64
;
122 hdr
.e_ident
[EI_CLASS
] = ELFCLASS32
;
124 hdr
.e_ident
[EI_DATA
] = ELFDATA2LSB
;
125 hdr
.e_ident
[EI_VERSION
] = EV_CURRENT
;
126 hdr
.e_ident
[EI_OSABI
] = ELFOSABI_LINUX
;
127 /* Placing program headers just after hdr */
128 hdr
.e_phoff
= sizeof (hdr
);
132 Elf64_Phdr phdr_load
= {
134 Elf32_Phdr phdr_load
= {
137 .p_offset
= 0, /* load everything */
138 .p_paddr
= ovmf_base_address
,
139 .p_filesz
= ovmf_blob_size
,
140 .p_memsz
= ovmf_blob_size
,
141 .p_flags
= PF_X
| PF_W
| PF_R
,
149 phdr_load
.p_vaddr
= phdr_load
.p_paddr
;
151 offset_into_file
+= sizeof (phdr_load
);
155 xen_elfnote_phys32_entry xen_elf_note
= {
156 .type
= XEN_ELFNOTE_PHYS32_ENTRY
,
158 .desc
= ovmfxen_pvh_entry_point
,
160 offsetof (xen_elfnote_phys32_entry
, desc
) -
161 offsetof (xen_elfnote_phys32_entry
, name
),
163 sizeof (xen_elfnote_phys32_entry
) -
164 offsetof (xen_elfnote_phys32_entry
, desc
),
167 Elf64_Phdr phdr_note
= {
169 Elf32_Phdr phdr_note
= {
172 .p_filesz
= sizeof (xen_elf_note
),
173 .p_memsz
= sizeof (xen_elf_note
),
183 offset_into_file
+= sizeof (phdr_note
);
184 phdr_note
.p_offset
= offset_into_file
;
185 phdr_note
.p_paddr
= ovmf_base_address
+ phdr_note
.p_offset
;
186 phdr_note
.p_vaddr
= phdr_note
.p_paddr
;
193 size_t hdr_size
= sizeof (hdr
);
194 size_t entry_off
= offsetof (typeof(hdr
), e_entry
);
196 fprintf (file
, "DATA = {\r\n");
198 fprintf (file
, " # ELF file header\r\n");
199 print_hdr (file
, &hdr
, entry_off
, true);
200 fprintf (file
, "\r\n");
201 print_hdr (file
, &hdr
.e_entry
, sizeof (hdr
.e_entry
), true);
202 fprintf (file
, " # hdr.e_entry\r\n");
203 print_hdr (file
, &hdr
.e_entry
+ 1, hdr_size
- entry_off
- sizeof (hdr
.e_entry
), true);
205 fprintf (file
, "\r\n\r\n # ELF Program segment headers\r\n");
206 fprintf (file
, " # - Load segment\r\n");
207 for (i
= 0; i
< sizeof (phdr_load
); i
+= 4) {
208 print_hdr (file
, ((char *)&phdr_load
) + i
, 4, true);
209 fprintf (file
, "\r\n");
212 fprintf (file
, " # - ELFNOTE segment\r\n");
213 for (i
= 0; i
< sizeof (phdr_note
); i
+= 4) {
214 print_hdr (file
, ((char *)&phdr_note
) + i
, 4, true);
215 fprintf (file
, "\r\n");
218 fprintf (file
, "\r\n # XEN_ELFNOTE_PHYS32_ENTRY\r\n");
219 for (i
= 0; i
< sizeof (xen_elf_note
); i
+= 4) {
220 print_hdr (file
, ((char *)&xen_elf_note
) + i
, 4, (sizeof (xen_elf_note
) - i
) > 4);
221 fprintf (file
, "\r\n");
224 fprintf (file
, "}\r\n");