From patchwork Sun Jul 9 23:02:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Piotr Dymacz X-Patchwork-Id: 785966 X-Patchwork-Delegate: pepe2k@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3x5P615tGDz9s1h for ; Mon, 10 Jul 2017 09:03:36 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="QjLElE5n"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="b9umLjPe"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Subject:Message-Id: Date:To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=e2CwtFG492I04CXcA7vAORNixUACbdd1dHzk0QypLiY=; b=QjLElE5nazBLgy caUvIwk3Eod/r2HOSN5VWE2AXXlKNR/I6rV2xmmkoBpkOm6PRu4CcgrNKhFQKdmJIDU07W4YzIiW0 8LgU1ChLzhqy6TldDUoqBeNUL5UKgWHiuwfztD7PVWdLY+t64iLQn/SGMbqEbvRtxlcz1b9+5KPEP uGznhGOioYH0E4ao/jCixhyvfQ9XwhQ5sO1t1Z6J/SuBoBC+PtVK6FyRL+3NIfl+Lr6W8/2g00GXL svrIGbFCwIRIwXoIV3eOZnZhWAcgx03sGS21tgKHfq3BpVdTdzlNCrjJdU8EfbhZLOXmr8+hq6voL fU/X9Dv3Qn8Fs9bXp7Kw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dULEO-0000I9-Kf; Sun, 09 Jul 2017 23:03:12 +0000 Received: from mail-lf0-x231.google.com ([2a00:1450:4010:c07::231]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dULEK-0000HH-CO for lede-dev@lists.infradead.org; Sun, 09 Jul 2017 23:03:10 +0000 Received: by mail-lf0-x231.google.com with SMTP id t72so48633924lff.1 for ; Sun, 09 Jul 2017 16:02:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=NUeD9POFzbea5+eqsJnGvPj2L847zZ1Wa3fw2V2UPSI=; b=b9umLjPeTr5s7wbHrG+BDA5/Nb/5zsSHkQUwKdX+R6uIQi4Je3eeiZ0sriig8RKI47 a6uVRc9kfhV91Dz8pRp0SLSsOlq69HYM7stYJ0QVkU2RtOXNQF9R0u50wJQIo39n/zN9 oNU1mWk38VQ423ZQuNv0croG4c/Iv5nl1DVGSDjVgH3GlM8a5Gz0RNdNbL45EVIdk5sH OhrbGF29PIet4x9TxVCWN3hmojCooT8YUKYut/J6hw2jlzMLIkVhfVjH3BXDxhBaaURZ kB07UeH4KRYie8kPrsHDmv1HGJoJvz3yuANHJBmqY/NnxML1nzWmGuUAKlOQy2kA3iJC YKUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=NUeD9POFzbea5+eqsJnGvPj2L847zZ1Wa3fw2V2UPSI=; b=SCjK1G03vesj/W0jLMmC4uYlM+i09qUnEu7gmTwh2FmzSqhDHC/Byps5JAlqGJhzKk BTUj73i6IhN7E2MSPgtZ/aFOhf9TYxGHyhWZ4C7cXx4J14ccLa1o9G3AOuD8AaX3QA0F 8F+Ol3iVNsotxBkaKNNKEEM4EZztoW0F5PXmfi93Tl4oq8AE+4RkrX/iA0m3ognkHhUv YMEczSODnzfQxLKbpzouKzsDcxPJuoehcQaiZrtUAy8clpjjjAYkko7gqgxjMwZgETw/ XUkGso9YS1Vm4kugYwfL1rlp7UQ67gRycWmtBNVuzmNlF3rDKORHzzwY5ZCbN6kztTzO Y+fg== X-Gm-Message-State: AIVw1118KvlJ6XE6160pB3bULmX5qqOSNbZTiDnfwuUYFQIARqJg+4Vj 85nG30B23jj+0RzxImg= X-Received: by 10.46.88.3 with SMTP id m3mr3140688ljb.136.1499641364892; Sun, 09 Jul 2017 16:02:44 -0700 (PDT) Received: from mint.lan (178235216171.warszawa.vectranet.pl. [178.235.216.171]) by smtp.gmail.com with ESMTPSA id w30sm1944513ljd.37.2017.07.09.16.02.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 09 Jul 2017 16:02:43 -0700 (PDT) From: Piotr Dymacz To: lede-dev@lists.infradead.org Date: Mon, 10 Jul 2017 01:02:32 +0200 Message-Id: <1499641352-31099-1-git-send-email-pepe2k@gmail.com> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170709_160308_644304_53070D78 X-CRM114-Status: GOOD ( 17.45 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:4010:c07:0:0:0:231 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (pepe2k[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain Subject: [LEDE-DEV] [PATCH] firmware-utils: mktplinkfw: rework combined image option X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mschiffer@universe-factory.net MIME-Version: 1.0 Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org We use combined option in "mktplinkfw" tool for generating initramfs kernel images and header for kernel inside "safeloader" image type (in fact, only for TL-WR1043ND v4 at this moment). There is also "mktplinkfw-kernel" tool, a stripped-down version, used only for generating "simple" header, for safeloader image types. This changes how "mktplinkfw" handles combined images (which then will allow us to drop the stripped-down version of the tool): - drop "ignore size" command line option (it was used only for combined images anyway) - don't require "flash layout id" for combined images (we don't need and shouldn't limit size of the initramfs kernel and for kernels inside safeloader images, the "tplink-safeloader" tool does the size check) - require kernel address and entry point in command line parameters for combined images (consequence of previous point) - don't include md5 sum and firmware length values in header (they are needed only for update from vendor GUI and are ingored in case of initramfs and "tplink-safeloader" images) - drop "fake" flash layout for TL-WR1043ND v4 as it's no longer needed Also, adjust "mktplinkfw-combined" command in ar71xx/image/tp-link.mk to match introduced changes in "mktplinkfw" tool. Signed-off-by: Piotr Dymacz --- target/linux/ar71xx/image/tp-link.mk | 7 ++- tools/firmware-utils/src/mktplinkfw.c | 99 +++++++++++++++-------------------- 2 files changed, 44 insertions(+), 62 deletions(-) diff --git a/target/linux/ar71xx/image/tp-link.mk b/target/linux/ar71xx/image/tp-link.mk index f717707..f393d15 100644 --- a/target/linux/ar71xx/image/tp-link.mk +++ b/target/linux/ar71xx/image/tp-link.mk @@ -40,11 +40,11 @@ endef # -c combined image define Build/mktplinkfw-combined $(STAGING_DIR_HOST)/bin/mktplinkfw \ - -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -F $(TPLINK_FLASHLAYOUT) -N OpenWrt -V $(REVISION) $(1) \ - -m $(TPLINK_HEADER_VERSION) \ + -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -N OpenWrt -V $(REVISION) $(1) \ + -L $(KERNEL_LOADADDR) -m $(TPLINK_HEADER_VERSION) \ + -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \ -k $@ \ -o $@.new \ - -s -S \ -c @mv $@.new $@ endef @@ -707,7 +707,6 @@ define Device/tl-wr1043nd-v4 BOARDNAME := TL-WR1043ND-v4 DEVICE_PROFILE := TLWR1043 TPLINK_HWID := 0x10430004 - TPLINK_FLASHLAYOUT := 16Msafeloader MTDPARTS := spi0.0:128k(u-boot)ro,1536k(kernel),14016k(rootfs),128k(product-info)ro,320k(config)ro,64k(partition-table)ro,128k(logs)ro,64k(ART)ro,15552k@0x20000(firmware) IMAGE_SIZE := 15552k TPLINK_BOARD_ID := TLWR1043NDV4 diff --git a/tools/firmware-utils/src/mktplinkfw.c b/tools/firmware-utils/src/mktplinkfw.c index 93db441..c537862 100644 --- a/tools/firmware-utils/src/mktplinkfw.c +++ b/tools/firmware-utils/src/mktplinkfw.c @@ -117,7 +117,6 @@ static uint32_t rootfs_align; static struct file_info boot_info; static int combined; static int strip_padding; -static int ignore_size; static int add_jffs2_eof; static unsigned char jffs2_eof_mark[4] = {0xde, 0xad, 0xc0, 0xde}; static uint32_t fw_max_len; @@ -181,20 +180,6 @@ static struct flash_layout layouts[] = { .kernel_ep = 0xc0000000, .rootfs_ofs = 0x2a0000, }, { - /* - Some devices (e.g. TL-WR1043 v4) use a mktplinkfw kernel image - embedded in a tplink-safeloader image as os-image partition. - - We use a 1.5MB partition for the compressed kernel, which should - be sufficient, but not too wasteful (the flash of the TL-WR1043 v4 - has 16MB in total). - */ - .id = "16Msafeloader", - .fw_max_len = 0x180000, - .kernel_la = 0x80060000, - .kernel_ep = 0x80060000, - .rootfs_ofs = 0, - }, { /* terminating entry */ } }; @@ -272,7 +257,6 @@ static void usage(int status) " -R overwrite rootfs offset with (hexval prefixed with 0x)\n" " -o write output to the file \n" " -s strip padding from the end of the image\n" -" -S ignore firmware size limit (only for combined images)\n" " -j add jffs2 end-of-filesystem markers\n" " -N set image vendor to \n" " -V set image version to \n" @@ -362,7 +346,7 @@ static int check_options(void) } hw_id = strtoul(opt_hw_id, NULL, 0); - if (layout_id == NULL) { + if (!combined && layout_id == NULL) { ERR("flash layout is not specified"); return -1; } @@ -380,26 +364,31 @@ static int check_options(void) } } - layout = find_layout(layout_id); - if (layout == NULL) { - ERR("unknown flash layout \"%s\"", layout_id); - return -1; - } + if (combined) { + if (!kernel_la || !kernel_ep) { + ERR("kernel loading address and entry point must be specified for combined image"); + return -1; + } + } else { + layout = find_layout(layout_id); + if (layout == NULL) { + ERR("unknown flash layout \"%s\"", layout_id); + return -1; + } - if (!kernel_la) - kernel_la = layout->kernel_la; - if (!kernel_ep) - kernel_ep = layout->kernel_ep; - if (!rootfs_ofs) - rootfs_ofs = layout->rootfs_ofs; + if (!kernel_la) + kernel_la = layout->kernel_la; + if (!kernel_ep) + kernel_ep = layout->kernel_ep; + if (!rootfs_ofs) + rootfs_ofs = layout->rootfs_ofs; - if (reserved_space > layout->fw_max_len) { - ERR("reserved space is not valid"); - return -1; + if (reserved_space > layout->fw_max_len) { + ERR("reserved space is not valid"); + return -1; + } } - fw_max_len = layout->fw_max_len - reserved_space; - if (kernel_info.file_name == NULL) { ERR("no kernel image specified"); return -1; @@ -411,18 +400,9 @@ static int check_options(void) kernel_len = kernel_info.file_size; - if (combined) { - exceed_bytes = kernel_info.file_size - (fw_max_len - sizeof(struct fw_header)); - if (exceed_bytes > 0) { - if (!ignore_size) { - ERR("kernel image is too big by %i bytes", exceed_bytes); - return -1; - } - layout->fw_max_len = sizeof(struct fw_header) + - kernel_info.file_size + - reserved_space; - } - } else { + if (!combined) { + fw_max_len = layout->fw_max_len - reserved_space; + if (rootfs_info.file_name == NULL) { ERR("no rootfs image specified"); return -1; @@ -494,17 +474,18 @@ static void fill_header(char *buf, int len) hdr->hw_id = htonl(hw_id); hdr->hw_rev = htonl(hw_rev); - if (boot_info.file_size == 0) - memcpy(hdr->md5sum1, md5salt_normal, sizeof(hdr->md5sum1)); - else - memcpy(hdr->md5sum1, md5salt_boot, sizeof(hdr->md5sum1)); - hdr->kernel_la = htonl(kernel_la); hdr->kernel_ep = htonl(kernel_ep); - hdr->fw_length = htonl(layout->fw_max_len); hdr->kernel_ofs = htonl(sizeof(struct fw_header)); hdr->kernel_len = htonl(kernel_len); + if (!combined) { + if (boot_info.file_size == 0) + memcpy(hdr->md5sum1, md5salt_normal, sizeof(hdr->md5sum1)); + else + memcpy(hdr->md5sum1, md5salt_boot, sizeof(hdr->md5sum1)); + + hdr->fw_length = htonl(layout->fw_max_len); hdr->rootfs_ofs = htonl(rootfs_ofs); hdr->rootfs_len = htonl(rootfs_info.file_size); } @@ -530,7 +511,8 @@ static void fill_header(char *buf, int len) hdr->kernel_ep = bswap_32(hdr->kernel_ep); } - get_md5(buf, len, hdr->md5sum1); + if (!combined) + get_md5(buf, len, hdr->md5sum1); } static int pad_jffs2(char *buf, int currlen) @@ -607,7 +589,12 @@ static int build_fw(void) int ret = EXIT_FAILURE; int writelen = 0; - buflen = layout->fw_max_len; + writelen = sizeof(struct fw_header) + kernel_len; + + if (combined) + buflen = writelen; + else + buflen = layout->fw_max_len; buf = malloc(buflen); if (!buf) { @@ -621,7 +608,6 @@ static int build_fw(void) if (ret) goto out_free_buf; - writelen = sizeof(struct fw_header) + kernel_len; if (!combined) { if (rootfs_align) @@ -814,7 +800,7 @@ int main(int argc, char *argv[]) while ( 1 ) { int c; - c = getopt(argc, argv, "a:H:E:F:L:m:V:N:W:C:ci:k:r:R:o:xX:ehsSjv:"); + c = getopt(argc, argv, "a:H:E:F:L:m:V:N:W:C:ci:k:r:R:o:xX:ehsjv:"); if (c == -1) break; @@ -870,9 +856,6 @@ int main(int argc, char *argv[]) case 's': strip_padding = 1; break; - case 'S': - ignore_size = 1; - break; case 'i': inspect_info.file_name = optarg; break;