[iw] Update iw to version 0.9.13.
[openwrt.git] / package / nvram / src / include / bcmnvram.h
1 /*
2 * NVRAM variable manipulation
3 *
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.
11 *
12 */
13
14 #ifndef _bcmnvram_h_
15 #define _bcmnvram_h_
16
17 #ifndef _LANGUAGE_ASSEMBLY
18
19 #include <typedefs.h>
20
21 struct nvram_header {
22 uint32 magic;
23 uint32 len;
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 */
27 };
28
29 struct nvram_tuple {
30 char *name;
31 char *value;
32 struct nvram_tuple *next;
33 };
34
35 /*
36 * Initialize NVRAM access. May be unnecessary or undefined on certain
37 * platforms.
38 */
39 extern int nvram_init(void *sbh);
40
41 /*
42 * Disable NVRAM access. May be unnecessary or undefined on certain
43 * platforms.
44 */
45 extern void nvram_exit(void);
46
47 /*
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
52 */
53 extern char * nvram_get(const char *name);
54
55 /*
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
59 */
60 #define nvram_safe_get(name) (nvram_get(name) ? : "")
61
62 #define nvram_safe_unset(name) ({ \
63 if(nvram_get(name)) \
64 nvram_unset(name); \
65 })
66
67 #define nvram_safe_set(name, value) ({ \
68 if(!nvram_get(name) || strcmp(nvram_get(name), value)) \
69 nvram_set(name, value); \
70 })
71
72 /*
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
78 */
79 static INLINE int
80 nvram_match(char *name, char *match) {
81 const char *value = nvram_get(name);
82 return (value && !strcmp(value, match));
83 }
84
85 /*
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
91 */
92 static INLINE int
93 nvram_invmatch(char *name, char *invmatch) {
94 const char *value = nvram_get(name);
95 return (value && strcmp(value, invmatch));
96 }
97
98 /*
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
106 */
107 extern int nvram_set(const char *name, const char *value);
108
109 /*
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.
115 */
116 extern int nvram_unset(const char *name);
117
118 /*
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
123 */
124 extern int nvram_commit(void);
125
126 /*
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
131 */
132 extern int nvram_getall(char *buf, int count);
133
134 #endif /* _LANGUAGE_ASSEMBLY */
135
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 */
143
144 #endif /* _bcmnvram_h_ */
This page took 0.050319 seconds and 5 git commands to generate.