Add amonet microloader support

This commit is contained in:
LoveSy 2023-03-13 21:34:10 +08:00 committed by John Wu
parent a07d4080b6
commit 2eef542054
3 changed files with 16 additions and 0 deletions

View File

@ -266,6 +266,14 @@ dyn_img_hdr *boot_img::create_hdr(uint8_t *addr, format_t type) {
flags[ACCLAIM_FLAG] = true; flags[ACCLAIM_FLAG] = true;
fprintf(stderr, "ACCLAIM_LOADER\n"); fprintf(stderr, "ACCLAIM_LOADER\n");
addr += ACCLAIM_PRE_HEADER_SZ; addr += ACCLAIM_PRE_HEADER_SZ;
} else if (str_contains(string_view((const char *) addr, AMONET_MICROLOADER_SZ), AMONET_MICROLOADER_MAGIC) &&
string_view((const char *)addr + AMONET_MICROLOADER_SZ, BOOT_MAGIC_SIZE) == BOOT_MAGIC) {
flags[AMONET_FLAG] = true;
fprintf(stderr, "AMONET_MICROLOADER\n");
uint8_t microloader[AMONET_MICROLOADER_SZ];
memcpy(microloader, addr, AMONET_MICROLOADER_SZ);
memcpy(addr, addr + AMONET_MICROLOADER_SZ, AMONET_MICROLOADER_SZ);
memcpy(addr + AMONET_MICROLOADER_SZ, microloader, AMONET_MICROLOADER_SZ);
} }
// addr could be adjusted // addr could be adjusted
@ -788,4 +796,9 @@ void repack(const char *src_img, const char *out_img, bool skip_comp) {
auto b_hdr = reinterpret_cast<blob_hdr *>(out.buf); auto b_hdr = reinterpret_cast<blob_hdr *>(out.buf);
b_hdr->size = off.total - sizeof(blob_hdr); b_hdr->size = off.total - sizeof(blob_hdr);
} }
if (boot.flags[AMONET_FLAG]) {
memcpy(out.buf + off.header + AMONET_MICROLOADER_SZ, out.buf + off.header, AMONET_MICROLOADER_SZ);
memcpy(out.buf + off.header, boot.hdr_addr + AMONET_MICROLOADER_SZ, AMONET_MICROLOADER_SZ);
}
} }

View File

@ -556,6 +556,7 @@ enum {
BLOB_FLAG, BLOB_FLAG,
NOOKHD_FLAG, NOOKHD_FLAG,
ACCLAIM_FLAG, ACCLAIM_FLAG,
AMONET_FLAG,
AVB_FLAG, AVB_FLAG,
ZIMAGE_KERNEL, ZIMAGE_KERNEL,
BOOT_FLAGS_MAX BOOT_FLAGS_MAX

View File

@ -57,6 +57,8 @@ typedef enum {
#define NOOKHD_PRE_HEADER_SZ 1048576 #define NOOKHD_PRE_HEADER_SZ 1048576
#define ACCLAIM_MAGIC "BauwksBoot" #define ACCLAIM_MAGIC "BauwksBoot"
#define ACCLAIM_PRE_HEADER_SZ 262144 #define ACCLAIM_PRE_HEADER_SZ 262144
#define AMONET_MICROLOADER_SZ 1024
#define AMONET_MICROLOADER_MAGIC "microloader"
#define AVB_FOOTER_MAGIC "AVBf" #define AVB_FOOTER_MAGIC "AVBf"
#define AVB_MAGIC "AVB0" #define AVB_MAGIC "AVB0"
#define ZIMAGE_MAGIC "\x18\x28\x6f\x01" #define ZIMAGE_MAGIC "\x18\x28\x6f\x01"