2 * (C) Copyright 2002-2008
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
12 * Programs using the library must check which API is available,
13 * that varies depending on the U-Boot version.
14 * This can be changed in future
16 #define FW_ENV_API_VERSION 1
22 int aes_flag; /* Is AES encryption used? */
23 uint8_t aes_key[AES_KEY_LENGTH];
27 int parse_aes_key(char *key, uint8_t *bin_key);
30 * fw_printenv() - print one or several environment variables
32 * @argc: number of variables names to be printed, prints all if 0
33 * @argv: array of variable names to be printed, if argc != 0
34 * @value_only: do not repeat the variable name, print the bare value,
35 * only one variable allowed with this option, argc must be 1
36 * @opts: encryption key, configuration file, defaults are used if NULL
39 * Uses fw_env_open, fw_getenv
42 * 0 on success, -1 on failure (modifies errno)
44 int fw_printenv(int argc, char *argv[], int value_only, struct env_opts *opts);
47 * fw_env_set() - adds or removes one variable to the environment
49 * @argc: number of strings in argv, argv[0] is variable name,
50 * argc==1 means erase variable, argc > 1 means add a variable
51 * @argv: argv[0] is variable name, argv[1..argc-1] are concatenated separated
52 * by single blank and set as the new value of the variable
53 * @opts: how to retrieve environment from flash, defaults are used if NULL
56 * Uses fw_env_open, fw_env_write, fw_env_flush
59 * 0 on success, -1 on failure (modifies errno)
62 * EROFS - some variables ("ethaddr", "serial#") cannot be modified
64 int fw_env_set(int argc, char *argv[], struct env_opts *opts);
67 * fw_parse_script() - adds or removes multiple variables with a batch script
69 * @fname: batch script file name
70 * @opts: encryption key, configuration file, defaults are used if NULL
73 * Uses fw_env_open, fw_env_write, fw_env_flush
76 * 0 success, -1 on failure (modifies errno)
80 * key [ [space]+ value]
82 * lines starting with '#' treated as comment
84 * A variable without value will be deleted. Any number of spaces are allowed
85 * between key and value. The value starts with the first non-space character
86 * and ends with newline. No comments allowed on these lines. Spaces inside
87 * the value are preserved verbatim.
95 * foo spaces are copied verbatim
97 * # delete variable bar
101 int fw_parse_script(char *fname, struct env_opts *opts);
105 * fw_env_open() - read enviroment from flash into RAM cache
107 * @opts: encryption key, configuration file, defaults are used if NULL
110 * 0 on success, -1 on failure (modifies errno)
112 int fw_env_open(struct env_opts *opts);
115 * fw_getenv() - lookup variable in the RAM cache
117 * @name: variable to be searched
119 * pointer to start of value, NULL if not found
121 char *fw_getenv(char *name);
124 * fw_env_write() - modify a variable held in the RAM cache
127 * @value: delete variable if NULL, otherwise create or overwrite the variable
129 * This is called in sequence to update the environment in RAM without updating
130 * the copy in flash after each set
133 * 0 on success, -1 on failure (modifies errno)
136 * EROFS - some variables ("ethaddr", "serial#") cannot be modified
138 int fw_env_write(char *name, char *value);
141 * fw_env_flush - write the environment from RAM cache back to flash
143 * @opts: encryption key, configuration file, defaults are used if NULL
146 * 0 on success, -1 on failure (modifies errno)
148 int fw_env_flush(struct env_opts *opts);
151 * fw_env_close - free allocated structure and close env
153 * @opts: encryption key, configuration file, defaults are used if NULL
156 * 0 on success, -1 on failure (modifies errno)
158 int fw_env_close(struct env_opts *opts);
162 * fw_env_version - return the current version of the library
165 * version string of the library
167 char *fw_env_version(void);
169 unsigned long crc32(unsigned long, const unsigned char *, unsigned);