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
25 printf ("0x%02hhx, ", *(c
++));
29 /* Format for the XEN_ELFNOTE_PHYS32_ENTRY program segment */
30 #define XEN_ELFNOTE_PHYS32_ENTRY 18
37 } xen_elfnote_phys32_entry
;
45 size_t ovmf_blob_size
= 0x00200000;
46 /* Load OVMF at 1MB when running as PVH guest */
47 uint32_t ovmf_base_address
= 0x00100000;
48 /* Xen PVH entry point */
49 uint32_t ovmfxen_pvh_entry_point
= ovmf_base_address
+ ovmf_blob_size
- 0x30;
50 size_t offset_into_file
= 0;
57 .e_version
= EV_CURRENT
,
58 .e_entry
= ovmfxen_pvh_entry_point
,
59 .e_flags
= R_386_NONE
,
60 .e_ehsize
= sizeof (hdr
),
61 .e_phentsize
= sizeof (Elf32_Phdr
),
64 offset_into_file
+= sizeof (hdr
);
66 hdr
.e_ident
[EI_CLASS
] = ELFCLASS32
;
67 hdr
.e_ident
[EI_DATA
] = ELFDATA2LSB
;
68 hdr
.e_ident
[EI_VERSION
] = EV_CURRENT
;
69 hdr
.e_ident
[EI_OSABI
] = ELFOSABI_LINUX
;
70 /* Placing program headers just after hdr */
71 hdr
.e_phoff
= sizeof (hdr
);
74 Elf32_Phdr phdr_load
= {
76 .p_offset
= 0, /* load everything */
77 .p_paddr
= ovmf_base_address
,
78 .p_filesz
= ovmf_blob_size
,
79 .p_memsz
= ovmf_blob_size
,
80 .p_flags
= PF_X
| PF_W
| PF_R
,
84 phdr_load
.p_vaddr
= phdr_load
.p_paddr
;
86 offset_into_file
+= sizeof (phdr_load
);
90 xen_elfnote_phys32_entry xen_elf_note
= {
91 .type
= XEN_ELFNOTE_PHYS32_ENTRY
,
93 .desc
= ovmfxen_pvh_entry_point
,
95 offsetof (xen_elfnote_phys32_entry
, desc
) -
96 offsetof (xen_elfnote_phys32_entry
, name
),
98 sizeof (xen_elfnote_phys32_entry
) -
99 offsetof (xen_elfnote_phys32_entry
, desc
),
101 Elf32_Phdr phdr_note
= {
103 .p_filesz
= sizeof (xen_elf_note
),
104 .p_memsz
= sizeof (xen_elf_note
),
110 offset_into_file
+= sizeof (phdr_note
);
111 phdr_note
.p_offset
= offset_into_file
;
112 phdr_note
.p_paddr
= ovmf_base_address
+ phdr_note
.p_offset
;
113 phdr_note
.p_vaddr
= phdr_note
.p_paddr
;
120 size_t hdr_size
= sizeof (hdr
);
121 size_t entry_off
= offsetof (typeof(hdr
), e_entry
);
123 printf ("# ELF file header\n");
124 print_hdr (&hdr
, entry_off
);
126 print_hdr (&hdr
.e_entry
, sizeof (hdr
.e_entry
));
127 printf (" # hdr.e_entry\n");
128 print_hdr (&hdr
.e_entry
+ 1, hdr_size
- entry_off
- sizeof (hdr
.e_entry
));
130 printf ("\n\n# ELF Program segment headers\n");
131 printf ("# - Load segment\n");
132 for (i
= 0; i
< sizeof (phdr_load
); i
+= 4) {
133 print_hdr (((char *)&phdr_load
) + i
, 4);
137 printf ("# - ELFNOTE segment\n");
138 for (i
= 0; i
< sizeof (phdr_note
); i
+= 4) {
139 print_hdr (((char *)&phdr_note
) + i
, 4);
143 printf ("\n# XEN_ELFNOTE_PHYS32_ENTRY\n");
144 for (i
= 0; i
< sizeof (xen_elf_note
); i
+= 4) {
145 print_hdr (((char *)&xen_elf_note
) + i
, 4);