X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=EdkNt32Pkg%2FDxe%2FPlatformBds%2FGeneric%2FBootMaint%2FBootOption.c;h=57b5239530c76876ff8ff8d08aafb88ee93e3ebc;hp=35187bf58f5d4dada71b5936b56279518a02a5b2;hb=4224ac208726ee643afc2d3712b6bf4b86184fb4;hpb=878ddf1fc3540a715f63594ed22b6929e881afb4;ds=inline diff --git a/EdkNt32Pkg/Dxe/PlatformBds/Generic/BootMaint/BootOption.c b/EdkNt32Pkg/Dxe/PlatformBds/Generic/BootMaint/BootOption.c index 35187bf58f..57b5239530 100644 --- a/EdkNt32Pkg/Dxe/PlatformBds/Generic/BootMaint/BootOption.c +++ b/EdkNt32Pkg/Dxe/PlatformBds/Generic/BootMaint/BootOption.c @@ -1055,6 +1055,27 @@ Returns: return MenuCount; } +CHAR16 * +BdsStrCpy ( + OUT CHAR16 *Destination, + IN CONST CHAR16 *Source + ) +{ + CHAR16 *ReturnValue; + + // + // Destination cannot be NULL + // + ASSERT (Destination != NULL); + + ReturnValue = Destination; + while (*Source) { + *(Destination++) = *(Source++); + } + *Destination = 0; + return ReturnValue; +} + CHAR16 * BOpt_AppendFileName ( IN CHAR16 *Str1, @@ -1102,13 +1123,13 @@ Returns: // DO NOT convert the .. if it is at the end of the string. This will // break the .. behavior in changing directories. // - StrCpy (LastSlash, Ptr + 3); + BdsStrCpy (LastSlash, Ptr + 3); Ptr = LastSlash; } else if (*Ptr == '\\' && *(Ptr + 1) == '.' && *(Ptr + 2) == '\\') { // // Convert a \.\ to a \ // - StrCpy (Ptr, Ptr + 2); + BdsStrCpy (Ptr, Ptr + 2); Ptr = LastSlash; } else if (*Ptr == '\\') { LastSlash = Ptr; @@ -1165,6 +1186,30 @@ Returns: return FALSE; } + +RETURN_STATUS +EFIAPI +IsEfiAppReadFromFile ( + IN VOID *FileHandle, + IN UINTN FileOffset, + IN OUT UINTN *ReadSize, + OUT VOID *Buffer + ) +{ + EFI_STATUS Status; + EFI_FILE_HANDLE File; + + File = (EFI_FILE_HANDLE)FileHandle; + Status = File->SetPosition (File, FileOffset); + if (EFI_ERROR (Status)) { + return Status; + } + + return File->Read (File, ReadSize, Buffer); +} + + + BOOLEAN BOpt_IsEfiApp ( IN EFI_FILE_HANDLE Dir, @@ -1185,60 +1230,32 @@ Returns: --*/ { - UINTN BufferSize; - EFI_IMAGE_DOS_HEADER DosHdr; - EFI_IMAGE_NT_HEADERS PeHdr; - EFI_IMAGE_OPTIONAL_HEADER32 *PeOpt32; - EFI_IMAGE_OPTIONAL_HEADER64 *PeOpt64; - UINT16 Subsystem; - EFI_FILE_HANDLE File; - EFI_STATUS Status; + EFI_STATUS Status; + PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; + EFI_FILE_HANDLE File; Status = Dir->Open (Dir, &File, FileName, EFI_FILE_MODE_READ, 0); - if (EFI_ERROR (Status)) { return FALSE; } - BufferSize = sizeof (EFI_IMAGE_DOS_HEADER); - File->Read (File, &BufferSize, &DosHdr); - if (DosHdr.e_magic != EFI_IMAGE_DOS_SIGNATURE) { - File->Close (File); - return FALSE; - } + ZeroMem (&ImageContext, sizeof (ImageContext)); + ImageContext.Handle = (VOID *)File; + ImageContext.ImageRead = IsEfiAppReadFromFile; - File->SetPosition (File, DosHdr.e_lfanew); - BufferSize = sizeof (EFI_IMAGE_NT_HEADERS); - File->Read (File, &BufferSize, &PeHdr); - if (PeHdr.Signature != EFI_IMAGE_NT_SIGNATURE) { - File->Close (File); - return FALSE; - } - // - // Determine PE type and read subsytem - // BugBug : We should be using EFI_IMAGE_MACHINE_TYPE_SUPPORTED (machine) - // macro to detect the machine type. - // We should not be using EFI_IMAGE_OPTIONAL_HEADER32 and - // EFI_IMAGE_OPTIONAL_HEADER64 - // - if (PeHdr.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { - PeOpt32 = (EFI_IMAGE_OPTIONAL_HEADER32 *) &(PeHdr.OptionalHeader); - Subsystem = PeOpt32->Subsystem; - } else if (PeHdr.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) { - PeOpt64 = (EFI_IMAGE_OPTIONAL_HEADER64 *) &(PeHdr.OptionalHeader); - Subsystem = PeOpt64->Subsystem; - } else { + Status = PeCoffLoaderGetImageInfo (&ImageContext); + File->Close (File); + if (EFI_ERROR (Status)) { return FALSE; } - if (Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) { - File->Close (File); + if (ImageContext.ImageType == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) { return TRUE; } else { - File->Close (File); return FALSE; } -} + } + EFI_STATUS BOpt_FindDrivers ( @@ -1362,6 +1379,9 @@ Returns: UINTN Index; UINTN Index2; BOOLEAN Found; + CHAR16 StrTemp[100]; + UINT16 *OptionBuffer; + UINTN OptionSize; BootOrderListSize = 0; BootOrderList = NULL; @@ -1388,6 +1408,14 @@ Returns: } if (Found) { + UnicodeSPrint (StrTemp, 100, L"Boot%04x", Index); + DEBUG((EFI_D_ERROR,"INdex= %s\n", StrTemp)); + OptionBuffer = BdsLibGetVariableAndSize ( + StrTemp, + &gEfiGlobalVariableGuid, + &OptionSize + ); + if (NULL == OptionBuffer) break; } }