Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libubootenv v0.3.2 cannot read env #20

Closed
nandra opened this issue Mar 23, 2022 · 10 comments
Closed

libubootenv v0.3.2 cannot read env #20

nandra opened this issue Mar 23, 2022 · 10 comments

Comments

@nandra
Copy link

nandra commented Mar 23, 2022

Hi, I'm having strange issue on cm4. I'm using v0.3.2 and print env ends with:

fw_printenv 
Cannot read environment, using default
Cannot read default environment from file

I checked config file and it's present with content:

cat /etc/fw_env.config
/dev/mmcblk0 0x800000 0x2000
/dev/mmcblk0 0x1000000 0x2000

I checked with dd and hexdump if env is present at offset and it is:

dd if=/dev/mmcblk0 of=env.bin bs=1024 skip=8192 count=1 | hexdump -C env.bin

print me :

00000000  ce a7 f3 12 04 61 3d 31  00 61 6c 74 62 6f 6f 74  |.....a=1.altboot|
00000010  63 6d 64 3d 72 75 6e 20  6d 65 6e 64 65 72 5f 61  |cmd=run mender_a|
00000020  6c 74 62 6f 6f 74 63 6d  64 3b 20 72 75 6e 20 62  |ltbootcmd; run b|
00000030  6f 6f 74 63 6d 64 00 61  72 63 68 3d 61 72 6d 00  |ootcmd.arch=arm.|
00000040  62 61 75 64 72 61 74 65  3d 31 31 35 32 30 30 00  |baudrate=115200.|
00000050  62 6f 61 72 64 3d 72 70  69 00 62 6f 61 72 64 5f  |board=rpi.board_|
00000060  6e 61 6d 65 3d 43 6f 6d  70 75 74 65 20 4d 6f 64  |name=Compute Mod|
00000070  75 6c 65 20 34 00 62 6f  61 72 64 5f 72 65 76 3d  |ule 4.board_rev=|
00000080  30 78 31 34 00 62 6f 61  72 64 5f 72 65 76 5f 73  |0x14.board_rev_s|
00000090  63 68 65 6d 65 3d 31 00  62 6f 61 72 64 5f 72 65  |cheme=1.board_re|
000000a0  76 69 73 69 6f 6e 3d 30  78 41 30 33 31 34 30 00  |vision=0xA03140.|
000000b0  62 6f 6f 74 5f 61 5f 73  63 72 69 70 74 3d 6c 6f  |boot_a_script=lo|
000000c0  61 64 20 24 7b 64 65 76  74 79 70 65 7d 20 24 7b  |ad ${devtype} ${|
000000d0  64 65 76 6e 75 6d 7d 3a  24 7b 64 69 73 74 72 6f  |devnum}:${distro|
000000e0  5f 62 6f 6f 74 70 61 72  74 7d 20 24 7b 73 63 72  |_bootpart} ${scr|
000000f0  69 70 74 61 64 64 72 7d  20 24 7b 70 72 65 66 69  |iptaddr} ${prefi|
00000100  78 7d 24 7b 73 63 72 69  70 74 7d 3b 20 73 6f 75  |x}${script}; sou|
00000110  72 63 65 20 24 7b 73 63  72 69 70 74 61 64 64 72  |rce ${scriptaddr|
00000120  7d 00 62 6f 6f 74 5f 65  66 69 5f 62 69 6e 61 72  |}.boot_efi_binar|
00000130  79 3d 6c 6f 61 64 20 24  7b 64 65 76 74 79 70 65  |y=load ${devtype|
00000140  7d 20 24 7b 64 65 76 6e  75 6d 7d 3a 24 7b 64 69  |} ${devnum}:${di|
00000150  73 74 72 6f 5f 62 6f 6f  74 70 61 72 74 7d 20 24  |stro_bootpart} $|
00000160  7b 6b 65 72 6e 65 6c 5f  61 64 64 72 5f 72 7d 20  |{kernel_addr_r} |
00000170  65 66 69 2f 62 6f 6f 74  2f 62 6f 6f 74 61 61 36  |efi/boot/bootaa6|
00000180  34 2e 65 66 69 3b 20 69  66 20 66 64 74 20 61 64  |4.efi; if fdt ad|
00000190  64 72 20 24 7b 66 64 74  5f 61 64 64 72 5f 72 7d  |dr ${fdt_addr_r}|
000001a0  3b 20 74 68 65 6e 20 62  6f 6f 74 65 66 69 20 24  |; then bootefi $|
000001b0  7b 6b 65 72 6e 65 6c 5f  61 64 64 72 5f 72 7d 20  |{kernel_addr_r} |
000001c0  24 7b 66 64 74 5f 61 64  64 72 5f 72 7d 3b 65 6c  |${fdt_addr_r};el|
000001d0  73 65 20 62 6f 6f 74 65  66 69 20 24 7b 6b 65 72  |se bootefi ${ker|
000001e0  6e 65 6c 5f 61 64 64 72  5f 72 7d 20 24 7b 66 64  |nel_addr_r} ${fd|
000001f0  74 63 6f 6e 74 72 6f 6c  61 64 64 72 7d 3b 66 69  |tcontroladdr};fi|
00000200  00 62 6f 6f 74 5f 65 66  69 5f 62 6f 6f 74 6d 67  |.boot_efi_bootmg|
00000210  72 3d 69 66 20 66 64 74  20 61 64 64 72 20 24 7b  |r=if fdt addr ${|
00000220  66 64 74 5f 61 64 64 72  5f 72 7d 3b 20 74 68 65  |fdt_addr_r}; the|
00000230  6e 20 62 6f 6f 74 65 66  69 20 62 6f 6f 74 6d 67  |n bootefi bootmg|
00000240  72 20 24 7b 66 64 74 5f  61 64 64 72 5f 72 7d 3b  |r ${fdt_addr_r};|
00000250  65 6c 73 65 20 62 6f 6f  74 65 66 69 20 62 6f 6f  |else bootefi boo|
00000260  74 6d 67 72 3b 66 69 00  62 6f 6f 74 5f 65 78 74  |tmgr;fi.boot_ext|
00000270  6c 69 6e 75 78 3d 73 79  73 62 6f 6f 74 20 24 7b  |linux=sysboot ${|
00000280  64 65 76 74 79 70 65 7d  20 24 7b 64 65 76 6e 75  |devtype} ${devnu|
00000290  6d 7d 3a 24 7b 64 69 73  74 72 6f 5f 62 6f 6f 74  |m}:${distro_boot|
000002a0  70 61 72 74 7d 20 61 6e  79 20 24 7b 73 63 72 69  |part} any ${scri|
000002b0  70 74 61 64 64 72 7d 20  24 7b 70 72 65 66 69 78  |ptaddr} ${prefix|
000002c0  7d 24 7b 62 6f 6f 74 5f  73 79 73 6c 69 6e 75 78  |}${boot_syslinux|
000002d0  5f 63 6f 6e 66 7d 00 62  6f 6f 74 5f 6e 65 74 5f  |_conf}.boot_net_|
000002e0  75 73 62 5f 73 74 61 72  74 3d 75 73 62 20 73 74  |usb_start=usb st|
000002f0  61 72 74 00 62 6f 6f 74  5f 70 63 69 5f 65 6e 75  |art.boot_pci_enu|
00000300  6d 3d 70 63 69 20 65 6e  75 6d 00 62 6f 6f 74 5f  |m=pci enum.boot_|
00000310  70 72 65 66 69 78 65 73  3d 2f 20 2f 62 6f 6f 74  |prefixes=/ /boot|
00000320  2f 00 62 6f 6f 74 5f 73  63 72 69 70 74 5f 64 68  |/.boot_script_dh|
00000330  63 70 3d 62 6f 6f 74 2e  73 63 72 2e 75 69 6d 67  |cp=boot.scr.uimg|
00000340  00 62 6f 6f 74 5f 73 63  72 69 70 74 73 3d 62 6f  |.boot_scripts=bo|
00000350  6f 74 2e 73 63 72 2e 75  69 6d 67 20 62 6f 6f 74  |ot.scr.uimg boot|
00000360  2e 73 63 72 00 62 6f 6f  74 5f 73 79 73 6c 69 6e  |.scr.boot_syslin|
00000370  75 78 5f 63 6f 6e 66 3d  65 78 74 6c 69 6e 75 78  |ux_conf=extlinux|
00000380  2f 65 78 74 6c 69 6e 75  78 2e 63 6f 6e 66 00 62  |/extlinux.conf.b|
00000390  6f 6f 74 5f 74 61 72 67  65 74 73 3d 6d 6d 63 30  |oot_targets=mmc0|
000003a0  20 6d 6d 63 31 20 75 73  62 30 20 70 78 65 20 64  | mmc1 usb0 pxe d|
000003b0  68 63 70 20 00 62 6f 6f  74 61 72 67 73 3d 63 6f  |hcp .bootargs=co|
000003c0  68 65 72 65 6e 74 5f 70  6f 6f 6c 3d 31 4d 20 38  |herent_pool=1M 8|
000003d0  32 35 30 2e 6e 72 5f 75  61 72 74 73 3d 31 20 73  |250.nr_uarts=1 s|
000003e0  6e 64 5f 62 63 6d 32 38  33 35 2e 65 6e 61 62 6c  |nd_bcm2835.enabl|
000003f0  65 5f 63 6f 6d 70 61 74  5f 61 6c 73 61 3d 30 20  |e_compat_alsa=0 |

