mtd: core: call devm_of_platform_populate() for MTD devices
Subsystems (4)
PATCH 1/3 mtd: core: call devm_of_platform_populate() for MTD devices
From: Rafał Miłecki <[email protected]>
This adds support for bindings present in MTD devices (applies to partitions too) nodes. The purpose of this change is to allow drivers handle MTD device (partition) data. Some partitions may contain info that requires parsing & processing.
An example can be U-Boot partition that contains block with environment variables somehwere in a middle. That block should be described in DT and parsed by a specific driver.
--- drivers/mtd/mtdcore.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/mtd/mtdcore.c +4 -0
@@ -19,6 +19,7 @@#include <linux/ioctl.h> #include <linux/init.h> #include <linux/of.h> +#include <linux/of_platform.h> #include <linux/proc_fs.h> #include <linux/idr.h> #include <linux/backing-dev.h>
@@ -690,6 +691,9 @@ int add_mtd_device(struct mtd_info *mtd) not->add (mtd);mutex_unlock (&mtd_table_mutex); + +devm_of_platform_populate (&mtd->dev); +/* We _know_ we aren't being removed, because our caller is still holding us here. So none of this try_ nonsense, and no bitching about it
Signature · 1 line
2.31.1
PATCH 2/3 dt-bindings: nvmem: add U-Boot environment variables binding
From: Rafał Miłecki <[email protected]>
This binding allows describing a (part of) MTD device (partition) that contains a block with environment variables. Operating system usually needs to parse that block to read variables values that may affect booting process & device configuration.
--- .../devicetree/bindings/nvmem/u-boot,env.yaml | 56 +++++++++++++++++++ MAINTAINERS | 5 ++ 2 files changed, 61 insertions(+) create mode 100644 Documentation/devicetree/bindings/nvmem/u-boot,env.yaml
Documentation/devicetree/bindings/nvmem/u-boot,env.yaml new file +56 -0
@@ -0,0 +1,56 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/nvmem/u-boot,env.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: U-Boot environment variables + +description: | + U-Boot uses environment variables to store device parameters and + configuration. They may be used for booting process, setup or keeping end user + interesting info. + + Data is stored on flash partition in a U-Boot specific format (CRC32 and NUL + separated key-value pairs). + + This binding allows specifying data location and format (default one or vendor + specific). + +maintainers: + - Rafał Miłecki <[email protected]> + +allOf: + - $ref: nvmem.yaml# + +properties: + compatible: + enum: + - u,boot,env + - brcm,env + + reg: + maxItems: 1 + +unevaluatedProperties: false + +examples: + - | + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + partition@0 { + label = "uboot"; + reg = <0x0 0x100000>; + + #address-cells = <1>; + #size-cells = <1>; + + nvmem@10000 { + compatible = "u,boot,env"; + reg = <0x10000 0x10000>; + }; + }; + };
MAINTAINERS +5 -0
@@ -19624,6 +19624,11 @@ W: http://linuxtv.org T: git git://linuxtv.org/media_tree.git F: drivers/media/pci/tw686x/ +U-BOOT ENVIRONMENT VARIABLES +M: Rafał Miłecki <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/nvmem/u-boot,env.yaml + UACCE ACCELERATOR FRAMEWORK M: Zhangfei Gao <[email protected]> M: Zhou Wang <[email protected]>
Signature · 1 line
2.31.1
Re: [PATCH 2/3] dt-bindings: nvmem: add U-Boot environment variables binding
Quoted 19 lines · Rafał Miłecki
From: Rafał Miłecki <[email protected]>
This binding allows describing a (part of) MTD device (partition) that contains a block with environment variables. Operating system usually needs to parse that block to read variables values that may affect booting process & device configuration.
Signed-off-by Rafał Miłecki <[email protected]>--- .../devicetree/bindings/nvmem/u-boot,env.yaml | 56 +++++++++++++++++++ MAINTAINERS | 5 ++ 2 files changed, 61 insertions(+) create mode 100644 Documentation/devicetree/bindings/nvmem/u-boot,env.yamlDocumentation/devicetree/bindings/nvmem/u-boot,env.yaml new file +0
-0
Documentation/devicetree/bindings/nvmem/u-boot,env.yaml line 29
Quoted 5 lines
Documentation/devicetree/bindings/nvmem/u-boot,env.yaml new file +5
-0+ +properties: + compatible: + enum: + - u,boot,env
Typo? In patch 3 you match u-boot,env.
Signature · 3 lines
Regards, Pratyush Yadav Texas Instruments Inc.
PATCH 3/3 nvmem: add driver handling U-Boot environment variables
In reply to Rafał MiłeckiFrom: Rafał Miłecki <[email protected]>
U-Boot binary contains a block of environment variables (NVMEM) that should be parsed and exposed as NVMEM cells.
--- MAINTAINERS | 1 + drivers/nvmem/Kconfig | 10 ++ drivers/nvmem/Makefile | 2 + drivers/nvmem/u-boot-env.c | 236 +++++++++++++++++++++++++++++++++++++ 4 files changed, 249 insertions(+) create mode 100644 drivers/nvmem/u-boot-env.c
MAINTAINERS +1 -0
@@ -19628,6 +19628,7 @@ U-BOOT ENVIRONMENT VARIABLES M: Rafał Miłecki <[email protected]> S: Maintained F: Documentation/devicetree/bindings/nvmem/u-boot,env.yaml +F: drivers/nvmem/u-boot-env.c UACCE ACCELERATOR FRAMEWORK M: Zhangfei Gao <[email protected]>
drivers/nvmem/Kconfig +10 -0
@@ -300,4 +300,14 @@ config NVMEM_BRCM_NVRAM This driver provides support for Broadcom's NVRAM that can be accessed using I/O mapping. +config NVMEM_U_BOOT_ENV + tristate "U-Boot environment variables support" + depends on ARCH_BCM4908 || COMPILE_TEST + depends on OF + help + This driver adds support for parsing U-Boot environment variables + stored on flash partition. + + If compiled as module it will be called nvmem_u-boot-env. + endif
drivers/nvmem/Makefile +2 -0
@@ -61,3 +61,5 @@ obj-$(CONFIG_NVMEM_RMEM) += nvmem-rmem.o nvmem-rmem-y := rmem.o obj-$(CONFIG_NVMEM_BRCM_NVRAM) += nvmem_brcm_nvram.o nvmem_brcm_nvram-y := brcm_nvram.o +obj-$(CONFIG_NVMEM_U_BOOT_ENV) += nvmem_u-boot-env.o +nvmem_u-boot-env-y := u-boot-env.o
drivers/nvmem/u-boot-env.c new file +236 -0
236 lines not on this page · raw message
Signature · 1 line
2.31.1
kernel test robot
build botRe: [PATCH 3/3] nvmem: add driver handling U-Boot environment variables
I love your patch! Yet something to improve:
Hi "Rafał,
I love your patch! Yet something to improve:
[auto build test ERROR on robh/for-next]
[also build test ERROR on mtd/mtd/next mtd/mtd/fixes linus/master v5.16-rc7 next-20211224] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Rafa-Mi-ecki/mtd-core-call-devm_of_platform_populate-for-MTD-devices/20211223-032456 base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next config: riscv-randconfig-c006-20211227 (https://download.01.org/0day-ci/archive/20211227/202112271307.07oSwFJV-lkp(a)intel.com/config) compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 511726c64d3b6cca66f7c54d457d586aa3129f67)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install riscv cross compiling tool for clang build
# apt-get install binutils-riscv64-linux-gnu
# https://github.com/0day-ci/linux/commit/43acf8c3e5ac48785826453744a925ff149b1d60
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Rafa-Mi-ecki/mtd-core-call-devm_of_platform_populate-for-MTD-devices/20211223-032456 git checkout 43acf8c3e5ac48785826453744a925ff149b1d60
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash drivers/nvmem/
If you fix the issue, kindly add following tag as appropriate
All error/warnings (new ones prefixed by >>):
>> drivers/nvmem/u-boot-env.c:126:46: warning: format specifies type 'unsigned int' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
dev_info(dev, "offset:0x%08x len:0x%08x\n", image_offset, image_len);
~~~~ ^~~~~~~~~~~~
%08lx
include/linux/dev_printk.h:150:67: note: expanded from macro 'dev_info'
dev_printk_index_wrap(_dev_info, KERN_INFO, dev, dev_fmt(fmt), ##__VA_ARGS__)
~~~ ^~~~~~~~~~~
include/linux/dev_printk.h:110:23: note: expanded from macro 'dev_printk_index_wrap'
_p_func(dev, fmt, ##__VA_ARGS__); \
~~~ ^~~~~~~~~~~
drivers/nvmem/u-boot-env.c:126:60: warning: format specifies type 'unsigned int' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
dev_info(dev, "offset:0x%08x len:0x%08x\n", image_offset, image_len);
~~~~ ^~~~~~~~~
%08lx
include/linux/dev_printk.h:150:67: note: expanded from macro 'dev_info'
dev_printk_index_wrap(_dev_info, KERN_INFO, dev, dev_fmt(fmt), ##__VA_ARGS__)
~~~ ^~~~~~~~~~~
include/linux/dev_printk.h:110:23: note: expanded from macro 'dev_printk_index_wrap'
_p_func(dev, fmt, ##__VA_ARGS__); \
~~~ ^~~~~~~~~~~
>> drivers/nvmem/u-boot-env.c:190:38: error: incompatible pointer types passing 'size_t *' (aka 'unsigned long *') to parameter of type 'u32 *' (aka 'unsigned int *') [-Werror,-Wincompatible-pointer-types]
if (of_property_read_u32(np, "reg", &priv->offset) ||
^~~~~~~~~~~~~
include/linux/of.h:1255:17: note: passing argument to parameter 'out_value' here
u32 *out_value)
^
drivers/nvmem/u-boot-env.c:191:47: error: incompatible pointer types passing 'size_t *' (aka 'unsigned long *') to parameter of type 'u32 *' (aka 'unsigned int *') [-Werror,-Wincompatible-pointer-types]
of_property_read_u32_index(np, "reg", 1, &priv->size)) {
^~~~~~~~~~~
include/linux/of.h:311:28: note: passing argument to parameter 'out_value' here
u32 index, u32 *out_value);
^2 warnings and 2 errors generated.
vim +190 drivers/nvmem/u-boot-env.c
99
100 static int u_boot_env_parse(struct u_boot_env *priv)
101 {
102 struct device *dev = priv->dev;
103 struct u_boot_env_image *image;
104 size_t image_offset;
105 size_t image_len;
106 uint32_t crc32;
107 size_t bytes;
108 uint8_t *buf;
109 int err;
110
111 image_offset = 0;
112 image_len = priv->size;
113 if (priv->format == U_BOOT_FORMAT_BRCM) {
114 struct u_boot_brcm_header header;
115
116 err = mtd_read(priv->mtd, priv->offset, sizeof(header), &bytes,
117 (uint8_t *)&header);
118 if (err && !mtd_is_bitflip(err)) {
119 dev_err(dev, "Failed to read from mtd: %d\n", err);
120 return err;
121 }
122
123 image_offset = sizeof(header);
124 image_len = le32_to_cpu(header.len);
125 }
> 126 dev_info(dev, "offset:0x%08x len:0x%08x\n", image_offset, image_len);
127
128 buf = kcalloc(1, image_len, GFP_KERNEL);
129 if (!buf) {
130 err = -ENOMEM;
131 goto err_out;
132 }
133 image = (struct u_boot_env_image *)buf;
134
135 err = mtd_read(priv->mtd, priv->offset + image_offset, image_len, &bytes, buf);
136 if (err && !mtd_is_bitflip(err)) {
137 dev_err(dev, "Failed to read from mtd: %d\n", err);
138 goto err_kfree;
139 }
140
141 crc32 = crc32(~0, buf + 4, image_len - 4) ^ ~0L;
142 if (crc32 != le32_to_cpu(image->crc32)) {
143 dev_err(dev, "Invalid calculated CRC32: 0x%08x\n", crc32);
144 err = -EINVAL;
145 goto err_kfree;
146 }
147
148 buf[image_len - 1] = '\0';
149 err = u_boot_env_add_cells(priv, image_offset + sizeof(*image),
150 buf + sizeof(*image),
151 image_len - sizeof(*image));
152 if (err)
153 dev_err(dev, "Failed to add cells: %d\n", err);
154
155 err_kfree:
156 kfree(buf);
157 err_out:
158 return err;
159 }
160
161 static const struct of_device_id u_boot_env_of_match_table[] = {
162 { .compatible = "u-boot,env", .data = (void *)U_BOOT_FORMAT_DEFAULT, },
163 { .compatible = "brcm,env", .data = (void *)U_BOOT_FORMAT_BRCM, },
164 {},
165 };
166
167 static int u_boot_env_probe(struct platform_device *pdev)
168 {
169 struct nvmem_config config = {
170 .name = "u-boot-env",
171 .reg_read = u_boot_env_read,
172 };
173 struct device *dev = &pdev->dev;
174 struct device_node *np = dev->of_node;
175 const struct of_device_id *of_id;
176 struct u_boot_env *priv;
177 const char *label;
178 int err;
179
180 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
181 if (!priv)
182 return -ENOMEM;
183 priv->dev = dev;
184
185 of_id = of_match_device(u_boot_env_of_match_table, dev);
186 if (!of_id)
187 return -EINVAL;
188 priv->format = (uintptr_t)of_id->data;
189
> 190 if (of_property_read_u32(np, "reg", &priv->offset) || 191 of_property_read_u32_index(np, "reg", 1, &priv->size)) {
192 dev_err(dev, "Failed to read \"reg\" property\n");
193 return -EINVAL;
194 }
195
196 label = of_get_property(np->parent, "label", NULL);
197 if (!label)
198 label = np->parent->name;
199
200 priv->mtd = get_mtd_device_nm(label);
201 if (IS_ERR(priv->mtd)) {
202 dev_err(dev, "Failed to find \"%s\" MTD device: %ld\n", label, PTR_ERR(priv->mtd));
203 return PTR_ERR(priv->mtd);
204 }
205
206 err = u_boot_env_parse(priv);
207 if (err)
208 return err;
209
210 config.dev = dev;
211 config.cells = priv->cells;
212 config.ncells = priv->ncells;
213 config.priv = priv;
214 config.size = priv->size;
215
216 return PTR_ERR_OR_ZERO(devm_nvmem_register(dev, &config));
217 }
218
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org