Simon Glass | bf4229c | 2019-08-01 09:46:40 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* |
| 3 | * Common environment functions |
| 4 | * |
| 5 | * (C) Copyright 2000-2009 |
| 6 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 7 | */ |
| 8 | |
| 9 | #ifndef __ENV_H |
| 10 | #define __ENV_H |
| 11 | |
| 12 | #include <stdbool.h> |
Simon Glass | 313112a | 2019-08-01 09:46:46 -0600 | [diff] [blame] | 13 | #include <linux/types.h> |
Simon Glass | bf4229c | 2019-08-01 09:46:40 -0600 | [diff] [blame] | 14 | |
| 15 | /** |
Simon Glass | 2d85a75 | 2019-08-01 09:46:41 -0600 | [diff] [blame] | 16 | * env_get_id() - Gets a sequence number for the environment |
| 17 | * |
| 18 | * This value increments every time the environment changes, so can be used an |
| 19 | * an indication of this |
| 20 | * |
| 21 | * @return environment ID |
| 22 | */ |
| 23 | int env_get_id(void); |
| 24 | |
| 25 | /** |
Simon Glass | 79fd214 | 2019-08-01 09:46:43 -0600 | [diff] [blame] | 26 | * env_init() - Set up the pre-relocation environment |
| 27 | * |
| 28 | * This locates the environment or uses the default if nothing is available. |
| 29 | * This must be called before env_get() will work. |
| 30 | * |
| 31 | * @return 0 if OK, -ENODEV if no environment drivers are enabled |
| 32 | */ |
| 33 | int env_init(void); |
| 34 | |
| 35 | /** |
Simon Glass | 8fe4093 | 2019-08-01 09:46:44 -0600 | [diff] [blame] | 36 | * env_relocate() - Set up the post-relocation environment |
| 37 | * |
| 38 | * This loads the environment into RAM so that it can be modified. This is |
| 39 | * called after relocation, before the environment is used |
| 40 | */ |
| 41 | void env_relocate(void); |
| 42 | |
| 43 | /** |
Simon Glass | 909ff4d | 2019-08-01 09:46:45 -0600 | [diff] [blame] | 44 | * env_match() - Match a name / name=value pair |
| 45 | * |
| 46 | * This is used prior to relocation for finding envrionment variables |
| 47 | * |
| 48 | * @name: A simple 'name', or a 'name=value' pair. |
| 49 | * @index: The environment index for a 'name2=value2' pair. |
| 50 | * @return index for the value if the names match, else -1. |
| 51 | */ |
| 52 | int env_match(unsigned char *name, int index); |
| 53 | |
| 54 | /** |
Simon Glass | db22961 | 2019-08-01 09:46:42 -0600 | [diff] [blame] | 55 | * env_get_f() - Look up the value of an environment variable (early) |
| 56 | * |
| 57 | * This function is called from env_get() if the environment has not been |
| 58 | * loaded yet (GD_FLG_ENV_READY flag is 0). Some environment locations will |
| 59 | * support reading the value (slowly) and some will not. |
| 60 | * |
| 61 | * @varname: Variable to look up |
| 62 | * @return value of variable, or NULL if not found |
| 63 | */ |
| 64 | int env_get_f(const char *name, char *buf, unsigned int len); |
| 65 | |
| 66 | /** |
Simon Glass | 07dc93c | 2019-08-01 09:46:47 -0600 | [diff] [blame^] | 67 | * env_set_ulong() - set an environment variable to an integer |
| 68 | * |
| 69 | * @varname: Variable to adjust |
| 70 | * @value: Value to set for the variable (will be converted to a string) |
| 71 | * @return 0 if OK, 1 on error |
| 72 | */ |
| 73 | int env_set_ulong(const char *varname, ulong value); |
| 74 | |
| 75 | /** |
Simon Glass | 313112a | 2019-08-01 09:46:46 -0600 | [diff] [blame] | 76 | * env_set_hex() - set an environment variable to a hex value |
| 77 | * |
| 78 | * @varname: Variable to adjust |
| 79 | * @value: Value to set for the variable (will be converted to a hex string) |
| 80 | * @return 0 if OK, 1 on error |
| 81 | */ |
| 82 | int env_set_hex(const char *varname, ulong value); |
| 83 | |
| 84 | /** |
| 85 | * env_set_addr - Set an environment variable to an address in hex |
| 86 | * |
| 87 | * @varname: Environment variable to set |
| 88 | * @addr: Value to set it to |
| 89 | * @return 0 if ok, 1 on error |
| 90 | */ |
| 91 | static inline int env_set_addr(const char *varname, const void *addr) |
| 92 | { |
| 93 | return env_set_hex(varname, (ulong)addr); |
| 94 | } |
| 95 | |
| 96 | /** |
Simon Glass | bf4229c | 2019-08-01 09:46:40 -0600 | [diff] [blame] | 97 | * env_complete() - return an auto-complete for environment variables |
| 98 | * |
| 99 | * @var: partial name to auto-complete |
| 100 | * @maxv: Maximum number of matches to return |
| 101 | * @cmdv: Returns a list of possible matches |
| 102 | * @maxsz: Size of buffer to use for matches |
| 103 | * @buf: Buffer to use for matches |
| 104 | * @dollar_comp: non-zero to wrap each match in ${...} |
| 105 | * @return number of matches found (in @cmdv) |
| 106 | */ |
| 107 | int env_complete(char *var, int maxv, char *cmdv[], int maxsz, char *buf, |
| 108 | bool dollar_comp); |
| 109 | |
| 110 | #endif |