Am i missing something? Thanks.

@sbabic
Copy link
Owner

sbabic commented Mar 23, 2022

Cannot read default environment from file ==> you have to provide u-boot-initial-env as built by U-Boot.

From your tests, the only reason I can imagine is that the environment size in U-Boot is different as 0x2000 you set in fw_env.config.
You can try fw_setenv and check if U-Boot is validating the environment or reports a CRC error, in the last case a mismatch in size is the most probable cause.

@nandra
Copy link
Author

nandra commented Mar 23, 2022

Hi, thanks for response.

After copying manually u-boot-init-env I can see output on fw_printenv which is default env. I'll check other things.

@nandra nandra closed this as completed Mar 23, 2022
@TopperBG
Copy link

TopperBG commented Apr 7, 2022

How did you manually copy u-boot-init-env ?

@nandra
Copy link
Author

nandra commented Apr 7, 2022

env size in config file was incorrect. When fix it it works as expected.

@TopperBG
Copy link

TopperBG commented Apr 8, 2022

env size in config file was incorrect. When fix it it works as expected.

Yes I understood your particular problem, glad you resolve it, but my question was - how did you generate and copy u-boot-init-env. I'm working with Yocto thud and there isn't generation of u-boot-init-env as in yocto hardknott and try to figure out how to achieve that file. So I do asking how you copy it.

