Commit 0d42f937 authored by topjohnwu's avatar topjohnwu

Refactor magiskboot

parent ac8372dd
This diff is collapsed.
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <stdint.h> #include <stdint.h>
#include <utility> #include <utility>
#include <bitset>
#include "format.hpp" #include "format.hpp"
/****************** /******************
...@@ -231,6 +232,7 @@ struct dyn_img_hdr { ...@@ -231,6 +232,7 @@ struct dyn_img_hdr {
decl_val(cmdline, char *) decl_val(cmdline, char *)
decl_val(id, char *) decl_val(id, char *)
decl_val(extra_cmdline, char *) decl_val(extra_cmdline, char *)
uint32_t kernel_dt_size = 0;
// v1/v2 specific // v1/v2 specific
decl_var(recovery_dtbo_size, 32) decl_var(recovery_dtbo_size, 32)
...@@ -244,6 +246,7 @@ struct dyn_img_hdr { ...@@ -244,6 +246,7 @@ struct dyn_img_hdr {
virtual size_t hdr_size() = 0; virtual size_t hdr_size() = 0;
virtual size_t hdr_space() { return page_size(); } virtual size_t hdr_space() { return page_size(); }
virtual dyn_img_hdr *clone() = 0;
const void *raw_hdr() const { return raw; } const void *raw_hdr() const { return raw; }
void print(); void print();
...@@ -276,7 +279,12 @@ name(void *ptr) { \ ...@@ -276,7 +279,12 @@ name(void *ptr) { \
raw = xmalloc(sizeof(hdr)); \ raw = xmalloc(sizeof(hdr)); \
memcpy(raw, ptr, sizeof(hdr)); \ memcpy(raw, ptr, sizeof(hdr)); \
} \ } \
size_t hdr_size() override { return sizeof(hdr); } size_t hdr_size() override { return sizeof(hdr); } \
dyn_img_hdr *clone() override { \
auto p = new name(this->raw); \
p->kernel_dt_size = kernel_dt_size; \
return p; \
};
#define __impl_val(name, hdr_name) \ #define __impl_val(name, hdr_name) \
decltype(std::declval<dyn_img_hdr>().name()) name() override { return hdr_name->name; } decltype(std::declval<dyn_img_hdr>().name()) name() override { return hdr_name->name; }
...@@ -351,7 +359,7 @@ struct dyn_img_v3 : public dyn_img_hdr { ...@@ -351,7 +359,7 @@ struct dyn_img_v3 : public dyn_img_hdr {
char *extra_cmdline() override { return &v3_hdr->cmdline[BOOT_ARGS_SIZE]; } char *extra_cmdline() override { return &v3_hdr->cmdline[BOOT_ARGS_SIZE]; }
private: private:
uint32_t page_sz; uint32_t page_sz = 4096;
}; };
#undef impl_val #undef impl_val
...@@ -383,16 +391,19 @@ struct dyn_img_vnd_v3 : public dyn_img_hdr { ...@@ -383,16 +391,19 @@ struct dyn_img_vnd_v3 : public dyn_img_hdr {
* Full Boot Image * Full Boot Image
******************/ ******************/
#define MTK_KERNEL (1 << 0) enum {
#define MTK_RAMDISK (1 << 1) MTK_KERNEL,
#define CHROMEOS_FLAG (1 << 2) MTK_RAMDISK,
#define DHTB_FLAG (1 << 3) CHROMEOS_FLAG,
#define SEANDROID_FLAG (1 << 4) DHTB_FLAG,
#define LG_BUMP_FLAG (1 << 5) SEANDROID_FLAG,
#define SHA256_FLAG (1 << 6) LG_BUMP_FLAG,
#define BLOB_FLAG (1 << 7) SHA256_FLAG,
#define NOOKHD_FLAG (1 << 8) BLOB_FLAG,
#define ACCLAIM_FLAG (1 << 9) NOOKHD_FLAG,
ACCLAIM_FLAG,
BOOT_FLAGS_MAX
};
struct boot_img { struct boot_img {
// Memory map of the whole image // Memory map of the whole image
...@@ -403,7 +414,7 @@ struct boot_img { ...@@ -403,7 +414,7 @@ struct boot_img {
dyn_img_hdr *hdr; dyn_img_hdr *hdr;
// Flags to indicate the state of current boot image // Flags to indicate the state of current boot image
uint16_t flags = 0; std::bitset<BOOT_FLAGS_MAX> flags;
// The format of kernel, ramdisk and extra // The format of kernel, ramdisk and extra
format_t k_fmt = UNKNOWN; format_t k_fmt = UNKNOWN;
...@@ -420,7 +431,6 @@ struct boot_img { ...@@ -420,7 +431,6 @@ struct boot_img {
// Pointer to dtb that is embedded in kernel // Pointer to dtb that is embedded in kernel
uint8_t *kernel_dtb; uint8_t *kernel_dtb;
uint32_t kernel_dt_size = 0;
// Pointer to end of image // Pointer to end of image
uint8_t *tail; uint8_t *tail;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#define NEW_BOOT "new-boot.img" #define NEW_BOOT "new-boot.img"
int unpack(const char *image, bool skip_decomp = false, bool hdr = false); int unpack(const char *image, bool skip_decomp = false, bool hdr = false);
void repack(const char* src_img, const char* out_img, bool skip_comp = false); void repack(const char *src_img, const char *out_img, bool skip_comp = false);
int split_image_dtb(const char *filename); int split_image_dtb(const char *filename);
int hexpatch(const char *image, const char *from, const char *to); int hexpatch(const char *image, const char *from, const char *to);
int cpio_commands(int argc, char *argv[]); int cpio_commands(int argc, char *argv[]);
......
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