2 * BCM947xx nvram variable access
4 * Copyright 2005, Broadcom Corporation
5 * Copyright 2006, Felix Fietkau <nbd@openwrt.org>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
13 #include <linux/init.h>
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/string.h>
17 #include <linux/interrupt.h>
18 #include <linux/spinlock.h>
19 #include <linux/slab.h>
20 #include <asm/byteorder.h>
21 #include <asm/bootinfo.h>
22 #include <asm/addrspace.h>
24 #include <asm/uaccess.h>
30 #define WINDOW_ADDR 0x1F000000
31 #define WINDOW_SIZE 0x800000
33 static char nvram_buf[NVRAM_SPACE];
35 extern char *cfe_env_get(char *nv_buf, const char *name);
37 /* Probe for NVRAM header */
38 void __init early_nvram_init(void)
40 struct nvram_header *header;
50 /* XXX: hack for supporting the CFE environment stuff on WGT634U */
52 src = (u32 *) KSEG1ADDR(base + 8 MB - 0x20000);
53 dst = (u32 *) nvram_buf;
55 /* We are looking for the String gOGoBrCm */
56 if ((*src) == 0x674f476f && (*(src + 1)) == 0x4272436d) {
57 printk("early_nvram_init: EasyGate NVRAM found.\n");
59 for (i = 0; i < 0x1ff0; i++) {
60 if (*src == 0xFFFFFFFF)
71 /* Windowed flash access */
72 header = (struct nvram_header *) KSEG1ADDR(base + off - NVRAM_SPACE);
73 if (header->magic == NVRAM_HEADER)
78 /* Try embedded NVRAM at 4 KB and 1 KB as last resorts */
79 header = (struct nvram_header *) KSEG1ADDR(base + 4096);
80 if (header->magic == NVRAM_HEADER)
83 header = (struct nvram_header *) KSEG1ADDR(base + 1024);
84 if (header->magic == NVRAM_HEADER)
87 printk("Found no CFE environnment\n");
91 printk("Found CFE environnment\n");
93 dst = (u32 *) nvram_buf;
94 for (i = 0; i < sizeof(struct nvram_header); i += 4)
96 for (; i < header->len && i < NVRAM_SPACE; i += 4)
97 //*dst++ = le32_to_cpu(*src++);
98 *dst++ = be32_to_cpu(*src++);
101 char *nvram_get(const char *name)
103 char *var, *value, *end, *eq;
112 return cfe_env_get(nvram_buf, name);
114 /* Look for name=value and return value */
115 var = &nvram_buf[sizeof(struct nvram_header)];
116 end = nvram_buf + sizeof(nvram_buf) - 2;
117 end[0] = end[1] = '\0';
118 for (; *var; var = value + strlen(value) + 1) {
119 if (!(eq = strchr(var, '=')))
122 if ((eq - var) == strlen(name) && strncmp(var, name, (eq - var)) == 0)
129 EXPORT_SYMBOL(nvram_get);