一、uboot存儲(chǔ)方式:
uboot源碼:二進(jìn)制的uboot程序
0xffffffff:uboot分區(qū)沒(méi)有用的空閑空間
uboot環(huán)境變量:bootdelay、bootcmd、bootargs等參數(shù),鍵與值用0x3d,即“=”隔開(kāi),兩參數(shù)之間用0x00,即\0隔開(kāi)
0x00000000:uboot參數(shù)分區(qū)沒(méi)有用的空閑空間
二、uboot參數(shù)操作:
2.1 參數(shù):
include/configs/xxx.h //xxx為芯片名稱(chēng)
中定義了一些環(huán)境變量默認(rèn)值的宏定義
common/env_embedded.c
中定義了環(huán)境變量鍵值對(duì)字符串結(jié)構(gòu)體
2.2 功能函數(shù):
common/env_common.c
初始化如下結(jié)構(gòu):
#ifdef CONFIG_ENV_IS_IN_NAND
extern int nand_env_init(void);
extern unsigned char nand_env_get_char_spec(int);
extern int nand_saveenv(void);
extern void nand_env_relocate_spec(void);
static struct env_common_func_t nand_env_cmn_func = {
.env_init = nand_env_init,
.env_get_char_spec = nand_env_get_char_spec,
.saveenv = nand_saveenv,
.env_relocate_spec = nand_env_relocate_spec,
.env_name_spec = "NAND",
};
#else
static struct env_common_func_t nand_env_cmn_func = {0};
#endif
#ifdef CONFIG_ENV_IS_IN_SPI_FLASH
extern int sf_env_init(void);
extern unsigned char sf_env_get_char_spec(int);
extern int sf_saveenv(void);
extern void sf_env_relocate_spec(void);
static struct env_common_func_t nand_env_cmn_func = {
.env_init = sf_env_init,
.env_get_char_spec = sf_env_get_char_spec,
.saveenv = sf_saveenv,
.env_relocate_spec = sf_env_relocate_spec,
.env_name_spec = "SPI FLASH",
};
#else
static struct env_common_func_t sf_env_cmn_func = {0};
#endif
#ifdef CONFIG_ENV_IS_IN_EMMC
extern int emmc_env_init(void);
extern unsigned char emmc_env_get_char_spec(int);
extern int emmc_saveenv(void);
extern void emmc_env_relocate_spec(void);
static struct env_common_func_t emmc_env_cmn_func = {
.env_init = emmc_env_init,
.env_get_char_spec = emmc_env_get_char_spec,
.saveenv = emmc_saveenv,
.env_relocate_spec = emmc_env_relocate_spec,
.env_name_spec = "NAND",
};
#else
static struct env_common_func_t emmc_env_cmn_func = {0};
#endif
int env_init(void)
{
switch (get_boot_media())
{
default:
env_cmn_func = NULL;
break;
case BOOT_MEDIA_NAND:
env_cmn_func = &nand_env_cmn_func;
break;
case BOOT_MEDIA_SPIFLASH:
env_cmn_func = &sf_env_cmn_func;
break;
case BOOT_MEDIA_EMMC:
env_cmn_func = &emmc_env_cmn_func;
break;
case BOOT_MEDIA_DDR:
env_cmn_func = &sf_env_cmn_func;
break;
}
if (env_cmn_func && !env_cmn_func->env_name_spec)
env_cmn_func = NULL;
if (!env_cmn_func)
return -1;
env_cmn_func->env_init();
env_name_spec = env_cmn_func->env_name_spec;
return 0;
}
2.3 功能函數(shù)調(diào)用
common/cmd_nvedit.c
U_BOOT_CMD(
saveenv, 1, 0, do_saveenv,
"save environment variables to persistent storage",
""
);
int do_saveenv (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
extern char * env_name_spec;
env_crc_update ();
return (saveenv()?? 1 : 0);
}
三、內(nèi)核查參方式:
3.1 mtd方式
文件形式,待補(bǔ)
3.2 ioremap
驅(qū)動(dòng)+應(yīng)用,待補(bǔ)
3.3 mtd_debug
軟件移植,待補(bǔ)
3.4 fw_printenv
3.4.1 工具生成方法:
uboot_source_tree # make ARCH=arm CROSS_COMPILE=arm-linux-gcc env
uboot_source_tree/tools/env下得到fw_printenv與fw_env.config
3.4.2 將工具與配置文件放到板子文件系統(tǒng)上
3.4.3 修改fw_env.config
Device offset ?對(duì)應(yīng)于uboot源碼目錄中include/configs/board_name.h的CONFIG_ENV_OFFSET
Env size 對(duì)應(yīng)于uboot源碼目錄中include/configs/board_name.h的CONFIG_ENV_SIZE
Flash sector size ?對(duì)應(yīng)于uboot源碼目錄中include/configs/board_name.h的CONFIG_ENV_SECT_SIZE
Number of sectors對(duì)應(yīng)于多少塊 這里用的是nand flash,如果用nor就不用寫(xiě)這個(gè)了
3.4.4 使用方法:
ln -s fw_printenv fw_setenv
讀:
fw_printenv 讀全參
fw_printenv -n param_name 讀指定參
寫(xiě):
fw_setenv?param_name param_value 寫(xiě)指定參
3.4.5 錯(cuò)誤解決辦法:
錯(cuò)誤A:/include/linux/types.h:154:36: error: conflicting types for ‘uintmax_t’?typedef u_int32_t uintmax_t;
arm-linux/target/usr/include/stdint.h:140:32: note: previous declaration of ‘uintmax_t’ was here
typedef unsigned long long int uintmax_t;
解決A:兩個(gè)文件的uintmax_t類(lèi)型沖突了,將uboot中的類(lèi)型按照編譯器文件中的類(lèi)型改過(guò)來(lái)
錯(cuò)誤B:include/linux/types.h:155:36: error: conflicting types for ‘intmax_t’?typedef int32_t intmax_t;
arm-linux/target/usr/include/stdint.h:138:24: note: previous declaration of ‘intmax_t’ was here
typedef long long int intmax_t;
解決B:方法同上
錯(cuò)誤C:Warning: Bad CRC, using default environment
解決C:方案一、環(huán)境變量沒(méi)save,uboot的環(huán)境變量分散于代碼中,只有save才會(huì)存儲(chǔ)與env地址中,如果不存到env地址中,fw_printenv是找不到的
方案二、fw_env.config沒(méi)設(shè)置參數(shù),參數(shù)設(shè)置方法見(jiàn)3.4.3
四、uboot增加環(huán)境變量
4.1 方法一、uboot命令行手動(dòng)set param_name param_value
4.2 方法二、uboot代碼中添加:
1)uboot源碼目錄中include/configs/board_name.h添加變量宏定義
2)uboot源碼目錄中common/env_common.c添加
?
評(píng)論
查看更多