From patchwork Sat Jun 18 19:17:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hauke Mehrtens X-Patchwork-Id: 637551 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rX6QR711xz9t1v for ; Sun, 19 Jun 2016 05:20:15 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1bELlS-00082V-RT; Sat, 18 Jun 2016 19:18:42 +0000 Received: from hauke-m.de ([2001:41d0:8:b27b::1]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1bELlP-0007pU-GP for linux-mtd@lists.infradead.org; Sat, 18 Jun 2016 19:18:40 +0000 Received: from hauke-desktop.lan (p2003008B2F0BA600DC80E70188091D99.dip0.t-ipconnect.de [IPv6:2003:8b:2f0b:a600:dc80:e701:8809:1d99]) by hauke-m.de (Postfix) with ESMTPSA id 868F3100063; Sat, 18 Jun 2016 21:18:17 +0200 (CEST) From: Hauke Mehrtens To: richard@nod.at, dwmw2@infradead.org Subject: [PATCH 2/2] ubi: open volumes define in device tree Date: Sat, 18 Jun 2016 21:17:56 +0200 Message-Id: <1466277476-14853-2-git-send-email-hauke@hauke-m.de> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1466277476-14853-1-git-send-email-hauke@hauke-m.de> References: <1466277476-14853-1-git-send-email-hauke@hauke-m.de> X-Spam-Status: No, score=0.0 required=7.0 tests=UNPARSEABLE_RELAY, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on hauke-m.de X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160618_121839_988249_18BE9563 X-CRM114-Status: GOOD ( 17.06 ) X-Spam-Score: -3.3 (---) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-3.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -1.4 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, devicetree@vger.kernel.org, dedekind1@gmail.com, Hauke Mehrtens , robh+dt@kernel.org, linux-mtd@lists.infradead.org, computersforpeace@gmail.com MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This makes it possible to define a volume to open in device tree. This is helpful when a root file system is on a ubi layer. Without this patch it is only possible to device with with kernel command line parameters. Signed-off-by: Hauke Mehrtens Acked-by: Daniel Golle --- Documentation/devicetree/bindings/mtd/ubi.txt | 22 +++++++++++++++++ drivers/mtd/ubi/build.c | 34 +++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/Documentation/devicetree/bindings/mtd/ubi.txt b/Documentation/devicetree/bindings/mtd/ubi.txt index 5fcd47e..f87a7d8 100644 --- a/Documentation/devicetree/bindings/mtd/ubi.txt +++ b/Documentation/devicetree/bindings/mtd/ubi.txt @@ -13,6 +13,16 @@ Describe of a UBI layer in device tree. which have to be assigned to the newly created UBI device (assigned automatically by default) +Partitions on a UBI layer can be defined: + + - compatible: "ubi,volume" + - name: name of the ubi volume to open + - ubi-mode: mode of the ubi volume to open value: + UBI_READONLY: 1 + UBI_READWRITE: 2 + UBI_EXCLUSIVE: 3 + UBI_METAONLY: 4 + Example: partitions { @@ -29,5 +39,17 @@ partitions { label = "system_sw"; reg = <0x1c0000 0xc800000>; compatible = "ubi,device"; + + rootfsA@0 { + compatible = "ubi,volume"; + name = "rootfsA"; + ubi-mode = <1>; + }; + + data_vol@0 { + compatible = "ubi,volume"; + name = "data_vol"; + ubi-mode = <2>; + }; }; }; diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c index 16baeb5..1c22533 100644 --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c @@ -1,6 +1,7 @@ /* * Copyright (c) International Business Machines Corp., 2006 * Copyright (c) Nokia Corporation, 2007 + * Copyright (c) 2016 Hauke Mehrtens * * 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 @@ -33,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -43,6 +45,7 @@ #include #include #include "ubi.h" +#include "../mtdcore.h" /* Maximum length of the 'mtd=' parameter */ #define MTD_PARAM_LEN_MAX 64 @@ -1205,6 +1208,7 @@ static struct mtd_info * __init open_mtd_device(const char *mtd_dev) static int __init ubi_init(void) { int err, i, k; + struct mtd_info *mtd_it; /* Ensure that EC and VID headers have correct size */ BUILD_BUG_ON(sizeof(struct ubi_ec_hdr) != 64); @@ -1285,6 +1289,36 @@ static int __init ubi_init(void) } } + mtd_for_each_device(mtd_it) { + struct mtd_info *mtd; + u32 ubi_num = 0; + u32 vid_hdr_offs = 0; + u32 max_beb_per1024 = CONFIG_MTD_UBI_BEB_LIMIT; + + mtd = get_mtd_device(mtd_it, -1); + + if (!of_device_is_compatible(mtd->dev.of_node, "ubi,device")) { + put_mtd_device(mtd); + continue; + } + + of_property_read_u32(mtd->dev.of_node, "vid_hdr_offs", + &vid_hdr_offs); + of_property_read_u32(mtd->dev.of_node, "max_beb_per1024", + &max_beb_per1024); + of_property_read_u32(mtd->dev.of_node, "ubi_num", &ubi_num); + + mutex_lock(&ubi_devices_mutex); + err = ubi_attach_mtd_dev(mtd, ubi_num, vid_hdr_offs, + max_beb_per1024); + mutex_unlock(&ubi_devices_mutex); + if (err < 0) { + pr_err("UBI error: cannot attach mtd%d", + mtd->index); + } + put_mtd_device(mtd); + } + err = ubiblock_init(); if (err) { pr_err("UBI error: block: cannot initialize, error %d", err);