Sebastian Siewior | 686d667 | 2014-05-05 15:08:09 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de> |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <image.h> |
| 9 | #include <android_image.h> |
| 10 | |
| 11 | static char andr_tmp_str[ANDR_BOOT_ARGS_SIZE + 1]; |
| 12 | |
| 13 | int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify, |
| 14 | ulong *os_data, ulong *os_len) |
| 15 | { |
| 16 | /* |
| 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. |
| 20 | */ |
| 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); |
| 25 | |
| 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); |
| 33 | } |
| 34 | if (hdr->ramdisk_size) |
| 35 | printf("RAM disk load addr 0x%08x size %u KiB\n", |
| 36 | hdr->ramdisk_addr, |
| 37 | DIV_ROUND_UP(hdr->ramdisk_size, 1024)); |
| 38 | |
| 39 | if (os_data) { |
| 40 | *os_data = (ulong)hdr; |
| 41 | *os_data += hdr->page_size; |
| 42 | } |
| 43 | if (os_len) |
| 44 | *os_len = hdr->kernel_size; |
| 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | int android_image_check_header(const struct andr_img_hdr *hdr) |
| 49 | { |
| 50 | return memcmp(ANDR_BOOT_MAGIC, hdr->magic, ANDR_BOOT_MAGIC_SIZE); |
| 51 | } |
| 52 | |
| 53 | ulong android_image_get_end(const struct andr_img_hdr *hdr) |
| 54 | { |
| 55 | u32 size = 0; |
| 56 | /* |
| 57 | * The header takes a full page, the remaining components are aligned |
| 58 | * on page boundary |
| 59 | */ |
| 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); |
| 64 | |
| 65 | return size; |
| 66 | } |
| 67 | |
| 68 | ulong android_image_get_kload(const struct andr_img_hdr *hdr) |
| 69 | { |
| 70 | return hdr->kernel_addr; |
| 71 | } |
| 72 | |
| 73 | int android_image_get_ramdisk(const struct andr_img_hdr *hdr, |
| 74 | ulong *rd_data, ulong *rd_len) |
| 75 | { |
| 76 | if (!hdr->ramdisk_size) |
| 77 | return -1; |
| 78 | *rd_data = (unsigned long)hdr; |
| 79 | *rd_data += hdr->page_size; |
| 80 | *rd_data += ALIGN(hdr->kernel_size, hdr->page_size); |
| 81 | |
| 82 | *rd_len = hdr->ramdisk_size; |
| 83 | return 0; |
| 84 | } |