+/** @file\r
+\r
+ Copyright (c) 2013-2014, ARM Ltd. All rights reserved.<BR>\r
+ Copyright (c) 2017, Linaro.\r
+\r
+ This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef __ABOOTIMG_H__\r
+#define __ABOOTIMG_H__\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+\r
+#include <Uefi/UefiBaseType.h>\r
+#include <Uefi/UefiSpec.h>\r
+\r
+#define ANDROID_BOOTIMG_KERNEL_ARGS_SIZE 512\r
+\r
+#define ANDROID_BOOT_MAGIC "ANDROID!"\r
+#define ANDROID_BOOT_MAGIC_LENGTH (sizeof (ANDROID_BOOT_MAGIC) - 1)\r
+\r
+// No documentation for this really - sizes of fields has been determined\r
+// empirically.\r
+#pragma pack(1)\r
+/* https://android.googlesource.com/platform/system/core/+/master/mkbootimg/bootimg.h */\r
+typedef struct {\r
+ UINT8 BootMagic[ANDROID_BOOT_MAGIC_LENGTH];\r
+ UINT32 KernelSize;\r
+ UINT32 KernelAddress;\r
+ UINT32 RamdiskSize;\r
+ UINT32 RamdiskAddress;\r
+ UINT32 SecondStageBootloaderSize;\r
+ UINT32 SecondStageBootloaderAddress;\r
+ UINT32 KernelTaggsAddress;\r
+ UINT32 PageSize;\r
+ UINT32 Reserved[2];\r
+ CHAR8 ProductName[16];\r
+ CHAR8 KernelArgs[ANDROID_BOOTIMG_KERNEL_ARGS_SIZE];\r
+ UINT32 Id[32];\r
+} ANDROID_BOOTIMG_HEADER;\r
+#pragma pack ()\r
+\r
+/* Check Val (unsigned) is a power of 2 (has only one bit set) */\r
+#define IS_POWER_OF_2(Val) ((Val) != 0 && (((Val) & ((Val) - 1)) == 0))\r
+/* Android boot image page size is not specified, but it should be power of 2\r
+ * and larger than boot header */\r
+#define IS_VALID_ANDROID_PAGE_SIZE(Val) \\r
+ (IS_POWER_OF_2(Val) && (Val > sizeof(ANDROID_BOOTIMG_HEADER)))\r
+#endif /* __ABOOTIMG_H__ */\r