From patchwork Mon Dec 19 10:36:04 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Gorski X-Patchwork-Id: 132185 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id DE24DB6FFE for ; Mon, 19 Dec 2011 21:38:30 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1RcaaT-0006Dc-7L; Mon, 19 Dec 2011 10:36:53 +0000 Received: from mail-ey0-f177.google.com ([209.85.215.177]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1RcaaO-0006DO-Dr for linux-mtd@lists.infradead.org; Mon, 19 Dec 2011 10:36:49 +0000 Received: by eaak12 with SMTP id k12so4969650eaa.36 for ; Mon, 19 Dec 2011 02:36:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=29OAhnzIw6HLVcB3SjCQ60EnCgSqR0nzSaGfqF8M3F0=; b=QsqRLcF8Xs+DVYD3M9RinyF8NPX3tIbrLakPPyJaSEtkWzhah9YjJQ/CxcUuwpC9qp 9nbF9jNx0aWr8yDPICSl+fKjayEYAZchnfdFq03+KYU2bRxgTxVTbvWsTsDvvdQGEu/4 GVHBei/sfZZAjiUiJHwfpRXOAYuwtIHtxWCTw= Received: by 10.205.138.5 with SMTP id iq5mr1240523bkc.76.1324291005678; Mon, 19 Dec 2011 02:36:45 -0800 (PST) Received: from shaker64.lan (dslb-088-073-137-229.pools.arcor-ip.net. [88.73.137.229]) by mx.google.com with ESMTPS id fa8sm40036609bkc.14.2011.12.19.02.36.43 (version=SSLv3 cipher=OTHER); Mon, 19 Dec 2011 02:36:44 -0800 (PST) From: Jonas Gorski To: Artem Bityutskiy Subject: [PATCH V2 2/5] MTD: bcm63xxpart: make sure CFE and NVRAM partitions are at least 64K Date: Mon, 19 Dec 2011 11:36:04 +0100 Message-Id: <1324290964-14096-1-git-send-email-jonas.gorski@gmail.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1324208821.17534.0.camel@sauron.fi.intel.com> References: <1324208821.17534.0.camel@sauron.fi.intel.com> X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (jonas.gorski[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -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 -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: linux-mips@linux-mips.org, linux-mtd@lists.infradead.org, David Woodhouse , Florian Fainelli X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The CFE boot loader on BCM63XX platforms assumes itself and the NVRAM partition to be 64 KiB (or erase block sized, if larger). Ensure this assumption is also met when creating the partitions to prevent accidential erasure of CFE or NVRAM. Signed-off-by: Jonas Gorski --- Changes V1 -> V2: Clarified the need for the minimum size. Hope this one's better :) drivers/mtd/bcm63xxpart.c | 22 +++++++++++++++------- 1 files changed, 15 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/bcm63xxpart.c b/drivers/mtd/bcm63xxpart.c index 9933b34..23f6201 100644 --- a/drivers/mtd/bcm63xxpart.c +++ b/drivers/mtd/bcm63xxpart.c @@ -36,6 +36,9 @@ #define BCM63XX_EXTENDED_SIZE 0xBFC00000 /* Extended flash address */ +#define BCM63XX_MIN_CFE_SIZE 0x10000 /* always at least 64K */ +#define BCM63XX_MIN_NVRAM_SIZE 0x10000 /* always at least 64K */ + #define BCM63XX_CFE_MAGIC_OFFSET 0x4e0 static int bcm63xx_detect_cfe(struct mtd_info *master) @@ -74,6 +77,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, size_t retlen; unsigned int rootfsaddr, kerneladdr, spareaddr; unsigned int rootfslen, kernellen, sparelen, totallen; + unsigned int cfelen, nvramlen; int namelen = 0; int i; char *boardid; @@ -82,14 +86,18 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, if (bcm63xx_detect_cfe(master)) return -EINVAL; + cfelen = max_t(uint32_t, master->erasesize, BCM63XX_MIN_CFE_SIZE); + nvramlen = max_t(uint32_t, master->erasesize, BCM63XX_MIN_NVRAM_SIZE); + /* Allocate memory for buffer */ buf = vmalloc(sizeof(struct bcm_tag)); if (!buf) return -ENOMEM; /* Get the tag */ - ret = master->read(master, master->erasesize, sizeof(struct bcm_tag), - &retlen, (void *)buf); + ret = master->read(master, cfelen, sizeof(struct bcm_tag), &retlen, + (void *)buf); + if (retlen != sizeof(struct bcm_tag)) { vfree(buf); return -EIO; @@ -106,8 +114,8 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, kerneladdr = kerneladdr - BCM63XX_EXTENDED_SIZE; rootfsaddr = kerneladdr + kernellen; - spareaddr = roundup(totallen, master->erasesize) + master->erasesize; - sparelen = master->size - spareaddr - master->erasesize; + spareaddr = roundup(totallen, master->erasesize) + cfelen; + sparelen = master->size - spareaddr - nvramlen; rootfslen = spareaddr - rootfsaddr; /* Determine number of partitions */ @@ -131,7 +139,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, /* Start building partition list */ parts[curpart].name = "CFE"; parts[curpart].offset = 0; - parts[curpart].size = master->erasesize; + parts[curpart].size = cfelen; curpart++; if (kernellen > 0) { @@ -151,8 +159,8 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, } parts[curpart].name = "nvram"; - parts[curpart].offset = master->size - master->erasesize; - parts[curpart].size = master->erasesize; + parts[curpart].offset = master->size - nvramlen; + parts[curpart].size = nvramlen; /* Global partition "linux" to make easy firmware upgrade */ curpart++;