1 /* SPDX-License-Identifier: GPL-2.0+ */
7 #ifndef __ENV_FLAGS_H__
8 #define __ENV_FLAGS_H__
12 enum env_flags_vartype {
13 env_flags_vartype_string,
14 env_flags_vartype_decimal,
15 env_flags_vartype_hex,
16 env_flags_vartype_bool,
18 env_flags_vartype_ipaddr,
19 env_flags_vartype_macaddr,
24 enum env_flags_varaccess {
25 env_flags_varaccess_any,
26 env_flags_varaccess_readonly,
27 env_flags_varaccess_writeonce,
28 env_flags_varaccess_changedefault,
29 #ifdef CONFIG_ENV_WRITEABLE_LIST
30 env_flags_varaccess_writeable,
32 env_flags_varaccess_end
35 #define ENV_FLAGS_VAR ".flags"
36 #define ENV_FLAGS_ATTR_MAX_LEN 2
37 #define ENV_FLAGS_VARTYPE_LOC 0
38 #define ENV_FLAGS_VARACCESS_LOC 1
40 #ifndef CFG_ENV_FLAGS_LIST_STATIC
41 #define CFG_ENV_FLAGS_LIST_STATIC ""
46 #define ETHADDR_WILDCARD "\\d*"
48 #define ETHADDR_WILDCARD
50 #ifdef CONFIG_ENV_OVERWRITE
51 #define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:ma,"
53 #ifdef CONFIG_OVERWRITE_ETHADDR_ONCE
54 #define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mc,"
56 #define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mo,"
81 #ifndef CONFIG_ENV_OVERWRITE
82 #define SERIAL_FLAGS "serial#:so,"
84 #define SERIAL_FLAGS ""
87 #define ENV_FLAGS_LIST_STATIC \
92 CFG_ENV_FLAGS_LIST_STATIC
94 #ifdef CONFIG_CMD_ENV_FLAGS
96 * Print the whole list of available type flags.
98 void env_flags_print_vartypes(void);
100 * Print the whole list of available access flags.
102 void env_flags_print_varaccess(void);
104 * Return the name of the type.
106 const char *env_flags_get_vartype_name(enum env_flags_vartype type);
108 * Return the name of the access.
110 const char *env_flags_get_varaccess_name(enum env_flags_varaccess access);
114 * Parse the flags string from a .flags attribute list into the vartype enum.
116 enum env_flags_vartype env_flags_parse_vartype(const char *flags);
118 * Parse the flags string from a .flags attribute list into the varaccess enum.
120 enum env_flags_varaccess env_flags_parse_varaccess(const char *flags);
122 * Parse the binary flags from a hash table entry into the varaccess enum.
124 enum env_flags_varaccess env_flags_parse_varaccess_from_binflags(int binflags);
128 * Check if a string has the format of an Ethernet MAC address
130 int eth_validate_ethaddr_str(const char *addr);
135 * Look up the type of a variable directly from the .flags var.
137 enum env_flags_vartype env_flags_get_type(const char *name);
139 * Look up the access of a variable directly from the .flags var.
141 enum env_flags_varaccess env_flags_get_access(const char *name);
143 * Validate the newval for its type to conform with the requirements defined by
144 * its flags (directly looked at the .flags var).
146 int env_flags_validate_type(const char *name, const char *newval);
148 * Validate the newval for its access to conform with the requirements defined
149 * by its flags (directly looked at the .flags var).
151 int env_flags_validate_access(const char *name, int check_mask);
153 * Validate that the proposed access to variable "name" is valid according to
154 * the defined flags for that variable, if any.
156 int env_flags_validate_varaccess(const char *name, int check_mask);
158 * Validate the parameters passed to "env set" for type compliance
160 int env_flags_validate_env_set_params(char *name, char *const val[], int count);
162 #else /* !USE_HOSTCC */
168 * When adding a variable to the environment, initialize the flags for that
171 void env_flags_init(struct env_entry *var_entry);
174 * Validate the newval for to conform with the requirements defined by its flags
176 int env_flags_validate(const struct env_entry *item, const char *newval,
177 enum env_op op, int flag);
179 #endif /* USE_HOSTCC */
182 * These are the binary flags used in the environment entry->flags variable to
183 * decribe properties of veriables in the table
185 #define ENV_FLAGS_VARTYPE_BIN_MASK 0x00000007
186 /* The actual variable type values use the enum value (within the mask) */
187 #define ENV_FLAGS_VARACCESS_PREVENT_DELETE 0x00000008
188 #define ENV_FLAGS_VARACCESS_PREVENT_CREATE 0x00000010
189 #define ENV_FLAGS_VARACCESS_PREVENT_OVERWR 0x00000020
190 #define ENV_FLAGS_VARACCESS_PREVENT_NONDEF_OVERWR 0x00000040
191 #define ENV_FLAGS_VARACCESS_WRITEABLE 0x00000080
192 #define ENV_FLAGS_VARACCESS_BIN_MASK 0x000000f8
194 #endif /* __ENV_FLAGS_H__ */