Commit eed86c76 authored by topjohnwu's avatar topjohnwu

Add support to PXA devices

Close #340
parent c471bb6f
This diff is collapsed.
...@@ -21,17 +21,10 @@ ...@@ -21,17 +21,10 @@
#ifndef _BOOT_IMAGE_H_ #ifndef _BOOT_IMAGE_H_
#define _BOOT_IMAGE_H_ #define _BOOT_IMAGE_H_
typedef struct boot_img_hdr boot_img_hdr;
#define BOOT_MAGIC "ANDROID!" #define BOOT_MAGIC "ANDROID!"
#define BOOT_MAGIC_SIZE 8
#define BOOT_NAME_SIZE 16
#define BOOT_ARGS_SIZE 512
#define BOOT_EXTRA_ARGS_SIZE 1024
struct boot_img_hdr typedef struct boot_img_hdr {
{ char magic[8];
uint8_t magic[BOOT_MAGIC_SIZE];
uint32_t kernel_size; /* size in bytes */ uint32_t kernel_size; /* size in bytes */
uint32_t kernel_addr; /* physical load addr */ uint32_t kernel_addr; /* physical load addr */
...@@ -53,16 +46,44 @@ struct boot_img_hdr ...@@ -53,16 +46,44 @@ struct boot_img_hdr
* os_version = ver << 11 | lvl */ * os_version = ver << 11 | lvl */
uint32_t os_version; uint32_t os_version;
uint8_t name[BOOT_NAME_SIZE]; /* asciiz product name */ char name[16]; /* asciiz product name */
char cmdline[512];
uint32_t id[8]; /* timestamp / checksum / sha1 / etc */
/* Supplemental command line data; kept here to maintain
* binary compatibility with older versions of mkbootimg */
char extra_cmdline[1024];
} __attribute__((packed)) boot_img_hdr ;
typedef struct pxa_boot_img_hdr {
char magic[8];
uint32_t kernel_size; /* size in bytes */
uint32_t kernel_addr; /* physical load addr */
uint32_t ramdisk_size; /* size in bytes */
uint32_t ramdisk_addr; /* physical load addr */
uint32_t second_size; /* size in bytes */
uint32_t second_addr; /* physical load addr */
uint32_t extra_size; /* extra blob size in bytes */
uint32_t unknown; /* unknown value */
uint32_t tags_addr; /* physical addr for kernel tags */
uint32_t page_size; /* flash page size we assume */
uint8_t cmdline[BOOT_ARGS_SIZE]; char name[24]; /* asciiz product name */
char cmdline[512];
uint32_t id[8]; /* timestamp / checksum / sha1 / etc */ uint32_t id[8]; /* timestamp / checksum / sha1 / etc */
/* Supplemental command line data; kept here to maintain /* Supplemental command line data; kept here to maintain
* binary compatibility with older versions of mkbootimg */ * binary compatibility with older versions of mkbootimg */
uint8_t extra_cmdline[BOOT_EXTRA_ARGS_SIZE]; char extra_cmdline[1024];
} __attribute__((packed)); } __attribute__((packed)) pxa_boot_img_hdr;
/* /*
** +-----------------+ ** +-----------------+
...@@ -74,7 +95,7 @@ struct boot_img_hdr ...@@ -74,7 +95,7 @@ struct boot_img_hdr
** +-----------------+ ** +-----------------+
** | second stage | o pages ** | second stage | o pages
** +-----------------+ ** +-----------------+
** | extra blobs | p pages ** | extra blob | p pages
** +-----------------+ ** +-----------------+
** **
** n = (kernel_size + page_size - 1) / page_size ** n = (kernel_size + page_size - 1) / page_size
...@@ -95,33 +116,47 @@ struct boot_img_hdr ...@@ -95,33 +116,47 @@ struct boot_img_hdr
*/ */
typedef struct mtk_hdr { typedef struct mtk_hdr {
uint8_t magic[4]; /* MTK magic */ uint32_t magic; /* MTK magic */
uint32_t size; /* Size of the content */ uint32_t size; /* Size of the content */
uint8_t name[32]; /* The type of the header */ char name[32]; /* The type of the header */
} mtk_hdr; } __attribute__((packed)) mtk_hdr;
// Flags // Flags
#define MTK_KERNEL 0x1 #define MTK_KERNEL 0x01
#define MTK_RAMDISK 0x2 #define MTK_RAMDISK 0x02
#define CHROMEOS_FLAG 0x4 #define CHROMEOS_FLAG 0x04
#define PXA_FLAG 0x08
typedef struct boot_img { typedef struct boot_img {
// Memory map of the whole image
void *map_addr;
size_t map_size; size_t map_size;
uint32_t dt_size;
size_t tail_size; // Headers
void *hdr; /* Either boot_img_hdr or pxa_boot_img_hdr */
mtk_hdr *k_hdr; /* MTK kernel header */
mtk_hdr *r_hdr; /* MTK ramdisk header */
// Flags to indicate the state of current boot image
uint8_t flags; uint8_t flags;
file_t kernel_type, ramdisk_type;
boot_img_hdr hdr; // The format of kernel and ramdisk
mtk_hdr mtk_kernel_hdr, mtk_ramdisk_hdr; file_t kernel_type;
file_t ramdisk_type;
void *map_addr; // Pointer to dtb that is appended after kernel
void *kernel;
void *dtb; void *dtb;
uint32_t dt_size;
// Pointer to end of image
void *tail;
size_t tail_size;
// Pointers to blocks defined in header
void *kernel;
void *ramdisk; void *ramdisk;
void *second; void *second;
void *extra; void *extra;
void *tail;
} boot_img; } boot_img;
#endif #endif
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#define NEW_BOOT "new-boot.img" #define NEW_BOOT "new-boot.img"
// Main entries // Main entries
void unpack(const char *image); int unpack(const char *image);
void repack(const char* orig_image, const char* out_image); void repack(const char* orig_image, const char* out_image);
void hexpatch(const char *image, const char *from, const char *to); void hexpatch(const char *image, const char *from, const char *to);
int parse_img(const char *image, boot_img *boot); int parse_img(const char *image, boot_img *boot);
......
...@@ -136,9 +136,9 @@ int main(int argc, char *argv[]) { ...@@ -136,9 +136,9 @@ int main(int argc, char *argv[]) {
munmap(buf, size); munmap(buf, size);
} else if (argc > 2 && strcmp(argv[1], "--parse") == 0) { } else if (argc > 2 && strcmp(argv[1], "--parse") == 0) {
boot_img boot; boot_img boot;
exit(parse_img(argv[2], &boot)); return parse_img(argv[2], &boot);
} else if (argc > 2 && strcmp(argv[1], "--unpack") == 0) { } else if (argc > 2 && strcmp(argv[1], "--unpack") == 0) {
unpack(argv[2]); return unpack(argv[2]);
} else if (argc > 2 && strcmp(argv[1], "--repack") == 0) { } else if (argc > 2 && strcmp(argv[1], "--repack") == 0) {
repack(argv[2], argc > 3 ? argv[3] : NEW_BOOT); repack(argv[2], argc > 3 ? argv[3] : NEW_BOOT);
} else if (argc > 2 && strcmp(argv[1], "--decompress") == 0) { } else if (argc > 2 && strcmp(argv[1], "--decompress") == 0) {
...@@ -157,7 +157,8 @@ int main(int argc, char *argv[]) { ...@@ -157,7 +157,8 @@ int main(int argc, char *argv[]) {
char *cmd = argv[1] + 5; char *cmd = argv[1] + 5;
if (*cmd == '\0') usage(argv[0]); if (*cmd == '\0') usage(argv[0]);
else ++cmd; else ++cmd;
if (dtb_commands(cmd, argc - 2, argv + 2)) usage(argv[0]); if (dtb_commands(cmd, argc - 2, argv + 2))
usage(argv[0]);
} else { } else {
usage(argv[0]); usage(argv[0]);
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
file_t check_type(const void *buf) { file_t check_type(const void *buf) {
if (memcmp(buf, CHROMEOS_MAGIC, 8) == 0) { if (memcmp(buf, CHROMEOS_MAGIC, 8) == 0) {
return CHROMEOS; return CHROMEOS;
} else if (memcmp(buf, BOOT_MAGIC, BOOT_MAGIC_SIZE) == 0) { } else if (memcmp(buf, BOOT_MAGIC, 8) == 0) {
return AOSP; return AOSP;
} else if (memcmp(buf, ELF32_MAGIC, 5) == 0) { } else if (memcmp(buf, ELF32_MAGIC, 5) == 0) {
return ELF32; return ELF32;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment