summaryrefslogtreecommitdiffstats
path: root/mkbootimg
diff options
context:
space:
mode:
authorSteve Kondik <steve@cyngn.com>2010-08-02 11:23:47 -0700
committerAdnan Begovic <adnan@cyngn.com>2015-10-09 11:30:26 -0700
commitcbe1aab12c5976e69ad4efe7cd3823351c2818e6 (patch)
tree5d4c2e017533b21773416db26900a5c690cea3d9 /mkbootimg
parent5f33a9460d301557692c46e07e40c0cf46426e08 (diff)
downloadsystem_core-cbe1aab12c5976e69ad4efe7cd3823351c2818e6.zip
system_core-cbe1aab12c5976e69ad4efe7cd3823351c2818e6.tar.gz
system_core-cbe1aab12c5976e69ad4efe7cd3823351c2818e6.tar.bz2
Forward-port mkbootimg / unpackbootimg support
* Mostly from Koush and Seth Shelnutt unpackbootimg (squashed) unpackbootimg ported forward from eclair Change-Id: I74d2df0b47d40e7105cc58c2b05f8f383dc7f8a0 port forward pagesize arg from eclair Change-Id: Ia789a4f392a3890aa0efa7efb42032482b48beb0 unpackbootimg should output BOARD_PAGE_SIZE Change-Id: Ieb5cda01943a33da97eee4d025f56c2c6e7560e8 output page size in mkbootimg add an option to override the pagesize for boot images created by nubs. ie, acer liquid mkliquidbootimg. Change-Id: Ie0c7e67edf5ae59019517e72b9be8c0b81388e41 Update unpackbootimg to verify the Android boot image magic value. It will also search the first 512 bytes for padding. Change-Id: I490cba05f2bb616a3f64e3271ecaa61eb9e64be8 unpackbootimg: Fix up the padding search in case the magic does not fall on a 8 byte boundary. Change-Id: I57471f9c2117cd7965b6958ea0aa88e356436da6 unpackbootimg: Fix magic search. Change-Id: I68470b637556a08e48ff72b7ef8811cba13b04ad unpackbootimg: apparently mkbootimg no longer accepts hex values Change-Id: I95a33f7b40470e4500d418d863a65a75e7aa8499 unpackbootimg: Need to also update the written file. Change-Id: I45faddbae85273c79b2837f97933634b6e70546f ramdiskaddr is now ramdisk_offset Change-Id: I3bf83af5f7001f581506dc7fd9b1eb653334ad35 unpackbootimg: remove host LOCAL_MODULE_TAG Change-Id: I199d680dc5ab8bf50f5be65c29095bf3adade695 unpackbootimg: Add support for device trees Change-Id: I340eed99d2274a2f4cbaf5a9f27726ff3a9302e5 unpackbootimg: Add support for detecting lz4 compressed ramdisks This will check for lz4 magic, and if found change the extension of the file. Else it'll fall back to the default behavior of assuming gzip. This has been tested with stock LS980 boot images and LS970 boot images for lz4 and gzip respectively. Change-Id: If2139ff172397b6db079ffb7ab9cb61897c38fb3 unpackbootimg: Add support for dumping ramdisk offset Change-Id: Ic62b9fe61db4435ecbc52b66db5ffc9b9d79cbb4 unpackbootimg: Add support for second, second_offset and tags_offset. Change-Id: Ia7ef7f00191dbf2c44736c4e4d980f72afa8c253
Diffstat (limited to 'mkbootimg')
-rw-r--r--mkbootimg/Android.mk29
-rw-r--r--mkbootimg/mkbootimg.c2
-rw-r--r--mkbootimg/unpackbootimg.c211
3 files changed, 242 insertions, 0 deletions
diff --git a/mkbootimg/Android.mk b/mkbootimg/Android.mk
index 0c9b0c6..c3fe06a 100644
--- a/mkbootimg/Android.mk
+++ b/mkbootimg/Android.mk
@@ -10,4 +10,33 @@ LOCAL_MODULE := mkbootimg
include $(BUILD_HOST_EXECUTABLE)
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := unpackbootimg.c
+LOCAL_MODULE := unpackbootimg
+include $(BUILD_HOST_EXECUTABLE)
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := mkbootimg.c
+LOCAL_STATIC_LIBRARIES := libmincrypt libcutils libc
+LOCAL_MODULE := utility_mkbootimg
+LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE_STEM := mkbootimg
+LOCAL_MODULE_CLASS := UTILITY_EXECUTABLES
+LOCAL_UNSTRIPPED_PATH := $(PRODUCT_OUT)/symbols/utilities
+LOCAL_MODULE_PATH := $(PRODUCT_OUT)/utilities
+LOCAL_FORCE_STATIC_EXECUTABLE := true
+include $(BUILD_EXECUTABLE)
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := unpackbootimg.c
+LOCAL_STATIC_LIBRARIES := libcutils libc
+LOCAL_MODULE := utility_unpackbootimg
+LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE_STEM := unpackbootimg
+LOCAL_MODULE_CLASS := UTILITY_EXECUTABLES
+LOCAL_UNSTRIPPED_PATH := $(PRODUCT_OUT)/symbols/utilities
+LOCAL_MODULE_PATH := $(PRODUCT_OUT)/utilities
+LOCAL_FORCE_STATIC_EXECUTABLE := true
+include $(BUILD_EXECUTABLE)
+
$(call dist-for-goals,dist_files,$(LOCAL_BUILT_MODULE))
diff --git a/mkbootimg/mkbootimg.c b/mkbootimg/mkbootimg.c
index 2fb8777..f3028cb 100644
--- a/mkbootimg/mkbootimg.c
+++ b/mkbootimg/mkbootimg.c
@@ -67,6 +67,8 @@ int usage(void)
" [ --base <address> ]\n"
" [ --pagesize <pagesize> ]\n"
" [ --dt <filename> ]\n"
+ " [ --ramdisk_offset <address> ]\n"
+ " [ --tags_offset <address> ]\n"
" [ --id ]\n"
" -o|--output <filename>\n"
);
diff --git a/mkbootimg/unpackbootimg.c b/mkbootimg/unpackbootimg.c
new file mode 100644
index 0000000..3d2fda7
--- /dev/null
+++ b/mkbootimg/unpackbootimg.c
@@ -0,0 +1,211 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <limits.h>
+#include <libgen.h>
+
+#include "mincrypt/sha.h"
+#include "bootimg.h"
+
+typedef unsigned char byte;
+
+int read_padding(FILE* f, unsigned itemsize, int pagesize)
+{
+ byte* buf = (byte*)malloc(sizeof(byte) * pagesize);
+ unsigned pagemask = pagesize - 1;
+ unsigned count;
+
+ if((itemsize & pagemask) == 0) {
+ free(buf);
+ return 0;
+ }
+
+ count = pagesize - (itemsize & pagemask);
+
+ fread(buf, count, 1, f);
+ free(buf);
+ return count;
+}
+
+void write_string_to_file(char* file, char* string)
+{
+ FILE* f = fopen(file, "w");
+ fwrite(string, strlen(string), 1, f);
+ fwrite("\n", 1, 1, f);
+ fclose(f);
+}
+
+int usage() {
+ printf("usage: unpackbootimg\n");
+ printf("\t-i|--input boot.img\n");
+ printf("\t[ -o|--output output_directory]\n");
+ printf("\t[ -p|--pagesize <size-in-hexadecimal> ]\n");
+ return 0;
+}
+
+int main(int argc, char** argv)
+{
+ char tmp[PATH_MAX];
+ char* directory = "./";
+ char* filename = NULL;
+ int pagesize = 0;
+
+ argc--;
+ argv++;
+ while(argc > 0){
+ char *arg = argv[0];
+ char *val = argv[1];
+ argc -= 2;
+ argv += 2;
+ if(!strcmp(arg, "--input") || !strcmp(arg, "-i")) {
+ filename = val;
+ } else if(!strcmp(arg, "--output") || !strcmp(arg, "-o")) {
+ directory = val;
+ } else if(!strcmp(arg, "--pagesize") || !strcmp(arg, "-p")) {
+ pagesize = strtoul(val, 0, 16);
+ } else {
+ return usage();
+ }
+ }
+
+ if (filename == NULL) {
+ return usage();
+ }
+
+ int total_read = 0;
+ FILE* f = fopen(filename, "rb");
+ boot_img_hdr header;
+
+ //printf("Reading header...\n");
+ int i;
+ for (i = 0; i <= 512; i++) {
+ fseek(f, i, SEEK_SET);
+ fread(tmp, BOOT_MAGIC_SIZE, 1, f);
+ if (memcmp(tmp, BOOT_MAGIC, BOOT_MAGIC_SIZE) == 0)
+ break;
+ }
+ total_read = i;
+ if (i > 512) {
+ printf("Android boot magic not found.\n");
+ return 1;
+ }
+ fseek(f, i, SEEK_SET);
+ printf("Android magic found at: %d\n", i);
+
+ fread(&header, sizeof(header), 1, f);
+ printf("BOARD_KERNEL_CMDLINE %s\n", header.cmdline);
+ printf("BOARD_KERNEL_BASE %08x\n", header.kernel_addr - 0x00008000);
+ printf("BOARD_RAMDISK_OFFSET %08x\n", header.ramdisk_addr - header.kernel_addr + 0x00008000);
+ printf("BOARD_SECOND_OFFSET %08x\n", header.second_addr - header.kernel_addr + 0x00008000);
+ printf("BOARD_TAGS_OFFSET %08x\n",header.tags_addr - header.kernel_addr + 0x00008000);
+ printf("BOARD_PAGE_SIZE %d\n", header.page_size);
+ printf("BOARD_SECOND_SIZE %d\n", header.second_size);
+ printf("BOARD_DT_SIZE %d\n", header.dt_size);
+
+ if (pagesize == 0) {
+ pagesize = header.page_size;
+ }
+
+ //printf("cmdline...\n");
+ sprintf(tmp, "%s/%s", directory, basename(filename));
+ strcat(tmp, "-cmdline");
+ write_string_to_file(tmp, header.cmdline);
+
+ //printf("base...\n");
+ sprintf(tmp, "%s/%s", directory, basename(filename));
+ strcat(tmp, "-base");
+ char basetmp[200];
+ sprintf(basetmp, "%08x", header.kernel_addr - 0x00008000);
+ write_string_to_file(tmp, basetmp);
+
+ //printf("ramdisk_offset...\n");
+ sprintf(tmp, "%s/%s", directory, basename(filename));
+ strcat(tmp, "-ramdisk_offset");
+ char ramdisktmp[200];
+ sprintf(ramdisktmp, "%08x", header.ramdisk_addr - header.kernel_addr + 0x00008000);
+ write_string_to_file(tmp, ramdisktmp);
+
+ //printf("second_offset...\n");
+ sprintf(tmp, "%s/%s", directory, basename(filename));
+ strcat(tmp, "-second_offset");
+ char secondtmp[200];
+ sprintf(secondtmp, "%08x", header.second_addr - header.kernel_addr + 0x00008000);
+ write_string_to_file(tmp, secondtmp);
+
+ //printf("tags_offset...\n");
+ sprintf(tmp, "%s/%s", directory, basename(filename));
+ strcat(tmp, "-tags_offset");
+ char tagstmp[200];
+ sprintf(tagstmp, "%08x", header.tags_addr - header.kernel_addr + 0x00008000);
+ write_string_to_file(tmp, tagstmp);
+
+ //printf("pagesize...\n");
+ sprintf(tmp, "%s/%s", directory, basename(filename));
+ strcat(tmp, "-pagesize");
+ char pagesizetmp[200];
+ sprintf(pagesizetmp, "%d", header.page_size);
+ write_string_to_file(tmp, pagesizetmp);
+
+ total_read += sizeof(header);
+ //printf("total read: %d\n", total_read);
+ total_read += read_padding(f, sizeof(header), pagesize);
+
+ sprintf(tmp, "%s/%s", directory, basename(filename));
+ strcat(tmp, "-zImage");
+ FILE *k = fopen(tmp, "wb");
+ byte* kernel = (byte*)malloc(header.kernel_size);
+ //printf("Reading kernel...\n");
+ fread(kernel, header.kernel_size, 1, f);
+ total_read += header.kernel_size;
+ fwrite(kernel, header.kernel_size, 1, k);
+ fclose(k);
+
+ //printf("total read: %d\n", header.kernel_size);
+ total_read += read_padding(f, header.kernel_size, pagesize);
+
+
+ byte* ramdisk = (byte*)malloc(header.ramdisk_size);
+ //printf("Reading ramdisk...\n");
+ fread(ramdisk, header.ramdisk_size, 1, f);
+ total_read += header.ramdisk_size;
+ sprintf(tmp, "%s/%s", directory, basename(filename));
+ if(ramdisk[0] == 0x02 && ramdisk[1]== 0x21)
+ strcat(tmp, "-ramdisk.lz4");
+ else
+ strcat(tmp, "-ramdisk.gz");
+ FILE *r = fopen(tmp, "wb");
+ fwrite(ramdisk, header.ramdisk_size, 1, r);
+ fclose(r);
+
+ total_read += read_padding(f, header.ramdisk_size, pagesize);
+
+ sprintf(tmp, "%s/%s", directory, basename(filename));
+ strcat(tmp, "-second");
+ FILE *s = fopen(tmp, "wb");
+ byte* second = (byte*)malloc(header.second_size);
+ //printf("Reading second...\n");
+ fread(second, header.second_size, 1, f);
+ total_read += header.second_size;
+ fwrite(second, header.second_size, 1, r);
+ fclose(s);
+
+ total_read += read_padding(f, header.second_size, pagesize);
+
+ sprintf(tmp, "%s/%s", directory, basename(filename));
+ strcat(tmp, "-dt");
+ FILE *d = fopen(tmp, "wb");
+ byte* dt = (byte*)malloc(header.dt_size);
+ //printf("Reading dt...\n");
+ fread(dt, header.dt_size, 1, f);
+ total_read += header.dt_size;
+ fwrite(dt, header.dt_size, 1, r);
+ fclose(d);
+
+ fclose(f);
+
+ //printf("Total Read: %d\n", total_read);
+ return 0;
+}