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
16 void print_hdr(void *s
, size_t size
)
21 printf("0x%02hhx, ", *(c
++));
25 /* Format for the XEN_ELFNOTE_PHYS32_ENTRY program segment */
26 #define XEN_ELFNOTE_PHYS32_ENTRY 18
33 } xen_elfnote_phys32_entry
;
38 size_t ovmf_blob_size
= 0x00200000;
39 /* Load OVMF at 1MB when running as PVH guest */
40 uint32_t ovmf_base_address
= 0x00100000;
41 /* Xen PVH entry point */
42 uint32_t ovmfxen_pvh_entry_point
= ovmf_base_address
+ ovmf_blob_size
- 0x30;
43 size_t offset_into_file
= 0;
50 .e_version
= EV_CURRENT
,
51 .e_entry
= ovmfxen_pvh_entry_point
,
52 .e_flags
= R_386_NONE
,
53 .e_ehsize
= sizeof (hdr
),
54 .e_phentsize
= sizeof (Elf32_Phdr
),
56 offset_into_file
+= sizeof (hdr
);
58 hdr
.e_ident
[EI_CLASS
] = ELFCLASS32
;
59 hdr
.e_ident
[EI_DATA
] = ELFDATA2LSB
;
60 hdr
.e_ident
[EI_VERSION
] = EV_CURRENT
;
61 hdr
.e_ident
[EI_OSABI
] = ELFOSABI_LINUX
;
62 /* Placing program headers just after hdr */
63 hdr
.e_phoff
= sizeof (hdr
);
66 Elf32_Phdr phdr_load
= {
68 .p_offset
= 0, /* load everything */
69 .p_paddr
= ovmf_base_address
,
70 .p_filesz
= ovmf_blob_size
,
71 .p_memsz
= ovmf_blob_size
,
72 .p_flags
= PF_X
| PF_W
| PF_R
,
75 phdr_load
.p_vaddr
= phdr_load
.p_paddr
;
77 offset_into_file
+= sizeof (phdr_load
);
81 xen_elfnote_phys32_entry xen_elf_note
= {
82 .type
= XEN_ELFNOTE_PHYS32_ENTRY
,
84 .desc
= ovmfxen_pvh_entry_point
,
86 offsetof (xen_elfnote_phys32_entry
, desc
) -
87 offsetof (xen_elfnote_phys32_entry
, name
),
89 sizeof (xen_elfnote_phys32_entry
) -
90 offsetof (xen_elfnote_phys32_entry
, desc
),
92 Elf32_Phdr phdr_note
= {
94 .p_filesz
= sizeof (xen_elf_note
),
95 .p_memsz
= sizeof (xen_elf_note
),
100 offset_into_file
+= sizeof (phdr_note
);
101 phdr_note
.p_offset
= offset_into_file
;
102 phdr_note
.p_paddr
= ovmf_base_address
+ phdr_note
.p_offset
;
103 phdr_note
.p_vaddr
= phdr_note
.p_paddr
;
111 size_t hdr_size
= sizeof (hdr
);
112 size_t entry_off
= offsetof(typeof(hdr
), e_entry
);
114 printf("# ELF file header\n");
115 print_hdr(&hdr
, entry_off
);
117 print_hdr(&hdr
.e_entry
, sizeof (hdr
.e_entry
));
118 printf(" # hdr.e_entry\n");
119 print_hdr(&hdr
.e_entry
+ 1, hdr_size
- entry_off
- sizeof (hdr
.e_entry
));
121 printf("\n\n# ELF Program segment headers\n");
122 printf("# - Load segment\n");
123 for (i
= 0; i
< sizeof (phdr_load
); i
+= 4) {
124 print_hdr(((char*)&phdr_load
) + i
, 4);
127 printf("# - ELFNOTE segment\n");
128 for (i
= 0; i
< sizeof (phdr_note
); i
+= 4) {
129 print_hdr(((char*)&phdr_note
) + i
, 4);
133 printf("\n# XEN_ELFNOTE_PHYS32_ENTRY\n");
134 for (i
= 0; i
< sizeof (xen_elf_note
); i
+= 4) {
135 print_hdr(((char*)&xen_elf_note
) + i
, 4);