mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-30 08:31:03 +00:00
9ace3fc814
This patch adds support for the Android boot-image format. The header file is from the Android project and got slightly alterted so the struct + its defines are not generic but have something like a namespace. The header file is from bootloader/legacy/include/boot/bootimg.h. The header parsing has been written from scratch and I looked at bootloader/legacy/usbloader/usbloader.c for some details. The image contains the physical address (load address) of the kernel and ramdisk. This address is considered only for the kernel image. The "second image" defined in the image header is currently not supported. I haven't found anything that is creating this. v3 (Rob Herring): This is based on http://patchwork.ozlabs.org/patch/126797/ with the following changes: - Rebased to current mainline - Moved android image handling to separate functions in common/image-android.c - s/u8/char/ in header to fix string function warnings - Use SPDX identifiers for licenses - Cleaned-up file source information: android_image.h is from file include/boot/bootimg.h in repository: https://android.googlesource.com/platform/bootable/bootloader/legacy The git commit hash is 4205b865141ff2e255fe1d3bd16de18e217ef06a usbloader.c would be from the same commit, but it does not appear to have been used for any actual code. v4: - s/andriod/android/ - Use a separate flag ep_found to track if the entry point has been set rather than using a magic value. Cc: Wolfgang Denk <wd@denx.de> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Rob Herring <robh@kernel.org> Reviewed-by: Tom Rini <trini@ti.com> Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
84 lines
2.2 KiB
C
84 lines
2.2 KiB
C
/*
|
|
* Copyright (c) 2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de>
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
*/
|
|
|
|
#include <common.h>
|
|
#include <image.h>
|
|
#include <android_image.h>
|
|
|
|
static char andr_tmp_str[ANDR_BOOT_ARGS_SIZE + 1];
|
|
|
|
int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
|
|
ulong *os_data, ulong *os_len)
|
|
{
|
|
/*
|
|
* Not all Android tools use the id field for signing the image with
|
|
* sha1 (or anything) so we don't check it. It is not obvious that the
|
|
* string is null terminated so we take care of this.
|
|
*/
|
|
strncpy(andr_tmp_str, hdr->name, ANDR_BOOT_NAME_SIZE);
|
|
andr_tmp_str[ANDR_BOOT_NAME_SIZE] = '\0';
|
|
if (strlen(andr_tmp_str))
|
|
printf("Android's image name: %s\n", andr_tmp_str);
|
|
|
|
printf("Kernel load addr 0x%08x size %u KiB\n",
|
|
hdr->kernel_addr, DIV_ROUND_UP(hdr->kernel_size, 1024));
|
|
strncpy(andr_tmp_str, hdr->cmdline, ANDR_BOOT_ARGS_SIZE);
|
|
andr_tmp_str[ANDR_BOOT_ARGS_SIZE] = '\0';
|
|
if (strlen(andr_tmp_str)) {
|
|
printf("Kernel command line: %s\n", andr_tmp_str);
|
|
setenv("bootargs", andr_tmp_str);
|
|
}
|
|
if (hdr->ramdisk_size)
|
|
printf("RAM disk load addr 0x%08x size %u KiB\n",
|
|
hdr->ramdisk_addr,
|
|
DIV_ROUND_UP(hdr->ramdisk_size, 1024));
|
|
|
|
if (os_data) {
|
|
*os_data = (ulong)hdr;
|
|
*os_data += hdr->page_size;
|
|
}
|
|
if (os_len)
|
|
*os_len = hdr->kernel_size;
|
|
return 0;
|
|
}
|
|
|
|
int android_image_check_header(const struct andr_img_hdr *hdr)
|
|
{
|
|
return memcmp(ANDR_BOOT_MAGIC, hdr->magic, ANDR_BOOT_MAGIC_SIZE);
|
|
}
|
|
|
|
ulong android_image_get_end(const struct andr_img_hdr *hdr)
|
|
{
|
|
u32 size = 0;
|
|
/*
|
|
* The header takes a full page, the remaining components are aligned
|
|
* on page boundary
|
|
*/
|
|
size += hdr->page_size;
|
|
size += ALIGN(hdr->kernel_size, hdr->page_size);
|
|
size += ALIGN(hdr->ramdisk_size, hdr->page_size);
|
|
size += ALIGN(hdr->second_size, hdr->page_size);
|
|
|
|
return size;
|
|
}
|
|
|
|
ulong android_image_get_kload(const struct andr_img_hdr *hdr)
|
|
{
|
|
return hdr->kernel_addr;
|
|
}
|
|
|
|
int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
|
|
ulong *rd_data, ulong *rd_len)
|
|
{
|
|
if (!hdr->ramdisk_size)
|
|
return -1;
|
|
*rd_data = (unsigned long)hdr;
|
|
*rd_data += hdr->page_size;
|
|
*rd_data += ALIGN(hdr->kernel_size, hdr->page_size);
|
|
|
|
*rd_len = hdr->ramdisk_size;
|
|
return 0;
|
|
}
|