Simon Glass | af95f20 | 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> |
| 13 | |
| 14 | /** |
Simon Glass | f1f0ae6 | 2019-08-01 09:46:41 -0600 | [diff] [blame] | 15 | * env_get_id() - Gets a sequence number for the environment |
| 16 | * |
| 17 | * This value increments every time the environment changes, so can be used an |
| 18 | * an indication of this |
| 19 | * |
| 20 | * @return environment ID |
| 21 | */ |
| 22 | int env_get_id(void); |
| 23 | |
| 24 | /** |
Simon Glass | 4bfd1f5 | 2019-08-01 09:46:43 -0600 | [diff] [blame] | 25 | * env_init() - Set up the pre-relocation environment |
| 26 | * |
| 27 | * This locates the environment or uses the default if nothing is available. |
| 28 | * This must be called before env_get() will work. |
| 29 | * |
| 30 | * @return 0 if OK, -ENODEV if no environment drivers are enabled |
| 31 | */ |
| 32 | int env_init(void); |
| 33 | |
| 34 | /** |
Simon Glass | 3f989e7b | 2019-08-01 09:46:44 -0600 | [diff] [blame] | 35 | * env_relocate() - Set up the post-relocation environment |
| 36 | * |
| 37 | * This loads the environment into RAM so that it can be modified. This is |
| 38 | * called after relocation, before the environment is used |
| 39 | */ |
| 40 | void env_relocate(void); |
| 41 | |
| 42 | /** |
Simon Glass | b9ca02c | 2019-08-01 09:46:45 -0600 | [diff] [blame^] | 43 | * env_match() - Match a name / name=value pair |
| 44 | * |
| 45 | * This is used prior to relocation for finding envrionment variables |
| 46 | * |
| 47 | * @name: A simple 'name', or a 'name=value' pair. |
| 48 | * @index: The environment index for a 'name2=value2' pair. |
| 49 | * @return index for the value if the names match, else -1. |
| 50 | */ |
| 51 | int env_match(unsigned char *name, int index); |
| 52 | |
| 53 | /** |
Simon Glass | 3a7d557 | 2019-08-01 09:46:42 -0600 | [diff] [blame] | 54 | * env_get_f() - Look up the value of an environment variable (early) |
| 55 | * |
| 56 | * This function is called from env_get() if the environment has not been |
| 57 | * loaded yet (GD_FLG_ENV_READY flag is 0). Some environment locations will |
| 58 | * support reading the value (slowly) and some will not. |
| 59 | * |
| 60 | * @varname: Variable to look up |
| 61 | * @return value of variable, or NULL if not found |
| 62 | */ |
| 63 | int env_get_f(const char *name, char *buf, unsigned int len); |
| 64 | |
| 65 | /** |
Simon Glass | af95f20 | 2019-08-01 09:46:40 -0600 | [diff] [blame] | 66 | * env_complete() - return an auto-complete for environment variables |
| 67 | * |
| 68 | * @var: partial name to auto-complete |
| 69 | * @maxv: Maximum number of matches to return |
| 70 | * @cmdv: Returns a list of possible matches |
| 71 | * @maxsz: Size of buffer to use for matches |
| 72 | * @buf: Buffer to use for matches |
| 73 | * @dollar_comp: non-zero to wrap each match in ${...} |
| 74 | * @return number of matches found (in @cmdv) |
| 75 | */ |
| 76 | int env_complete(char *var, int maxv, char *cmdv[], int maxsz, char *buf, |
| 77 | bool dollar_comp); |
| 78 | |
| 79 | #endif |