source: freewrt/package/base-files/include/bcmnvram.h@ db5651c

freewrt_1_0 freewrt_2_0
Last change on this file since db5651c was db5651c, checked in by Waldemar Brodkorb <wbx@…>, 19 years ago

merge wbx-target-cleanup to trunk.

  • mk directory for some top level makefiles (build.mk,vars.mk)
  • add a separate configfs partition to all models, 128 kb big
  • add model and platform specific startup files and kernel configs
  • delete target/linux/package, add all addon kernel packages to packages
  • simplify target/linux/brcm-2.4/Makefile, abstraction to mk/ comes later
  • add target/image directory, place where the different images are created
  • default off for all extra packages, be sure that you enable all packages you need to get a dsl-capable router. snapshots will be created by a specific config which contains all needed stuff (iptables, pppoe, pptp, haserl, webif)

git-svn-id: svn://www.freewrt.org/trunk/freewrt@588 afb5a338-a214-0410-bd46-81f09a774fd1

  • Property mode set to 100644
File size: 4.1 KB
Line 
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 * $Id: bcmnvram.h 1517 2005-07-21 11:45:36Z nbd $
13 */
14
15#ifndef _bcmnvram_h_
16#define _bcmnvram_h_
17
18#ifndef _LANGUAGE_ASSEMBLY
19
20#include <typedefs.h>
21
22struct nvram_header {
23 uint32 magic;
24 uint32 len;
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 */
28};
29
30struct nvram_tuple {
31 char *name;
32 char *value;
33 struct nvram_tuple *next;
34};
35
36/*
37 * Initialize NVRAM access. May be unnecessary or undefined on certain
38 * platforms.
39 */
40extern int nvram_init(void *sbh);
41
42/*
43 * Disable NVRAM access. May be unnecessary or undefined on certain
44 * platforms.
45 */
46extern void nvram_exit(void);
47
48/*
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
53 */
54extern char * nvram_get(const char *name);
55
56/*
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
60 */
61#define nvram_safe_get(name) (nvram_get(name) ? : "")
62
63#define nvram_safe_unset(name) ({ \
64 if(nvram_get(name)) \
65 nvram_unset(name); \
66})
67
68#define nvram_safe_set(name, value) ({ \
69 if(!nvram_get(name) || strcmp(nvram_get(name), value)) \
70 nvram_set(name, value); \
71})
72
73/*
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
79 */
80static INLINE int
81nvram_match(char *name, char *match) {
82 const char *value = nvram_get(name);
83 return (value && !strcmp(value, match));
84}
85
86/*
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
92 */
93static INLINE int
94nvram_invmatch(char *name, char *invmatch) {
95 const char *value = nvram_get(name);
96 return (value && strcmp(value, invmatch));
97}
98
99/*
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
107 */
108extern int nvram_set(const char *name, const char *value);
109
110/*
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.
116 */
117extern int nvram_unset(const char *name);
118
119/*
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
124 */
125extern int nvram_commit(void);
126
127/*
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
132 */
133extern int nvram_getall(char *buf, int count);
134
135extern int file2nvram(char *filename, char *varname);
136extern int nvram2file(char *varname, char *filename);
137
138#endif /* _LANGUAGE_ASSEMBLY */
139
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 */
147
148#endif /* _bcmnvram_h_ */
Note: See TracBrowser for help on using the repository browser.