Getting U-boot's Version from Userspace
Asked Answered
C

8

20

Does anyone know of a way to get U-boot version installed from userspace? There is the fw_printenv command that provides access to U-boot's environment variables, but not the version.

Culliton answered 25/4, 2011 at 18:35 Comment(0)
H
3

There's no defined way to do this. Once Linux boots, u-boot is no longer running and it's RAM is reclaimed for Linux's use. Linux doesn't even know about u-boot. Nor does it have to have been booted by u-boot.

If you really want to do this, the only way to do it is to add the u-boot version to the kernel's command line, write code to scan the u-boot image in flash for it's version, or something even nastier.

Horseshoe answered 25/4, 2011 at 19:42 Comment(2)
Where there is no defined way to do this, there are reliable ways to extract the data from the flash you booted from. A bulletproof way of accomplishing this would be to pass your u-boot version to the kernel (uboot=blah) and then read /proc. If you're want to make sure you know for sure what version you booted with, not just whats on the flash.Swanee
Disagree, if u-boot is still a mounted partition then you can extract this info from it with strings. Maybe not standard but doable for most.Paralipomena
J
23

If U-boot is located in mtd0, you can get version info as follows:

root@SUPERWIFI:/proc# strings /dev/mtd0 | grep U-Boot    
U-Boot 1.1.4-g1c8343c8-dirty (Feb 28 2014 - 13:56:54)
U-Boot
Now running in RAM - U-Boot at: %08lx
Jemina answered 31/7, 2014 at 3:25 Comment(2)
I've used a similar version of this, extending the grep to be a little more precise i.e. 'U-Boot [0-9]*\.[0-9]*.*\(Build.*)' to return less. This can be optimized if you have a general idea of where your u-boot image lives on the flash device. If you know for a fact that it's in the first megabyte, you can use dd to siphon off the first meg of data before you run strings on it to save yourself processing time.Swanee
Thanks. Use dd to save the processing time.Jemina
T
5

Just an update for this. In our version of U-Boot we changed the code for main_loop() in main.c to this:

#ifdef CONFIG_VERSION_VARIABLE
    char *oldver=getenv("ver");
    if(oldver==0 ||strcmp(oldver,version_string))
    {
        setenv("ver", version_string);  /* set version variable */
        saveenv();
    }
#endif /* CONFIG_VERSION_VARIABLE */

So setenv/saveenv is only called, if needed by an update. In our firmware we added

/sbin/fw_printenv -n ver > /var/config/u-boot.ver

to make the u-boot version public available.

Term answered 18/3, 2019 at 12:8 Comment(0)
M
4

An alternative solution is to read the version directly from the u-boot binary file (can be even embedded in an image file containing other binaries as well like e.g. the first stage bootloader) with e.g. mmcblk0boot0 as partition (of device mmcblk0) the bootloader resides in:

sudo grep -a --null-data U-Boot /dev/mmcblk0boot0

Site note: Does work not only for Arch Linux but e.g. Ubuntu as well.

Mestee answered 27/7, 2017 at 7:27 Comment(0)
H
3

There's no defined way to do this. Once Linux boots, u-boot is no longer running and it's RAM is reclaimed for Linux's use. Linux doesn't even know about u-boot. Nor does it have to have been booted by u-boot.

If you really want to do this, the only way to do it is to add the u-boot version to the kernel's command line, write code to scan the u-boot image in flash for it's version, or something even nastier.

Horseshoe answered 25/4, 2011 at 19:42 Comment(2)
Where there is no defined way to do this, there are reliable ways to extract the data from the flash you booted from. A bulletproof way of accomplishing this would be to pass your u-boot version to the kernel (uboot=blah) and then read /proc. If you're want to make sure you know for sure what version you booted with, not just whats on the flash.Swanee
Disagree, if u-boot is still a mounted partition then you can extract this info from it with strings. Maybe not standard but doable for most.Paralipomena
M
1

In my devices UBoot automatically creates a "ver" environment variable containing its version:

U-Boot > printenv
baudrate=115200
ethact=FEC ETHERNET
ethaddr=24-db-ad-00-00-08
bootdelay=3
bootcmd=bootm fc080000 - fc060000
bootargs=console=ttyCPM0,115200n8 rdinit=/sbin/init
stdin=serial
stdout=serial
stderr=serial
ver=U-Boot 2009.03-svn9684 (Mar 08 2010 - 17:08:32)

Environment size: 253/131068 bytes
U-Boot >

I don't use fw_printenv, but I would imagine that this variable gets passed along as well. Maybe you already have something similar in your system?

UPDATE (5/23/2012): I added fw_printenv to my linux image and can confirm that I do see the "ver" variable:

[root@ST600 /]# fw_printenv
baudrate=115200
ethact=FEC ETHERNET
ethaddr=24-db-ad-00-00-08
stdin=serial
stdout=serial
stderr=serial
ver=U-Boot 2009.03-svn9684 (Mar 11 2010 - 09:43:08)
bootcmd=bootm fc080000 - fc060000
bootdelay=3
bootargs=console=ttyCPM0,115200n8 rdinit=/sbin/init panic=10 mem=32m
[root@ST600 /]#
Masterson answered 22/2, 2012 at 14:57 Comment(2)
This "works fine" until you update your U-Boot. After that moment and unless you change some environment variables and say 'save' from U-Boot prompt, you will be getting your old U-Boot's version this way. That's because fw_printenv provides access to the stored environment, not to the current one (where your new U-Boot will put its version). The solution would be to make your U-Boot check if the stored and current values for 'ver' differ and re-flash the environment if so, but that may also bring some undesirable effects.Overtake
You also have to make sure that U-Boot is built with CONFIG_VERSION_VARIABLE=y for ver to appear in the environment.Mandamus
G
1

Try to read uboot version this way:

  1. Find uboot partition, eg. for MTD device:

    cat /proc/mtd

  2. For /dev/mtd5:

    cat /dev/mtd5 | hexdump -C -n 64

Garamond answered 31/10, 2013 at 14:1 Comment(0)
G
0

You can't rely on fw_printenv if you want to know u-boot version.

fw_printenv just looks for the printenv partition and dumps its data. So it's OK for normal variables, but it's not OK for the "ver" variable, which is dynamic, and whose value is initialized by u-boot when it boots. The value of this variable doesn't remain after u-boot exit, except if you manually save it to environment.

For example, on my board, if I print the "ver" variable from u-boot prompt:

U-Boot >      printenv ver
ver=U-Boot 2009.11-00393-g5ca9497-dirty (Nov 26 2012 - 11:08:44)

This is the real version of u-boot, coming from u-boot itself.

Now, if I boot my board and use fw_printenv:

el@board # fw_printenv | grep ver=
ver=U-Boot 2009.11-00323-gbcc6e0e (Sep 21 2012 - 11:07:19)

As you can see, it's different. Because it happens that I have a "ver" variable defined in my environment. And it doesn't match the real u-boot version.

Of course, I could go back to u-boot, use "saveenv" to update the "ver" value in the environment. Then the two values would match. But then, I should always update the environment after changing u-boot.

So, my conclusion is that using fw_printenv to get u-boot version is definitely not a good idea.

Gannie answered 21/12, 2012 at 8:43 Comment(0)
P
0

If u-boot is residing in an MTD partition then this will work:

U_BOOT_VER=$(for part in `grep u-boot-[01] /proc/mtd | cut -f 1 -d ':'`; do strings /dev/${part} | grep "^U-Boot.*("; break; done)
Paralipomena answered 10/8, 2018 at 18:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.