Commit | Line | Data |
---|---|---|
d2839953 RC |
1 | /* |
2 | * NVRAM variable manipulation | |
3 | * | |
965f77c4 | 4 | * Copyright (C) 1999-2019, Broadcom. |
d2839953 RC |
5 | * |
6 | * Unless you and Broadcom execute a separate written software license | |
7 | * agreement governing use of this software, this software is licensed to you | |
8 | * under the terms of the GNU General Public License version 2 (the "GPL"), | |
9 | * available at http://www.broadcom.com/licenses/GPLv2.php, with the | |
10 | * following added to such license: | |
11 | * | |
12 | * As a special exception, the copyright holders of this software give you | |
13 | * permission to link this software with independent modules, and to copy and | |
14 | * distribute the resulting executable under terms of your choice, provided that | |
15 | * you also meet, for each linked independent module, the terms and conditions of | |
16 | * the license of that module. An independent module is a module which is not | |
17 | * derived from this software. The special exception does not apply to any | |
18 | * modifications of the software. | |
19 | * | |
20 | * Notwithstanding the above, under no circumstances may you combine this | |
21 | * software in any way with any other Broadcom software provided under a license | |
22 | * other than the GPL, without Broadcom's express prior written consent. | |
23 | * | |
24 | * | |
25 | * <<Broadcom-WL-IPTag/Open:>> | |
26 | * | |
27 | * $Id: bcmnvram.h 655606 2016-08-22 17:16:11Z $ | |
28 | */ | |
29 | ||
30 | #ifndef _bcmnvram_h_ | |
31 | #define _bcmnvram_h_ | |
32 | ||
33 | #ifndef _LANGUAGE_ASSEMBLY | |
34 | ||
35 | #include <typedefs.h> | |
36 | #include <bcmdefs.h> | |
37 | ||
38 | struct nvram_header { | |
39 | uint32 magic; | |
40 | uint32 len; | |
41 | uint32 crc_ver_init; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */ | |
42 | uint32 config_refresh; /* 0:15 sdram_config, 16:31 sdram_refresh */ | |
43 | uint32 config_ncdl; /* ncdl values for memc */ | |
44 | }; | |
45 | ||
46 | struct nvram_tuple { | |
47 | char *name; | |
48 | char *value; | |
49 | struct nvram_tuple *next; | |
50 | }; | |
51 | ||
52 | /* | |
53 | * Get default value for an NVRAM variable | |
54 | */ | |
55 | extern char *nvram_default_get(const char *name); | |
56 | /* | |
57 | * validate/restore all per-interface related variables | |
58 | */ | |
59 | extern void nvram_validate_all(char *prefix, bool restore); | |
60 | ||
61 | /* | |
62 | * restore specific per-interface variable | |
63 | */ | |
64 | extern void nvram_restore_var(char *prefix, char *name); | |
65 | ||
66 | /* | |
67 | * Initialize NVRAM access. May be unnecessary or undefined on certain | |
68 | * platforms. | |
69 | */ | |
70 | extern int nvram_init(void *sih); | |
71 | extern int nvram_deinit(void *sih); | |
72 | ||
73 | extern int nvram_file_read(char **nvramp, int *nvraml); | |
74 | ||
75 | /* | |
76 | * Append a chunk of nvram variables to the global list | |
77 | */ | |
78 | extern int nvram_append(void *si, char *vars, uint varsz); | |
79 | ||
80 | extern void nvram_get_global_vars(char **varlst, uint *varsz); | |
81 | ||
82 | /* | |
83 | * Check for reset button press for restoring factory defaults. | |
84 | */ | |
85 | extern int nvram_reset(void *sih); | |
86 | ||
87 | /* | |
88 | * Disable NVRAM access. May be unnecessary or undefined on certain | |
89 | * platforms. | |
90 | */ | |
91 | extern void nvram_exit(void *sih); | |
92 | ||
93 | /* | |
94 | * Get the value of an NVRAM variable. The pointer returned may be | |
95 | * invalid after a set. | |
96 | * @param name name of variable to get | |
97 | * @return value of variable or NULL if undefined | |
98 | */ | |
99 | extern char * nvram_get(const char *name); | |
100 | ||
101 | /* | |
102 | * Get the value of an NVRAM variable. The pointer returned may be | |
103 | * invalid after a set. | |
104 | * @param name name of variable to get | |
105 | * @param bit bit value to get | |
106 | * @return value of variable or NULL if undefined | |
107 | */ | |
108 | extern char * nvram_get_bitflag(const char *name, const int bit); | |
109 | ||
110 | /* | |
111 | * Read the reset GPIO value from the nvram and set the GPIO | |
112 | * as input | |
113 | */ | |
114 | extern int nvram_resetgpio_init(void *sih); | |
115 | ||
116 | /* | |
117 | * Get the value of an NVRAM variable. | |
118 | * @param name name of variable to get | |
119 | * @return value of variable or NUL if undefined | |
120 | */ | |
121 | static INLINE char * | |
122 | nvram_safe_get(const char *name) | |
123 | { | |
124 | char *p = nvram_get(name); | |
125 | return p ? p : ""; | |
126 | } | |
127 | ||
128 | /* | |
129 | * Match an NVRAM variable. | |
130 | * @param name name of variable to match | |
131 | * @param match value to compare against value of variable | |
132 | * @return TRUE if variable is defined and its value is string equal | |
133 | * to match or FALSE otherwise | |
134 | */ | |
135 | static INLINE int | |
136 | nvram_match(const char *name, const char *match) | |
137 | { | |
138 | const char *value = nvram_get(name); | |
139 | ||
140 | /* In nvramstubs.c builds, nvram_get() is defined as returning zero, | |
141 | * so the return line below never executes the strcmp(), | |
142 | * resulting in 'match' being an unused parameter. | |
143 | * Make a ref to 'match' to quiet the compiler warning. | |
144 | */ | |
145 | ||
146 | BCM_REFERENCE(match); | |
147 | ||
148 | return (value && !strcmp(value, match)); | |
149 | } | |
150 | ||
151 | /* | |
152 | * Match an NVRAM variable. | |
153 | * @param name name of variable to match | |
154 | * @param bit bit value to get | |
155 | * @param match value to compare against value of variable | |
156 | * @return TRUE if variable is defined and its value is string equal | |
157 | * to match or FALSE otherwise | |
158 | */ | |
159 | static INLINE int | |
160 | nvram_match_bitflag(const char *name, const int bit, const char *match) | |
161 | { | |
162 | const char *value = nvram_get_bitflag(name, bit); | |
163 | BCM_REFERENCE(match); | |
164 | return (value && !strcmp(value, match)); | |
165 | } | |
166 | ||
167 | /* | |
168 | * Inversely match an NVRAM variable. | |
169 | * @param name name of variable to match | |
170 | * @param match value to compare against value of variable | |
171 | * @return TRUE if variable is defined and its value is not string | |
172 | * equal to invmatch or FALSE otherwise | |
173 | */ | |
174 | static INLINE int | |
175 | nvram_invmatch(const char *name, const char *invmatch) | |
176 | { | |
177 | const char *value = nvram_get(name); | |
178 | ||
179 | /* In nvramstubs.c builds, nvram_get() is defined as returning zero, | |
180 | * so the return line below never executes the strcmp(), | |
181 | * resulting in 'invmatch' being an unused parameter. | |
182 | * Make a ref to 'invmatch' to quiet the compiler warning. | |
183 | */ | |
184 | ||
185 | BCM_REFERENCE(invmatch); | |
186 | ||
187 | return (value && strcmp(value, invmatch)); | |
188 | } | |
189 | ||
190 | /* | |
191 | * Set the value of an NVRAM variable. The name and value strings are | |
192 | * copied into private storage. Pointers to previously set values | |
193 | * may become invalid. The new value may be immediately | |
194 | * retrieved but will not be permanently stored until a commit. | |
195 | * @param name name of variable to set | |
196 | * @param value value of variable | |
197 | * @return 0 on success and errno on failure | |
198 | */ | |
199 | extern int nvram_set(const char *name, const char *value); | |
200 | ||
201 | /* | |
202 | * Set the value of an NVRAM variable. The name and value strings are | |
203 | * copied into private storage. Pointers to previously set values | |
204 | * may become invalid. The new value may be immediately | |
205 | * retrieved but will not be permanently stored until a commit. | |
206 | * @param name name of variable to set | |
207 | * @param bit bit value to set | |
208 | * @param value value of variable | |
209 | * @return 0 on success and errno on failure | |
210 | */ | |
211 | extern int nvram_set_bitflag(const char *name, const int bit, const int value); | |
212 | /* | |
213 | * Unset an NVRAM variable. Pointers to previously set values | |
214 | * remain valid until a set. | |
215 | * @param name name of variable to unset | |
216 | * @return 0 on success and errno on failure | |
217 | * NOTE: use nvram_commit to commit this change to flash. | |
218 | */ | |
219 | extern int nvram_unset(const char *name); | |
220 | ||
221 | /* | |
222 | * Commit NVRAM variables to permanent storage. All pointers to values | |
223 | * may be invalid after a commit. | |
224 | * NVRAM values are undefined after a commit. | |
225 | * @param nvram_corrupt true to corrupt nvram, false otherwise. | |
226 | * @return 0 on success and errno on failure | |
227 | */ | |
228 | extern int nvram_commit_internal(bool nvram_corrupt); | |
229 | ||
230 | /* | |
231 | * Commit NVRAM variables to permanent storage. All pointers to values | |
232 | * may be invalid after a commit. | |
233 | * NVRAM values are undefined after a commit. | |
234 | * @return 0 on success and errno on failure | |
235 | */ | |
236 | extern int nvram_commit(void); | |
237 | ||
238 | /* | |
239 | * Get all NVRAM variables (format name=value\0 ... \0\0). | |
240 | * @param buf buffer to store variables | |
241 | * @param count size of buffer in bytes | |
242 | * @return 0 on success and errno on failure | |
243 | */ | |
244 | extern int nvram_getall(char *nvram_buf, int count); | |
245 | ||
246 | /* | |
247 | * returns the crc value of the nvram | |
248 | * @param nvh nvram header pointer | |
249 | */ | |
250 | uint8 nvram_calc_crc(struct nvram_header * nvh); | |
251 | ||
252 | extern int nvram_space; | |
253 | #endif /* _LANGUAGE_ASSEMBLY */ | |
254 | ||
255 | /* The NVRAM version number stored as an NVRAM variable */ | |
256 | #define NVRAM_SOFTWARE_VERSION "1" | |
257 | ||
258 | #define NVRAM_MAGIC 0x48534C46 /* 'FLSH' */ | |
259 | #define NVRAM_CLEAR_MAGIC 0x0 | |
260 | #define NVRAM_INVALID_MAGIC 0xFFFFFFFF | |
261 | #define NVRAM_VERSION 1 | |
262 | #define NVRAM_HEADER_SIZE 20 | |
263 | /* This definition is for precommit staging, and will be removed */ | |
264 | #define NVRAM_SPACE 0x8000 | |
265 | /* For CFE builds this gets passed in thru the makefile */ | |
266 | #ifndef MAX_NVRAM_SPACE | |
267 | #define MAX_NVRAM_SPACE 0x10000 | |
268 | #endif // endif | |
269 | #define DEF_NVRAM_SPACE 0x8000 | |
270 | #define ROM_ENVRAM_SPACE 0x1000 | |
271 | #define NVRAM_LZMA_MAGIC 0x4c5a4d41 /* 'LZMA' */ | |
272 | ||
273 | #define NVRAM_MAX_VALUE_LEN 255 | |
274 | #define NVRAM_MAX_PARAM_LEN 64 | |
275 | ||
276 | #define NVRAM_CRC_START_POSITION 9 /* magic, len, crc8 to be skipped */ | |
277 | #define NVRAM_CRC_VER_MASK 0xffffff00 /* for crc_ver_init */ | |
278 | ||
279 | /* Offsets to embedded nvram area */ | |
280 | #define NVRAM_START_COMPRESSED 0x400 | |
281 | #define NVRAM_START 0x1000 | |
282 | ||
283 | #define BCM_JUMBO_NVRAM_DELIMIT '\n' | |
284 | #define BCM_JUMBO_START "Broadcom Jumbo Nvram file" | |
285 | ||
286 | #if (defined(FAILSAFE_UPGRADE) || defined(CONFIG_FAILSAFE_UPGRADE) || \ | |
287 | defined(__CONFIG_FAILSAFE_UPGRADE_SUPPORT__)) | |
288 | #define IMAGE_SIZE "image_size" | |
289 | #define BOOTPARTITION "bootpartition" | |
290 | #define IMAGE_BOOT BOOTPARTITION | |
291 | #define PARTIALBOOTS "partialboots" | |
292 | #define MAXPARTIALBOOTS "maxpartialboots" | |
293 | #define IMAGE_1ST_FLASH_TRX "flash0.trx" | |
294 | #define IMAGE_1ST_FLASH_OS "flash0.os" | |
295 | #define IMAGE_2ND_FLASH_TRX "flash0.trx2" | |
296 | #define IMAGE_2ND_FLASH_OS "flash0.os2" | |
297 | #define IMAGE_FIRST_OFFSET "image_first_offset" | |
298 | #define IMAGE_SECOND_OFFSET "image_second_offset" | |
299 | #define LINUX_FIRST "linux" | |
300 | #define LINUX_SECOND "linux2" | |
301 | #endif // endif | |
302 | ||
303 | #if (defined(DUAL_IMAGE) || defined(CONFIG_DUAL_IMAGE) || \ | |
304 | defined(__CONFIG_DUAL_IMAGE_FLASH_SUPPORT__)) | |
305 | /* Shared by all: CFE, Linux Kernel, and Ap */ | |
306 | #define IMAGE_BOOT "image_boot" | |
307 | #define BOOTPARTITION IMAGE_BOOT | |
308 | /* CFE variables */ | |
309 | #define IMAGE_1ST_FLASH_TRX "flash0.trx" | |
310 | #define IMAGE_1ST_FLASH_OS "flash0.os" | |
311 | #define IMAGE_2ND_FLASH_TRX "flash0.trx2" | |
312 | #define IMAGE_2ND_FLASH_OS "flash0.os2" | |
313 | #define IMAGE_SIZE "image_size" | |
314 | ||
315 | /* CFE and Linux Kernel shared variables */ | |
316 | #define IMAGE_FIRST_OFFSET "image_first_offset" | |
317 | #define IMAGE_SECOND_OFFSET "image_second_offset" | |
318 | ||
319 | /* Linux application variables */ | |
320 | #define LINUX_FIRST "linux" | |
321 | #define LINUX_SECOND "linux2" | |
322 | #define POLICY_TOGGLE "toggle" | |
323 | #define LINUX_PART_TO_FLASH "linux_to_flash" | |
324 | #define LINUX_FLASH_POLICY "linux_flash_policy" | |
325 | ||
326 | #endif /* defined(DUAL_IMAGE||CONFIG_DUAL_IMAGE)||__CONFIG_DUAL_IMAGE_FLASH_SUPPORT__ */ | |
327 | ||
328 | #endif /* _bcmnvram_h_ */ |