2 * NVRAM variable manipulation
4 * Copyright 2004, Broadcom Corporation
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.
17 #ifndef _LANGUAGE_ASSEMBLY
24 uint32 crc_ver_init
; /* 0:7 crc, 8:15 ver, 16:27 init, mem. test 28, 29-31 reserved */
25 uint32 config_refresh
; /* 0:15 config, 16:31 refresh */
26 uint32 config_ncdl
; /* ncdl values for memc */
32 struct nvram_tuple
*next
;
36 * Initialize NVRAM access. May be unnecessary or undefined on certain
39 extern int nvram_init(void *sbh
);
42 * Disable NVRAM access. May be unnecessary or undefined on certain
45 extern void nvram_exit(void);
48 * Get the value of an NVRAM variable. The pointer returned may be
49 * invalid after a set.
50 * @param name name of variable to get
51 * @return value of variable or NULL if undefined
53 extern char * nvram_get(const char *name
);
56 * Get the value of an NVRAM variable.
57 * @param name name of variable to get
58 * @return value of variable or NUL if undefined
60 #define nvram_safe_get(name) (nvram_get(name) ? : "")
62 #define nvram_safe_unset(name) ({ \
67 #define nvram_safe_set(name, value) ({ \
68 if(!nvram_get(name) || strcmp(nvram_get(name), value)) \
69 nvram_set(name, value); \
73 * Match an NVRAM variable.
74 * @param name name of variable to match
75 * @param match value to compare against value of variable
76 * @return TRUE if variable is defined and its value is string equal
77 * to match or FALSE otherwise
80 nvram_match(char *name
, char *match
) {
81 const char *value
= nvram_get(name
);
82 return (value
&& !strcmp(value
, match
));
86 * Inversely 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 not string
90 * equal to invmatch or FALSE otherwise
93 nvram_invmatch(char *name
, char *invmatch
) {
94 const char *value
= nvram_get(name
);
95 return (value
&& strcmp(value
, invmatch
));
99 * Set the value of an NVRAM variable. The name and value strings are
100 * copied into private storage. Pointers to previously set values
101 * may become invalid. The new value may be immediately
102 * retrieved but will not be permanently stored until a commit.
103 * @param name name of variable to set
104 * @param value value of variable
105 * @return 0 on success and errno on failure
107 extern int nvram_set(const char *name
, const char *value
);
110 * Unset an NVRAM variable. Pointers to previously set values
111 * remain valid until a set.
112 * @param name name of variable to unset
113 * @return 0 on success and errno on failure
114 * NOTE: use nvram_commit to commit this change to flash.
116 extern int nvram_unset(const char *name
);
119 * Commit NVRAM variables to permanent storage. All pointers to values
120 * may be invalid after a commit.
121 * NVRAM values are undefined after a commit.
122 * @return 0 on success and errno on failure
124 extern int nvram_commit(void);
127 * Get all NVRAM variables (format name=value\0 ... \0\0).
128 * @param buf buffer to store variables
129 * @param count size of buffer in bytes
130 * @return 0 on success and errno on failure
132 extern int nvram_getall(char *buf
, int count
);
134 #endif /* _LANGUAGE_ASSEMBLY */
136 #define NVRAM_MAGIC 0x48534C46 /* 'FLSH' */
137 #define NVRAM_VERSION 1
138 #define NVRAM_HEADER_SIZE 20
139 #define NVRAM_SPACE 0x8000
140 #define FLASH_BASE 0xbfc00000 /* Extif core */
141 #define FLASH_MIN 0x00100000 /* Minimum flash size */
142 #define FLASH_MAX 0x00400000 /* Maximum flash size with extif */
144 #endif /* _bcmnvram_h_ */
This page took 0.050319 seconds and 5 git commands to generate.