Yocto Linux BSP Ver.9 User Guide for iMX8 series

From ESS-WIKI
Revision as of 08:30, 15 April 2020 by Tim.liang (talk | contribs)
Jump to: navigation, search


Getting Started

Conventions

${PREBUILT_IMAGE} : compressed prebuilt image (*.img.gz)

${CONTAINER_NAME} : container name (e.g. imx9LBV90016)

${BSP_TARBALL} : BSP tarball (*.tgz)

${BSP_HOME} : home directory of the BSP

${BDIR} : build directory (e.g. build_x11)

${MX8PROC} : i.MX8 Processor

mx8mq for iMX8M Dual Core
mx8mm for iMX8MM
mx8qm for iMX8QM
mx8qxp for iMX8QXP

${IMX8PROC} : i.MX8 Processor

imx8mq / imx8mm / imx8qm /imx8qxp

${BOARD} : available target boards list below

rom5720
rom5721
rom7720
rom5620

${BOARD_REV} : board revision

a1

${MC} : machine code combined with ${IMX8PROC}${BOARD}${BOARD_REV}

for example,
imx8mqrom5720a1 for ROM-5720 A1
imx8qmrom7720a1 for ROM-7720 A1
imx8qxprom5620a1 for ROM-5620 A1
imx8mmrom5721a1 for ROM-5721 A1
You can also use the command below to check supported machines on BSP
$ source setup-environment

${MEM_SIZE} : memory size

 2G/4G

${SD_DEVICE} : device name of SD card in Linux (e.g. /dev/sdf)

${SDCARD_IMAGE} : sdcard image built by bitbake (*.sdcard.bz2)

${WORKSPACE} : host workspace folders

${UBOOT} :u-boot version(e.g. 2016.03)

${KERNEL} : linux kernel version(e.g. 4.1.15)

${TOOLCHAIN} : toolchain installed directory(e.g. /opt/fsl-imx-x11/4.1.15-2.0.0)

debug console / serial console

serial terminal program (e.g. minicom, putty, teraterm ...) that serial port is configured to 115200 8N1

terminal console

terminal program (e.g. gnome-terminal, xfce4-terminal ...)

Docker install and setting

If you don't have docker in your system, then you can follow the below  steps to install docker and run it first.

To install Docker Engine on your platform

Please refer to Docker Installation Guide for details

To pull ubuntu 16.04 image from Docker Hub 

$ docker pull advrisc/u16.04-imx8lbv1

To create container

$ docker run --privileged -it --name ${CONTAINER_NAME} -v ${WORKSPACE}:/home/adv/adv-release-bsp -v /dev:/dev advrisc/u16.04-imx8lbv1 /bin/bash

Get BSP

You have two methods to put BSP into container created above

Download_BSP_From_GitHub

The following example shows how to download the Advantech Yocto BSP from GitHub.
For this example, a directory called adv-release-bsp is created for the project.
Refer to IoTGateway/BSP/Linux/iMX8/OS_Support_List , Official version "imx8LBV90029" is taken as an example :
$ git config --global user.name "Your Name"
$ git config --global user.email you@example.com
$ sudo chown adv:adv adv-release-bsp
$ cd adv-release-bsp
$ repo init -u git://github.com/ADVANTECH-Corp/adv-arm-yocto-bsp.git -b refs/tags/imx8LBV90029 -m imx8LBV90029.xml 
$ repo sync
If you want to get latest bsp
$ repo init -u git://github.com/ADVANTECH-Corp/adv-arm-yocto-bsp.git  -b imx-linux-sumo -m imx-4.14.98-2.0.0_ga.xml 
$ repo sync

Copy BSP tarball to Container

If you have BSP tarball (eg. imx8LBV90029_2019-10-23.tgz), then you have to copy it into container.

Follow the steps below:

1.Exit container and back to local machine

$ exit

2.Copy BSP tarball to ${WORKSPACE} , and change owner

