EmbeddedPkg: add base DtPlatformDtbLoaderLib implementation

Introduce an implementation of the new DtPlatformDtbLoaderLib library
class that simply retrieves the first raw section of an FV file named
'gDtPlatformDefaultDtbFileGuid'.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
diff --git a/EmbeddedPkg/EmbeddedPkg.dsc b/EmbeddedPkg/EmbeddedPkg.dsc
index 1453cbf..16b368e 100644
--- a/EmbeddedPkg/EmbeddedPkg.dsc
+++ b/EmbeddedPkg/EmbeddedPkg.dsc
@@ -109,6 +109,9 @@
   HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf

   UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf

 

+  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf

+  DtPlatformDtbLoaderLib|EmbeddedPkg/Library/DxeDtPlatformDtbLoaderLibDefault/DxeDtPlatformDtbLoaderLibDefault.inf

+

 [LibraryClasses.common.DXE_DRIVER]

   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf

   ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf

@@ -247,6 +250,7 @@
   EmbeddedPkg/Library/TemplateRealTimeClockLib/TemplateRealTimeClockLib.inf

   EmbeddedPkg/Library/LzmaHobCustomDecompressLib/LzmaHobCustomDecompressLib.inf

   EmbeddedPkg/Library/NullDmaLib/NullDmaLib.inf

+  EmbeddedPkg/Library/DxeDtPlatformDtbLoaderLibDefault/DxeDtPlatformDtbLoaderLibDefault.inf

 

   EmbeddedPkg/Ebl/Ebl.inf

 ####  EmbeddedPkg/EblExternCmd/EblExternCmd.inf

diff --git a/EmbeddedPkg/Library/DxeDtPlatformDtbLoaderLibDefault/DxeDtPlatformDtbLoaderLibDefault.c b/EmbeddedPkg/Library/DxeDtPlatformDtbLoaderLibDefault/DxeDtPlatformDtbLoaderLibDefault.c
new file mode 100644
index 0000000..313d0b1
--- /dev/null
+++ b/EmbeddedPkg/Library/DxeDtPlatformDtbLoaderLibDefault/DxeDtPlatformDtbLoaderLibDefault.c
@@ -0,0 +1,60 @@
+/** @file

+*

+*  Copyright (c) 2017, Linaro, Ltd. All rights reserved.

+*

+*  This program and the accompanying materials

+*  are licensed and made available under the terms and conditions of the BSD License

+*  which accompanies this distribution.  The full text of the license may be found at

+*  http://opensource.org/licenses/bsd-license.php

+*

+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,

+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

+*

+**/

+

+#include <PiDxe.h>

+

+#include <Library/BaseLib.h>

+#include <Library/DxeServicesLib.h>

+#include <Library/MemoryAllocationLib.h>

+

+/**

+  Return a pool allocated copy of the DTB image that is appropriate for

+  booting the current platform via DT.

+

+  @param[out]   Dtb                   Pointer to the DTB copy

+  @param[out]   DtbSize               Size of the DTB copy

+

+  @retval       EFI_SUCCESS           Operation completed successfully

+  @retval       EFI_NOT_FOUND         No suitable DTB image could be located

+  @retval       EFI_OUT_OF_RESOURCES  No pool memory available

+

+**/

+EFI_STATUS

+EFIAPI

+DtPlatformLoadDtb (

+  OUT   VOID        **Dtb,

+  OUT   UINTN       *DtbSize

+  )

+{

+  EFI_STATUS      Status;

+  VOID            *OrigDtb;

+  VOID            *CopyDtb;

+  UINTN           OrigDtbSize;

+

+  Status = GetSectionFromAnyFv (&gDtPlatformDefaultDtbFileGuid,

+             EFI_SECTION_RAW, 0, &OrigDtb, &OrigDtbSize);

+  if (EFI_ERROR (Status)) {

+    return EFI_NOT_FOUND;

+  }

+

+  CopyDtb = AllocateCopyPool (OrigDtbSize, OrigDtb);

+  if (CopyDtb == NULL) {

+    return EFI_OUT_OF_RESOURCES;

+  }

+

+  *Dtb = CopyDtb;

+  *DtbSize = OrigDtbSize;

+

+  return EFI_SUCCESS;

+}

diff --git a/EmbeddedPkg/Library/DxeDtPlatformDtbLoaderLibDefault/DxeDtPlatformDtbLoaderLibDefault.inf b/EmbeddedPkg/Library/DxeDtPlatformDtbLoaderLibDefault/DxeDtPlatformDtbLoaderLibDefault.inf
new file mode 100644
index 0000000..9d49fc5
--- /dev/null
+++ b/EmbeddedPkg/Library/DxeDtPlatformDtbLoaderLibDefault/DxeDtPlatformDtbLoaderLibDefault.inf
@@ -0,0 +1,36 @@
+/** @file

+*

+*  Copyright (c) 2017, Linaro, Ltd. All rights reserved.

+*

+*  This program and the accompanying materials

+*  are licensed and made available under the terms and conditions of the BSD License

+*  which accompanies this distribution.  The full text of the license may be found at

+*  http://opensource.org/licenses/bsd-license.php

+*

+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,

+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

+*

+**/

+

+[Defines]

+  INF_VERSION                    = 0x00010019

+  BASE_NAME                      = DxeDtPlatformDtbLoaderLibDefault

+  FILE_GUID                      = 419a1910-70da-4c99-8696-ba81a57be508

+  MODULE_TYPE                    = DXE_DRIVER

+  VERSION_STRING                 = 1.0

+  LIBRARY_CLASS                  = DtPlatformDtbLoaderLib|DXE_DRIVER

+

+[Sources]

+  DxeDtPlatformDtbLoaderLibDefault.c

+

+[Packages]

+  MdePkg/MdePkg.dec

+  EmbeddedPkg/EmbeddedPkg.dec

+

+[LibraryClasses]

+  BaseLib

+  DxeServicesLib

+  MemoryAllocationLib

+

+[Guids]

+  gDtPlatformDefaultDtbFileGuid