From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-in6.apple.com (mail-out6.apple.com [17.151.62.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id BC25621A04817 for ; Mon, 10 Apr 2017 08:49:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; d=apple.com; s=mailout2048s; c=relaxed/simple; q=dns/txt; i=@apple.com; t=1491839398; h=From:Sender:Reply-To:Subject:Date:Message-id:To:Cc:MIME-version:Content-type: Content-transfer-encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-reply-to:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=qvXDvCr7RGgDiQ6rjyyo8LK6bVhi9HbSm71HQKWrTWc=; b=H0P5Dr+lT3hbff1cu4RNtj6v19ZK3XwnzZlckCUDQMZqgdcKtHCaASvyOWleYYFF fqHm5JiSgFuriQAcQNGmbFfrdk2TItdAR2wz37lL3LkpYjo5LKVX1vwPpmqw0nrN na3g4FK8Uxlce1FEiseemkj7n2hm/aq229y2epjVwfCUO9RP324UwxkLXwptQD3h E7cNYr6bCmtFGax7RCb5gEvnR95BmU58NSYKNm+OJnMNUNmgIvJrA754W03tQ+qu pYF9ITanTjUdUZA2p6nq0O/QX02t2ifo04ohsI05LwzvuXWt5nKH/3KTBoZ+bEVH lKZ0X+SKEzL/DjS2rnpQHA==; Received: from relay2.apple.com (relay2.apple.com [17.128.113.67]) by mail-in6.apple.com (Apple Secure Mail Relay) with SMTP id 5B.45.29635.6A9ABE85; Mon, 10 Apr 2017 08:49:58 -0700 (PDT) X-AuditID: 11973e15-3419d9a0000073c3-f3-58eba9a6f5d3 Received: from nwk-mmpp-sz13.apple.com (nwk-mmpp-sz13.apple.com [17.128.115.216]) by relay2.apple.com (Apple SCV relay) with SMTP id 03.28.06512.5A9ABE85; Mon, 10 Apr 2017 08:49:58 -0700 (PDT) MIME-version: 1.0 Received: from [17.153.21.108] (unknown [17.153.21.108]) by nwk-mmpp-sz13.apple.com (Oracle Communications Messaging Server 8.0.1.2.20170210 64bit (built Feb 10 2017)) with ESMTPSA id <0OO7004OEAN8QU20@nwk-mmpp-sz13.apple.com>; Mon, 10 Apr 2017 08:49:57 -0700 (PDT) Sender: afish@apple.com From: Andrew Fish In-reply-to: Date: Mon, 10 Apr 2017 08:49:55 -0700 Cc: edk2-devel@lists.01.org Message-id: <904DA880-DC03-4FAC-AA01-0A9BACAEA0F8@apple.com> References: To: Stefano Cristalli X-Mailer: Apple Mail (2.3273) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrFLMWRmVeSWpSXmKPExsUi2FDorLts5esIg/k3+S32HDrKbHFpWw+b A5PHzll32T26Z/9jCWCK4rJJSc3JLEst0rdL4Mr4f/4La8F9tYru6SvZGhhfyncxcnJICJhI NO2/wdjFyMUhJLCXUaL3QCMLTOLv72ZWiMQhRoldPd/ZQRK8AoISPybfAyri4GAWkJc4eF4W JMwsoCXx/VErC0T9RCaJg996WEESwgLiEu/ObGKGsB0lLt+ZD2azCShLrJj/AWwmp0CwxK8d UxlBbBYBVYknhzqYIYZKSzyceJwVYq+NxIJ9Lcwge4UEAiS+fjAFCYsIGElM//iBFeJmWYlb sy8xg9wgIbCCTWLNx162CYzCs5CcPQvh7FlIzl7AyLyKUSg3MTNHNzPPTC+xoCAnVS85P3cT Iyiwp9uJ7mA8s8rqEKMAB6MSD29BxesIIdbEsuLK3EOM0hwsSuK8pz+/ihASSE8sSc1OTS1I LYovKs1JLT7EyMTBKdXAWP7A2palPcT3e+7hR281KnkDnETj1ZNutCrNVW9VSmFeOZFnQ+zD Du9tZ448VrzNvH92696P3zR0cn25ueWZ5kytsXhwMlb9uaK0YHL2Q4YT6y/P46ycbnPzXsGM jacjdhlIKZpdLJecbfsqVUZ5rnLSho6V6VtStLXni4uUS1nuTZggY79WiaU4I9FQi7moOBEA WnpyAE0CAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuphkeLIzCtJLcpLzFFi42IRbCi+obts5esIg89rmC32HDrKbHFpWw+b A5PHzll32T26Z/9jCWCK4rJJSc3JLEst0rdL4Mr4f/4La8F9tYru6SvZGhhfyncxcnJICJhI /P3dzNrFyMUhJHCIUWJXz3d2kASvgKDEj8n3WLoYOTiYBeQlDp6XBQkzC2hJfH/UygJRP5FJ 4uC3HlaQhLCAuMS7M5uYIWxHict35oPZbALKEivmfwCbySkQLPFrx1RGEJtFQFXiyaEOZoih 0hIPJx5nhdhrI7FgXwszyF4hgQCJrx9MQcIiAkYS0z9+YIW4WVbi1uxLzBMYBWYhuXQWwqWz kFy6gJF5FaNAUWpOYqWRXmJBQU6qXnJ+7iZGcCAWOu9gPLbM6hCjAAejEg9vQcXrCCHWxLLi ylxgUHAwK4nw9iwDCvGmJFZWpRblxxeV5qQWH2KsAjp/IrOUaHI+MErySuINTUwMTIyNzYyN zU3MqSKsJM57bfHzCCGB9MSS1OzU1ILUIpjlTBycUg2M/r9vLzI+FvEukF+eR7ztioNO1MMp q5byiu63Xy3247v2qfalhtPiTq7+cuOc9Cf2j47s20wFdimd2F8Z1Trp+tVJ87ysDSt93vzf Pz2CZfnZLfvavjeJdLyzk0qQ2aSY16oYkh17OnWe4iyhh5U7dHUmWq9Nmc0e+WxW9NJXL4Ry /gZtv/hqkRJLcUaioRZzUXEiAH/sI1KfAgAA Subject: Re: Running pieces of PEI from binary UEFI images X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Apr 2017 15:49:58 -0000 Content-transfer-encoding: 7BIT Content-type: text/plain; CHARSET=US-ASCII > On Apr 10, 2017, at 12:48 AM, Stefano Cristalli wrote: > > Hello everyone, > > I'm interested in experimenting with the PEI phase using EmulatorPkg, > OVMF and other EDKII parts that could be useful. > In particular, I'm interested in the possibility of integrating parts > of an existing pre-built binary UEFI image with such environments. If > the image was developed based on EDKII, would I expect things to work? > I'm not looking for complete emulation, I just think it would be > interesting to be able to single-step code inside PEIMs or even the > PeiCore from random images, leveraging the already existing EDKII > infrastructures (rather than switching to other debugging/emulation > projects). > > I thought that the task might be feasible, since the layout of the > memory at the beginning of PEI and even the arguments passed to the > PeiCore are standardized... I should at least be able to begin > execution. > > What do you think? Am I missing something? > > Additionally, I would ask for technical help, as it's not clear to me > how exactly I would be able > to load such modules. I saw that there is > the possibility of loading binaries inside an EDKII image build (cfr. > INF_Spec_1_25 section 2.7), but I don't understand how would I do this > for PEI binaries and if I could expect things to work (as in with only > the pointer to the image, without any additional information > specified). > Stefano, PEI and DXE are designed to support your usage model. The FD (Flash Device) layout is a simple file system (usually read only, but does not have to be) called an FV (Firmware Volume). The FV contains files that are named by EFI_GUID (UUID), and does not support directories. Each file in an FV consists of a set of sections and sections can encapsulate other sections (that is how compression works). Two (PEI and DXE) of the section types are for depex (Dependency Expressions). The PEI depex grammar is simpler than DXE but they both support TRUE, and ANDing together PPI/Protocol GUIDs. When the depex is true the PEI/DXE Driver is queued for dispatch. So PPI_A AND PPI_B means dispatch this PEIM when both PPI_A and PPI_B are installed in the system. The PEI and DXE Cores both contain dispatchers that make all this happen. This is all described in great detail in the UEFI Platform Initialization (PI) Specification that you can download from here: http://www.uefi.org/specifications The edk2 uses FDF files to layout the FD and build FVs. Here is an example of a binary DXE driver that will dispatch after gPlatformGOPPolicyGuid is installed. https://github.com/tianocore/edk2/blob/master/Vlv2TbltDevicePkg/PlatformPkg.fdf#L577 FILE DRIVER = FF0C8745-3270-4439-B74F-3E45F8C77064 { SECTION DXE_DEPEX_EXP = {gPlatformGOPPolicyGuid} SECTION PE32 = Vlv2MiscBinariesPkg/GOP/7.2.1011/RELEASE_VS2008x86/$(DXE_ARCHITECTURE)/IntelGopDriver.efi SECTION UI = "IntelGopDriver" } The depex type would be different for PEI but you get the idea. The FDF spec lives here: https://github.com/tianocore/tianocore.github.io/wiki/EDK%20II%20Specifications In PEI it is common that the image type may be TE vs. PE/COFF. TE (Tiano Executable) is just a hack to make the PE/COFF header smaller, as in PE/COFF (unlike other image formats) the header is part of the executable image. In general TE makes the most sense when an image is executed from FLASH. You can tell if an image is TE if you hexdump it you will see a VZ signature, and PE/COFF has a PE/0/0 header and can also start with a DOS header that has an MZ signature. The PEI Core will use the FV to find the PE/COFF image, and from the PE/COFF header it can find the offset to the entry point. Thus the PEI Core can call into the PE/COFF image and run it from FLASH, or it can shadow it into memory, relocate the image, and call the entry point. Thanks, Andrew Fish PS MZ is for Mark Zbikowski one of the developers of MS-DOS. VZ is for Vincent Zimmer as he wrote that part of the Tiano Spec that ended up in the PI Spec. Vincent also made the uninitialized memory value 0xAF as a joke about my initials. > I'd really appreciate if someone could give me some explanations to > clear my ideas about this. Some pointers to documentation would be > just fine, for it's quite complicated to figure out completely as an > EDKII beginner. "Dude, it's completely unfeasible" is also fine and > helpful as a response, if that's the case for some reason. > > Thanks in advance. > Best regards. > > Stefano Cristalli > _______________________________________________ > edk2-devel mailing > list > edk2-devel@lists.01.org > https://angler.apple.com:443/proxy?url=ChY71XmEIaglKYTvqPpJ7AsI5LDpggaDTaabgJPkJxd8IubgWIh3iPGbZH%2BpoQgRuP3YvQVwjIVArds4ikYRj%2BSF45Qc%2FowwxUMxCowjAQA%3D&rewritten=true&o=https%3A%2F%2Flists.01.org%2Fmailman%2Flistinfo%2Fedk2-devel