$ cp imx8LBV90029_2019-10-23.tgz ${WORKSPACE}
$ sudo chown adv:adv ${WORKSPACE}/imx8LBV90029_2019-10-23.tgz 

3.Back to container

$ docker start ${CONTAINER_NAME}
$ docker attach ${CONTAINER_NAME}

4.Unpack BSP tarball

$ tar zxvf imx8LBV90029_2019-10-23.tgz

Downloads tarball

Not necessarily step
During building  Yocto image , it will generate downloads folder which includes all packages we need , but it usually can't fetch normally, so we keep this downloads folder. Then we can reduce some fetch failed issue.
You can get Downloads tarball (downloads_imx8-2.5.tgz) from following URL:
[1]
If you get downloads tarball, you can copy to your ${WORKSPACE}

Follow the steps below:

1.Exit container and back to local machine

$ exit

2.Copy Downloads tarball to ${WORKSPACE} , and change owner

$ cp downloads_imx8-2.5.tgz ${WORKSPACE}
$ sudo chown adv:adv ${WORKSPACE}/downloads_imx8-2.5.tgz 

3.Back to container

$ docker start ${CONTAINER_NAME}
$ docker attach ${CONTAINER_NAME}

4.Unpack Downloads tarball

$ tar zxvf downloads_imx8-2.5.tgz

5.make link to downloads folder

$ cd adv-release-bsp
$ ln -s ${WORKSPACE}/downloads_imx8-2.5 downloads

Introducing BSP

The BSP is based on Yocto Project with Freescale enhanced features for i.MX8, plus specific target board features from Advantech Inc..
The Advantech Yocto Project BSP Release directory contains a "sources" directory, which contains the recipes used to build,

one or more build directories, and a set of scripts used to set up the environment.

The recipes used to build the project come from both the community and Advantech. The Yocto Project layers are downloaded

to the sources directory. This sets up the recipes that are used to build the project.

Naming Rule

The tarball/prebuilt image name is consist of the model name followed by "LB" or "LI" plus version number and released date.
For example, BSP file name: imx8LBV90010_2019-08-27.tgz
which , "LB" is acronym of Linux BSP,
           "V90010" stands for Version 9.0010.



For example, Yocto image name: '5720A1AIM20LIV90010_iMX8M_2019-08-27.img.gz'
which "5720A1" stands for ROM-5720 A1
          "LI" is acronym for prebuilt Linux Image


BSP Content

The description of some important folders list below:
sources/
meta-advantech/ : meta layer by Advantech
meta-fsl-*/ : meta layer by Freescale
fsl-setup-release.sh : to create one new build environment
setup-environment : to continue an exist build environment

Build Instructions

To create one new build environment

Perform the following commands in terminal console
$ cd ${BSP_HOME}
$ MACHINE=${MC} DISTRO=fsl-imx-xwayland source fsl-setup-release.sh -b ${BDIR}
You need to read and accept the EULA.
RTENOTITLE

To continue an exist build environment

Perform the following commands in terminal console
$ cd ${BSP_HOME}
$ source setup-environment ${BDIR}

To build sdcard image

To create/continue a build environment
Perform the following command in terminal console
$ bitbake fsl-image-validation-imx
The file, fsl-image-validation-imx-${MC}.sdcard.bz2, will be located in directory, ./tmp/deploy/images/${MC}, while building process finished successfully.

To build toolchain installer

To create/continue a build environment
Perform the following command in terminal console
$ bitbake meta-toolchain
The below installer will be located in the directory "./tmp/deploy/sdk".
fsl-imx-xwayland-glibc-x86_64-meta-toolchain-aarch64-toolchain-${KERNEL}-sumo.sh

To build bootloader

To create/continue a build environment
Perform the following command in terminal console
$ bitbake imx-boot


To build linux kernel

