2 * Copyright (c) 2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de>
4 * SPDX-License-Identifier: GPL-2.0+
9 #include <android_image.h>
11 static char andr_tmp_str[ANDR_BOOT_ARGS_SIZE + 1];
13 int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
14 ulong *os_data, ulong *os_len)
17 * Not all Android tools use the id field for signing the image with
18 * sha1 (or anything) so we don't check it. It is not obvious that the
19 * string is null terminated so we take care of this.
21 strncpy(andr_tmp_str, hdr->name, ANDR_BOOT_NAME_SIZE);
22 andr_tmp_str[ANDR_BOOT_NAME_SIZE] = '\0';
23 if (strlen(andr_tmp_str))
24 printf("Android's image name: %s\n", andr_tmp_str);
26 printf("Kernel load addr 0x%08x size %u KiB\n",
27 hdr->kernel_addr, DIV_ROUND_UP(hdr->kernel_size, 1024));
28 strncpy(andr_tmp_str, hdr->cmdline, ANDR_BOOT_ARGS_SIZE);
29 andr_tmp_str[ANDR_BOOT_ARGS_SIZE] = '\0';
30 if (strlen(andr_tmp_str)) {
31 printf("Kernel command line: %s\n", andr_tmp_str);
32 setenv("bootargs", andr_tmp_str);
34 if (hdr->ramdisk_size)
35 printf("RAM disk load addr 0x%08x size %u KiB\n",
37 DIV_ROUND_UP(hdr->ramdisk_size, 1024));
40 *os_data = (ulong)hdr;
41 *os_data += hdr->page_size;
44 *os_len = hdr->kernel_size;
48 int android_image_check_header(const struct andr_img_hdr *hdr)
50 return memcmp(ANDR_BOOT_MAGIC, hdr->magic, ANDR_BOOT_MAGIC_SIZE);
53 ulong android_image_get_end(const struct andr_img_hdr *hdr)
57 * The header takes a full page, the remaining components are aligned
60 size += hdr->page_size;
61 size += ALIGN(hdr->kernel_size, hdr->page_size);
62 size += ALIGN(hdr->ramdisk_size, hdr->page_size);
63 size += ALIGN(hdr->second_size, hdr->page_size);
68 ulong android_image_get_kload(const struct andr_img_hdr *hdr)
70 return hdr->kernel_addr;
73 int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
74 ulong *rd_data, ulong *rd_len)
76 if (!hdr->ramdisk_size)
78 *rd_data = (unsigned long)hdr;
79 *rd_data += hdr->page_size;
80 *rd_data += ALIGN(hdr->kernel_size, hdr->page_size);
82 *rd_len = hdr->ramdisk_size;