cosmetics
[tomato.git] / release / src / include / bcmnvram.h
blob6e10c4678fa1b7e4f3bc44b4212db25022299285
1 /*
2 * NVRAM variable manipulation
4 * Copyright 2004, Broadcom Corporation
5 * All Rights Reserved.
6 *
7 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
12 * $Id$
15 #ifndef _bcmnvram_h_
16 #define _bcmnvram_h_
18 #ifndef _LANGUAGE_ASSEMBLY
20 #include <typedefs.h>
21 #include <bcmdefs.h>
23 struct nvram_header {
24 uint32 magic;
25 uint32 len;
26 uint32 crc_ver_init; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */
27 uint32 config_refresh; /* 0:15 sdram_config, 16:31 sdram_refresh */
28 uint32 config_ncdl; /* ncdl values for memc */
31 struct nvram_tuple {
32 char *name;
33 char *value;
34 struct nvram_tuple *next;
38 * Get default value for an NVRAM variable
40 extern char *nvram_default_get(const char *name);
43 * Initialize NVRAM access. May be unnecessary or undefined on certain
44 * platforms.
46 extern int nvram_init(void *sbh);
49 * Append a chunk of nvram variables to the global list
51 extern int nvram_append(void *sb, char *vars, uint varsz);
54 * Check for reset button press for restoring factory defaults.
56 extern bool nvram_reset(void *sbh);
59 * Disable NVRAM access. May be unnecessary or undefined on certain
60 * platforms.
62 extern void nvram_exit(void *sbh);
65 * Get the value of an NVRAM variable. The pointer returned may be
66 * invalid after a set.
67 * @param name name of variable to get
68 * @return value of variable or NULL if undefined
70 extern char * nvram_get(const char *name);
72 /*
73 * Read the reset GPIO value from the nvram and set the GPIO
74 * as input
76 extern int BCMINITFN(nvram_resetgpio_init)(void *sbh);
78 /*
79 * Get the value of an NVRAM variable.
80 * @param name name of variable to get
81 * @return value of variable or NUL if undefined
83 #define nvram_safe_get(name) (nvram_get(name) ? : "")
86 * Match an NVRAM variable.
87 * @param name name of variable to match
88 * @param match value to compare against value of variable
89 * @return TRUE if variable is defined and its value is string equal
90 * to match or FALSE otherwise
92 static INLINE int
93 nvram_match(char *name, char *match) {
94 const char *value = nvram_get(name);
95 return (value && !strcmp(value, match));
99 * Inversely match an NVRAM variable.
100 * @param name name of variable to match
101 * @param match value to compare against value of variable
102 * @return TRUE if variable is defined and its value is not string
103 * equal to invmatch or FALSE otherwise
105 static INLINE int
106 nvram_invmatch(char *name, char *invmatch) {
107 const char *value = nvram_get(name);
108 return (value && strcmp(value, invmatch));
112 * Set the value of an NVRAM variable. The name and value strings are
113 * copied into private storage. Pointers to previously set values
114 * may become invalid. The new value may be immediately
115 * retrieved but will not be permanently stored until a commit.
116 * @param name name of variable to set
117 * @param value value of variable
118 * @return 0 on success and errno on failure
120 extern int nvram_set(const char *name, const char *value);
123 * Unset an NVRAM variable. Pointers to previously set values
124 * remain valid until a set.
125 * @param name name of variable to unset
126 * @return 0 on success and errno on failure
127 * NOTE: use nvram_commit to commit this change to flash.
129 extern int nvram_unset(const char *name);
132 * Commit NVRAM variables to permanent storage. All pointers to values
133 * may be invalid after a commit.
134 * NVRAM values are undefined after a commit.
135 * @return 0 on success and errno on failure
137 extern int nvram_commit(void);
140 * Get all NVRAM variables (format name=value\0 ... \0\0).
141 * @param buf buffer to store variables
142 * @param count size of buffer in bytes
143 * @return 0 on success and errno on failure
145 extern int nvram_getall(char *nvram_buf, int count);
148 * returns the crc value of the nvram
149 * @param nvh nvram header pointer
151 uint8 nvram_calc_crc(struct nvram_header * nvh);
153 #endif /* _LANGUAGE_ASSEMBLY */
155 /* The NVRAM version number stored as an NVRAM variable */
156 #define NVRAM_SOFTWARE_VERSION "1"
158 #define NVRAM_MAGIC 0x48534C46 /* 'FLSH' */
159 #define NVRAM_CLEAR_MAGIC 0x0
160 #define NVRAM_INVALID_MAGIC 0xFFFFFFFF
161 #define NVRAM_VERSION 1
162 #define NVRAM_HEADER_SIZE 20
163 #if CONFIG_NVRAM_SIZE
164 #define NVRAM_SPACE CONFIG_NVRAM_SIZE * 0x0400
165 #else
166 #define NVRAM_SPACE 0x8000
167 #endif
169 #define NVRAM_MAX_VALUE_LEN 255
170 #define NVRAM_MAX_PARAM_LEN 64
172 #define NVRAM_CRC_START_POSITION 9 /* magic, len, crc8 to be skipped */
173 #define NVRAM_CRC_VER_MASK 0xffffff00 /* for crc_ver_init */
175 #endif /* _bcmnvram_h_ */