Android introduced boot header version 3 or 4.
The header structure change with version 3 and 4 to support
the new updates such as:
- Introducing Vendor boot image: with a vendor ramdisk
- Bootconfig feature (v4)
Change andr_img_hdr struct name to maintain support for version v0,
v1 and v2 while introducing version 3 and 4.
Signed-off-by: Safae Ouajih <souajih@baylibre.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Tested-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
static char andr_tmp_str[ANDR_BOOT_ARGS_SIZE + 1];
-static ulong android_image_get_kernel_addr(const struct andr_img_hdr *hdr)
+static ulong android_image_get_kernel_addr(const struct andr_boot_img_hdr_v0 *hdr)
{
/*
* All the Android tools that generate a boot.img use this
* Return: Zero, os start address and length on success,
* otherwise on failure.
*/
-int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
+int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr, int verify,
ulong *os_data, ulong *os_len)
{
u32 kernel_addr = android_image_get_kernel_addr(hdr);
return 0;
}
-int android_image_check_header(const struct andr_img_hdr *hdr)
+/**
+ * android_image_check_header() - Check the magic of boot image
+ *
+ * This checks the header of Android boot image and verifies the
+ * magic is "ANDROID!"
+ *
+ * @hdr: Pointer to boot image
+ * Return: 0 if the magic is correct, non-zero if there is a magic mismatch
+ */
+int android_image_check_header(const struct andr_boot_img_hdr_v0 *hdr)
{
return memcmp(ANDR_BOOT_MAGIC, hdr->magic, ANDR_BOOT_MAGIC_SIZE);
}
-ulong android_image_get_end(const struct andr_img_hdr *hdr)
+ulong android_image_get_end(const struct andr_boot_img_hdr_v0 *hdr)
{
ulong end;
return end;
}
-ulong android_image_get_kload(const struct andr_img_hdr *hdr)
+ulong android_image_get_kload(const struct andr_boot_img_hdr_v0 *hdr)
{
return android_image_get_kernel_addr(hdr);
}
-ulong android_image_get_kcomp(const struct andr_img_hdr *hdr)
+ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0 *hdr)
{
const void *p = (void *)((uintptr_t)hdr + hdr->page_size);
return image_decomp_type(p, sizeof(u32));
}
-int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
+int android_image_get_ramdisk(const struct andr_boot_img_hdr_v0 *hdr,
ulong *rd_data, ulong *rd_len)
{
if (!hdr->ramdisk_size) {
return 0;
}
-int android_image_get_second(const struct andr_img_hdr *hdr,
- ulong *second_data, ulong *second_len)
+int android_image_get_second(const struct andr_boot_img_hdr_v0 *hdr,
+ ulong *second_data, ulong *second_len)
{
if (!hdr->second_size) {
*second_data = *second_len = 0;
*/
bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size)
{
- const struct andr_img_hdr *hdr;
+ const struct andr_boot_img_hdr_v0 *hdr;
ulong dtbo_img_addr;
bool ret = true;
*/
static bool android_image_get_dtb_img_addr(ulong hdr_addr, ulong *addr)
{
- const struct andr_img_hdr *hdr;
+ const struct andr_boot_img_hdr_v0 *hdr;
ulong dtb_img_addr;
bool ret = true;
bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr,
u32 *size)
{
- const struct andr_img_hdr *hdr;
+ const struct andr_boot_img_hdr_v0 *hdr;
bool res;
ulong dtb_img_addr; /* address of DTB part in boot image */
u32 dtb_img_size; /* size of DTB payload in boot image */
* returns:
* no returned results
*/
-void android_print_contents(const struct andr_img_hdr *hdr)
+void android_print_contents(const struct andr_boot_img_hdr_v0 *hdr)
{
const char * const p = IMAGE_INDENT_STRING;
/* os_version = ver << 11 | lvl */
*/
bool android_image_print_dtb_contents(ulong hdr_addr)
{
- const struct andr_img_hdr *hdr;
+ const struct andr_boot_img_hdr_v0 *hdr;
bool res;
ulong dtb_img_addr; /* address of DTB part in boot image */
u32 dtb_img_size; /* size of DTB payload in boot image */
}
#ifdef CONFIG_ANDROID_BOOT_IMAGE
} else if (genimg_get_format(buf) == IMAGE_FORMAT_ANDROID) {
- struct andr_img_hdr *hdr = buf;
+ struct andr_boot_img_hdr_v0 *hdr = buf;
ulong fdt_data, fdt_len;
u32 fdt_size, dtb_idx;
/*
static int abootimg_get_ver(int argc, char *const argv[])
{
- const struct andr_img_hdr *hdr;
+ const struct andr_boot_img_hdr_v0 *hdr;
int res = CMD_RET_SUCCESS;
if (argc > 1)
static int abootimg_get_dtb_load_addr(int argc, char *const argv[])
{
- const struct andr_img_hdr *hdr;
+ const struct andr_boot_img_hdr_v0 *hdr;
int res = CMD_RET_SUCCESS;
if (argc > 1)
*/
static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
struct disk_partition *info,
- struct andr_img_hdr *hdr,
+ struct andr_boot_img_hdr_v0 *hdr,
char *response)
{
ulong sector_size; /* boot partition sector size */
/* Calculate boot image sectors count */
sector_size = info->blksz;
- hdr_sectors = DIV_ROUND_UP(sizeof(struct andr_img_hdr), sector_size);
+ hdr_sectors = DIV_ROUND_UP(sizeof(struct andr_boot_img_hdr_v0), sector_size);
if (hdr_sectors == 0) {
pr_err("invalid number of boot sectors: 0\n");
fastboot_fail("invalid number of boot sectors: 0", response);
char *response)
{
uintptr_t hdr_addr; /* boot image header address */
- struct andr_img_hdr *hdr; /* boot image header */
+ struct andr_boot_img_hdr_v0 *hdr; /* boot image header */
lbaint_t hdr_sectors; /* boot image header sectors */
u8 *ramdisk_buffer;
u32 ramdisk_sector_start;
/* Put boot image header in fastboot buffer after downloaded zImage */
hdr_addr = (uintptr_t)download_buffer + ALIGN(download_bytes, PAGE_SIZE);
- hdr = (struct andr_img_hdr *)hdr_addr;
+ hdr = (struct andr_boot_img_hdr_v0 *)hdr_addr;
/* Read boot image header */
hdr_sectors = fb_mmc_get_boot_header(dev_desc, &info, hdr, response);
#define ANDR_BOOT_ARGS_SIZE 512
#define ANDR_BOOT_EXTRA_ARGS_SIZE 1024
-/* The bootloader expects the structure of andr_img_hdr with header
+/* The bootloader expects the structure of andr_boot_img_hdr_v0 with header
* version 0 to be as follows: */
-struct andr_img_hdr {
+struct andr_boot_img_hdr_v0 {
/* Must be ANDR_BOOT_MAGIC. */
char magic[ANDR_BOOT_MAGIC_SIZE];
struct cipher_algo *image_get_cipher_algo(const char *full_name);
-struct andr_img_hdr;
-int android_image_check_header(const struct andr_img_hdr *hdr);
-int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
+struct andr_boot_img_hdr_v0;
+
+/**
+ * android_image_check_header() - Check the magic of boot image
+ *
+ * This checks the header of Android boot image and verifies the
+ * magic is "ANDROID!"
+ *
+ * @hdr: Pointer to image header
+ * Return: 0 if the magic is correct, non-zero if there is a magic mismatch
+ */
+int android_image_check_header(const struct andr_boot_img_hdr_v0 *hdr);
+
+/**
+ * android_image_get_kernel() - Processes kernel part of Android boot images
+ *
+ * This function returns the os image's start address and length. Also,
+ * it appends the kernel command line to the bootargs env variable.
+ *
+ * @hdr: Pointer to image header, which is at the start
+ * of the image.
+ * @verify: Checksum verification flag. Currently unimplemented.
+ * @os_data: Pointer to a ulong variable, will hold os data start
+ * address.
+ * @os_len: Pointer to a ulong variable, will hold os data length.
+ * Return: Zero, os start address and length on success,
+ * otherwise on failure.
+ */
+int android_image_get_kernel(const struct andr_boot_img_hdr_v0 *hdr, int verify,
ulong *os_data, ulong *os_len);
-int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
+
+/**
+ * android_image_get_ramdisk() - Extracts the ramdisk load address and its size
+ *
+ * This extracts the load address of the ramdisk and its size
+ *
+ * @hdr: Pointer to image header
+ * @rd_data: Pointer to a ulong variable, will hold ramdisk address
+ * @rd_len: Pointer to a ulong variable, will hold ramdisk length
+ * Return: 0 if succeeded, -1 if ramdisk size is 0
+ */
+int android_image_get_ramdisk(const struct andr_boot_img_hdr_v0 *hdr,
ulong *rd_data, ulong *rd_len);
-int android_image_get_second(const struct andr_img_hdr *hdr,
- ulong *second_data, ulong *second_len);
+
+/**
+ * android_image_get_second() - Extracts the secondary bootloader address
+ * and its size
+ *
+ * This extracts the address of the secondary bootloader and its size
+ *
+ * @hdr: Pointer to image header
+ * @second_data: Pointer to a ulong variable, will hold secondary bootloader address
+ * @second_len : Pointer to a ulong variable, will hold secondary bootloader length
+ * Return: 0 if succeeded, -1 if secondary bootloader size is 0
+ */
+int android_image_get_second(const struct andr_boot_img_hdr_v0 *hdr,
+ ulong *second_data, ulong *second_len);
bool android_image_get_dtbo(ulong hdr_addr, ulong *addr, u32 *size);
bool android_image_get_dtb_by_index(ulong hdr_addr, u32 index, ulong *addr,
u32 *size);
-ulong android_image_get_end(const struct andr_img_hdr *hdr);
-ulong android_image_get_kload(const struct andr_img_hdr *hdr);
-ulong android_image_get_kcomp(const struct andr_img_hdr *hdr);
-void android_print_contents(const struct andr_img_hdr *hdr);
+
+/**
+ * android_image_get_end() - Get the end of Android boot image
+ *
+ * This returns the end address of Android boot image address
+ *
+ * @hdr: Pointer to image header
+ * Return: The end address of Android boot image
+ */
+ulong android_image_get_end(const struct andr_boot_img_hdr_v0 *hdr);
+
+/**
+ * android_image_get_kload() - Get the kernel load address
+ *
+ * This returns the kernel load address. The load address is extracted
+ * from the boot image header or the "kernel_addr_r" environment variable
+ *
+ * @hdr: Pointer to image header
+ * Return: The kernel load address
+ */
+ulong android_image_get_kload(const struct andr_boot_img_hdr_v0 *hdr);
+
+/**
+ * android_image_get_kcomp() - Get kernel compression type
+ *
+ * This gets the kernel compression type from the boot image header
+ *
+ * @hdr: Pointer to image header
+ * Return: Kernel compression type
+ */
+ulong android_image_get_kcomp(const struct andr_boot_img_hdr_v0 *hdr);
+
+/**
+ * android_print_contents() - Prints out the contents of the Android format image
+ *
+ * This formats a multi line Android image contents description.
+ * The routine prints out Android image properties
+ *
+ * @hdr: Pointer to the Android format image header
+ * Return: no returned results
+ */
+void android_print_contents(const struct andr_boot_img_hdr_v0 *hdr);
bool android_image_print_dtb_contents(ulong hdr_addr);
/**