u-boot
来源:互联网 发布:淘宝人气值是什么 编辑:程序博客网 时间:2024/05/29 04:14
Overview
描述uboot中environment相关的数据结构和接口。
这里的源代码经过了部分简化。
environment存储在存储设备上的某个区域,以eMMC为例,会放在某个分区(如boot)的偏移量为CONFIG_ENV_OFFSET的地方,存储空间为CONFIG_ENV_SIZE的区域。其中前4个字节为CRC32,后面(data[])是实际的key=value序列。剩余存储区域,全部填0。CRC32是针对整个data(包括后面填充的0x00)计算出来的。
env的有些接口实现,依赖于实际的存储设备。
Download u-boot
在http://www.denx.de/wiki/U-Boot/SourceCode中可以链接到ftp://ftp.denx.de/pub/u-boot/,这里可以下载到uboot各个版本。
这里采用的版本:u-boot-2017.07: http://download.csdn.net/download/u013344915/9930135
Description
README
- CONFIG_ENV_IS_IN_MMC: Define this if you have an MMC device which you want to use for the environment. - CONFIG_SYS_MMC_ENV_DEV: Specifies which MMC device the environment is stored in. - CONFIG_SYS_MMC_ENV_PART (optional): Specifies which MMC partition the environment is stored in. If not set, defaults to partition 0, the user area. Common values might be 1 (first MMC boot partition), 2 (second MMC boot partition). - CONFIG_ENV_OFFSET: - CONFIG_ENV_SIZE: These two #defines specify the offset and size of the environment area within the specified MMC device. If offset is positive (the usual case), it is treated as relative to the start of the MMC partition. If offset is negative, it is treated as relative to the end of the MMC partition. This can be useful if your board may be fitted with different MMC devices, which have different sizes for the MMC partitions, and you always want the environment placed at the very end of the partition, to leave the maximum possible space before it, to store other data. These two values are in units of bytes, but must be aligned to an MMC sector boundary. - CONFIG_ENV_OFFSET_REDUND (optional): Specifies a second storage area, of CONFIG_ENV_SIZE size, used to hold a redundant copy of the environment data. This provides a valid backup copy in case the other copy is corrupted, e.g. due to a power failure during a "saveenv" operation. This value may also be positive or negative; this is handled in the same way as CONFIG_ENV_OFFSET. This value is also in units of bytes, but must also be aligned to an MMC sector boundary. - CONFIG_ENV_SIZE_REDUND (optional): This value need not be set, even when CONFIG_ENV_OFFSET_REDUND is set. If this value is set, it must be set to the same value as CONFIG_ENV_SIZE.Please note that the environment is read-only until the monitorhas been relocated to RAM and a RAM copy of the environment has beencreated; also, when using EEPROM you will have to use getenv_f()until then to read environment variables.The environment is protected by a CRC32 checksum. Before the monitoris relocated into RAM, as a result of a bad CRC you will be workingwith the compiled-in default environment - *silently*!!! [This isnecessary, because the first environment variable we need is the"baudrate" setting for the console - if we have a bad CRC, we don'thave any device yet where we could complain.]Note: once the monitor has been relocated, then it will complain ifthe default environment is used; a new CRC is computed as soon as youuse the "saveenv" command to store a valid environment.
environment.h
/************************************************************************** * * The "environment" is stored as a list of '\0' terminated * "name=value" strings. The end of the list is marked by a double * '\0'. New entries are always added at the end. Deleting an entry * shifts the remaining entries to the front. Replacing an entry is a * combination of deleting the old value and adding the new one. * * The environment is preceded by a 32 bit CRC over the data part. * *************************************************************************/
Files
- README: 对environment的概念说明
- include/environment.h: 数据结构,APIs
- include/common.h:
使用的#defines
#define CONFIG_ENV_SIZE (8 * 1024)#define CONFIG_ENV_IS_IN_MMC#define CONFIG_ENV_OFFSET (8 * 64 * 1024)#define ENV_HEADER_SIZE (sizeof(uint32_t))#define ENV_SIZE (CONFIG_ENV_SIZE - ENV_HEADER_SIZE)
未使用的#defines
CONFIG_ENV_OFFSET_REDUNDCONFIG_SYS_REDUNDAND_ENVIRONMENTCONFIG_SYS_MMC_ENV_PARTCONFIG_ENV_AESDO_DEPS_ONLYCONFIG_ENV_IS_NOWHERECONFIG_NEEDS_MANUAL_RELOC
Structure
typedef struct environment_s { uint32_t crc; /* CRC32 over data bytes */ unsigned char data[ENV_SIZE]; /* Environment data */} env_t;
Variables
extern const unsigned char default_environment[];extern env_t *env_ptr;extern struct hsearch_data env_htab;extern char *env_name_spec;
APIs
include/environment.h
extern void env_relocate_spec(void);extern unsigned char env_get_char_spec(int);extern int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr);extern uint mmc_get_env_part(struct mmc *mmc);/* Function that returns a character from the environment */unsigned char env_get_char(int);/* Function that returns a pointer to a value from the environment */const unsigned char *env_get_addr(int);unsigned char env_get_char_memory(int index);/* Function that updates CRC of the enironment */void env_crc_update(void);/* Look up the variable from the default environment */char *getenv_default(const char *name);/* [re]set to the default environment */void set_default_env(const char *s);/* [re]set individual variables to their value in the default environment */int set_default_vars(int nvars, char * const vars[]);/* Import from binary representation into hash table */int env_import(const char *buf, int check);/* Export from hash table into binary representation */int env_export(env_t *env_out);
include/common.h
/* common/cmd_nvedit.c */int env_init (void);void env_relocate (void);int envmatch (uchar *, int);/* Avoid unfortunate conflict with libc's getenv() */#ifdef CONFIG_SANDBOX#define getenv uboot_getenv#endifchar *getenv (const char *);int getenv_f (const char *name, char *buf, unsigned len);ulong getenv_ulong(const char *name, int base, ulong default_val);/** * getenv_hex() - Return an environment variable as a hex value * * Decode an environment as a hex number (it may or may not have a 0x * prefix). If the environment variable cannot be found, or does not start * with hex digits, the default value is returned. * * @varname: Variable to decode * @default_val: Value to return on error */ulong getenv_hex(const char *varname, ulong default_val);/* * Read an environment variable as a boolean * Return -1 if variable does not exist (default to true) */int getenv_yesno(const char *var);int saveenv (void);int setenv (const char *, const char *);int setenv_ulong(const char *varname, ulong value);int setenv_hex(const char *varname, ulong value);/** * setenv_addr - Set an environment variable to an address in hex * * @varname: Environment variable to set * @addr: Value to set it to * @return 0 if ok, 1 on error */static inline int setenv_addr(const char *varname, const void *addr){ return setenv_hex(varname, (ulong)addr);}#ifdef CONFIG_AUTO_COMPLETEint env_complete(char *var, int maxv, char *cmdv[], int maxsz, char *buf);#endifint get_env_id (void);
阅读全文
0 0
- U-BOOT
- u-boot
- U-boot
- U-Boot
- u-boot
- u-boot
- u-boot!!
- U-BOOT
- U-boot
- U-BOOT
- U BOOT
- U-boot
- u-boot
- U-Boot
- U-boot
- U-boot
- U-boot
- U-Boot
- python的matplotlib模块实现tensorflow结果可视化
- HDU 6096 String(2017 Multi-University Training Contest
- 小白学tkinter(tags(标签)的用法)
- 计算器(版本1)
- HashMap源码阅读
- u-boot
- 一分钟了解"用matlab计算信杂比SCR 以及 背景区域的标准差"
- 一行Spark代码的诞生记(深度剖析Spark架构)
- Matlab中数组元素引用——三种方法
- 20170811
- ACM-ICPC Asia Regional Contest HDU 5974 A Simple Math Problem(数论)
- Effective Modern C++翻译系列之Item2
- 【POJ1795】DNA Laboratory(状态压缩DP)
- Linux 小功能