To create/continue a build environment
If you operate on docker images, please install tmux application before running this command
$ sudo apt-get install tmux
Type following command to enter tmux
$ tmux
Perform the following command in terminal console to show up menuconfig
$ bitbake linux-imx -c menuconfig
After edit menuconfig, type following command to exit tmux windows
$ exit
to build kernel image
$ bitbake linux-imx
The two files, Image & Image-adv-${IMX8PROC}-${BOARD}-${BOARD_REV}.dtb, will be located in the directory, ./tmp/deploy/images/${MC}.

Creating boot-up on-board flash from prebuilt image

To create one boot-up SD card

Perform the following command in terminal console
# gunzip -c ${PREBUILT_IMAGE} | dd of=${SD_DEVICE} bs=1M
# sync

Creating boot-up on-board flash from built sdcard image

To create one boot-up SD card

Perform the following commands in terminal console
$ pushd ${BSP_HOME}/${BDIR}/tmp/deploy/images/${MC}
$ bunzip -dk -f ${SDCARD_IMAGE} | of=${SD_DEVICE} bs=1M
$ sync
$ popd

Debug console information

If you want to see debug message from device, you need to prepare for hardware device and software tool.

Preparing for hardware device

  • The following URL provides information about the debug port slot and the debug port line for each device

Debug Port Information

Preparing for software tool

  • You need to prepare the debug console tool. For example: "minicom" tool or "putty" tool.
  • Baud rate: 115200

Customization

Package addition

To add tcf-agent & openssh-sftp-server

Navigate to the directory where fsl-image-adv.inc located
$ cd ${BSP_HOME}/sources/meta-advantech/meta-fsl-imx/recipes-fsl/images
Add following line to fsl-image-adv.inc
IMAGE_INSTALL += " tcf-agent openssh-sftp-server "
Continue an exist build environment and build sdcard image

To add chromium browser

Navigate to the directory where local.conf located
$ cd ${BSP_HOME}/${BDIR}/conf
  • Method 1(Suggest): Add following one line to local.conf
CORE_IMAGE_EXTRA_INSTALL += "chromium-ozone-wayland"
  • Method 2: Add following two lines to local.conf
IMAGE_INSTALL_append = \
   "${@bb.utils.contains('DISTRO_FEATURES', 'wayland', ' chromium-ozone-wayland libexif', \
       bb.utils.contains('DISTRO_FEATURES',     'x11', ' chromium-x11 libexif', \
                                                        , d), d)}"
LICENSE_FLAGS_WHITELIST = \
   "${@bb.utils.contains('DISTRO_FEATURES', 'wayland', 'commercial', \
       bb.utils.contains('DISTRO_FEATURES',     'x11', 'commercial', \
                                                       , d),"
Continue an exist build environment and build sdcard image

Setting up SDK

Please follow the section,To build toolchain installer, to build one toolchain installer
Perform the following command in terminal console
$ cd ${BSP_HOME}/${BDIR}/tmp/deploy/sdk
$ sudo ./fsl-imx-xwayland-glibc-x86_64-meta-toolchain-aarch64-toolchain-4.14-sumo.sh
Enter new installed directory or just press Enter to use default directory.
While Proceed[y/n]? shows up, please enter the correct one.
Waiting for the SDK installed (while the following messages show up completely)
RTENOTITLE

Setting up cross compiling environment

SDK has been set up (ref.Setting up SDK)
Perform the following command in terminal console
$ source ${TOOLCHAIN}/environment-setup-aarch64-poky-linux

Updating bootloader

ROM-5720/ROM-5721

Build bootloader

If you already have a exist build environment
Refer to IoTGateway/BSP/Linux/iMX8/Yocto_LBV9_User_Guide#To_continue_an_exist_build_environment

Perform the following commands:

bitbake u-boot-imx -c compile -f && bitbake imx-boot -c compile -f && bitbake imx-boot -c deploy -f

You will get new bootloader

