DxeDtPlatformDtbLoaderLibDefault.c 1.4 KB

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