2 * NVRAM variable manipulation
4 * Copyright 2004, Broadcom Corporation
7 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
18 #ifndef _LANGUAGE_ASSEMBLY
23 #define ROUNDUP_P2(n, a) ((n + (a - 1)) & ~(a - 1))
28 uint32 crc_ver_init
; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */
30 uint32 config_refresh
; /* 0:15 sdram_config, 16:31 sdram_refresh */
31 uint32 config_ncdl
; /* ncdl values for memc */
34 /* Used by app, CFE, etc. */
38 struct nvram_tuple
*next
;
41 /* Used by kernel NVRAM internals. */
43 struct nvram_dbitem
*next
;
51 * Get default value for an NVRAM variable
53 extern char *nvram_default_get(const char *name
);
56 * Initialize NVRAM access. May be unnecessary or undefined on certain
59 extern int nvram_init(void *sbh
);
62 * Append a chunk of nvram variables to the global list
64 extern int nvram_append(void *sb
, char *vars
, uint varsz
);
67 * Check for reset button press for restoring factory defaults.
69 extern bool nvram_reset(void *sbh
);
72 * Disable NVRAM access. May be unnecessary or undefined on certain
75 extern void nvram_exit(void *sbh
);
78 * Get the value of an NVRAM variable. The pointer returned may be
79 * invalid after a set.
80 * @param name name of variable to get
81 * @return value of variable or NULL if undefined
83 extern char * nvram_get(const char *name
);
86 * Read the reset GPIO value from the nvram and set the GPIO
89 extern int BCMINITFN(nvram_resetgpio_init
)(void *sbh
);
92 * Get the value of an NVRAM variable.
93 * @param name name of variable to get
94 * @return value of variable or NUL if undefined
96 #define nvram_safe_get(name) (nvram_get(name) ? : "")
99 * Match an NVRAM variable.
100 * @param name name of variable to match
101 * @param match value to compare against value of variable
102 * @return TRUE if variable is defined and its value is string equal
103 * to match or FALSE otherwise
106 nvram_match(char *name
, char *match
) {
107 const char *value
= nvram_get(name
);
108 return (value
&& !strcmp(value
, match
));
112 * Inversely match an NVRAM variable.
113 * @param name name of variable to match
114 * @param match value to compare against value of variable
115 * @return TRUE if variable is defined and its value is not string
116 * equal to invmatch or FALSE otherwise
119 nvram_invmatch(char *name
, char *invmatch
) {
120 const char *value
= nvram_get(name
);
121 return (value
&& strcmp(value
, invmatch
));
125 * Set the value of an NVRAM variable. The name and value strings are
126 * copied into private storage. Pointers to previously set values
127 * may become invalid. The new value may be immediately
128 * retrieved but will not be permanently stored until a commit.
129 * @param name name of variable to set
130 * @param value value of variable
131 * @return 0 on success and errno on failure
133 extern int nvram_set(const char *name
, const char *value
);
136 * Unset an NVRAM variable. Pointers to previously set values
137 * remain valid until a set.
138 * @param name name of variable to unset
139 * @return 0 on success and errno on failure
140 * NOTE: use nvram_commit to commit this change to flash.
142 extern int nvram_unset(const char *name
);
145 * Commit NVRAM variables to permanent storage. All pointers to values
146 * may be invalid after a commit.
147 * NVRAM values are undefined after a commit.
148 * @return 0 on success and errno on failure
150 extern int nvram_commit(void);
153 * Get all NVRAM variables (format name=value\0 ... \0\0).
154 * @param buf buffer to store variables
155 * @param count size of buffer in bytes
156 * @return 0 on success and errno on failure
158 extern int nvram_getall(char *nvram_buf
, int count
);
161 * returns the crc value of the nvram
162 * @param nvh nvram header pointer
164 uint8
nvram_calc_crc(struct nvram_header
* nvh
);
166 #endif /* _LANGUAGE_ASSEMBLY */
168 /* The NVRAM version number stored as an NVRAM variable */
169 #define NVRAM_SOFTWARE_VERSION "1"
171 #define NVRAM_MAGIC 0x48534C46 /* 'FLSH' */
172 #define NVRAM_OFLOW_MAGIC 0x464c5348 /* 'HSLF' */
173 #define NVRAM_CLEAR_MAGIC 0x0
174 #define NVRAM_INVALID_MAGIC 0xFFFFFFFF
175 #define NVRAM_VERSION 1
176 #define NVRAM_HEADER_SIZE 20
177 #define NVRAM_SPACE 0x8000
179 /* The size of the buffer for storing item values.
180 * This can be smaller than the nvram area, because it has no names.
181 * But each value is on a 4-byte boundary, so average of 2 wasted
182 * bytes per item. Replaced values also occupy space. We have to
183 * garbage collect when it gets full.
185 * This is for "nvram_buf", which is statically allocated.
186 * early_nvram_*() copies the nvram data to this buffer. So it *must*
187 * be at least 60KB for E3000 routers that have 60KB nvram.
189 #define NVRAM_VAL_SIZE (64 * 1024)
191 #define NVRAM_32K 0x8000 /* Sorry, 32kB is pretty much baked in. */
193 #define NVRAM_MAX_VALUE_LEN 255 /* Not true! */
194 #define NVRAM_MAX_PARAM_LEN 64 /* Not true! */
196 #define NVRAM_CRC_START_POSITION 9 /* magic, len, crc8 to be skipped */
197 #define NVRAM_CRC_VER_MASK 0xffffff00 /* for crc_ver_init */
199 #endif /* _bcmnvram_h_ */