Resync with broadcom drivers 5.100.138.20 and utilities.
[tomato.git] / release / src-rt / include / bcmnvram.h
blobd86ecfd5b162e67de825a4464bc540af48f00242
1 /*
2 * NVRAM variable manipulation
4 * Copyright (C) 2010, 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,v 13.62.110.1 2010-08-05 23:00:00 Exp $
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);
49 * Initialize NVRAM access. May be unnecessary or undefined on certain
50 * platforms.
52 extern int nvram_init(void *sih);
55 * Append a chunk of nvram variables to the global list
57 extern int nvram_append(void *si, char *vars, uint varsz);
58 extern void nvram_get_global_vars(char **varlst, uint *varsz);
60 * Check for reset button press for restoring factory defaults.
62 extern int nvram_reset(void *sih);
65 * Disable NVRAM access. May be unnecessary or undefined on certain
66 * platforms.
68 extern void nvram_exit(void *sih);
71 * Get the value of an NVRAM variable. The pointer returned may be
72 * invalid after a set.
73 * @param name name of variable to get
74 * @return value of variable or NULL if undefined
76 extern char * nvram_get(const char *name);
78 /*
79 * Read the reset GPIO value from the nvram and set the GPIO
80 * as input
82 extern int BCMINITFN(nvram_resetgpio_init)(void *sih);
84 /*
85 * Get the value of an NVRAM variable.
86 * @param name name of variable to get
87 * @return value of variable or NUL if undefined
89 #define nvram_safe_get(name) (nvram_get(name) ? : "")
92 * Match an NVRAM variable.
93 * @param name name of variable to match
94 * @param match value to compare against value of variable
95 * @return TRUE if variable is defined and its value is string equal
96 * to match or FALSE otherwise
98 static INLINE int
99 nvram_match(char *name, char *match)
101 const char *value = nvram_get(name);
102 return (value && !strcmp(value, match));
106 * Inversely match an NVRAM variable.
107 * @param name name of variable to match
108 * @param match value to compare against value of variable
109 * @return TRUE if variable is defined and its value is not string
110 * equal to invmatch or FALSE otherwise
112 static INLINE int
113 nvram_invmatch(char *name, char *invmatch)
115 const char *value = nvram_get(name);
116 return (value && strcmp(value, invmatch));
120 * Set the value of an NVRAM variable. The name and value strings are
121 * copied into private storage. Pointers to previously set values
122 * may become invalid. The new value may be immediately
123 * retrieved but will not be permanently stored until a commit.
124 * @param name name of variable to set
125 * @param value value of variable
126 * @return 0 on success and errno on failure
128 extern int nvram_set(const char *name, const char *value);
131 * Unset an NVRAM variable. Pointers to previously set values
132 * remain valid until a set.
133 * @param name name of variable to unset
134 * @return 0 on success and errno on failure
135 * NOTE: use nvram_commit to commit this change to flash.
137 extern int nvram_unset(const char *name);
140 * Commit NVRAM variables to permanent storage. All pointers to values
141 * may be invalid after a commit.
142 * NVRAM values are undefined after a commit.
143 * @return 0 on success and errno on failure
145 extern int nvram_commit(void);
148 * Get all NVRAM variables (format name=value\0 ... \0\0).
149 * @param buf buffer to store variables
150 * @param count size of buffer in bytes
151 * @return 0 on success and errno on failure
153 extern int nvram_getall(char *nvram_buf, int count);
156 * returns the crc value of the nvram
157 * @param nvh nvram header pointer
159 uint8 nvram_calc_crc(struct nvram_header * nvh);
161 #endif /* _LANGUAGE_ASSEMBLY */
163 /* The NVRAM version number stored as an NVRAM variable */
164 #define NVRAM_SOFTWARE_VERSION "1"
166 #define NVRAM_MAGIC 0x48534C46 /* 'FLSH' */
167 #define NVRAM_CLEAR_MAGIC 0x0
168 #define NVRAM_INVALID_MAGIC 0xFFFFFFFF
169 #define NVRAM_VERSION 1
170 #define NVRAM_HEADER_SIZE 20
171 #if (defined(TCONFIG_NVRAM_64K) || defined(CONFIG_NVRAM_64K))
172 #define NVRAM_SPACE 0x10000
173 #else
174 #define NVRAM_SPACE 0x8000
175 #endif
177 #define NVRAM_MAX_VALUE_LEN 255
178 #define NVRAM_MAX_PARAM_LEN 64
180 #define NVRAM_CRC_START_POSITION 9 /* magic, len, crc8 to be skipped */
181 #define NVRAM_CRC_VER_MASK 0xffffff00 /* for crc_ver_init */
183 #if (defined(DUAL_IMAGE) || defined(CONFIG_DUAL_IMAGE) || \
184 defined(__CONFIG_DUAL_IMAGE_FLASH_SUPPORT__))
185 /* Shared by all: CFE, Linux Kernel, and Ap */
186 #define IMAGE_BOOT "image_boot"
187 /* CFE variables */
188 #define IMAGE_1ST_FLASH_TRX "flash3.trx"
189 #define IMAGE_1ST_FLASH_OS "flash3.os"
190 #define IMAGE_2ND_FLASH_TRX "flash3.trx2"
191 #define IMAGE_2ND_FLASH_OS "flash3.os2"
193 /* CFE and Linux Kernel shared variables */
194 #define IMAGE_FIRST_OFFSET "image_first_offset"
195 #define IMAGE_SECOND_OFFSET "image_second_offset"
197 /* Linux application variables */
198 #define LINUX_FIRST "linux"
199 #define LINUX_SECOND "linux2"
200 #define POLICY_TOGGLE "toggle"
201 #define LINUX_PART_TO_FLASH "linux_to_flash"
202 #define LINUX_FLASH_POLICY "linux_flash_policy"
204 #endif /* defined(DUAL_IMAGE||CONFIG_DUAL_IMAGE)||__CONFIG_DUAL_IMAGE_FLASH_SUPPORT__ */
205 #endif /* _bcmnvram_h_ */