VirtualBox

Changeset 42397 in vbox for trunk/src


Ignore:
Timestamp:
Jul 25, 2012 3:22:05 PM (12 years ago)
Author:
vboxsync
Message:

EFI/Ovmf: Intermediate changes to boot Ovmf based firmware (disabled:VBOX_WITH_OVMF).

Location:
trunk/src/VBox/Devices
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/EFI/DevOVMF.cpp

    r41470 r42397  
    5353#include <Common/PiFirmwareVolume.h>
    5454#include <Common/PiFirmwareFile.h>
    55 #include <IndustryStandard/PeImage.h>
    5655
    5756/*******************************************************************************
     
    359358            {
    360359                case EFI_PANIC_CMD_BAD_ORG:
     360#if 0
    361361                    LogRel(("EFI Panic: You have to fix ORG offset in EfiThunk.asm! Must be 0x%x\n",
    362362                            g_cbEfiThunkBinary));
     
    364364                                     g_cbEfiThunkBinary);
    365365                    break;
     366#endif
    366367
    367368                case EFI_PANIC_CMD_THUNK_TRAP:
     
    579580}
    580581
    581 static int efiFindRelativeAddressOfEPAndBaseAddressOfModule(EFI_FFS_FILE_HEADER const *pFfsFile, uint32_t cbFfsFile, RTGCPHYS *pImageBase, uint8_t **ppbImage)
    582 {
    583     /*
    584      * Sections headers are lays at the beginning of block it describes,
    585      * the first section header is located immediately after FFS header.
    586      */
    587     EFI_FILE_SECTION_POINTER uSecHdrPtr;
    588     uint8_t const * const    pbFfsFileEnd = (uint8_t *)pFfsFile + cbFfsFile;
    589     uint8_t const           *pbImage      = NULL;
    590     uint8_t const           *pbSecHdr     = (uint8_t const *)&pFfsFile[1]; /* FFS header has fixed size */
    591     for (; (uintptr_t)pbSecHdr < (uintptr_t)pbFfsFileEnd;
    592          pbSecHdr += SECTION_SIZE(uSecHdrPtr.CommonHeader))
    593     {
    594         uSecHdrPtr.CommonHeader = (EFI_COMMON_SECTION_HEADER *)pbSecHdr;
    595         if (    uSecHdrPtr.CommonHeader->Type == EFI_SECTION_PE32
    596             ||  uSecHdrPtr.CommonHeader->Type == EFI_SECTION_TE)
    597         {
    598             /*Here should be other code containing sections*/
    599             pbImage = (uint8_t const *)&uSecHdrPtr.Pe32Section[1]; /* the PE/PE+/TE headers begins just after the Section Header */
    600             break;
    601         }
    602         Log2(("EFI: Section of type:%d has been detected\n", uSecHdrPtr.CommonHeader->Type));
    603     }
    604     AssertLogRelMsgReturn(pbImage, ("Failed to find PE32 or TE section for the SECURITY_CORE FFS\n"), VERR_INVALID_PARAMETER);
    605 
    606     /*
    607      * Parse the image extracting the ImageBase and the EntryPoint.
    608      */
    609     int rc = VINF_SUCCESS;
    610     union EfiHdrUnion
    611     {
    612         EFI_IMAGE_DOS_HEADER    Dos;
    613         EFI_IMAGE_NT_HEADERS32  Nt32;
    614         EFI_IMAGE_NT_HEADERS64  Nt64;
    615         EFI_TE_IMAGE_HEADER     Te;
    616     };
    617     EfiHdrUnion const *pHdr = (EfiHdrUnion const *)pbImage;
    618 
    619     /* Skip MZ if found. */
    620     if (pHdr->Dos.e_magic == RT_MAKE_U16('M',  'Z'))
    621     {
    622         uint8_t const *pbNewHdr = (uint8_t const *)pHdr + pHdr->Dos.e_lfanew;
    623         AssertLogRelMsgReturn(   (uintptr_t)pbNewHdr <  (uintptr_t)pbFfsFileEnd
    624                               && (uintptr_t)pbNewHdr >= (uintptr_t)&pHdr->Dos.e_lfanew + sizeof(pHdr->Dos.e_lfanew),
    625                               ("%x\n", pHdr->Dos.e_lfanew),
    626                               VERR_BAD_EXE_FORMAT);
    627         pHdr = (EfiHdrUnion const *)pbNewHdr;
    628     }
    629 
    630     RTGCPHYS ImageBase;
    631     RTGCPHYS EpRVA;
    632     if (pHdr->Nt32.Signature == RT_MAKE_U32_FROM_U8('P', 'E', 0, 0))
    633     {
    634         AssertLogRelMsgReturn(   (   pHdr->Nt32.FileHeader.Machine == EFI_IMAGE_FILE_MACHINE_I386
    635                                   && pHdr->Nt32.FileHeader.SizeOfOptionalHeader == sizeof(pHdr->Nt32.OptionalHeader))
    636                               || (   pHdr->Nt32.FileHeader.Machine == EFI_IMAGE_MACHINE_X64
    637                                   && pHdr->Nt32.FileHeader.SizeOfOptionalHeader == sizeof(pHdr->Nt64.OptionalHeader)),
    638                               ("%x / %x\n", pHdr->Nt32.FileHeader.Machine, pHdr->Nt32.FileHeader.SizeOfOptionalHeader),
    639                               VERR_LDR_ARCH_MISMATCH);
    640         EFI_IMAGE_SECTION_HEADER *pSectionsHeaders = NULL;
    641         int cSectionsHeaders = 0;
    642         if (pHdr->Nt32.FileHeader.Machine == EFI_IMAGE_FILE_MACHINE_I386)
    643         {
    644             Log2(("EFI: PE32/i386\n"));
    645             AssertLogRelMsgReturn(pHdr->Nt32.OptionalHeader.SizeOfImage < cbFfsFile,
    646                                   ("%#x / %#x\n", pHdr->Nt32.OptionalHeader.SizeOfImage, cbFfsFile),
    647                                   VERR_BAD_EXE_FORMAT);
    648             ImageBase = pHdr->Nt32.OptionalHeader.ImageBase;
    649             EpRVA     = pHdr->Nt32.OptionalHeader.AddressOfEntryPoint;
    650             EpRVA     -= pHdr->Nt32.OptionalHeader.BaseOfCode;
    651             AssertLogRelMsgReturn(EpRVA < pHdr->Nt32.OptionalHeader.SizeOfImage,
    652                                   ("%#RGp / %#x\n", EpRVA, pHdr->Nt32.OptionalHeader.SizeOfImage),
    653                                   VERR_BAD_EXE_FORMAT);
    654             pSectionsHeaders = (EFI_IMAGE_SECTION_HEADER *)((uint8_t *)&pHdr->Nt32.OptionalHeader + pHdr->Nt32.FileHeader.SizeOfOptionalHeader);
    655             cSectionsHeaders = pHdr->Nt32.FileHeader.NumberOfSections;
    656         }
    657         else
    658         {
    659             Log2(("EFI: PE+/AMD64 %RX16\n", pHdr->Nt32.FileHeader.Machine));
    660             AssertLogRelMsgReturn(pHdr->Nt64.OptionalHeader.SizeOfImage < cbFfsFile,
    661                                   ("%#x / %#x\n", pHdr->Nt64.OptionalHeader.SizeOfImage, cbFfsFile),
    662                                   VERR_BAD_EXE_FORMAT);
    663             ImageBase = pHdr->Nt64.OptionalHeader.ImageBase;
    664             EpRVA     = pHdr->Nt64.OptionalHeader.AddressOfEntryPoint;
    665             EpRVA     -= pHdr->Nt64.OptionalHeader.BaseOfCode;
    666             AssertLogRelMsgReturn(EpRVA < pHdr->Nt64.OptionalHeader.SizeOfImage,
    667                                   ("%#RGp / %#x\n", EpRVA, pHdr->Nt64.OptionalHeader.SizeOfImage),
    668                                   VERR_BAD_EXE_FORMAT);
    669             pSectionsHeaders = (EFI_IMAGE_SECTION_HEADER *)((uint8_t *)&pHdr->Nt64.OptionalHeader + pHdr->Nt64.FileHeader.SizeOfOptionalHeader);
    670             cSectionsHeaders = pHdr->Nt64.FileHeader.NumberOfSections;
    671         }
    672         AssertPtrReturn(pSectionsHeaders, VERR_BAD_EXE_FORMAT);
    673         int idxSection = 0;
    674         for (; idxSection < cSectionsHeaders; ++idxSection)
    675         {
    676             EFI_IMAGE_SECTION_HEADER *pSection = &pSectionsHeaders[idxSection];
    677             if (!RTStrCmp((const char *)&pSection->Name[0], ".text"))
    678             {
    679                 EpRVA += pSection->PointerToRawData;
    680                 break;
    681             }
    682         }
    683     }
    684     else if (pHdr->Te.Signature == RT_MAKE_U16('V', 'Z'))
    685     {
    686         /* TE header */
    687         Log2(("EFI: TE header\n"));
    688         AssertLogRelMsgReturn(   pHdr->Te.Machine == EFI_IMAGE_FILE_MACHINE_I386
    689                               || pHdr->Te.Machine == EFI_IMAGE_MACHINE_X64,
    690                               ("%x\n", pHdr->Te.Machine),
    691                               VERR_LDR_ARCH_MISMATCH);
    692         ImageBase = pHdr->Te.ImageBase;
    693         EpRVA     = pHdr->Te.AddressOfEntryPoint;
    694         AssertLogRelMsgReturn(EpRVA < cbFfsFile,
    695                               ("%#RGp / %#x\n", EpRVA, cbFfsFile),
    696                               VERR_BAD_EXE_FORMAT);
    697     }
    698     else
    699         AssertLogRelMsgFailedReturn(("%#x\n", pHdr->Nt32.Signature), VERR_INVALID_EXE_SIGNATURE);
    700 
    701     Log2(("EFI: EpRVA=%RGp ImageBase=%RGp EntryPoint=%RGp\n", EpRVA, ImageBase, EpRVA + ImageBase));
    702     if (pImageBase != NULL)
    703         *pImageBase = ImageBase;
    704     if (ppbImage != NULL)
    705         *ppbImage = (uint8_t *)pbImage;
    706     return (EpRVA);
    707 }
    708582
    709583/**
     
    738612
    739613    uint8_t const * const pbFwVolEnd = pThis->pu8EfiRom + pFwVolHdr->FvLength;
    740 
     614    pThis->GCLoadAddress = UINT32_C(0xfffff000) - pThis->cbEfiRom + PAGE_SIZE;
     615
     616#if 0
    741617    /*
    742618     * Ffs files are stored one by one, so to find SECURITY_CORE we've to
     
    779655    LogRel(("EFI: Firmware volume loading at %RGp, PEI CORE at with EP at %RGp\n",
    780656            pThis->GCLoadAddress, pThis->GCEntryPoint1));
     657#endif
    781658    return VINF_SUCCESS;
    782659}
     
    863740}
    864741
     742#if 0
    865743/**
    866744 * Patches and loads the EfiThunk ROM image.
     
    941819    return rc;
    942820}
     821#endif
    943822
    944823
     
    12101089        return rc;
    12111090
     1091#if 0
    12121092    rc = efiLoadThunk(pThis, pCfg);
    12131093    if (RT_FAILURE(rc))
    12141094        return rc;
     1095#endif
    12151096
    12161097    /*
  • trunk/src/VBox/Devices/Makefile.kmk

    r42310 r42397  
    4444  include $(PATH_SUB_CURRENT)/Graphics/BIOS/Makefile.kmk
    4545 endif
    46  ifdef VBOX_WITH_EFI
     46 if defined(VBOX_WITH_EFI) && !defined(VBOX_WITH_OVMF)
    4747  include $(PATH_SUB_CURRENT)/EFI/Thunk/Makefile.kmk
    4848 endif
     
    469469
    470470 ifdef VBOX_WITH_EFI
    471   VBoxDD_DEFS           += VBOX_WITH_EFI
    472   VBoxDD_LIBS           += $(PATH_STAGE_LIB)/EfiThunkBin$(VBOX_SUFF_LIB)
    473   ifdef VBOX_WITH_ALT_EFITHUNK
    474    VBoxDD_DEFS          += VBOX_WITH_ALT_EFITHUNK
    475   endif
    476   VBoxDD_SOURCES        += EFI/DevEFI.cpp
    477   EFI/DevEFI.cpp_INCS       += EFI/tools/include
    478   EFI/DevEFI.cpp_INCS.x86   += EFI/tools/include/Ia32
    479   EFI/DevEFI.cpp_INCS.amd64 += EFI/tools/include/X64
     471  ifndef VBOX_WITH_OVMF
     472   VBoxDD_DEFS           += VBOX_WITH_EFI
     473   VBoxDD_LIBS           += $(PATH_STAGE_LIB)/EfiThunkBin$(VBOX_SUFF_LIB)
     474   ifdef VBOX_WITH_ALT_EFITHUNK
     475    VBoxDD_DEFS          += VBOX_WITH_ALT_EFITHUNK
     476   endif
     477   VBoxDD_SOURCES        += EFI/DevEFI.cpp
     478   EFI/DevEFI.cpp_INCS       += EFI/tools/include
     479   EFI/DevEFI.cpp_INCS.x86   += EFI/tools/include/Ia32
     480   EFI/DevEFI.cpp_INCS.amd64 += EFI/tools/include/X64
     481  else
     482   VBoxDD_DEFS           += VBOX_WITH_EFI
     483   VBoxDD_SOURCES        += EFI/DevOVMF.cpp
     484   EFI/DevOVMF.cpp_INCS       += EFI/tools/include
     485   EFI/DevOVMF.cpp_INCS.x86   += EFI/tools/include/Ia32
     486   EFI/DevOVMF.cpp_INCS.amd64 += EFI/tools/include/X64
     487   build/VBoxDD.cpp_DEFS += VBOX_WITH_OVMF
     488  endif
    480489 endif
    481490
  • trunk/src/VBox/Devices/build/VBoxDD.cpp

    r40652 r42397  
    3737const void *g_apvVBoxDDDependencies[] =
    3838{
    39 #ifdef VBOX_WITH_EFI
     39#if defined(VBOX_WITH_EFI) && !defined(VBOX_WITH_OVMF)
    4040    &g_abEfiThunkBinary[0],
    4141#endif
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette