From patchwork Sun Jul 2 21:13:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 783240 X-Patchwork-Delegate: zajec5@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 3x131P2z1Pz9sNc for ; Mon, 3 Jul 2017 07:14:33 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="qFcNcMSj"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="YWikMTI4"; 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version: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=CXW4EcUIAXMGH1DcJyLmVvIkWao6F6GCFiPdJcCIDfo=; b=qFcNcMSj/1ptt7 VCPI7kScKKFVEMGL8Em+Lo0ZOgAl7/ytV7pDe16UABU1Bp4+ojN1dKFoQjT3dMN7hgiQnB3f/zf49 J/+j8830X/gei+ZyI+elsblZwo61txXhqCp39svQp/CL6nra+nG9I4893GlsHna/GA4L4FW+8WMHp qwkpk0j4ylto5bcIAQc9W4svktDnTdZTPf52v+OufFepFV2uidEunK/f655a0j8c83OPISGgn3G1a sWHjAls13G5BVGnf8ZvXNI001OUQpcQGmwZ/0AgkFiFYlYB53ilo9snBz/bmgXQGUPvAxOKwhnguJ +HFDfCYTih3i+0E1Mulg==; 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 1dRmC5-0002ZS-9x; Sun, 02 Jul 2017 21:14:13 +0000 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dRmC1-0002M8-IU for lede-dev@lists.infradead.org; Sun, 02 Jul 2017 21:14:11 +0000 Received: by mail-lf0-x241.google.com with SMTP id g21so13760010lfk.1 for ; Sun, 02 Jul 2017 14:13:49 -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:mime-version :content-transfer-encoding; bh=krOOJ7pVYuUF4RyuKPwn9UtLnEFWvcMCOXiJshM0IFY=; b=YWikMTI4kHqZMXtZZvTfiyKynoF7c3jOQ4ZMtVCDpPMup/gSWreZje03fKcu9ExzKj QKuaVb+cZglz7ANBP79blpTbjwJS1cLepIjZa8PLBGgvdB1+yZda16DhCjcvaJcHMsVJ 9dPzh83nVPStky3SIFJlj9hU3ri836h/J9bU3INu6GUix3N7x0e3MU5YU2b/Oy7VJFuS K669qfHDBSkZJT0RysE5KuusSxSXBabQEesdV/Yna2FaQgxoeSDCXPWeQux78Tx+pLQS a6NA5BYz6crUpjN0drT7sC4fhQDT0YftnKhsviPnsyluHLPKL3RWa4RCx5Ld7b/kw+Ln r1mg== 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:mime-version :content-transfer-encoding; bh=krOOJ7pVYuUF4RyuKPwn9UtLnEFWvcMCOXiJshM0IFY=; b=sv2vyGm0iT8Up1X7crbvxMuIHvXEbIrMSPhRGjFes+vc4U4bO3uGQ1/nLCeI8aPxPI XHop+QoPJeSuFHIZIaQYzJY8lELPR3sFXTibdWx7DjGgTV0XamBa8ALZ+eXAL5zB+ziM Oez6w9mrkTdmA8C2+PizibHUJ9FBtrlEyJZIO/t7izdwVWi8bnL9vuykQ9WN3AGLdsh0 vMMgzhKVvBnx7yaIabGETyxpaJTOum4Wxxc+ujwihvJlVAk+kUEJwwFkAG2Yqo4FZ5IJ RWbKJCk4kJ6o5+YaPbpieE0TiZlfFVTz2Xa34Jeco0AxG62C/HciX4iKcOWHk1AetTlI Ixeg== X-Gm-Message-State: AIVw1121EthlkKjROc3XbbO4q7TQrKlkIUHLYj4U7Kzl7si/cRt+QLop aGCckXN2WjtSWU7L X-Received: by 10.25.89.130 with SMTP id n124mr2206703lfb.82.1499030027156; Sun, 02 Jul 2017 14:13:47 -0700 (PDT) Received: from linux-samsung.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id 136sm2844565ljf.29.2017.07.02.14.13.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 Jul 2017 14:13:46 -0700 (PDT) From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= To: lede-dev@lists.infradead.org Date: Sun, 2 Jul 2017 23:13:39 +0200 Message-Id: <20170702211339.6709-1-zajec5@gmail.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170702_141409_900612_00B11EFF X-CRM114-Status: GOOD ( 11.62 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.5 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:241 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (zajec5[at]gmail.com) 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (zajec5[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: mktplinkfw2: use static board struct for custom values 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: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Rafał Miłecki It seems simpler to store all custom (command line set) option values in a struct identical to the predefined ones. It doesn't require: 1) Having so many global variables 2) Copying data from the predefined boards Signed-off-by: Rafał Miłecki --- tools/firmware-utils/src/mktplinkfw2.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/tools/firmware-utils/src/mktplinkfw2.c b/tools/firmware-utils/src/mktplinkfw2.c index 98dcdf6b74..2395d30c04 100644 --- a/tools/firmware-utils/src/mktplinkfw2.c +++ b/tools/firmware-utils/src/mktplinkfw2.c @@ -118,16 +118,15 @@ static char *fw_ver = "0.0.0"; static char *sver = "1.0"; static uint32_t hdr_ver = 2; +static struct board_info custom_board; + static char *board_id; static struct board_info *board; static char *layout_id; static struct flash_layout *layout; static char *opt_hw_id; -static uint32_t hw_id; static char *opt_hw_rev; -static uint32_t hw_rev; static char *opt_hw_ver_add; -static uint32_t hw_ver_add; static int fw_ver_lo; static int fw_ver_mid; static int fw_ver_hi; @@ -148,7 +147,6 @@ static unsigned char jffs2_eof_mark[4] = {0xde, 0xad, 0xc0, 0xde}; static struct file_info inspect_info; static int extract = 0; -static bool endian_swap = false; char md5salt_normal[MD5SUM_LEN] = { 0xdc, 0xd7, 0x3a, 0xa5, 0xc3, 0x95, 0x98, 0xfb, @@ -430,28 +428,27 @@ static int check_options(void) if (layout_id == NULL) layout_id = board->layout_id; - hw_id = board->hw_id; - hw_rev = board->hw_rev; - hw_ver_add = board->hw_ver_add; if (board->hdr_ver) hdr_ver = board->hdr_ver; - endian_swap = board->endian_swap; } else { + board = &custom_board; + if (layout_id == NULL) { ERR("flash layout is not specified"); return -1; } - hw_id = strtoul(opt_hw_id, NULL, 0); + + board->hw_id = strtoul(opt_hw_id, NULL, 0); if (opt_hw_rev) - hw_rev = strtoul(opt_hw_rev, NULL, 0); + board->hw_rev = strtoul(opt_hw_rev, NULL, 0); else - hw_rev = 1; + board->hw_rev = 1; if (opt_hw_ver_add) - hw_ver_add = strtoul(opt_hw_ver_add, NULL, 0); + board->hw_ver_add = strtoul(opt_hw_ver_add, NULL, 0); else - hw_ver_add = 0; + board->hw_ver_add = 0; } layout = find_layout(layout_id); @@ -556,9 +553,9 @@ static void fill_header(char *buf, int len) memcpy(hdr->fw_version, version, ver_len); hdr->fw_version[ver_len] = 0; - hdr->hw_id = htonl(hw_id); - hdr->hw_rev = htonl(hw_rev); - hdr->hw_ver_add = htonl(hw_ver_add); + hdr->hw_id = htonl(board->hw_id); + hdr->hw_rev = htonl(board->hw_rev); + hdr->hw_ver_add = htonl(board->hw_ver_add); if (boot_info.file_size == 0) { memcpy(hdr->md5sum1, md5salt_normal, sizeof(hdr->md5sum1)); @@ -595,7 +592,7 @@ static void fill_header(char *buf, int len) hdr->ver_mid = fw_ver_mid; hdr->ver_lo = fw_ver_lo; - if (endian_swap) { + if (board->endian_swap) { hdr->kernel_la = bswap_32(hdr->kernel_la); hdr->kernel_ep = bswap_32(hdr->kernel_ep); } @@ -1039,7 +1036,7 @@ int main(int argc, char *argv[]) hdr_ver = atoi(optarg); break; case 'e': - endian_swap = true; + custom_board.endian_swap = true; break; case 'h': usage(EXIT_SUCCESS);