From patchwork Thu May 2 14:30:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 163263 Delivered-To: patch@linaro.org Received: by 2002:a92:7e86:0:0:0:0:0 with SMTP id q6csp5809082ill; Thu, 2 May 2019 07:33:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqz2jhfauug2Nn6+KcLzMBwNhOdwgqROeVK/w3DB8m33DBY6JBwEhMgHgZ7bFx6nOjMbHnR9 X-Received: by 2002:a65:51c5:: with SMTP id i5mr4335182pgq.189.1556807596025; Thu, 02 May 2019 07:33:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556807596; cv=none; d=google.com; s=arc-20160816; b=TFdQ4ScrppwaCkZlo8A6dQvgHy7tkvs9O7EJRvo5HGG+qjiz//jjiU7uGyxfCVJIHN v9LhOg07A95aD1FnQmdra+znErQS7cFIqCyATF/SEgxCF1Xct2CD673TmAg0gYP+8SF7 3PdJdmOXellmeMbwJWmxWBptOn5GjxiwHnwPk+0kIDWfvKr5+FeWbHw7AK4jPjqGbOET Rz12H1LYFjiU5Nm22AzPQeaLOaOej25+icFEARuACZ6Qe1yUmQxjPNfesZHwb4AMeqfp VLST21ptGqCF8//bJYOcMerrEeAK9dbpI8YEYawCZDXVoio7e7swnRnfeM4WfuOfAWPI NUmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:dkim-signature; bh=IDlx9JIz/j5vhDo/sU2Ok8HnWLOMFZP1m5XyjIhQXVQ=; b=oALOJMCdP+70eELnUNDIn8uhJpsa+u00ZidfqFJXKM6LBnjUrg0314e7GlCjS4Lc4K TpGRJSp89dAQwTRklYWtoWjrtxqV8Cet3z0ZrivhHeF4kYPUkmxuQaaY6DS36GNWGaXN xZb53TZjAdXRw6wHc10ZJx0L0FL+y7aHbKEHc2e6vY2X2WEPaVVC5nlFxjRVPUgGHi04 jYV355PdtyZLz/9adrlfg8Q6Svxr66LpbhIo+q0DpY2QIRQF60fZSir3AqAeygpQSUda G/vGJKNM6XvkJpB1jQD111mL/VjlFX/U+qYOzmxXCmKilno5bUlihJ55UcgsCh9xFNeF lZNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=XKqxE93F; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=B8bbSTqI; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id l13si15396299pgh.88.2019.05.02.07.33.15 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 07:33:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=XKqxE93F; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=B8bbSTqI; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=IDlx9JIz/j5vhDo/sU2Ok8HnWLOMFZP1m5XyjIhQXVQ=; b=XKqxE93FtLp4+i F5J7HVCRBt+ISfCmWP0A3MQDt3vIiZSNPYqIs193ei6Patlc1/YSuACP1OaXqfFLpKREKf0kj5QhT L8PxEAkINkz+lDvMGEsSlXN3T5HNgdmQnevDskVUlQ6Wc0+qP/w1m45rvOUttTN5IclQgSSmEMWHc uUHwUYqdXK4uo5k4lGkt9mKnP1fsRAExYByEctrGsTZ07u/mbIFWsFQ2Gmntdv0JzYZIpVdSGhPFD AH3CjJVesJcVrQpudlofEQXGYkSQIFm6z2ZTqoD+BfTqYExBq790FE4X1ZliLLRdFOH3+vZiIyzt8 8evfP0/6aqOK3DiQ0zlw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMCll-0000s3-BG; Thu, 02 May 2019 14:33:05 +0000 Received: from mail-lf1-x144.google.com ([2a00:1450:4864:20::144]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMClh-0000pk-Jr for linux-mtd@lists.infradead.org; Thu, 02 May 2019 14:33:03 +0000 Received: by mail-lf1-x144.google.com with SMTP id t11so2034889lfl.12 for ; Thu, 02 May 2019 07:33:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DLwpITDJbH5GI5CFlNLCDZnAvlJ2JECuaH3FVz5jQ5k=; b=B8bbSTqIqX7Z3Y/lOUkykw5zHh0zBSiJa0H00hD5qAIoS8iHZYC2RkYIHqbEt0f53l DJ0jfody6Gp/40F1UpsoMBlN6w/42tf9Css6hiKEz6okVgyZUdQbngtnpWCQ2I4pAPir o1nK1z+Qt/hkacbm1Vr5lshgYPVqYplOku7zPzNzVtS5i+xrF+Gw8+kpFddqFJgWAXER 17QcN+srN7FchUd+l2dgkDHT5dzMLzgO+9P9vvr0V8or2O6k950RGv6wMYOikujbPsLc 0jhBBGIcH+7qmqtlt2W6C2jn1fBngpVaWIToe+nUI5jxOO67z2xnJAjucpPu818PO0L6 gCbg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=DLwpITDJbH5GI5CFlNLCDZnAvlJ2JECuaH3FVz5jQ5k=; b=toM9liV8jesRvtook3B4teUeFG6ST0Ns228kXRdTTK2EKamFCIgt5O92JzCjDEOR6I 7LDj6KdNVuG8GjAvB+h14m0BRo4mI29LDsEpusqXZZDFdsjLomeZYXi5KhqXvCVNXY7/ Fp7YmkcSzo2QKA7KjcFs5PENQVX3KauvcpOtgZPkWh7S5WXfpkWoycHf9ptuGw4hOaNV 529FC/9n/qdUjlyPPt29cexIumypc8nrLMOx2Kq5nf3/MrrHq8PQokHGX6JS+URuRsXL gtTEw+RiRtxWf7RCTCLEMHYg8I+YsIAuZtxSJX2y08kFs4GXxQOIyI6wcSGRgJUHEwyw XFpw== X-Gm-Message-State: APjAAAXgG+uznWrKjiSIbPIfbfz6ar/HmOH9tjWHwMpfrbJuQh5d8eLj OCSr4wXN6QuxP7x956WepY2gVA== X-Received: by 2002:ac2:596d:: with SMTP id h13mr2347513lfp.35.1556807579576; Thu, 02 May 2019 07:32:59 -0700 (PDT) Received: from localhost.localdomain (c-d2cd225c.014-348-6c756e10.bbcust.telenor.se. [92.34.205.210]) by smtp.gmail.com with ESMTPSA id l79sm9430625lfe.92.2019.05.02.07.32.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 07:32:58 -0700 (PDT) From: Linus Walleij To: David Woodhouse , Brian Norris , Marek Vasut , Richard Weinberger , Miquel Raynal , linux-mtd@lists.infradead.org Subject: [PATCH 1/9 RESEND 2] mtd: afs: Move AFS partition parser to parsers subdir Date: Thu, 2 May 2019 16:30:26 +0200 Message-Id: <20190502143034.16781-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190502143034.16781-1-linus.walleij@linaro.org> References: <20190502143034.16781-1-linus.walleij@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190502_073301_649251_FA51400E X-CRM114-Status: GOOD ( 13.48 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:144 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -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_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Linus Walleij Sender: "linux-mtd" Errors-To: linux-mtd-bounces+patch=linaro.org@lists.infradead.org This moves the AFS (ARM Firmware Suite) partition parser for NOR flash down into the parsers subdirectory. Signed-off-by: Linus Walleij --- drivers/mtd/Kconfig | 16 ---------------- drivers/mtd/Makefile | 1 - drivers/mtd/parsers/Kconfig | 16 ++++++++++++++++ drivers/mtd/parsers/Makefile | 1 + drivers/mtd/{ => parsers}/afs.c | 0 5 files changed, 17 insertions(+), 17 deletions(-) rename drivers/mtd/{ => parsers}/afs.c (100%) -- 2.20.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig index 79a8ff542883..55cacc1edcd4 100644 --- a/drivers/mtd/Kconfig +++ b/drivers/mtd/Kconfig @@ -60,22 +60,6 @@ config MTD_CMDLINE_PARTS If unsure, say 'N'. -config MTD_AFS_PARTS - tristate "ARM Firmware Suite partition parsing" - depends on (ARM || ARM64) - help - The ARM Firmware Suite allows the user to divide flash devices into - multiple 'images'. Each such image has a header containing its name - and offset/size etc. - - If you need code which can detect and parse these tables, and - register MTD 'partitions' corresponding to each image detected, - enable this option. - - You will still need the parsing functions to be called by the driver - for your particular device. It won't happen automatically. The - 'physmap' map driver (CONFIG_MTD_PHYSMAP) does this, for example. - config MTD_OF_PARTS tristate "OpenFirmware partitioning information support" default y diff --git a/drivers/mtd/Makefile b/drivers/mtd/Makefile index 58fc327a5276..806287e80e84 100644 --- a/drivers/mtd/Makefile +++ b/drivers/mtd/Makefile @@ -9,7 +9,6 @@ mtd-y := mtdcore.o mtdsuper.o mtdconcat.o mtdpart.o mtdchar.o obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o obj-$(CONFIG_MTD_CMDLINE_PARTS) += cmdlinepart.o -obj-$(CONFIG_MTD_AFS_PARTS) += afs.o obj-$(CONFIG_MTD_AR7_PARTS) += ar7part.o obj-$(CONFIG_MTD_BCM63XX_PARTS) += bcm63xxpart.o obj-$(CONFIG_MTD_BCM47XX_PARTS) += bcm47xxpart.o diff --git a/drivers/mtd/parsers/Kconfig b/drivers/mtd/parsers/Kconfig index fccf1950e92d..419529318504 100644 --- a/drivers/mtd/parsers/Kconfig +++ b/drivers/mtd/parsers/Kconfig @@ -1,3 +1,19 @@ +config MTD_AFS_PARTS + tristate "ARM Firmware Suite partition parsing" + depends on (ARM || ARM64) + help + The ARM Firmware Suite allows the user to divide flash devices into + multiple 'images'. Each such image has a header containing its name + and offset/size etc. + + If you need code which can detect and parse these tables, and + register MTD 'partitions' corresponding to each image detected, + enable this option. + + You will still need the parsing functions to be called by the driver + for your particular device. It won't happen automatically. The + 'physmap' map driver (CONFIG_MTD_PHYSMAP) does this, for example. + config MTD_PARSER_TRX tristate "Parser for TRX format partitions" depends on MTD && (BCM47XX || ARCH_BCM_5301X || COMPILE_TEST) diff --git a/drivers/mtd/parsers/Makefile b/drivers/mtd/parsers/Makefile index d8418bf6804a..f7a8fe66e2ca 100644 --- a/drivers/mtd/parsers/Makefile +++ b/drivers/mtd/parsers/Makefile @@ -1,3 +1,4 @@ +obj-$(CONFIG_MTD_AFS_PARTS) += afs.o obj-$(CONFIG_MTD_PARSER_TRX) += parser_trx.o obj-$(CONFIG_MTD_SHARPSL_PARTS) += sharpslpart.o obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o diff --git a/drivers/mtd/afs.c b/drivers/mtd/parsers/afs.c similarity index 100% rename from drivers/mtd/afs.c rename to drivers/mtd/parsers/afs.c From patchwork Thu May 2 14:30:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 163264 Delivered-To: patch@linaro.org Received: by 2002:a92:7e86:0:0:0:0:0 with SMTP id q6csp5809435ill; Thu, 2 May 2019 07:33:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqz1zYvY1ZvBmZZJi8+v6vDoeVAiB4HkLkaBcXX/eq20d07/TGx0qdjXVr4ChgZgD6a507Uz X-Received: by 2002:aa7:8092:: with SMTP id v18mr4483499pff.35.1556807613928; Thu, 02 May 2019 07:33:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556807613; cv=none; d=google.com; s=arc-20160816; b=l5J7Zky35QcljX97vhBPx0rKGWg81VsbHLeo5v4QVp0A4cbyHr2nJqV8nXycJoAtsl dmML6D3vwgPJH6qNLyF1ejF1QMnrmqaBHEx9XTXX/hry/a8VAGHNI9MncoYdlAWYe5t6 CeDoik/PUuuQxHGZwDQRJ9+q2J2RvPs6cZd9JxbEUJPtZwuO97Wy4CvdR3ryy1NOjLl9 dzByXQ/JJjfurKLDefY9fSGdkP8QI02jaxkoSQYqmYTveo3oC9j6A5AwLRI1lAeikkLx v9Z+SulKHsBtwolZUGMmRLaEb18vhRPC30a+oa76LIWhi2DP/m+32/iOAHnXwkEpquoz o1+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:dkim-signature; bh=qWyAfF+ARACNCNglXLQZFObMilSOE+gUwD02cNO7xzE=; b=GHB+5E967SPhzeUW3wemdBVSOzj/2B6E8zfh778pRN88R3Kts+WCHEQAr46q5TMgUd le7RRA6yN8EMix4AUzTxHqpQL62W3oeAgvEgaKcyOaU8BOtkwp49cgrJUmpL8xi9q9TQ BXyG+IkcBBxIZA96n/kPuaHr9pTRIIGa5uSkwIH79EkOLwjP2iqLM7IJUKj1dYAkA+Bg AH5MA7DXAlcVoaIXPk+AcaTp8ZCPl/lKRyhlpLwV8OuAq14NogyWuI45ui/5UAG0OCN5 +9xtzKtgWt+YdA+D6zLVXZMNNq+tT//ctaBQ1m2Mk+/vIAXbNEENCAi6/FhLwB8y84kJ 6Qfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=P1NDwXRn; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=SXUDLULi; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id 3si47441802plo.300.2019.05.02.07.33.33 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 07:33:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=P1NDwXRn; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=SXUDLULi; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=qWyAfF+ARACNCNglXLQZFObMilSOE+gUwD02cNO7xzE=; b=P1NDwXRnZAoWlc L4N18Df42q58+uBSrfEY3a2X/Qn6J3tTOifRb4/puxAhGCneSNi8OafXiweUUcctMKnDtlRdARP2b 0QxMBERbsKpKtnUKqywXfHN9Oh9kEqcNwc7dV12mKWUdssUbX4ZnxDfSvYo9q+iYaYAhLJJhegJPw MZtQRnd/tkmfSzld82682V6/5anhrzwarDzRTtzQ2TrCc1JycaQqw7r3SAcABTZD36yLUdVD58bRs M4oahbmtVOgkOji3mmn17LjEJapirZjTCXIBOvrUGUcjJ7EIZ1U+AXehCC+jXwUvJDwV+PydJFjVw 5D+kDKOD9NOhQBVr3FKg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMCm3-0001H6-BK; Thu, 02 May 2019 14:33:23 +0000 Received: from mail-lf1-x143.google.com ([2a00:1450:4864:20::143]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMCln-0000tA-Ht for linux-mtd@lists.infradead.org; Thu, 02 May 2019 14:33:11 +0000 Received: by mail-lf1-x143.google.com with SMTP id v1so2060364lfg.5 for ; Thu, 02 May 2019 07:33:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Gewc66hFqAnao5dd8IKaoQ3SMy6KoSmYwlwea0wjupY=; b=SXUDLULiWdxE0S3I9fVX/PmlB772WLAgbkjKLXjiC/sBWUhpfclGdXt89Vl1ptM0Iw 9it1U0ddZ6+dxphHai+eIN/YT/OUwII18qI6GL3Kbw91cLm+aewWGQSZUUu5ekSRPzLw sA+KL2iKt7qN3vr73/KFhJ+S4EmJ5prhKKrYVXGFpb2DtFlS7a1dcPEUW1+/uNpT6vf0 W/PZ7vmo0n06TMYLblC6cXBVPYglQTQADRQ2g5mCHykf8d5f1y1kwq30boWSxSms2elx iGd5iRZh/IJdFxaE0RSmRYNevAEEbFyCRn6jzQVmyNoz+Xt0pwdOYlpC4k6t5cLjYFsw Y3dg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=Gewc66hFqAnao5dd8IKaoQ3SMy6KoSmYwlwea0wjupY=; b=BKS6aNNRH155XRJs4QI0oECYUdHwuA2rUke1LFyuYKP0eTx/J03MXHj8vzp7dER+bK p5gvz+sDZgFqO4GtcGDjKd2zcwMVggtejimk53NF4jPxYUYAMz1+IpjxEXymBDt8PoBc jQGKgzZH7O8xlgAHJQxWdokuVKz+NWZudBptJ5/VU+QQER18B4i2CHrpF3SPRaGvurNI 4hyUx7cNtaxJk15jMqETSaENKaYwLfotpxJZ4nFzU5csynnVF4V3hvHM0NxQLHcEC5C0 S6qML2B+L5KEk30+Vj+ub5NGsQpYBllUO11JZ5kZ3dNzjUGHjYmuobFc0cNyQwiKeEze V+yw== X-Gm-Message-State: APjAAAX9QJ8bJxX1r1KZxILPWBqtHaSiyPVqzOIn+bMqbPtJeQXftYpQ Mz7DsMD6vl6JuYRuhdK3WqtLQw== X-Received: by 2002:a19:a417:: with SMTP id q23mr2174757lfc.110.1556807585462; Thu, 02 May 2019 07:33:05 -0700 (PDT) Received: from localhost.localdomain (c-d2cd225c.014-348-6c756e10.bbcust.telenor.se. [92.34.205.210]) by smtp.gmail.com with ESMTPSA id l79sm9430625lfe.92.2019.05.02.07.33.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 07:33:04 -0700 (PDT) From: Linus Walleij To: David Woodhouse , Brian Norris , Marek Vasut , Richard Weinberger , Miquel Raynal , linux-mtd@lists.infradead.org Subject: [PATCH 3/9 RESEND 2] mtd: partitions: Add OF support to AFS partitions Date: Thu, 2 May 2019 16:30:28 +0200 Message-Id: <20190502143034.16781-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190502143034.16781-1-linus.walleij@linaro.org> References: <20190502143034.16781-1-linus.walleij@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190502_073308_117523_13ADDCD2 X-CRM114-Status: GOOD ( 13.27 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:143 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -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_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Linus Walleij Sender: "linux-mtd" Errors-To: linux-mtd-bounces+patch=linaro.org@lists.infradead.org This adds device tree support for AFS partitioning. Signed-off-by: Linus Walleij --- drivers/mtd/parsers/afs.c | 7 +++++++ 1 file changed, 7 insertions(+) -- 2.20.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ diff --git a/drivers/mtd/parsers/afs.c b/drivers/mtd/parsers/afs.c index d61b7edfc938..3679e1d22595 100644 --- a/drivers/mtd/parsers/afs.c +++ b/drivers/mtd/parsers/afs.c @@ -255,9 +255,16 @@ static int parse_afs_partitions(struct mtd_info *mtd, return idx ? idx : ret; } +static const struct of_device_id mtd_parser_afs_of_match_table[] = { + { .compatible = "arm,arm-firmware-suite" }, + {}, +}; +MODULE_DEVICE_TABLE(of, mtd_parser_afs_of_match_table); + static struct mtd_part_parser afs_parser = { .parse_fn = parse_afs_partitions, .name = "afs", + .of_match_table = mtd_parser_afs_of_match_table, }; module_mtd_part_parser(afs_parser); From patchwork Thu May 2 14:30:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 163265 Delivered-To: patch@linaro.org Received: by 2002:a92:7e86:0:0:0:0:0 with SMTP id q6csp5809618ill; Thu, 2 May 2019 07:33:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqyknB0dCYu4K3U544mU85Z88I3CVUnQeB2Bo4BqgtlIfaWv0xczeQ+N+ZsIJwFXq6LL+2HJ X-Received: by 2002:a62:5994:: with SMTP id k20mr4511759pfj.150.1556807624068; Thu, 02 May 2019 07:33:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556807624; cv=none; d=google.com; s=arc-20160816; b=QQtMCtqWHEfrqoM/zovwuyVw5RsF9ZDdD+npD1eJpqzusn9sR4joQp1lyvzIBKqxyU FCByuH1f4ktpgqJAiAZ3t0OFH6qJ7+YdYrpHIiPobXJLdxSz2jevM9kpj4xVUIXRlt2o GmL5upAFKD/ejsvV/ORN25/K2ZVE/hhjvnqxzFM6qeNXR7P2/DlnZ9G5GUr5McB/9XPc I2aqkTSOktffIfmb0dqKWslQASSaJN2HVKjOwyHKu0DPxQQzGR466UkUQz/tU9iY0qCS vUU+/Dbj5NjQ+bemtQEZw1+ZMQ6iC2HUWPVV9IWmD6FWl0iiSJ7jzhbhQZ0qhLiE3fEF WkIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:dkim-signature; bh=/En1BVyh0M0iO48rPx8d2VlGWTBy/CR7ht9GXG0vDeY=; b=DD99o8Yx7OMpyFH4a1em8/dNS1EoMs4BJbocrtBrFUfOcW3kYstu53Wlg+MPrukuUw 0GfAD1FKxOPAPcGwzwl9SA/TnH9NErzaYsrE8RperjGPFyFXLEHvpxjkqJkW2KCFEcAr a9+j/y+3UjVwxquy7b8yr7StNnvy+OR9QxW4eslxwUc2Qv9QZ9aOYsPx/qhb4KpawOL0 UvRKhpqaiEJChqJhYvN4NSgg0+PzXq53VLI6bBsh+3BprgZsgRBxiDzrVufx8e4BoUuu O1vX49uqVtQ6IzmgE9XwOai4D9Z8L721H9ckz0sze5uvFwhcDdL0qFdZmPhrBcBhlHQ5 +53w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=vDp333S2; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=jojellB7; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id g33si43089968pgb.192.2019.05.02.07.33.43 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 07:33:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=vDp333S2; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=jojellB7; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/En1BVyh0M0iO48rPx8d2VlGWTBy/CR7ht9GXG0vDeY=; b=vDp333S2sqHlQq VfeCE7cOT5QJY05bIxYwEaGQHQN9eqziVYHddJGpNaWukiklvn57RwrIl3W5BVDfz1r4yS1XxuhwT HPamz58LRYG+Rpf4xDQPe1JwQwUxPF6in/ZxMEg6ROf68UJ3JFiYzTnlyKIYZtQ31yTvPOCrADPa7 66w6PK7yTDFKUtpu5AxE0oFL+elsoZRg7kJStusDVuiyWx33RnFONv44U1YjZrXGJdj9oxPn8kGLX aDGbNRunA4dfBu+2nH3echFSXbACogW+I9eQUsPfIjI5Chfg8bpmY72Q4Wo8forqBcw8/UMroKmqG 60F9OPmp3DI/VS6TCz0g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMCmD-0001Vc-Tr; Thu, 02 May 2019 14:33:33 +0000 Received: from mail-lj1-x243.google.com ([2a00:1450:4864:20::243]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMClq-0000xf-MV for linux-mtd@lists.infradead.org; Thu, 02 May 2019 14:33:18 +0000 Received: by mail-lj1-x243.google.com with SMTP id b12so2396695lji.4 for ; Thu, 02 May 2019 07:33:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=t94QfyZ+Xm+PlEwTvOydeskpmPUSbr8jtJqXKc3oa1Q=; b=jojellB7eQYHQh2jiEdC3WoSIUGzBAXF4CAsT+921TB2HELzTjiGLwi8emvbhJPvJF wP08WvFkVK42LgkUwMIfr/iiLVRUt1WQXguXaf7smm8d/5nr+9/V9/6NT9AuZklJtI7K zgV168yLPnf4bpvEhpWMofy8BDOQnFjCdSfQb1hZhaRFKtY/FgI1T4cIU8zbzmWLzlcQ BhZ9D2LSwu8YXSF03JEIei5PN67PrbLsYcwdZr2GWp80z71snCZLLHdlr1XjryoJMgeZ Zdone5W3QB0QOgVDFmhG9R320A5GABy+jAhpLjQ0L9eLg8jZpXJOQM9KoKO7QY9/mWw/ LkAA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=t94QfyZ+Xm+PlEwTvOydeskpmPUSbr8jtJqXKc3oa1Q=; b=puWkfrPk/e/CO8i5Kjvx4kpblLOZA6xTQoflgB9UCwAm7ch9G3gkwj7wZulnwh8bZs ypndVe8XubRbu8DTWFFKJrHdIHL292+axA5cp7SsScLG5KgRvU/tTmfSBO49abAAS8Fw FnWxqWD3K43rzQFzjbIr/Bhxe8b7z670b5DI++2jKcwNwl7CuFuO5TAKTPmdnNEwc3Fv Qzfa5C3AN/woghPiXBkrqeCT3sdym438tGOx+xsZiExWucwOU061Mv/Ojx4flLluv438 R/vnBsMWk4H5Hk7l/32K2iW2qLJPqHw0PMGe2Jyw/8bY+Rh3FbmF2GFFO+3gwtnM5dWl X8Dg== X-Gm-Message-State: APjAAAWK0AHvhZeaZ4jlSJVRwOeb93ID7ql9DxEIE1UCvhEwq257uZWo ZCA2FKiOBqScMVHlV8L6sT1V1Q== X-Received: by 2002:a2e:9659:: with SMTP id z25mr2167017ljh.92.1556807588324; Thu, 02 May 2019 07:33:08 -0700 (PDT) Received: from localhost.localdomain (c-d2cd225c.014-348-6c756e10.bbcust.telenor.se. [92.34.205.210]) by smtp.gmail.com with ESMTPSA id l79sm9430625lfe.92.2019.05.02.07.33.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 07:33:07 -0700 (PDT) From: Linus Walleij To: David Woodhouse , Brian Norris , Marek Vasut , Richard Weinberger , Miquel Raynal , linux-mtd@lists.infradead.org Subject: [PATCH 4/9 RESEND 2] mtd: afs: simplify partition parsing Date: Thu, 2 May 2019 16:30:29 +0200 Message-Id: <20190502143034.16781-5-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190502143034.16781-1-linus.walleij@linaro.org> References: <20190502143034.16781-1-linus.walleij@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190502_073311_147601_6824AE14 X-CRM114-Status: GOOD ( 21.16 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:243 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -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_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Linus Walleij , Liviu Dudau , Ryan Harkin Sender: "linux-mtd" Errors-To: linux-mtd-bounces+patch=linaro.org@lists.infradead.org This simplifies the AFS partition parsing to make the code more straight-forward and readable. Before this patch the code tried to calculate the memory required to hold the partition info by adding up the sizes of the strings of the names and adding that to a single memory allocation, indexing the name pointers in front of the struct mtd_partition allocations so all allocated data was in one chunk. This is overzealous. Instead use kstrdup and bail out, kfree():ing the memory used for MTD partitions and names alike on the errorpath. In the process rename the index variable from idx to i. Cc: Ryan Harkin Acked-by: Liviu Dudau Signed-off-by: Linus Walleij --- drivers/mtd/parsers/afs.c | 67 +++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 35 deletions(-) -- 2.20.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ diff --git a/drivers/mtd/parsers/afs.c b/drivers/mtd/parsers/afs.c index 3679e1d22595..c489938cd665 100644 --- a/drivers/mtd/parsers/afs.c +++ b/drivers/mtd/parsers/afs.c @@ -166,9 +166,9 @@ static int parse_afs_partitions(struct mtd_info *mtd, struct mtd_part_parser_data *data) { struct mtd_partition *parts; - u_int mask, off, idx, sz; + u_int mask, off, sz; int ret = 0; - char *str; + int i; /* * This is the address mask; we use this to mask off out of @@ -181,78 +181,75 @@ static int parse_afs_partitions(struct mtd_info *mtd, * partition information. We include in this the size of * the strings. */ - for (idx = off = sz = 0; off < mtd->size; off += mtd->erasesize) { - struct image_info_v1 iis; + for (i = off = sz = 0; off < mtd->size; off += mtd->erasesize) { u_int iis_ptr, img_ptr; ret = afs_read_footer_v1(mtd, &img_ptr, &iis_ptr, off, mask); if (ret < 0) - break; + return ret; if (ret) { - ret = afs_read_iis_v1(mtd, &iis, iis_ptr); - if (ret < 0) - break; - if (ret == 0) - continue; - sz += sizeof(struct mtd_partition); - sz += strlen(iis.name) + 1; - idx += 1; + i += 1; } } - if (!sz) - return ret; + if (!i) + return 0; parts = kzalloc(sz, GFP_KERNEL); if (!parts) return -ENOMEM; - str = (char *)(parts + idx); - /* * Identify the partitions */ - for (idx = off = 0; off < mtd->size; off += mtd->erasesize) { + for (i = off = 0; off < mtd->size; off += mtd->erasesize) { struct image_info_v1 iis; u_int iis_ptr, img_ptr; /* Read the footer. */ ret = afs_read_footer_v1(mtd, &img_ptr, &iis_ptr, off, mask); if (ret < 0) - break; + goto out_free_parts; if (ret == 0) continue; /* Read the image info block */ ret = afs_read_iis_v1(mtd, &iis, iis_ptr); if (ret < 0) - break; + goto out_free_parts; if (ret == 0) continue; - strcpy(str, iis.name); + parts[i].name = kstrdup(iis.name, GFP_KERNEL); + if (!parts[i].name) { + ret = -ENOMEM; + goto out_free_parts; + } - parts[idx].name = str; - parts[idx].size = (iis.length + mtd->erasesize - 1) & ~(mtd->erasesize - 1); - parts[idx].offset = img_ptr; - parts[idx].mask_flags = 0; + parts[i].size = (iis.length + mtd->erasesize - 1) & ~(mtd->erasesize - 1); + parts[i].offset = img_ptr; + parts[i].mask_flags = 0; printk(" mtd%d: at 0x%08x, %5lluKiB, %8u, %s\n", - idx, img_ptr, parts[idx].size / 1024, - iis.imageNumber, str); - - idx += 1; - str = str + strlen(iis.name) + 1; - } + i, img_ptr, parts[i].size / 1024, + iis.imageNumber, parts[i].name); - if (!idx) { - kfree(parts); - parts = NULL; + i += 1; } *pparts = parts; - return idx ? idx : ret; + return i; + +out_free_parts: + while (i >= 0) { + if (parts[i].name) + kfree(parts[i].name); + i--; + } + kfree(parts); + *pparts = NULL; + return ret; } static const struct of_device_id mtd_parser_afs_of_match_table[] = { From patchwork Thu May 2 14:30:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 163266 Delivered-To: patch@linaro.org Received: by 2002:a92:7e86:0:0:0:0:0 with SMTP id q6csp5809860ill; Thu, 2 May 2019 07:33:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqxhf8+Fj6/8u7m31s/DwbMA9mqGEvo53KSZ3+3EmvuzyeXRt9wlMKtyZNG/t2/Q2IGg4dRR X-Received: by 2002:a65:44cb:: with SMTP id g11mr4318759pgs.193.1556807635415; Thu, 02 May 2019 07:33:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556807635; cv=none; d=google.com; s=arc-20160816; b=pisxioR5edP2xBVerasHtxaA8mexYvq5P2sKKyppipxXZOVQNf3is6XDd6JPjNjV0Q GTYx5iyo6TqaIVst33vnrMMxpJSs4xT3lFYpcOD5CDjgEyr1zw9AaaZyHqJEgiJAgE9F luGVSPZljt9XRkb3kGulpGVD6Ln0CY26e52pbiIsZXNLaG2zsXR3cXF1x9W8/VBpPHYU nuByIMQkjtOfEl6FEH9GWPXPBtFxR6y+yc4lRN28sYv5UaG2ye2wvUYnXQdP4u5MUxH0 ZcNf4E4qAydYlJn1gYCpS7Niv50eIifPaBiUjoNA1NBxYQaH5Pi1Qk4RtNtaOzO2S6yo bcJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:dkim-signature; bh=9UOE/ebYlNAKUixyLRrSJG1boZv/VLFf9EVzAPVs7Is=; b=g4fXrMZ6U7f26BSQn3VrKrkq3EmffqJ4sUoPLN5HVT3gzRy2d8Z4g8Xyj31RRArPnv kbxhPMQgPUopf4/As+KRDHqm2Sqh1LRa4siu0gWzNPtkd4Ie1xEDTQudPiOkBV3fYAnF a8jr60uIf33L4WWR6syrmWOGIntKzwMLQqn4+LbtRhc64SEAknN62NXQwL+Fg4CBmgeB sdnzebgDmLhfyXz53hDDz38wJPxnweTASm/TZTRbnUPH+ySDGlRYPT+Mp0kr5OBH1Qj8 o7AyA7HN9SXIkiDutXUQi4ZCWbDQ0nQW7hf1/TOd+QPJryJEI2yTiZCdwEXIJm8798BB l3wA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=Um0G42aD; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=DkSmuAUf; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id i9si18754913pgs.402.2019.05.02.07.33.55 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 07:33:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=Um0G42aD; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=DkSmuAUf; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9UOE/ebYlNAKUixyLRrSJG1boZv/VLFf9EVzAPVs7Is=; b=Um0G42aDQRqqyG JIFaZhsBuPTLNEea+gfjCHNkODtmG+siyFhSnRH+eduRQBSxdzr0Vacat3/Q5hfY2P9MYwI2Tzc+d KLDqhvmaBm1tO5P2w3a7o2Y6NSkoop26sZb9qUj83RSMr6O817ip6voR8xhdc7q168NZGf4RsjLkO ZMt94dx+K+aFQ+0sRWDQCOhdTNzuxRsygbyQtvVLDkHodGCzPfDIpQ4w//HbYj5vkOIxKoYJgc1XD jNEJz1G9rtSTRD+xKBFAhdFjotco3w0Ku2FQJYdxArd/ZZywqYZb2NLpcH5jbVvGCQ/vQv6bCt6Rx X128oli8k1kKVHyin9mA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMCmO-0001jX-Sq; Thu, 02 May 2019 14:33:44 +0000 Received: from mail-lf1-x141.google.com ([2a00:1450:4864:20::141]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMClt-00011p-2b for linux-mtd@lists.infradead.org; Thu, 02 May 2019 14:33:23 +0000 Received: by mail-lf1-x141.google.com with SMTP id n134so243372lfn.11 for ; Thu, 02 May 2019 07:33:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JN8+FUhBHB+3KhRg/Al6vKCq53Lvs7UOlgl2J6s0o8c=; b=DkSmuAUf6UysBxChIOAZitWX8KvzTXGVRHjI1Cn+DcMK3PIAcgaRE2BaYDogakUSY+ Q/EpdVqu8x2dit4MCYiu1n9wFahR0fLHKQaNpt1cJ6htBVOeWNRsgEIHCdgSuEekRcrS cNoWwY69Ha1cleBCn/v/eTUx1Is9t6msPa4g+TS/1DfkkQPV9vMg2mP0eXMhgh9AncVE 8TlaZA3V5go4dS853VnJdqtmstDFJW7ptoB79b3+pMR/v5GPKAgAHKoXWPiS6H2gSFz5 EMrfYF1wKe//UgE5rqhEWl/hqSbMvs8KHMpwRs/qpiVJKPIW5KYb2wR61bvKn/C7RnM0 U2ww== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=JN8+FUhBHB+3KhRg/Al6vKCq53Lvs7UOlgl2J6s0o8c=; b=GMnFThasiKJAYRB/B7bbnBkaOV2R+BymeaWuj9BlKbRKxw7bdn5Ffa6jq2RCB9zSn7 r3CmBC30RyoJg2m2ZhWK/iNJZU9i3nYRlchfV8Bm07SU/Zu7aETs1mNJhC/k4o7QRUzr 3BgfWl6wvjkDcxuZ1o5Zuh+omFoUOWPrzuuQzLs7co8gUB9U0K9INCBAz5MPUkDyKkqu SYvxX2KzqhD58VHnejFbAD87lrf9jnw8ufs993cfe7jhVVjlaxNUITlFP94mr7A1UYnT MmaAu2GLuVJ1NFxJlly+NPOjSiQmNkA7TpHeJnrgzUfi8aqMoC6yhKvrqtGxDDl5Mat2 ZqIw== X-Gm-Message-State: APjAAAUkRNIoOKjbt8vcsFBlAQwI2J0ovdNK3F218LipK3io4o2SRaGv yoket+QJ29T7YQYYFFzb/5REcg== X-Received: by 2002:a19:c511:: with SMTP id w17mr2113016lfe.37.1556807591140; Thu, 02 May 2019 07:33:11 -0700 (PDT) Received: from localhost.localdomain (c-d2cd225c.014-348-6c756e10.bbcust.telenor.se. [92.34.205.210]) by smtp.gmail.com with ESMTPSA id l79sm9430625lfe.92.2019.05.02.07.33.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 07:33:09 -0700 (PDT) From: Linus Walleij To: David Woodhouse , Brian Norris , Marek Vasut , Richard Weinberger , Miquel Raynal , linux-mtd@lists.infradead.org Subject: [PATCH 5/9 RESEND 2] mtd: afs: simplify partition detection Date: Thu, 2 May 2019 16:30:30 +0200 Message-Id: <20190502143034.16781-6-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190502143034.16781-1-linus.walleij@linaro.org> References: <20190502143034.16781-1-linus.walleij@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190502_073313_504443_6200F0D9 X-CRM114-Status: GOOD ( 17.64 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:141 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -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_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Linus Walleij , Liviu Dudau , Ryan Harkin Sender: "linux-mtd" Errors-To: linux-mtd-bounces+patch=linaro.org@lists.infradead.org Instead of reading out the AFS footers twice, create a separate function to just check if there is a footer or not. Rids a few local variables and prepare us to join the actual parser into one function. Cc: Ryan Harkin Acked-by: Liviu Dudau Signed-off-by: Linus Walleij --- drivers/mtd/parsers/afs.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) -- 2.20.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ diff --git a/drivers/mtd/parsers/afs.c b/drivers/mtd/parsers/afs.c index c489938cd665..ccc198818057 100644 --- a/drivers/mtd/parsers/afs.c +++ b/drivers/mtd/parsers/afs.c @@ -68,6 +68,26 @@ static u32 word_sum(void *words, int num) return sum; } +static bool afs_is_v1(struct mtd_info *mtd, u_int off) +{ + /* The magic is 12 bytes from the end of the erase block */ + u_int ptr = off + mtd->erasesize - 12; + u32 magic; + size_t sz; + int ret; + + ret = mtd_read(mtd, ptr, 4, &sz, (u_char *)&magic); + if (ret < 0) { + printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n", + ptr, ret); + return false; + } + if (ret >= 0 && sz != 4) + return false; + + return (magic == AFSV1_FOOTER_MAGIC); +} + static int afs_read_footer_v1(struct mtd_info *mtd, u_int *img_start, u_int *iis_start, u_int off, u_int mask) @@ -176,18 +196,9 @@ static int parse_afs_partitions(struct mtd_info *mtd, */ mask = mtd->size - 1; - /* - * First, calculate the size of the array we need for the - * partition information. We include in this the size of - * the strings. - */ + /* Count the partitions by looping over all erase blocks */ for (i = off = sz = 0; off < mtd->size; off += mtd->erasesize) { - u_int iis_ptr, img_ptr; - - ret = afs_read_footer_v1(mtd, &img_ptr, &iis_ptr, off, mask); - if (ret < 0) - return ret; - if (ret) { + if (afs_is_v1(mtd, off)) { sz += sizeof(struct mtd_partition); i += 1; } From patchwork Thu May 2 14:30:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 163267 Delivered-To: patch@linaro.org Received: by 2002:a92:7e86:0:0:0:0:0 with SMTP id q6csp5810160ill; Thu, 2 May 2019 07:34:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqxjUUxbDNSD0ngfcNGiMZZffd2pbcHnj40KyEnxAaCDGmnDUKxBwON2I+OHM4KFRJ1UxZYW X-Received: by 2002:a17:902:2e83:: with SMTP id r3mr4198848plb.286.1556807649087; Thu, 02 May 2019 07:34:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556807649; cv=none; d=google.com; s=arc-20160816; b=py9Fv7CPBQ9A5ikgfoFW41jG8OXTqa9byBODxQlQhmUUGLP7m3FnFB4VrN9FP1tqWM oXYYzLLFnebkj/E+36j0bjfmCyk5SBFgceQLYk2V67rAEBOeohV751FaBk5Z9LUjY7Eh 24GDeomrgRDY9FjMSOPWCGRZXElA4xMM51ZHQiPdyFKGL+aLqNOMFojRyWHNzoXiMj9o LCCrK5g+F+towJWAnuthr+uaW3DZSw4WzAA7AsB0QkQlWC4m+nBijR8BsMB9UzAR1y78 ZTljtbEFfOEwGkIhBIwMydE8WX1xQKOY7bK+fQgZrF2KqxnLc2ljb/Kp7nqEWSBjC8ZR BihA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:dkim-signature; bh=Akef23xsONd0UQO7Q52/SwvVw9EVxKRajkd7lt7xsWg=; b=M7yeg9LdOLQjZDDMNfjco0VwP2LvFKYwtZ2frJRPh8ONE1cfTd2ucTq47ivGQSI0j8 QGaWfxqptSzbCj0MpJ9nH1Pww0yV9BebVhJFDYxaT59iNdJZYOlCcKtrewW3LjJ+EF6q oykMEAC/b4xls5oHrSwM3p4R9drGWvbHrEIArCu/JUtPcqD6tdDhJjON6ERWj6lNwQzw KXi+3tYdyeoiTpw+McQKBfLN45ROkxK18PqkmELMQpZ6BZ9kNPReaefUMc5RuaeyDq6Z tJ38cHHDMn+o4jturLUCLKUwcFuvxjh0cOCiycWk28IN/LJo+Etnv+WSrkm/8f3ka+Nj GObw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=XQ2EP4B3; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=P0bb27D+; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id g6si11346549pgi.21.2019.05.02.07.34.08 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 07:34:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=XQ2EP4B3; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=P0bb27D+; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Akef23xsONd0UQO7Q52/SwvVw9EVxKRajkd7lt7xsWg=; b=XQ2EP4B3h0Ifd5 oAxcALmwM26dC8xLEmrtg0VmaqALZ7tMi0+PIylkWbwVOLerwK3I5orVX0iZEunZhf2LibC5p1u+t 1mbDGNixGr4tvJpJfuQhQcv+7dlKzrZ6k4QZ2alGTOxrdlnlgE4v1icFjjyso2RYkVEIaDILSTRnR Ir7Y4nHQHdgLHGc6elKs48bH7RKha/iLrp+eNMFFS6hP5hbLOj2qtWIWn7r/pHZf2L+JMnoPIgtoH KCB0HUDiynOcTbSfC0fUypSUUUSiS3kM5YSo0WK/dppYWAezSMNGZSRO3uphwRDAsvFUgM0vq1afZ Ygk6U6At6l7YDDKSEsqQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMCmb-0001zd-Ds; Thu, 02 May 2019 14:33:57 +0000 Received: from mail-lf1-x143.google.com ([2a00:1450:4864:20::143]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMClv-00015b-HO for linux-mtd@lists.infradead.org; Thu, 02 May 2019 14:33:28 +0000 Received: by mail-lf1-x143.google.com with SMTP id j20so2068411lfh.2 for ; Thu, 02 May 2019 07:33:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rKgEJ1Km5j3zIkbrJZuw9OFBKPPbAWx/j0MzNmJOHJ4=; b=P0bb27D+6Y0ovg9oJjGhlYW8s1jemW6BE3aR8v7PboluNO0H1h3FexJXFM1Gp+rw7Q UKMl1VzeoQV4LRcKOx7xLQ+BvFFHcqBKfGUpYUfrPgpul7HdWpl8v5uANhKhGkao9xLk o8rhKUIJKWAIK9/GJvoaxjiZeinGGQ3wvxX1HRwMy7i+F5txdekxodLjFtKCkh7V7T8Q F7HidmUT/T6miXxUpJ6nlaI6ilshpRxXvtu584KBXXLDvzvLTpWWIe8IqvUa9pcZfEke 6CCdIdPHsKBHAIMdG/gbOQShE0KDyGIC1D8FluIBjzC0IQT8MOjfy0axZ/9UfoN6tEjK wOkw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=rKgEJ1Km5j3zIkbrJZuw9OFBKPPbAWx/j0MzNmJOHJ4=; b=FyVV9ieYVUKTQUcPDTB4HPBv4NqRkJs6XJzsLU2ZnGyZxzDlWm4GSxFn98IdomUMmd F76xB320Z9HE/1jt5fr5zb9FL6+kw3iYU6UpTKvVPMHfikP2aaxaN8P7SHWWB3wxnjjC fKI/a8UC+eB8Yp7USMzYKLJ9bezOy7CBEhcF/Yd8964MuLal6evF90cDtNXNX1eo6p12 MnNWSuM0cIkhRc+Fi9wWzbacOS29pIQ4BzhhQF57AcqJGHfLbgmLviiIpXjgZcbtB8xZ pPnzDkrP4jiIe/+Ob68EiYmOHoBprO06waMBxwQ5heSocRfq927j2BgSZf+zvLthMVRl SOJw== X-Gm-Message-State: APjAAAW+YAuqS34G2Eg/ayii0ed8bcrVl8Wp34bQRB9DOQgs+nQAXIAb 8WCWaEyk5Bv2LYFN80JZwYgefg== X-Received: by 2002:a19:4a04:: with SMTP id x4mr2191114lfa.124.1556807593883; Thu, 02 May 2019 07:33:13 -0700 (PDT) Received: from localhost.localdomain (c-d2cd225c.014-348-6c756e10.bbcust.telenor.se. [92.34.205.210]) by smtp.gmail.com with ESMTPSA id l79sm9430625lfe.92.2019.05.02.07.33.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 07:33:12 -0700 (PDT) From: Linus Walleij To: David Woodhouse , Brian Norris , Marek Vasut , Richard Weinberger , Miquel Raynal , linux-mtd@lists.infradead.org Subject: [PATCH 6/9 RESEND 2] mtd: factor out v1 partition parsing Date: Thu, 2 May 2019 16:30:31 +0200 Message-Id: <20190502143034.16781-7-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190502143034.16781-1-linus.walleij@linaro.org> References: <20190502143034.16781-1-linus.walleij@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190502_073316_129393_F7EA2A49 X-CRM114-Status: GOOD ( 19.69 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:143 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -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_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Linus Walleij , Liviu Dudau , Ryan Harkin Sender: "linux-mtd" Errors-To: linux-mtd-bounces+patch=linaro.org@lists.infradead.org This breaks out the parsing of v1 partitions so we can later add a v2 partition parser. Cc: Ryan Harkin Acked-by: Liviu Dudau Signed-off-by: Linus Walleij --- drivers/mtd/parsers/afs.c | 88 ++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 38 deletions(-) -- 2.20.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ diff --git a/drivers/mtd/parsers/afs.c b/drivers/mtd/parsers/afs.c index ccc198818057..32ded91ae66c 100644 --- a/drivers/mtd/parsers/afs.c +++ b/drivers/mtd/parsers/afs.c @@ -181,14 +181,18 @@ afs_read_iis_v1(struct mtd_info *mtd, struct image_info_v1 *iis, u_int ptr) return ret; } -static int parse_afs_partitions(struct mtd_info *mtd, - const struct mtd_partition **pparts, - struct mtd_part_parser_data *data) +static int afs_parse_v1_partition(struct mtd_info *mtd, + u_int off, struct mtd_partition *part) { - struct mtd_partition *parts; - u_int mask, off, sz; - int ret = 0; - int i; + struct image_info_v1 iis; + u_int mask; + /* + * Static checks cannot see that we bail out if we have an error + * reading the footer. + */ + u_int uninitialized_var(iis_ptr); + u_int uninitialized_var(img_ptr); + int ret; /* * This is the address mask; we use this to mask off out of @@ -196,6 +200,39 @@ static int parse_afs_partitions(struct mtd_info *mtd, */ mask = mtd->size - 1; + ret = afs_read_footer_v1(mtd, &img_ptr, &iis_ptr, off, mask); + if (ret < 0) + return ret; + + /* Read the image info block */ + ret = afs_read_iis_v1(mtd, &iis, iis_ptr); + if (ret < 0) + return ret; + + part->name = kstrdup(iis.name, GFP_KERNEL); + if (!part->name) + return -ENOMEM; + + part->size = (iis.length + mtd->erasesize - 1) & ~(mtd->erasesize - 1); + part->offset = img_ptr; + part->mask_flags = 0; + + printk(" mtd: at 0x%08x, %5lluKiB, %8u, %s\n", + img_ptr, part->size / 1024, + iis.imageNumber, part->name); + + return 0; +} + +static int parse_afs_partitions(struct mtd_info *mtd, + const struct mtd_partition **pparts, + struct mtd_part_parser_data *data) +{ + struct mtd_partition *parts; + u_int off, sz; + int ret = 0; + int i; + /* Count the partitions by looping over all erase blocks */ for (i = off = sz = 0; off < mtd->size; off += mtd->erasesize) { if (afs_is_v1(mtd, off)) { @@ -215,38 +252,13 @@ static int parse_afs_partitions(struct mtd_info *mtd, * Identify the partitions */ for (i = off = 0; off < mtd->size; off += mtd->erasesize) { - struct image_info_v1 iis; - u_int iis_ptr, img_ptr; - - /* Read the footer. */ - ret = afs_read_footer_v1(mtd, &img_ptr, &iis_ptr, off, mask); - if (ret < 0) - goto out_free_parts; - if (ret == 0) - continue; - - /* Read the image info block */ - ret = afs_read_iis_v1(mtd, &iis, iis_ptr); - if (ret < 0) - goto out_free_parts; - if (ret == 0) - continue; - - parts[i].name = kstrdup(iis.name, GFP_KERNEL); - if (!parts[i].name) { - ret = -ENOMEM; - goto out_free_parts; - } - parts[i].size = (iis.length + mtd->erasesize - 1) & ~(mtd->erasesize - 1); - parts[i].offset = img_ptr; - parts[i].mask_flags = 0; - - printk(" mtd%d: at 0x%08x, %5lluKiB, %8u, %s\n", - i, img_ptr, parts[i].size / 1024, - iis.imageNumber, parts[i].name); - - i += 1; + if (afs_is_v1(mtd, off)) { + ret = afs_parse_v1_partition(mtd, off, &parts[i]); + if (ret) + goto out_free_parts; + i++; + } } *pparts = parts; From patchwork Thu May 2 14:30:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 163269 Delivered-To: patch@linaro.org Received: by 2002:a92:7e86:0:0:0:0:0 with SMTP id q6csp5810422ill; Thu, 2 May 2019 07:34:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqy36k/kMmQV/uz9335LSdaGzXRsSRGMPh+iGGe4QiNgdHGzFRjkiiYC7TaOOGhP5SvBifGw X-Received: by 2002:a17:902:294b:: with SMTP id g69mr4105737plb.57.1556807661193; Thu, 02 May 2019 07:34:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556807661; cv=none; d=google.com; s=arc-20160816; b=Bjp6hxt6ynAzlW61+w7yIsPksXh9/nT4vXVy4tKTFsoGyTJR/SWNN7X3F0STLebhbo SH4/e0ozBNa0fWs2Tx6Gxg7dcSV8iVvAlj8lkJgyQPRMmu8fNKIryy15gFokf/JPHbRe ck1CMHx/wv2yQ2ORvNZgDW4sa7xlSFy7V64wI55h+AYd0J05vIlvsvKifVSwxQ9FrsSS ZSGdO0cYoxVhJWuHxqT8yFdIIlRxB0tRLtscg1M5mlbDXW/A23iOcuHhnbytrI4oQcFz +lnsnynLLBbS5VsCDbfaMgeogDGHAW5NrdXYhxbZGhGytxcgezJttyLbAnm5e5QljApj veww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:dkim-signature; bh=YFpsCRb+VDkKHNFadVWETTUK20jCdxzZrg5Dp2XYUic=; b=vJIMsSu/+0YethuTNe27XEyDctJN1Ii+HPZhCkPgApQiGbWkex+S/oXuLgqD3wNQT0 HJFZC/XLql0Klk2MgHSfWCnTeaAoIvymjCfsZZtAIgOwLI0MNCLiE0dK5zrAW5GNXRaP PqMh+qiAFBN/fGIXkt2lbfbYn20HRW243u6U6T2cuzjNiQ0/+muYV0VeGGWwHNOkogIM HOEZm8rcXI7+OOnNZanyqeQ2XRgszONESgdX7XBPhS5gVKENGWrESOyYffdEcmdK0Er4 cZE5lnGaWuNrCdtf36AG8RkMfpL69BEbhkHFSB2zpYbJwfaVVUOsiaMJ53sZUaFu0pcc jr+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=Q1jtGjlW; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=D7mY8KNN; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id 30si31821898plc.8.2019.05.02.07.34.21 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 07:34:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=Q1jtGjlW; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=D7mY8KNN; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YFpsCRb+VDkKHNFadVWETTUK20jCdxzZrg5Dp2XYUic=; b=Q1jtGjlWpsRl0p vZr9JEYbXg+rDqQ5atFNUVbJL0rzETs0BrlVkQFgTDwDA9VYR78zvWwdJQGLOC6ww3ug5rQTZ9Hd4 CtwIi0J8+Dl1z+MmUaNdiShojWltfMcCEWADOcl4qpZSzqIYmVemcVK/m9Bnx9vjyDHiaRqj/3CqK 2a26QK72PePF2FcDuCCf7G0Of5FHqD8b8Iysm7V83hQ6wo/ekDbcNPuIShdGhKURXGT0EeHf2NvFr pTJw25lx96XP/2UMABEIfgwAZlE6GyxGeWbzIxffZz3tJ6B1aDurfAmNkKWBnPHQGIhm/6AAPt9tJ wjTmxVVftzGvAqgSIjiw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMCmu-0002R1-M5; Thu, 02 May 2019 14:34:16 +0000 Received: from mail-lj1-x241.google.com ([2a00:1450:4864:20::241]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMCly-00019J-MO for linux-mtd@lists.infradead.org; Thu, 02 May 2019 14:33:34 +0000 Received: by mail-lj1-x241.google.com with SMTP id t1so2369906lje.10 for ; Thu, 02 May 2019 07:33:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Rj711N4u+SYqDnZQYL9jQuymU6HES5b6qp0qWAvrKoQ=; b=D7mY8KNNHfwil5hxYax+JTkRllxmZ+8WgLY7qWAfx9AdL1gSo3m4/izbROLE1LSG+A +iBSsTbFaPkZuTZj3AE1I09F7dGYDWeNdb3drV/ev0mLrcgOLgRGpI7g/QObVgVoGOQ4 bIFQ7g2WekCbENIGTP3NiB8r6ntDNN4J1tgf+M+oOC6rTwpYsw7IKpDzR/SeYRYL494M RY98M7k5uCv4WUQDHHSA2lHDp9S6M5em+F5ACvHcbzLxvD+Q8zwYlc1u3YaBpoLpr87o d0rsPVPZj39X/wjPqi/J4eeVAuv05FH6p3jLVQDQXt8BygmBaGDlIJNEGKIzUc8+x78w 0wrA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=Rj711N4u+SYqDnZQYL9jQuymU6HES5b6qp0qWAvrKoQ=; b=ft8wewyfn+3c+0ngl+qhKbz8Ufy/d8lZU/yeyPoaaLx8gh4Fm4jmQglcEu9eLH5N7X uRgmZ3++S0T7Eywq+ysAEOPmB+rSmkUdfbjRKE44YR1od6cRikmIJc45UoCSr8ZamgmH R+rrWZlX+vyoXibNcDuDFdH6AcQJg6p5u5x5oH+wWjI3joj1LMjWhgmfEWMTs9YlpHz9 tF49E2e9KP96+ltd9fKnJ7IODz73ldUSEUbcZuc0LL6a5GitSLaBwJsRRezDVxg87k4q xGXQVIQJ4dX422BP8Uped5ahH1MCoPVaCYr4MPwfcV7dr4JfBEhUC95Og6dsBwVUD5T1 0Wlw== X-Gm-Message-State: APjAAAV0UeIvEQtFuLlaK+LRhwSXiuWWXdIEjo4plZ/3UETxr8Q3Axn4 LguAX/HjFXiM5O21GMW66+7JDw== X-Received: by 2002:a2e:99d5:: with SMTP id l21mr2250903ljj.113.1556807596581; Thu, 02 May 2019 07:33:16 -0700 (PDT) Received: from localhost.localdomain (c-d2cd225c.014-348-6c756e10.bbcust.telenor.se. [92.34.205.210]) by smtp.gmail.com with ESMTPSA id l79sm9430625lfe.92.2019.05.02.07.33.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 07:33:15 -0700 (PDT) From: Linus Walleij To: David Woodhouse , Brian Norris , Marek Vasut , Richard Weinberger , Miquel Raynal , linux-mtd@lists.infradead.org Subject: [PATCH 7/9 RESEND 2] mtd: afs: factor footer parsing into the v1 part parsing Date: Thu, 2 May 2019 16:30:32 +0200 Message-Id: <20190502143034.16781-8-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190502143034.16781-1-linus.walleij@linaro.org> References: <20190502143034.16781-1-linus.walleij@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190502_073319_518712_5A353BA0 X-CRM114-Status: GOOD ( 19.41 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:241 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -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_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Linus Walleij , Liviu Dudau , Ryan Harkin Sender: "linux-mtd" Errors-To: linux-mtd-bounces+patch=linaro.org@lists.infradead.org This simplifies the code by factoring in the image footer parsing into the single function parsing the AFSv1 partitions. Cc: Ryan Harkin Acked-by: Liviu Dudau Signed-off-by: Linus Walleij --- drivers/mtd/parsers/afs.c | 98 ++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 59 deletions(-) -- 2.20.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ diff --git a/drivers/mtd/parsers/afs.c b/drivers/mtd/parsers/afs.c index 32ded91ae66c..8ff82a548252 100644 --- a/drivers/mtd/parsers/afs.c +++ b/drivers/mtd/parsers/afs.c @@ -88,63 +88,6 @@ static bool afs_is_v1(struct mtd_info *mtd, u_int off) return (magic == AFSV1_FOOTER_MAGIC); } -static int -afs_read_footer_v1(struct mtd_info *mtd, u_int *img_start, u_int *iis_start, - u_int off, u_int mask) -{ - struct footer_v1 fs; - u_int ptr = off + mtd->erasesize - sizeof(fs); - size_t sz; - int ret; - - ret = mtd_read(mtd, ptr, sizeof(fs), &sz, (u_char *)&fs); - if (ret >= 0 && sz != sizeof(fs)) - ret = -EINVAL; - - if (ret < 0) { - printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n", - ptr, ret); - return ret; - } - - /* - * Does it contain the magic number? - */ - if (fs.signature != AFSV1_FOOTER_MAGIC) - return 0; - - /* - * Check the checksum. - */ - if (word_sum(&fs, sizeof(fs) / sizeof(u32)) != 0xffffffff) - return 0; - - /* - * Don't touch the SIB. - */ - if (fs.type == 2) - return 0; - - *iis_start = fs.image_info_base & mask; - *img_start = fs.image_start & mask; - - /* - * Check the image info base. This can not - * be located after the footer structure. - */ - if (*iis_start >= ptr) - return 0; - - /* - * Check the start of this image. The image - * data can not be located after this block. - */ - if (*img_start > off) - return 0; - - return 1; -} - static int afs_read_iis_v1(struct mtd_info *mtd, struct image_info_v1 *iis, u_int ptr) { @@ -184,6 +127,7 @@ afs_read_iis_v1(struct mtd_info *mtd, struct image_info_v1 *iis, u_int ptr) static int afs_parse_v1_partition(struct mtd_info *mtd, u_int off, struct mtd_partition *part) { + struct footer_v1 fs; struct image_info_v1 iis; u_int mask; /* @@ -192,6 +136,8 @@ static int afs_parse_v1_partition(struct mtd_info *mtd, */ u_int uninitialized_var(iis_ptr); u_int uninitialized_var(img_ptr); + u_int ptr; + size_t sz; int ret; /* @@ -200,9 +146,43 @@ static int afs_parse_v1_partition(struct mtd_info *mtd, */ mask = mtd->size - 1; - ret = afs_read_footer_v1(mtd, &img_ptr, &iis_ptr, off, mask); - if (ret < 0) + ptr = off + mtd->erasesize - sizeof(fs); + ret = mtd_read(mtd, ptr, sizeof(fs), &sz, (u_char *)&fs); + if (ret >= 0 && sz != sizeof(fs)) + ret = -EINVAL; + if (ret < 0) { + printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n", + ptr, ret); return ret; + } + /* + * Check the checksum. + */ + if (word_sum(&fs, sizeof(fs) / sizeof(u32)) != 0xffffffff) + return -EINVAL; + + /* + * Hide the SIB (System Information Block) + */ + if (fs.type == 2) + return 0; + + iis_ptr = fs.image_info_base & mask; + img_ptr = fs.image_start & mask; + + /* + * Check the image info base. This can not + * be located after the footer structure. + */ + if (iis_ptr >= ptr) + return 0; + + /* + * Check the start of this image. The image + * data can not be located after this block. + */ + if (img_ptr > off) + return 0; /* Read the image info block */ ret = afs_read_iis_v1(mtd, &iis, iis_ptr); From patchwork Thu May 2 14:30:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 163268 Delivered-To: patch@linaro.org Received: by 2002:a92:7e86:0:0:0:0:0 with SMTP id q6csp5810329ill; Thu, 2 May 2019 07:34:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqwj5rKzQZlKXsE8EEBBSIA51H+6UgfrKbf2AUXpx/eWKKUiYA+a4G4FCPUmeo1vlPOE13Bd X-Received: by 2002:a63:d408:: with SMTP id a8mr4260395pgh.184.1556807657940; Thu, 02 May 2019 07:34:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556807657; cv=none; d=google.com; s=arc-20160816; b=QMFKox3fd6LMJoGfKz30N8WgfZFGMYzJEUtbRo/N9wBr0C4wNuhQO1WskzyJxvk/dh zYTJKj4D/l1ZbrMWMi+Olir0ri0xUyc+C7s0en+nYCmwClW/DKDLT4v6wMzbAJ09o8f5 uZytZ23pT8bGMybksdQrVuGQ4ILKDTqdGYMzzpLiHDxbW4XsT7Y2VqUhjjcwOb0ZtXva u3582i/N0eUCkv0S8GI8Yv5H2PLGpbYhfs05wk4hNZyc/y3cDTXWXeR/bsJtrzWl0A9W smksuOSJV6YefEUkO6nAXzOwYHF/akuSW1Ozq2uFMTnPp4slnLMAdGH61sXCBrXOw7p9 pA8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:dkim-signature; bh=32g4R+o6Kgn45gK8Rj91pX+/5009gOMXzAIc3aIEiY0=; b=R+IKBLDHmJemIZUkLqKQYxkHA4diS4/t+hGl66h0atAG7lUDrK5hmpW171XRaDhJ1w HDSUhFvq2QIzGmChVwfjbI9k5v+eWwDE6J0Hh07G/RnMluiGn5AP6YDE1TD0LP7Ig1ze +B1+QvEPOqe0l411gSW+bYjD55LJgL2aj+6HI93b163tsctJqxN4iDOzBPao5MBRxh5m /Fgdb5sY61osadKp07v0qSM3WrJ6NkjDnMg7I5oRV1aPmnIoNS2SF4xJO8HvKBre1Ij3 /dSdJSflGTrJmFcZhwuhiAmucva8LlHo7G+PAK5fNxBt7/7CFn0EkYcGsYLNKW/uLbPy SGtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=Ye5KOw38; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ifnaU5YL; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id q22si23294589pll.184.2019.05.02.07.34.17 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 07:34:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=Ye5KOw38; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ifnaU5YL; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=32g4R+o6Kgn45gK8Rj91pX+/5009gOMXzAIc3aIEiY0=; b=Ye5KOw38t34uAG z9GpcL0AePkVDPxaW0ux0lqjZSZndtXv+J3aLmiiW0eGkH42KaTCMyr+kmzirzozuoPOkhlIcp8pS oyxNCO3L9xPRCKyqXW0ricvFK2WwwueRvpAqFgV2SR2qi0H/QVtYbFi1r+Ox1P5ugfxBeduQ9hIkN j2DBwjuTEOBcTklnkVeh5VWfGYeyIFPKI9AUUhnH98iBtnuiccFxvBUwGuyFykS1wa1DLgHsADHmB 8mjJVLOj3gK/euUGIUUqQCNIOx962w/Xc1gXkjqYCxpsJu4Y0V8faxZFZH6vOytwkjJVA28FNbYXh SnYl5pYoRD2WjfDJevjQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMCml-0002Df-A4; Thu, 02 May 2019 14:34:07 +0000 Received: from mail-lf1-x142.google.com ([2a00:1450:4864:20::142]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMCm1-0001DK-6P for linux-mtd@lists.infradead.org; Thu, 02 May 2019 14:33:34 +0000 Received: by mail-lf1-x142.google.com with SMTP id j20so2068658lfh.2 for ; Thu, 02 May 2019 07:33:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o4x2AwA/3CLBONjG7dpZpyuRhgYfsOiX68AZc6HGuSQ=; b=ifnaU5YL8TOetW2sEUOBvTwzLn3XYh8p46Mu3ByasHC79TnX5LkzcJYj0lrt9GAufY u3HCJDusK4e2Mm6O5/KFbjUpiZtSwULT/OwQzhnrFrNNFmJYxKv0jh2wcLM2Jj8Eb76J 5nRi4zC5PpvdlrxnYgzlUfW5/aCX69IHiFKB4cY9GO12gUf8bkIVJOB8k5OqXiIzLh0p KLwylVzcK0o8k3ivYK9hIjlOyPSCI45Z97H4MMNMhHJFLjCB52zPoOgw6XlMZiYkor9j yEvN7v0P6Mau3Nqqxc33Kb1yMX4I054+mbWG13NGfOlvgwFrQVD5ZlGXxxdm3IGiKUSR bQAA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=o4x2AwA/3CLBONjG7dpZpyuRhgYfsOiX68AZc6HGuSQ=; b=P3PmQtmt5UKkElBllVLTsBW+PsVIjHERUt6aFNuxwXhu1TN1lmCDPRIk09Yzre4nyW HC4HFfbLwdPhyCQkXnztsUW80GtFajv8bQrT07EBeaqVFqDAPaWwyBo0EjpgQ5PPGe9A 3PmNt+uFyiFaTa5qqLb5z+i6WzPHSvB2POYNDbx9TGUnCS3zu+yPTwTBF9JiH0F0lESk 9sD3CR9eGJUXaPQmHBogH7T5GS6COO8hVix08G//JhAuWQMzYVpfZKtIegCqE0tPMTyf q9DACVSejmKPSjs+yrE05y6vU3hI06qo2swTyFcPNi05Hj1cWl6dNjvAYEw2H4dMmJwR wZyA== X-Gm-Message-State: APjAAAVqq+YZggI5PB40vliknfVS/ulYFzxqYwnjOPEcwuXYqlWj8cgk WFLbLIsNYPP04mFFVgq0u/w5lw== X-Received: by 2002:a19:189:: with SMTP id 131mr650254lfb.74.1556807599102; Thu, 02 May 2019 07:33:19 -0700 (PDT) Received: from localhost.localdomain (c-d2cd225c.014-348-6c756e10.bbcust.telenor.se. [92.34.205.210]) by smtp.gmail.com with ESMTPSA id l79sm9430625lfe.92.2019.05.02.07.33.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 07:33:17 -0700 (PDT) From: Linus Walleij To: David Woodhouse , Brian Norris , Marek Vasut , Richard Weinberger , Miquel Raynal , linux-mtd@lists.infradead.org Subject: [PATCH 8/9 RESEND 2] mtd: afs: factor the IIS read into partition parser Date: Thu, 2 May 2019 16:30:33 +0200 Message-Id: <20190502143034.16781-9-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190502143034.16781-1-linus.walleij@linaro.org> References: <20190502143034.16781-1-linus.walleij@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190502_073321_863816_86E26DE8 X-CRM114-Status: GOOD ( 17.87 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:142 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -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_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Linus Walleij , Liviu Dudau , Ryan Harkin Sender: "linux-mtd" Errors-To: linux-mtd-bounces+patch=linaro.org@lists.infradead.org Factor the IIS (Image Information Structure) reading into the partition parser, giving us a single, clean partition parser function. Cc: Ryan Harkin Acked-by: Liviu Dudau Signed-off-by: Linus Walleij --- drivers/mtd/parsers/afs.c | 59 +++++++++++++-------------------------- 1 file changed, 20 insertions(+), 39 deletions(-) -- 2.20.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ diff --git a/drivers/mtd/parsers/afs.c b/drivers/mtd/parsers/afs.c index 8ff82a548252..72c688b8a383 100644 --- a/drivers/mtd/parsers/afs.c +++ b/drivers/mtd/parsers/afs.c @@ -88,42 +88,6 @@ static bool afs_is_v1(struct mtd_info *mtd, u_int off) return (magic == AFSV1_FOOTER_MAGIC); } -static int -afs_read_iis_v1(struct mtd_info *mtd, struct image_info_v1 *iis, u_int ptr) -{ - size_t sz; - int ret, i; - - memset(iis, 0, sizeof(*iis)); - ret = mtd_read(mtd, ptr, sizeof(*iis), &sz, (u_char *)iis); - if (ret < 0) - goto failed; - - if (sz != sizeof(*iis)) { - ret = -EINVAL; - goto failed; - } - - ret = 0; - - /* - * Validate the name - it must be NUL terminated. - */ - for (i = 0; i < sizeof(iis->name); i++) - if (iis->name[i] == '\0') - break; - - if (i < sizeof(iis->name)) - ret = 1; - - return ret; - - failed: - printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n", - ptr, ret); - return ret; -} - static int afs_parse_v1_partition(struct mtd_info *mtd, u_int off, struct mtd_partition *part) { @@ -139,6 +103,7 @@ static int afs_parse_v1_partition(struct mtd_info *mtd, u_int ptr; size_t sz; int ret; + int i; /* * This is the address mask; we use this to mask off out of @@ -185,9 +150,25 @@ static int afs_parse_v1_partition(struct mtd_info *mtd, return 0; /* Read the image info block */ - ret = afs_read_iis_v1(mtd, &iis, iis_ptr); - if (ret < 0) - return ret; + memset(&iis, 0, sizeof(iis)); + ret = mtd_read(mtd, iis_ptr, sizeof(iis), &sz, (u_char *)&iis); + if (ret < 0) { + printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n", + iis_ptr, ret); + return -EINVAL; + } + + if (sz != sizeof(iis)) + return -EINVAL; + + /* + * Validate the name - it must be NUL terminated. + */ + for (i = 0; i < sizeof(iis.name); i++) + if (iis.name[i] == '\0') + break; + if (i > sizeof(iis.name)) + return -EINVAL; part->name = kstrdup(iis.name, GFP_KERNEL); if (!part->name) From patchwork Thu May 2 14:30:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 163270 Delivered-To: patch@linaro.org Received: by 2002:a92:7e86:0:0:0:0:0 with SMTP id q6csp5821979ill; Thu, 2 May 2019 07:43:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqx266QNXWs3ZRGO5U43GRvB4/EskfrCQq8PcWTDk8IQCUnyhx2NfgmBpLSqiKyKI/kut+RK X-Received: by 2002:a63:3dc8:: with SMTP id k191mr4358659pga.286.1556808223972; Thu, 02 May 2019 07:43:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556808223; cv=none; d=google.com; s=arc-20160816; b=p43BcKW+eRUGsWlg2dnTNCYinTg4qDKQk+QUgPIqf09bvA50RTo0FoTm6OgoR+YWQi nw+rkQ+dhbsWiSjZFRi0vAX7Eet4zDvzVgtooytpAHpifAcTvgwwFUEijPgKR/OWfe+V UL3Xhdd/RxyeMLQ1wTLW3kBwhuS3UQALpXVjqafJJ2i9T1uy/+a/9/vCOZo/EQ0ok4w8 Z7kUxnM0FOCrUPBDlvk6uZrVjRu35xq86b0yYQv9vScLl56Ns8IlOsUOB9hiNo2IMgWL ATozHP49UCN/gK3T0RE2HNLKix/bvgnOafyJAvEEQoR47r+ITDKSKAD4vhKr3m2pxplc IyWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:references :in-reply-to:message-id:date:subject:to:from:dkim-signature :dkim-signature; bh=v8yUtN6vIAd/lI043ek3nasz8tZzzShueR6fOz98NsU=; b=Ng1L6+XXwFh5fgpu4M6ejz66G3/pxGAoN1LiCNq18h1PZYSQcGELWzc9npqlNTlIJa s9n7L+wKhd7Q7Z0IHBwWncuQ69/2vf3SXOwQImxpy+aMIq7oCOStSFuWlXsS3Tcrnlpf VAZ712OMKO85UvHza4Uaz3T9Z6HkOOpnHExo4+NF/hhadQBJfxKe0Nmn0tykzF1B3f+U 33i4XgXWPrNIWCf2t37kFun+dol+FdnqS6g0ltVEzJ53Dw7C69It2B+25aqNWWRjy/Z/ asSTCeqmVOP+h9w0zFqSGRJonhNnv6a3uxlB+wleP68pzWsn8gHLmpx0U0EYJw03YMHF bS8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=Uie51uBO; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Wqes9SeN; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id e14si26182351pgm.340.2019.05.02.07.43.43 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 07:43:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20170209 header.b=Uie51uBO; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Wqes9SeN; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Content-Type:Cc: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=v8yUtN6vIAd/lI043ek3nasz8tZzzShueR6fOz98NsU=; b=Uie51uBOLT4uEQlxz9c4x/oBQ 0vrh7QEStRaC8N/fWZ4I70Zn4RqeVzJvspPnZP4GiOqUYtJmkDq4tmzvjeM3wJDaL79+rTEdzzzEC VkXErU+YZ9oFR5LqBrFImr2fiOrJZl7NrE2VCbpTrDXGG50uNO26RqPtvmaKjdWCFqhfmvNyy3UQX +ujgjjPBAaeioyilC1x3AdN3V3WbEiMKyhHC7HMTvtfULcaNa1PGsOSVBOhWVkQ9r4I9G1i/xoH66 UF8Wusg4wg8bnWnOASehW3ubM/qcm2C9BFp4ZDnWVN8YbJql5ZI7g37Cskheii5Mp3dSdKqnjI88b Zc8F9GjFg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMCvy-0005qT-EI; Thu, 02 May 2019 14:43:38 +0000 Received: from mail-lj1-x241.google.com ([2a00:1450:4864:20::241]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMCm3-0001H5-FL for linux-mtd@lists.infradead.org; Thu, 02 May 2019 14:33:44 +0000 Received: by mail-lj1-x241.google.com with SMTP id z26so2408481ljj.2 for ; Thu, 02 May 2019 07:33:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6ohcDEvkPistHHHhOpFFR0NARkPBUpb4Juo62pfPYr0=; b=Wqes9SeNHgt8NqnKfKCZ6AhoUzeRAIz4/tnbpeK/SgJ6K4ycOZENvW/4XsuUS1flPS KqZqA2RKIfiEBzUQJIVwku6thOl25HI7r7GUHaa4PELY0nqsqkbO8CjMMMvxZ9N1KPb+ d8pWJe37XHka9oTuxgyNu/3gOiHNOVesGLxaiLfEX0pv2ZjBkDkaVjd5cTz4baOFPhrD 4vcVuoxwYa1m3dV7FhbHvVtC/pPIr46T3WRWCyOvuBcDHdYt/LSGABg0uRFx/D6+hXOc mYDFG2KVCkrimMoVIahumnaoKxh56v+R9EKxv/hSI9z5+Gc4K8LJGZeyvscnfDVbdWmo zLJQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=6ohcDEvkPistHHHhOpFFR0NARkPBUpb4Juo62pfPYr0=; b=nbMYhI2Lh3gmsiEEt1A7EN7aZExvcy/rrmRjf4ezLFE5V9CsC8skaT3Bu3IDjI489H JvQ/r091a1swXACC/sHhBwe+1ORZzVxMJsmUEeFNWsIYKnyGphtNScjA2kuJw5Z3eOsr a+tdGr4y29AkET8//pDhQHI+xVFAwsLCud6VT8Hyvmsq7ro8S5hrIWE2usxi6TdQKHDy jL9cln6j8sf3KqyKO/79Y0c/DogEsdzQRDlhdkFp/Rka4yk5ncpdwgELx44L0C2HwiY3 CNlaKDceXqmjunYbXO5fFxxrGRB3C3FB10qXLBLAkADJ2N4u3qoZDsQmKdd6pXyma3Z+ vaWA== X-Gm-Message-State: APjAAAW3/u5c9lUNpMIm3nk3+vxRhpICn1g4cvvrYHeUifZawEYgoAGm EJzQ4j+2oBCYIsGDer5aEVaweA== X-Received: by 2002:a2e:94ca:: with SMTP id r10mr2096891ljh.33.1556807601756; Thu, 02 May 2019 07:33:21 -0700 (PDT) Received: from localhost.localdomain (c-d2cd225c.014-348-6c756e10.bbcust.telenor.se. [92.34.205.210]) by smtp.gmail.com with ESMTPSA id l79sm9430625lfe.92.2019.05.02.07.33.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 07:33:20 -0700 (PDT) From: Linus Walleij To: David Woodhouse , Brian Norris , Marek Vasut , Richard Weinberger , Miquel Raynal , linux-mtd@lists.infradead.org Subject: [PATCH 9/9 RESEND 2] mtd: afs: add v2 partition parsing Date: Thu, 2 May 2019 16:30:34 +0200 Message-Id: <20190502143034.16781-10-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190502143034.16781-1-linus.walleij@linaro.org> References: <20190502143034.16781-1-linus.walleij@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190502_073324_041490_E69932D5 X-CRM114-Status: GOOD ( 22.38 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:241 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -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_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Linus Walleij , Liviu Dudau , Ryan Harkin Sender: "linux-mtd" Errors-To: linux-mtd-bounces+patch=linaro.org@lists.infradead.org The AFS v2 partition type appear in later ARM reference designs such as RealView, Versatile Express and the 64bit Juno Development Platform. The image informations is padded with a 32bit word (4 bytes) on the 32bit platforms and a 64bit word (8 bytes) on the 64bit platforms. The boot monitor source code gives at hand that this is because the first entry in the struct mapped over the image information is a "next" pointer for a linked list, filled in by firmware after reading in the info block, and always zero in the flash. We adjust padding by checking what padding gives the right checksum. This was tested on: - Integrator/AP (v1 partitions) - RealView PB11MPCore (v2 32bit partitions) - Juno Development System (v2 64bit partitions) All systems display the images in flash very nicely as separate partitions, e.g on Juno: 4 afs partitions found on MTD device 8000000.flash Creating 4 MTD partitions on "8000000.flash": 0x000000040000-0x0000000c0000 : "fip" 0x000000ec0000-0x0000018c0000 : "Image" 0x000000f00000-0x000000f40000 : "juno" 0x000003ec0000-0x000003f00000 : "bl1" Cc: Ryan Harkin Acked-by: Liviu Dudau Signed-off-by: Linus Walleij --- drivers/mtd/parsers/afs.c | 158 +++++++++++++++++++++++++++++++++++++- 1 file changed, 157 insertions(+), 1 deletion(-) -- 2.20.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ diff --git a/drivers/mtd/parsers/afs.c b/drivers/mtd/parsers/afs.c index 72c688b8a383..0c730024f806 100644 --- a/drivers/mtd/parsers/afs.c +++ b/drivers/mtd/parsers/afs.c @@ -3,6 +3,7 @@ drivers/mtd/afs.c: ARM Flash Layout/Partitioning Copyright © 2000 ARM Limited + Copyright (C) 2019 Linus Walleij This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -35,6 +36,8 @@ #include #define AFSV1_FOOTER_MAGIC 0xA0FFFF9F +#define AFSV2_FOOTER_MAGIC1 0x464C5348 /* "FLSH" */ +#define AFSV2_FOOTER_MAGIC2 0x464F4F54 /* "FOOT" */ struct footer_v1 { u32 image_info_base; /* Address of first word of ImageFooter */ @@ -68,6 +71,22 @@ static u32 word_sum(void *words, int num) return sum; } +static u32 word_sum_v2(u32 *p, u32 num) +{ + u32 sum = 0; + int i; + + for (i = 0; i < num; i++) { + u32 val; + + val = p[i]; + if (val > ~sum) + sum++; + sum += val; + } + return ~sum; +} + static bool afs_is_v1(struct mtd_info *mtd, u_int off) { /* The magic is 12 bytes from the end of the erase block */ @@ -88,6 +107,27 @@ static bool afs_is_v1(struct mtd_info *mtd, u_int off) return (magic == AFSV1_FOOTER_MAGIC); } +static bool afs_is_v2(struct mtd_info *mtd, u_int off) +{ + /* The magic is the 8 last bytes of the erase block */ + u_int ptr = off + mtd->erasesize - 8; + u32 foot[2]; + size_t sz; + int ret; + + ret = mtd_read(mtd, ptr, 8, &sz, (u_char *)foot); + if (ret < 0) { + printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n", + ptr, ret); + return false; + } + if (ret >= 0 && sz != 8) + return false; + + return (foot[0] == AFSV2_FOOTER_MAGIC1 && + foot[1] == AFSV2_FOOTER_MAGIC2); +} + static int afs_parse_v1_partition(struct mtd_info *mtd, u_int off, struct mtd_partition *part) { @@ -185,6 +225,113 @@ static int afs_parse_v1_partition(struct mtd_info *mtd, return 0; } +static int afs_parse_v2_partition(struct mtd_info *mtd, + u_int off, struct mtd_partition *part) +{ + u_int ptr; + u32 footer[12]; + u32 imginfo[36]; + char *name; + u32 version; + u32 entrypoint; + u32 attributes; + u32 region_count; + u32 block_start; + u32 block_end; + u32 crc; + size_t sz; + int ret; + int i; + int pad = 0; + + pr_debug("Parsing v2 partition @%08x-%08x\n", + off, off + mtd->erasesize); + + /* First read the footer */ + ptr = off + mtd->erasesize - sizeof(footer); + ret = mtd_read(mtd, ptr, sizeof(footer), &sz, (u_char *)footer); + if ((ret < 0) || (ret >= 0 && sz != sizeof(footer))) { + pr_err("AFS: mtd read failed at 0x%x: %d\n", + ptr, ret); + return -EIO; + } + name = (char *) &footer[0]; + version = footer[9]; + ptr = off + mtd->erasesize - sizeof(footer) - footer[8]; + + pr_debug("found image \"%s\", version %08x, info @%08x\n", + name, version, ptr); + + /* Then read the image information */ + ret = mtd_read(mtd, ptr, sizeof(imginfo), &sz, (u_char *)imginfo); + if ((ret < 0) || (ret >= 0 && sz != sizeof(imginfo))) { + pr_err("AFS: mtd read failed at 0x%x: %d\n", + ptr, ret); + return -EIO; + } + + /* 32bit platforms have 4 bytes padding */ + crc = word_sum_v2(&imginfo[1], 34); + if (!crc) { + pr_debug("Padding 1 word (4 bytes)\n"); + pad = 1; + } else { + /* 64bit platforms have 8 bytes padding */ + crc = word_sum_v2(&imginfo[2], 34); + if (!crc) { + pr_debug("Padding 2 words (8 bytes)\n"); + pad = 2; + } + } + if (crc) { + pr_err("AFS: bad checksum on v2 image info: %08x\n", crc); + return -EINVAL; + } + entrypoint = imginfo[pad]; + attributes = imginfo[pad+1]; + region_count = imginfo[pad+2]; + block_start = imginfo[20]; + block_end = imginfo[21]; + + pr_debug("image entry=%08x, attr=%08x, regions=%08x, " + "bs=%08x, be=%08x\n", + entrypoint, attributes, region_count, + block_start, block_end); + + for (i = 0; i < region_count; i++) { + u32 region_load_addr = imginfo[pad + 3 + i*4]; + u32 region_size = imginfo[pad + 4 + i*4]; + u32 region_offset = imginfo[pad + 5 + i*4]; + u32 region_start; + u32 region_end; + + pr_debug(" region %d: address: %08x, size: %08x, " + "offset: %08x\n", + i, + region_load_addr, + region_size, + region_offset); + + region_start = off + region_offset; + region_end = region_start + region_size; + /* Align partition to end of erase block */ + region_end += (mtd->erasesize - 1); + region_end &= ~(mtd->erasesize -1); + pr_debug(" partition start = %08x, partition end = %08x\n", + region_start, region_end); + + /* Create one partition per region */ + part->name = kstrdup(name, GFP_KERNEL); + if (!part->name) + return -ENOMEM; + part->offset = region_start; + part->size = region_end - region_start; + part->mask_flags = 0; + } + + return 0; +} + static int parse_afs_partitions(struct mtd_info *mtd, const struct mtd_partition **pparts, struct mtd_part_parser_data *data) @@ -200,6 +347,10 @@ static int parse_afs_partitions(struct mtd_info *mtd, sz += sizeof(struct mtd_partition); i += 1; } + if (afs_is_v2(mtd, off)) { + sz += sizeof(struct mtd_partition); + i += 1; + } } if (!i) @@ -213,13 +364,18 @@ static int parse_afs_partitions(struct mtd_info *mtd, * Identify the partitions */ for (i = off = 0; off < mtd->size; off += mtd->erasesize) { - if (afs_is_v1(mtd, off)) { ret = afs_parse_v1_partition(mtd, off, &parts[i]); if (ret) goto out_free_parts; i++; } + if (afs_is_v2(mtd, off)) { + ret = afs_parse_v2_partition(mtd, off, &parts[i]); + if (ret) + goto out_free_parts; + i++; + } } *pparts = parts;