嵌入式Linux如何設定獲取uboot引數
阿新 • • 發佈:2020-07-20
---
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
---
,建立一個fw_setenv到fw_printenv的軟鏈。
章節概述:
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
配置
這個工具還需要一個配置檔案,以獲取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的環境變數。