get rid of $Id$ - it has never helped us and it has broken too many patches ;)
[openwrt.git] / target / linux / brcm-2.4 / files / arch / mips / bcm947xx / include / bcmnvram.h
1 /*
2 * NVRAM variable manipulation
3 *
4 * Copyright 2007, 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 #include <bcmdefs.h>
21
22 struct nvram_header {
23 uint32 magic;
24 uint32 len;
25 uint32 crc_ver_init; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */
26 uint32 config_refresh; /* 0:15 sdram_config, 16:31 sdram_refresh */
27 uint32 config_ncdl; /* ncdl values for memc */
28 };
29
30 struct nvram_tuple {
31 char *name;
32 char *value;
33 struct nvram_tuple *next;
34 };
35
36 /*
37 * Get default value for an NVRAM variable
38 */
39 extern char *nvram_default_get(const char *name);
40
41 /*
42 * Append a chunk of nvram variables to the global list
43 */
44 extern int nvram_append(void *sb, char *vars, uint varsz);
45
46 /*
47 * Check for reset button press for restoring factory defaults.
48 */
49 extern bool nvram_reset(void *sbh);
50
51 /*
52 * Disable NVRAM access. May be unnecessary or undefined on certain
53 * platforms.
54 */
55 extern void nvram_exit(void *sbh);
56
57 /*
58 * Get the value of an NVRAM variable. The pointer returned may be
59 * invalid after a set.
60 * @param name name of variable to get
61 * @return value of variable or NULL if undefined
62 */
63 extern char * nvram_get(const char *name);
64
65 /*
66 * Read the reset GPIO value from the nvram and set the GPIO
67 * as input
68 */
69 extern int BCMINITFN(nvram_resetgpio_init)(void *sbh);
70
71 /*
72 * Get the value of an NVRAM variable.
73 * @param name name of variable to get
74 * @return value of variable or NUL if undefined
75 */
76 #define nvram_safe_get(name) (nvram_get(name) ? : "")
77
78 /*
79 * Match an NVRAM variable.
80 * @param name name of variable to match
81 * @param match value to compare against value of variable
82 * @return TRUE if variable is defined and its value is string equal
83 * to match or FALSE otherwise
84 */
85 static INLINE int
86 nvram_match(char *name, char *match) {
87 const char *value = nvram_get(name);
88 return (value && !strcmp(value, match));
89 }
90
91 /*
92 * Inversely match an NVRAM variable.
93 * @param name name of variable to match
94 * @param match value to compare against value of variable
95 * @return TRUE if variable is defined and its value is not string
96 * equal to invmatch or FALSE otherwise
97 */
98 static INLINE int
99 nvram_invmatch(char *name, char *invmatch) {
100 const char *value = nvram_get(name);
101 return (value && strcmp(value, invmatch));
102 }
103
104 /*
105 * Set the value of an NVRAM variable. The name and value strings are
106 * copied into private storage. Pointers to previously set values
107 * may become invalid. The new value may be immediately
108 * retrieved but will not be permanently stored until a commit.
109 * @param name name of variable to set
110 * @param value value of variable
111 * @return 0 on success and errno on failure
112 */
113 extern int nvram_set(const char *name, const char *value);
114
115 /*
116 * Unset an NVRAM variable. Pointers to previously set values
117 * remain valid until a set.
118 * @param name name of variable to unset
119 * @return 0 on success and errno on failure
120 * NOTE: use nvram_commit to commit this change to flash.
121 */
122 extern int nvram_unset(const char *name);
123
124 /*
125 * Commit NVRAM variables to permanent storage. All pointers to values
126 * may be invalid after a commit.
127 * NVRAM values are undefined after a commit.
128 * @return 0 on success and errno on failure
129 */
130 extern int nvram_commit(void);
131
132 /*
133 * Get all NVRAM variables (format name=value\0 ... \0\0).
134 * @param buf buffer to store variables
135 * @param count size of buffer in bytes
136 * @return 0 on success and errno on failure
137 */
138 extern int nvram_getall(char *nvram_buf, int count);
139
140 /*
141 * returns the crc value of the nvram
142 * @param nvh nvram header pointer
143 */
144 extern uint8 nvram_calc_crc(struct nvram_header * nvh);
145
146 extern char* getvar(char *vars, const char *name);
147 extern int getintvar(char *vars, const char *name);
148
149 #endif /* _LANGUAGE_ASSEMBLY */
150
151 /* The NVRAM version number stored as an NVRAM variable */
152 #define NVRAM_SOFTWARE_VERSION "1"
153
154 #define NVRAM_MAGIC 0x48534C46 /* 'FLSH' */
155 #define NVRAM_CLEAR_MAGIC 0x0
156 #define NVRAM_INVALID_MAGIC 0xFFFFFFFF
157 #define NVRAM_VERSION 1
158 #define NVRAM_HEADER_SIZE 20
159 #define NVRAM_SPACE 0x8000
160
161 #define NVRAM_MAX_VALUE_LEN 255
162 #define NVRAM_MAX_PARAM_LEN 64
163
164 #define NVRAM_CRC_START_POSITION 9 /* magic, len, crc8 to be skipped */
165 #define NVRAM_CRC_VER_MASK 0xffffff00 /* for crc_ver_init */
166
167 #endif /* _bcmnvram_h_ */
This page took 0.04891 seconds and 5 git commands to generate.