Message ID | cover.1708906456.git.daniel@makrotopia.org |
---|---|
Headers |
Return-Path: <linux-kernel+bounces-80354-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1795977dyb; Sun, 25 Feb 2024 16:23:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXElJumYcgJ5pBTNnIuil6NCw0V3+EM44a4EfSAJe+CkD0eOZH0FeA66DnYabfRHR9lmbc5cewlndW3sE03K3QFGcjrrw== X-Google-Smtp-Source: AGHT+IEmsNqC0cpXwCcxRpWxG2W2lEAt8y/NLfr0xyfoss6ACeeMqj0vptVUAVMy9Utacl1lVTeW X-Received: by 2002:ad4:5ce9:0:b0:68f:2b1c:5516 with SMTP id iv9-20020ad45ce9000000b0068f2b1c5516mr7873704qvb.32.1708906989276; Sun, 25 Feb 2024 16:23:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708906989; cv=pass; d=google.com; s=arc-20160816; b=sjGNP+gIMmB+QhySOOvyAevKjZo+r7lMrNeRrQwM+iWqRggL1SQxKrt6QLEBRFnogn PfG5Q9e9VI/ktbDr29yI4vdRdbLomccBNVCC4zOwgzYc55HY4Hrqdf+atBIW7D+tIthf f5IxyT3ORN2GnkWS1iaJUzJZnTBv6YufDdsBt0uSqp2+WQFfpARUZrsaTrU0RgDd/WTJ hg+d310ibnHhgvOsT4B2R0WeyBuIonFD5Y+1enumVSRRbpPdNxXa5ls5qWcC/juAlENV G6HT/sPaD+Ho04SZHqVonBljhwyMKcP7UCKJ7IwkXdQ35spdTYpjZtxGP3mdqTI8naK0 mm1w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:subject:to:from:date; bh=ehR6kOfELph4rGdaHvBNiKIbe8JDWNQF7DqPPK2I+RE=; fh=iCY7pZACTeEM/aV1VSRdKj3GWTB74ZtqN+MwTbm3QUU=; b=g9qr9vzfh8GknFVAN6YV5EjJUFoiFiNwuCqbUHBYiZcyQAK6SGl/PEMFMehbxT97Mv /nzC6SGh/Cu9rgfGMEAVZnD3GGH/u7c+SSG+QQYLNP7S2TZIf/TtAwYJ/vQJm82gUFDU fzDlztGARODAjgjmAjPnxJTB72zH0BtgOhwa0hit3i24UsxuGBRIqSiNjyr2jmteb06z XIjjaVBHkcYmG4bCijrF+kjSzpb3gpF6TVModF7QEGKulftA0gAWAgVBKNlo2H55BmnX 4ZzrqPI/wi5ed9bnog6lNKZLswMJeYVayeku62GIxgeDLZVeiqJaLOdqja1bP780qDqO B1rg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=makrotopia.org); spf=pass (google.com: domain of linux-kernel+bounces-80354-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80354-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id gw6-20020a0562140f0600b0068f07ff2506si4023851qvb.223.2024.02.25.16.23.09 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 16:23:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80354-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=makrotopia.org); spf=pass (google.com: domain of linux-kernel+bounces-80354-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80354-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 148DE1C20B62 for <ouuuleilei@gmail.com>; Mon, 26 Feb 2024 00:23:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4ADEF4C8F; Mon, 26 Feb 2024 00:22:57 +0000 (UTC) Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B56519F; Mon, 26 Feb 2024 00:22:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.142.180.65 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708906975; cv=none; b=tG2S6OH83wiqxbTEcWxa8EIl6XgbqZgWtIrDT0B1UBlFRdIMDzYGofFZotZRY5fkjeRsTEsFCvB22YWfIUmTOHfWASl34yMzeuy24tHV6DqvFf6lmdPNr6109U9cXbqqAV5UGJYiIZlrPPcb5qMbEl4ll95qDbDCRVxM97Mpe1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708906975; c=relaxed/simple; bh=XgpawS2kecmzLSDpMZ/VLjdoFInp94yEmYbRTjat95w=; h=Date:From:To:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=oWBL1eatTYhJbwbhnV/gCdzrIPi8LDmYHjqrhHjB0wLfLf4FnW8ahXdJnyJTocPM2/k2yIL4DL/wQN0E9TBFWIFpD3y9iVGUNr/osUz87G5ufSPYqRYnTFfZRBt0EYBoVtX5uNVZVDui2W3u1+W/z6/IsMFNysx7Q/O4q278v7I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org; spf=pass smtp.mailfrom=makrotopia.org; arc=none smtp.client-ip=185.142.180.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=makrotopia.org Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96.2) (envelope-from <daniel@makrotopia.org>) id 1reOlW-0001nE-1i; Mon, 26 Feb 2024 00:22:42 +0000 Date: Mon, 26 Feb 2024 00:22:39 +0000 From: Daniel Golle <daniel@makrotopia.org> To: Miquel Raynal <miquel.raynal@bootlin.com>, Richard Weinberger <richard@nod.at>, Vignesh Raghavendra <vigneshr@ti.com>, Rob Herring <robh@kernel.org>, Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>, Conor Dooley <conor+dt@kernel.org>, Daniel Golle <daniel@makrotopia.org>, linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 0/7] mtd: ubi: allow UBI volumes to provide NVMEM Message-ID: <cover.1708906456.git.daniel@makrotopia.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791918855025964077 X-GMAIL-MSGID: 1791918855025964077 |
Series |
mtd: ubi: allow UBI volumes to provide NVMEM
|
|
Message
Daniel Golle
Feb. 26, 2024, 12:22 a.m. UTC
Similar to how MAC addresses and Wi-Fi calibration data would be stored inside an MTD partition on devices coming with NOR flash, a UBI volume is used by some vendors in the same way on devices with NAND flash. The goal of this series is to support such embedded Linux devices which got NVMEM bits stored inside a UBI volume. Representing the UBI volume in the Device Tree and adding a phandle to be referenced by NVMEM consumers allows such devices to come up with their correct MAC addresses and device-specific Wi-Fi calibration data loaded. In order for NVMEM bits to be available for other drivers, attaching UBI devices has to be moved from late_initcall (which is too late for other drivers) to happen earlier. As an alternative to the existing kernel cmdline parameter the Device Tree property 'compatible = "linux,ubi";' inside an MTD partition can be used to have that MTD device attached as UBI device. MTD partitions which serve as UBI devices may have a "volumes" subnode with volumes, and volumes may have an "nvmem-layout" object which will trigger the creation of an emulated NVMEM device on top of the UBI volume. In this way, other drivers (think: Ethernet, Wi-Fi) can resolve and acquire NVMEM bits using the usual device tree phandle, just this time the NVMEM content is read from a UBI volume. This series is a follow-up and contains most patches of the previous series "mtd: ubi: behave like a good MTD citizen"[1] which was meant in preparation for implementing the NVMEM provider. As lots of time has passed NVMEM-on-UBI is by now already in-use downstream at OpenWrt to support reading WiFi EEPROMs and MAC addresses on a bunch of ASUS devices[2], [3] which laudably store all in UBI. That also exposed a possible issue on 32-bit platforms which has now been addressed in v8. [1]: https://patchwork.ozlabs.org/project/linux-mtd/list/?series=353177&state=%2A&archive=both [2]: https://github.com/openwrt/openwrt/pull/14676 (merged) [3]: https://github.com/openwrt/openwrt/pull/14729 (pending) Changes since v7: * use integer types with well-defined size for use with do_div(n, base) (addresses compiler warning when building on 32-bit platforms) Changes since v6: * dt-bindings fixes got squashed into the wrong patch, fix that and newly introduced YAML white space issues Changes since v5: * fix whitespace problems in dt-schema additions Changes since v4: * split ubi_open_volume_path() breaking out reusable parts for new match_volume_desc() function as suggested by Richard Weinberger. Doing the same for ubi_open_volume_nm() doesn't work as we are working on struct ubi_volume_info in match_volume_desc() while ubi_open_volume_nm() is working on struct ubi_volume. That reduces the common part to a string comparision and length check which doesn't seem worth breaking out of the existing function. * drop patches and changes not strictly needed for NVMEM use-case: - don't handle ubi detach on MTD removal notification. It was not done until now and the locking hell I was facing when trying to implement that is non trivial. - don't relocate the call to ubiblock device creation to the notification handler - change ubiblock only as far as needed to handle creation from cmdline parameter when a volume is added. * improve commit messages and comments Changes since v3: * dt-bindings fixes as requested Changes since v2: * include dt-bindings additions Changes since v1: * include patch to fix exiting Kconfig formatting issues * fix typo and indentation in Kconfig Daniel Golle (7): dt-bindings: mtd: add basic bindings for UBI dt-bindings: mtd: ubi-volume: allow UBI volumes to provide NVMEM mtd: ubi: block: use notifier to create ubiblock from parameter mtd: ubi: attach from device tree mtd: ubi: introduce pre-removal notification for UBI volumes mtd: ubi: populate ubi volume fwnode mtd: ubi: provide NVMEM layer over UBI volumes .../bindings/mtd/partitions/linux,ubi.yaml | 75 +++++++ .../bindings/mtd/partitions/ubi-volume.yaml | 40 ++++ drivers/mtd/ubi/Kconfig | 13 ++ drivers/mtd/ubi/Makefile | 1 + drivers/mtd/ubi/block.c | 136 ++++++------- drivers/mtd/ubi/build.c | 154 ++++++++++---- drivers/mtd/ubi/kapi.c | 56 +++-- drivers/mtd/ubi/nvmem.c | 191 ++++++++++++++++++ drivers/mtd/ubi/ubi.h | 3 + drivers/mtd/ubi/vmt.c | 44 +++- include/linux/mtd/ubi.h | 2 + 11 files changed, 583 insertions(+), 132 deletions(-) create mode 100644 Documentation/devicetree/bindings/mtd/partitions/linux,ubi.yaml create mode 100644 Documentation/devicetree/bindings/mtd/partitions/ubi-volume.yaml create mode 100644 drivers/mtd/ubi/nvmem.c