Changeset 99404 in vbox for trunk/src/VBox/Devices/EFI/FirmwareNew/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c
- Timestamp:
- Apr 14, 2023 3:17:44 PM (21 months ago)
- Location:
- trunk/src/VBox/Devices/EFI/FirmwareNew
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/FirmwareNew
-
Property svn:mergeinfo
changed from (toggle deleted branches)
to (toggle deleted branches)/vendor/edk2/current 103735-103757,103769-103776,129194-145445 /vendor/edk2/current 103735-103757,103769-103776,129194-156846
-
Property svn:mergeinfo
changed from (toggle deleted branches)
-
trunk/src/VBox/Devices/EFI/FirmwareNew/ShellPkg/Library/UefiShellDebug1CommandsLib/LoadPciRom.c
r85718 r99404 40 40 EFI_STATUS 41 41 LoadEfiDriversFromRomImage ( 42 VOID 43 UINTN 44 CONST CHAR16 42 VOID *RomBar, 43 UINTN RomSize, 44 CONST CHAR16 *FileName 45 45 ); 46 46 47 STATIC CONST SHELL_PARAM_ITEM ParamList[] = {48 { L"-nc", TypeFlag},49 { NULL, TypeMax}50 47 STATIC CONST SHELL_PARAM_ITEM ParamList[] = { 48 { L"-nc", TypeFlag }, 49 { NULL, TypeMax } 50 }; 51 51 52 52 /** … … 63 63 ) 64 64 { 65 EFI_SHELL_FILE_INFO *FileList; 66 UINTN SourceSize; 67 UINT8 *File1Buffer; 68 EFI_STATUS Status; 69 LIST_ENTRY *Package; 70 CHAR16 *ProblemParam; 71 SHELL_STATUS ShellStatus; 72 BOOLEAN Connect; 73 CONST CHAR16 *Param; 74 UINTN ParamCount; 75 EFI_SHELL_FILE_INFO *Node; 65 EFI_SHELL_FILE_INFO *FileList; 66 UINTN SourceSize; 67 UINT8 *File1Buffer; 68 EFI_STATUS Status; 69 LIST_ENTRY *Package; 70 CHAR16 *ProblemParam; 71 SHELL_STATUS ShellStatus; 72 BOOLEAN Connect; 73 CONST CHAR16 *Param; 74 UINTN ParamCount; 75 EFI_SHELL_FILE_INFO *Node; 76 76 77 // 77 78 // Local variable initializations … … 81 82 FileList = NULL; 82 83 83 84 84 // 85 85 // verify number of arguments 86 86 // 87 87 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); 88 if (EFI_ERROR (Status)) {89 if ( Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {90 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"loadpcirom", ProblemParam);91 FreePool (ProblemParam);88 if (EFI_ERROR (Status)) { 89 if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { 90 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"loadpcirom", ProblemParam); 91 FreePool (ProblemParam); 92 92 ShellStatus = SHELL_INVALID_PARAMETER; 93 93 } else { 94 ASSERT (FALSE);94 ASSERT (FALSE); 95 95 } 96 96 } else { 97 if (ShellCommandLineGetCount (Package) < 2) {98 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"loadpcirom");97 if (ShellCommandLineGetCount (Package) < 2) { 98 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"loadpcirom"); 99 99 ShellStatus = SHELL_INVALID_PARAMETER; 100 100 } else { 101 if (ShellCommandLineGetFlag (Package, L"-nc")) {101 if (ShellCommandLineGetFlag (Package, L"-nc")) { 102 102 Connect = FALSE; 103 103 } else { … … 109 109 // if parameter is a directory then add all the files below it to the list 110 110 // 111 for ( ParamCount = 1, Param = ShellCommandLineGetRawValue(Package, ParamCount) 112 ; Param != NULL 113 ; ParamCount++, Param = ShellCommandLineGetRawValue(Package, ParamCount) 114 ){ 115 Status = ShellOpenFileMetaArg((CHAR16*)Param, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList); 116 if (EFI_ERROR(Status)) { 117 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"loadpcirom", Param); 111 for ( ParamCount = 1, Param = ShellCommandLineGetRawValue (Package, ParamCount) 112 ; Param != NULL 113 ; ParamCount++, Param = ShellCommandLineGetRawValue (Package, ParamCount) 114 ) 115 { 116 Status = ShellOpenFileMetaArg ((CHAR16 *)Param, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList); 117 if (EFI_ERROR (Status)) { 118 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"loadpcirom", Param); 118 119 ShellStatus = SHELL_ACCESS_DENIED; 119 120 break; 120 121 } 121 122 } 122 if (ShellStatus == SHELL_SUCCESS && FileList != NULL) { 123 124 if ((ShellStatus == SHELL_SUCCESS) && (FileList != NULL)) { 123 125 // 124 126 // loop through the list and make sure we are not aborting... 125 127 // 126 for ( Node = (EFI_SHELL_FILE_INFO*)GetFirstNode(&FileList->Link) 127 ; !IsNull(&FileList->Link, &Node->Link) && !ShellGetExecutionBreakFlag() 128 ; Node = (EFI_SHELL_FILE_INFO*)GetNextNode(&FileList->Link, &Node->Link) 129 ){ 130 if (EFI_ERROR(Node->Status)){ 131 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"loadpcirom", Node->FullName); 128 for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode (&FileList->Link) 129 ; !IsNull (&FileList->Link, &Node->Link) && !ShellGetExecutionBreakFlag () 130 ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode (&FileList->Link, &Node->Link) 131 ) 132 { 133 if (EFI_ERROR (Node->Status)) { 134 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"loadpcirom", Node->FullName); 132 135 ShellStatus = SHELL_INVALID_PARAMETER; 133 136 continue; 134 137 } 135 if (FileHandleIsDirectory(Node->Handle) == EFI_SUCCESS) { 136 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"loadpcirom", Node->FullName); 138 139 if (FileHandleIsDirectory (Node->Handle) == EFI_SUCCESS) { 140 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"loadpcirom", Node->FullName); 137 141 ShellStatus = SHELL_INVALID_PARAMETER; 138 142 continue; 139 143 } 140 SourceSize = (UINTN) Node->Info->FileSize; 144 145 SourceSize = (UINTN)Node->Info->FileSize; 141 146 File1Buffer = AllocateZeroPool (SourceSize); 142 147 if (File1Buffer == NULL) { … … 145 150 continue; 146 151 } 147 Status = gEfiShellProtocol->ReadFile(Node->Handle, &SourceSize, File1Buffer); 148 if (EFI_ERROR(Status)) { 149 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_READ_FAIL), gShellDebug1HiiHandle, L"loadpcirom", Node->FullName); 152 153 Status = gEfiShellProtocol->ReadFile (Node->Handle, &SourceSize, File1Buffer); 154 if (EFI_ERROR (Status)) { 155 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_FILE_READ_FAIL), gShellDebug1HiiHandle, L"loadpcirom", Node->FullName); 150 156 ShellStatus = SHELL_INVALID_PARAMETER; 151 157 } else { 152 158 Status = LoadEfiDriversFromRomImage ( 153 File1Buffer, 154 SourceSize, 155 Node->FullName 156 ); 157 158 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LOAD_PCI_ROM_RES), gShellDebug1HiiHandle, Node->FullName, Status); 159 } 160 FreePool(File1Buffer); 159 File1Buffer, 160 SourceSize, 161 Node->FullName 162 ); 163 164 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_LOAD_PCI_ROM_RES), gShellDebug1HiiHandle, Node->FullName, Status); 165 } 166 167 FreePool (File1Buffer); 161 168 } 162 169 } else if (ShellStatus == SHELL_SUCCESS) { 163 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_SPEC), gShellDebug1HiiHandle, "loadpcirom");170 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_SPEC), gShellDebug1HiiHandle, "loadpcirom"); 164 171 ShellStatus = SHELL_NOT_FOUND; 165 172 } 166 if (FileList != NULL && !IsListEmpty(&FileList->Link)) { 167 Status = ShellCloseFileMetaArg(&FileList); 168 } 173 174 if ((FileList != NULL) && !IsListEmpty (&FileList->Link)) { 175 Status = ShellCloseFileMetaArg (&FileList); 176 } 177 169 178 FileList = NULL; 170 179 … … 193 202 EFI_STATUS 194 203 LoadEfiDriversFromRomImage ( 195 VOID 196 UINTN 197 CONST CHAR16 204 VOID *RomBar, 205 UINTN RomSize, 206 CONST CHAR16 *FileName 198 207 ) 199 208 … … 220 229 UINT32 InitializationSize; 221 230 222 ImageIndex 223 ReturnStatus 224 RomBarOffset = (UINTN)RomBar;231 ImageIndex = 0; 232 ReturnStatus = EFI_NOT_FOUND; 233 RomBarOffset = (UINTN)RomBar; 225 234 226 235 do { 227 228 EfiRomHeader = (EFI_PCI_EXPANSION_ROM_HEADER *) (UINTN) RomBarOffset; 236 EfiRomHeader = (EFI_PCI_EXPANSION_ROM_HEADER *)(UINTN)RomBarOffset; 229 237 230 238 if (EfiRomHeader->Signature != PCI_EXPANSION_ROM_HEADER_SIGNATURE) { 231 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_LOADPCIROM_CORRUPT), gShellDebug1HiiHandle, L"loadpcirom", FileName, ImageIndex);232 // PrintToken (STRING_TOKEN (STR_LOADPCIROM_IMAGE_CORRUPT), HiiHandle, ImageIndex);239 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_LOADPCIROM_CORRUPT), gShellDebug1HiiHandle, L"loadpcirom", FileName, ImageIndex); 240 // PrintToken (STRING_TOKEN (STR_LOADPCIROM_IMAGE_CORRUPT), HiiHandle, ImageIndex); 233 241 return ReturnStatus; 234 242 } … … 238 246 // The PCI Data Structure must be DWORD aligned. 239 247 // 240 if (EfiRomHeader->PcirOffset == 0 || 241 (EfiRomHeader->PcirOffset & 3) != 0 || 242 RomBarOffset - (UINTN)RomBar + EfiRomHeader->PcirOffset + sizeof (PCI_DATA_STRUCTURE) > RomSize) { 248 if ((EfiRomHeader->PcirOffset == 0) || 249 ((EfiRomHeader->PcirOffset & 3) != 0) || 250 (RomBarOffset - (UINTN)RomBar + EfiRomHeader->PcirOffset + sizeof (PCI_DATA_STRUCTURE) > RomSize)) 251 { 243 252 break; 244 253 } 245 254 246 Pcir = (PCI_DATA_STRUCTURE *) (UINTN)(RomBarOffset + EfiRomHeader->PcirOffset);255 Pcir = (PCI_DATA_STRUCTURE *)(UINTN)(RomBarOffset + EfiRomHeader->PcirOffset); 247 256 // 248 257 // If a valid signature is not present in the PCI Data Structure, no further images can be located. … … 251 260 break; 252 261 } 262 253 263 ImageSize = Pcir->ImageLength * 512; 254 264 if (RomBarOffset - (UINTN)RomBar + ImageSize > RomSize) { … … 259 269 (EfiRomHeader->EfiSignature == EFI_PCI_EXPANSION_ROM_HEADER_EFISIGNATURE) && 260 270 ((EfiRomHeader->EfiSubsystem == EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER) || 261 (EfiRomHeader->EfiSubsystem == EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER))) { 262 263 ImageOffset = EfiRomHeader->EfiImageHeaderOffset; 264 InitializationSize = EfiRomHeader->InitializationSize * 512; 265 266 if (InitializationSize <= ImageSize && ImageOffset < InitializationSize) { 267 268 ImageBuffer = (VOID *) (UINTN) (RomBarOffset + ImageOffset); 271 (EfiRomHeader->EfiSubsystem == EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER))) 272 { 273 ImageOffset = EfiRomHeader->EfiImageHeaderOffset; 274 InitializationSize = EfiRomHeader->InitializationSize * 512; 275 276 if ((InitializationSize <= ImageSize) && (ImageOffset < InitializationSize)) { 277 ImageBuffer = (VOID *)(UINTN)(RomBarOffset + ImageOffset); 269 278 ImageLength = InitializationSize - ImageOffset; 270 279 DecompressedImageBuffer = NULL; … … 279 288 280 289 if (EfiRomHeader->CompressionType == EFI_PCI_EXPANSION_ROM_HEADER_COMPRESSED) { 281 Status = gBS->LocateProtocol (&gEfiDecompressProtocolGuid, NULL, (VOID **)&Decompress);282 ASSERT_EFI_ERROR (Status);290 Status = gBS->LocateProtocol (&gEfiDecompressProtocolGuid, NULL, (VOID **)&Decompress); 291 ASSERT_EFI_ERROR (Status); 283 292 if (EFI_ERROR (Status)) { 284 293 SkipImage = TRUE; 285 294 } else { 286 295 SkipImage = TRUE; 287 Status = Decompress->GetInfo (288 Decompress,289 ImageBuffer,290 ImageLength,291 &DestinationSize,292 &ScratchSize293 );296 Status = Decompress->GetInfo ( 297 Decompress, 298 ImageBuffer, 299 ImageLength, 300 &DestinationSize, 301 &ScratchSize 302 ); 294 303 if (!EFI_ERROR (Status)) { 295 304 DecompressedImageBuffer = AllocateZeroPool (DestinationSize); … … 298 307 if (Scratch != NULL) { 299 308 Status = Decompress->Decompress ( 300 Decompress,301 ImageBuffer,302 ImageLength,303 DecompressedImageBuffer,304 DestinationSize,305 Scratch,306 ScratchSize307 );309 Decompress, 310 ImageBuffer, 311 ImageLength, 312 DecompressedImageBuffer, 313 DestinationSize, 314 Scratch, 315 ScratchSize 316 ); 308 317 if (!EFI_ERROR (Status)) { 309 318 ImageBuffer = DecompressedImageBuffer; … … 327 336 328 337 Status = gBS->LoadImage ( 329 TRUE,330 gImageHandle,331 FilePath,332 ImageBuffer,333 ImageLength,334 &ImageHandle335 );338 TRUE, 339 gImageHandle, 340 FilePath, 341 ImageBuffer, 342 ImageLength, 343 &ImageHandle 344 ); 336 345 if (EFI_ERROR (Status)) { 337 346 // … … 344 353 gBS->UnloadImage (ImageHandle); 345 354 } 346 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LOADPCIROM_LOAD_FAIL), gShellDebug1HiiHandle, L"loadpcirom", FileName, ImageIndex); 347 // PrintToken (STRING_TOKEN (STR_LOADPCIROM_LOAD_IMAGE_ERROR), HiiHandle, ImageIndex, Status); 355 356 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_LOADPCIROM_LOAD_FAIL), gShellDebug1HiiHandle, L"loadpcirom", FileName, ImageIndex); 357 // PrintToken (STRING_TOKEN (STR_LOADPCIROM_LOAD_IMAGE_ERROR), HiiHandle, ImageIndex, Status); 348 358 } else { 349 359 Status = gBS->StartImage (ImageHandle, NULL, NULL); 350 360 if (EFI_ERROR (Status)) { 351 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_LOADPCIROM_START_FAIL), gShellDebug1HiiHandle, L"loadpcirom", FileName, ImageIndex);352 // PrintToken (STRING_TOKEN (STR_LOADPCIROM_START_IMAGE), HiiHandle, ImageIndex, Status);361 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_LOADPCIROM_START_FAIL), gShellDebug1HiiHandle, L"loadpcirom", FileName, ImageIndex); 362 // PrintToken (STRING_TOKEN (STR_LOADPCIROM_START_IMAGE), HiiHandle, ImageIndex, Status); 353 363 } else { 354 364 ReturnStatus = Status; … … 360 370 FreePool (DecompressedImageBuffer); 361 371 } 362 363 372 } 364 373 } … … 366 375 RomBarOffset = RomBarOffset + ImageSize; 367 376 ImageIndex++; 368 } while (((Pcir->Indicator & 0x80) == 0x00) && ((RomBarOffset - (UINTN) 377 } while (((Pcir->Indicator & 0x80) == 0x00) && ((RomBarOffset - (UINTN)RomBar) < RomSize)); 369 378 370 379 return ReturnStatus; … … 403 412 break; 404 413 } 414 405 415 gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE); 406 416 } … … 409 419 FreePool (HandleBuffer); 410 420 } 421 411 422 return Status; 412 423 }
Note:
See TracChangeset
for help on using the changeset viewer.