1/*  *********************************************************************
2    *  Broadcom Common Firmware Environment (CFE)
3    *
4    *  Environment helper routines		File: env_subr.h
5    *
6    *  Definitions and prototypes for environment variable subroutines
7    *
8    *  Author:  Mitch Lichtenberg (mpl@broadcom.com)
9    *
10    *********************************************************************
11    *
12    *  Copyright 2000,2001,2002,2003
13    *  Broadcom Corporation. All rights reserved.
14    *
15    *  This software is furnished under license and may be used and
16    *  copied only in accordance with the following terms and
17    *  conditions.  Subject to these conditions, you may download,
18    *  copy, install, use, modify and distribute modified or unmodified
19    *  copies of this software in source and/or binary form.  No title
20    *  or ownership is transferred hereby.
21    *
22    *  1) Any source code used, modified or distributed must reproduce
23    *     and retain this copyright notice and list of conditions
24    *     as they appear in the source file.
25    *
26    *  2) No right is granted to use any trade name, trademark, or
27    *     logo of Broadcom Corporation.  The "Broadcom Corporation"
28    *     name may not be used to endorse or promote products derived
29    *     from this software without the prior written permission of
30    *     Broadcom Corporation.
31    *
32    *  3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
33    *     IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
34    *     WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
35    *     PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
36    *     SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
37    *     PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
38    *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39    *     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
40    *     GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
41    *     BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
42    *     OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
43    *     TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
44    *     THE POSSIBILITY OF SUCH DAMAGE.
45    ********************************************************************* */
46
47
48
49/*  *********************************************************************
50    *  Constants
51    ********************************************************************* */
52
53
54/*
55 * TLV types.  These codes are used in the "type-length-value"
56 * encoding of the items stored in the NVRAM device (flash or EEPROM)
57 *
58 * The layout of the flash/nvram is as follows:
59 *
60 * <type> <length> <data ...> <type> <length> <data ...> <type_end>
61 *
62 * The type code of "ENV_TLV_TYPE_END" marks the end of the list.
63 * The "length" field marks the length of the data section, not
64 * including the type and length fields.
65 *
66 * Environment variables are stored as follows:
67 *
68 * <type_env> <length> <flags> <name> = <value>
69 *
70 * If bit 0 (low bit) is set, the length is an 8-bit value.
71 * If bit 0 (low bit) is clear, the length is a 16-bit value
72 *
73 * Bit 7 set indicates "user" TLVs.  In this case, bit 0 still
74 * indicates the size of the length field.
75 *
76 * Flags are from the constants below:
77 *
78 */
79
80#define ENV_LENGTH_16BITS	0x00	/* for low bit */
81#define ENV_LENGTH_8BITS	0x01
82
83#define ENV_TYPE_USER		0x80
84
85#define ENV_CODE_SYS(n,l) (((n)<<1)|(l))
86#define ENV_CODE_USER(n,l) ((((n)<<1)|(l)) | ENV_TYPE_USER)
87
88/*
89 * The actual TLV types we support
90 */
91
92#define ENV_TLV_TYPE_END	0x00
93#define ENV_TLV_TYPE_ENV	ENV_CODE_SYS(0,ENV_LENGTH_8BITS)
94
95/*
96 * Environment variable flags
97 */
98
99#define ENV_FLG_NORMAL		0x00	/* normal read/write */
100#define ENV_FLG_BUILTIN		0x01	/* builtin - not stored in flash */
101#define ENV_FLG_READONLY	0x02	/* read-only - cannot be changed */
102
103#define ENV_FLG_MASK		0xFF	/* mask of attributes we keep */
104#define ENV_FLG_ADMIN		0x100	/* lets us internally override permissions */
105
106/*  *********************************************************************
107    *  Prototypes
108    ********************************************************************* */
109
110int env_delenv(const char *name);
111char *env_getenv(const char *name);
112int env_setenv(const char *name,char *value,int flags);
113int env_load(void);
114int env_save(void);
115int env_enum(int idx,char *name,int *namelen,char *val,int *vallen);
116int env_envtype(const char *name);
117
118