On 09/03/2014 07:14 PM, Rafał Miłecki wrote: > NVRAM can be read using magic memory offset, but after all it's just a > flash partition. On platforms where NVRAM isn't needed early we can get > it using mtd subsystem. Where would this work? Do you plan the following initialization order in bcma on arm and mips? 1. bcma SoC version 2. bcma bus scan 3. flash driver registration 4. nvram read 5. sprom generation from nvram and attaching to bcma 6. registration of the other bcam cores (wifi, ...) The nvram is memory mapped on every SoC, just on devices with nand flash booting we would need something to check for bad blocks. > > Signed-off-by: Rafał Miłecki <zajec5@xxxxxxxxx> > --- > arch/mips/bcm47xx/nvram.c | 40 ++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 40 insertions(+) > > diff --git a/arch/mips/bcm47xx/nvram.c b/arch/mips/bcm47xx/nvram.c > index 8ea2116..9ab74db 100644 > --- a/arch/mips/bcm47xx/nvram.c > +++ b/arch/mips/bcm47xx/nvram.c > @@ -16,6 +16,7 @@ > #include <linux/ssb/ssb.h> > #include <linux/kernel.h> > #include <linux/string.h> > +#include <linux/mtd/mtd.h> > #include <asm/addrspace.h> > #include <bcm47xx_nvram.h> > #include <asm/mach-bcm47xx/bcm47xx.h> > @@ -148,6 +149,13 @@ static int nvram_init_bcma(void) > > static int nvram_init(void) > { > +#ifdef CONFIG_MTD > + struct mtd_info *mtd; > + struct nvram_header header; > + size_t bytes_read; > + int i; > +#endif > + > switch (bcm47xx_bus_type) { > #ifdef CONFIG_BCM47XX_SSB > case BCM47XX_BUS_TYPE_SSB: > @@ -158,6 +166,38 @@ static int nvram_init(void) > return nvram_init_bcma(); > #endif > } > + > +#ifdef CONFIG_MTD > + mtd = get_mtd_device_nm("nvram"); > + if (IS_ERR(mtd)) > + return -ENODEV; > + > + for (i = 0; i < ARRAY_SIZE(nvram_sizes); i++) { > + loff_t from = mtd->size - nvram_sizes[i]; > + > + if (from < 0) > + continue; > + > + if (mtd_read(mtd, from, sizeof(header), &bytes_read, > + (uint8_t *)&header) < 0) > + continue; > + if (header.magic == NVRAM_HEADER) { > + u8 *dst = (uint8_t *)nvram_buf; > + size_t len = header.len; > + > + if (header.len > NVRAM_SPACE) { > + pr_err("nvram on flash (%i bytes) is bigger than the reserved space in memory, will just copy the first %i bytes\n", > + header.len, NVRAM_SPACE); > + len = NVRAM_SPACE; > + } > + > + if (mtd_read(mtd, from, len, &bytes_read, dst) < 0) > + continue; > + memset(dst + bytes_read, 0x0, NVRAM_SPACE - bytes_read); > + } > + } > +#endif > + > return -ENXIO; > } > >