tmp/deploy/images/imx8mqrom5720a1/imx-boot-imx8mqrom5720a1-sd.bin-flash_evk

Replace u-boot

eg. SD card
dd if=imx-boot-imx8mqrom5720a1-sd.bin-flash_evk of=/dev/mmcblk1 bs=1k seek=33 conv=fsync

ROM-7720

Build bootloader

1. download the following files:
(1) arm cross toolchain: gcc-arm-none-eabi-4_9-2015q3-20150921-linux.tar.bz2
(Ref. sc_fw_port.pdf in the imx-scfw-porting-kit)
(2) imx-atf(Yocto - imx-atf_2.0.bb): bl31.bin
(3) firmware-imx(Yocto - firmware-imx_8.1.bb): mx8qm-ahab-container.img
(4) imx-sc-firmware(Yocto - imx-sc-firmware_1.2.bb): scfw_tcm.bin
(Ref. sc_fw_port.pdf in the imx-scfw-porting-kit)
2. decompress the toolchain:
$ tar xvf gcc-arm-none-eabi-4_9-2015q3-20150921-linux.tar.bz2 -C ~
3. export toolchain:
$ export TOOLS=~
4. download imx-mkimage:
$ git clone https://source.codeaurora.org/external/imx/imx-mkimage.git -b imx_4.14.98_2.0.0_ga
$ cd ~/imx-mkimage
5. copy the bl31.bin, mx8qm-ahab-container.img, scfw_tcm.bin and u-boot.bin to the iMX8QM/
6. build the flash.bin:
$ make clean
$ make SOC=iMX8QM flash

Replace u-boot

Perform the following command to transfer to exist boot-up SD card
$ dd if=flash.bin of=${SD_DEVICE} bs=1K seek=<offset> conv=fsync
Perform the following command to transfer to on-board flash
$ dd if=flash.bin of=/dev/mmcblk0 bs=1K seek=<offset> conv=fsync
Where offset is:
33 - for i.MAX 8QuadMax A0, i.MAX 8QuadXPlus A0, i.MAX 8M Quad, and i.MAX 8M Mini
32 - for i.MAX 8QuadXPlus B0 and i.MAX 8QuadMax B0

Building & updating kernel/modules/dtb manually

The cross compiling environment has been set up. (ref. Setting up cross compiling environment)

Copy BSP tarball to Container

Refer to Copy_BSP_tarball_to_Container , copy kernel tarball to ${WORKSPACE} and back to container

change owner & unpack tarball

$ sudo chown adv:adv imx8LBV90029_2019-10-23_linux-imx6.tgz
$ tar zxvf imx8LBV90029_2019-10-23_linux-imx6.tgz

Config kernel

Configure linux kernel
$ cd linux-imx6
$ make distclean
$ make imx8_adv_defconfig
$ make menuconfig
Start building linux kernel
$ make -j4 Image
When you get error like below

RTENOTITLE

run command then rebuild
$ unset LDFLAGS 


The kernel image file, Image, is located in the directory "./arch/arm64/boot/".
Start building kernel modules
$ make -j4 modules
Copy all modules to a temporary rootfs directory, "~/temp/rootfs"
$ make modules_install INSTALL_MOD_PATH=~/temp/rootfs
Building device tree blob
$ make -j4 freescale/adv-${IMX8PROC}-${BOARD}-${BOARD_REV}.dtb
eg.
$ make -j4 freescale/adv-imx8mq-rom5720-a1.dtb
The device tree blob, ${IMX6PROC}-${BOARD}-${BOARD_REV}.dtb, is located in the directory "./arch/arm64/boot/dts/freescale/".

Replace kernel & dts

Replace kernel
copy Image to SDcard or emmc
Replace dtb file
copy dtb file to SDcard or emmc

Improve boot speed

  • Bootloader

1.bootdelay time

We can cancel the bootdelay time by setting bootloader environment value.
setenv bootdelay 0
env save
reset

