blob: d785f87cdcbe11f342a24206b6dc2c0bc74a2d16 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Joe Hershberger71497d02012-12-11 22:16:31 -06002/*
3 * (C) Copyright 2012
4 * Joe Hershberger, National Instruments, joe.hershberger@ni.com
Joe Hershberger71497d02012-12-11 22:16:31 -06005 */
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,
Jan Kiszka59b328d2023-02-03 13:22:52 +010015#ifdef CONFIG_NET
Joe Hershberger71497d02012-12-11 22:16:31 -060016 env_flags_vartype_ipaddr,
17 env_flags_vartype_macaddr,
18#endif
19 env_flags_vartype_end
20};
21
Joe Hershberger6fe26c92012-12-11 22:16:34 -060022enum env_flags_varaccess {
23 env_flags_varaccess_any,
24 env_flags_varaccess_readonly,
25 env_flags_varaccess_writeonce,
26 env_flags_varaccess_changedefault,
Marek Vasut803549f2020-07-07 20:51:39 +020027#ifdef CONFIG_ENV_WRITEABLE_LIST
28 env_flags_varaccess_writeable,
29#endif
Joe Hershberger6fe26c92012-12-11 22:16:34 -060030 env_flags_varaccess_end
31};
32
Joe Hershberger71497d02012-12-11 22:16:31 -060033#define ENV_FLAGS_VAR ".flags"
34#define ENV_FLAGS_ATTR_MAX_LEN 2
35#define ENV_FLAGS_VARTYPE_LOC 0
Joe Hershberger6fe26c92012-12-11 22:16:34 -060036#define ENV_FLAGS_VARACCESS_LOC 1
Joe Hershberger71497d02012-12-11 22:16:31 -060037
Tom Rini0297e5f2022-12-04 10:03:40 -050038#ifndef CFG_ENV_FLAGS_LIST_STATIC
39#define CFG_ENV_FLAGS_LIST_STATIC ""
Joe Hershberger71497d02012-12-11 22:16:31 -060040#endif
41
Heinrich Schuchardtfe04d062019-09-02 10:10:34 +020042#ifdef CONFIG_NET
Joe Hershbergere84ca292015-05-20 14:27:22 -050043#ifdef CONFIG_REGEX
Simon Goldschmidt7da02292018-11-22 17:06:39 +010044#define ETHADDR_WILDCARD "\\d*"
Joe Hershbergere84ca292015-05-20 14:27:22 -050045#else
46#define ETHADDR_WILDCARD
47#endif
Joe Hershberger2289ec12012-12-11 22:16:37 -060048#ifdef CONFIG_ENV_OVERWRITE
Joe Hershbergere84ca292015-05-20 14:27:22 -050049#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:ma,"
Joe Hershberger2289ec12012-12-11 22:16:37 -060050#else
51#ifdef CONFIG_OVERWRITE_ETHADDR_ONCE
Joe Hershbergere84ca292015-05-20 14:27:22 -050052#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mc,"
Joe Hershberger2289ec12012-12-11 22:16:37 -060053#else
Joe Hershbergere84ca292015-05-20 14:27:22 -050054#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mo,"
Joe Hershberger2289ec12012-12-11 22:16:37 -060055#endif
56#endif
Joe Hershbergerd26195e72015-05-20 14:27:24 -050057#define NET_FLAGS \
58 "ipaddr:i," \
59 "gatewayip:i," \
60 "netmask:i," \
61 "serverip:i," \
Stefan Agner18c067f2016-04-13 16:38:01 -070062 "nvlan:d," \
63 "vlan:d," \
Joe Hershbergerd26195e72015-05-20 14:27:24 -050064 "dnsip:i,"
Joe Hershberger2289ec12012-12-11 22:16:37 -060065#else
Joe Hershbergerd26195e72015-05-20 14:27:24 -050066#define ETHADDR_FLAGS
67#define NET_FLAGS
Joe Hershberger2289ec12012-12-11 22:16:37 -060068#endif
69
Viacheslav Mitrofanovdf264cf2022-12-02 12:18:00 +030070#ifdef CONFIG_IPV6
71#define NET6_FLAGS \
72 "ip6addr:s," \
73 "serverip6:s," \
Sean Edmond65815e72023-02-15 20:38:36 -080074 "gatewayip6:s,"
Viacheslav Mitrofanovdf264cf2022-12-02 12:18:00 +030075#else
76#define NET6_FLAGS
77#endif
78
Joe Hershberger2289ec12012-12-11 22:16:37 -060079#ifndef CONFIG_ENV_OVERWRITE
80#define SERIAL_FLAGS "serial#:so,"
81#else
82#define SERIAL_FLAGS ""
83#endif
84
Joe Hershberger71497d02012-12-11 22:16:31 -060085#define ENV_FLAGS_LIST_STATIC \
Joe Hershberger2289ec12012-12-11 22:16:37 -060086 ETHADDR_FLAGS \
Joe Hershbergerd26195e72015-05-20 14:27:24 -050087 NET_FLAGS \
Viacheslav Mitrofanovdf264cf2022-12-02 12:18:00 +030088 NET6_FLAGS \
Joe Hershberger2289ec12012-12-11 22:16:37 -060089 SERIAL_FLAGS \
Tom Rini0297e5f2022-12-04 10:03:40 -050090 CFG_ENV_FLAGS_LIST_STATIC
Joe Hershberger71497d02012-12-11 22:16:31 -060091
Joe Hershbergera2d62b72012-12-11 22:16:33 -060092#ifdef CONFIG_CMD_ENV_FLAGS
93/*
94 * Print the whole list of available type flags.
95 */
96void env_flags_print_vartypes(void);
97/*
Joe Hershberger6fe26c92012-12-11 22:16:34 -060098 * Print the whole list of available access flags.
99 */
100void env_flags_print_varaccess(void);
101/*
Joe Hershbergera2d62b72012-12-11 22:16:33 -0600102 * Return the name of the type.
103 */
104const char *env_flags_get_vartype_name(enum env_flags_vartype type);
Joe Hershberger6fe26c92012-12-11 22:16:34 -0600105/*
106 * Return the name of the access.
107 */
108const char *env_flags_get_varaccess_name(enum env_flags_varaccess access);
Joe Hershbergera2d62b72012-12-11 22:16:33 -0600109#endif
110
Joe Hershberger71497d02012-12-11 22:16:31 -0600111/*
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);
Joe Hershberger6fe26c92012-12-11 22:16:34 -0600115/*
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);
Joe Hershberger71497d02012-12-11 22:16:31 -0600123
Jan Kiszka59b328d2023-02-03 13:22:52 +0100124#ifdef CONFIG_NET
Codrin Ciubotariu265c0d32015-09-09 18:00:51 +0300125/*
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
Joe Hershbergerdd7750a2012-12-11 22:16:32 -0600131#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);
136/*
Joe Hershberger6fe26c92012-12-11 22:16:34 -0600137 * Look up the access of a variable directly from the .flags var.
138 */
139enum env_flags_varaccess env_flags_get_access(const char *name);
140/*
Joe Hershbergerdd7750a2012-12-11 22:16:32 -0600141 * 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);
145/*
Joe Hershberger6fe26c92012-12-11 22:16:34 -0600146 * 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);
155/*
Joe Hershbergerdd7750a2012-12-11 22:16:32 -0600156 * Validate the parameters passed to "env set" for type compliance
157 */
Andreas Fenkart4e336ee2015-12-09 13:13:21 +0100158int env_flags_validate_env_set_params(char *name, char *const val[], int count);
Joe Hershbergerdd7750a2012-12-11 22:16:32 -0600159
160#else /* !USE_HOSTCC */
161
Simon Glass5e6201b2019-08-01 09:46:51 -0600162#include <env.h>
Joe Hershberger71497d02012-12-11 22:16:31 -0600163#include <search.h>
164
165/*
166 * When adding a variable to the environment, initialize the flags for that
167 * variable.
168 */
Simon Glass1a236862019-08-02 09:44:18 -0600169void env_flags_init(struct env_entry *var_entry);
Joe Hershberger71497d02012-12-11 22:16:31 -0600170
171/*
172 * Validate the newval for to conform with the requirements defined by its flags
173 */
Simon Glass1a236862019-08-02 09:44:18 -0600174int env_flags_validate(const struct env_entry *item, const char *newval,
175 enum env_op op, int flag);
Joe Hershberger71497d02012-12-11 22:16:31 -0600176
Joe Hershberger6fe26c92012-12-11 22:16:34 -0600177#endif /* USE_HOSTCC */
178
Joe Hershberger71497d02012-12-11 22:16:31 -0600179/*
180 * These are the binary flags used in the environment entry->flags variable to
181 * decribe properties of veriables in the table
182 */
Joe Hershberger6fe26c92012-12-11 22:16:34 -0600183#define ENV_FLAGS_VARTYPE_BIN_MASK 0x00000007
Joe Hershberger71497d02012-12-11 22:16:31 -0600184/* The actual variable type values use the enum value (within the mask) */
Joe Hershberger6fe26c92012-12-11 22:16:34 -0600185#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
Marek Vasut803549f2020-07-07 20:51:39 +0200189#define ENV_FLAGS_VARACCESS_WRITEABLE 0x00000080
190#define ENV_FLAGS_VARACCESS_BIN_MASK 0x000000f8
Joe Hershbergerdd7750a2012-12-11 22:16:32 -0600191
Joe Hershberger71497d02012-12-11 22:16:31 -0600192#endif /* __ENV_FLAGS_H__ */