From patchwork Mon Jan 17 08:36:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "kestrel1974@t-online.de" X-Patchwork-Id: 1580632 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=slxHBqSM; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jclgh0lHNz9s9c for ; Mon, 17 Jan 2022 19:39:12 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id: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:In-Reply-To:References: List-Owner; bh=xhJSNGZXBB7Ey3ZnBiBAOt4S/S8VZAnzuK6Bjz3WE8Q=; b=slxHBqSMQwfvlt ve5Qcsf9BuWx96GAJKOpEQM2gYO6UyNIFZayQYJGIoW0zgin4DYEdG/AMWx8ODqlGdKiOSZAlJuNa PYc96FU/vY/MPyB7XGLcouZY1bYcw8KklfwUEpDwRadS8T3p00pXokPOTPH9QIl4RlNIvoFJl/DjZ RilzRWcZQZ6CcbpT+MWTOv8KZU09vkRnS6oMCj65hM+mzGzMTDgvs0kLdlPT8ZVPTWep6YW4udhe2 mjnvN9SVH6rJdgyS13Ipj5iAYMoGO54ZwjrlF3raPeooNJDyPchsE8SkSnPRpZNSuVdpZaQ8ZDUI+ r6P3adt4NIQEpqEO/m3A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n9NVQ-00E6Ak-Gt; Mon, 17 Jan 2022 08:36:48 +0000 Received: from mailout02.t-online.de ([194.25.134.17]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n9NVM-00E686-3N for openwrt-devel@lists.openwrt.org; Mon, 17 Jan 2022 08:36:46 +0000 Received: from fwd78.dcpf.telekom.de (fwd78.aul.t-online.de [10.223.144.104]) by mailout02.t-online.de (Postfix) with SMTP id 5F7FE2DE6 for ; Mon, 17 Jan 2022 09:36:39 +0100 (CET) Received: from ubuntu.fritz.box ([155.133.219.250]) by fwd78.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1n9NVF-2U6oNt0; Mon, 17 Jan 2022 09:36:37 +0100 From: kestrel1974@t-online.de To: openwrt-devel@lists.openwrt.org Cc: Daniel Kestrel Subject: [PATCH v2] firmware-utils: support checksum for AVM fritzbox wasp SOCs Date: Mon, 17 Jan 2022 09:36:29 +0100 Message-Id: <20220117083629.29813-1-kestrel1974@t-online.de> X-Mailer: git-send-email 2.17.1 X-TOI-EXPURGATEID: 150726::1642408597-0000AD4E-DEE37B10/0/0 CLEAN NORMAL X-TOI-MSGID: ad1ac11f-7a9e-4021-8a90-ec74c40aa0c7 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220117_003644_363320_454111F4 X-CRM114-Status: GOOD ( 18.80 ) X-Spam-Score: 0.3 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.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: Daniel Kestrel This patch adds creating the checksum to be able to create an image and boot the secondary ath79 based wireless assist (WASP) SoC with a second instance of OpenWrt for some AVM Fritzbox devices (3390, [...] Content analysis details: (0.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [194.25.134.17 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [194.25.134.17 listed in wl.mailspike.net] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [kestrel1974[at]t-online.de] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [kestrel1974[at]t-online.de] 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders 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: , MIME-Version: 1.0 Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Daniel Kestrel This patch adds creating the checksum to be able to create an image and boot the secondary ath79 based wireless assist (WASP) SoC with a second instance of OpenWrt for some AVM Fritzbox devices (3390, 3490, 5490, 7490). The utility is called avm-wasp-checksum and was originally created by Andreas Boehler. Signed-off-by: Daniel Kestrel --- CMakeLists.txt | 1 + src/avm-wasp-checksum.c | 171 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+) create mode 100644 src/avm-wasp-checksum.c diff --git a/CMakeLists.txt b/CMakeLists.txt index f406520..5f886ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,7 @@ ENDMACRO(FW_UTIL) FW_UTIL(add_header "" "" "") FW_UTIL(addpattern "" "" "") FW_UTIL(asustrx "" "" "") +FW_UTIL(avm-wasp-checksum "" --std=gnu99 "") FW_UTIL(bcm4908asus "" "" "") FW_UTIL(bcm4908kernel "" "" "") FW_UTIL(buffalo-enc src/buffalo-lib.c "" "") diff --git a/src/avm-wasp-checksum.c b/src/avm-wasp-checksum.c new file mode 100644 index 0000000..8c112f3 --- /dev/null +++ b/src/avm-wasp-checksum.c @@ -0,0 +1,171 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2020 Andreas Boehler + * + * This tool was based on: + * firmware-crc.pl by Atheros Communications + * + * 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 /* for getopt() */ +#include + +char *infile; +char *outfile; +char *progname; +enum { + MODEL_3390, + MODEL_X490 +} model; + +#define CHUNK_SIZE 256 + +uint32_t crc32_for_byte(uint32_t r) +{ + for (int j = 0; j < 8; ++j) + r = (r & 1 ? 0 : (uint32_t)0xEDB88320L) ^ r >> 1; + return r ^ (uint32_t)0xFF000000L; +} + +void crc32(const void *data, size_t n_bytes, uint32_t *crc) +{ + static uint32_t table[0x100]; + + if (!*table) + for (size_t i = 0; i < 0x100; ++i) + table[i] = crc32_for_byte(i); + for (size_t i = 0; i < n_bytes; ++i) + *crc = table[(uint8_t)*crc ^ ((uint8_t *)data)[i]] ^ *crc >> 8; +} + +static void usage(int status) +{ + fprintf(stderr, "Usage: %s [OPTIONS...]\n", progname); + fprintf(stderr, + "\n" + "Options:\n" + " -i input file name\n" + " -o output file name\n" + " -m model (3390, x490 for 3490/5490/7490)\n" + " -h show this screen\n" + ); + + exit(status); +} + +int main(int argc, char *argv[]) +{ + uint32_t crc = 0; + FILE *in_fp; + FILE *out_fp; + uint32_t buf[CHUNK_SIZE]; + size_t read; + + progname = argv[0]; + + while (1) { + int c; + + c = getopt(argc, argv, "i:o:m:h"); + if (c == -1) + break; + + switch (c) { + case 'i': + infile = optarg; + break; + case 'o': + outfile = optarg; + break; + case 'm': + if (strcmp(optarg, "3390") == 0) + model = MODEL_3390; + else if (strcmp(optarg, "x490") == 0) + model = MODEL_X490; + else + usage(EXIT_FAILURE); + break; + case 'h': + usage(EXIT_SUCCESS); + default: + usage(EXIT_FAILURE); + break; + } + } + + if (!infile || !outfile) + usage(EXIT_FAILURE); + + in_fp = fopen(infile, "r"); + if (!in_fp) { + fprintf(stderr, "Error opening input file: %s\n", infile); + return EXIT_FAILURE; + } + out_fp = fopen(outfile, "w"); + if (!out_fp) { + fprintf(stderr, "Error opening output file: %s\n", outfile); + fclose(in_fp); + return EXIT_FAILURE; + } + + while (!feof(in_fp)) { + switch (model) { + case MODEL_3390: + read = fread(buf, sizeof(uint32_t), CHUNK_SIZE, in_fp); + if (ferror(in_fp)) { + fprintf(stderr, "Error reading input file: %s\n", infile); + fclose(in_fp); + fclose(out_fp); + return EXIT_FAILURE; + } + for (int i = 0; i < read; i++) + crc = crc ^ buf[i]; + fwrite(buf, sizeof(uint32_t), read, out_fp); + if (ferror(out_fp)) { + fprintf(stderr, "Error writing output file: %s\n", outfile); + fclose(in_fp); + fclose(out_fp); + return EXIT_FAILURE; + } + break; + case MODEL_X490: + read = fread(buf, 1, sizeof(uint32_t) * CHUNK_SIZE, in_fp); + if (ferror(in_fp)) { + fprintf(stderr, "Error reading input file: %s\n", infile); + fclose(in_fp); + fclose(out_fp); + return EXIT_FAILURE; + } + crc32(buf, read, &crc); + fwrite(buf, 1, read, out_fp); + if (ferror(out_fp)) { + fprintf(stderr, "Error writing output file: %s\n", outfile); + fclose(in_fp); + fclose(out_fp); + return EXIT_FAILURE; + } + break; + } + } + if (model == MODEL_X490) + crc = __bswap_32(crc); + fwrite(&crc, sizeof(uint32_t), 1, out_fp); + if (ferror(out_fp)) { + fprintf(stderr, "Error writing checksum to output file: %s\n", outfile); + fclose(in_fp); + fclose(out_fp); + return EXIT_FAILURE; + } + fclose(in_fp); + fclose(out_fp); + printf("Done.\n"); + return EXIT_SUCCESS; +}