fw_printenv fw_setenv

举报
aiot_bigbear 发表于 2022/09/25 01:32:02 2022/09/25
【摘要】 he fw_printenv and fw_setenv commands can be used to read and set U-Boot environment variables from Li...

he fw_printenv and fw_setenv commands can be used to read and set U-Boot environment variables from Linux. This guide uses the RidgeRun SDK to enable these commands in your target board and configure the /etc/fw_env.config file accordingly.

Contents
1 Setup
1.1 Building the U-Boot env tools
1.2 Preparing the fw_env.config file
1.2.1 fw_env.config file for known boards
1.2.1.1 DM36x Leopard
1.2.1.2 DM816x EVM
1.2.1.3 DM816x Z3
2 Using the env tools
3 References
Setup
Building the U-Boot env tools
Edit the $DEVDIR/bootloader/u-boot-*/Makefile and add a buildenv rule with the following commands.

buildenv:
$(V) ( M A K E ) − C s r c H O S T C C = (MAKE) -C src HOSTCC= (MAKE)CsrcHOSTCC=(TOOLCHAIN_PREFIX)-gcc env $(QOUT) $(ERRQOUT)
$(V) cp src/tools/env/fw_printenv $(FSROOT)/usr/bin
$(V) ( cd $(FSROOT)/usr/bin ; rm -f fw_setenv ; ln -s fw_printenv fw_setenv )
You may find interesting that we’re setting HOSTCC to our cross-compiler. That’s misleading indeed, but that’s how maintainers thought of this (interesting reading).

After editing your file, you’ll be able to build the tools, installing fw_printenv and fw_setenv in $(FSROOT)/usr/bin/.

cd $DEVDIR/bootloader/u-boot-*/
make buildenv
In order to enable the fw_printenv and fw_setenv commands, you will have to activate the option, into the config system, by toggling it in the following location:

Prompt: Bootloader user space environment tools
Location:
-> Bootloader configuration
Preparing the fw_env.config file
For the fw_env.config file you need to know the MTD device name, the device offset, the environment size, flash sector size, and the number of sectors (ignored in the NOR case).

MTD device name: the Linux command “cat /proc/mtd” can be helpful to determine the MTD device where u-boot is living in your board.
Device offset: in the u-boot source folder, look inside include/configs for the header file related to your board; for the DM36x leopard board, the file is davinci_dm368leopard.h. Search for CONFIG_ENV_OFFSET.
Environment size: same as above, but search for CONFIG_ENV_SIZE.
Flash sector size: in u-boot’s prompt, the command “nand info” will display the sector size; example output: NAND 256MiB 3,3V 8-bit, sector size 128 KiB.
Number of sectors: this setting will be ignored in the NOR case, and possibly not necessary to set in other cases. Anyway, it is the division of the environment size, i.e. 0x40000, and the sector size, i.e. 0x20000 for 128Kb, resulting in this example that the environment takes 2 sectors (0x40000/0x20000).
fw_env.config file for known boards
Using RidgeRun’s SDK, these /etc/fw_env.config files work out of the box. For simplicity, all of these files assume uboot lives in mtd0.

DM36x Leopard

MTD device name Device offset Env. size Flash sector size Number of sectors

/dev/mtd0 0x3C0000 0x40000 0x20000 2
DM816x EVM

MTD device name Device offset Env. size Flash sector size Number of sectors

/dev/mtd4 0x260000 0x2000 0x20000 1
DM816x Z3

MTD device name Device offset Env. size Flash sector size Number of sectors

/dev/mtd0 0x260000 0x2000 0x20000 1
Using the env tools
The Linux command fw_printenv is the homologous of U-boot’s printenv command.

/ fw_printenv

autoload=no
autostart=yes
baudrate=115200

To print a single variable/

/ fw_printenv autoload

autoload=no
Then fw_setenv is the homologous of U-boot’s setenv command.

/ fw_setenv autoload yes

/ fw_printenv autoload

autoload=yes

文章来源: blog.csdn.net,作者:悟空胆好小,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/xushx_bigbear/article/details/123364451

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。