From patchwork Wed Aug 5 18:07:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Weijie Gao X-Patchwork-Id: 504151 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4E57A1402A1 for ; Thu, 6 Aug 2015 04:08:09 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=uRD7UsQc; dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 5535528050F; Wed, 5 Aug 2015 20:07:20 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 21FE1280163 for ; Wed, 5 Aug 2015 20:07:15 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 CL_IP_EQ_HELO_IP=-2 (check from: .gmail. - helo: .mail-pa0-f51.google. - helo-domain: .google.) FROM/MX_MATCHES_HELO(DOMAIN)=-2; rate: -8.5 Received: from mail-pa0-f51.google.com (mail-pa0-f51.google.com [209.85.220.51]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Wed, 5 Aug 2015 20:07:14 +0200 (CEST) Received: by pacrr5 with SMTP id rr5so6676166pac.3 for ; Wed, 05 Aug 2015 11:07:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=OaGZnJ2UxI1IMEWnrHoLF/HEAaa9KI6mm1bkBwDhZyM=; b=uRD7UsQcaE++4MfiPTi0Rdkli6jF7XVEKW+TLxXkFTlwxGQYVYT3jmf9TR4q5QGX0X LdfOkdPna/pkfInptGQXqZIpqpdR10FCcv9nTQbYx/FE6xpGvgkAVc3MXN5bCnbNkBEy +tS2Fj1C2JR/yDM/DM4kLc1xNrJM8zGGYFHd1s1/IcAzJN6fN/AJAhtOLwMOjcWz6Ohx 7S1/3PvPLvwLusYs39d1QE3ryOWKTIr3fRoxBDmYMRIll9ZOd0QEq8eYzWHrvSTv1cWV MS+0i3ukHNygk3EV1N3eq4xHubTGzCaP4IfknfIrGMgFnR9dbEJGiAqE87n7n99j/npx 5GhQ== X-Received: by 10.68.178.35 with SMTP id cv3mr21452387pbc.141.1438798070869; Wed, 05 Aug 2015 11:07:50 -0700 (PDT) Received: from localhost ([2605:f700:40:c00::ab48:b246]) by smtp.gmail.com with ESMTPSA id nx1sm3677289pab.6.2015.08.05.11.07.49 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Aug 2015 11:07:50 -0700 (PDT) From: Weijie Gao To: openwrt-devel@lists.openwrt.org Date: Thu, 6 Aug 2015 02:07:38 +0800 Message-Id: <1438798058-31119-1-git-send-email-hackpascal@gmail.com> X-Mailer: git-send-email 2.1.4 Subject: [OpenWrt-Devel] [PATCH 1/3] tools/firmware-utils: add header version 2 support for mktplinkfw X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" Signed-off-by: Weijie Gao This patch adds header version 2 option for mktplinkfw. The version 2 header is used for AR/QCA firmwares and is not the same as the header generated by mktplinkfw2. Instead, it is nearly the same as version 1 header except for the header version and the RSA signature. The header version 2 support is used for newer TP-Link routers which have only a 64kb bootloader part, e.g. TL-WDR6500 v2. --- tools/firmware-utils/src/mktplinkfw.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/tools/firmware-utils/src/mktplinkfw.c b/tools/firmware-utils/src/mktplinkfw.c index 12420ad..1302d46 100644 --- a/tools/firmware-utils/src/mktplinkfw.c +++ b/tools/firmware-utils/src/mktplinkfw.c @@ -30,6 +30,7 @@ #define ALIGN(x,a) ({ typeof(a) __a = (a); (((x) + __a - 1) & ~(__a - 1)); }) #define HEADER_VERSION_V1 0x01000000 +#define HEADER_VERSION_V2 0x02000000 #define HWID_ANTMINER_S1 0x04440001 #define HWID_ANTMINER_S3 0x04440003 #define HWID_GL_INET_V1 0x08000001 @@ -130,6 +131,7 @@ static char *progname; static char *vendor = "TP-LINK Technologies"; static char *version = "ver. 1.0"; static char *fw_ver = "0.0.0"; +static uint32_t hdr_ver = HEADER_VERSION_V1; static char *board_id; static struct board_info *board; @@ -139,6 +141,7 @@ static char *opt_hw_id; static uint32_t hw_id; static char *opt_hw_rev; static uint32_t hw_rev; +static uint32_t opt_hdr_ver = 1; static int fw_ver_lo; static int fw_ver_mid; static int fw_ver_hi; @@ -526,6 +529,7 @@ static void usage(int status) " -N set image vendor to \n" " -V set image version to \n" " -v set firmware version to \n" +" -m set header version to \n" " -i inspect given firmware file \n" " -x extract kernel and rootfs while inspecting (requires -i)\n" " -X reserve bytes in the firmware image (hexval prefixed with 0x)\n" @@ -723,6 +727,15 @@ static int check_options(void) return -1; } + if (opt_hdr_ver == 1) { + hdr_ver = HEADER_VERSION_V1; + } else if (opt_hdr_ver == 2) { + hdr_ver = HEADER_VERSION_V2; + } else { + ERR("invalid header version '%u'", opt_hdr_ver); + return -1; + } + return 0; } @@ -732,7 +745,7 @@ static void fill_header(char *buf, int len) memset(hdr, 0, sizeof(struct fw_header)); - hdr->version = htonl(HEADER_VERSION_V1); + hdr->version = htonl(hdr_ver); strncpy(hdr->vendor_name, vendor, sizeof(hdr->vendor_name)); strncpy(hdr->fw_version, version, sizeof(hdr->fw_version)); hdr->hw_id = htonl(hw_id); @@ -972,8 +985,9 @@ static int inspect_fw(void) inspect_fw_pstr("File name", inspect_info.file_name); inspect_fw_phexdec("File size", inspect_info.file_size); - if (ntohl(hdr->version) != HEADER_VERSION_V1) { - ERR("file does not seem to have V1 header!\n"); + if ((ntohl(hdr->version) != HEADER_VERSION_V1) && + (ntohl(hdr->version) != HEADER_VERSION_V2)) { + ERR("file does not seem to have V1/V2 header!\n"); goto out_free_buf; } @@ -1108,7 +1122,7 @@ int main(int argc, char *argv[]) while ( 1 ) { int c; - c = getopt(argc, argv, "a:B:H:E:F:L:V:N:W:ci:k:r:R:o:xX:hsSjv:"); + c = getopt(argc, argv, "a:B:H:E:F:L:m:V:N:W:ci:k:r:R:o:xX:hsSjv:"); if (c == -1) break; @@ -1134,6 +1148,9 @@ int main(int argc, char *argv[]) case 'L': sscanf(optarg, "0x%x", &kernel_la); break; + case 'm': + sscanf(optarg, "%u", &opt_hdr_ver); + break; case 'V': version = optarg; break;