CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
orangepi-xunlong

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: orangepi-xunlong/orangepi-build
Path: blob/next/external/cache/sources/wl/include/bcmnvram.h
Views: 3959
1
/*
2
* NVRAM variable manipulation
3
*
4
* $Copyright Open Broadcom Corporation$
5
*
6
* $Id: bcmnvram.h 401759 2013-05-13 16:08:08Z sudhirbs $
7
*/
8
9
#ifndef _bcmnvram_h_
10
#define _bcmnvram_h_
11
12
#ifndef _LANGUAGE_ASSEMBLY
13
14
#include <typedefs.h>
15
#include <bcmdefs.h>
16
17
struct nvram_header {
18
uint32 magic;
19
uint32 len;
20
uint32 crc_ver_init; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */
21
uint32 config_refresh; /* 0:15 sdram_config, 16:31 sdram_refresh */
22
uint32 config_ncdl; /* ncdl values for memc */
23
};
24
25
struct nvram_tuple {
26
char *name;
27
char *value;
28
struct nvram_tuple *next;
29
};
30
31
/*
32
* Get default value for an NVRAM variable
33
*/
34
extern char *nvram_default_get(const char *name);
35
/*
36
* validate/restore all per-interface related variables
37
*/
38
extern void nvram_validate_all(char *prefix, bool restore);
39
40
/*
41
* restore specific per-interface variable
42
*/
43
extern void nvram_restore_var(char *prefix, char *name);
44
45
/*
46
* Initialize NVRAM access. May be unnecessary or undefined on certain
47
* platforms.
48
*/
49
extern int nvram_init(void *sih);
50
extern int nvram_deinit(void *sih);
51
52
#if defined(_CFE_) && defined(BCM_DEVINFO)
53
extern char *flashdrv_nvram;
54
extern char *devinfo_flashdrv_nvram;
55
extern int devinfo_nvram_init(void *sih);
56
extern int devinfo_nvram_sync(void);
57
extern void _nvram_hash_select(int idx);
58
#endif
59
60
/*
61
* Append a chunk of nvram variables to the global list
62
*/
63
extern int nvram_append(void *si, char *vars, uint varsz);
64
65
extern void nvram_get_global_vars(char **varlst, uint *varsz);
66
67
68
/*
69
* Check for reset button press for restoring factory defaults.
70
*/
71
extern int nvram_reset(void *sih);
72
73
/*
74
* Disable NVRAM access. May be unnecessary or undefined on certain
75
* platforms.
76
*/
77
extern void nvram_exit(void *sih);
78
79
/*
80
* Get the value of an NVRAM variable. The pointer returned may be
81
* invalid after a set.
82
* @param name name of variable to get
83
* @return value of variable or NULL if undefined
84
*/
85
extern char * nvram_get(const char *name);
86
87
/*
88
* Read the reset GPIO value from the nvram and set the GPIO
89
* as input
90
*/
91
extern int BCMINITFN(nvram_resetgpio_init)(void *sih);
92
93
/*
94
* Get the value of an NVRAM variable.
95
* @param name name of variable to get
96
* @return value of variable or NUL if undefined
97
*/
98
static INLINE char *
99
nvram_safe_get(const char *name)
100
{
101
char *p = nvram_get(name);
102
return p ? p : "";
103
}
104
105
/*
106
* Match an NVRAM variable.
107
* @param name name of variable to match
108
* @param match value to compare against value of variable
109
* @return TRUE if variable is defined and its value is string equal
110
* to match or FALSE otherwise
111
*/
112
static INLINE int
113
nvram_match(const char *name, const char *match)
114
{
115
const char *value = nvram_get(name);
116
return (value && !strcmp(value, match));
117
}
118
119
/*
120
* Inversely match an NVRAM variable.
121
* @param name name of variable to match
122
* @param match value to compare against value of variable
123
* @return TRUE if variable is defined and its value is not string
124
* equal to invmatch or FALSE otherwise
125
*/
126
static INLINE int
127
nvram_invmatch(const char *name, const char *invmatch)
128
{
129
const char *value = nvram_get(name);
130
return (value && strcmp(value, invmatch));
131
}
132
133
/*
134
* Set the value of an NVRAM variable. The name and value strings are
135
* copied into private storage. Pointers to previously set values
136
* may become invalid. The new value may be immediately
137
* retrieved but will not be permanently stored until a commit.
138
* @param name name of variable to set
139
* @param value value of variable
140
* @return 0 on success and errno on failure
141
*/
142
extern int nvram_set(const char *name, const char *value);
143
144
/*
145
* Unset an NVRAM variable. Pointers to previously set values
146
* remain valid until a set.
147
* @param name name of variable to unset
148
* @return 0 on success and errno on failure
149
* NOTE: use nvram_commit to commit this change to flash.
150
*/
151
extern int nvram_unset(const char *name);
152
153
/*
154
* Commit NVRAM variables to permanent storage. All pointers to values
155
* may be invalid after a commit.
156
* NVRAM values are undefined after a commit.
157
* @param nvram_corrupt true to corrupt nvram, false otherwise.
158
* @return 0 on success and errno on failure
159
*/
160
extern int nvram_commit_internal(bool nvram_corrupt);
161
162
/*
163
* Commit NVRAM variables to permanent storage. All pointers to values
164
* may be invalid after a commit.
165
* NVRAM values are undefined after a commit.
166
* @return 0 on success and errno on failure
167
*/
168
extern int nvram_commit(void);
169
170
/*
171
* Get all NVRAM variables (format name=value\0 ... \0\0).
172
* @param buf buffer to store variables
173
* @param count size of buffer in bytes
174
* @return 0 on success and errno on failure
175
*/
176
extern int nvram_getall(char *nvram_buf, int count);
177
178
/*
179
* returns the crc value of the nvram
180
* @param nvh nvram header pointer
181
*/
182
uint8 nvram_calc_crc(struct nvram_header * nvh);
183
184
extern int nvram_space;
185
#endif /* _LANGUAGE_ASSEMBLY */
186
187
/* The NVRAM version number stored as an NVRAM variable */
188
#define NVRAM_SOFTWARE_VERSION "1"
189
190
#define NVRAM_MAGIC 0x48534C46 /* 'FLSH' */
191
#define NVRAM_CLEAR_MAGIC 0x0
192
#define NVRAM_INVALID_MAGIC 0xFFFFFFFF
193
#define NVRAM_VERSION 1
194
#define NVRAM_HEADER_SIZE 20
195
/* This definition is for precommit staging, and will be removed */
196
#define NVRAM_SPACE 0x8000
197
/* For CFE builds this gets passed in thru the makefile */
198
#ifndef MAX_NVRAM_SPACE
199
#define MAX_NVRAM_SPACE 0x10000
200
#endif
201
#define DEF_NVRAM_SPACE 0x8000
202
#define ROM_ENVRAM_SPACE 0x1000
203
#define NVRAM_LZMA_MAGIC 0x4c5a4d41 /* 'LZMA' */
204
205
#define NVRAM_MAX_VALUE_LEN 255
206
#define NVRAM_MAX_PARAM_LEN 64
207
208
#define NVRAM_CRC_START_POSITION 9 /* magic, len, crc8 to be skipped */
209
#define NVRAM_CRC_VER_MASK 0xffffff00 /* for crc_ver_init */
210
211
/* Offsets to embedded nvram area */
212
#define NVRAM_START_COMPRESSED 0x400
213
#define NVRAM_START 0x1000
214
215
#define BCM_JUMBO_NVRAM_DELIMIT '\n'
216
#define BCM_JUMBO_START "Broadcom Jumbo Nvram file"
217
218
#if !defined(BCMDONGLEHOST) && !defined(BCMHIGHSDIO) && defined(BCMTRXV2)
219
extern char *_vars;
220
extern uint _varsz;
221
#endif /* !defined(BCMDONGLEHOST) && !defined(BCMHIGHSDIO) && defined(BCMTRXV2) */
222
223
#if (defined(FAILSAFE_UPGRADE) || defined(CONFIG_FAILSAFE_UPGRADE) || \
224
defined(__CONFIG_FAILSAFE_UPGRADE_SUPPORT__))
225
#define IMAGE_SIZE "image_size"
226
#define BOOTPARTITION "bootpartition"
227
#define IMAGE_BOOT BOOTPARTITION
228
#define PARTIALBOOTS "partialboots"
229
#define MAXPARTIALBOOTS "maxpartialboots"
230
#define IMAGE_1ST_FLASH_TRX "flash0.trx"
231
#define IMAGE_1ST_FLASH_OS "flash0.os"
232
#define IMAGE_2ND_FLASH_TRX "flash0.trx2"
233
#define IMAGE_2ND_FLASH_OS "flash0.os2"
234
#define IMAGE_FIRST_OFFSET "image_first_offset"
235
#define IMAGE_SECOND_OFFSET "image_second_offset"
236
#define LINUX_FIRST "linux"
237
#define LINUX_SECOND "linux2"
238
#endif
239
240
#if (defined(DUAL_IMAGE) || defined(CONFIG_DUAL_IMAGE) || \
241
defined(__CONFIG_DUAL_IMAGE_FLASH_SUPPORT__))
242
/* Shared by all: CFE, Linux Kernel, and Ap */
243
#define IMAGE_BOOT "image_boot"
244
#define BOOTPARTITION IMAGE_BOOT
245
/* CFE variables */
246
#define IMAGE_1ST_FLASH_TRX "flash0.trx"
247
#define IMAGE_1ST_FLASH_OS "flash0.os"
248
#define IMAGE_2ND_FLASH_TRX "flash0.trx2"
249
#define IMAGE_2ND_FLASH_OS "flash0.os2"
250
#define IMAGE_SIZE "image_size"
251
252
/* CFE and Linux Kernel shared variables */
253
#define IMAGE_FIRST_OFFSET "image_first_offset"
254
#define IMAGE_SECOND_OFFSET "image_second_offset"
255
256
/* Linux application variables */
257
#define LINUX_FIRST "linux"
258
#define LINUX_SECOND "linux2"
259
#define POLICY_TOGGLE "toggle"
260
#define LINUX_PART_TO_FLASH "linux_to_flash"
261
#define LINUX_FLASH_POLICY "linux_flash_policy"
262
263
#endif /* defined(DUAL_IMAGE||CONFIG_DUAL_IMAGE)||__CONFIG_DUAL_IMAGE_FLASH_SUPPORT__ */
264
265
#endif /* _bcmnvram_h_ */
266
267