20161215_jeffrey - silenceuncrio/diary GitHub Wiki
-
0920 -
linux 去改 uboot 的 環境變數
- 1305 - fw_printenv: cannot execute binary file: Exec format error
- 1545 - u-boot-fw-utils
-
1615 - fw_printenv -
/etc/fw_env.config
繼續昨天 winston 提到之後還要克服的點
- linux 去改 uboot 的 環境變數
- 怎麼從 uboot 來看
- kernel partion 是否完整
- rootfs ubi partition 是否完整
- 不完整的 kernel partion 或 rootfs ubi partition 均會導致系統開機異常
- uboot 要能在此時切換到備援的 partition
linux 去改 uboot 的 環境變數
- http://elinux.org/U-boot_environment_variables_in_linux
- http://www.denx.de/wiki/DULG/HowCanIAccessUBootEnvironmentVariablesInLinux
- http://labs.isee.biz/index.php/How_to_modify_the_uboot_environment_from_userspace
我在 <u-boot-imx>\tools\env
看到這個 tools
make env
r0/git/tools/env# make env
make: *** No rule to make target `env'. Stop.
參考 http://elinux.org/U-boot_environment_variables_in_linux
make env ARCH=arm CROSS_COMPILE= /usr/local/angstrom/arm/bin/arm-angstrom-linux-gnuabi-
root@30e08a478d9e:/var/m300/fsl-release-bsp/build_small/tmp/work/imx6ulevk-poky-linux-gnueabi/u-boot-imx/2015.04-r0/git/tools/env# make env ARCH=arm CROSS_COMPILE= /usr/local/angstrom/arm/bin/arm-angstrom-linux-gnuabi-
make: *** No rule to make target `env'. Stop.
make env ARCH=arm CROSS_COMPILE= /usr/local/angstrom/arm/bin/arm-angstrom-linux-gnuabi-
這個動作要在 <u-boot-imx>
執行, 而不是 <u-boot-imx>/tools/env
而且要先在 <u-boot-imx>
做過 make menuconfig
才能得到 .config
build@30e08a478d9e:/var/m300/fsl-release-bsp/build_small/tmp/work/imx6ulevk-poky-linux-gnueabi/u-boot-imx/2015.04-r0/git$ make env ARCH=arm CROSS_COMPILE= /usr/local/angstrom/arm/bin/arm-angstrom-linux-gnuabi-
Makefile:1351: target `_clean_arch/arm/cpu' given more than once in the same rule.
HOSTCC scripts/basic/fixdep
HOSTCC scripts/kconfig/conf.o
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
scripts/kconfig/conf --silentoldconfig Kconfig
CHK include/config.h
GEN include/autoconf.mk
./include/common.h:372:73: fatal error: asm/u-boot-sandbox.h: No such file or directory
# include <asm/u-boot-sandbox.h> /* TODO(sjg) what needs to be fixed? */
^
compilation terminated.
make[1]: *** [include/autoconf.mk] Error 1
HOSTCC tools/env/fw_env.o
HOSTCC tools/env/fw_env_main.o
HOSTCC tools/env/crc32.o
HOSTCC tools/env/ctype.o
HOSTCC tools/env/linux_string.o
HOSTCC tools/env/env_attr.o
HOSTCC tools/env/env_flags.o
HOSTCC tools/env/aes.o
HOSTLD tools/env/fw_printenv
STRIP tools/env/fw_printenv
make: *** No rule to make target `/usr/local/angstrom/arm/bin/arm-angstrom-linux-gnuabi-'. Stop.
雖然過程有些錯誤
但我們還是在 <u-boot-imx>/tools/env
發現了 fw_printenv
build@30e08a478d9e:/var/m300/fsl-release-bsp/build_small/tmp/work/imx6ulevk-poky-linux-gnueabi/u-boot-imx/2015.04-r0/git/tools/env$ ls
Makefile aes.o ctype.c env_attr.o fw_env.c fw_env.o fw_printenv
README crc32.c ctype.o env_flags.c fw_env.config fw_env_main.c linux_string.c
aes.c crc32.o env_attr.c env_flags.o fw_env.h fw_env_main.o linux_string.o
複製到 /var/m300/fsl-release-bsp/build_small/images
build@30e08a478d9e:/var/m300/fsl-release-bsp/build_small/tmp/work/imx6ulevk-poky-linux-gnueabi/u-boot-imx/2015.04-r0/git/tools/env$ cp fw_printenv /var/m300/fsl-release-bsp/build_small/images
切換到 m300
- 把開發環境上的 images folder 掛載到 m300 上的
/tmp/images
cd /tmp
mkdir images
mount -t nfs 192.168.1.200:/home/jeffrey/M300/fsl-release-bsp/build_small/images images
直接執行看看
root@M300:/tmp/images# ./fw_printenv
-sh: ./fw_printenv: cannot execute binary file: Exec format error
shit!
http://recipes.yoctoproject.org/rrs/recipedetail/22/
關鍵字是 u-boot-fw-utils
➜ sources git:(nandflash) ✗ find . -name "u-boot-fw*"
./poky/meta/recipes-bsp/u-boot/u-boot-fw-utils_2015.01.bb
./poky/meta/recipes-bsp/u-boot/u-boot-fw-utils
shit!
bitbake u-boot-fw-utils
... fail
ERROR: Function failed: do_compile (log file is located at /var/m300/fsl-release-bsp/build_small/tmp/work/imx6ulevk-poky-linux-gnueabi/u-boot-fw-utils/v2015.01+gitAUTOINC+92fa7f53f1-r0/temp/log.do_compile.3357)
ERROR: Logfile of failure stored in: /var/m300/fsl-release-bsp/build_small/tmp/work/imx6ulevk-poky-linux-gnueabi/u-boot-fw-utils/v2015.01+gitAUTOINC+92fa7f53f1-r0/temp/log.do_compile.3357
Log data follows:
| DEBUG: Executing shell function do_compile
| NOTE: make -j 4 CROSS_COMPILE=arm-poky-linux-gnueabi- CC=arm-poky-linux-gnueabi-gcc -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a7 --sysroot=/var/m300/fsl-release-bsp/build_small/tmp/sysroots/imx6ulevk -O2 -pipe -g -feliminate-unused-debug-types -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed V=1 mx6ul_14x14_evk_nand_config
| make -f ./scripts/Makefile.build obj=scripts/basic
| cc -Wp,-MD,scripts/basic/.fixdep.d -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -o scripts/basic/fixdep scripts/basic/fixdep.c
| rm -f .tmp_quiet_recordmcount
| /bin/bash ./scripts/multiconfig.sh mx6ul_14x14_evk_nand_config
| ***
| *** Can't find default configuration "configs/mx6ul_14x14_evk_nand_defconfig"!
| ***
| make: *** [mx6ul_14x14_evk_nand_config] Error 1
| ERROR: oe_runmake failed
| WARNING: exit code 1 from a shell command.
| ERROR: Function failed: do_compile (log file is located at /var/m300/fsl-release-bsp/build_small/tmp/work/imx6ulevk-poky-linux-gnueabi/u-boot-fw-utils/v2015.01+gitAUTOINC+92fa7f53f1-r0/temp/log.do_compile.3357)
ERROR: Task 4 (/var/m300/fsl-release-bsp/sources/poky/meta/recipes-bsp/u-boot/u-boot-fw-utils_2015.01.bb, do_compile) failed with exit code '1'
NOTE: Tasks Summary: Attempted 310 tasks of which 305 didn't need to be rerun and 1 failed.
Summary: 1 task failed:
/var/m300/fsl-release-bsp/sources/poky/meta/recipes-bsp/u-boot/u-boot-fw-utils_2015.01.bb, do_compile
Summary: There were 2 WARNING messages shown.
Summary: There was 1 ERROR message shown, returning a non-zero exit code.
管他的
直接從 <u-boot-imx>/configs/mx6ul_14x14_evk_nand_defconfig
複製過去
bitbake u-boot-fw-utils
... ok
➜ git git:(92fa7f5) ls tools/env
aes.c ctype.c env_flags.c fw_env.h fw_printenv README
aes.o ctype.o env_flags.o fw_env_main.c linux_string.c
crc32.c env_attr.c fw_env.c fw_env_main.o linux_string.o
crc32.o env_attr.o fw_env.config fw_env.o Makefile
終於看到 <u-boot-fw-utils>/tools/env/fw_printenv
➜ git git:(92fa7f5) file tools/env/fw_printenv
tools/env/fw_printenv: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.32, BuildID[sha1]=8171f598c1dff0921d4e5b9950542a4c2b152610, stripped
驗明正身... ok
複製到 fsl-release-bsp/build_small/images
切換到 m300
- 把開發環境上的 images folder 掛載到 m300 上的
/tmp/images
cd /tmp
mkdir images
mount -t nfs 192.168.1.200:/home/jeffrey/M300/fsl-release-bsp/build_small/images images
直接執行看看
root@M300:/tmp/images# ./fw_printenv
Cannot parse config file: No such file or directory
google 一下怎麼用
參考 http://elinux.org/U-boot_environment_variables_in_linux
m300 需要 /etc/fw_env.config
而 /etc/fw_env.config
需要下面的資訊
- the mtd device name
- the device offset
- the env size
- the flash sector size
從 /proc/mtd
得到 the mtd device name
和 the flash sector size
root@M300:/tmp/images# cat /proc/mtd
dev: size erasesize name
mtd0: 04000000 00020000 "boot"
mtd1: 01000000 00020000 "kernel"
mtd2: 01000000 00020000 "dtb"
mtd3: 04000000 00020000 "rootfs"
mtd4: 06000000 00020000 "test"
從 m300 一開機由 linux 提供的資訊可以得到 the device offset
5 cmdlinepart partitions found on MTD device gpmi-nand
Creating 5 MTD partitions on "gpmi-nand":
0x000000000000-0x000004000000 : "boot"
0x000004000000-0x000005000000 : "kernel"
0x000005000000-0x000006000000 : "dtb"
0x000006000000-0x00000a000000 : "rootfs"
0x00000a000000-0x000010000000 : "test"
gpmi-nand 1806000.gpmi-nand: driver registered.
剩 the env size
在 <u-boot-imx>\include\configs\mx6ul_14x14_evk.h
看到
#define CONFIG_ENV_OFFSET (8 << 20)
#define CONFIG_ENV_SECT_SIZE (128 << 10)
#define CONFIG_ENV_SIZE CONFIG_ENV_SECT_SIZE
128 << 10
是 0x20000
整理一下
- MTD device name -
/dev/mtd0
- Device offset -
0x0000
- Env. size -
0x20000
- Flash sector size -
0x4000000
所以 /etc/fw_env.config
為
# MTD device name Device offset Env. size Flash sector size
/dev/mtd0 0x0000 0x20000 0x4000000
直接執行看看
root@M300:/tmp/images# ./fw_printenv
Warning: Bad CRC, using default environment
bootargs=root=/dev/mtdblock0 console=ttyAM0 console=tty
bootcmd=
bootdelay=2
baudrate=38400
怪怪的
重開機進 uboot
=> printenv
baudrate=115200
bootargs=console=ttymxc0,115200 ubi.mtd=3 root=ubi0:rootfs rootfstype=ubifs mtdparts=gpmi-nand:64m(boot),16m(kernel),16m(dtb),64m(rootfs),-(test)
bootcmd=nand read ${loadaddr} 0x4000000 0x800000;nand read ${fdt_addr} 0x5000000 0x100000;bootz ${loadaddr} - ${fdt_addr}
bootcmd_mfg=run mfgtool_args;bootz ${loadaddr} ${initrd_addr} ${fdt_addr};
bootdelay=3
console=ttymxc0
ethact=FEC1
ethprime=FEC
fdt_addr=0x83000000
fdt_high=0xffffffff
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.idVendor=0x066F g_mass_storage.idProduct=0x37FF g_mass_storage.iSerialNumber="" mtdparts=gpmi-nand:64m(boot),16m(kernel),16m(dtb),64m(rootfs),-(test) clk_ignore_unused
panel=TFT43AB
Environment size: 873/131068 bytes
讀到哪去了...