Loading cpio/mkbootfs.c +57 −16 Original line number Diff line number Diff line Loading @@ -44,6 +44,11 @@ static void fix_stat(const char *path, struct stat *s) static void _eject(struct stat *s, char *out, int olen, char *data, unsigned datasize) { // Nothing is special about this value, just picked something in the // approximate range that was being used already, and avoiding small // values which may be special. static unsigned next_inode = 300000; while(total_size & 3) { total_size++; putchar(0); Loading @@ -55,12 +60,12 @@ static void _eject(struct stat *s, char *out, int olen, char *data, unsigned dat printf("%06x%08x%08x%08x%08x%08x%08x" "%08x%08x%08x%08x%08x%08x%08x%s%c", 0x070701, (unsigned) s->st_ino, next_inode++, // s.st_ino, s->st_mode, 0, // s.st_uid, 0, // s.st_gid, 1, // s.st_nlink, (unsigned) s->st_mtime, 0, // s.st_mtime, datasize, 0, // volmajor 0, // volminor Loading Loading @@ -101,9 +106,13 @@ static void _eject_trailer() static void _archive(char *in, char *out, int ilen, int olen); static int compare(const void* a, const void* b) { return strcmp(*(const char**)a, *(const char**)b); } static void _archive_dir(char *in, char *out, int ilen, int olen) { int t; int i, t; DIR *d; struct dirent *de; Loading @@ -115,6 +124,14 @@ static void _archive_dir(char *in, char *out, int ilen, int olen) d = opendir(in); if(d == 0) die("cannot open directory '%s'", in); int size = 32; int entries = 0; char** names = malloc(size * sizeof(char*)); if (names == NULL) { fprintf(stderr, "failed to allocate dir names array (size %d)\n", size); exit(1); } while((de = readdir(d)) != 0){ /* xxx: feature? maybe some dotfiles are okay */ if(de->d_name[0] == '.') continue; Loading @@ -122,22 +139,46 @@ static void _archive_dir(char *in, char *out, int ilen, int olen) /* xxx: hack. use a real exclude list */ if(!strcmp(de->d_name, "root")) continue; t = strlen(de->d_name); if (entries >= size) { size *= 2; names = realloc(names, size * sizeof(char*)); if (names == NULL) { fprintf(stderr, "failed to reallocate dir names array (size %d)\n", size); exit(1); } } names[entries] = strdup(de->d_name); if (names[entries] == NULL) { fprintf(stderr, "failed to strdup name \"%s\"\n", de->d_name); exit(1); } ++entries; } qsort(names, entries, sizeof(char*), compare); for (i = 0; i < entries; ++i) { t = strlen(names[i]); in[ilen] = '/'; memcpy(in + ilen + 1, de->d_name, t + 1); memcpy(in + ilen + 1, names[i], t + 1); if(olen > 0) { out[olen] = '/'; memcpy(out + olen + 1, de->d_name, t + 1); memcpy(out + olen + 1, names[i], t + 1); _archive(in, out, ilen + t + 1, olen + t + 1); } else { memcpy(out, de->d_name, t + 1); memcpy(out, names[i], t + 1); _archive(in, out, ilen + t + 1, t); } in[ilen] = 0; out[olen] = 0; free(names[i]); } free(names); } static void _archive(char *in, char *out, int ilen, int olen) Loading include/cutils/native_handle.h 0 → 100644 +28 −0 Original line number Diff line number Diff line /* * Copyright (C) 2009 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 * * 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 * limitations under the License. */ #ifndef NATIVE_HANDLE_H_ #define NATIVE_HANDLE_H_ typedef struct { int version; /* sizeof(native_handle) */ int numFds; /* number of file-descriptors at &data[0] */ int numInts; /* number of ints at &data[numFds] */ int data[0]; /* numFds + numInts ints */ } native_handle; #endif /* NATIVE_HANDLE_H_ */ libmincrypt/Android.mk +7 −0 Original line number Diff line number Diff line Loading @@ -7,5 +7,12 @@ LOCAL_MODULE := libmincrypt LOCAL_SRC_FILES := rsa.c sha.c include $(BUILD_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libmincrypt LOCAL_SRC_FILES := rsa.c sha.c include $(BUILD_HOST_STATIC_LIBRARY) # TODO: drop the hyphen once these are checked in include $(LOCAL_PATH)/tools/Android.mk mkbootimg/Android.mk +1 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES := mkbootimg.c LOCAL_STATIC_LIBRARIES := libmincrypt LOCAL_MODULE := mkbootimg Loading mkbootimg/mkbootimg.c +34 −40 Original line number Diff line number Diff line Loading @@ -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) Loading Loading @@ -90,17 +90,6 @@ 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; Loading @@ -117,6 +106,8 @@ int main(int argc, char **argv) unsigned pagesize = 2048; unsigned saddr = 0; int fd; SHA_CTX ctx; uint8_t* sha; argc--; argv++; Loading Loading @@ -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 /* put a hash of the contents in the header so boot images can be * differentiated 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); 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) { Loading Loading @@ -254,4 +249,3 @@ fail: strerror(errno)); return 1; } Loading
cpio/mkbootfs.c +57 −16 Original line number Diff line number Diff line Loading @@ -44,6 +44,11 @@ static void fix_stat(const char *path, struct stat *s) static void _eject(struct stat *s, char *out, int olen, char *data, unsigned datasize) { // Nothing is special about this value, just picked something in the // approximate range that was being used already, and avoiding small // values which may be special. static unsigned next_inode = 300000; while(total_size & 3) { total_size++; putchar(0); Loading @@ -55,12 +60,12 @@ static void _eject(struct stat *s, char *out, int olen, char *data, unsigned dat printf("%06x%08x%08x%08x%08x%08x%08x" "%08x%08x%08x%08x%08x%08x%08x%s%c", 0x070701, (unsigned) s->st_ino, next_inode++, // s.st_ino, s->st_mode, 0, // s.st_uid, 0, // s.st_gid, 1, // s.st_nlink, (unsigned) s->st_mtime, 0, // s.st_mtime, datasize, 0, // volmajor 0, // volminor Loading Loading @@ -101,9 +106,13 @@ static void _eject_trailer() static void _archive(char *in, char *out, int ilen, int olen); static int compare(const void* a, const void* b) { return strcmp(*(const char**)a, *(const char**)b); } static void _archive_dir(char *in, char *out, int ilen, int olen) { int t; int i, t; DIR *d; struct dirent *de; Loading @@ -115,6 +124,14 @@ static void _archive_dir(char *in, char *out, int ilen, int olen) d = opendir(in); if(d == 0) die("cannot open directory '%s'", in); int size = 32; int entries = 0; char** names = malloc(size * sizeof(char*)); if (names == NULL) { fprintf(stderr, "failed to allocate dir names array (size %d)\n", size); exit(1); } while((de = readdir(d)) != 0){ /* xxx: feature? maybe some dotfiles are okay */ if(de->d_name[0] == '.') continue; Loading @@ -122,22 +139,46 @@ static void _archive_dir(char *in, char *out, int ilen, int olen) /* xxx: hack. use a real exclude list */ if(!strcmp(de->d_name, "root")) continue; t = strlen(de->d_name); if (entries >= size) { size *= 2; names = realloc(names, size * sizeof(char*)); if (names == NULL) { fprintf(stderr, "failed to reallocate dir names array (size %d)\n", size); exit(1); } } names[entries] = strdup(de->d_name); if (names[entries] == NULL) { fprintf(stderr, "failed to strdup name \"%s\"\n", de->d_name); exit(1); } ++entries; } qsort(names, entries, sizeof(char*), compare); for (i = 0; i < entries; ++i) { t = strlen(names[i]); in[ilen] = '/'; memcpy(in + ilen + 1, de->d_name, t + 1); memcpy(in + ilen + 1, names[i], t + 1); if(olen > 0) { out[olen] = '/'; memcpy(out + olen + 1, de->d_name, t + 1); memcpy(out + olen + 1, names[i], t + 1); _archive(in, out, ilen + t + 1, olen + t + 1); } else { memcpy(out, de->d_name, t + 1); memcpy(out, names[i], t + 1); _archive(in, out, ilen + t + 1, t); } in[ilen] = 0; out[olen] = 0; free(names[i]); } free(names); } static void _archive(char *in, char *out, int ilen, int olen) Loading
include/cutils/native_handle.h 0 → 100644 +28 −0 Original line number Diff line number Diff line /* * Copyright (C) 2009 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 * * 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 * limitations under the License. */ #ifndef NATIVE_HANDLE_H_ #define NATIVE_HANDLE_H_ typedef struct { int version; /* sizeof(native_handle) */ int numFds; /* number of file-descriptors at &data[0] */ int numInts; /* number of ints at &data[numFds] */ int data[0]; /* numFds + numInts ints */ } native_handle; #endif /* NATIVE_HANDLE_H_ */
libmincrypt/Android.mk +7 −0 Original line number Diff line number Diff line Loading @@ -7,5 +7,12 @@ LOCAL_MODULE := libmincrypt LOCAL_SRC_FILES := rsa.c sha.c include $(BUILD_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libmincrypt LOCAL_SRC_FILES := rsa.c sha.c include $(BUILD_HOST_STATIC_LIBRARY) # TODO: drop the hyphen once these are checked in include $(LOCAL_PATH)/tools/Android.mk
mkbootimg/Android.mk +1 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES := mkbootimg.c LOCAL_STATIC_LIBRARIES := libmincrypt LOCAL_MODULE := mkbootimg Loading
mkbootimg/mkbootimg.c +34 −40 Original line number Diff line number Diff line Loading @@ -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) Loading Loading @@ -90,17 +90,6 @@ 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; Loading @@ -117,6 +106,8 @@ int main(int argc, char **argv) unsigned pagesize = 2048; unsigned saddr = 0; int fd; SHA_CTX ctx; uint8_t* sha; argc--; argv++; Loading Loading @@ -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 /* put a hash of the contents in the header so boot images can be * differentiated 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); 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) { Loading Loading @@ -254,4 +249,3 @@ fail: strerror(errno)); return 1; }