From patchwork Sun Dec 11 01:17:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUKAUMI Naoki X-Patchwork-Id: 704793 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tbp9D66LJz9t1b for ; Sun, 11 Dec 2016 12:22:08 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="wFm1/OYj"; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cFsmY-0000YV-3I; Sun, 11 Dec 2016 01:18:26 +0000 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cFsmU-0000Va-UA for lede-dev@lists.infradead.org; Sun, 11 Dec 2016 01:18:24 +0000 Received: by mail-pf0-x243.google.com with SMTP id y68so2788454pfb.1 for ; Sat, 10 Dec 2016 17:18:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=yOLQLC40qYIaT939vlIoYEHqqk0znKiyluq5XYsRZAU=; b=wFm1/OYjpT1RQdmjIlMWaf0gIpYJC9qVBFEMzjs2foEEfZ7wZGTjoDQ+2opPbjFNQc +dSC03eiafo0yHGyCU/5CwllXE8DeSMVnOVgcA3b5RC2RLLdpn5LN/49H9+Am3uEWDkz bW2C8PyoMqeqNn2kMPtR2UhtOhZ5c19aCLDpixSgkR9sNXFAjL072sqKRN2KhSPT8yMm rnujKzkaTIAsidCmAJ4mDYTuksqOm42XM/ZORQBpgboi2dmlRNoHaWGqwl3BfWXflJwS a89HyuQCoVPZJB9y6xavOgrd62NKaS6beII4rfp4XQHX1/4gDJavGk/q6Ax5wIB07bbh M0Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=yOLQLC40qYIaT939vlIoYEHqqk0znKiyluq5XYsRZAU=; b=btm0qTEvY750X13xlIs+RyyjoIQ2MOpE7pkpmRPqh+HzvVPGG3p67ebIB2fF/hFDmf bLwNn3wKM1tvEcsUQ+/gHiuRQqd3HSBNUhQBxSopiUOr9f/c76UnEX3FgUzus4BymWw7 UmZmfK6/UaCAenpH7hLkolgBYCcCQPntj7Fix2Jr9tAkk+7K83Bbg8/+sB/gAtRVHXTr Mxb73jL2lYtyfGn+PbGLNDZCmtlMo60lrb1W7SMho+LPSIxHCyjNmUHSsuyp5QHO1JGM gyeBCoYe/2shYiCFQRp/Tp6Tfxgdkivwty/qEYTPKLrpOsZ6D+P4XAEhddfWhWDtQLM7 GPEQ== X-Gm-Message-State: AKaTC00bxUaoymwsdriioS2kS1002lo9LimKgbxNZ6Y88YxyqHU+9F9q5+9FNobo7tRTmA== X-Received: by 10.99.175.69 with SMTP id s5mr156010315pgo.6.1481419081389; Sat, 10 Dec 2016 17:18:01 -0800 (PST) Received: from localhost.localdomain (sakura.naobsd.org. [160.16.200.221]) by smtp.gmail.com with ESMTPSA id z62sm66893478pfz.19.2016.12.10.17.18.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Dec 2016 17:18:00 -0800 (PST) From: FUKAUMI Naoki To: lede-dev@lists.infradead.org Date: Sun, 11 Dec 2016 10:17:53 +0900 Message-Id: <20161211011753.26526-1-naobsd@gmail.com> X-Mailer: git-send-email 2.11.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161210_171823_092240_F92A2E36 X-CRM114-Status: GOOD ( 19.69 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 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 [2607:f8b0:400e:c00:0:0:0:243 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 (naobsd[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_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid Subject: [LEDE-DEV] [PATCH v3] ramips: build factory images for Buffalo WSR-1166DHP/WSR-1166DHP2 X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: FUKAUMI Naoki MIME-Version: 1.0 Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org factory image has to have custom trx magic, and trx file will be written in the middle of the mtd3 partition (bootpartition=1 on u-boot). therefore, sysupgrade.bin cannot be installed directly from stock Web UI. with this patch, factory.bin will be built with initramfs image. it can be installed from stock Web UI, then sysupgrade.bin can be installed by sysupgrade on initramfs image. install procedure: 1. install factory.bin (initramfs image) from stock Web UI 2. ssh root@192.168.1.1 3. run "mtd erase firmware" (erase trx file from factory.bin in mtd3) 4. install sysupgrade.bin by sysupgrade Signed-off-by: FUKAUMI Naoki --- Changes in v3: - use "DHP/dhp" instead of "WSR/wsr" for keyword for common things - use "-I" instead of "-W" for buffalo-tag optarg - make commit log message better Changes in v2: - cosmetic cleanup in mt7621.mk target/linux/ramips/image/mt7621.mk | 33 ++++++++++++ tools/firmware-utils/Makefile | 1 + tools/firmware-utils/src/buffalo-tag.c | 29 ++++++++--- tools/firmware-utils/src/mkdhpimg.c | 94 ++++++++++++++++++++++++++++++++++ tools/firmware-utils/src/trx.c | 13 ++++- 5 files changed, 161 insertions(+), 9 deletions(-) create mode 100644 tools/firmware-utils/src/mkdhpimg.c diff --git a/target/linux/ramips/image/mt7621.mk b/target/linux/ramips/image/mt7621.mk index 6d85511..23a79f5 100644 --- a/target/linux/ramips/image/mt7621.mk +++ b/target/linux/ramips/image/mt7621.mk @@ -192,8 +192,41 @@ define Device/wndr3700v5 endef TARGET_DEVICES += wndr3700v5 +define Build/wsr-factory-image + $(STAGING_DIR_HOST)/bin/trx \ + -M $(2) \ + -m $(IMAGE_SIZE) \ + -f $(1) \ + -o $(1).trx + $(STAGING_DIR_HOST)/bin/buffalo-enc \ + -l -m 'start' \ + -p $(3) -v '0.00' \ + -i $(1).trx -o $(1).trx.enc + $(STAGING_DIR_HOST)/bin/buffalo-tag \ + -a MTK \ + -b $(3) -p $(3) \ + -l JP -r JP -r JP \ + -s \ + -v '0.00' -m '0.00' \ + -w 1 \ + -I $(1).trx.enc -o $(1).tag + $(STAGING_DIR_HOST)/bin/buffalo-enc \ + -l -m 'start' \ + -p '' -v '' \ + -i $(1).tag -o $(1).tag.enc + $(STAGING_DIR_HOST)/bin/mkdhpimg \ + $(1).tag.enc $(1).trx.enc \ + $(call imgname,initramfs,$(4))-factory.bin +endef + +define Build/wsr-1166-factory-images + $(call Build/wsr-factory-image,$@,0x746f435c,WSR-1166DHP,wsr-1166dhp) + $(call Build/wsr-factory-image,$@,0x1fc384dd,WSR-1166DHP2,wsr-1166dhp2) +endef + define Device/wsr-1166 DTS := WSR-1166 + KERNEL_INITRAMFS := $$(KERNEL) | wsr-1166-factory-images IMAGE/sysupgrade.bin := trx | pad-rootfs | append-metadata IMAGE_SIZE := $(ralink_default_fw_size_16M) DEVICE_TITLE := Buffalo WSR-1166 diff --git a/tools/firmware-utils/Makefile b/tools/firmware-utils/Makefile index 456b7a3..8a0d13f 100644 --- a/tools/firmware-utils/Makefile +++ b/tools/firmware-utils/Makefile @@ -79,6 +79,7 @@ define Host/Compile $(call cc,jcgimage, -lz -Wall) $(call cc,mkbuffaloimg, -Wall) $(call cc,zyimage, -Wall) + $(call cc,mkdhpimg buffalo-lib, -Wall) endef define Host/Install diff --git a/tools/firmware-utils/src/buffalo-tag.c b/tools/firmware-utils/src/buffalo-tag.c index b5db72e..63bc6d3 100644 --- a/tools/firmware-utils/src/buffalo-tag.c +++ b/tools/firmware-utils/src/buffalo-tag.c @@ -7,6 +7,7 @@ * */ +#include #include #include #include @@ -48,6 +49,7 @@ static uint32_t base2; static char *region_code; static uint32_t region_mask; static int num_regions; +static int dhp; void usage(int status) { @@ -63,6 +65,7 @@ void usage(int status) " -d \n" " -f set flag to \n" " -i read input from the file \n" +" -I read input from the file for DHP series\n" " -l set language to \n" " -m set minor version to \n" " -o write output to the file \n" @@ -177,11 +180,17 @@ static void fixup_tag(unsigned char *buf, ssize_t buflen) memcpy(tag->region_code, region_code, 2); } - tag->len = htonl(buflen); - tag->data_len = htonl(fsize[0]); - tag->base1 = htonl(base1); - tag->base2 = htonl(base2); - tag->flag = flag; + if (dhp) { + tag->len = htonl(buflen + 200); + tag->base1 = htonl(buflen); + tag->base2 = htonl(0x01000000); + } else { + tag->len = htonl(buflen); + tag->data_len = htonl(fsize[0]); + tag->base1 = htonl(base1); + tag->base2 = htonl(base2); + tag->flag = flag; + } if (hwver) { memcpy(tag->hwv, "hwv", 3); @@ -270,7 +279,10 @@ static int tag_file(void) offset += fsize[i]; } - if (num_files == 1) + if (dhp) { + buflen = offsetof(struct buffalo_tag, data_len); + fixup_tag(buf, fsize[0]); + } else if (num_files == 1) fixup_tag(buf, buflen); else fixup_tag2(buf, buflen); @@ -299,7 +311,7 @@ int main(int argc, char *argv[]) while ( 1 ) { int c; - c = getopt(argc, argv, "a:b:c:d:f:hi:l:m:o:p:r:sv:w:"); + c = getopt(argc, argv, "a:b:c:d:f:hi:l:m:o:p:r:sv:w:I:"); if (c == -1) break; @@ -319,6 +331,9 @@ int main(int argc, char *argv[]) case 'f': flag = strtoul(optarg, NULL, 2); break; + case 'I': + dhp = 1; + /* FALLTHROUGH */ case 'i': err = process_ifname(optarg); if (err) diff --git a/tools/firmware-utils/src/mkdhpimg.c b/tools/firmware-utils/src/mkdhpimg.c new file mode 100644 index 0000000..775e512 --- /dev/null +++ b/tools/firmware-utils/src/mkdhpimg.c @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2016 FUKAUMI Naoki + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "buffalo-lib.h" + +#define DHP_HEADER_SIZE 20 + +static char *progname; + +static void +usage(void) +{ + + fprintf(stderr, "usage: %s \n", progname); + exit(EXIT_FAILURE); +} + +int +main(int argc, char *argv[]) +{ + struct stat tag_st, trx_st; + size_t size; + uint32_t crc; + int tag, trx, out; + uint8_t *buf; + + progname = argv[0]; + + if (argc != 4) + usage(); + + if ((tag = open(argv[1], O_RDONLY)) == -1) + err(EXIT_FAILURE, "%s", argv[1]); + + if (fstat(tag, &tag_st) == -1) + err(EXIT_FAILURE, "%s", argv[1]); + + if ((trx = open(argv[2], O_RDONLY)) == -1) + err(EXIT_FAILURE, "%s", argv[2]); + + if (fstat(trx, &trx_st) == -1) + err(EXIT_FAILURE, "%s", argv[2]); + + size = DHP_HEADER_SIZE + tag_st.st_size + trx_st.st_size; + + if ((buf = malloc(size)) == NULL) + err(EXIT_FAILURE, "malloc"); + + memset(buf, 0, DHP_HEADER_SIZE); + buf[0x0] = 0x62; + buf[0x1] = 0x67; + buf[0x2] = 0x6e; + buf[0xb] = 0xb1; + buf[0xc] = (size >> 24) & 0xff; + buf[0xd] = (size >> 16) & 0xff; + buf[0xe] = (size >> 8) & 0xff; + buf[0xf] = size & 0xff; + + read(tag, &buf[DHP_HEADER_SIZE], tag_st.st_size); + close(tag); + + read(trx, &buf[DHP_HEADER_SIZE + tag_st.st_size], trx_st.st_size); + close(trx); + + crc = buffalo_crc(buf, size); + buf[0x10] = (crc >> 24) & 0xff; + buf[0x11] = (crc >> 16) & 0xff; + buf[0x12] = (crc >> 8) & 0xff; + buf[0x13] = crc & 0xff; + + if ((out = open(argv[3], O_WRONLY | O_CREAT | O_TRUNC, 0644)) == -1) + err(EXIT_FAILURE, "%s", argv[3]); + write(out, buf, size); + close(out); + + free(buf); + + return EXIT_SUCCESS; +} diff --git a/tools/firmware-utils/src/trx.c b/tools/firmware-utils/src/trx.c index aa1f5be..dc5bb67 100644 --- a/tools/firmware-utils/src/trx.c +++ b/tools/firmware-utils/src/trx.c @@ -100,7 +100,7 @@ int main(int argc, char **argv) int c, i, append = 0; size_t n; ssize_t n2; - uint32_t cur_len, fsmark=0; + uint32_t cur_len, fsmark=0, magic; unsigned long maxlen = TRX_MAX_LEN; struct trx_header *p; char trx_version = 1; @@ -121,7 +121,7 @@ int main(int argc, char **argv) in = NULL; i = 0; - while ((c = getopt(argc, argv, "-:2o:m:a:x:b:f:A:F:")) != -1) { + while ((c = getopt(argc, argv, "-:2o:m:a:x:b:f:A:F:M:")) != -1) { switch (c) { case '2': /* take care that nothing was written to buf so far */ @@ -243,6 +243,15 @@ int main(int argc, char **argv) } break; + case 'M': + errno = 0; + magic = strtoul(optarg, &e, 0); + if (errno || (e == optarg) || *e) { + fprintf(stderr, "illegal numeric string\n"); + usage(); + } + p->magic = STORE32_LE(magic); + break; default: usage(); }