DEV Community

ronnie R
ronnie R

Posted on

How to Compile and Use fw_printenv in the OKMX6UL Series Linux 4.1.15 System

fw _ printenv is a tool for reading the U-boot environment variable. It provides the configuration information stored in the U-boot environment variable to the Linux system. These environment variables are typically used to configure and control the boot loading process, such as boot commands, kernel parameters, device tree file paths, and more.

This article shows how to use fw_printenv on OKMX6UL boards, mainly for Forlinx OKMX6UL with Linux 4.1.15. Other platforms can also reference this guide, but adjustments may be required.

  1. Compile the fw_printenv Tool Execute the following commands under the U-boot source code path, and then the tool will be generated under tools/env.

$ . /opt/fsl-imx-x11/4.1.15-2.0.0/environment-setup-cortexa7hf-neon-poky-linux-gnueabi
$ make env
If you encounter the following error:

......
In file included from tools/env/aes.c:1:0:
tools/env/../../lib/aes.c:28:20: fatal error: string.h: No such file or directory
compilation terminated.
scripts/Makefile.host:111: recipe for target 'tools/env/aes.o' failed
make[1]: *** [tools/env/aes.o] Error 1
Makefile:1372: recipe for target 'env' failed
make: *** [env] Error 2
Then modify the uboot top-level Makefile to comment out CC

CC = $(CROSS_COMPILE)gcc

Then compile

$ make env
Compile to generate the following two files under the tools/env/ path:

fw_printenv
fw_env.config
fw_printenv used for reading and writing environment variables
fw_env.config used to describe the partition, address, etc. where the variable is located.

  1. Configuration File modify the fw_env.config file under tools/env in the uboot source directory according to the mtd partition, the location and size of the UBOOT environment variables, etc. See the instructions in the fw_env.config file and the /tools/env/README file for specific modifications.

Device offset, Env size, and Flash sector size should correspond to the three macro definitions in the include/configs/xxxx. H files in the uboot source directory.

CONFIG_ENV_OFFSET
CONFIG_ENV_SIZE
CONFIG_ENV_SECT_SIZE
Note: The following is based on the 2024 image, and it is recommended to double-check the exact address in uboot.

(1) OKMX6ULL

The header file for the OKMX6ULL-S and OKMX6ULL-C series is include/configs/mx6ullevk.h, which is configured as follows:

define CONFIG_ENV_SIZE SZ_8K

if defined(CONFIG_ENV_IS_IN_MMC)

define CONFIG_ENV_OFFSET (12 * SZ_64K)

elif defined(CONFIG_ENV_IS_IN_SPI_FLASH)

define CONFIG_ENV_OFFSET (768 * 1024)

define CONFIG_ENV_SECT_SIZE (64 * 1024)

define CONFIG_ENV_SPI_BUS CONFIG_SF_DEFAULT_BUS

define CONFIG_ENV_SPI_CS CONFIG_SF_DEFAULT_CS

define CONFIG_ENV_SPI_MODE CONFIG_SF_DEFAULT_MODE

define CONFIG_ENV_SPI_MAX_HZ CONFIG_SF_DEFAULT_SPEED

elif defined(CONFIG_SYS_BOOT_NAND)

undef CONFIG_ENV_SIZE

define CONFIG_ENV_OFFSET (0x6 << 20) /* 60 -> 06 */

define CONFIG_ENV_SECT_SIZE (128 << 10) #define CONFIG_ENV_SIZE CONFIG_ENV_SECT_SIZE #elif defined(CONFIG_SYS_BOOT_NAND_1G) #undef CONFIG_ENV_SIZE #define CONFIG_ENV_OFFSET (0xa << 20) #define CONFIG_ENV_SECT_SIZE (256 << 10) #define CONFIG_ENV_SIZE CONFIG_ENV_SECT_SIZE #endif

Some of the macros used above can be found in the./include/Linux/sizes. h.

define SZ_8K 0x00002000

define SZ_16K 0x00004000

define SZ_32K 0x00008000

define SZ_64K 0x00010000

......
It follows that:

CONFIG_ENV_OFFSET CONFIG_ENV_SIZE CONFIG_ENV_SECT_SIZE
EMMC 0x80000 0x2000 /
256 Nand 0x600000 0x20000 0x20000
1G Nand 0xA00000 0x40000 0x40000
Therefore, the configuration files for each version of the SoM are as follows:

emmc

......

Block device example

/dev/mmcblk1 0x80000 0x2000
......
256 nand

......

NAND example

/dev/mtd2 0x00000 0x20000 0x20000 1
......
1G nand

......

NAND example

/dev/mtd2 0x00000 0x40000 0x40000 1
......
(2) OKMX6UL

OKMX6UL-C Environment Variables

define CONFIG_ENV_SIZE SZ_8K

if defined(CONFIG_ENV_IS_IN_MMC)

define CONFIG_ENV_OFFSET (8 * SZ_64K)

elif defined(CONFIG_ENV_IS_IN_SPI_FLASH)

define CONFIG_ENV_OFFSET (768 * 1024)

define CONFIG_ENV_SECT_SIZE (64 * 1024)

define CONFIG_ENV_SPI_BUS CONFIG_SF_DEFAULT_BUS

define CONFIG_ENV_SPI_CS CONFIG_SF_DEFAULT_CS

define CONFIG_ENV_SPI_MODE CONFIG_SF_DEFAULT_MODE

