This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linux: Beaglebone black dual-boot using u-boot environment variables from user space

Tool/software: Linux

Hi,

I am trying to implement booting Linux from images stored at different partitions on eMMC for Beaglebone black. The idea is to change u-boot environment variables from user space to boot from a different partition after images are updated. After some research, there are a couple of questions. Please help:

1. I tried two different machines using Yocto build system, "am35x-evm" and "beaglebone". "am35x-evm" places the u-boot environment variables in a file in the SD card. "beaglebone" places them at some locations in eMMC. Is it possible to save the u-boot environment in a file on eMMC? If yes, how do we do that?

2. How do we change u-boot environment variables from user space if they are stored in eMMC? The standard way seems to be using fw_printenv utility.

- How do we build and install it using Yocto?

- Where do we find the locations and the sizes of the env variables to configure /etc/fw_env.config file?

3. If we save the u-boot environment variables in a file, what is a good way of accessing them from user space?

4. Now I have u-boot, zImage, MLO, dtb in the same disk partition on the SD card. Can Linux boot from zImage and dbt that reside on a different partition from the bootloaders? If yes, how to achieve that?

Thank you for your help!

  • Hello Matt,

    Matt Tsai52 said:
    1. I tried two different machines using Yocto build system, "am35x-evm" and "beaglebone". "am35x-evm" places the u-boot environment variables in a file in the SD card. "beaglebone" places them at some locations in eMMC. Is it possible to save the u-boot environment in a file on eMMC? If yes, how do we do that?

    You can save the u-boot environment in a file on eMMC in this way.

    $ cd <Processor SDK>/
    $ make u-boot_clean && make u-boot
    $ cd board-support/u-boot-<version>/
    $ ARCH=arm make menuconfig

    Environment  ---> (1:1) Device and partition for where to store the environemt in FAT
    Changing the (0:1) to (1:1) will make the uenv.env to save and load from eMMC.
    Exit
    Exit
    Do you wish to save your new configuration?
    < Yes >
    $ cp .config configs/am335x_evm_defconfig
    $ cd ../../
    $ make u-boot_clean && make u-boot


    Matt Tsai52 said:

    2. How do we change u-boot environment variables from user space if they are stored in eMMC? The standard way seems to be using fw_printenv utility.

    - How do we build and install it using Yocto?



    fw_printenv and fw_setenv are part of u-boot-fw-utils package. You have them installed by default on the Processor SDK. If you want to build them on the OE build system, you can done it with MACHINE=am335x-evm bitbake u-boot-fw-utils command.


    Matt Tsai52 said:
    - Where do we find the locations and the sizes of the env variables to configure /etc/fw_env.config file?

    Comment out these two lines in the /etc/fw_env.config.
    # 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

    Add this line to set and print uboot.env which is located in MMC.
    # VFAT example
    /run/media/mmcblk0p1/uboot.env    0x0000          0x20000

    Add this line to set and print uboot.env which is located in eMMC.
    # VFAT example
    /run/media/mmcblk1p1/uboot.env    0x0000          0x20000

    Where the U-Boot saves the uboot.env with the saveenv command it loads it from the same device MMC or eMMC during boot.
    Env. size is 0x20000 since the CONFIG_ENV_SIZE in <Processor SDK>/board-support/u-boot-<version>/include/configs/am335x_evm.h is (128 << 10).


    Matt Tsai52 said:
    3. If we save the u-boot environment variables in a file, what is a good way of accessing them from user space?

    The best way to accessing the u-boot environment variables from user space is by using fw_printenv and fw_setenv commands, or by using the same approach which they use to manipulate the uboot.env.


    Matt Tsai52 said:
    4. Now I have u-boot, zImage, MLO, dtb in the same disk partition on the SD card. Can Linux boot from zImage and dbt that reside on a different partition from the bootloaders? If yes, how to achieve that?

    Yes, it can. Please see this thread.


    Note: To fix the "FAT: Misaligned buffer address (9def0ed8)" issue which appears while saving the environment you will need to apply this patch.

    Best regards,
    Kemal

  • Hi Kemal,

    I have further questions regarding your answers. Hope I can get your clarification. Thank you!

    First, do you suggest to store u-boot environment variables in a file in FAT rather than some location on the eMMC?

    For 1, I am not sure what build your environment you use. I tried to use run the menuconfig using Yocto but it did not work:

    $ bitbake u-boot-ti-staging -c menuconfig

    ...

    ERROR: Task do_menuconfig does not exist for target u-boot-ti-staging

    ...

    So I had to run this in the Yocto build environment and hopefully it does the same thing. Can you please confirm?

    build/tmp/work/am335x_evm-poky-linux-gnueabi/u-boot-ti-staging/2018.01+gitAUTOINC+8b2f1df4b5-r19/build$ ARCH=arm make menuconfig

    For 2,  I am not sure if I understand it correctly. Please explain if my understanding is not correct:

    Do u-boot environment variables always store as a file in eMMC or MMC (SD card)?

    If they can be store at some particular location on eMMC, how do we configure the "Device offset", "Env. size", ...etc. in /etc/fw_env.config?

    Thank you for your help!

  • Matt Tsai52 said:
    First, do you suggest to store u-boot environment variables in a file in FAT rather than some location on the eMMC?


    It will depend on your project requirements, if your goal is uboot.env to be widely available for more platforms and easily accessible I suggest you to save it to the FAT, else you can save it to eMMC's boot partition. To do so.

    $ cd <Processor SDK>/
    $ make u-boot_clean && make u-boot
    $ cd board-support/u-boot-<version>/
    $ ARCH=arm make menuconfig

    Environment  ---> Select the location of the environment (Environment in an MMC device)  ---> (X) Environment in an MMC device
    Exit
    Exit
    Do you wish to save your new configuration?
    < Yes >
    $ cp .config configs/am335x_evm_defconfig
    $ git apply 0001-am335x_evm.h-Save-uboot.env-to-dev-mmcblk1boot1.patch
    $ cd ../../
    $ make u-boot_clean && make u-boot

    Boot and login, then:

    root@am335x-evm:~# vi /etc/fw_env.config

    Comment out these two lines in the /etc/fw_env.config.
    # 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

    Change these lines to be able to set and print the environment variables which are saved to /dev/mmcblk1boot1.

    # Block device example
    #/dev/mmcblk0        0xc0000        0x20000
    #/dev/mmcblk0        -0x20000    0x20000

    to

    # Block device example
    /dev/mmcblk1boot1    0x00000        0x20000
    /dev/mmcblk1boot1    0x20000        0x20000

    To make the partition writable.
    root@am335x-evm:~# echo 0 > /sys/class/block/mmcblk1boot1/force_ro


    Matt Tsai52 said:
    For 1, I am not sure what build your environment you use. I tried to use run the menuconfig using Yocto but it did not work:

    I use the latest Processor SDK.


    Matt Tsai52 said:

    $ bitbake u-boot-ti-staging -c menuconfig

    ...

    ERROR: Task do_menuconfig does not exist for target u-boot-ti-staging

    ...


    -c menuconfig will not work on u-boot-ti-staging, it works only with linux-ti-staging and busybox


    Matt Tsai52 said:

    So I had to run this in the Yocto build environment and hopefully it does the same thing. Can you please confirm?

    build/tmp/work/am335x_evm-poky-linux-gnueabi/u-boot-ti-staging/2018.01+gitAUTOINC+8b2f1df4b5-r19/build$ ARCH=arm make menuconfig

    For 2,  I am not sure if I understand it correctly. Please explain if my understanding is not correct:


    Please, read this thread.


    Matt Tsai52 said:
    Do u-boot environment variables always store as a file in eMMC or MMC (SD card)?

    Please, read this thread.


    Matt Tsai52 said:
    If they can be store at some particular location on eMMC, how do we configure the "Device offset", "Env. size", ...etc. in /etc/fw_env.config?

    Please, read this thread.


    0001-am335x_evm.h-Save-uboot.env-to-dev-mmcblk1boot1.patch

  • Hi Kemal,

    The FAT approach to store u-boot environment variables in a file seems to be a more flexible solution to me. I am able to make it work with u-boot-fw-utils on SD card.

    The threads you referred to seem to imply that my way of using "ARCH=arm make menuconfig" for u-boot should work. I will try it with the eMMC.

    Thank your for your help!