magiskboot: allow forcing no recompression on ramdisk.cpio

- when input image had a compressed ramdisk magiskboot had no way to force the repack with the uncompressed ramdisk.cpio since it does not formally recognize cpio as its own format, so add a switch to support forcing repacking to any possible ramdisk format regardless of input image
This commit is contained in:
osm0sis 2019-06-07 15:56:20 -03:00 committed by topjohnwu
parent f341f3b2dd
commit ee407472cf
3 changed files with 14 additions and 7 deletions

View File

@ -340,7 +340,7 @@ int unpack(const char *image, bool hdr) {
}
#define file_align() write_zero(fd, align_off(lseek(fd, 0, SEEK_CUR) - header_off, boot.hdr.page_size()))
void repack(const char* orig_image, const char* out_image) {
void repack(const char* orig_image, const char* out_image, bool force_nocomp) {
boot_img boot {};
off_t header_off, kernel_off, ramdisk_off, second_off, extra_off, dtb_off;
@ -442,7 +442,7 @@ void repack(const char* orig_image, const char* out_image) {
size_t raw_size;
void *raw_buf;
mmap_ro(RAMDISK_FILE, raw_buf, raw_size);
if (!COMPRESSED_ANY(check_fmt(raw_buf, raw_size)) && COMPRESSED(boot.r_fmt)) {
if (!COMPRESSED_ANY(check_fmt(raw_buf, raw_size)) && COMPRESSED(boot.r_fmt) && !force_nocomp) {
boot.hdr->ramdisk_size = compress(boot.r_fmt, fd, raw_buf, raw_size);
} else {
boot.hdr->ramdisk_size = write(fd, raw_buf, raw_size);

View File

@ -14,7 +14,7 @@
// Main entries
int unpack(const char *image, bool hdr = false);
void repack(const char* orig_image, const char* out_image);
void repack(const char* orig_image, const char* out_image, bool force_nocomp = false);
int hexpatch(const char *image, const char *from, const char *to);
int cpio_commands(int argc, char *argv[]);
int dtb_commands(const char *cmd, int argc, char *argv[]);

View File

@ -26,11 +26,12 @@ static void usage(char *arg0) {
" Return values:\n"
" 0:valid 1:error 2:chromeos\n"
"\n"
" repack <origbootimg> [outbootimg]\n"
" repack [-n] <origbootimg> [outbootimg]\n"
" Repack boot image components from current directory\n"
" to [outbootimg], or new-boot.img if not specified.\n"
" It will compress ramdisk.cpio and kernel with the same method in\n"
" <origbootimg> if the file provided is not already compressed.\n"
" If '-n' is provided, it will not attempt to recompress ramdisk.cpio,\n"
" otherwise it will compress ramdisk.cpio and kernel with the same method\n"
" in <origbootimg> if the file provided is not already compressed.\n"
"\n"
" hexpatch <file> <hexpattern1> <hexpattern2>\n"
" Search <hexpattern1> in <file>, and replace with <hexpattern2>\n"
@ -145,7 +146,13 @@ int main(int argc, char *argv[]) {
return unpack(argv[2]);
}
} else if (argc > 2 && strcmp(argv[1], "repack") == 0) {
repack(argv[2], argv[3] ? argv[3] : NEW_BOOT);
if (strcmp(argv[2], "-n") == 0) {
if (argc == 4)
usage(argv[0]);
repack(argv[3], argv[4] ? argv[4] : NEW_BOOT, true);
} else {
repack(argv[2], argv[3] ? argv[3] : NEW_BOOT);
}
} else if (argc > 2 && strcmp(argv[1], "decompress") == 0) {
decompress(argv[2], argv[3]);
} else if (argc > 2 && strncmp(argv[1], "compress", 8) == 0) {