1 /* 2 * Copyright 2016-2017 Frank Hunleth 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef UBOOT_ENV_H 18 #define UBOOT_ENV_H 19 20 #include <stdbool.h> 21 #include <stdint.h> 22 #include <confuse.h> 23 24 struct uboot_name_value { 25 char *name; 26 char *value; 27 struct uboot_name_value *next; 28 }; 29 30 struct uboot_env { 31 uint32_t block_offset; 32 uint32_t block_count; 33 size_t env_size; 34 35 bool use_redundant; 36 uint32_t redundant_block_offset; 37 38 // These flags determine which environment gets written. When 39 // not using redundant environments, write_primary is always true. 40 // For redundant environments, these ping/pong. 41 bool write_primary; 42 bool write_secondary; 43 uint8_t flags; 44 45 struct uboot_name_value *vars; 46 }; 47 48 int uboot_env_verify_cfg(cfg_t *cfg); 49 int uboot_env_create_cfg(cfg_t *cfg, struct uboot_env *output); 50 51 int uboot_env_setenv(struct uboot_env *env, const char *name, const char *value); 52 int uboot_env_unsetenv(struct uboot_env *env, const char *name); 53 int uboot_env_getenv(struct uboot_env *env, const char *name, char **value); 54 void uboot_env_free(struct uboot_env *env); 55 56 struct block_cache; 57 int uboot_env_read(struct block_cache *bc, struct uboot_env *env); 58 int uboot_env_write(struct block_cache *bc, struct uboot_env *env); 59 60 #endif // UBOOT_ENV_H 61