2.Disable console

Disable debug message output can also improve boot speed

Disable kernel message

setenv mmcargs setenv bootargs ${jh_clk} console=${console} modprobe.blacklist=${modprobe.blacklist} root=${mmcroot} video=HDMI-A-1:${videores} quiet
env save
reset

Or

Disable debug port
setenv console
env save
reset
  • Rootfs
TBD
  • Services

1. Using systemctl disable remove ,we can remove unnecessary services.

systemctl disable <services>

eg.

systemctl disable boottimes

System Recovery

This section provides detail procedures of restoring the eMMC image.

If you destroy the onboard flash image by accident, you can recover a system following these steps.

  • Recovery by SD card

1.Copy 5720A1AIM20LIV90022_iMX8M_flash_tool.tgz package to your desktop.

2.Insert SD card to PC

3.Make a bootable sd card

# tar zxvf 5720A1AIM20LIV90022_iMX8M_flash_tool.tgz
# cd 5720A1AIM20LIV90022_iMX8M_flash_tool/mk_inand/
# sudo ./mksd-linux.sh /dev/sdg

4.Insert SD card and copy 5720A1AIM20LIV90022_iMX8M_flash_tool to USB disk

5.Insert USB disk and SD card then Boot from SD

6.Enter usb disk folder, make a bootable emmc

# cd /run/media/sda1/
# cd 5720A1AIM20LIV90022_iMX8M_flash_tool/mk_inand/
# sudo ./mksd-linux.sh /dev/mmcblk0


  • Recovery by UUU tool

1.Download uuu tool from (https://github.com/ADVANTECH-Corp/uuu/releases/download/v20191101/uuu)

2.Create a folder with files as below:

1.uuu
2.imx-boot-imx8mqrom5720a1-sd.bin-flash_evk
3.fsl-image-validation-imx-imx8mqrom5720a1-20190917152605.rootfs.sdcard 

3.Connect otg cable from PC to device

4.Set the correct boot mode(1,2,3-off 4-on), then power on

5.Perform the following command:

PS.If you want to burn uboot to mmcblk0 instead of mmcblk0boot0, u-boot must be updated to version 20191101,

1.Burn uboot to emmc
   a)replace uboot in mmcblk0boot0
       sudo ./uuu -b emmc imx-boot-imx8mqrom5720a1-sd.bin-flash_evk
   b)replace uboot in mmcblk0
       sudo ./uuu -b emmc_adv imx-boot-imx8mqrom5720a1-sd.bin-flash_evk
2.Burn rootfs image to emmc
   a)replace uboot in mmcblk0boot0
       sudo ./uuu -b emmc_all imx-boot-imx8mqrom5720a1-sd.bin-flash_evk fsl-image-validation-imx-imx8mqrom5720a1-20190917152605.rootfs.sdcard
   b)replace uboot in mmcblk0
       sudo ./uuu -b emmc_all_adv imx-boot-imx8mqrom5720a1-sd.bin-flash_evk fsl-image-validation-imx-imx8mqrom5720a1-20190917152605.rootfs.sdcard

6.uuu tool will start recovery image to emmc.

7.For more usage (https://github.com/NXPmicro/mfgtools/wiki)

Package List

In BSP, list all packages which will be built in the image

bitbake -g fsl-image-qt5-validation-imx && cat recipe-depends.dot | grep -v -e '-native' | grep -v digraph | grep -v -e '-image' | awk '{print $1}' | sort | uniq
20191025 Package List

Show all recipes (include non-installed packages)

bitbake -s
20191025 Package Version List

You can also check ${BDIR}/tmp/deploy/images/${MC}/fsl-image-qt5-validation-imx-${MC}.manifest

It will show the same content with checking by rpm tool on target board.

On target board, list all packages by rpm tool

rpm -qa --root / --dbpath /var/lib/rpm | sort
20191025 RPM on Board List