]> git.proxmox.com Git - mirror_edk2.git/blob - EmbeddedPkg/Include/Library/AndroidBootImgLib.h
EmbeddedPkg/AndroidBoot: boot android kernel from storage
[mirror_edk2.git] / EmbeddedPkg / Include / Library / AndroidBootImgLib.h
1 /** @file
2
3 Copyright (c) 2013-2014, ARM Ltd. All rights reserved.<BR>
4 Copyright (c) 2017, Linaro.
5
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #ifndef __ABOOTIMG_H__
17 #define __ABOOTIMG_H__
18
19 #include <Library/BaseLib.h>
20 #include <Library/DebugLib.h>
21 #include <Library/MemoryAllocationLib.h>
22
23 #include <Uefi/UefiBaseType.h>
24 #include <Uefi/UefiSpec.h>
25
26 #define ANDROID_BOOTIMG_KERNEL_ARGS_SIZE 512
27
28 #define ANDROID_BOOT_MAGIC "ANDROID!"
29 #define ANDROID_BOOT_MAGIC_LENGTH (sizeof (ANDROID_BOOT_MAGIC) - 1)
30
31 // No documentation for this really - sizes of fields has been determined
32 // empirically.
33 #pragma pack(1)
34 /* https://android.googlesource.com/platform/system/core/+/master/mkbootimg/bootimg.h */
35 typedef struct {
36 UINT8 BootMagic[ANDROID_BOOT_MAGIC_LENGTH];
37 UINT32 KernelSize;
38 UINT32 KernelAddress;
39 UINT32 RamdiskSize;
40 UINT32 RamdiskAddress;
41 UINT32 SecondStageBootloaderSize;
42 UINT32 SecondStageBootloaderAddress;
43 UINT32 KernelTaggsAddress;
44 UINT32 PageSize;
45 UINT32 Reserved[2];
46 CHAR8 ProductName[16];
47 CHAR8 KernelArgs[ANDROID_BOOTIMG_KERNEL_ARGS_SIZE];
48 UINT32 Id[32];
49 } ANDROID_BOOTIMG_HEADER;
50 #pragma pack ()
51
52 /* Check Val (unsigned) is a power of 2 (has only one bit set) */
53 #define IS_POWER_OF_2(Val) ((Val) != 0 && (((Val) & ((Val) - 1)) == 0))
54 /* Android boot image page size is not specified, but it should be power of 2
55 * and larger than boot header */
56 #define IS_VALID_ANDROID_PAGE_SIZE(Val) \
57 (IS_POWER_OF_2(Val) && (Val > sizeof(ANDROID_BOOTIMG_HEADER)))
58
59 EFI_STATUS
60 AndroidBootImgGetImgSize (
61 IN VOID *BootImg,
62 OUT UINTN *ImgSize
63 );
64
65 EFI_STATUS
66 AndroidBootImgBoot (
67 IN VOID *Buffer,
68 IN UINTN BufferSize
69 );
70
71 #endif /* __ABOOTIMG_H__ */