Skip to main content

Miscellaneous

Root file system on SD card

By default, U-Boot, kernel, and root file system are stored on the onboard eMMC flash. The instructions in this section show how to put the root file system on an external SD card. The U-Boot, kernel and dtb files are still stored on the eMMC.

Detect which device file the SD card is available on

  1. Boot into Linux without having an SD card inserted in the SD card slot
  2. Insert the SD card and you will see output similar to below in the terminal. In this example the device file to use will be /dev/mmcblk1p1
    mmc1: new SD card at address 9047
    mmcblk1: mmc1:9047 SU01G 968 MiB
    mmcblk1: p1

Put the root file system on the SD card

  1. Make sure you have downloaded and unpacked the UUU bundle (from imx.embeddedartists.com) for the board you are using.

  2. Open the file <mfgtool dir>/full_tar.uuu

  3. At the end of this file you will see a list of commands used to burn the file system to the target. The commands use the variable mmc (${mmc}) to indicate which mmc device to use. Instead of using a variable you can change to the device previously retrieved (mmcblk1p1 in this example). See the excerpt below for how you could change the file.

    #FBK: ucmd mmc=`cat /tmp/mmcdev`; mkfs.ext3 -F -E nodiscard -j /dev/mmcblk${mmc}p2
    #FBK: ucmd mkdir -p /mnt/ext3
    #FBK: ucmd mmc=`cat /tmp/mmcdev`; mount -t ext3 /dev/mmcblk${mmc}p2 /mnt/ext3

    FBK: ucmd mkfs.ext3 -F -E nodiscard -j /dev/mmcblk1p2
    FBK: ucmd mkdir -p /mnt/ext3
    FBK: ucmd mount -t ext3 /dev/mmcblk1p2 /mnt/ext3

    FBK: acmd export EXTRACT_UNSAFE_SYMLINKS=1; tar -jx -C /mnt/ext3
    FBK: ucp files/ea-image-base-imx8mmea-ucom.tar.bz2 t:-
    FBK: Sync
    FBK: ucmd umount /mnt/ext3
  4. Now you can run uuu with full.tar to update the target. See the Deploy Images chapter for more information about deploying images.

note

In this section we are modifying an existing configuration file. An alternative is to copy the configuration file and renaming it instead of modifying it.

Update U-Boot variables

  1. Boot into U-Boot
  2. Set mmcautodetect to no. If you don’t do this U-Boot will detect and set the value of mmcroot by itself, that is, overwriting any value you set.
    setenv mmcautodetect no
  3. Set mmcroot to the device file for the SD card
    setenv mmcroot '/dev/mmcblk1p1 rootwait rw'
  4. Save the changes
    saveenv
  5. When you reset/boot the board it will use the root file system stored on the SD card

Build Linux kernel from source code

You can build the Linux kernel outside of Yocto by following the instructions in this section. Please note that it is recommended that the kernel is built by Yocto when you are generating your final distribution images since there can be dependencies between the root file system and the kernel.

The instructions in this section assume that you have built and installed the toolchain as described in meta-toolchain section.

Setup the environment variables for the toolchain. We are using the same installation path as described in the meta-toolchain section. If you have installed the toolchain in a different path use that path in the instructions below.

source /opt/fsl-imx-fb/4.14-sumo/environment-setup-cortexa9hfneon-poky-linux-gnueabi

If you are compiling Linux for an iMX8 based board then run the following command to avoid linker error(s).

unset LDFLAGS

Get the source code from the Embedded Artists GitHub repository. In this example we are checking out branch ea_4.14.78.

git clone https://github.com/embeddedartists/linux-imx.git
cd linux-imx
git checkout ea_4.14.78

Use Embedded Artists kernel configurations (use ea_imx8_defconfi instead if compiling for an iMX8M target).

make ea_imx_defconfig

(Optional) If you want to change kernel configurations you can at this point run the menuconfig tool.

make menuconfig

Build the kernel.

make

When the build process has finished the kernel will be available here: arch/arm/boot/zImage. Device tree files are available in the following directory: arch/arm/boot/dts. A compiled device tree file has the file extension dtb.

Update the device

You have several options to update your device with the new kernel. The first option is to use the manufacturing tool / UUU as described in the Deploy Images chapter. The other option is to update the boot partition from within Linux as described in the Update from within Linux section.

Build U-Boot from source code

You can build U-Boot outside of Yocto by following the instructions in this section.

The instructions in this section assume that you have built and installed the toolchain as described in meta-toolchain section.

Setup the environment variables for the toolchain. We are using the same installation path as described in the meta-toolchain section. If you have installed the toolchain in a different path use that path in the instructions below.

source /opt/fsl-imx-fb/4.14-sumo/environment-setup-cortexa9hfneon-poky-linux-gnueabi

If you are compiling Linux for an iMX8 based board then run the following command to avoid linker error(s).

unset LDFLAGS

Get the source code from the Embedded Artists GitHub repository. In this example we are checking out branch ea_v2018.03.

git clone https://github.com/embeddedartists/uboot-imx.git
cd uboot-imx
git checkout ea_v2018.03

Use the Embedded Artists configuration for the COM board you are using. In the example below the configuration for the iMX6 SoloX COM board is used.

make mx6sxea-com_config

Build the bootloader

make

When the build process has finished the U-Boot image will be available directly in the uboot-imx directory.

Update the device

