VirtualBox

Changeset 91329 in vbox for trunk/src/VBox/Devices/EFI


Ignore:
Timestamp:
Sep 22, 2021 3:16:12 PM (3 years ago)
Author:
vboxsync
Message:

Devices/DevEFI: Use the new NVRAM storage interface if it is available, bugref:10098

Location:
trunk/src/VBox/Devices/EFI
Files:
3 edited

Legend:

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

    r91324 r91329  
    209209        /** The NVRAM driver base interface. */
    210210        PPDMIBASE           pDrvBase;
     211        /** The VFS interface of the driver below for NVRAM state loading and storing. */
     212        PPDMIVFSCONNECTOR   pDrvVfs;
    211213    } Lun0;
    212214} DEVEFIR3;
     
    10091011static DECLCALLBACK(void) efiPowerOff(PPDMDEVINS pDevIns)
    10101012{
    1011     PDEVEFIR3  pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PDEVEFIR3);
    1012     RT_NOREF(pThisCC);
     1013    PDEVEFI   pThis   = PDMDEVINS_2_DATA(pDevIns, PDEVEFI);
     1014    PDEVEFIR3 pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PDEVEFIR3);
     1015
     1016    if (pThisCC->Lun0.pDrvVfs)
     1017    {
     1018        int rc = flashR3SaveToVfs(&pThis->Flash, pDevIns, pThisCC->Lun0.pDrvVfs,
     1019                                  pDevIns->pReg->szName, "nvram");
     1020        if (RT_FAILURE(rc))
     1021            LogRel(("EFI: Failed to save flash file to NVRAM store: %Rrc\n", rc));
     1022    }
     1023    else if (pThisCC->pszNvramFile)
     1024    {
     1025        int rc = flashR3SaveToFile(&pThis->Flash, pDevIns, pThisCC->pszNvramFile);
     1026        if (RT_FAILURE(rc))
     1027            LogRel(("EFI: Failed to save flash file to '%s': %Rrc\n", pThisCC->pszNvramFile, rc));
     1028    }
    10131029}
    10141030
     
    10281044    PDEVEFI   pThis   = PDMDEVINS_2_DATA(pDevIns, PDEVEFI);
    10291045    PDEVEFIR3 pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PDEVEFIR3);
    1030 
    1031     if (pThisCC->pszNvramFile)
    1032     {
    1033         int rc = flashR3SaveToFile(&pThis->Flash, pDevIns, pThisCC->pszNvramFile);
    1034         if (RT_FAILURE(rc))
    1035             LogRel(("EFI: Failed to save flash file to '%s': %Rrc\n", pThisCC->pszNvramFile, rc));
    1036     }
    10371046
    10381047    flashR3Destruct(&pThis->Flash, pDevIns);
     
    11561165        return rc;
    11571166
    1158     /* If the file does not exist we initialize the NVRAM from the loaded ROM file. */
    1159     if (!pThisCC->pszNvramFile || !RTPathExists(pThisCC->pszNvramFile))
    1160         rc = flashR3LoadFromBuf(&pThis->Flash, pThisCC->pu8EfiRom, pThisCC->cbNvram);
     1167    if (pThisCC->Lun0.pDrvVfs)
     1168    {
     1169        rc = flashR3LoadFromVfs(&pThis->Flash, pDevIns, pThisCC->Lun0.pDrvVfs,
     1170                                pDevIns->pReg->szName, "nvram");
     1171        if (rc == VERR_NOT_FOUND)
     1172        {
     1173            /* Initialize the NVRAM content from the loaded ROM file as the NVRAM wasn't initialized yet. */
     1174            rc = flashR3LoadFromBuf(&pThis->Flash, pThisCC->pu8EfiRom, pThisCC->cbNvram);
     1175        }
     1176        else if (RT_FAILURE(rc))
     1177            return rc;
     1178    }
    11611179    else
    1162         rc = flashR3LoadFromFile(&pThis->Flash, pDevIns, pThisCC->pszNvramFile);
    1163     if (RT_FAILURE(rc))
    1164         return rc;
     1180    {
     1181        /* If the file does not exist we initialize the NVRAM from the loaded ROM file. */
     1182        if (!pThisCC->pszNvramFile || !RTPathExists(pThisCC->pszNvramFile))
     1183            rc = flashR3LoadFromBuf(&pThis->Flash, pThisCC->pu8EfiRom, pThisCC->cbNvram);
     1184        else
     1185            rc = flashR3LoadFromFile(&pThis->Flash, pDevIns, pThisCC->pszNvramFile);
     1186        if (RT_FAILURE(rc))
     1187            return rc;
     1188    }
    11651189
    11661190    pThisCC->GCLoadAddress = pThisCC->GCPhysNvram + pThisCC->cbNvram;
     
    15711595    if (RT_SUCCESS(rc))
    15721596    {
    1573         /** @todo */
     1597        pThisCC->Lun0.pDrvVfs = PDMIBASE_QUERY_INTERFACE(pThisCC->Lun0.pDrvBase, PDMIVFSCONNECTOR);
     1598        if (!pThisCC->Lun0.pDrvVfs)
     1599            return PDMDevHlpVMSetError(pDevIns, VERR_PDM_MISSING_INTERFACE_BELOW, RT_SRC_POS, N_("NVRAM storage driver is missing VFS interface below"));
    15741600    }
    15751601    else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
  • trunk/src/VBox/Devices/EFI/FlashCore.cpp

    r82968 r91329  
    470470
    471471/**
     472 * Loads the flash content using the PDM VFS interface.
     473 *
     474 * @returns VBox status code.
     475 * @param   pThis               The flash device core instance.
     476 * @param   pDevIns             The owning device instance.
     477 * @param   pDrvVfs             Pointer to the VFS interface.
     478 * @param   pszNamespace        The namespace to load from.
     479 * @param   pszPath             The path to the flash content to load.
     480 */
     481DECLHIDDEN(int) flashR3LoadFromVfs(PFLASHCORE pThis, PPDMDEVINS pDevIns, PPDMIVFSCONNECTOR pDrvVfs,
     482                                   const char *pszNamespace, const char *pszPath)
     483{
     484    uint64_t cbFlash = 0;
     485    int rc = pDrvVfs->pfnQuerySize(pDrvVfs, pszNamespace, pszPath, &cbFlash);
     486    if (RT_SUCCESS(rc))
     487    {
     488        if (cbFlash == pThis->cbFlashSize)
     489            rc = pDrvVfs->pfnReadAll(pDrvVfs, pszNamespace, pszPath, pThis->pbFlash, pThis->cbFlashSize);
     490        else
     491            return PDMDEV_SET_ERROR(pDevIns, VERR_MISMATCH, N_("Size of the flash device and the content to load doesn't match"));
     492    }
     493
     494    return rc;
     495}
     496
     497/**
    472498 * Saves the flash content to the given file.
    473499 *
     
    507533    memcpy(pvBuf, pThis->pbFlash, RT_MIN(cbBuf, pThis->cbFlashSize));
    508534    return VINF_SUCCESS;
     535}
     536
     537/**
     538 * Saves the flash content using the given PDM VFS interface.
     539 *
     540 * @returns VBox status code.
     541 * @param   pThis               The flash device core instance.
     542 * @param   pDevIns             The owning device instance.
     543 * @param   pDrvVfs             Pointer to the VFS interface.
     544 * @param   pszNamespace        The namespace to store to.
     545 * @param   pszPath             The path to store the flash content under.
     546 */
     547DECLHIDDEN(int) flashR3SaveToVfs(PFLASHCORE pThis, PPDMDEVINS pDevIns, PPDMIVFSCONNECTOR pDrvVfs,
     548                                 const char *pszNamespace, const char *pszPath)
     549{
     550    RT_NOREF(pDevIns);
     551    return pDrvVfs->pfnWriteAll(pDrvVfs, pszNamespace, pszPath, pThis->pbFlash, pThis->cbFlashSize);
    509552}
    510553
  • trunk/src/VBox/Devices/EFI/FlashCore.h

    r82968 r91329  
    3232*********************************************************************************************************************************/
    3333#include <VBox/vmm/pdmdev.h>
     34#include <VBox/vmm/pdmifs.h>
    3435#include <VBox/log.h>
    3536#include <VBox/err.h>
     
    115116DECLHIDDEN(int) flashR3LoadFromFile(PFLASHCORE pThis, PPDMDEVINS pDevIns, const char *pszFilename);
    116117DECLHIDDEN(int) flashR3LoadFromBuf(PFLASHCORE pThis, void const *pvBuf, size_t cbBuf);
     118DECLHIDDEN(int) flashR3LoadFromVfs(PFLASHCORE pThis, PPDMDEVINS pDevIns, PPDMIVFSCONNECTOR pDrvVfs,
     119                                   const char *pszNamespace, const char *pszPath);
    117120DECLHIDDEN(int) flashR3SaveToFile(PFLASHCORE pThis, PPDMDEVINS pDevIns, const char *pszFilename);
    118121DECLHIDDEN(int) flashR3SaveToBuf(PFLASHCORE pThis, void *pvBuf, size_t cbBuf);
     122DECLHIDDEN(int) flashR3SaveToVfs(PFLASHCORE pThis, PPDMDEVINS pDevIns, PPDMIVFSCONNECTOR pDrvVfs,
     123                                 const char *pszNamespace, const char *pszPath);
    119124DECLHIDDEN(void) flashR3Reset(PFLASHCORE pThis);
    120125DECLHIDDEN(int) flashR3SaveExec(PFLASHCORE pThis, PPDMDEVINS pDevIns, PSSMHANDLE pSSM);
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