Also, I just tried to load the x86 version of bootmgfw.efi in a the
IA32 Nt32Pkg shell. First I copied this file under
edk2\Build\NT32IA32\DEBUG_VS2012x86\IA32. Then I ran the shell and
then issued the command "load bootmgfw.efi". This failed with the
error "Image is not a driver". This obviously means that the "load"
command loads only drivers. How do I load an EFI application in this
shell then?

Thanks.

-Gurinder

On Fri, Jul 4, 2014 at 5:20 PM, Gurinder Singh
<frederick.the.f...@gmail.com> wrote:
> Hi Andrew,
>
> Thanks for the reply.
>
> From the looks of it, it TFTP over a DevicePath will require quite a
> bit of work. So, being short of time, perhaps I should not attempt
> that.
>
> My only option then is if I can somehow debug the StartImage()
> function. So I just wanna know how I go about doing that.
>
> For starters, I see that CoreStartImge() has some DEBUG calls which
> print debug messages. How can I get these messages to be displayed on
> the client that's booting. My client is a HyperV VM (I'm of course
> assuming here that HyperV UEFI firmware is built on EDK2).
>
> Thanks in advance.
>
> -Gurinder
>
>
>
>
>
>
>
>
>
>
> On Thu, Jul 3, 2014 at 8:50 PM, Andrew Fish <af...@apple.com> wrote:
>>
>> On Jul 3, 2014, at 6:25 AM, Gurinder Singh <frederick.the.f...@gmail.com> 
>> wrote:
>>
>>> Hi Feng,
>>>
>>> I moved the FreePool() call as you suggested, but it had no effect.
>>> But was expected because the buffer has no role to play once the image
>>> is loaded, I think. :( Thanks for the suggestion though.
>>>
>>> I have a question about loading the binary into a shell. This is an
>>> x64 binary. The only shell in EDK I know of is the one in Nt32Pkg. But
>>> can it load an x64 binary? If not, how do I get my hands on an x64
>>> shell?
>>>
>>
>> Well this is the edk2 mailing list, not the EDK mailing list……
>>
>> There are UEFI shell binaries here: 
>> https://svn.code.sf.net/p/edk2/code/trunk/edk2/ShellBinPkg/UefiShell/
>>
>> And the NT32 package supports IA32 and X64 
>> https://svn.code.sf.net/p/edk2/code/trunk/edk2/Nt32Pkg/Nt32Pkg.dsc
>>
>>> My second question is about device paths. This binary I'm trying to
>>> run resides on a TFTP server (it's a PXE boot loader). I was wondering
>>> if I could load it via DevicePath.
>>
>> To boot from the network you need a LoadFile protocol: 
>> https://svn.code.sf.net/p/edk2/code/trunk/edk2/MdePkg/Include/Protocol/LoadFile.h
>>
>> The LoadFile protocol needs to be on a handle in the device path you try to 
>> boot from.
>>
>> I don’t think PXE boot supports booting from a passed in device path. The 
>> design of the PXE boot is to have the remote server pick the image that gets 
>> served to the machine.
>>
>> If you want to support TFTP booting from a known device path (IP + 
>> filename), you would have to write a driver that implements LoadFile, and 
>> then does a TFTP read from the IP and filename.
>>
>>> But I don't know what device path I
>>> should build for it because UEFI spec does not mention TFTP under the
>>> EFI_DEVICE_PATH_PROTOCOL section. So given the following two pieces of
>>> info, could you guys suggest me the correct device path (in string
>>> from):
>>>
>>
>> You could double check with a PXE boot but I think it would be:
>>
>> Device Path to NIC (handle will have a LoadFile portico on itl)
>> +
>> IPv4/IPv6 device path node
>> +
>> File Path
>>
>> Thanks,
>>
>> Andrew Fish
>>
>>> 1. TFTP server IP: 192.168.1.1
>>> 2. boot file path: boot/x64/bootmgfw.efi
>>>
>>> Thanks a lot in advance.
>>>
>>> -Gurinder
>>>
>>> On Thu, Jul 3, 2014 at 10:43 AM, Tian, Feng <feng.t...@intel.com> wrote:
>>>> Hi, Gurinder
>>>>
>>>> Please move FreePool(bootProgramBuffer) behind gBS->StartImage() and have 
>>>> a try to see if your issue could be solved.
>>>>
>>>> Thanks
>>>> Feng
>>>>
>>>> -----Original Message-----
>>>> From: Gurinder Singh [mailto:frederick.the.f...@gmail.com]
>>>> Sent: Thursday, July 03, 2014 12:49
>>>> To: edk2-devel@lists.sourceforge.net
>>>> Subject: Re: [edk2] Failing to Start Image bootmgfw.efi
>>>>
>>>>> // Load it as an image
>>>>>
>>>>> status = gBS->LoadImage(FALSE, NULL, NULL, bootProgramBuffer,
>>>>> bootProgramSize, &loadedBootProgram);
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> What return status do you get here? Is loadedBootProgram a valid handle? 
>>>>> It should have the LoadedImage protocol on the handle. You can dump that 
>>>>> out for more info.
>>>>
>>>>
>>>> I get a status of 0 here which means success. So the image is getting 
>>>> loaded okay. I've dumped things like ImageBase, ImageCodeType, 
>>>> ImageDataType and it all looks good to me.
>>>>
>>>> The failure occurs only when I return StartImage(), which is return status 
>>>> code 2.
>>>>
>>>> Anyway, thanks for pointing me to the implementation of StartImage 
>>>> (CoreStartImage). I think it should easier solve the problem now.
>>>>
>>>>
>>>>>> Will it run if you launch it from the shell?
>>>>
>>>> No I haven't tried with the shell. Will try it and see.
>>>>
>>>>
>>>> Thanks for your help Andrew. Much appreciated.
>>>>
>>>> -Gurinder
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On Wed, Jul 2, 2014 at 9:15 PM, Andrew Fish <af...@apple.com> wrote:
>>>>>
>>>>>
>>>>> On Jul 2, 2014, at 2:49 AM, Gurinder Singh <frederick.the.f...@gmail.com> 
>>>>> wrote:
>>>>>
>>>>> Hi guys,
>>>>>
>>>>>
>>>>>
>>>>> I’m writing a small EFI shim that will load the Windows UEFI loader 
>>>>> bootmgfw.efi and run it. Here’s the relevant code snippet:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> bootProgramName = "boot\\x64\\bootmgfw.efi";
>>>>>
>>>>>
>>>>>
>>>>> // Get the size of bootmgfw.efi from the TFTP server
>>>>>
>>>>> status = pxeProtocol->Mtftp(pxeProtocol,
>>>>> EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE, NULL, FALSE, &bootProgramSize,
>>>>> &tftpBlockSize, &bootServerIp, bootProgramName, NULL, FALSE);
>>>>>
>>>>>
>>>>>
>>>>> // Allocate buffer and download bootmgfw.efi
>>>>>
>>>>> bootProgramBuffer = AllocatePool(bootProgramSize);
>>>>>
>>>>> status = pxeProtocol->Mtftp(pxeProtocol,
>>>>> EFI_PXE_BASE_CODE_TFTP_READ_FILE, bootProgramBuffer, FALSE,
>>>>> &bootProgramSize, &tftpBlockSize, &bootServerIp, bootProgramName,
>>>>> NULL, FALSE);
>>>>>
>>>>>
>>>>>
>>>>> // Load it as an image
>>>>>
>>>>> status = gBS->LoadImage(FALSE, NULL, NULL, bootProgramBuffer,
>>>>> bootProgramSize, &loadedBootProgram);
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> What return status do you get here? Is loadedBootProgram a valid handle? 
>>>>> It should have the LoadedImage protocol on the handle. You can dump that 
>>>>> out for more info.
>>>>>
>>>>> https://svn.code.sf.net/p/edk2/code/trunk/edk2/MdePkg/Include/Protocol
>>>>> /LoadedImage.h
>>>>>
>>>>> typedef struct {
>>>>>  UINT32            Revision;       ///< Defines the revision of the 
>>>>> EFI_LOADED_IMAGE_PROTOCOL structure.
>>>>>                                    ///< All future revisions will be 
>>>>> backward compatible to the current revision.
>>>>>  EFI_HANDLE        ParentHandle;   ///< Parent image's image handle. NULL 
>>>>> if the image is loaded directly from
>>>>>                                    ///< the firmware's boot manager.
>>>>>  EFI_SYSTEM_TABLE  *SystemTable;   ///< the image's EFI system table 
>>>>> pointer.
>>>>>
>>>>>  //
>>>>>  // Source location of image
>>>>>  //
>>>>>  EFI_HANDLE        DeviceHandle;   ///< The device handle that the EFI 
>>>>> Image was loaded from.
>>>>>  EFI_DEVICE_PATH_PROTOCOL  *FilePath;  ///< A pointer to the file path 
>>>>> portion specific to DeviceHandle
>>>>>                                        ///< that the EFI Image was loaded 
>>>>> from.
>>>>>  VOID              *Reserved;      ///< Reserved. DO NOT USE.
>>>>>
>>>>>  //
>>>>>  // Images load options
>>>>>  //
>>>>>  UINT32            LoadOptionsSize;///< The size in bytes of LoadOptions.
>>>>>  VOID              *LoadOptions;   ///< A pointer to the image's binary 
>>>>> load options.
>>>>>
>>>>>  //
>>>>>  // Location of where image was loaded
>>>>>  //
>>>>>  VOID              *ImageBase;     ///< The base address at which the 
>>>>> image was loaded.
>>>>>  UINT64            ImageSize;      ///< The size in bytes of the loaded 
>>>>> image.
>>>>>  EFI_MEMORY_TYPE   ImageCodeType;  ///< The memory type that the code 
>>>>> sections were loaded as.
>>>>>  EFI_MEMORY_TYPE   ImageDataType;  ///< The memory type that the data 
>>>>> sections were loaded as.
>>>>>  EFI_IMAGE_UNLOAD  Unload;
>>>>> } EFI_LOADED_IMAGE_PROTOCOL;
>>>>>
>>>>>
>>>>>
>>>>> FreePool(bootProgramBuffer);
>>>>>
>>>>>
>>>>>
>>>>> // And start it.
>>>>>
>>>>> status = gBS->StartImage(loadedBootProgram, NULL, NULL); <--- This
>>>>> call returns status 2 (EFI_INVALID_PARAMETER)
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> gBS->StartImage maps to CoreStartImage()...
>>>>>
>>>>> https://svn.code.sf.net/p/edk2/code/trunk/edk2/MdeModulePkg/Core/Dxe/I
>>>>> mage/Image.c
>>>>>
>>>>> EFI_STATUS
>>>>> EFIAPI
>>>>> CoreStartImage (
>>>>>  IN EFI_HANDLE  ImageHandle,
>>>>>  OUT UINTN      *ExitDataSize,
>>>>>  OUT CHAR16     **ExitData  OPTIONAL
>>>>>  )
>>>>> {
>>>>>  EFI_STATUS                    Status;
>>>>>  LOADED_IMAGE_PRIVATE_DATA     *Image;
>>>>>  LOADED_IMAGE_PRIVATE_DATA     *LastImage;
>>>>>  UINT64                        HandleDatabaseKey;
>>>>>  UINTN                         SetJumpFlag;
>>>>>  UINT64                        Tick;
>>>>>  EFI_HANDLE                    Handle;
>>>>>
>>>>>  Tick = 0;
>>>>>  Handle = ImageHandle;
>>>>>
>>>>>  Image = CoreLoadedImageInfo (ImageHandle);
>>>>>  if (Image == NULL  ||  Image->Started) {
>>>>>    return EFI_INVALID_PARAMETER;
>>>>>  }
>>>>>  if (EFI_ERROR (Image->LoadImageStatus)) {
>>>>>    return Image->LoadImageStatus;
>>>>>  }
>>>>>
>>>>> The return status could also be coming from the PE/COFF image if you 
>>>>> actually started it.
>>>>>
>>>>>
>>>>>
>>>>> The shim downloads the bootmgfw.efi file correctly and successfully loads 
>>>>> it with LoadImage(). However, when it tries to transfer control to it by 
>>>>> calling StartImage() an EFI_INVALID_PARAMETER status is returned. As per 
>>>>> UEFI documentation this status code means the image is not valid.
>>>>>
>>>>>
>>>>>
>>>>> I’ve tried to tweak the PE headers of this image (file alignment and 
>>>>> all), but nothing has worked. I don’t know any other reason why the image 
>>>>> can be invalid.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> The gBS->LoadImage() does all the PE/COFF loading. So you should get an 
>>>>> error out of that.
>>>>>
>>>>> You can DUMPBIN.EXE /ALL (or other sets of args) to dump the PE/COFF
>>>>>
>>>>> The shim successfully loads and starts other .efi files that I’ve created 
>>>>> myself using EDK. So I can’t see what’s wrong with this code either.
>>>>>
>>>>>
>>>>>
>>>>> Also bootmgfw.efi runs successfully if it is directly downloaded by the 
>>>>> machine firmware over PXE (without my shim being involved at all).
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Will it run if you launch it from the shell?
>>>>>
>>>>
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Andrew Fish
>>>>>
>>>>> Could anyone please spot what I’m doing wrong in the above code and help 
>>>>> me? Or, if anyone has previous experience with this Microsoft boot 
>>>>> loader, is there something special about it that I'm missing?
>>>>>
>>>>>
>>>>> Thanks in advance.
>>>>>
>>>>>
>>>>>
>>>>> Here’s the relevant information about my environment:
>>>>>
>>>>>
>>>>>
>>>>> UEFI machine: a HyperV virtual machine.
>>>>>
>>>>> TOOL_CHAIN_TAG value: VS2012x86.
>>>>>
>>>>> Architecture I’m building this shim for: x64
>>>>>
>>>>> Architecture of bootmgfw.efi: x64
>>>>>
>>>>> My build command-line:
>>>>>
>>>>> cd /D D:\Projects\1E\tianocore-edk2
>>>>>
>>>>> set WORKSPACE=D:\Projects\1E\tianocore-edk2
>>>>>
>>>>> call edksetup.bat
>>>>>
>>>>> Build -a X64 -p DuetPkg/DuetPkgX64.dsc
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Cheers,
>>>>>
>>>>> Gurinder
>>>>>
>>>>> ----------------------------------------------------------------------
>>>>> -------- Open source business process management suite built on Java
>>>>> and Eclipse Turn processes into business applications with Bonita BPM
>>>>> Community Edition Quickly connect people, data, and systems into
>>>>> organized workflows Winner of BOSSIE, CODIE, OW2 and Gartner awards
>>>>> http://p.sf.net/sfu/Bonitasoft________________________________________
>>>>> _______
>>>>> edk2-devel mailing list
>>>>> edk2-devel@lists.sourceforge.net
>>>>> https://lists.sourceforge.net/lists/listinfo/edk2-devel
>>>>>
>>>>>
>>>>>
>>>>> ----------------------------------------------------------------------
>>>>> -------- Open source business process management suite built on Java
>>>>> and Eclipse Turn processes into business applications with Bonita BPM
>>>>> Community Edition Quickly connect people, data, and systems into
>>>>> organized workflows Winner of BOSSIE, CODIE, OW2 and Gartner awards
>>>>> http://p.sf.net/sfu/Bonitasoft
>>>>> _______________________________________________
>>>>> edk2-devel mailing list
>>>>> edk2-devel@lists.sourceforge.net
>>>>> https://lists.sourceforge.net/lists/listinfo/edk2-devel
>>>>>
>>>>
>>>> ------------------------------------------------------------------------------
>>>> Open source business process management suite built on Java and Eclipse 
>>>> Turn processes into business applications with Bonita BPM Community 
>>>> Edition Quickly connect people, data, and systems into organized workflows 
>>>> Winner of BOSSIE, CODIE, OW2 and Gartner awards 
>>>> http://p.sf.net/sfu/Bonitasoft 
>>>> _______________________________________________
>>>> edk2-devel mailing list
>>>> edk2-devel@lists.sourceforge.net
>>>> https://lists.sourceforge.net/lists/listinfo/edk2-devel
>>>> ------------------------------------------------------------------------------
>>>> Open source business process management suite built on Java and Eclipse
>>>> Turn processes into business applications with Bonita BPM Community Edition
>>>> Quickly connect people, data, and systems into organized workflows
>>>> Winner of BOSSIE, CODIE, OW2 and Gartner awards
>>>> http://p.sf.net/sfu/Bonitasoft
>>>> _______________________________________________
>>>> edk2-devel mailing list
>>>> edk2-devel@lists.sourceforge.net
>>>> https://lists.sourceforge.net/lists/listinfo/edk2-devel
>>>
>>> ------------------------------------------------------------------------------
>>> Open source business process management suite built on Java and Eclipse
>>> Turn processes into business applications with Bonita BPM Community Edition
>>> Quickly connect people, data, and systems into organized workflows
>>> Winner of BOSSIE, CODIE, OW2 and Gartner awards
>>> http://p.sf.net/sfu/Bonitasoft
>>> _______________________________________________
>>> edk2-devel mailing list
>>> edk2-devel@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/edk2-devel
>>
>>
>> ------------------------------------------------------------------------------
>> Open source business process management suite built on Java and Eclipse
>> Turn processes into business applications with Bonita BPM Community Edition
>> Quickly connect people, data, and systems into organized workflows
>> Winner of BOSSIE, CODIE, OW2 and Gartner awards
>> http://p.sf.net/sfu/Bonitasoft
>> _______________________________________________
>> edk2-devel mailing list
>> edk2-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/edk2-devel

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to