From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mx.groups.io with SMTP id smtpd.web12.14289.1645545213224397987 for ; Tue, 22 Feb 2022 07:53:33 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=NAITMLT3; spf=pass (domain: intel.com, ip: 192.55.52.93, 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=1645545213; x=1677081213; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VE4zOHGyLSrx6SDbpA3k7/QQACECo5oK53ofJxUJlRI=; b=NAITMLT3WIThMc/fugAPYAzseQH5QOvPWBRx933RrzKQtp9RpPnHkOv8 bRcIQdODqiHC7QRwsOuvzRJJPG/NKEUPd9WI5Wx7Qffm3ttkNFeJ4yiTo 7MqdMXY52pVVjBo0w4ngCrhnE+aNfbldzBqLOdFkcNzU5irKjihhQ7S8k v2RnToHCNZEy0XJl9xEaqniVYxOp4ZLdArIf3U6cej3T14i+FiR4u8n7b RL2CHP6xI3HhsGqq6Rs5M6jt1lsbK1wRnmrGzjyOqSevX3mmg41vKGPPB rQ/hlwcrr6ErfsDgLQSe0iSPzAh2kIXNSmaqqM+K1IAZ2K0kZHCJcdkJr g==; X-IronPort-AV: E=McAfee;i="6200,9189,10266"; a="249318542" X-IronPort-AV: E=Sophos;i="5.88,387,1635231600"; d="scan'208";a="249318542" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2022 07:53:32 -0800 X-IronPort-AV: E=Sophos;i="5.88,387,1635231600"; d="scan'208";a="683560635" Received: from bmolloy-mobl1.ger.corp.intel.com (HELO sboeuf-mobl.home) ([10.252.22.166]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2022 07:53:31 -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 1/3] OvmfPkg: Generate CloudHv as a PVH ELF binary Date: Tue, 22 Feb 2022 16:53:04 +0100 Message-Id: <54a8547ccdea2ae8fc5a58728f861d7019847369.1645542995.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 Following the model from the Xen target, CloudHv is generated as a PVH ELF binary to take advantage of the PVH specification. Signed-off-by: Sebastien Boeuf --- OvmfPkg/CloudHv/CloudHvElfHeaderGenerator.c | 150 ++++++++++++++++++++ OvmfPkg/CloudHv/CloudHvX64.dsc | 2 +- OvmfPkg/CloudHv/CloudHvX64.fdf | 92 +++++++++++- 3 files changed, 241 insertions(+), 3 deletions(-) create mode 100644 OvmfPkg/CloudHv/CloudHvElfHeaderGenerator.c diff --git a/OvmfPkg/CloudHv/CloudHvElfHeaderGenerator.c b/OvmfPkg/CloudHv/= CloudHvElfHeaderGenerator.c new file mode 100644 index 0000000000..83f4e37147 --- /dev/null +++ b/OvmfPkg/CloudHv/CloudHvElfHeaderGenerator.c @@ -0,0 +1,150 @@ +/** @file + This program generates a hex array to be manually coppied into + OvmfXen.fdf. + + The purpose is for the flash device image to be recognize as an ELF. + + Copyright (c) 2019, Citrix Systems, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "elf.h" +#include "stdio.h" +#include "stddef.h" + +void +print_hdr ( + void *s, + size_t size + ) +{ + char *c =3D s; + + while (size--) { + printf ("0x%02hhx, ", *(c++)); + } +} + +/* Format for the XEN_ELFNOTE_PHYS32_ENTRY program segment */ +#define XEN_ELFNOTE_PHYS32_ENTRY 18 +typedef struct { + uint32_t name_size; + uint32_t desc_size; + uint32_t type; + char name[4]; + uint32_t desc; +} xen_elfnote_phys32_entry; + +int +main ( + void + ) +{ + /* FW_SIZE */ + size_t ovmf_blob_size =3D 0x00400000; + /* Load OVMF at 1MB when running as PVH guest */ + 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; + + /* ELF file header */ + Elf64_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), + .e_phentsize =3D sizeof (Elf64_Phdr), + }; + + offset_into_file +=3D sizeof (hdr); + + hdr.e_ident[EI_CLASS] =3D ELFCLASS64; + hdr.e_ident[EI_DATA] =3D ELFDATA2LSB; + hdr.e_ident[EI_VERSION] =3D EV_CURRENT; + hdr.e_ident[EI_OSABI] =3D ELFOSABI_LINUX; + /* Placing program headers just after hdr */ + hdr.e_phoff =3D sizeof (hdr); + + /* program header */ + Elf64_Phdr phdr_load =3D { + .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, + .p_align =3D 4, + }; + + phdr_load.p_vaddr =3D phdr_load.p_paddr; + hdr.e_phnum +=3D 1; + offset_into_file +=3D sizeof (phdr_load); + + /* Xen ELF Note. */ + + xen_elfnote_phys32_entry xen_elf_note =3D { + .type =3D XEN_ELFNOTE_PHYS32_ENTRY, + .name =3D "Xen", + .desc =3D ovmfxen_pvh_entry_point, + .name_size =3D + offsetof (xen_elfnote_phys32_entry, desc) - + offsetof (xen_elfnote_phys32_entry, name), + .desc_size =3D + sizeof (xen_elfnote_phys32_entry) - + offsetof (xen_elfnote_phys32_entry, desc), + }; + Elf64_Phdr phdr_note =3D { + .p_type =3D PT_NOTE, + .p_filesz =3D sizeof (xen_elf_note), + .p_memsz =3D sizeof (xen_elf_note), + .p_flags =3D PF_R, + .p_align =3D 4, + }; + + hdr.e_phnum +=3D 1; + offset_into_file +=3D sizeof (phdr_note); + phdr_note.p_offset =3D offset_into_file; + phdr_note.p_paddr =3D ovmf_base_address + phdr_note.p_offset; + phdr_note.p_vaddr =3D phdr_note.p_paddr; + + /* + * print elf header + */ + + size_t i; + size_t hdr_size =3D sizeof (hdr); + size_t entry_off =3D offsetof (typeof(hdr), e_entry); + + printf ("# ELF file header\n"); + print_hdr (&hdr, entry_off); + printf ("\n"); + print_hdr (&hdr.e_entry, sizeof (hdr.e_entry)); + printf (" # hdr.e_entry\n"); + print_hdr (&hdr.e_entry + 1, hdr_size - entry_off - sizeof (hdr.e_entry)= ); + + printf ("\n\n# ELF Program segment headers\n"); + printf ("# - Load segment\n"); + for (i =3D 0; i < sizeof (phdr_load); i +=3D 4) { + print_hdr (((char *)&phdr_load) + i, 4); + printf ("\n"); + } + + printf ("# - ELFNOTE segment\n"); + for (i =3D 0; i < sizeof (phdr_note); i +=3D 4) { + print_hdr (((char *)&phdr_note) + i, 4); + printf ("\n"); + } + + printf ("\n# XEN_ELFNOTE_PHYS32_ENTRY\n"); + for (i =3D 0; i < sizeof (xen_elf_note); i +=3D 4) { + print_hdr (((char *)&xen_elf_note) + i, 4); + printf ("\n"); + } + + return 0; +} diff --git a/OvmfPkg/CloudHv/CloudHvX64.dsc b/OvmfPkg/CloudHv/CloudHvX64.dsc index 3172100310..b4d855d80f 100644 --- a/OvmfPkg/CloudHv/CloudHvX64.dsc +++ b/OvmfPkg/CloudHv/CloudHvX64.dsc @@ -631,7 +631,7 @@ # ##########################################################################= ###### [Components] - OvmfPkg/ResetVector/ResetVector.inf + OvmfPkg/XenResetVector/XenResetVector.inf = # # SEC Phase modules diff --git a/OvmfPkg/CloudHv/CloudHvX64.fdf b/OvmfPkg/CloudHv/CloudHvX64.fdf index ce3302c6d6..bb734d4c8d 100644 --- a/OvmfPkg/CloudHv/CloudHvX64.fdf +++ b/OvmfPkg/CloudHv/CloudHvX64.fdf @@ -24,7 +24,95 @@ ErasePolarity =3D 1 BlockSize =3D $(BLOCK_SIZE) NumBlocks =3D $(FW_BLOCKS) = -!include OvmfPkg/VarStore.fdf.inc +!if ($(FD_SIZE_IN_KB) =3D=3D 1024) || ($(FD_SIZE_IN_KB) =3D=3D 2048) +0x00000000|0x0000e000 +!endif +!if $(FD_SIZE_IN_KB) =3D=3D 4096 +0x00000000|0x00040000 +!endif +DATA =3D { + # + # This hex array have been generated by OvmfPkg/OvmfXenElfHeaderGenerato= r.c + # and copied manually. + # + # ELF file header + 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, = 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, + 0xd0, 0xff, 0x4f, 0x00, 0x00, 0x00, 0x00, 0x00, # hdr.e_entry + 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x38, 0x00, 0x0= 2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + # ELF Program segment headers + # - Load segment + 0x01, 0x00, 0x00, 0x00, + 0x07, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x40, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x40, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + # - ELFNOTE segment + 0x04, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, + 0xb0, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0xb0, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0xb0, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + + # XEN_ELFNOTE_PHYS32_ENTRY + 0x04, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, + 0x12, 0x00, 0x00, 0x00, + 0x58, 0x65, 0x6e, 0x00, + 0xd0, 0xff, 0x4f, 0x00 +} + +!if ($(FD_SIZE_IN_KB) =3D=3D 1024) || ($(FD_SIZE_IN_KB) =3D=3D 2048) +0x0000e000|0x00001000 +!endif +!if $(FD_SIZE_IN_KB) =3D=3D 4096 +0x00040000|0x00001000 +!endif +#NV_EVENT_LOG + +!if ($(FD_SIZE_IN_KB) =3D=3D 1024) || ($(FD_SIZE_IN_KB) =3D=3D 2048) +0x0000f000|0x00001000 +!endif +!if $(FD_SIZE_IN_KB) =3D=3D 4096 +0x00041000|0x00001000 +!endif +#NV_FTW_WORKING +DATA =3D { + # EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER->Signature =3D gEdkiiWorkingBl= ockSignatureGuid =3D + # { 0x9e58292b, 0x7c68, 0x497d, { 0xa0, 0xce, 0x65, 0x0, 0xfd, 0x9f, 0= x1b, 0x95 }} + 0x2b, 0x29, 0x58, 0x9e, 0x68, 0x7c, 0x7d, 0x49, + 0xa0, 0xce, 0x65, 0x0, 0xfd, 0x9f, 0x1b, 0x95, + # Crc:UINT32 #WorkingBlockValid:1, WorkingBlockInvalid:1, Res= erved + 0x2c, 0xaf, 0x2c, 0x64, 0xFE, 0xFF, 0xFF, 0xFF, + # WriteQueueSize: UINT64 + 0xE0, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +} + +!if ($(FD_SIZE_IN_KB) =3D=3D 1024) || ($(FD_SIZE_IN_KB) =3D=3D 2048) +0x00010000|0x00010000 +!endif +!if $(FD_SIZE_IN_KB) =3D=3D 4096 +0x00042000|0x00042000 +!endif +#NV_FTW_SPARE = $(VARS_SIZE)|$(FVMAIN_SIZE) FV =3D FVMAIN_COMPACT @@ -142,7 +230,7 @@ READ_LOCK_STATUS =3D TRUE # INF OvmfPkg/Sec/SecMain.inf = -INF RuleOverride=3DRESET_VECTOR OvmfPkg/ResetVector/ResetVector.inf +INF RuleOverride=3DRESET_VECTOR OvmfPkg/XenResetVector/XenResetVector.inf = ##########################################################################= ###### [FV.PEIFV] -- = 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.