From: Alexander Couzens Date: Tue, 7 May 2019 14:33:58 +0000 (+0200) Subject: tools/mktplinkfw2: add support to extract bootloader images X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=91d583503ca20def61020f56d22c1992609ca98c;p=openwrt%2Fstaging%2Flynxis.git tools/mktplinkfw2: add support to extract bootloader images tplinkfw2 images from TP-Link contains a bootloader image in most cases. -x will create a -bootloader.bin file. Signed-off-by: Alexander Couzens --- diff --git a/tools/firmware-utils/src/mktplinkfw2.c b/tools/firmware-utils/src/mktplinkfw2.c index 102d72b1cc..cec7c87126 100644 --- a/tools/firmware-utils/src/mktplinkfw2.c +++ b/tools/firmware-utils/src/mktplinkfw2.c @@ -205,7 +205,7 @@ static void usage(int status) " -v set firmware version to \n" " -y set secondary version to \n" " -i inspect given firmware file \n" -" -x extract kernel and rootfs while inspecting (requires -i)\n" +" -x extract bootloader, kernel and rootfs while inspecting (requires -i)\n" " -h show this screen\n" ); @@ -505,6 +505,23 @@ static int inspect_fw(void) printf("\n"); + if (hdr->boot_len) { + filename = malloc(strlen(inspect_info.file_name) + 8); + sprintf(filename, "%s-bootloader", inspect_info.file_name); + printf("Extracting bootloader to \"%s\"...\n", filename); + fp = fopen(filename, "w"); + if (fp) { + if (!fwrite(buf + sizeof(struct fw_header) + ntohl(hdr->boot_ofs), + ntohl(hdr->boot_len), 1, fp)) { + ERR("error in fwrite(): %s", strerror(errno)); + } + fclose(fp); + } else { + ERR("error in fopen(): %s", strerror(errno)); + } + free(filename); + } + filename = malloc(strlen(inspect_info.file_name) + 8); sprintf(filename, "%s-kernel", inspect_info.file_name); printf("Extracting kernel to \"%s\"...\n", filename);