Netgear R6400 support
[tomato.git] / release / src-rt-6.x.4708 / include / bcmnvram.h
blobcb970818e3f2bde907aad6692d18fb616832a853
1 /*
2 * NVRAM variable manipulation
4 * Copyright (C) 2013, Broadcom Corporation. All Rights Reserved.
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
13 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
15 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 * $Id: bcmnvram.h 419467 2013-08-21 09:19:48Z $
21 #ifndef _bcmnvram_h_
22 #define _bcmnvram_h_
24 #ifndef _LANGUAGE_ASSEMBLY
26 #include <typedefs.h>
27 #include <bcmdefs.h>
29 struct nvram_header {
30 uint32 magic;
31 uint32 len;
32 uint32 crc_ver_init; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */
33 uint32 config_refresh; /* 0:15 sdram_config, 16:31 sdram_refresh */
34 uint32 config_ncdl; /* ncdl values for memc */
37 struct nvram_tuple {
38 char *name;
39 char *value;
40 struct nvram_tuple *next;
44 * Get default value for an NVRAM variable
46 extern char *nvram_default_get(const char *name);
48 * validate/restore all per-interface related variables
50 extern void nvram_validate_all(char *prefix, bool restore);
53 * restore specific per-interface variable
55 extern void nvram_restore_var(char *prefix, char *name);
58 * Initialize NVRAM access. May be unnecessary or undefined on certain
59 * platforms.
61 extern int nvram_init(void *sih);
62 extern int nvram_deinit(void *sih);
64 #if defined(_CFE_) && defined(BCM_DEVINFO)
65 extern char *flashdrv_nvram;
66 extern char *devinfo_flashdrv_nvram;
67 extern int devinfo_nvram_init(void *sih);
68 extern int devinfo_nvram_sync(void);
69 extern void _nvram_hash_select(int idx);
70 #endif
73 * Append a chunk of nvram variables to the global list
75 extern int nvram_append(void *si, char *vars, uint varsz);
77 extern void nvram_get_global_vars(char **varlst, uint *varsz);
81 * Check for reset button press for restoring factory defaults.
83 extern int nvram_reset(void *sih);
86 * Disable NVRAM access. May be unnecessary or undefined on certain
87 * platforms.
89 extern void nvram_exit(void *sih);
92 * Get the value of an NVRAM variable. The pointer returned may be
93 * invalid after a set.
94 * @param name name of variable to get
95 * @return value of variable or NULL if undefined
97 extern char * nvram_get(const char *name);
100 * Read the reset GPIO value from the nvram and set the GPIO
101 * as input
103 extern int BCMINITFN(nvram_resetgpio_init)(void *sih);
106 * Get the value of an NVRAM variable.
107 * @param name name of variable to get
108 * @return value of variable or NUL if undefined
110 static INLINE char *
111 nvram_safe_get(const char *name)
113 char *p = nvram_get(name);
114 return p ? p : "";
118 * Match an NVRAM variable.
119 * @param name name of variable to match
120 * @param match value to compare against value of variable
121 * @return TRUE if variable is defined and its value is string equal
122 * to match or FALSE otherwise
124 static INLINE int
125 nvram_match(const char *name, const char *match)
127 const char *value = nvram_get(name);
128 return (value && !strcmp(value, match));
132 * Inversely match an NVRAM variable.
133 * @param name name of variable to match
134 * @param match value to compare against value of variable
135 * @return TRUE if variable is defined and its value is not string
136 * equal to invmatch or FALSE otherwise
138 static INLINE int
139 nvram_invmatch(const char *name, const char *invmatch)
141 const char *value = nvram_get(name);
142 return (value && strcmp(value, invmatch));
146 * Set the value of an NVRAM variable. The name and value strings are
147 * copied into private storage. Pointers to previously set values
148 * may become invalid. The new value may be immediately
149 * retrieved but will not be permanently stored until a commit.
150 * @param name name of variable to set
151 * @param value value of variable
152 * @return 0 on success and errno on failure
154 extern int nvram_set(const char *name, const char *value);
157 * Unset an NVRAM variable. Pointers to previously set values
158 * remain valid until a set.
159 * @param name name of variable to unset
160 * @return 0 on success and errno on failure
161 * NOTE: use nvram_commit to commit this change to flash.
163 extern int nvram_unset(const char *name);
166 * Commit NVRAM variables to permanent storage. All pointers to values
167 * may be invalid after a commit.
168 * NVRAM values are undefined after a commit.
169 * @param nvram_corrupt true to corrupt nvram, false otherwise.
170 * @return 0 on success and errno on failure
172 extern int nvram_commit_internal(bool nvram_corrupt);
175 * Commit NVRAM variables to permanent storage. All pointers to values
176 * may be invalid after a commit.
177 * NVRAM values are undefined after a commit.
178 * @return 0 on success and errno on failure
180 extern int nvram_commit(void);
183 * Get all NVRAM variables (format name=value\0 ... \0\0).
184 * @param buf buffer to store variables
185 * @param count size of buffer in bytes
186 * @return 0 on success and errno on failure
188 extern int nvram_getall(char *nvram_buf, int count);
191 * returns the crc value of the nvram
192 * @param nvh nvram header pointer
194 uint8 nvram_calc_crc(struct nvram_header * nvh);
196 extern int nvram_space;
197 #endif /* _LANGUAGE_ASSEMBLY */
199 /* The NVRAM version number stored as an NVRAM variable */
200 #define NVRAM_SOFTWARE_VERSION "1"
202 #define NVRAM_MAGIC 0x48534C46 /* 'FLSH' */
203 #define NVRAM_CLEAR_MAGIC 0x0
204 #define NVRAM_INVALID_MAGIC 0xFFFFFFFF
205 #define NVRAM_VERSION 1
206 #define NVRAM_HEADER_SIZE 20
207 #if (defined(TCONFIG_NVRAM_128K) || defined(CONFIG_NVRAM_128K))
208 /* This definition is for precommit staging, and will be removed */
209 #define NVRAM_SPACE 0x20000
210 /* For CFE builds this gets passed in thru the makefile */
211 #ifndef MAX_NVRAM_SPACE
212 #define MAX_NVRAM_SPACE 0x20000
213 #endif
214 #define DEF_NVRAM_SPACE 0x20000
215 #else
216 /* This definition is for precommit staging, and will be removed */
217 #define NVRAM_SPACE 0x10000
218 /* For CFE builds this gets passed in thru the makefile */
219 #ifndef MAX_NVRAM_SPACE
220 #define MAX_NVRAM_SPACE 0x10000
221 #endif
222 #define DEF_NVRAM_SPACE 0x10000
223 #endif
224 #define ROM_ENVRAM_SPACE 0x1000
225 #define NVRAM_LZMA_MAGIC 0x4c5a4d41 /* 'LZMA' */
227 #define NVRAM_MAX_VALUE_LEN 2048
228 #define NVRAM_MAX_PARAM_LEN 64
230 #define NVRAM_CRC_START_POSITION 9 /* magic, len, crc8 to be skipped */
231 #define NVRAM_CRC_VER_MASK 0xffffff00 /* for crc_ver_init */
233 /* Offsets to embedded nvram area */
234 #define NVRAM_START_COMPRESSED 0x400
235 #define NVRAM_START 0x1000
237 #define BCM_JUMBO_NVRAM_DELIMIT '\n'
238 #define BCM_JUMBO_START "Broadcom Jumbo Nvram file"
240 #if !defined(BCMHIGHSDIO) && defined(BCMTRXV2)
241 extern char *_vars;
242 extern uint _varsz;
243 #endif
245 #if (defined(FAILSAFE_UPGRADE) || defined(CONFIG_FAILSAFE_UPGRADE) || \
246 defined(__CONFIG_FAILSAFE_UPGRADE_SUPPORT__))
247 #define IMAGE_SIZE "image_size"
248 #define BOOTPARTITION "bootpartition"
249 #define IMAGE_BOOT BOOTPARTITION
250 #define PARTIALBOOTS "partialboots"
251 #define MAXPARTIALBOOTS "maxpartialboots"
252 #define IMAGE_1ST_FLASH_TRX "flash0.trx"
253 #define IMAGE_1ST_FLASH_OS "flash0.os"
254 #define IMAGE_2ND_FLASH_TRX "flash0.trx2"
255 #define IMAGE_2ND_FLASH_OS "flash0.os2"
256 #define IMAGE_FIRST_OFFSET "image_first_offset"
257 #define IMAGE_SECOND_OFFSET "image_second_offset"
258 #define LINUX_FIRST "linux"
259 #define LINUX_SECOND "linux2"
260 #endif
262 #if (defined(DUAL_IMAGE) || defined(CONFIG_DUAL_IMAGE) || \
263 defined(__CONFIG_DUAL_IMAGE_FLASH_SUPPORT__))
264 /* Shared by all: CFE, Linux Kernel, and Ap */
265 #define IMAGE_BOOT "image_boot"
266 #define BOOTPARTITION IMAGE_BOOT
267 /* CFE variables */
268 #define IMAGE_1ST_FLASH_TRX "flash0.trx"
269 #define IMAGE_1ST_FLASH_OS "flash0.os"
270 #define IMAGE_2ND_FLASH_TRX "flash0.trx2"
271 #define IMAGE_2ND_FLASH_OS "flash0.os2"
272 #define IMAGE_SIZE "image_size"
274 /* CFE and Linux Kernel shared variables */
275 #define IMAGE_FIRST_OFFSET "image_first_offset"
276 #define IMAGE_SECOND_OFFSET "image_second_offset"
278 /* Linux application variables */
279 #define LINUX_FIRST "linux"
280 #define LINUX_SECOND "linux2"
281 #define POLICY_TOGGLE "toggle"
282 #define LINUX_PART_TO_FLASH "linux_to_flash"
283 #define LINUX_FLASH_POLICY "linux_flash_policy"
285 #endif /* defined(DUAL_IMAGE||CONFIG_DUAL_IMAGE)||__CONFIG_DUAL_IMAGE_FLASH_SUPPORT__ */
287 #endif /* _bcmnvram_h_ */