@nandra
Copy link
Author

nandra commented Apr 8, 2022

I'm using meta-mender and magic in that layer ;) (I didn't study it sorry)

@TopperBG
Copy link

TopperBG commented Apr 8, 2022

I'm using meta-mender and magic in that layer ;) (I didn't study it sorry)

Ok understood, last question - what version of Yocto did you use, Hardknott?

@nandra
Copy link
Author

nandra commented Apr 8, 2022

dunfell

@simon-rechermann
Copy link

simon-rechermann commented May 23, 2023

Hi,
I have the same issue with v0.3.2 and I'm on kirkstone so uboot version 2022.04+fsl+g181859317b. The second part Cannot read default environment from file does not bother me. I have my environment on the mmc device/SD card. But I don't know why I get the first error Cannot read environment, using default. Here is the content of my fw_env.config file:
cat /etc/fw_env.config /dev/mmcblk0 0x500000 0x1da
and my uboot env read with hexdump:

hexdump /dev/mmcblk0 -C -s 0x500000 -n 480
00500000  57 d5 9b 54 62 6f 6f 74  61 72 67 73 3d 63 6f 6e  |W..Tbootargs=con|
00500010  73 6f 6c 65 3d 74 74 79  53 30 2c 31 31 35 32 30  |sole=ttyS0,11520|
00500020  30 20 72 6f 6f 74 3d 2f  64 65 76 2f 72 61 6d 30  |0 root=/dev/ram0|
00500030  20 72 77 20 72 6f 6f 74  64 65 6c 61 79 3d 32 00  | rw rootdelay=2.|
00500040  62 6f 6f 74 63 6d 64 3d  73 65 74 65 6e 76 20 66  |bootcmd=setenv f|
00500050  69 74 5f 69 6d 61 67 65  5f 61 64 64 72 20 30 78  |it_image_addr 0x|
00500060  38 30 30 30 30 30 30 30  3b 6d 6d 63 20 72 65 61  |80000000;mmc rea|
00500070  64 20 24 7b 66 69 74 5f  69 6d 61 67 65 5f 61 64  |d ${fit_image_ad|
00500080  64 72 7d 20 30 78 34 38  34 30 20 30 78 31 37 65  |dr} 0x4840 0x17e|
00500090  34 38 3b 62 6f 6f 74 6d  20 24 7b 66 69 74 5f 69  |48;bootm ${fit_i|
005000a0  6d 61 67 65 5f 61 64 64  72 7d 3b 00 62 6f 6f 74  |mage_addr};.boot|
005000b0  64 65 6c 61 79 3d 34 00  65 74 68 31 61 64 64 72  |delay=4.eth1addr|
005000c0  3d 30 30 3a 30 34 3a 39  46 3a 30 37 3a 37 34 3a  |=00:04:9F:07:74:|
005000d0  33 32 00 65 74 68 32 61  64 64 72 3d 30 30 3a 30  |32.eth2addr=00:0|
005000e0  34 3a 39 46 3a 30 37 3a  37 34 3a 32 44 00 65 74  |4:9F:07:74:2D.et|
005000f0  68 33 61 64 64 72 3d 30  30 3a 30 34 3a 39 46 3a  |h3addr=00:04:9F:|
00500100  30 37 3a 37 34 3a 32 45  00 65 74 68 34 61 64 64  |07:74:2E.eth4add|
00500110  72 3d 30 30 3a 30 34 3a  39 46 3a 30 37 3a 37 34  |r=00:04:9F:07:74|
00500120  3a 33 30 00 65 74 68 35  61 64 64 72 3d 30 30 3a  |:30.eth5addr=00:|
00500130  30 34 3a 39 46 3a 30 37  3a 37 34 3a 32 46 00 65  |04:9F:07:74:2F.e|
00500140  74 68 61 64 64 72 3d 30  30 3a 30 34 3a 39 46 3a  |thaddr=00:04:9F:|
00500150  30 37 3a 37 34 3a 33 31  00 66 64 74 63 6f 6e 74  |07:74:31.fdtcont|
00500160  72 6f 6c 61 64 64 72 3d  66 62 63 30 65 66 39 30  |roladdr=fbc0ef90|
00500170  00 66 6d 61 6e 5f 75 63  6f 64 65 3d 66 62 63 32  |.fman_ucode=fbc2|
00500180  34 65 37 30 00 66 73 6c  5f 62 6f 6f 74 63 6d 64  |4e70.fsl_bootcmd|
00500190  5f 6d 63 69 6e 69 74 63  6d 64 5f 73 65 74 3d 79  |_mcinitcmd_set=y|
005001a0  00 69 70 61 64 64 72 3d  31 30 30 2e 31 2e 31 2e  |.ipaddr=100.1.1.|
005001b0  32 00 73 74 64 65 72 72  3d 73 65 72 69 61 6c 00  |2.stderr=serial.|
005001c0  73 74 64 69 6e 3d 73 65  72 69 61 6c 00 73 74 64  |stdin=serial.std|
005001d0  6f 75 74 3d 73 65 72 69  61 6c 00 00 00 00 00 00  |out=serial......|

out=serial is the last env variable so I think the offset and size specified in the fw_env.config file should fit. Are the uboot env formats that are not compatible with the libubootenv? But I'm using the standard uboot-mkimage from yocto kirkstone to compile the environment, that is provided by poky/meta/recipes-bsp/u-boot/u-boot-tools_2022.01.bb where also the poky/meta/recipes-bsp/u-boot/libubootenv_0.3.2.bb file is located. Maybe I'm using the wrong size? Does it have to be blocksize aligned or something like that? I already tried 0x200 and 0x400 as size but it gives me the same error.

@DavidAntliff
Copy link

DavidAntliff commented Jun 12, 2023

Moved to #25.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants