source: src/linux/universal/linux-4.9/drivers/mtd/maps/nvram_linux.h @ 31690

Last change on this file since 31690 was 31690, checked in by brainslayer, 4 months ago

increase nvram size for wdr4900

File size: 4.6 KB
Line 
1#ifndef __NVRAM_LINUX__
2#define __NVRAM_LINUX__
3
4//typedef unsigned int  uint;
5typedef unsigned int uint32;
6typedef unsigned short uint16;
7typedef unsigned char uint8;
8#define u32             uint32
9#define u16             uint16
10#define u8              uint8
11#define ulong   uint32
12#define ushort  uint16
13#define uchar   uint8
14
15#define INLINE  __inline__
16#define ltoh32
17#define htol32
18#define bzero(b, len)           memset((b), '\0', (len))
19extern void *MALLOC(size_t size);
20extern void MFREE(void *addr);
21
22extern uint8 crc8(uint8 * pdata, uint nbytes, uint8 crc);
23#define CRC8_INIT_VALUE  0xff   /* Initial CRC8 checksum value */
24#define CRC8_GOOD_VALUE  0x9f   /* Good final CRC8 checksum value */
25
26#ifndef MIN
27#define MIN(a, b)               (((a)<(b))?(a):(b))
28#endif
29
30#ifndef MAX
31#define MAX(a, b)               (((a)>(b))?(a):(b))
32#endif
33
34#define CEIL(x, y)              (((x) + ((y)-1)) / (y))
35#define ROUNDUP(x, y)           ((((ulong)(x)+((y)-1))/(y))*(y))
36#define ISALIGNED(a, x)         (((uint)(a) & ((x)-1)) == 0)
37#define ISPOWEROF2(x)           ((((x)-1)&(x))==0)
38#define OFFSETOF(type, member)  ((uint) &((type *)0)->member)
39#define ARRAYSIZE(a)            (sizeof(a)/sizeof(a[0]))
40
41struct nvram_header {
42        uint32 magic;
43        uint32 len;
44        uint32 crc_ver_init;    /* 0:7 crc, 8:15 ver, 16:27 init, mem. test 28, 29-31 reserved */
45        uint32 config_refresh;  /* 0:15 config, 16:31 refresh */
46        uint32 config_ncdl;     /* ncdl values for memc */
47};
48
49struct nvram_tuple {
50        char *name;
51        char *value;
52        struct nvram_tuple *next;
53};
54
55/*
56 * Initialize NVRAM access. May be unnecessary or undefined on certain
57 * platforms.
58 */
59extern int nvram_init(void *sbh);
60
61/*
62 * Disable NVRAM access. May be unnecessary or undefined on certain
63 * platforms.
64 */
65extern void nvram_exit(void);
66
67/*
68 * Get the value of an NVRAM variable. The pointer returned may be
69 * invalid after a set.
70 * @param       name    name of variable to get
71 * @return      value of variable or NULL if undefined
72 */
73extern char *nvram_get(const char *name);
74
75/*
76 * Get the value of an NVRAM variable.
77 * @param       name    name of variable to get
78 * @return      value of variable or NUL if undefined
79 */
80#define nvram_safe_get(name) (nvram_get(name) ? : "")
81
82/*
83 * Match an NVRAM variable.
84 * @param       name    name of variable to match
85 * @param       match   value to compare against value of variable
86 * @return      TRUE if variable is defined and its value is string equal
87 *              to match or FALSE otherwise
88 */
89static INLINE int nvram_match(char *name, char *match)
90{
91        const char *value = nvram_get(name);
92        return (value && !strcmp(value, match));
93}
94
95/*
96 * Inversely match an NVRAM variable.
97 * @param       name    name of variable to match
98 * @param       match   value to compare against value of variable
99 * @return      TRUE if variable is defined and its value is not string
100 *              equal to invmatch or FALSE otherwise
101 */
102static INLINE int nvram_invmatch(char *name, char *invmatch)
103{
104        const char *value = nvram_get(name);
105        return (value && strcmp(value, invmatch));
106}
107
108/*
109 * Set the value of an NVRAM variable. The name and value strings are
110 * copied into private storage. Pointers to previously set values
111 * may become invalid. The new value may be immediately
112 * retrieved but will not be permanently stored until a commit.
113 * @param       name    name of variable to set
114 * @param       value   value of variable
115 * @return      0 on success and errno on failure
116 */
117extern int nvram_set(const char *name, const char *value);
118
119/*
120 * Unset an NVRAM variable. Pointers to previously set values
121 * remain valid until a set.
122 * @param       name    name of variable to unset
123 * @return      0 on success and errno on failure
124 * NOTE: use nvram_commit to commit this change to flash.
125 */
126extern int nvram_unset(const char *name);
127
128/*
129 * Commit NVRAM variables to permanent storage. All pointers to values
130 * may be invalid after a commit.
131 * NVRAM values are undefined after a commit.
132 * @return      0 on success and errno on failure
133 */
134extern int nvram_commit(void);
135
136/*
137 * Get all NVRAM variables (format name=value\0 ... \0\0).
138 * @param       buf     buffer to store variables
139 * @param       count   size of buffer in bytes
140 * @return      0 on success and errno on failure
141 */
142extern int nvram_getall(char *buf, int count);
143
144#define NVRAM_MAGIC                     0x48534C46      /* 'NVFL' */
145#define NVRAM_VERSION           1
146#define NVRAM_HEADER_SIZE       sizeof(struct nvram_header)
147#if defined(CONFIG_WZR_HP_G300NH) || defined(CONFIG_ARCH_ALPINE) || defined(CONFIG_TL_WDR4900_V1)
148#define NVRAM_SPACE                     0x20000
149#else
150#define NVRAM_SPACE                     0x10000
151#endif
152
153#define NVRAM_CRC_MASK          0x000000ff
154#define NVRAM_CRC_SHIFT         0
155#define NVRAM_VER_MASK          0x0000ff00
156#define NVRAM_VER_SHIFT         8
157#define NVRAM_OPT_MASK          0xffff0000
158#define NVRAM_OPT_SHIFT         16
159
160#define NVRAM_RUNTIME           1
161#define NVRAM_DEFAULT           2
162#define NVRAM_RT_SPACE          NVRAM_SPACE
163#define NVRAM_DF_SPACE          0x1000
164#define NVRAM_DF_OFFS           (0x200 + 0x400)
165
166#endif  /*__NVRAM_LINUX__*/
Note: See TracBrowser for help on using the repository browser.