]> git.proxmox.com Git - mirror_edk2.git/blob - EmbeddedPkg/Library/DxeDtPlatformDtbLoaderLibDefault/DxeDtPlatformDtbLoaderLibDefault.c
EmbeddedPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / EmbeddedPkg / Library / DxeDtPlatformDtbLoaderLibDefault / DxeDtPlatformDtbLoaderLibDefault.c
1 /** @file
2 *
3 * Copyright (c) 2017, Linaro, Ltd. All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-2-Clause-Patent
6 *
7 **/
8
9 #include <PiDxe.h>
10
11 #include <Library/BaseLib.h>
12 #include <Library/DxeServicesLib.h>
13 #include <Library/MemoryAllocationLib.h>
14
15 /**
16 Return a pool allocated copy of the DTB image that is appropriate for
17 booting the current platform via DT.
18
19 @param[out] Dtb Pointer to the DTB copy
20 @param[out] DtbSize Size of the DTB copy
21
22 @retval EFI_SUCCESS Operation completed successfully
23 @retval EFI_NOT_FOUND No suitable DTB image could be located
24 @retval EFI_OUT_OF_RESOURCES No pool memory available
25
26 **/
27 EFI_STATUS
28 EFIAPI
29 DtPlatformLoadDtb (
30 OUT VOID **Dtb,
31 OUT UINTN *DtbSize
32 )
33 {
34 EFI_STATUS Status;
35 VOID *OrigDtb;
36 VOID *CopyDtb;
37 UINTN OrigDtbSize;
38
39 Status = GetSectionFromAnyFv (&gDtPlatformDefaultDtbFileGuid,
40 EFI_SECTION_RAW, 0, &OrigDtb, &OrigDtbSize);
41 if (EFI_ERROR (Status)) {
42 return EFI_NOT_FOUND;
43 }
44
45 CopyDtb = AllocateCopyPool (OrigDtbSize, OrigDtb);
46 if (CopyDtb == NULL) {
47 return EFI_OUT_OF_RESOURCES;
48 }
49
50 *Dtb = CopyDtb;
51 *DtbSize = OrigDtbSize;
52
53 return EFI_SUCCESS;
54 }