1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * (C) Copyright 2002-2008
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
11 * Programs using the library must check which API is available,
12 * that varies depending on the U-Boot version.
13 * This can be changed in future
15 #define FW_ENV_API_VERSION 1
25 * fw_printenv() - print one or several environment variables
27 * @argc: number of variables names to be printed, prints all if 0
28 * @argv: array of variable names to be printed, if argc != 0
29 * @value_only: do not repeat the variable name, print the bare value,
30 * only one variable allowed with this option, argc must be 1
31 * @opts: encryption key, configuration file, defaults are used if NULL
34 * Uses fw_env_open, fw_getenv
37 * 0 on success, -1 on failure (modifies errno)
39 int fw_printenv(int argc, char *argv[], int value_only, struct env_opts *opts);
42 * fw_env_set() - adds or removes one variable to the environment
44 * @argc: number of strings in argv, argv[0] is variable name,
45 * argc==1 means erase variable, argc > 1 means add a variable
46 * @argv: argv[0] is variable name, argv[1..argc-1] are concatenated separated
47 * by single blank and set as the new value of the variable
48 * @opts: how to retrieve environment from flash, defaults are used if NULL
51 * Uses fw_env_open, fw_env_write, fw_env_flush
54 * 0 on success, -1 on failure (modifies errno)
57 * EROFS - some variables ("ethaddr", "serial#") cannot be modified
59 int fw_env_set(int argc, char *argv[], struct env_opts *opts);
62 * fw_parse_script() - adds or removes multiple variables with a batch script
64 * @fname: batch script file name
65 * @opts: encryption key, configuration file, defaults are used if NULL
68 * Uses fw_env_open, fw_env_write, fw_env_flush
71 * 0 success, -1 on failure (modifies errno)
75 * key [ [space]+ value]
77 * lines starting with '#' treated as comment
79 * A variable without value will be deleted. Any number of spaces are allowed
80 * between key and value. The value starts with the first non-space character
81 * and ends with newline. No comments allowed on these lines. Spaces inside
82 * the value are preserved verbatim.
90 * foo spaces are copied verbatim
92 * # delete variable bar
96 int fw_parse_script(char *fname, struct env_opts *opts);
100 * fw_env_open() - read enviroment from flash into RAM cache
102 * @opts: encryption key, configuration file, defaults are used if NULL
105 * 0 on success, -1 on failure (modifies errno)
107 int fw_env_open(struct env_opts *opts);
110 * fw_getenv() - lookup variable in the RAM cache
112 * @name: variable to be searched
114 * pointer to start of value, NULL if not found
116 char *fw_getenv(char *name);
119 * fw_env_write() - modify a variable held in the RAM cache
122 * @value: delete variable if NULL, otherwise create or overwrite the variable
124 * This is called in sequence to update the environment in RAM without updating
125 * the copy in flash after each set
128 * 0 on success, -1 on failure (modifies errno)
131 * EROFS - some variables ("ethaddr", "serial#") cannot be modified
133 int fw_env_write(char *name, char *value);
136 * fw_env_flush - write the environment from RAM cache back to flash
138 * @opts: encryption key, configuration file, defaults are used if NULL
141 * 0 on success, -1 on failure (modifies errno)
143 int fw_env_flush(struct env_opts *opts);
146 * fw_env_close - free allocated structure and close env
148 * @opts: encryption key, configuration file, defaults are used if NULL
151 * 0 on success, -1 on failure (modifies errno)
153 int fw_env_close(struct env_opts *opts);
157 * fw_env_version - return the current version of the library
160 * version string of the library
162 char *fw_env_version(void);