博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux下如何访问和修改u-boot环境变量?
阅读量:2022 次
发布时间:2019-04-28

本文共 1525 字,大约阅读时间需要 5 分钟。

  uboot下可以通过命令访问和修改环境变量,但是如果需要在
系统下访问这些数据该怎么办呢?其实uboot早就帮我们想好了。

 

    1、编译fw_printenv工具

    在你使用的uboot代码中用以下编译指令:

    make env

    这样就可以编译tools/env下的代码,编译出的fw_printenv工具有读写uboot环境变量区的能力。这个工具是针对目标机的,也就是说如果你的uboot代码之前是针对ARM编译的话,fw_printenv也是交叉编译给ARM芯片的。


    2、安装fw_printenv工具

    到/tools/env目录中,将编译好的fw_printenv拷贝到目标机的文件系统中,并通过"ln -s fw_printenv fw_setenv",创建一个fw_setenv到fw_printenv的软链。

    这个工具还需要一个配置文件,以获取uboot的ENV区域的位置信息。默认状态下,请将fw_env.config文件拷贝到目标机的文件系统的/etc目录下。然后结合uboot配置中定义的ENV区和Linux下mtd分区的情况修改配置文件。具体的修改方法见fw_env.config文件中的说明及/tools/env/README文件。


   
 3、fw_printenv工具的使用

    其实fw_printenv使用起来和uboot下的printenv和setenv指令是一模一样的。

    打印uboot环境变量:

    fw_printenv [[ -n name ] | [ name ... ]]

    # ./fw_printenv -n baudrate

    115200

    # ./fw_printenv baudrate

    baudrate=115200

    如果不指定name,fw_printenv会打印出ENV区中的所有环境变量

    设置uboot环境变量:

    fw_setenv name [ value ... ]

    如果不指定value,表示要删除这个name的环境变量。

    # ./fw_setenv temp tekkaman

    # ./fw_printenv -n temp

    tekkaman

    # ./fw_setenv temp

    # ./fw_printenv -n temp

    ## Error: "temp" not defined

问题:

1  解决uboot命令行中 不能设置ethaddr的问题(Can't overwrite "ethaddr"),修改Fw_env.c 中的fw_setenv函数代码改为如下。

[cpp] 
  1. if (oldval) {  
  2.     /* 
  3.      * Ethernet Address and serial# can be set only once 
  4.      */  
  5.     if ((<strong>strcmp (name, "ethaddr") == 1)</strong> ||  
  6.         (strcmp (name, "serial#") == 0)) {  
  7.         fprintf (stderr, "Can't overwrite \"%s\"\n", name);  

2 解决fw_setenv 时提示Warning: Bad CRC, using default environment

设置Fw_env.h 为实际使用值,并配置好fw_env.config
#define DEVICE1_NAME      "/dev/mtd1"
#define DEVICE2_NAME      "/dev/mtd2"
#define DEVICE1_OFFSET    0x0000
#define ENV1_SIZE         0x10000  
#define DEVICE1_ESIZE     0x4000

转载地址:http://msgxf.baihongyu.com/

你可能感兴趣的文章
LeetCode131. Palindrome Partitioning(思路及python解法)
查看>>
LeetCode179. Largest Number(思路及python解法)
查看>>
LeetCode236. Lowest Common Ancestor of a Binary Tree(思路及python解法)
查看>>
LeetCode404. Sum of Left Leaves(思路及python解法)
查看>>
LeetCode222. Count Complete Tree Nodes (思路及python解法)
查看>>
LeetCode227. Basic Calculator II(思路及python解法)
查看>>
LeetCode240. Search a 2D Matrix II(思路及python解法)
查看>>
LeetCode322. Coin Change(思路及python解法)
查看>>
LeetCode150. Evaluate Reverse Polish Notation(思路及python解法)
查看>>
LeetCode166. Fraction to Recurring Decimal(思路及python解法)
查看>>
LeetCode454. 4Sum II(思路及python解法)
查看>>
LeetCode395. Longest Substring with At Least K Repeating Characters(思路及python解法)
查看>>
LeetCode334. Increasing Triplet Subsequence(思路及python解法)
查看>>
LeetCode134. Gas Station(思路及python解法)
查看>>
LeetCode328. Odd Even Linked List(思路及python解法)
查看>>
LeetCode146. LRU Cache(思路及python解法)
查看>>
LeetCode29. Divide Two Integers(思路及python解法)
查看>>
LeetCode1038. Binary Search Tree to Greater Sum Tree(思路及python解法)
查看>>
LeetCode18. 4Sum (思路及python解法)
查看>>
LeetCode16. 3Sum Closest(思路及python解法)
查看>>