3 * Copyright (c) 2011, ARM Limited. All rights reserved.
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
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.
15 #include "BdsInternal.h"
17 EFI_STATUS
BdsLoadFileFromFirmwareVolume(
18 IN EFI_HANDLE FvHandle
,
20 IN EFI_FV_FILETYPE FileTypeFilter
,
23 EFI_FIRMWARE_VOLUME2_PROTOCOL
*FvProtocol
;
25 EFI_STATUS Status
, FileStatus
;
27 EFI_FV_FILETYPE FileType
;
28 EFI_FV_FILE_ATTRIBUTES Attributes
;
32 UINT32 Authentication
;
35 return EFI_INVALID_PARAMETER
;
38 Status
= gBS
->HandleProtocol(FvHandle
,&gEfiFirmwareVolume2ProtocolGuid
, (VOID
**)&FvProtocol
);
39 if (EFI_ERROR(Status
)) {
44 UiStringLen
= StrLen (FilePath
);
47 Key
= AllocatePool (FvProtocol
->KeySize
);
49 ZeroMem (Key
, FvProtocol
->KeySize
);
52 // Search in all files
53 FileType
= FileTypeFilter
;
55 Status
= FvProtocol
->GetNextFile (FvProtocol
, Key
, &FileType
, &NameGuid
, &Attributes
, &Size
);
56 if (!EFI_ERROR (Status
)) {
58 FileStatus
= FvProtocol
->ReadSection (
61 EFI_SECTION_USER_INTERFACE
,
67 if (!EFI_ERROR (FileStatus
)) {
68 if (StrnCmp (FilePath
, UiSection
, UiStringLen
) == 0) {
71 // We found a UiString match.
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
;
80 Status
= gBS
->HandleProtocol(FvHandle
,&gEfiDevicePathProtocolGuid
, (VOID
**)&(File
->DevicePath
));
89 } while (!EFI_ERROR (Status
));
95 EFI_STATUS
BdsCopyRawFileToRuntimeMemoryFV(
96 IN BDS_FV_FILE
*FvFile
,
100 EFI_STATUS Status
= EFI_INVALID_PARAMETER
;
101 EFI_FIRMWARE_VOLUME2_PROTOCOL
*FvProtocol
;
102 EFI_FV_FILETYPE FileType
;
104 EFI_FV_FILE_ATTRIBUTES Attributes
;
105 UINT32 Authentication
;
107 FvProtocol
= FvFile
->FvProtocol
;
108 FileType
= FvFile
->FileType
;
109 NameGuid
= &(FvFile
->Guid
);
111 if (FileType
== EFI_FV_FILETYPE_RAW
) {
114 Status
= FvProtocol
->ReadFile(
115 FvProtocol
,NameGuid
, // IN
116 FileImage
,FileSize
, // IN OUT
117 &FileType
,&Attributes
,&Authentication
// OUT
119 ASSERT_EFI_ERROR(Status
);
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
130 ASSERT_EFI_ERROR(Status
);
132 ASSERT(0); //Maybe support application as well ???