From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web11.10267.1645635350141524745 for ; Wed, 23 Feb 2022 08:55:50 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=eQ68pX4q; spf=pass (domain: intel.com, ip: 192.55.52.151, mailfrom: sebastien.boeuf@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645635350; x=1677171350; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8C8E9Hy3vOJr+MMUlr5Jlhy06rQrLJyxuSnkYPzuWc4=; b=eQ68pX4q+6JFNmk1hpCNxwzogtv8bGz0u+dte2BbVVVLxa6iSJ5fUReN lKPF6NxbCwofuqgfrV0UwsoNLJS5zcji5/8ZfzRyhhCbw8dwFO9p+or4k 8ubjyCamoDPjUscZW/QdhXTHS9fvLaopO7L7V+gh7PZUOZFZ1sobuxne7 3v605WLJizMBqxQaSxEN+b3uNzbaWeeIG2RlP6ELv7yaNmKQtGnapiKju NNJgY+p0WYYtQZIukI7g57mZJ2SWB3TRZjJ6qw8KNm6cAAn99jo4ptHy4 g58c97XkRiuiMaF5OAIFTnsiz0QKz1DIOnUPi/H3G7PjMuTbsjcMv90V7 g==; X-IronPort-AV: E=McAfee;i="6200,9189,10267"; a="232642668" X-IronPort-AV: E=Sophos;i="5.88,391,1635231600"; d="scan'208";a="232642668" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2022 08:51:52 -0800 X-IronPort-AV: E=Sophos;i="5.88,391,1635231600"; d="scan'208";a="505986316" Received: from lobrie3x-mobl4.ger.corp.intel.com (HELO sboeuf-mobl.home) ([10.252.24.99]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2022 08:51:49 -0800 From: "Boeuf, Sebastien" To: devel@edk2.groups.io Cc: jiewen.yao@intel.com, jordan.l.justen@intel.com, kraxel@redhat.com, sebastien.boeuf@intel.com Subject: [PATCH v2 1/5] OvmfPkg: Make the Xen ELF header generator more flexible Date: Wed, 23 Feb 2022 17:51:26 +0100 Message-Id: <28aafabd6d684650e526fbc42a28cef2c90a9e86.1645634879.git.sebastien.boeuf@intel.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable From: Sebastien Boeuf Adding some flexibility to the program so that other targets can use it if needed. An optional size parameter is added so that we can provide the expected blob size of the generated binary. A global define is added so that we can choose at build time if we want to use 32-bit or 64-bit bases structures. The default behavior isn't modified. Signed-off-by: Sebastien Boeuf --- OvmfPkg/OvmfXenElfHeaderGenerator.c | 63 ++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 11 deletions(-) diff --git a/OvmfPkg/OvmfXenElfHeaderGenerator.c b/OvmfPkg/OvmfXenElfHeader= Generator.c index 489060cdad..a054c77cda 100644 --- a/OvmfPkg/OvmfXenElfHeaderGenerator.c +++ b/OvmfPkg/OvmfXenElfHeaderGenerator.c @@ -12,6 +12,7 @@ #include "elf.h" #include "stdio.h" #include "stddef.h" +#include "stdlib.h" = void print_hdr ( @@ -38,7 +39,8 @@ typedef struct { = int main ( - void + int argc, + char *argv[] ) { /* FW_SIZE */ @@ -47,23 +49,46 @@ main ( uint32_t ovmf_base_address =3D 0x00100000; /* Xen PVH entry point */ uint32_t ovmfxen_pvh_entry_point =3D ovmf_base_address + ovmf_blob_size= - 0x30; - size_t offset_into_file =3D 0; + size_t offset_into_file =3D 0; + char *endptr, *str; + long param; + + /* Parse the size parameter */ + if (argc > 1) { + str =3D argv[1]; + param =3D strtol (str, &endptr, 10); + if (endptr !=3D str) { + ovmf_blob_size =3D (size_t)param; + } + } = /* ELF file header */ + #ifdef PVH64 + Elf64_Ehdr hdr =3D { + #else Elf32_Ehdr hdr =3D { - .e_ident =3D ELFMAG, - .e_type =3D ET_EXEC, - .e_machine =3D EM_386, - .e_version =3D EV_CURRENT, - .e_entry =3D ovmfxen_pvh_entry_point, - .e_flags =3D R_386_NONE, - .e_ehsize =3D sizeof (hdr), + #endif + .e_ident =3D ELFMAG, + .e_type =3D ET_EXEC, + .e_machine =3D EM_386, + .e_version =3D EV_CURRENT, + .e_entry =3D ovmfxen_pvh_entry_point, + .e_flags =3D R_386_NONE, + .e_ehsize =3D sizeof (hdr), + #ifdef PVH64 + .e_phentsize =3D sizeof (Elf64_Phdr), + #else .e_phentsize =3D sizeof (Elf32_Phdr), + #endif }; = offset_into_file +=3D sizeof (hdr); = - hdr.e_ident[EI_CLASS] =3D ELFCLASS32; + #ifdef PVH64 + hdr.e_ident[EI_CLASS] =3D ELFCLASS64; + #else + hdr.e_ident[EI_CLASS] =3D ELFCLASS32; + #endif hdr.e_ident[EI_DATA] =3D ELFDATA2LSB; hdr.e_ident[EI_VERSION] =3D EV_CURRENT; hdr.e_ident[EI_OSABI] =3D ELFOSABI_LINUX; @@ -71,14 +96,22 @@ main ( hdr.e_phoff =3D sizeof (hdr); = /* program header */ + #ifdef PVH64 + Elf64_Phdr phdr_load =3D { + #else Elf32_Phdr phdr_load =3D { + #endif .p_type =3D PT_LOAD, .p_offset =3D 0, /* load everything */ .p_paddr =3D ovmf_base_address, .p_filesz =3D ovmf_blob_size, .p_memsz =3D ovmf_blob_size, .p_flags =3D PF_X | PF_W | PF_R, + #ifdef PVH64 + .p_align =3D 4, + #else .p_align =3D 0, + #endif }; = phdr_load.p_vaddr =3D phdr_load.p_paddr; @@ -98,12 +131,20 @@ main ( sizeof (xen_elfnote_phys32_entry) - offsetof (xen_elfnote_phys32_entry, desc), }; - Elf32_Phdr phdr_note =3D { + #ifdef PVH64 + Elf64_Phdr phdr_note =3D { + #else + Elf32_Phdr phdr_note =3D { + #endif .p_type =3D PT_NOTE, .p_filesz =3D sizeof (xen_elf_note), .p_memsz =3D sizeof (xen_elf_note), .p_flags =3D PF_R, + #ifdef PVH64 + .p_align =3D 4, + #else .p_align =3D 0, + #endif }; = hdr.e_phnum +=3D 1; -- = 2.32.0 --------------------------------------------------------------------- Intel Corporation SAS (French simplified joint stock company) Registered headquarters: "Les Montalets"- 2, rue de Paris, = 92196 Meudon Cedex, France Registration Number: 302 456 199 R.C.S. NANTERRE Capital: 4,572,000 Euros This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.