From patchwork Tue Mar 9 23:52:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hauke Mehrtens X-Patchwork-Id: 1450246 X-Patchwork-Delegate: hauke@hauke-m.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=QDqXTmgX; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=hauke-m.de header.i=@hauke-m.de header.a=rsa-sha256 header.s=MBO0001 header.b=ChgQeyuE; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DwBsS45rkz9sR4 for ; Wed, 10 Mar 2021 10:55:04 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=HmjAMRqX+BNncmwecBEEx1Bwqsi7vwP3Y+4s8bGMEOQ=; b=QDqXTmgXb+KGcLVIE0VsHJOOT eHPhigaxl2XcDPd00iZiYEI6LOb+bD4LKClzOq8ZA8t4TUZtfgLInB3R7YehfFTJjTFf0LIrt/CRK 8c/1EDMWFOc3mICF0gAQHvDZpjtnDRMcsXt9gJSLhYiEe32aD6mIi22GibJh4ZJp4xKatGt3ZY5cB eItUE6u6JUR1m9Cj441sXckXDTG+Lj9mTEVQXvXFbpgzLQ1BVCPaYbinT0IIW5WWPafOp0u6/gvOY 2M24sTmdfH6Y3Gv7WiUKVZGWU5NLXuhEPWykQgme9vBp3zYUNaX7TnTiK1W4mB8rlunbBR2130f1l 3AsBsigRQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lJm9w-005ezB-QW; Tue, 09 Mar 2021 23:53:05 +0000 Received: from mout-p-102.mailbox.org ([2001:67c:2050::465:102]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lJm9d-005evf-Os for openwrt-devel@lists.openwrt.org; Tue, 09 Mar 2021 23:52:48 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4DwBph057fzQjnl; Wed, 10 Mar 2021 00:52:44 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hauke-m.de; s=MBO0001; t=1615333962; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+ArGYeAm7fZ0lZRqur9rekG9zTaSSGIp0Yoyoqkf1LE=; b=ChgQeyuEbzewE5YpihYx4p7UA2m2B/e0ffsfnulK2KF3zzTTFAXojRH4zp/5MPFKr9Gklb /VrsCBAI+cGOzWnTXHZKWTnfDbDEoSefP4A46wrObaPlc6uwo9mpt9xTX7VO6WHAMJgtH0 yR65vxP7crT9agnseYE7TAdet/CuznVhgLZ5mHMd3IN8RMZHOjX6HCnUgkDRE5+llDVzYz LPQe43JFAgIp48sxjJnCAdlO0IeCcG7DHq8T6qgvJmBEcqVBDooQJGA9CN64T+81sDXMnb APkdYdXyxS3CLXbYC9AJqp9Fjgp9Qa2jMUGZOaEyWmVUZgLkTJe34MUkDTxpGg== Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter06.heinlein-hosting.de (spamfilter06.heinlein-hosting.de [80.241.56.125]) (amavisd-new, port 10030) with ESMTP id YyFJyK6qWzFO; Wed, 10 Mar 2021 00:52:41 +0100 (CET) From: Hauke Mehrtens To: openwrt-devel@lists.openwrt.org Cc: musashino.open@gmail.com, Hauke Mehrtens Subject: [PATCH 3/5] mtd: Add option for TRX magic to fixtrx Date: Wed, 10 Mar 2021 00:52:12 +0100 Message-Id: <20210309235214.1690449-4-hauke@hauke-m.de> In-Reply-To: <20210309235214.1690449-1-hauke@hauke-m.de> References: <20210309235214.1690449-1-hauke@hauke-m.de> MIME-Version: 1.0 X-MBO-SPAM-Probability: X-Rspamd-Score: -0.23 / 15.00 / 15.00 X-Rspamd-Queue-Id: 1EFB917D0 X-Rspamd-UID: e7910d X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210309_235245_984380_77525F0C X-CRM114-Status: GOOD ( 17.38 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: INAGAKI Hiroshi Buffalo uses the TRX header with a different magic and even changes this magic with different devices. This change allows to specify the header to use as a command line argument. Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2001:67c:2050:0:0:0:465:102 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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 X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: INAGAKI Hiroshi Buffalo uses the TRX header with a different magic and even changes this magic with different devices. This change allows to specify the header to use as a command line argument. This is needed for the Buffalo WSR-2533DHP2 based on mt7622. Co-Developed-by: Hauke Mehrtens Signed-off-by: Hauke Mehrtens --- package/system/mtd/src/mtd.c | 14 ++++++++++++-- package/system/mtd/src/mtd.h | 1 + package/system/mtd/src/trx.c | 8 ++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/package/system/mtd/src/mtd.c b/package/system/mtd/src/mtd.c index 9baed3fd5e99..fc7071d94083 100644 --- a/package/system/mtd/src/mtd.c +++ b/package/system/mtd/src/mtd.c @@ -94,6 +94,7 @@ int mtdsize = 0; int erasesize = 0; int jffs2_skip_bytes=0; int mtdtype = 0; +uint32_t opt_trxmagic = TRX_MAGIC; int mtd_open(const char *mtd, bool block) { @@ -205,7 +206,7 @@ image_check(int imagefd, const char *mtd) magic = ((uint32_t *)buf)[0]; - if (be32_to_cpu(magic) == TRX_MAGIC) + if (be32_to_cpu(magic) == opt_trxmagic) imageformat = MTD_IMAGE_FORMAT_TRX; else if (be32_to_cpu(magic) == SEAMA_MAGIC) imageformat = MTD_IMAGE_FORMAT_SEAMA; @@ -810,6 +811,7 @@ static void usage(void) " -l the length of data that we want to dump\n"); if (mtd_fixtrx) { fprintf(stderr, + " -M magic number of the image header in the partition (for fixtrx)\n" " -o offset offset of the image header in the partition(for fixtrx)\n"); } if (mtd_fixtrx || mtd_fixseama || mtd_fixwrg || mtd_fixwrgg) { @@ -877,7 +879,7 @@ int main (int argc, char **argv) #ifdef FIS_SUPPORT "F:" #endif - "frnqe:d:s:j:p:o:c:t:l:")) != -1) + "frnqe:d:s:j:p:o:c:t:l:M:")) != -1) switch (ch) { case 'f': force = 1; @@ -929,6 +931,14 @@ int main (int argc, char **argv) usage(); } break; + case 'M': + errno = 0; + opt_trxmagic = strtoul(optarg, 0, 0); + if (errno) { + fprintf(stderr, "-M: illegal numeric string\n"); + usage(); + } + break; case 'o': errno = 0; offset = strtoul(optarg, 0, 0); diff --git a/package/system/mtd/src/mtd.h b/package/system/mtd/src/mtd.h index fe716b715090..d2facc8e3b94 100644 --- a/package/system/mtd/src/mtd.h +++ b/package/system/mtd/src/mtd.h @@ -12,6 +12,7 @@ extern int quiet; extern int mtdsize; extern int erasesize; +extern uint32_t opt_trxmagic; extern int mtd_open(const char *mtd, bool block); extern int mtd_check_open(const char *mtd); diff --git a/package/system/mtd/src/trx.c b/package/system/mtd/src/trx.c index 3e3b5d220c62..d7c5d832c42d 100644 --- a/package/system/mtd/src/trx.c +++ b/package/system/mtd/src/trx.c @@ -35,7 +35,6 @@ #include "mtd.h" #include "crc32.h" -#define TRX_MAGIC 0x30524448 /* "HDR0" */ #define TRX_CRC32_DATA_OFFSET 12 /* First 12 bytes are not covered by CRC32 */ #define TRX_CRC32_DATA_SIZE 16 struct trx_header { @@ -92,7 +91,7 @@ trx_fixup(int fd, const char *name) } trx = ptr; - if (trx->magic != TRX_MAGIC) { + if (ntohl(trx->magic) != opt_trxmagic) { fprintf(stderr, "TRX header not found\n"); goto err; } @@ -127,7 +126,8 @@ trx_check(int imagefd, const char *mtd, char *buf, int *len) } } - if (trx->magic != TRX_MAGIC || trx->len < sizeof(struct trx_header)) { + if (ntohl(trx->magic) != opt_trxmagic || + trx->len < sizeof(struct trx_header)) { if (quiet < 2) { fprintf(stderr, "Bad trx header\n"); fprintf(stderr, "This is not the correct file format; refusing to flash.\n" @@ -200,7 +200,7 @@ mtd_fixtrx(const char *mtd, size_t offset, size_t data_size) } trx = (struct trx_header *)(first_block + offset); - if (trx->magic != STORE32_LE(0x30524448)) { + if (ntohl(trx->magic) != opt_trxmagic) { fprintf(stderr, "No trx magic found\n"); exit(1); }