From patchwork Thu Mar 30 12:35:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 745234 X-Patchwork-Delegate: computersforpeace@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vv4060cvbz9s0g for ; Thu, 30 Mar 2017 23:37:25 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="cneiDVDN"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="gpIraY3z"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id: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=/1DT4IyhtL8KBw46tDya5qFMigmPLCOm40SXPl6oVaM=; b=cneiDVDNOWDJAX SuEiRfQqess2LhT+XWu14W5JKjsdyCjBmuvQ1J6zO7Wo/+G7LmXT41v0Wrluox1VsAAPqPCkOcXBN 6ZGr9EMx/7OIZ5pbUa0JAN2qc+t4PLckt68hvAPh3D3RnxmeKNkuIcCWHQDfhNA3CaMpvOyuSeH8F ZegQHYNLa/E5u+4E5aZG2H66FcrFvlvCZGDpFvJiJ9ihXoiQIufpqwC0Cp1W450bjSeArW8nRPRPj 6Fqs+0dMZdVYs1Iy0EXscvWudrjLCPZo/txK7Lxt+vIhnthfr6JZ5o0lWQA2bfg3mJv3+XT76GisB 0jLD0Mo4HaoWWKqeUYEw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ctZKK-0006g7-98; Thu, 30 Mar 2017 12:37:20 +0000 Received: from mail-lf0-x243.google.com ([2a00:1450:4010:c07::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ctZKF-0006di-KE for linux-mtd@lists.infradead.org; Thu, 30 Mar 2017 12:37:17 +0000 Received: by mail-lf0-x243.google.com with SMTP id x137so4460597lff.1 for ; Thu, 30 Mar 2017 05:36:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CQ1JzhtqbTvTZXzpQdgiQFNmE/VQvqlaAH6Zw6D7HpM=; b=gpIraY3zXQIE66Mir7UISWQ10gLwjFvaii5EPcjHATm9K48aOt7FBx7G1wi8I9u3BE uZ10mIRZys/VrKV+jOrHOGYG1sRtJnA7JtqkOJBaevC/k6DPtwghYr9p7eVgl4x2kREd +d/10f+q6S4JtUlBflWDnEsGICspEw/OFvJinVC2aMZRYYtLlxgDzX8Z3tIRhv0hZvZY Z5KI9xiWv0UHzOdcC7IPKU95cTyAfGhxjjULSjiVAD5DZvlht/qNS+VEvcnSNUaEaJaJ n2yCrBnK9nwOSFRkn5IiX/yxsTTJpDqCTdJ0CYf1nN6OJOz51rINNyNBFw05uPjVtGjf LD+w== 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=CQ1JzhtqbTvTZXzpQdgiQFNmE/VQvqlaAH6Zw6D7HpM=; b=QcMEuHXwdYEVAbAmgIHEfFI1B3EBpT/J6TQOwb0rn0+9IU09uHAyWBmpyxkVT7lgfx FE3JGEcPqr3SzPlHfmSniGEWGYtsZlTShho2r8NMHsIBrqSqheDRfU7d0qJO185g3o8n putdnFp3xHhyKntEnES0odkz1SyQNZeoFnFqDOu9UT5EtbsUyA+auWJSA0LxJPVt8tMz adjZqTacuFj9S7A2/ItEUvO0yxC7c8bGnB0X9aaVj0LBp0TRCSUbs1hScgdJTHDpeaIw HaYBUv8rmc91Hk8N3aeUqcJaCOp8k2btfKxQ/7KFiK7u+j8YIdcPg9r4YNrvWP0frvul 471w== X-Gm-Message-State: AFeK/H1Nb/mk27eUeyV8HBopgPMKY4/SlefDZdm/LhVDWjh11cwNnzVUTwMnhffqwoihRA== X-Received: by 10.46.5.68 with SMTP id 65mr2108277ljf.49.1490877413599; Thu, 30 Mar 2017 05:36:53 -0700 (PDT) Received: from linux-samsung.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id i18sm350556lfe.16.2017.03.30.05.36.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Mar 2017 05:36:52 -0700 (PDT) From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= To: David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger Subject: [PATCH V4 1/2] mtd: add support for partition parsers Date: Thu, 30 Mar 2017 14:35:26 +0200 Message-Id: <20170330123527.30181-1-zajec5@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170227130633.4020-1-zajec5@gmail.com> References: <20170227130633.4020-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170330_053715_856418_B4E9DE22 X-CRM114-Status: GOOD ( 19.55 ) X-Spam-Score: -1.8 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (zajec5[at]gmail.com) 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (zajec5[at]gmail.com) -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 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: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , Cyrille Pitchen , linux-mtd@lists.infradead.org Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Rafał Miłecki Some devices have partitions that are kind of containers with extra subpartitions / volumes instead of e.g. simple filesystem data. To support such cases we need to first create normal flash partitions and then take care of these special ones. It's very common case for home routers. Depending on the vendor there are formats like TRX, Seama, TP-Link, WRGG & more. All of them are used to embed few partitions into a single one / single firmware file. Ideally all vendors would use some well documented / standardized format like UBI (and some probably start doing so), but there are still countless devices on the market using these poor vendor specific formats. This patch extends MTD subsystem by allowing to specify partition format and trying to use a proper parser when needed. Supporting such poor formats is highly unlikely to be the top priority so these changes try to minimize maintenance cost to the minimum. It reuses existing code for these new parsers and just adds a one property and one new function. This implementation requires setting partition format in a flash parser. A proper change of bcm47xxpart will follow and in the future we will hopefully also find a solution for doing it with ofpart ("fixed-partitions"). Signed-off-by: Rafał Miłecki Acked-by: Marek Vasut --- V2: A totally rebased & refreshed version. V3: Don't mention uImage in commit message, it was a mistake. V4: Document mtd_parse_part parameters --- drivers/mtd/mtdpart.c | 41 +++++++++++++++++++++++++++++++++++++++++ include/linux/mtd/partitions.h | 7 +++++++ 2 files changed, 48 insertions(+) diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index ea5e5307f667..81e0b80237df 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -363,6 +363,45 @@ static inline void free_partition(struct mtd_part *p) kfree(p); } +/** + * mtd_parse_part - parse MTD partition with a matching parser + * + * @slave: part to be parsed for subpartitions + * @format: partition format used to call a proper parser + * + * Some partitions use a specific format to describe contained subpartitions + * (volumes). This function tries to use a proper parser for a given format and + * registers found (sub)partitions. + */ +static int mtd_parse_part(struct mtd_part *slave, const char *format) +{ + struct mtd_partitions parsed; + const char *probes[2]; + int i; + int err; + + probes[0] = format; /* Use parser with name matching the format */ + probes[1] = NULL; /* End of parsers */ + err = parse_mtd_partitions(&slave->mtd, probes, &parsed, NULL); + if (err) + return err; + else if (!parsed.nr_parts) + return -ENOENT; + + for (i = 0; i < parsed.nr_parts; i++) { + struct mtd_partition *part; + + part = (struct mtd_partition *)&parsed.parts[i]; + part->offset += slave->offset; + } + + err = add_mtd_partitions(slave->master, parsed.parts, parsed.nr_parts); + + mtd_part_parser_cleanup(&parsed); + + return err; +} + /* * This function unregisters and destroy all slave MTD objects which are * attached to the given master MTD object. @@ -724,6 +763,8 @@ int add_mtd_partitions(struct mtd_info *master, add_mtd_device(&slave->mtd); mtd_add_partition_attrs(slave); + if (parts[i].format) + mtd_parse_part(slave, parts[i].format); cur_offset = slave->offset + slave->mtd.size; } diff --git a/include/linux/mtd/partitions.h b/include/linux/mtd/partitions.h index 06df1e06b6e0..2787e76c030f 100644 --- a/include/linux/mtd/partitions.h +++ b/include/linux/mtd/partitions.h @@ -20,6 +20,12 @@ * * For each partition, these fields are available: * name: string that will be used to label the partition's MTD device. + * format: some partitions can be containers using specific format to describe + * embedded subpartitions / volumes. E.g. many home routers use "firmware" + * partition that contains at least kernel and rootfs. In such case an + * extra parser is needed that will detect these dynamic partitions and + * report them to the MTD subsystem. This property describes partition + * format and allows MTD core to call a proper parser. * size: the partition size; if defined as MTDPART_SIZ_FULL, the partition * will extend to the end of the master MTD device. * offset: absolute starting position within the master MTD device; if @@ -38,6 +44,7 @@ struct mtd_partition { const char *name; /* identifier string */ + const char *format; /* partition format */ uint64_t size; /* partition size */ uint64_t offset; /* offset within the master MTD space */ uint32_t mask_flags; /* master MTD flags to mask out for this partition */