AndroidBootImgLib.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /** @file
  2. Copyright (c) 2013-2014, ARM Ltd. All rights reserved.<BR>
  3. Copyright (c) 2017, Linaro.
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef __ABOOTIMG_H__
  7. #define __ABOOTIMG_H__
  8. #include <Library/BaseLib.h>
  9. #include <Library/DebugLib.h>
  10. #include <Library/MemoryAllocationLib.h>
  11. #include <Uefi/UefiBaseType.h>
  12. #include <Uefi/UefiSpec.h>
  13. #define ANDROID_BOOTIMG_KERNEL_ARGS_SIZE 512
  14. #define ANDROID_BOOT_MAGIC "ANDROID!"
  15. #define ANDROID_BOOT_MAGIC_LENGTH (sizeof (ANDROID_BOOT_MAGIC) - 1)
  16. // No documentation for this really - sizes of fields has been determined
  17. // empirically.
  18. #pragma pack(1)
  19. /* https://android.googlesource.com/platform/system/core/+/master/mkbootimg/bootimg.h */
  20. typedef struct {
  21. UINT8 BootMagic[ANDROID_BOOT_MAGIC_LENGTH];
  22. UINT32 KernelSize;
  23. UINT32 KernelAddress;
  24. UINT32 RamdiskSize;
  25. UINT32 RamdiskAddress;
  26. UINT32 SecondStageBootloaderSize;
  27. UINT32 SecondStageBootloaderAddress;
  28. UINT32 KernelTaggsAddress;
  29. UINT32 PageSize;
  30. UINT32 Reserved[2];
  31. CHAR8 ProductName[16];
  32. CHAR8 KernelArgs[ANDROID_BOOTIMG_KERNEL_ARGS_SIZE];
  33. UINT32 Id[32];
  34. } ANDROID_BOOTIMG_HEADER;
  35. #pragma pack ()
  36. /* Check Val (unsigned) is a power of 2 (has only one bit set) */
  37. #define IS_POWER_OF_2(Val) ((Val) != 0 && (((Val) & ((Val) - 1)) == 0))
  38. /* Android boot image page size is not specified, but it should be power of 2
  39. * and larger than boot header */
  40. #define IS_VALID_ANDROID_PAGE_SIZE(Val) \
  41. (IS_POWER_OF_2(Val) && (Val > sizeof(ANDROID_BOOTIMG_HEADER)))
  42. EFI_STATUS
  43. AndroidBootImgGetImgSize (
  44. IN VOID *BootImg,
  45. OUT UINTN *ImgSize
  46. );
  47. EFI_STATUS
  48. AndroidBootImgBoot (
  49. IN VOID *Buffer,
  50. IN UINTN BufferSize
  51. );
  52. #endif /* __ABOOTIMG_H__ */