]> git.ipfire.org Git - thirdparty/u-boot.git/blame - include/env_flags.h
phycore_imx8mp: Move environment from include/config to board
[thirdparty/u-boot.git] / include / env_flags.h
CommitLineData
83d290c5 1/* SPDX-License-Identifier: GPL-2.0+ */
2598090b
JH
2/*
3 * (C) Copyright 2012
4 * Joe Hershberger, National Instruments, joe.hershberger@ni.com
2598090b
JH
5 */
6
7#ifndef __ENV_FLAGS_H__
8#define __ENV_FLAGS_H__
9
10enum env_flags_vartype {
11 env_flags_vartype_string,
12 env_flags_vartype_decimal,
13 env_flags_vartype_hex,
14 env_flags_vartype_bool,
906bad3c 15#ifdef CONFIG_NET
2598090b
JH
16 env_flags_vartype_ipaddr,
17 env_flags_vartype_macaddr,
18#endif
19 env_flags_vartype_end
20};
21
267541f7
JH
22enum env_flags_varaccess {
23 env_flags_varaccess_any,
24 env_flags_varaccess_readonly,
25 env_flags_varaccess_writeonce,
26 env_flags_varaccess_changedefault,
d045cbac
MV
27#ifdef CONFIG_ENV_WRITEABLE_LIST
28 env_flags_varaccess_writeable,
29#endif
267541f7
JH
30 env_flags_varaccess_end
31};
32
2598090b
JH
33#define ENV_FLAGS_VAR ".flags"
34#define ENV_FLAGS_ATTR_MAX_LEN 2
35#define ENV_FLAGS_VARTYPE_LOC 0
267541f7 36#define ENV_FLAGS_VARACCESS_LOC 1
2598090b 37
acf29d8c
TR
38#ifndef CFG_ENV_FLAGS_LIST_STATIC
39#define CFG_ENV_FLAGS_LIST_STATIC ""
2598090b
JH
40#endif
41
cccc05ee 42#ifdef CONFIG_NET
73c2bbee 43#ifdef CONFIG_REGEX
be09f5bc 44#define ETHADDR_WILDCARD "\\d*"
73c2bbee
JH
45#else
46#define ETHADDR_WILDCARD
47#endif
1d6cd0a3 48#ifdef CONFIG_ENV_OVERWRITE
73c2bbee 49#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:ma,"
1d6cd0a3
JH
50#else
51#ifdef CONFIG_OVERWRITE_ETHADDR_ONCE
73c2bbee 52#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mc,"
1d6cd0a3 53#else
73c2bbee 54#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mo,"
1d6cd0a3
JH
55#endif
56#endif
c0a93440
JH
57#define NET_FLAGS \
58 "ipaddr:i," \
59 "gatewayip:i," \
60 "netmask:i," \
61 "serverip:i," \
0299cee5
SA
62 "nvlan:d," \
63 "vlan:d," \
c0a93440 64 "dnsip:i,"
1d6cd0a3 65#else
c0a93440
JH
66#define ETHADDR_FLAGS
67#define NET_FLAGS
1d6cd0a3
JH
68#endif
69
1dfa4ef1
VM
70#ifdef CONFIG_IPV6
71#define NET6_FLAGS \
72 "ip6addr:s," \
73 "serverip6:s," \
5e541c48 74 "gatewayip6:s,"
1dfa4ef1
VM
75#else
76#define NET6_FLAGS
77#endif
78
1d6cd0a3
JH
79#ifndef CONFIG_ENV_OVERWRITE
80#define SERIAL_FLAGS "serial#:so,"
81#else
82#define SERIAL_FLAGS ""
83#endif
84
2598090b 85#define ENV_FLAGS_LIST_STATIC \
1d6cd0a3 86 ETHADDR_FLAGS \
c0a93440 87 NET_FLAGS \
1dfa4ef1 88 NET6_FLAGS \
1d6cd0a3 89 SERIAL_FLAGS \
acf29d8c 90 CFG_ENV_FLAGS_LIST_STATIC
2598090b 91
fffad71b
JH
92#ifdef CONFIG_CMD_ENV_FLAGS
93/*
94 * Print the whole list of available type flags.
95 */
96void env_flags_print_vartypes(void);
267541f7
JH
97/*
98 * Print the whole list of available access flags.
99 */
100void env_flags_print_varaccess(void);
fffad71b
JH
101/*
102 * Return the name of the type.
103 */
104const char *env_flags_get_vartype_name(enum env_flags_vartype type);
267541f7
JH
105/*
106 * Return the name of the access.
107 */
108const char *env_flags_get_varaccess_name(enum env_flags_varaccess access);
fffad71b
JH
109#endif
110
2598090b
JH
111/*
112 * Parse the flags string from a .flags attribute list into the vartype enum.
113 */
114enum env_flags_vartype env_flags_parse_vartype(const char *flags);
267541f7
JH
115/*
116 * Parse the flags string from a .flags attribute list into the varaccess enum.
117 */
118enum env_flags_varaccess env_flags_parse_varaccess(const char *flags);
119/*
120 * Parse the binary flags from a hash table entry into the varaccess enum.
121 */
122enum env_flags_varaccess env_flags_parse_varaccess_from_binflags(int binflags);
2598090b 123
906bad3c 124#ifdef CONFIG_NET
0118e83b
CC
125/*
126 * Check if a string has the format of an Ethernet MAC address
127 */
128int eth_validate_ethaddr_str(const char *addr);
129#endif
130
30fd4fad
JH
131#ifdef USE_HOSTCC
132/*
133 * Look up the type of a variable directly from the .flags var.
134 */
135enum env_flags_vartype env_flags_get_type(const char *name);
267541f7
JH
136/*
137 * Look up the access of a variable directly from the .flags var.
138 */
139enum env_flags_varaccess env_flags_get_access(const char *name);
30fd4fad
JH
140/*
141 * Validate the newval for its type to conform with the requirements defined by
142 * its flags (directly looked at the .flags var).
143 */
144int env_flags_validate_type(const char *name, const char *newval);
267541f7
JH
145/*
146 * Validate the newval for its access to conform with the requirements defined
147 * by its flags (directly looked at the .flags var).
148 */
149int env_flags_validate_access(const char *name, int check_mask);
150/*
151 * Validate that the proposed access to variable "name" is valid according to
152 * the defined flags for that variable, if any.
153 */
154int env_flags_validate_varaccess(const char *name, int check_mask);
30fd4fad
JH
155/*
156 * Validate the parameters passed to "env set" for type compliance
157 */
167f5258 158int env_flags_validate_env_set_params(char *name, char *const val[], int count);
30fd4fad
JH
159
160#else /* !USE_HOSTCC */
161
9fb625ce 162#include <env.h>
2598090b
JH
163#include <search.h>
164
165/*
166 * When adding a variable to the environment, initialize the flags for that
167 * variable.
168 */
dd2408ca 169void env_flags_init(struct env_entry *var_entry);
2598090b
JH
170
171/*
172 * Validate the newval for to conform with the requirements defined by its flags
173 */
dd2408ca
SG
174int env_flags_validate(const struct env_entry *item, const char *newval,
175 enum env_op op, int flag);
2598090b 176
267541f7
JH
177#endif /* USE_HOSTCC */
178
2598090b
JH
179/*
180 * These are the binary flags used in the environment entry->flags variable to
181 * decribe properties of veriables in the table
182 */
267541f7 183#define ENV_FLAGS_VARTYPE_BIN_MASK 0x00000007
2598090b 184/* The actual variable type values use the enum value (within the mask) */
267541f7
JH
185#define ENV_FLAGS_VARACCESS_PREVENT_DELETE 0x00000008
186#define ENV_FLAGS_VARACCESS_PREVENT_CREATE 0x00000010
187#define ENV_FLAGS_VARACCESS_PREVENT_OVERWR 0x00000020
188#define ENV_FLAGS_VARACCESS_PREVENT_NONDEF_OVERWR 0x00000040
d045cbac
MV
189#define ENV_FLAGS_VARACCESS_WRITEABLE 0x00000080
190#define ENV_FLAGS_VARACCESS_BIN_MASK 0x000000f8
30fd4fad 191
2598090b 192#endif /* __ENV_FLAGS_H__ */