/** @file\r
Main file for LoadPciRom shell Debug1 function.\r
\r
- Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.<BR>\r
+ (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
+ Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);\r
if (EFI_ERROR(Status)) {\r
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, ProblemParam);\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"loadpcirom", ProblemParam); \r
FreePool(ProblemParam);\r
ShellStatus = SHELL_INVALID_PARAMETER;\r
} else {\r
}\r
} else {\r
if (ShellCommandLineGetCount(Package) < 2) {\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"loadpcirom"); \r
ShellStatus = SHELL_INVALID_PARAMETER;\r
} else {\r
if (ShellCommandLineGetFlag(Package, L"-nc")) {\r
){\r
Status = ShellOpenFileMetaArg((CHAR16*)Param, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);\r
if (EFI_ERROR(Status)) {\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, Param, Status);\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"loadpcirom", Param); \r
ShellStatus = SHELL_ACCESS_DENIED;\r
break;\r
}\r
; Node = (EFI_SHELL_FILE_INFO*)GetNextNode(&FileList->Link, &Node->Link)\r
){\r
if (EFI_ERROR(Node->Status)){\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, Node->FullName);\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"loadpcirom", Node->FullName); \r
ShellStatus = SHELL_INVALID_PARAMETER;\r
continue;\r
}\r
if (FileHandleIsDirectory(Node->Handle) == EFI_SUCCESS) {\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, Node->FullName);\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"loadpcirom", Node->FullName); \r
ShellStatus = SHELL_INVALID_PARAMETER;\r
continue;\r
}\r
ASSERT(File1Buffer != NULL);\r
Status = gEfiShellProtocol->ReadFile(Node->Handle, &SourceSize, File1Buffer);\r
if (EFI_ERROR(Status)) {\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_READ_FAIL), gShellDebug1HiiHandle, Node->FullName);\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_READ_FAIL), gShellDebug1HiiHandle, L"loadpcirom", Node->FullName); \r
ShellStatus = SHELL_INVALID_PARAMETER;\r
} else {\r
Status = LoadEfiDriversFromRomImage (\r
FreePool(File1Buffer);\r
}\r
} else if (ShellStatus == SHELL_SUCCESS) {\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_SPEC), gShellDebug1HiiHandle);\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_SPEC), gShellDebug1HiiHandle, "loadpcirom"); \r
ShellStatus = SHELL_NOT_FOUND;\r
}\r
if (FileList != NULL && !IsListEmpty(&FileList->Link)) {\r
VOID *DecompressedImageBuffer;\r
UINT32 ImageLength;\r
EFI_DECOMPRESS_PROTOCOL *Decompress;\r
+ UINT32 InitializationSize;\r
\r
ImageIndex = 0;\r
ReturnStatus = EFI_NOT_FOUND;\r
\r
EfiRomHeader = (EFI_PCI_EXPANSION_ROM_HEADER *) (UINTN) RomBarOffset;\r
\r
- if (EfiRomHeader->Signature != 0xaa55) {\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LOADPCIROM_CORRUPT), gShellDebug1HiiHandle, FileName, ImageIndex);\r
+ if (EfiRomHeader->Signature != PCI_EXPANSION_ROM_HEADER_SIGNATURE) {\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LOADPCIROM_CORRUPT), gShellDebug1HiiHandle, L"loadpcirom", FileName, ImageIndex); \r
// PrintToken (STRING_TOKEN (STR_LOADPCIROM_IMAGE_CORRUPT), HiiHandle, ImageIndex);\r
return ReturnStatus;\r
}\r
\r
+ //\r
+ // If the pointer to the PCI Data Structure is invalid, no further images can be located. \r
+ // The PCI Data Structure must be DWORD aligned. \r
+ //\r
+ if (EfiRomHeader->PcirOffset == 0 ||\r
+ (EfiRomHeader->PcirOffset & 3) != 0 ||\r
+ RomBarOffset - (UINTN)RomBar + EfiRomHeader->PcirOffset + sizeof (PCI_DATA_STRUCTURE) > RomSize) {\r
+ break;\r
+ }\r
+\r
Pcir = (PCI_DATA_STRUCTURE *) (UINTN) (RomBarOffset + EfiRomHeader->PcirOffset);\r
+ //\r
+ // If a valid signature is not present in the PCI Data Structure, no further images can be located.\r
+ //\r
+ if (Pcir->Signature != PCI_DATA_STRUCTURE_SIGNATURE) {\r
+ break;\r
+ }\r
ImageSize = Pcir->ImageLength * 512;\r
+ if (RomBarOffset - (UINTN)RomBar + ImageSize > RomSize) {\r
+ break;\r
+ }\r
\r
if ((Pcir->CodeType == PCI_CODE_TYPE_EFI_IMAGE) &&\r
- (EfiRomHeader->EfiSignature == EFI_PCI_EXPANSION_ROM_HEADER_EFISIGNATURE)\r
- ) {\r
+ (EfiRomHeader->EfiSignature == EFI_PCI_EXPANSION_ROM_HEADER_EFISIGNATURE) &&\r
+ ((EfiRomHeader->EfiSubsystem == EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER) ||\r
+ (EfiRomHeader->EfiSubsystem == EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER))) {\r
+\r
+ ImageOffset = EfiRomHeader->EfiImageHeaderOffset;\r
+ InitializationSize = EfiRomHeader->InitializationSize * 512;\r
\r
- if ((EfiRomHeader->EfiSubsystem == EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER) ||\r
- (EfiRomHeader->EfiSubsystem == EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER)\r
- ) {\r
- ImageOffset = EfiRomHeader->EfiImageHeaderOffset;\r
- ImageSize = EfiRomHeader->InitializationSize * 512;\r
+ if (InitializationSize <= ImageSize && ImageOffset < InitializationSize) {\r
\r
ImageBuffer = (VOID *) (UINTN) (RomBarOffset + ImageOffset);\r
- ImageLength = ImageSize - ImageOffset;\r
+ ImageLength = InitializationSize - ImageOffset;\r
DecompressedImageBuffer = NULL;\r
\r
//\r
&ImageHandle\r
);\r
if (EFI_ERROR (Status)) {\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LOADPCIROM_LOAD_FAIL), gShellDebug1HiiHandle, FileName, ImageIndex, Status);\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LOADPCIROM_LOAD_FAIL), gShellDebug1HiiHandle, L"loadpcirom", FileName, ImageIndex); \r
// PrintToken (STRING_TOKEN (STR_LOADPCIROM_LOAD_IMAGE_ERROR), HiiHandle, ImageIndex, Status);\r
} else {\r
Status = gBS->StartImage (ImageHandle, NULL, NULL);\r
if (EFI_ERROR (Status)) {\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LOADPCIROM_START_FAIL), gShellDebug1HiiHandle, FileName, ImageIndex, Status);\r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LOADPCIROM_START_FAIL), gShellDebug1HiiHandle, L"loadpcirom", FileName, ImageIndex); \r
// PrintToken (STRING_TOKEN (STR_LOADPCIROM_START_IMAGE), HiiHandle, ImageIndex, Status);\r
} else {\r
ReturnStatus = Status;\r