]>
git.ipfire.org Git - people/ms/u-boot.git/blob - common/image-android.c
2 * Copyright (c) 2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de>
4 * SPDX-License-Identifier: GPL-2.0+
9 #include <android_image.h>
13 static char andr_tmp_str
[ANDR_BOOT_ARGS_SIZE
+ 1];
16 * android_image_get_kernel() - processes kernel part of Android boot images
17 * @hdr: Pointer to image header, which is at the start
19 * @verify: Checksum verification flag. Currently unimplemented.
20 * @os_data: Pointer to a ulong variable, will hold os data start
22 * @os_len: Pointer to a ulong variable, will hold os data length.
24 * This function returns the os image's start address and length. Also,
25 * it appends the kernel command line to the bootargs env variable.
27 * Return: Zero, os start address and length on success,
28 * otherwise on failure.
30 int android_image_get_kernel(const struct andr_img_hdr
*hdr
, int verify
,
31 ulong
*os_data
, ulong
*os_len
)
34 * Not all Android tools use the id field for signing the image with
35 * sha1 (or anything) so we don't check it. It is not obvious that the
36 * string is null terminated so we take care of this.
38 strncpy(andr_tmp_str
, hdr
->name
, ANDR_BOOT_NAME_SIZE
);
39 andr_tmp_str
[ANDR_BOOT_NAME_SIZE
] = '\0';
40 if (strlen(andr_tmp_str
))
41 printf("Android's image name: %s\n", andr_tmp_str
);
43 printf("Kernel load addr 0x%08x size %u KiB\n",
44 hdr
->kernel_addr
, DIV_ROUND_UP(hdr
->kernel_size
, 1024));
48 printf("Kernel command line: %s\n", hdr
->cmdline
);
49 len
+= strlen(hdr
->cmdline
);
52 char *bootargs
= getenv("bootargs");
54 len
+= strlen(bootargs
);
56 char *newbootargs
= malloc(len
+ 2);
58 puts("Error: malloc in android_image_get_kernel failed!\n");
64 strcpy(newbootargs
, bootargs
);
65 strcat(newbootargs
, " ");
68 strcat(newbootargs
, hdr
->cmdline
);
70 setenv("bootargs", newbootargs
);
73 *os_data
= (ulong
)hdr
;
74 *os_data
+= hdr
->page_size
;
77 *os_len
= hdr
->kernel_size
;
81 int android_image_check_header(const struct andr_img_hdr
*hdr
)
83 return memcmp(ANDR_BOOT_MAGIC
, hdr
->magic
, ANDR_BOOT_MAGIC_SIZE
);
86 ulong
android_image_get_end(const struct andr_img_hdr
*hdr
)
90 * The header takes a full page, the remaining components are aligned
94 end
+= hdr
->page_size
;
95 end
+= ALIGN(hdr
->kernel_size
, hdr
->page_size
);
96 end
+= ALIGN(hdr
->ramdisk_size
, hdr
->page_size
);
97 end
+= ALIGN(hdr
->second_size
, hdr
->page_size
);
102 ulong
android_image_get_kload(const struct andr_img_hdr
*hdr
)
104 return hdr
->kernel_addr
;
107 int android_image_get_ramdisk(const struct andr_img_hdr
*hdr
,
108 ulong
*rd_data
, ulong
*rd_len
)
110 if (!hdr
->ramdisk_size
)
113 printf("RAM disk load addr 0x%08x size %u KiB\n",
114 hdr
->ramdisk_addr
, DIV_ROUND_UP(hdr
->ramdisk_size
, 1024));
116 *rd_data
= (unsigned long)hdr
;
117 *rd_data
+= hdr
->page_size
;
118 *rd_data
+= ALIGN(hdr
->kernel_size
, hdr
->page_size
);
120 *rd_len
= hdr
->ramdisk_size
;