Flashing a yocto image from uboot

  • Hi @all,


    i generated a minimal yocto image for efusA9 with .sdimg extension. The image can not be written/flashed on the NAND flash due to the NAND flash size capacity. I need to write/flash the image from uboot to the internal 4Gbytes emmc.

    Is there any u-boot command which can flash the image from USB to the emmc?

    I know i can perform this from linux using dd command, I simply put the image on the usb, mount the usb and use dd to flash the image on /dev/mmcblk2 which represents the emmc card. However, I need to use u-boot to detect the USB and if it finds an image file, then it flashes it on the emmc.

    Thanks in advance,


    Ahmed

  • Hi,


    just for clarification, if you want to write to the NAND flash you should write the filesystem with the extension .ubifs. I think the minimal image is smaller then the NAND flash size.

    If you want to to write the filesystem to the eMMC then you should use the filesystem with the extension .ext4.


    UBoot only supports raw write commands, e.g. mmc wirte (block wise).


    I know i can perform this from linux using dd command, I simply put the image on the usb, mount the usb and use dd to flash the image on /dev/mmcblk2 which represents the emmc card. However, I need to use u-boot to detect the USB and if it finds an image file, then it flashes it on the emmc.


    In linux you can either write the filesystem with dd to eMMC or you can mount the rootfs.ext4 and copy the files high level to the eMMC ext4 partition.


    We recommend to use NAND flash if the ubifs filesize fits.


    Your F&S Support Team

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Thanks for your reply.

    So i understood that it is possible to write a yocto image on the emmc from the uboot console. is it correct?

    Again i will describe what i need to do:

    I have an image called "minimal.img" it has 2 partitions (partition 1 is FAT32 and partition 2 has the root file system). I can write this image from linux user space on the emmc using:

    dd if=/home/root/minimal.img of=/dev/mmcblk2 where /dev/mmcblk2 is the emmc

    How can i perform such command from u-boot? is it mmc write and if yes what are the correct arguments for mmc write?

    Thanks in advance.

  • Hi,


    yes it is possible to write an yocto image to emmc. Yes you can use the mmc write command. The syntax of this command is:


    Code
    1. mmc write addr blk# cnt


    If you use the command mmc write you have to convert the byte size of the image to block size. Every block has 512 bytes. So if you have an image with the length of 1048576 bytes, the blocksize is 1048576/512 = 2048 blocks in hex 0x800.


    For example you want to write the image with the length 1048576 bytes to mmc device 0 at offset 0. The image is available at $loadaddr. The command is

    Code
    1. mmc write $loadaddr 0x0 0x800


    Here are the following steps which you have to do:


    1. Transfer image to your Board
      1. tftp minimal.img
    2. Switch to emmc (I guess device 0)
      1. mmc dev 0 0
    3. Write to emmc (I assume length is 10 MB (10485760 Bytes = 20480 Block / 0x5000 block)
      1. mmc write $loadaddr 0x0 0x5000
    4. Now you should be able to read this partitions
      1. ls mmc 0:1 and ls mmc 0:2


    Your F&S Support Team

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Thank you so much! It works flawlessly. Another small question please. I understood that we must load the minimal.img in RAM first to write it later on the emmc. is it correct?

    In case yes, then this means if i have another yocto image that is larger than the RAM size, then i can not flash that image on the emmc. correct?

    Thanks in advance.

  • Hi,


    you´re welcome. Yes this is correct, first you have to transfer the image to the RAM and after that you can write it to the emmc.


    Yes if the image size is bigger than the RAM size, you are not able to transfer and write it in one piece. But normally it should work if you split the image in different parts and write it with the correct offsets.


    Your F&S Support Team

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • If your image is coming from a filesystem for example on USB stick or SD card, then you can also read the file in parts to RAM and then store each part on eMMC. Then you do not need to split up the file beforehand.


    The generic form of the load command is:

    Code
    1. load <device> <n> <ramaddr> <filename> <bytes> <offset>

    For example if you have 512MB of RAM, you can load your image in chunks of 256MB (0x10000000 bytes or 0x80000 sectors).

    Code
    1. load usb 0 $loadaddr emmc.img 10000000 0
    2. mmc write $loadaddr 0 80000
    3. load usb 0 $loadaddr emmc.img 10000000 10000000
    4. mmc write $loadaddr 80000 80000
    5. load usb 0 $loadaddr emmc.img 10000000 20000000
    6. mmc write $loadaddr 100000 80000
    7. load usb 0 $loadaddr emmc.img 10000000 30000000
    8. mmc write $loadaddr 180000 80000
    9. ...

    Please note that this is slightly more complicated if you use an SD card because you have to switch mmc devices in between.


    See also chapters "5.8.5 High-Level Read From Filesystem" and "5.9.3 Save to SD Card or eMMC" in the current Linux on F&S boards documentation. Chapters "5.10.2 Copy an External SD Card to Local eMMC" and "5.10.3 Copy Individual Files From USB Stick to Local eMMC" show similar examples in more detail.

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.