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