Is there a way to include a custom binary in EDK2 and load it in a UEFI driver?


mzktsn@...
 

Hello,

i was wondering if there is a way to embed somehow in the build process of the edk2
a custom binary and then be able to load it (read it) from a UEFI driver from C code.


Guomin Jiang
 

You can use PEI Firmware Volume PPI or Firmware Volume2 Protocol to access content from firmware.

https://uefi.org/sites/default/files/resources/PI_Spec_1_7_final_Jan_2019.pdf contain the information you need, the section you need read to get the information is Volume 3, Section 3.3.1 PEI Firmware Volume PPI and Section 3.4.1 Firmware Volume2 Protocol.

I suggest you to read Section 3 Firmware Storage Code Definitions carefully so you can know the storage format.

If you just need sample and just want to support you project quickly, you can search edk2 repository and edk2-platform repository for it.

-----Original Message-----
From: discuss@edk2.groups.io <discuss@edk2.groups.io> On Behalf Of
mzktsn@gmail.com
Sent: Tuesday, April 28, 2020 8:04 PM
To: discuss@edk2.groups.io
Subject: [edk2-discuss] Is there a way to include a custom binary in EDK2 and
load it in a UEFI driver?

Hello,

i was wondering if there is a way to embed somehow in the build process of
the edk2 a custom binary and then be able to load it (read it) from a UEFI
driver from C code.


mzktsn@...
 

Hello Guomin,

Thank you very much for the information,
i am about to read the specifications, although i thought
that the functions described are used to extract files
from a specific FV(files that are already there),..
my questions were one step behind,
in terms on how could someone be able to insert
a raw binary (or a file) from a local filesystem inside a
Firmware Volume.

Thanks


Guomin Jiang
 

Please search the *.fdf file and add below content in the FV section.

FILE RAW = {GUID} {
Align = {Alignment} {File Path}
}

Where {GUID} is the identifier of the file, format is XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX, you can refer any inf for it's format. You can use ```guidgen.exe``` from Microsoft to generate new GUID.
Where {Alignment} is the boundary, can be 4k, 64k, or others.
Where {File Path} is the relative path from you project root path.

This is not the only format, you can refer https://www.gitbook.com/read/book/edk2-docs/edk-ii-fdf-specification 3.6 [FV] Sections for more information about it.

-----Original Message-----
From: discuss@edk2.groups.io <discuss@edk2.groups.io> On Behalf Of
mzktsn@gmail.com
Sent: Tuesday, April 28, 2020 10:10 PM
To: Jiang, Guomin <guomin.jiang@intel.com>; discuss@edk2.groups.io
Subject: Re: [edk2-discuss] Is there a way to include a custom binary in EDK2
and load it in a UEFI driver?

Hello Guomin,

Thank you very much for the information, i am about to read the
specifications, although i thought that the functions described are used to
extract files from a specific FV(files that are already there),..
my questions were one step behind,
in terms on how could someone be able to insert a raw binary (or a file) from
a local filesystem inside a Firmware Volume.

Thanks


mzktsn@...
 

Thanks!


Laszlo Ersek
 

On 04/30/20 19:02, mzktsn@gmail.com wrote:
Hello!

I have managed to insert a custom file into the Firmware Volume,
but then attempting to retrieve the original contents from a DXE_DRIVER,
only the first 4 bytes of the file are returned correct.

Used ReadFile() from EFI_FIRMWARE_VOLUME2_PROTOCOL
succesfully retrieves the 4 first bytes and the rest are modified.
The file size of the Buffer returned is correct by the way.

Am i missing something in the way to retrieve the file contents? Or there is some processing that may alter the contents
without noticing it?
I probably won't have much time to spend on this thread, but I'd suggest
posting a minimal / self-contained reproducer, complete with DSC / FDF /
INF file(s).

Independently, some of the functions in
"MdePkg/Include/Library/DxeServicesLib.h" might prove useful.

Laszlo


Guomin Jiang
 

I am busy recently and won't spend time on the thread until July.

I suggest that you can search the source code and figure out how to use ReadFile() function, I think it is better that use ReadSection service to get the file content.

Best Regards
Guomin

-----Original Message-----
From: Laszlo Ersek <lersek@redhat.com>
Sent: Tuesday, May 5, 2020 11:45 PM
To: discuss@edk2.groups.io; mzktsn@gmail.com; Jiang, Guomin
<guomin.jiang@intel.com>
Subject: Re: [edk2-discuss] Is there a way to include a custom binary in EDK2
and load it in a UEFI driver?

On 04/30/20 19:02, mzktsn@gmail.com wrote:
Hello!

I have managed to insert a custom file into the Firmware Volume, but
then attempting to retrieve the original contents from a DXE_DRIVER,
only the first 4 bytes of the file are returned correct.

Used ReadFile() from EFI_FIRMWARE_VOLUME2_PROTOCOL succesfully
retrieves the 4 first bytes and the rest are modified.
The file size of the Buffer returned is correct by the way.

Am i missing something in the way to retrieve the file contents? Or
there is some processing that may alter the contents without noticing it?
I probably won't have much time to spend on this thread, but I'd suggest
posting a minimal / self-contained reproducer, complete with DSC / FDF / INF
file(s).

Independently, some of the functions in
"MdePkg/Include/Library/DxeServicesLib.h" might prove useful.

Laszlo