GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / include / bcmnvram.h
blob802508b0236f09f3cfc7930273ead469b1c88658
1 /*
2 * NVRAM variable manipulation
4 * Copyright (C) 2012, 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 398971 2013-04-26 22:39:49Z $
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 /* This definition is for precommit staging, and will be removed */
208 #define NVRAM_SPACE 0x10000
209 /* For CFE builds this gets passed in thru the makefile */
210 #ifndef MAX_NVRAM_SPACE
211 #define MAX_NVRAM_SPACE 0x10000
212 #endif
213 #define DEF_NVRAM_SPACE 0x10000
214 #define ROM_ENVRAM_SPACE 0x1000
215 #define NVRAM_LZMA_MAGIC 0x4c5a4d41 /* 'LZMA' */
217 #define NVRAM_MAX_VALUE_LEN 2048
218 #define NVRAM_MAX_PARAM_LEN 64
220 #define NVRAM_CRC_START_POSITION 9 /* magic, len, crc8 to be skipped */
221 #define NVRAM_CRC_VER_MASK 0xffffff00 /* for crc_ver_init */
223 /* Offsets to embedded nvram area */
224 #define NVRAM_START_COMPRESSED 0x400
225 #define NVRAM_START 0x1000
227 #define BCM_JUMBO_NVRAM_DELIMIT '\n'
228 #define BCM_JUMBO_START "Broadcom Jumbo Nvram file"
230 #if !defined(BCMHIGHSDIO) && defined(BCMTRXV2)
231 extern char *_vars;
232 extern uint _varsz;
233 #endif
235 #if (defined(FAILSAFE_UPGRADE) || defined(CONFIG_FAILSAFE_UPGRADE) || \
236 defined(__CONFIG_FAILSAFE_UPGRADE_SUPPORT__))
237 #define IMAGE_SIZE "image_size"
238 #define BOOTPARTITION "bootpartition"
239 #define IMAGE_BOOT BOOTPARTITION
240 #define PARTIALBOOTS "partialboots"
241 #define MAXPARTIALBOOTS "maxpartialboots"
242 #define IMAGE_1ST_FLASH_TRX "flash0.trx"
243 #define IMAGE_1ST_FLASH_OS "flash0.os"
244 #define IMAGE_2ND_FLASH_TRX "flash0.trx2"
245 #define IMAGE_2ND_FLASH_OS "flash0.os2"
246 #define IMAGE_FIRST_OFFSET "image_first_offset"
247 #define IMAGE_SECOND_OFFSET "image_second_offset"
248 #define LINUX_FIRST "linux"
249 #define LINUX_SECOND "linux2"
250 #endif
252 #if (defined(DUAL_IMAGE) || defined(CONFIG_DUAL_IMAGE) || \
253 defined(__CONFIG_DUAL_IMAGE_FLASH_SUPPORT__))
254 /* Shared by all: CFE, Linux Kernel, and Ap */
255 #define IMAGE_BOOT "image_boot"
256 #define BOOTPARTITION IMAGE_BOOT
257 /* CFE variables */
258 #define IMAGE_1ST_FLASH_TRX "flash0.trx"
259 #define IMAGE_1ST_FLASH_OS "flash0.os"
260 #define IMAGE_2ND_FLASH_TRX "flash0.trx2"
261 #define IMAGE_2ND_FLASH_OS "flash0.os2"
262 #define IMAGE_SIZE "image_size"
264 /* CFE and Linux Kernel shared variables */
265 #define IMAGE_FIRST_OFFSET "image_first_offset"
266 #define IMAGE_SECOND_OFFSET "image_second_offset"
268 /* Linux application variables */
269 #define LINUX_FIRST "linux"
270 #define LINUX_SECOND "linux2"
271 #define POLICY_TOGGLE "toggle"
272 #define LINUX_PART_TO_FLASH "linux_to_flash"
273 #define LINUX_FLASH_POLICY "linux_flash_policy"
275 #endif /* defined(DUAL_IMAGE||CONFIG_DUAL_IMAGE)||__CONFIG_DUAL_IMAGE_FLASH_SUPPORT__ */
277 #endif /* _bcmnvram_h_ */