• 嵌入式Linux如何设置获取uboot参数


    --- title: 嵌入式Linux如何设置获取uboot参数 EntryName: embeded-linux-debug-get-and-set-u-boot-envarg date: 2020-07-20 09:33:01 categories: tags: - uboot - arm - linux - debug ---

    章节概述:

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

    步骤

    uboot版本:一般在2011年以后的都有(见过2011年版本的uboot教程)

    编译fw_printenv

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

    make env ARCH=xx CROSS_COMPLIE=xx-
    

    这样就可以编译tools/env下的代码,编译出的fw_printenv工具有读写uboot环境变量区的能力。

    安装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文件。

    配置一定要和系统的配置相同。

    跟据以上三个定义修改fw_env.config,以emmc为例:

    # Configuration file for fw_(printenv/setenv) utility.
    # Up to two entries are valid, in this case the redundant
    # environment sector is assumed present.
    # Notice, that the "Number of sectors" is not required on NOR and SPI-dataflash.
    # Futhermore, if the Flash sector size is ommitted, this value is assumed to
    # be the same as the Environment size, which is valid for NOR and SPI-dataflash
    
    # NOR example
    # MTD device name       Device offset   Env. size       Flash sector size       Number of sectors
    #/dev/mtd1              0x0000          0x4000          0x4000
    #/dev/mtd2              0x0000          0x4000          0x4000
    # MTD SPI-dataflash example
    # MTD device name       Device offset   Env. size       Flash sector size       Number of sectors
    #/dev/mtd5              0x4200          0x4200
    #/dev/mtd6              0x4200          0x4200
    
    # NAND example
    #/dev/mtd0              0x4000          0x4000          0x20000                 2
    
    # Block device example
    # device name           env_offset      Env.bin_size    Env.bin_size    Env_partition_sectors        
    /dev/mmcblk0            0x3000000       0x20000         0x20000         0x8000
    

    参数解析:

    • /dev/mtd0是专门给环境变量分配的分区。Device offset 是只环境变量在此分区上的偏移,不是指在整个nand上的偏移。

    环境变量的烧写地址是 0x80000,大小0x10000,block大小是0x20000。这里因为mtd0分区设定了起始地址是0x80000,所以环境变量在此分区上的偏移地址为 0了

    使用 fw_printenv

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

    获取uboot环境变量

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

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

    设置uboot环境变量

    fw_setenv name [ value ... ]
    

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

  • 相关阅读:
    0309. Best Time to Buy and Sell Stock with Cooldown (M)
    0621. Task Scheduler (M)
    0106. Construct Binary Tree from Inorder and Postorder Traversal (M)
    0258. Add Digits (E)
    0154. Find Minimum in Rotated Sorted Array II (H)
    0797. All Paths From Source to Target (M)
    0260. Single Number III (M)
    0072. Edit Distance (H)
    0103. Binary Tree Zigzag Level Order Traversal (M)
    0312. Burst Balloons (H)
  • 原文地址:https://www.cnblogs.com/schips/p/13343453.html
Copyright © 2020-2023  润新知