Use the manufacturing tool / UUU as described in the Deploy Images chapter to update the device with the new U-Boot image

Extra steps for iMX8

note

Instead of running these commands manually you can use devtool as described in the Use devtool section.

For the iMX8 it is not enough to compile the U-Boot - it must also be packaged together with these components to get something that can be flashed:

  • U-Boot (including SPL)
  • ARM Trusted Firmware
  • DDR Firmware
  • HDMI Firmware

This is normally handled in yocto automatically but if you want to do it outside of yocto these are the steps.

  1. Build the U-Boot as explained above. These steps will assume that the folder ~/work/uboot-imx/ was used - otherwise change accordingly below.

  2. Download and build the ARM Trusted Firmware

    cd ~/work/
    git clone https://source.codeaurora.org/external/imx/imx-atf
    cd imx-atf
    git checkout imx_4.14.78_1.0.0_ga
    source /opt/fsl-imx-wayland/4.14-sumo/environment-setup-aarch64-poky-linux
    unset LDFLAGS

    For iMX8M Mini uCOM:

    make PLAT=imx8mm bl31

    For iMX8M Quad COM:

    make PLAT=imx8mq bl31
  3. Download and extract the DDR/HDMI Firmware and answer yes to the end user license agreement.

    cd ~/work/
    wget https://www.nxp.com/lgfiles/NMG/MAD/YOCTO/firmware-imx8.0.bin
    chmod +x firmware-imx-8.0.bin
    ./firmware-imx-8.0.bin
  4. Download the tool to create the final image

    cd ~/work/
    git clone https://source.codeaurora.org/external/imx/imx-mkimage
    cd imx-mkimage
    git checkout imx_4.14.78_1.0.0_ga
  5. Gather all common files

    cp ../firmware-imx-8.0/firmware/ddr/synopsys/lpddr4_pmu_* iMX8M/
    cp ../firmware-imx-8.0/firmware/hdmi/cadence/signed_* iMX8M/
    cp ../uboot-imx/u-boot.bin iMX8M/
    cp ../uboot-imx/u-boot-nodtb.bin iMX8M/
    cp ../uboot-imx/spl/u-boot-spl.bin iMX8M/
    cp ../uboot-imx/tools/mkimage iMX8M/mkimage_uboot
  6. Gather all target specific files

    For iMX8M Mini uCOM:

    cp ../imx-atf/build/imx8mm/release/bl31.bin iMX8M/
    cp ../uboot-imx/arch/arm/dts/fsl-imx8mm-ea-ucom-kit_v2.dtb iMX8M/fsl-imx8mm-evk.dtb

    For iMX8M Quad COM:

    cp ../imx-atf/build/imx8mq/release/bl31.bin iMX8M/
    cp ../uboot-imx/arch/arm/dts/fsl-imx8mq-ea-com-kit_v2.dtb iMX8M/fsl-imx8mq-evk.dtb
  7. Build to get iMX8M/flash.bin and then rename it to match the file name used in UUU.

    For iMX8M Mini uCOM:

    make SOC=iMX8MM flash_evk
    mv iMX8M/flash.bin iMX8M/imx-boot-imx8mmea-ucom-sd.bin

    For iMX8M Quad COM:

    make SOC=iMX8MQ flash_evk
    mv iMX8M/flash.bin iMX8M/imx-boot-imx8mqea-com-sd.bin
  8. Use the UUU tool as described in Deploy Images to update the system with the bootloader.

Use devtool to build Linux / U-Boot

The Build Linux from source code and the Build U-Boot from source code sections describe how to build Linux and U-Boot from source code outside of Yocto. This is in general a fast way to work with Linux / U-Boot development compared to re-building inside of Yocto. There is however another alternative that will let you build within Yocto, but with your own Linux / U-Boot repositories. This can be suitable when you for example want to test modifications, but make sure to keep the kernel in sync with the root file system. For U-Boot and especially U-Boot for iMX8 the benefits of using devtool is that you don’t have to manually re-create the boot image as described in the Extra steps for iMX8 section.

Run the commands below within your Yocto build directory.

For Linux kernel:

devtool modify linux-ea -n <path to Linux repository>

For U-Boot:

devtool modify u-boot-ea -n <path to U-Boot repository>

Once you have modified the repository you can build a new Yocto image, for example, ea-image-base.

bitbake ea-image-base

If you want to switch back to using the default repositories you can use devtool reset as shown below.

devtool reset linux-ea
devtool reset u-boot-ea

State and download cache in Yocto

If you regularly build Yocto images you can significantly reduce build times by using state and download caches. The download cache will contain downloaded packages so they don’t have to be downloaded multiple times for new build directories. The state cache will contain built packages so you these don’t have to be re-built between build directories given that the state hasn’t changed.

You can enable the caches by adding the lines below to your local.conf file (<build dir>/conf/local.conf).

Download cache (change the directory name below to a directory on your computer): DL_DIR="~/downloads"

State cache (change the directory name below to a directory on your computer): SSTATE_DIR="~/shared-sstate-cache"

You could also create a file called site.conf that you copy to your conf directory each time you create a new build directory. Below is an example of how such a file could look like.

SSTATE_DIR = "/opt/yocto-cache/shared-sstate-cache"
DL_DIR = "/opt/yocto-cache/downloads"
SSTATE_MIRRORS = " file://.* file:///opt/yocto-cache/shared-sstatecachePATH "