]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Library/BdsLib/BdsFilePathMem.c
Patch from open source community for CryptoPkg to allow it to build for ARM using...
[mirror_edk2.git] / ArmPkg / Library / BdsLib / BdsFilePathMem.c
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
17
18 EFI_STATUS BdsLoadFileFromMemMap (
19 IN EFI_HANDLE Handle,
20 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
21 OUT BDS_FILE *File
22 ) {
23 EFI_DEVICE_PATH_PROTOCOL *LastDevicePath;
24
25 if ((File == NULL) || (DevicePath == NULL) || (IsDevicePathEnd (DevicePath))) {
26 return EFI_INVALID_PARAMETER;
27 }
28
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);
35 }
36 if ((LastDevicePath->Type != HARDWARE_DEVICE_PATH) || (LastDevicePath->SubType != HW_MEMMAP_DP)) {
37 return EFI_UNSUPPORTED;
38 }
39
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;
44
45 return EFI_SUCCESS;
46 }
47
48 EFI_STATUS BdsCopyRawFileToRuntimeMemoryMemMap(
49 IN BDS_MEM_FILE *MemFile,
50 OUT VOID **FileImage,
51 OUT UINTN *FileSize
52 ) {
53 UINTN Size;
54 VOID* Image;
55
56 Size = MemFile->EndingAddress - MemFile->StartingAddress;
57
58 if ((Size == 0) || (FileImage == NULL)) {
59 return EFI_INVALID_PARAMETER;
60 }
61 if (FileSize != NULL) {
62 *FileSize = Size;
63 }
64
65 Image = AllocateRuntimePool(Size);
66 if (Image == NULL) {
67 return EFI_OUT_OF_RESOURCES;
68 }
69
70 *FileImage = CopyMem(Image,(CONST VOID*)(UINTN)MemFile->StartingAddress,Size);
71
72 return EFI_SUCCESS;
73 }