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.
18 #ifndef _LANGUAGE_ASSEMBLY
25 uint32 crc_ver_init
; /* 0:7 crc, 8:15 ver, 16:27 init, mem. test 28, 29-31 reserved */
26 uint32 config_refresh
; /* 0:15 config, 16:31 refresh */
27 uint32 config_ncdl
; /* ncdl values for memc */
33 struct nvram_tuple
*next
;
37 * Initialize NVRAM access. May be unnecessary or undefined on certain
40 extern int nvram_init(void *sbh
);
43 * Disable NVRAM access. May be unnecessary or undefined on certain
46 extern void nvram_exit(void);
49 * Get the value of an NVRAM variable. The pointer returned may be
50 * invalid after a set.
51 * @param name name of variable to get
52 * @return value of variable or NULL if undefined
54 extern char * nvram_get(const char *name
);
57 * Get the value of an NVRAM variable.
58 * @param name name of variable to get
59 * @return value of variable or NUL if undefined
61 #define nvram_safe_get(name) (nvram_get(name) ? : "")
63 #define nvram_safe_unset(name) ({ \
68 #define nvram_safe_set(name, value) ({ \
69 if(!nvram_get(name) || strcmp(nvram_get(name), value)) \
70 nvram_set(name, value); \
74 * Match an NVRAM variable.
75 * @param name name of variable to match
76 * @param match value to compare against value of variable
77 * @return TRUE if variable is defined and its value is string equal
78 * to match or FALSE otherwise
81 nvram_match(char *name
, char *match
) {
82 const char *value
= nvram_get(name
);
83 return (value
&& !strcmp(value
, match
));
87 * Inversely match an NVRAM variable.
88 * @param name name of variable to match
89 * @param match value to compare against value of variable
90 * @return TRUE if variable is defined and its value is not string
91 * equal to invmatch or FALSE otherwise
94 nvram_invmatch(char *name
, char *invmatch
) {
95 const char *value
= nvram_get(name
);
96 return (value
&& strcmp(value
, invmatch
));
100 * Set the value of an NVRAM variable. The name and value strings are
101 * copied into private storage. Pointers to previously set values
102 * may become invalid. The new value may be immediately
103 * retrieved but will not be permanently stored until a commit.
104 * @param name name of variable to set
105 * @param value value of variable
106 * @return 0 on success and errno on failure
108 extern int nvram_set(const char *name
, const char *value
);
111 * Unset an NVRAM variable. Pointers to previously set values
112 * remain valid until a set.
113 * @param name name of variable to unset
114 * @return 0 on success and errno on failure
115 * NOTE: use nvram_commit to commit this change to flash.
117 extern int nvram_unset(const char *name
);
120 * Commit NVRAM variables to permanent storage. All pointers to values
121 * may be invalid after a commit.
122 * NVRAM values are undefined after a commit.
123 * @return 0 on success and errno on failure
125 extern int nvram_commit(void);
128 * Get all NVRAM variables (format name=value\0 ... \0\0).
129 * @param buf buffer to store variables
130 * @param count size of buffer in bytes
131 * @return 0 on success and errno on failure
133 extern int nvram_getall(char *buf
, int count
);
135 extern int file2nvram(char *filename
, char *varname
);
136 extern int nvram2file(char *varname
, char *filename
);
138 #endif /* _LANGUAGE_ASSEMBLY */
140 #define NVRAM_MAGIC 0x48534C46 /* 'FLSH' */
141 #define NVRAM_VERSION 1
142 #define NVRAM_HEADER_SIZE 20
143 #define NVRAM_SPACE 0x8000
144 #define FLASH_BASE 0xbfc00000 /* Extif core */
145 #define FLASH_MIN 0x00100000 /* Minimum flash size */
146 #define FLASH_MAX 0x00400000 /* Maximum flash size with extif */
148 #endif /* _bcmnvram_h_ */
This page took 0.047432 seconds and 5 git commands to generate.