]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/BdsLib/BdsFilePathFv.c
Sync up ArmPkg with patch from mailing list. Changed name of BdsLib.h to BdsUnixLib...
[mirror_edk2.git] / ArmPkg / Library / BdsLib / BdsFilePathFv.c
CommitLineData
1bfda055 1/** @file
2*
3* Copyright (c) 2011, ARM Limited. All rights reserved.
4*
5* This program and the accompanying materials
6* are licensed and made available under the terms and conditions of the BSD License
7* which accompanies this distribution. The full text of the license may be found at
8* http://opensource.org/licenses/bsd-license.php
9*
10* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12*
13**/
14
15#include "BdsInternal.h"
16
17EFI_STATUS BdsLoadFileFromFirmwareVolume(
18 IN EFI_HANDLE FvHandle,
19 IN CHAR16 *FilePath,
20 IN EFI_FV_FILETYPE FileTypeFilter,
21 OUT BDS_FILE *File
22) {
23 EFI_FIRMWARE_VOLUME2_PROTOCOL *FvProtocol;
24 VOID *Key;
25 EFI_STATUS Status, FileStatus;
26 EFI_GUID NameGuid;
27 EFI_FV_FILETYPE FileType;
28 EFI_FV_FILE_ATTRIBUTES Attributes;
29 UINTN Size;
30 UINTN UiStringLen;
31 CHAR16 *UiSection;
32 UINT32 Authentication;
33
34 if (File == NULL) {
35 return EFI_INVALID_PARAMETER;
36 }
37
38 Status = gBS->HandleProtocol(FvHandle,&gEfiFirmwareVolume2ProtocolGuid, (VOID **)&FvProtocol);
39 if (EFI_ERROR(Status)) {
40 return Status;
41 }
42
43 // Length of FilePath
44 UiStringLen = StrLen (FilePath);
45
46 // Allocate Key
47 Key = AllocatePool (FvProtocol->KeySize);
48 ASSERT (Key != NULL);
49 ZeroMem (Key, FvProtocol->KeySize);
50
51 do {
52 // Search in all files
53 FileType = FileTypeFilter;
54
55 Status = FvProtocol->GetNextFile (FvProtocol, Key, &FileType, &NameGuid, &Attributes, &Size);
56 if (!EFI_ERROR (Status)) {
57 UiSection = NULL;
58 FileStatus = FvProtocol->ReadSection (
59 FvProtocol,
60 &NameGuid,
61 EFI_SECTION_USER_INTERFACE,
62 0,
63 (VOID **)&UiSection,
64 &Size,
65 &Authentication
66 );
67 if (!EFI_ERROR (FileStatus)) {
68 if (StrnCmp (FilePath, UiSection, UiStringLen) == 0) {
69
70 //
71 // We found a UiString match.
72 //
73 //*FileGuid = NameGuid;
74 File->Type = BDS_FILETYPE_FV;
75 File->FilePath = FilePath;
76 CopyGuid (&(File->File.Fv.Guid),&NameGuid);
77 File->File.Fv.FvProtocol = FvProtocol;
78 File->File.Fv.FileType = FileType;
79
80 Status = gBS->HandleProtocol(FvHandle,&gEfiDevicePathProtocolGuid, (VOID **)&(File->DevicePath));
81
82 FreePool (Key);
83 FreePool (UiSection);
84 return FileStatus;
85 }
86 FreePool (UiSection);
87 }
88 }
89 } while (!EFI_ERROR (Status));
90
91 FreePool(Key);
92 return Status;
93}
94
95EFI_STATUS BdsCopyRawFileToRuntimeMemoryFV(
96 IN BDS_FV_FILE *FvFile,
97 OUT VOID **FileImage,
98 OUT UINTN *FileSize
99) {
100 EFI_STATUS Status = EFI_INVALID_PARAMETER;
101 EFI_FIRMWARE_VOLUME2_PROTOCOL *FvProtocol;
102 EFI_FV_FILETYPE FileType;
103 EFI_GUID* NameGuid;
104 EFI_FV_FILE_ATTRIBUTES Attributes;
105 UINT32 Authentication;
106
107 FvProtocol = FvFile->FvProtocol;
108 FileType = FvFile->FileType;
109 NameGuid = &(FvFile->Guid);
110
111 if (FileType == EFI_FV_FILETYPE_RAW) {
112 *FileImage = NULL;
113 *FileSize = 0;
114 Status = FvProtocol->ReadFile(
115 FvProtocol,NameGuid, // IN
116 FileImage,FileSize, // IN OUT
117 &FileType,&Attributes,&Authentication // OUT
118 );
119 ASSERT_EFI_ERROR(Status);
120
121 // This raw file also contains a header
122 *FileSize = *FileSize - 4;
123 *FileImage = (UINT8*)FileImage + 4;
124 } else if (FileType == EFI_FV_FILETYPE_FREEFORM) {
125 Status = FvProtocol->ReadSection (
126 FvProtocol,NameGuid,EFI_SECTION_RAW,0, // IN
127 FileImage,FileSize, // IN OUT
128 &Authentication // OUT
129 );
130 ASSERT_EFI_ERROR(Status);
131 } else {
132 ASSERT(0); //Maybe support application as well ???
133 }
134
135 return Status;
136}