[openwrt/openwrt] bcm53xx: initialize NVRAM from NVMEM driver

LEDE Commits lede-commits at lists.infradead.org
Fri Mar 12 17:25:22 GMT 2021


rmilecki pushed a commit to openwrt/openwrt.git, branch master:
https://git.openwrt.org/baf04eed028a838518c65be48cbaabe0892343aa

commit baf04eed028a838518c65be48cbaabe0892343aa
Author: Rafał Miłecki <rafal at milecki.pl>
AuthorDate: Fri Mar 12 18:10:09 2021 +0100

    bcm53xx: initialize NVRAM from NVMEM driver
    
    NVRAM access may be needed early in boot process. Reading it using mtd
    happens quite late in the init process. Add NVRAM initialization to the
    NVMEM driver which comes up early and depends on IO mapping only.
    
    This is required by Linksys devices which use NVRAM content for proper
    partitioning (detecting current firmware partition).
    
    Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
---
 ...bcm47xx_nvram-support-init-from-IO-memory.patch | 61 ++++++++++++++++++++++
 ...nvram-provide-NVMEM-content-to-the-NVRAM-.patch | 31 +++++++++++
 2 files changed, 92 insertions(+)

diff --git a/target/linux/bcm53xx/patches-5.4/800-0001-firmware-bcm47xx_nvram-support-init-from-IO-memory.patch b/target/linux/bcm53xx/patches-5.4/800-0001-firmware-bcm47xx_nvram-support-init-from-IO-memory.patch
new file mode 100644
index 0000000000..86792d6ebf
--- /dev/null
+++ b/target/linux/bcm53xx/patches-5.4/800-0001-firmware-bcm47xx_nvram-support-init-from-IO-memory.patch
@@ -0,0 +1,61 @@
+From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal at milecki.pl>
+Date: Thu, 11 Mar 2021 08:24:44 +0100
+Subject: [PATCH] firmware: bcm47xx_nvram: support init from IO memory
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
+---
+ drivers/firmware/broadcom/bcm47xx_nvram.c | 17 +++++++++++++++++
+ include/linux/bcm47xx_nvram.h             |  6 ++++++
+ 2 files changed, 23 insertions(+)
+
+--- a/drivers/firmware/broadcom/bcm47xx_nvram.c
++++ b/drivers/firmware/broadcom/bcm47xx_nvram.c
+@@ -110,6 +110,23 @@ found:
+ 	return 0;
+ }
+ 
++int bcm47xx_nvram_init_from_iomem(void __iomem *nvram_start, size_t res_size)
++{
++	if (nvram_len) {
++		pr_warn("nvram already initialized\n");
++		return -EEXIST;
++	}
++
++	if (!bcm47xx_nvram_is_valid(nvram_start)) {
++		pr_err("No valid NVRAM found\n");
++		return -ENOENT;
++	}
++
++	bcm47xx_nvram_copy(nvram_start, res_size);
++
++	return 0;
++}
++
+ /*
+  * On bcm47xx we need access to the NVRAM very early, so we can't use mtd
+  * subsystem to access flash. We can't even use platform device / driver to
+--- a/include/linux/bcm47xx_nvram.h
++++ b/include/linux/bcm47xx_nvram.h
+@@ -11,6 +11,7 @@
+ #include <linux/vmalloc.h>
+ 
+ #ifdef CONFIG_BCM47XX_NVRAM
++int bcm47xx_nvram_init_from_iomem(void __iomem *nvram_start, size_t res_size);
+ int bcm47xx_nvram_init_from_mem(u32 base, u32 lim);
+ int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len);
+ int bcm47xx_nvram_gpio_pin(const char *name);
+@@ -20,6 +21,11 @@ static inline void bcm47xx_nvram_release
+ 	vfree(nvram);
+ };
+ #else
++static inline int bcm47xx_nvram_init_from_iomem(void __iomem *nvram_start,
++						size_t res_size)
++{
++	return -ENOTSUPP;
++}
+ static inline int bcm47xx_nvram_init_from_mem(u32 base, u32 lim)
+ {
+ 	return -ENOTSUPP;
diff --git a/target/linux/bcm53xx/patches-5.4/800-0002-nvmem-brcm_nvram-provide-NVMEM-content-to-the-NVRAM-.patch b/target/linux/bcm53xx/patches-5.4/800-0002-nvmem-brcm_nvram-provide-NVMEM-content-to-the-NVRAM-.patch
new file mode 100644
index 0000000000..cf5952ad5f
--- /dev/null
+++ b/target/linux/bcm53xx/patches-5.4/800-0002-nvmem-brcm_nvram-provide-NVMEM-content-to-the-NVRAM-.patch
@@ -0,0 +1,31 @@
+From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal at milecki.pl>
+Date: Thu, 11 Mar 2021 08:26:14 +0100
+Subject: [PATCH] nvmem: brcm_nvram: provide NVMEM content to the NVRAM driver
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
+---
+ drivers/nvmem/brcm_nvram.c | 3 +++
+ 1 file changed, 3 insertions(+)
+
+--- a/drivers/nvmem/brcm_nvram.c
++++ b/drivers/nvmem/brcm_nvram.c
+@@ -3,6 +3,7 @@
+  * Copyright (C) 2021 Rafał Miłecki <rafal at milecki.pl>
+  */
+ 
++#include <linux/bcm47xx_nvram.h>
+ #include <linux/io.h>
+ #include <linux/mod_devicetable.h>
+ #include <linux/module.h>
+@@ -46,6 +47,8 @@ static int brcm_nvram_probe(struct platf
+ 	if (IS_ERR(priv->base))
+ 		return PTR_ERR(priv->base);
+ 
++	bcm47xx_nvram_init_from_iomem(priv->base, resource_size(res));
++
+ 	config.dev = dev;
+ 	config.priv = priv;
+ 	config.size = resource_size(res);



More information about the lede-commits mailing list