mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-24 20:27:37 +00:00
magiskboot: add support for lz4 compressed dt (extra)
- legacy devices brought up to Android 10 may now use a compressed dt in a hdr_v0 AOSP dt variant extra section, so detect, decompress and recompress this - so far these have only been done using lz4 compression (latest format revision magic), e.g. LOS 17.1 victara (Moto X)
This commit is contained in:
parent
fde78be2b4
commit
e50295d337
@ -255,6 +255,7 @@ void boot_img::parse_image(uint8_t *addr) {
|
||||
|
||||
k_fmt = check_fmt(kernel, hdr->kernel_size());
|
||||
r_fmt = check_fmt(ramdisk, hdr->ramdisk_size());
|
||||
e_fmt = check_fmt(extra, hdr->extra_size());
|
||||
|
||||
// Check MTK
|
||||
if (k_fmt == MTK) {
|
||||
@ -280,6 +281,7 @@ void boot_img::parse_image(uint8_t *addr) {
|
||||
|
||||
fprintf(stderr, "KERNEL_FMT [%s]\n", fmt2name[k_fmt]);
|
||||
fprintf(stderr, "RAMDISK_FMT [%s]\n", fmt2name[r_fmt]);
|
||||
fprintf(stderr, "EXTRA_FMT [%s]\n", fmt2name[e_fmt]);
|
||||
}
|
||||
|
||||
static int find_dtb_offset(uint8_t *buf, int sz) {
|
||||
@ -371,7 +373,13 @@ int unpack(const char *image, bool nodecomp, bool hdr) {
|
||||
dump(boot.second, boot.hdr->second_size(), SECOND_FILE);
|
||||
|
||||
// Dump extra
|
||||
dump(boot.extra, boot.hdr->extra_size(), EXTRA_FILE);
|
||||
if (!nodecomp && COMPRESSED(boot.e_fmt)) {
|
||||
int fd = creat(EXTRA_FILE, 0644);
|
||||
decompress(boot.e_fmt, fd, boot.extra, boot.hdr->extra_size());
|
||||
close(fd);
|
||||
} else {
|
||||
dump(boot.extra, boot.hdr->extra_size(), EXTRA_FILE);
|
||||
}
|
||||
|
||||
// Dump recovery_dtbo
|
||||
dump(boot.recovery_dtbo, boot.hdr->recovery_dtbo_size(), RECV_DTBO_FILE);
|
||||
@ -483,7 +491,15 @@ void repack(const char* src_img, const char* out_img, bool nocomp) {
|
||||
// extra
|
||||
off.extra = lseek(fd, 0, SEEK_CUR);
|
||||
if (access(EXTRA_FILE, R_OK) == 0) {
|
||||
boot.hdr->extra_size() = restore(fd, EXTRA_FILE);
|
||||
size_t raw_size;
|
||||
void *raw_buf;
|
||||
mmap_ro(EXTRA_FILE, raw_buf, raw_size);
|
||||
if (!nocomp && !COMPRESSED_ANY(check_fmt(raw_buf, raw_size)) && COMPRESSED(boot.e_fmt)) {
|
||||
boot.hdr->extra_size() = compress(boot.e_fmt, fd, raw_buf, raw_size);
|
||||
} else {
|
||||
boot.hdr->extra_size() = xwrite(fd, raw_buf, raw_size);
|
||||
}
|
||||
munmap(raw_buf, raw_size);
|
||||
file_align();
|
||||
}
|
||||
|
||||
|
@ -303,9 +303,10 @@ struct boot_img {
|
||||
// Flags to indicate the state of current boot image
|
||||
uint16_t flags = 0;
|
||||
|
||||
// The format of kernel and ramdisk
|
||||
// The format of kernel, ramdisk and extra
|
||||
format_t k_fmt;
|
||||
format_t r_fmt;
|
||||
format_t e_fmt;
|
||||
|
||||
/***************************************************
|
||||
* Following pointers points within the mmap region
|
||||
|
Loading…
x
Reference in New Issue
Block a user