]> git.ipfire.org Git - people/ms/u-boot.git/blame - tools/env/fw_env.h
env: add a version number to check API
[people/ms/u-boot.git] / tools / env / fw_env.h
CommitLineData
6aff3115 1/*
bc11756d 2 * (C) Copyright 2002-2008
6aff3115
WD
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
3765b3e7 5 * SPDX-License-Identifier: GPL-2.0+
6aff3115
WD
6 */
7
371ee137 8#include <stdint.h>
9d80b49a 9#include <uboot_aes.h>
e3c52f2b 10
00c234f3
SB
11/*
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
15 */
16#define FW_ENV_API_VERSION 1
17
81974f44 18struct env_opts {
371ee137
AF
19#ifdef CONFIG_FILE
20 char *config_file;
21#endif
371ee137 22 int aes_flag; /* Is AES encryption used? */
81974f44 23 uint8_t aes_key[AES_KEY_LENGTH];
d40dbfb7 24 char *lockname;
371ee137 25};
07ce9440 26
371ee137
AF
27int parse_aes_key(char *key, uint8_t *bin_key);
28
fd4e3280
AF
29/**
30 * fw_printenv() - print one or several environment variables
31 *
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
37 *
38 * Description:
39 * Uses fw_env_open, fw_getenv
40 *
41 * Return:
42 * 0 on success, -1 on failure (modifies errno)
43 */
81974f44 44int fw_printenv(int argc, char *argv[], int value_only, struct env_opts *opts);
fd4e3280
AF
45
46/**
47 * fw_setenv() - adds or removes one variable to the environment
48 *
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
54 *
55 * Description:
56 * Uses fw_env_open, fw_env_write, fw_env_close
57 *
58 * Return:
59 * 0 on success, -1 on failure (modifies errno)
60 *
61 * ERRORS:
62 * EROFS - some variables ("ethaddr", "serial#") cannot be modified
63 */
81974f44 64int fw_setenv(int argc, char *argv[], struct env_opts *opts);
fd4e3280
AF
65
66/**
67 * fw_parse_script() - adds or removes multiple variables with a batch script
68 *
69 * @fname: batch script file name
70 * @opts: encryption key, configuration file, defaults are used if NULL
71 *
72 * Description:
73 * Uses fw_env_open, fw_env_write, fw_env_close
74 *
75 * Return:
76 * 0 success, -1 on failure (modifies errno)
77 *
78 * Script Syntax:
79 *
80 * key [ [space]+ value]
81 *
82 * lines starting with '#' treated as comment
83 *
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.
88 *
89 * Script Example:
90 *
91 * netdev eth0
92 *
93 * kernel_addr 400000
94 *
95 * foo spaces are copied verbatim
96 *
97 * # delete variable bar
98 *
99 * bar
100 */
81974f44 101int fw_parse_script(char *fname, struct env_opts *opts);
fd4e3280
AF
102
103
104/**
105 * fw_env_open() - read enviroment from flash into RAM cache
106 *
107 * @opts: encryption key, configuration file, defaults are used if NULL
108 *
109 * Return:
110 * 0 on success, -1 on failure (modifies errno)
111 */
81974f44 112int fw_env_open(struct env_opts *opts);
fd4e3280
AF
113
114/**
115 * fw_getenv() - lookup variable in the RAM cache
116 *
117 * @name: variable to be searched
118 * Return:
119 * pointer to start of value, NULL if not found
120 */
121char *fw_getenv(char *name);
122
123/**
124 * fw_env_write() - modify a variable held in the RAM cache
125 *
126 * @name: variable
127 * @value: delete variable if NULL, otherwise create or overwrite the variable
128 *
129 * This is called in sequence to update the environment in RAM without updating
130 * the copy in flash after each set
131 *
132 * Return:
133 * 0 on success, -1 on failure (modifies errno)
134 *
135 * ERRORS:
136 * EROFS - some variables ("ethaddr", "serial#") cannot be modified
137 */
c3a23e8b 138int fw_env_write(char *name, char *value);
fd4e3280
AF
139
140/**
141 * fw_env_close - write the environment from RAM cache back to flash
142 *
143 * @opts: encryption key, configuration file, defaults are used if NULL
144 *
145 * Return:
146 * 0 on success, -1 on failure (modifies errno)
147 */
81974f44 148int fw_env_close(struct env_opts *opts);
6aff3115 149
00c234f3
SB
150/**
151 * fw_env_version - return the current version of the library
152 *
153 * Return:
154 * version string of the library
155 */
156char *fw_env_version(void);
157
c3a23e8b 158unsigned long crc32(unsigned long, const unsigned char *, unsigned);