]> git.proxmox.com Git - mirror_edk2.git/blob - EmbeddedPkg/Library/DxeDtPlatformDtbLoaderLibDefault/DxeDtPlatformDtbLoaderLibDefault.c
313d0b1046814193fe508ec16875d9a7ed75f104
[mirror_edk2.git] / EmbeddedPkg / Library / DxeDtPlatformDtbLoaderLibDefault / DxeDtPlatformDtbLoaderLibDefault.c
1 /** @file
2 *
3 * Copyright (c) 2017, Linaro, Ltd. 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 <PiDxe.h>
16
17 #include <Library/BaseLib.h>
18 #include <Library/DxeServicesLib.h>
19 #include <Library/MemoryAllocationLib.h>
20
21 /**
22 Return a pool allocated copy of the DTB image that is appropriate for
23 booting the current platform via DT.
24
25 @param[out] Dtb Pointer to the DTB copy
26 @param[out] DtbSize Size of the DTB copy
27
28 @retval EFI_SUCCESS Operation completed successfully
29 @retval EFI_NOT_FOUND No suitable DTB image could be located
30 @retval EFI_OUT_OF_RESOURCES No pool memory available
31
32 **/
33 EFI_STATUS
34 EFIAPI
35 DtPlatformLoadDtb (
36 OUT VOID **Dtb,
37 OUT UINTN *DtbSize
38 )
39 {
40 EFI_STATUS Status;
41 VOID *OrigDtb;
42 VOID *CopyDtb;
43 UINTN OrigDtbSize;
44
45 Status = GetSectionFromAnyFv (&gDtPlatformDefaultDtbFileGuid,
46 EFI_SECTION_RAW, 0, &OrigDtb, &OrigDtbSize);
47 if (EFI_ERROR (Status)) {
48 return EFI_NOT_FOUND;
49 }
50
51 CopyDtb = AllocateCopyPool (OrigDtbSize, OrigDtb);
52 if (CopyDtb == NULL) {
53 return EFI_OUT_OF_RESOURCES;
54 }
55
56 *Dtb = CopyDtb;
57 *DtbSize = OrigDtbSize;
58
59 return EFI_SUCCESS;
60 }