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"
18 EFI_STATUS
BdsLoadFileFromMemMap (
20 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
23 EFI_DEVICE_PATH_PROTOCOL
*LastDevicePath
;
25 if ((File
== NULL
) || (DevicePath
== NULL
) || (IsDevicePathEnd (DevicePath
))) {
26 return EFI_INVALID_PARAMETER
;
29 // Check if the last node of the device Path is a Memory Map Device Node
30 LastDevicePath
= DevicePath
;
31 DevicePath
= NextDevicePathNode(DevicePath
);
32 while (!IsDevicePathEnd (DevicePath
)) {
33 LastDevicePath
= DevicePath
;
34 DevicePath
= NextDevicePathNode(DevicePath
);
36 if ((LastDevicePath
->Type
!= HARDWARE_DEVICE_PATH
) || (LastDevicePath
->SubType
!= HW_MEMMAP_DP
)) {
37 return EFI_UNSUPPORTED
;
40 File
->Type
= BDS_FILETYPE_MEM
;
41 File
->File
.Mem
.MemoryType
= ((MEMMAP_DEVICE_PATH
*)LastDevicePath
)->MemoryType
;
42 File
->File
.Mem
.StartingAddress
= ((MEMMAP_DEVICE_PATH
*)LastDevicePath
)->StartingAddress
;
43 File
->File
.Mem
.EndingAddress
= ((MEMMAP_DEVICE_PATH
*)LastDevicePath
)->EndingAddress
;
48 EFI_STATUS
BdsCopyRawFileToRuntimeMemoryMemMap(
49 IN BDS_MEM_FILE
*MemFile
,
56 Size
= MemFile
->EndingAddress
- MemFile
->StartingAddress
;
58 if ((Size
== 0) || (FileImage
== NULL
)) {
59 return EFI_INVALID_PARAMETER
;
61 if (FileSize
!= NULL
) {
65 Image
= AllocateRuntimePool(Size
);
67 return EFI_OUT_OF_RESOURCES
;
70 *FileImage
= CopyMem(Image
,(CONST VOID
*)(UINTN
)MemFile
->StartingAddress
,Size
);