Changeset 91329 in vbox for trunk/src/VBox/Devices/EFI
- Timestamp:
- Sep 22, 2021 3:16:12 PM (3 years ago)
- Location:
- trunk/src/VBox/Devices/EFI
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/DevEFI.cpp
r91324 r91329 209 209 /** The NVRAM driver base interface. */ 210 210 PPDMIBASE pDrvBase; 211 /** The VFS interface of the driver below for NVRAM state loading and storing. */ 212 PPDMIVFSCONNECTOR pDrvVfs; 211 213 } Lun0; 212 214 } DEVEFIR3; … … 1009 1011 static DECLCALLBACK(void) efiPowerOff(PPDMDEVINS pDevIns) 1010 1012 { 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 } 1013 1029 } 1014 1030 … … 1028 1044 PDEVEFI pThis = PDMDEVINS_2_DATA(pDevIns, PDEVEFI); 1029 1045 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 }1037 1046 1038 1047 flashR3Destruct(&pThis->Flash, pDevIns); … … 1156 1165 return rc; 1157 1166 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 } 1161 1179 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 } 1165 1189 1166 1190 pThisCC->GCLoadAddress = pThisCC->GCPhysNvram + pThisCC->cbNvram; … … 1571 1595 if (RT_SUCCESS(rc)) 1572 1596 { 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")); 1574 1600 } 1575 1601 else if (rc == VERR_PDM_NO_ATTACHED_DRIVER) -
trunk/src/VBox/Devices/EFI/FlashCore.cpp
r82968 r91329 470 470 471 471 /** 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 */ 481 DECLHIDDEN(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 /** 472 498 * Saves the flash content to the given file. 473 499 * … … 507 533 memcpy(pvBuf, pThis->pbFlash, RT_MIN(cbBuf, pThis->cbFlashSize)); 508 534 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 */ 547 DECLHIDDEN(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); 509 552 } 510 553 -
trunk/src/VBox/Devices/EFI/FlashCore.h
r82968 r91329 32 32 *********************************************************************************************************************************/ 33 33 #include <VBox/vmm/pdmdev.h> 34 #include <VBox/vmm/pdmifs.h> 34 35 #include <VBox/log.h> 35 36 #include <VBox/err.h> … … 115 116 DECLHIDDEN(int) flashR3LoadFromFile(PFLASHCORE pThis, PPDMDEVINS pDevIns, const char *pszFilename); 116 117 DECLHIDDEN(int) flashR3LoadFromBuf(PFLASHCORE pThis, void const *pvBuf, size_t cbBuf); 118 DECLHIDDEN(int) flashR3LoadFromVfs(PFLASHCORE pThis, PPDMDEVINS pDevIns, PPDMIVFSCONNECTOR pDrvVfs, 119 const char *pszNamespace, const char *pszPath); 117 120 DECLHIDDEN(int) flashR3SaveToFile(PFLASHCORE pThis, PPDMDEVINS pDevIns, const char *pszFilename); 118 121 DECLHIDDEN(int) flashR3SaveToBuf(PFLASHCORE pThis, void *pvBuf, size_t cbBuf); 122 DECLHIDDEN(int) flashR3SaveToVfs(PFLASHCORE pThis, PPDMDEVINS pDevIns, PPDMIVFSCONNECTOR pDrvVfs, 123 const char *pszNamespace, const char *pszPath); 119 124 DECLHIDDEN(void) flashR3Reset(PFLASHCORE pThis); 120 125 DECLHIDDEN(int) flashR3SaveExec(PFLASHCORE pThis, PPDMDEVINS pDevIns, PSSMHANDLE pSSM);
Note:
See TracChangeset
for help on using the changeset viewer.