2 * NVRAM variable manipulation
4 * Copyright (C) 1999-2011, Broadcom Corporation
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:
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.
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.
24 * $Id: bcmnvram.h,v 13.62 2008-11-25 21:02:44 $
30 #ifndef _LANGUAGE_ASSEMBLY
38 uint32 crc_ver_init; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */
39 uint32 config_refresh; /* 0:15 sdram_config, 16:31 sdram_refresh */
40 uint32 config_ncdl; /* ncdl values for memc */
46 struct nvram_tuple *next;
50 * Get default value for an NVRAM variable
52 extern char *nvram_default_get(const char *name);
55 * Initialize NVRAM access. May be unnecessary or undefined on certain
58 extern int nvram_init(void *sih);
61 * Append a chunk of nvram variables to the global list
63 extern int nvram_append(void *si, char *vars, uint varsz);
66 * Check for reset button press for restoring factory defaults.
68 extern int nvram_reset(void *sih);
71 * Disable NVRAM access. May be unnecessary or undefined on certain
74 extern void nvram_exit(void *sih);
77 * Get the value of an NVRAM variable. The pointer returned may be
78 * invalid after a set.
79 * @param name name of variable to get
80 * @return value of variable or NULL if undefined
82 extern char * nvram_get(const char *name);
85 * Read the reset GPIO value from the nvram and set the GPIO
88 extern int nvram_resetgpio_init(void *sih);
91 * Get the value of an NVRAM variable.
92 * @param name name of variable to get
93 * @return value of variable or NUL if undefined
95 #define nvram_safe_get(name) (nvram_get(name) ? : "")
98 * Match an NVRAM variable.
99 * @param name name of variable to match
100 * @param match value to compare against value of variable
101 * @return TRUE if variable is defined and its value is string equal
102 * to match or FALSE otherwise
105 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)
121 const char *value = nvram_get(name);
122 return (value && strcmp(value, invmatch));
126 * Set the value of an NVRAM variable. The name and value strings are
127 * copied into private storage. Pointers to previously set values
128 * may become invalid. The new value may be immediately
129 * retrieved but will not be permanently stored until a commit.
130 * @param name name of variable to set
131 * @param value value of variable
132 * @return 0 on success and errno on failure
134 extern int nvram_set(const char *name, const char *value);
137 * Unset an NVRAM variable. Pointers to previously set values
138 * remain valid until a set.
139 * @param name name of variable to unset
140 * @return 0 on success and errno on failure
141 * NOTE: use nvram_commit to commit this change to flash.
143 extern int nvram_unset(const char *name);
146 * Commit NVRAM variables to permanent storage. All pointers to values
147 * may be invalid after a commit.
148 * NVRAM values are undefined after a commit.
149 * @return 0 on success and errno on failure
151 extern int nvram_commit(void);
154 * Get all NVRAM variables (format name=value\0 ... \0\0).
155 * @param buf buffer to store variables
156 * @param count size of buffer in bytes
157 * @return 0 on success and errno on failure
159 extern int nvram_getall(char *nvram_buf, int count);
162 * returns the crc value of the nvram
163 * @param nvh nvram header pointer
165 uint8 nvram_calc_crc(struct nvram_header * nvh);
167 #endif /* _LANGUAGE_ASSEMBLY */
169 /* The NVRAM version number stored as an NVRAM variable */
170 #define NVRAM_SOFTWARE_VERSION "1"
172 #define NVRAM_MAGIC 0x48534C46 /* 'FLSH' */
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 #define NVRAM_MAX_VALUE_LEN 255
180 #define NVRAM_MAX_PARAM_LEN 64
182 #define NVRAM_CRC_START_POSITION 9 /* magic, len, crc8 to be skipped */
183 #define NVRAM_CRC_VER_MASK 0xffffff00 /* for crc_ver_init */
185 #endif /* _bcmnvram_h_ */