Skip to content

Commit

Permalink
[image] support baisc mkbootimg
Browse files Browse the repository at this point in the history
  • Loading branch information
YuzukiTsuru committed Jan 13, 2024
1 parent 170830a commit 0a15353
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/image/bimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,63 @@

#include "image_loader.h"

#define ANDR_BOOT_MAGIC "ANDROID!"
#define ANDR_BOOT_MAGIC_SIZE 8
#define ANDR_BOOT_NAME_SIZE 16
#define ANDR_BOOT_ARGS_SIZE 512
#define BOOT_EXTRA_ARGS_SIZE 1024

typedef struct linux_bimage_header {
char magic[ANDR_BOOT_MAGIC_SIZE];

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 tags_addr; /* physical addr for kernel tags */
uint32_t page_size; /* flash page size we assume */
uint32_t unused; /* reserved for future expansion: MUST be 0 */

/* operating system version and security patch level; for
* version "A.B.C" and patch level "Y-M-D":
* ver = A << 14 | B << 7 | C (7 bits for each of A, B, C)
* lvl = ((Y - 2000) & 127) << 4 | M (7 bits for Y, 4 bits for M)
* os_version = ver << 11 | lvl */
uint32_t os_version;

char name[ANDR_BOOT_NAME_SIZE]; /* asciiz product name */

char cmdline[ANDR_BOOT_ARGS_SIZE];

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[BOOT_EXTRA_ARGS_SIZE];
uint32_t recovery_dtbo_size; /* size of recovery dtbo image */
uint64_t recovery_dtbo_offset; /*physical load addr */
uint32_t header_size; /*size of boot image header in bytes */
uint32_t dtb_size;
uint64_t dtb_addr;
} __attribute__((packed)) linux_bimage_header_t;

int bImage_loader(uint8_t *addr, uint32_t *entry) {
linux_bimage_header_t *image_header = (linux_bimage_header_t *) addr;

if (!memcmp(image_header->magic, ANDR_BOOT_MAGIC, 8)) {
printk(LOG_LEVEL_DEBUG, "[IMG] kernel magic is ok\n");
printk(LOG_LEVEL_DEBUG, "[IMG] kernel_size = 0x%x\n", image_header->kernel_size);
printk(LOG_LEVEL_DEBUG, "[IMG] ramdisk_size = 0x%x\n", image_header->ramdisk_size);
rbytes = image_header->kernel_size + image_header->ramdisk_size + image_header->second_size + 4 * 1024 + 511;
} else {
printk(LOG_LEVEL_ERROR, "[IMG] kernel 0x%08x magic is error\n", addr);
return -1;
}

return -1;
}

0 comments on commit 0a15353

Please sign in to comment.