summaryrefslogtreecommitdiffstats
path: root/mkbootimg
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-01-20 14:04:01 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-01-20 14:04:01 -0800
commit8ac3a138168f79b47356fb5aea2f6d95fc3147c6 (patch)
tree97e97f6ce4dbd0461e52b50192420b4a70b1b988 /mkbootimg
parent2eef60297a0ca1433d0824d6d662efd402709cfd (diff)
downloadsystem_core-8ac3a138168f79b47356fb5aea2f6d95fc3147c6.zip
system_core-8ac3a138168f79b47356fb5aea2f6d95fc3147c6.tar.gz
system_core-8ac3a138168f79b47356fb5aea2f6d95fc3147c6.tar.bz2
auto import from //branches/cupcake/...@127101
Diffstat (limited to 'mkbootimg')
-rw-r--r--mkbootimg/Android.mk1
-rw-r--r--mkbootimg/mkbootimg.c74
2 files changed, 35 insertions, 40 deletions
diff --git a/mkbootimg/Android.mk b/mkbootimg/Android.mk
index a579de0..18f0ff3 100644
--- a/mkbootimg/Android.mk
+++ b/mkbootimg/Android.mk
@@ -3,6 +3,7 @@ LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := mkbootimg.c
+LOCAL_STATIC_LIBRARIES := libmincrypt
LOCAL_MODULE := mkbootimg
diff --git a/mkbootimg/mkbootimg.c b/mkbootimg/mkbootimg.c
index fa650cf..d803cf6 100644
--- a/mkbootimg/mkbootimg.c
+++ b/mkbootimg/mkbootimg.c
@@ -2,16 +2,16 @@
**
** Copyright 2007, The Android Open Source Project
**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
**
-** http://www.apache.org/licenses/LICENSE-2.0
+** http://www.apache.org/licenses/LICENSE-2.0
**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
** limitations under the License.
*/
@@ -21,8 +21,8 @@
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
-#include <time.h>
+#include "mincrypt/sha.h"
#include "bootimg.h"
static void *load_file(const char *fn, unsigned *_sz)
@@ -82,7 +82,7 @@ int write_padding(int fd, unsigned pagesize, unsigned itemsize)
}
count = pagesize - (itemsize & pagemask);
-
+
if(write(fd, padding, count) != count) {
return -1;
} else {
@@ -90,21 +90,10 @@ int write_padding(int fd, unsigned pagesize, unsigned itemsize)
}
}
-unsigned checksum(void *_ptr, unsigned len)
-{
- unsigned chk = 0;
- unsigned char *ptr = _ptr;
- while (len > 0) {
- chk += *ptr++;
- len--;
- }
- return chk;
-}
-
int main(int argc, char **argv)
{
boot_img_hdr hdr;
-
+
char *kernel_fn = 0;
void *kernel_data = 0;
char *ramdisk_fn = 0;
@@ -117,12 +106,14 @@ int main(int argc, char **argv)
unsigned pagesize = 2048;
unsigned saddr = 0;
int fd;
-
+ SHA_CTX ctx;
+ uint8_t* sha;
+
argc--;
argv++;
memset(&hdr, 0, sizeof(hdr));
-
+
while(argc > 0){
char *arg = argv[0];
char *val = argv[1];
@@ -171,7 +162,7 @@ int main(int argc, char **argv)
}
strcpy(hdr.name, board);
-
+
hdr.kernel_addr = 0x10008000;
hdr.ramdisk_addr = 0x11000000;
if(saddr) {
@@ -181,21 +172,21 @@ int main(int argc, char **argv)
}
hdr.tags_addr = 0x10000100;
hdr.page_size = pagesize;
-
+
memcpy(hdr.magic, BOOT_MAGIC, BOOT_MAGIC_SIZE);
-
+
if(strlen(cmdline) > (BOOT_ARGS_SIZE - 1)) {
fprintf(stderr,"error: kernel commandline too large\n");
return 1;
}
strcpy((char*)hdr.cmdline, cmdline);
-
+
kernel_data = load_file(kernel_fn, &hdr.kernel_size);
if(kernel_data == 0) {
fprintf(stderr,"error: could not load kernel '%s'\n", kernel_fn);
return 1;
}
-
+
if(!strcmp(ramdisk_fn,"NONE")) {
ramdisk_data = 0;
hdr.ramdisk_size = 0;
@@ -215,15 +206,19 @@ int main(int argc, char **argv)
}
}
- /* put some stuff in the header to differentiate between
- * different boot images. SHA1 would be nicer, but this
- * isn't for crypto grade anything, just to have a quick
- * way to compare boot.imgs based on their first 2k
- */
- hdr.id[0] = (unsigned) time(0);
- hdr.id[1] = checksum(kernel_data, hdr.kernel_size);
- hdr.id[2] = checksum(ramdisk_data, hdr.ramdisk_size);
- hdr.id[3] = checksum(second_data, hdr.second_size);
+ /* put a hash of the contents in the header so boot images can be
+ * differentiated based on their first 2k.
+ */
+ SHA_init(&ctx);
+ SHA_update(&ctx, kernel_data, hdr.kernel_size);
+ SHA_update(&ctx, &hdr.kernel_size, sizeof(hdr.kernel_size));
+ SHA_update(&ctx, ramdisk_data, hdr.ramdisk_size);
+ SHA_update(&ctx, &hdr.ramdisk_size, sizeof(hdr.ramdisk_size));
+ SHA_update(&ctx, second_data, hdr.second_size);
+ SHA_update(&ctx, &hdr.second_size, sizeof(hdr.second_size));
+ sha = SHA_final(&ctx);
+ memcpy(hdr.id, sha,
+ SHA_DIGEST_SIZE > sizeof(hdr.id) ? sizeof(hdr.id) : SHA_DIGEST_SIZE);
fd = open(bootimg, O_CREAT | O_TRUNC | O_WRONLY, 0644);
if(fd < 0) {
@@ -246,7 +241,7 @@ int main(int argc, char **argv)
}
return 0;
-
+
fail:
unlink(bootimg);
close(fd);
@@ -254,4 +249,3 @@ fail:
strerror(errno));
return 1;
}
-