define CONFIG_ENV_SPI_MAX_HZ CONFIG_SF_DEFAULT_SPEED

elif defined(CONFIG_SYS_BOOT_NAND)

undef CONFIG_ENV_SIZE

if defined(CONFIG_

                    FCU1101
Enter fullscreen mode Exit fullscreen mode

)
/#define CONFIG_ENV_OFFSET (60 << 20)/ #define CONFIG_ENV_OFFSET (0x4 << 20) #else #define CONFIG_ENV_OFFSET (0x6 << 20) #endif /*#define CONFIG_ENV_OFFSET (0x6 << 20) */ #define CONFIG_ENV_SECT_SIZE (128 << 10) #define CONFIG_ENV_SIZE CONFIG_ENV_SECT_SIZE #elif defined(CONFIG_SYS_BOOT_NAND_1G) #undef CONFIG_ENV_SIZE #define CONFIG_ENV_OFFSET (0xa << 20) #define CONFIG_ENV_SECT_SIZE (256 << 10) #define CONFIG_ENV_SIZE CONFIG_ENV_SECT_SIZE
Some of the macros used above can be found in the./include/Linux/sizes. h.

......

define SZ_8K 0x00002000

define SZ_16K 0x00004000

define SZ_32K 0x00008000

define SZ_64K 0x00010000

......
We can get

CONFIG_ENV_OFFSET CONFIG_ENV_SIZE CONFIG_ENV_SECT_SIZE
EMMC 0xc0000 0x2000 /
256 Nand 0x600000 0x20000 0x20000
1G Nand 0xA00000 0x40000 0x40000
Therefore, the configuration files for each version of the SoM are as follows:

emmc.

......

Block device example

/dev/mmcblk1 0xc0000 0x2000
......
256nand

......

NAND example

/dev/mtd2 0x00000 0x20000 0x20000 1
......
1G nand

......

NAND example

/dev/mtd2 0x00000 0x40000 0x40000 1
......
Deploy to the Development Board

Copy tools/env/fw_env.config to the /etc path of the development board;
Copy tools/env/fw_printenv to the root file system of the development board under the path /usr/bin.
Create a soft link so that fw_setenv links to /usr/bin/fw_printenv
Create a soft link method:

$ ln -s /usr/bin/fw_printenv /usr/bin/fw_setenv

  1. Use & Method Read Environment Variables

root@fl-imx6ull:~# fw_printenv
baudrate=115200
board_name=EVK
board_rev=14X14
bootcmd=if test ${bootdev} = sd1; then run erase_env;mmc dev 0;if fatload mmc 0:1 83200000 target/env.txt;then echo burn default env from sdcard......;setenv_sdcard mmc 0:1 83200000 target/env.txt;fi;echo update from sd ...;run update_from_sd;else echo boot from nand ...;run nandargs;run bootnand; fi;
bootcmd_mfg=run erase_env;run setenv_mfgtool;run mfgtool_args;bootz ${loadaddr} ${initrd_addr} ${fdt_addr};
bootdelay=1
bootdev=mmc2
bootnand=nand read ${loadaddr} 0xa00000 0x800000;nand read ${fdt_addr} ${nand_addr} 0x40000;bootz ${loadaddr} - ${fdt_addr};
calibrate=y
console=ttymxc0
env_addr=0x83200000
erase_env=nand erase 0x600000 0x100000;
eth1addr=72:d9:26:cf:b7:42
ethaddr=ee:71:d9:26:cf:b7
ethprime=FEC
fdt_addr=0x83000000
fdt_high=0xffffffff
fl_menu1=1
initrd_addr=0x83800000
initrd_high=0xffffffff
loadaddr=0x80800000
mfgtool_args=setenv bootargs console=${console},${baudrate} rdinit=/linuxrc g_mass_storage.stall=0 g_mass_storage.removable=1 g_mass_storage.file=/fat g_mass_storage.ro=1 g_mass_storage.idVendor=0x066F g_mass_storage.idProduct=0x37FF g_mass_storage.iSerialNumber="" clk_ignore_unused
nand_addr=0x780000
nandargs=setenv bootargs console=ttymxc0,115200 cma=64M root=/dev/mtdblock5 rw rootfstype=yaffs2
panel=TFT70AB-1024x600
setenv_mfgtool=setenv_mfgtools ${env_addr} 2000 ;
splashimage=0x83800000
splashpos=m,m
update_from_sd=run update_nand;
update_nand=mmc rescan;fatload mmc 0 ${loadaddr} /sdrun/zImage; fatload mmc 0 ${initrd_addr} /sdrun/ramdisk.img.u; fatload mmc 0 ${fdt_addr} /sdrun/imx6ull-14x14-evk.dtb; setenv bootargs console=${console},${baudrate} rdinit=/linuxrc; bootz ${loadaddr} ${initrd_addr} ${fdt_addr};
Write environment variable:

root@fl-imx6ull:~# fw_setenv panel TFT70AB-800x480
root@fl-imx6ull:~# fw_printenv
baudrate=115200
board_name=EVK
board_rev=14X14
......
panel=TFT70AB-800x480
Reboot and check the environment variables in uboot.

=> print
baudrate=115200
board_name=EVK
board_rev=14X14
......
panel=TFT70AB-800x480
......
Environment size: 1779/131068 bytes
=>

Top comments (0)