From patchwork Thu Dec 21 22:59:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Heimpold X-Patchwork-Id: 852167 X-Patchwork-Delegate: blogic@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="i5tk/jl1"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=heimpold.de header.i=@heimpold.de header.b="fom5An9S"; dkim-atps=neutral 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 3z2nFH4mqwz9ryQ for ; Fri, 22 Dec 2017 10:01:23 +1100 (AEDT) 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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Subject:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=QnDUPU70iAizhv5IIAn4aCfJJbClps+0NN4bU2lbh+I=; b=i5tk/jl1Cj3SJj UPsuyXTq8aHJ3Kk5tVhjgph9g+qAe2zefm5Tt5CnpQZeOHuFCTTjKbr9z+D9UmPpoG32OolGvlbsq 49LEEWy41aPd/SNycbh+Pk35muOVF+YMARZ91khSr+ph57rhDOSHW11IKbK2tKoQcKAJJ+9HFvAnW tvaVsNy6UoQ6wmaxgJlycV2FpC2MOYQRUCIFA+eQoV3Kv6xUhTfVYnIEi3g1rQKvpq3gxmp+Nhmc1 ayfhrJJ5Kor5vtyLo684FARFpwRjZywn9vTsaAkPOaBFZyZ5tPzrMo2Hci3PKTiypZcMPkS4q21ih R8D7mTSZctSsL2MyqXdQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eS9pt-00078u-Gx; Thu, 21 Dec 2017 23:01:09 +0000 Received: from mo6-p00-ob.smtp.rzone.de ([2a01:238:20a:202:5300::3]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eS9om-0005Vy-3K for lede-dev@lists.infradead.org; Thu, 21 Dec 2017 23:00:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1513897187; s=domk; d=heimpold.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject; bh=DekTs+UK2ac65L8fscZfhHQ5oD/QA/aCn9m0qNWXFhU=; b=fom5An9ScDYgyLlrsewNxJLiqVTzKspBsJWyKHaMRgVhNvNccCubbUCD+/f0DuboST pqkAZzw7FaXe+K8RQEQamx1+ItEqie5Wxg1+RA16edZ+uQm5BRI2+d8+D/GWweE3aye0 jEJ7+OvIh35LolpsAmnYuC66oZH0V9+S6ql88= X-RZG-AUTH: :O2kGeEG7b/pS1EW8QnKjhhg/vO4pzqdNytq77N6ZPUGwIpLOmsCM+BB/Jumg6xgvP7zTEmd6XE5ldAR8t4zBTaiOPbzqatzKSbW9t+O5KA== X-RZG-CLASS-ID: mo00 Received: from tonne.mhei.heimpold.itr (p200300C7CBD4A700505400FFFEE949E7.dip0.t-ipconnect.de [IPv6:2003:c7:cbd4:a700:5054:ff:fee9:49e7]) by smtp.strato.de (RZmta 42.14 AUTH) with ESMTPSA id Y00a23tBLMxkSWQ (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Thu, 21 Dec 2017 23:59:46 +0100 (CET) Received: from kerker.mhei.heimpold.itr (kerker.mhei.heimpold.itr [192.168.8.1]) by tonne.mhei.heimpold.itr (Postfix) with ESMTP id 4CABB1C23FD; Thu, 21 Dec 2017 23:59:46 +0100 (CET) From: Michael Heimpold To: lede-dev@lists.infradead.org Date: Thu, 21 Dec 2017 23:59:28 +0100 Message-Id: <1513897174-20803-2-git-send-email-mhei@heimpold.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513897174-20803-1-git-send-email-mhei@heimpold.de> References: <1513897174-20803-1-git-send-email-mhei@heimpold.de> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171221_150000_589612_7F116F05 X-CRM114-Status: GOOD ( 13.42 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.1 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 [2a01:238:20a:202:5300:0:0:3 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -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 Subject: [LEDE-DEV] [PATCH 1/7] firmware-tools/ptgen: fix minor coding style issues 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: Michael Heimpold MIME-Version: 1.0 Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Signed-off-by: Michael Heimpold --- tools/firmware-utils/src/ptgen.c | 60 +++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/tools/firmware-utils/src/ptgen.c b/tools/firmware-utils/src/ptgen.c index 8466d35..93d66eb 100644 --- a/tools/firmware-utils/src/ptgen.c +++ b/tools/firmware-utils/src/ptgen.c @@ -1,4 +1,4 @@ -/* +/* * ptgen - partition table generator * Copyright (C) 2006 by Felix Fietkau * @@ -9,12 +9,12 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA @@ -63,25 +63,26 @@ struct partinfo parts[4]; char *filename = NULL; -/* +/* * parse the size argument, which is either * a simple number (K assumed) or * K, M or G * * returns the size in KByte */ -static long to_kbytes(const char *string) { +static long to_kbytes(const char *string) +{ int exp = 0; long result; char *end; result = strtoul(string, &end, 0); switch (tolower(*end)) { - case 'k' : - case '\0' : exp = 0; break; - case 'm' : exp = 1; break; - case 'g' : exp = 2; break; - default: return 0; + case 'k' : + case '\0' : exp = 0; break; + case 'm' : exp = 1; break; + case 'g' : exp = 2; break; + default: return 0; } if (*end) @@ -99,9 +100,10 @@ static long to_kbytes(const char *string) { } /* convert the sector number into a CHS value for the partition table */ -static void to_chs(long sect, unsigned char chs[3]) { +static void to_chs(long sect, unsigned char chs[3]) +{ int c,h,s; - + s = (sect % sectors) + 1; sect = sect / sectors; h = sect % heads; @@ -116,10 +118,11 @@ static void to_chs(long sect, unsigned char chs[3]) { } /* round the sector number up to the next cylinder */ -static inline unsigned long round_to_cyl(long sect) { +static inline unsigned long round_to_cyl(long sect) +{ int cyl_size = heads * sectors; - return sect + cyl_size - (sect % cyl_size); + return sect + cyl_size - (sect % cyl_size); } /* round the sector number up to the kb_align boundary */ @@ -131,7 +134,7 @@ static inline unsigned long round_to_kb(long sect) { static int gen_ptable(uint32_t signature, int nr) { struct pte pte[4]; - unsigned long sect = 0; + unsigned long sect = 0; int i, fd, ret = -1, start, len; memset(pte, 0, sizeof(struct pte) * 4); @@ -140,22 +143,27 @@ static int gen_ptable(uint32_t signature, int nr) fprintf(stderr, "Invalid size in partition %d!\n", i); return -1; } + pte[i].active = ((i + 1) == active) ? 0x80 : 0; pte[i].type = parts[i].type; + start = sect + sectors; if (kb_align != 0) start = round_to_kb(start); pte[i].start = cpu_to_le32(start); + sect = start + parts[i].size * 2; if (kb_align == 0) sect = round_to_cyl(sect); pte[i].length = cpu_to_le32(len = sect - start); + to_chs(start, pte[i].chs_start); to_chs(start + len - 1, pte[i].chs_end); + if (verbose) - fprintf(stderr, "Partition %d: start=%ld, end=%ld, size=%ld\n", i, (long) start * 512, ((long) start + (long) len) * 512, (long) len * 512); - printf("%ld\n", ((long) start * 512)); - printf("%ld\n", ((long) len * 512)); + fprintf(stderr, "Partition %d: start=%ld, end=%ld, size=%ld\n", i, (long)start * 512, ((long)start + (long)len) * 512, (long)len * 512); + printf("%ld\n", (long)start * 512); + printf("%ld\n", (long)len * 512); } if ((fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0644)) < 0) { @@ -179,7 +187,7 @@ static int gen_ptable(uint32_t signature, int nr) fprintf(stderr, "write failed.\n"); goto fail; } - + ret = 0; fail: close(fd); @@ -188,7 +196,7 @@ fail: static void usage(char *prog) { - fprintf(stderr, "Usage: %s [-v] -h -s -o [-a 0..4] [-l ] [[-t ] -p ...] \n", prog); + fprintf(stderr, "Usage: %s [-v] -h -s -o [-a 0..4] [-l ] [[-t ] -p ...] \n", prog); exit(1); } @@ -208,10 +216,10 @@ int main (int argc, char **argv) verbose++; break; case 'h': - heads = (int) strtoul(optarg, NULL, 0); + heads = (int)strtoul(optarg, NULL, 0); break; case 's': - sectors = (int) strtoul(optarg, NULL, 0); + sectors = (int)strtoul(optarg, NULL, 0); break; case 'p': if (part > 3) { @@ -222,15 +230,15 @@ int main (int argc, char **argv) parts[part++].type = type; break; case 't': - type = (char) strtoul(optarg, NULL, 16); + type = (char)strtoul(optarg, NULL, 16); break; case 'a': - active = (int) strtoul(optarg, NULL, 0); + active = (int)strtoul(optarg, NULL, 0); if ((active < 0) || (active > 4)) active = 0; break; case 'l': - kb_align = (int) strtoul(optarg, NULL, 0) * 2; + kb_align = (int)strtoul(optarg, NULL, 0) * 2; break; case 'S': signature = strtoul(optarg, NULL, 0); @@ -241,7 +249,7 @@ int main (int argc, char **argv) } } argc -= optind; - if (argc || (heads <= 0) || (sectors <= 0) || !filename) + if (argc || (heads <= 0) || (sectors <= 0) || !filename) usage(argv[0]); return gen_ptable(signature, part);