Yocto Debian Build Release

From Variscite Wiki
Warning: This page is designed to be used with a 'release' URL parameter.

This page is using the default release mx93-debian-bookworm-6.1.36_2.1.0-v1.0.
To view this page for a specific Variscite SoM and software release, please follow these steps:

  1. Visit variwiki.com
  2. Select your SoM
  3. Select the software release


VAR-SOM-MX93 - Debian Bookworm 12.5 based on Yocto Mickledore 4.2 with NXP BSP L6.1.36_2.1.0




Note

Since Debian Bookworm with NXP BSP L6.1.36_2.1.0, the build system has transitioned to Yocto. If you previously used an older Debian release, please note that setting up a new development environment may be necessary. Therefore, it is recommended to familiarize yourself with the following guides first:


Installing required packages

Please make sure your host PC is running Ubuntu 20.04/22.04 64-bit and is up to date:

 $ sudo apt-get update && sudo apt-get dist-upgrade

Then, install the following packages:

 $ sudo apt-get install gawk wget git diffstat unzip texinfo gcc-multilib \
 build-essential chrpath socat cpio python3 python3-pip python3-pexpect \
 xz-utils debianutils iputils-ping libsdl1.2-dev xterm libyaml-dev libssl-dev
 
 $ sudo apt-get install autoconf libtool libglib2.0-dev libarchive-dev \
 sed cvs subversion coreutils texi2html docbook-utils \
 help2man make gcc g++ desktop-file-utils libgl1-mesa-dev libglu1-mesa-dev \
 mercurial automake groff curl lzop asciidoc u-boot-tools dos2unix mtd-utils pv \
 libncurses5 libncurses5-dev libncursesw5-dev libelf-dev zlib1g-dev bc rename \
 zstd libgnutls28-dev
 
 $ sudo apt-get install python3-git zstd liblz4-tool

For Ubuntu 20.04 and earlier, install python2:

$ sudo apt-get install python python-pysqlite2

Starting in Ubuntu 22.04, python2 is no longer available. Install the following to create a symbolic link from python to python3:

$ sudo apt-get install python-is-python3


Note: Variscite provides Docker containers that can be used for a development environment as an alternative to using a virtual machine or a dedicated computer. To learn more, please see Variscite's Docker Build Environment guide.


Reference documentation

Setting Up Yocto Build Environment

Configure git user and email:

$ git config --global user.name "Your Name"
$ git config --global user.email "Your Email"


Fetch and install the Google git-repo tool:

$ mkdir -p ~/bin

# For Ubuntu 20.04 and older, install repo 2.32 according to https://gerrit.googlesource.com/git-repo/+/HEAD/docs/python-support.md:
$ curl https://commondatastorage.googleapis.com/git-repo-downloads/repo-2.32 > ~/bin/repo

# For Ubuntu 22.04 and newer, install the latest repo tool:
$ curl https://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo

# Give repo execute permissions and add it to the path:
$ chmod a+x ~/bin/repo
$ export PATH=~/bin:$PATH


Create a build directory:

$ mkdir ~/debian_imx93_var_som
$ cd ~/debian_imx93_var_som

Now, choose between downloading a release tag, and downloading the latest revision (recommended) and follow only one of the next two bullet sections, accordingly:

  • Download the latest revision (recommended)
$ repo init -u https://github.com/varigit/variscite-bsp-platform.git -b mickledore -m imx-6.1.36-2.1.0-debian.xml
$ repo sync -j$(nproc)


or

  • Download a release tag

Each release in https://github.com/varigit/variscite-bsp-platform/releases corresponds to a tag.
The tags are also listed in https://github.com/varigit/variscite-bsp-platform/tags
To specify a specific release/tag, run the following:

$ repo init -u https://github.com/varigit/variscite-bsp-platform.git -b refs/tags/TAG_NAME

For example:
$ repo init -u https://github.com/varigit/variscite-bsp-platform.git -b refs/tags/mx93-debian-bookworm-6.1.36_2.1.0-v1.0 -m imx-6.1.36-2.1.0-debian.xml
$ repo sync -j$(nproc)

Building the Image

Supported images

Variscite provides the following images for evaluation purposes:

  • var-image-debian: Default Variscite demo image for Debian build with Yocto. This image recipe works currently only with Xwayland

Supported distros

The following distros can be used:

  • var-debian-xwayland: Distro for Wayland with X11. This distro includes both Wayland and X11 emulation features.

Build Debian Xwayland GUI demo image

After the Yocto environment is set up, you need to configure the build environment for your target device:

$ cd ~/debian_imx93_var_som
$ MACHINE=imx93-var-som DISTRO=var-debian-xwayland . var-setup-debian.sh build_debian_xwayland

The above command is only mandatory for the very first build setup. Whenever restarting a newer build session (from a different terminal or in a different time), you can skip the full setup and just run:

$ cd ~/debian_imx93_var_som
$ source setup-environment build_debian_xwayland

Then, the image can be created by running the following bitbake command:

$ bitbake var-image-debian

The target rootfs image is located at:

~/debian_imx93_var_som/build_debian_xwayland/tmp/deploy/images/imx93-var-som/var-image-debian-imx93-var-som.wic.gz

Build Results

The resulting images are located in ~/debian_imx93_var_som/build_debian_xwayland/tmp/deploy/images/imx93-var-som.


Image Name
How to use
var-image-debian-imx93-var-som.wic.zst This image is for SD card boot.
It can be flashed as-is on an SD card that can then be used to boot your system,
according to the relevant startup-guide of your product
(usually requires to press the boot select button, or toggle a DIP switch).
For detailed information refer to the Create a bootable SD card section below.
var-image-debian-imx93-var-som.tar.zst Tarball with rootfs files.
Can be used to create an NFS root file system on the host.
See the Yocto Setup TFTP/NFS section for more info.
Also used to create our extended SD card.
See the Create a bootable SD card section below.
Image.gz Linux kernel image, same binary for SD card and eMMC.
imx-boot-sd.bin U-Boot built for SD card boot or eMMC boot.
File Name
Description
imx93-var-som-symphony.dtb Device tree for VAR-SOM-MX93 on Symphony-Board
imx93-var-som-symphony-ld.dtb Device tree for VAR-SOM-MX93 with Low Drive mode on Symphony-Board
imx93-var-som-wbe-symphony.dtb Device tree for VAR-SOM-MX93 with WBE support on Symphony-Board
imx93-var-som-wbe-symphony-ld.dtb Device tree for VAR-SOM-MX93 with Low Drive mode, and WBE support on Symphony-Board
imx93-var-som-symphony-m33.dtb Device tree for VAR-SOM-MX93 with Cortex-M33 on Symphony-Board
imx93-var-dart-dt8mcustomboard.dtb Device tree for DART-MX93 on DT8MCustomBoard
imx93-var-dart-dt8mcustomboard.dtb Device tree for DART-MX93 with Low Drive mode, and WBE support on DT8MCustomBoard

Linux console access

Default users and passwords

User name User password User descriptor
root root system administrator
user user local user

You can customize the users during runtime with the common known methods in Debian. Please follow up with the next section if you'd like to customize them during the build.

Customize users during the build

The Variscite Debian image is pre-configured to include the user's 'user' and 'root'. While the user 'root' is mandatory, the user 'user' is optional and can be configured or dropped according to your needs (it's also possible to add additional users).

The related statements in the Yocto tree are in 'dynamic-layers/var-debian/recipes-var/images/var-image-common.inc' within the meta layer meta-variscite-sdk-imx.

var-image-common.inc

...
# Default password: root
USER_PASSWD_ROOT ?= "POYe5TylsuKjU"
# Add user with password user and default shell bash
USER_SHELL_BASH ?= "/bin/bash"
# Default password: user
USER_PASSWD_USER ?= "zHipsIr46vtZk"
APTGET_ADD_USERS ?= "user:${USER_PASSWD_USER}:${USER_SHELL_BASH}"
...

This makes use of the API APTGET_ADD_USERS variable of the bitbake class nativeaptinstall.bbclass (can be found in 'classes/nativeaptinstall.bbclass' in the meta layer meta-variscite-debian).

The syntax of the variable APTGET_ADD_USERS is <name:pass:shell>, with the following meaning:

  • name: The user name
  • pass: An encrypted password (if empty or missing, an empty password will be assigned)
  • shell: The default shell (if empty, default is /bin/sh)

For multiple definitions, a space can be used as a separator.

The encrypted password (DES hash) can be created using the tool 'mkpasswd', provided by the package 'whois'.

For instance:

$ sudo apt-get update; sudo apt-get install -y whois
$ mkpasswd --method=DES user
$ lAeYt2gLbjniw

This will generate a hash with a random salt. To double-check, we can pass the salt (the first 2 characters of the output), like:

$ mkpasswd --method=DES --salt lA user
$ lAeYt2gLbjniw

One can either change the variables in 'var-image-common.inc' directly or overwrite the default values, e.g., in the local.conf ('~/debian_imx93_var_som/build_debian_xwayland/conf/local.conf').

For instance, to configure 2 users, 'user' and 'user2', with the password being the same as the user name:
local.conf

...
APTGET_ADD_USERS = " \
    user:lAeYt2gLbjniw:/bin/bash \
    user2:FuOvd4U8o1Y4.:/bin/bash \
"
...

Or to add an additional user to the one already present:

...
APTGET_ADD_USERS:append = " \
    user2:FuOvd4U8o1Y4.:/bin/bash \
"
...

Or drop all additional users (only user 'root'):

...
APTGET_ADD_USERS = ""
...


Note: If you only want to change the password of the default user 'user', overwrite the variable USER_PASSWD_USER to your needs. The same applies to the user 'root' with the associated variable USER_PASSWD_ROOT.

Create a bootable SD card

SD Card Structure

This is the structure of our default SD card programmed from Yocto images:

Disk /dev/sdX: 59.48 GiB, 63864569856 bytes, 124735488 sectors                                                                                              
Disk model: MassStorageClass                                                                                                                                
Units: sectors of 1 * 512 = 512 bytes                                                                                                                       
Sector size (logical/physical): 512 bytes / 512 bytes                                                                                                       
I/O size (minimum/optimal): 512 bytes / 512 bytes                                                                                                           
Disklabel type: dos                                                                                                                                         
Disk identifier: 0x5ebf1617                                                                                                                                 
                                                                                                                                                          
Device     Boot Start      End  Sectors  Size Id Type                                                                                                       
/dev/sdX1       16384 15165439 15149056  7.2G 83 Linux


  • At the beginning of the card is 8 MiB of reserved area for the partition table and bootloader.
  • The first and only SD card partition begins at offset 16,384 (of 512 byte sectors) which is due to the reserved area explained above. This partition is an ext4 partition that contains the complete root filesystem (including kernel image and device tree files under /boot).


Note: This partition includes an unallocated area to ensure compatibility with all 8 GB SD cards, as their actual sizes may vary. For instructions on optimizing the usage of your SD card's capacity, refer to the section Extending the SD Card Size.

Yocto pre-built bootable SD card

The Yocto build products contains many files as explained in the Build Results section. For example, var-image-debian-imx93-var-som.wic.zst, depending on your build. This is a complete and bootable image ready to be flashed directly to an SD card.

Example usage:

$ sudo umount /dev/sdX*
$ cd ~/debian_imx93_var_som/build_debian_xwayland
$ zstdcat tmp/deploy/images/imx93-var-som/var-image-debian-imx93-var-som.wic.zst | sudo dd of=/dev/sdX bs=1M conv=fsync

Replace sdX with the right device name. This can be obtained by "dmesg" command on your host Linux PC, after the SD card reader is inserted.


Note: Booting your system from an SD card requires pressing the boot-select button, or switching the relevant DIP switch to "Boot from SD card", according to the relevant start-up guide of your system


Note: If using any of the native .wic.zst images output from Yocto, these will only have a default partition size of slightly less than 8 GB in order to fit on most SD cards. In order to maximize all usable space on the SD card, please see the section on Extending the SD Card Size.

Yocto Recovery Image

Beginning in Yocto Langdale, Variscite has released a new recovery Yocto image recipe called "var-recovery-image." This image is used to create a bootable SD card that contains another target image to be programmed to the eMMC. See the Debian Recovery SD card or the more manual Installing Yocto to the SOM's internal storage articles for specifics of installing a recovery image.

Usage:

To create a recovery image, simply run the following from your Yocto environment:

$ bitbake var-recovery-image

This will produce an output relative to the build folder of "./tmp/deploy/images/imx93-var-som/var-recovery-image-imx93-var-som.wic.zst" that can be flashed to the SD card. By default, this image boots fsl-image-gui and contains a fsl-image-gui target image to be programmed to eMMC.

You can also specify a different target eMMC image to be embedded in the recovery image by setting VAR_RECOVERY_TARGET_ROOTFS via the command line during build:
i.e.

$ VAR_RECOVERY_TARGET_ROOTFS="<desired-emmc-image-recipe>" bitbake var-recovery-image


Or alternatively, by setting this variable in local.conf:

$ VAR_RECOVERY_TARGET_ROOTFS = "<desired-emmc-image-recipe>" 


Additionally, the file name of the recovery image output can be modified by setting something like the following in local.conf:

$ echo 'VAR_RECOVERY_SD_NAME = "mx93-debian-bookworm-6.1.36_2.1.0-v1.0"' >> conf/local.conf

Would produce a recovery image relative to the build folder of "./tmp/deploy/images/imx93-var-som/mx93-debian-bookworm-6.1.36_2.1.0-v1.0.wic.zst"

Note: Please see the var-recovery-image recipe source for advanced usages of the recovery image.

Extending the SD Card Size

Flashing the default .wic.zst images from Yocto results in a rootfs that does not utilize the entire SD card. This section explains how the SD card can be extended on the build host after flashing.

Procedure:

Begin with an SD card on which you have previously flashed a Yocto .wic.zst image. Ensure the SD card is inserted and the device present (i.e. /dev/sda, /dev/mmcblk0, etc.)

Note: Below replace /dev/sdX with your actual device (i.e. /dev/sda)

Start by running fdisk as below and typing "p" and enter to print current partitions. You should see a layout similar to below but numbers may differ depending on card sizes. Note that the partition starts at 16,384 (bytes offset 16384*512) which is to account for the boot content explained above.

$ sudo fdisk /dev/sdX

Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sdX: 59.48 GiB, 63864569856 bytes, 124735488 sectors                                                                                              
Disk model: MassStorageClass                                                                                                                                
Units: sectors of 1 * 512 = 512 bytes                                                                                                                       
Sector size (logical/physical): 512 bytes / 512 bytes                                                                                                       
I/O size (minimum/optimal): 512 bytes / 512 bytes                                                                                                           
Disklabel type: dos                                                                                                                                         
Disk identifier: 0x5ebf1617                                                                                                                                 
                                                                                                                                                           
Device     Boot Start      End  Sectors  Size Id Type                                                                                                       
/dev/sdX1       16384 15165439 15149056  7.2G 83 Linux

Next, run the following sequence of commands followed by enter with each step explained with a "-" to the right. Each command/input should be followed by enter:

  • d - Delete current partition (1).
  • n - Create a new parition.
  • - Empty, hit enter only which will leave default response p for primary partition.
  • - Empty, hit enter only which will leave default response 1 for first partition.
  • 16384 - Enter 16384 to begin partition past bootloader section.
  • - Empty, hit enter only which will leave last sector as default which should choose ending size of the SD card.
  • N - Answers no to not remove the ext4 signature on the disk
  • p - Print output and verify before we write. We should see the starting offset the same and the end expanded to fill the SD card.
  • w - Write output to disk


See the full log of the above sequence below:

Command (m for help): d                                                                                                                                     
Selected partition 1                                                                                                                                        
Partition 1 has been deleted.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-124735487, default 2048): 16384
Last sector, +/-sectors or +/-size{K,M,G,T,P} (16384-124735487, default 124735487): 

Created a new partition 1 of type 'Linux' and of size 59.5 GiB.
Partition #1 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: N

Command (m for help): p

Disk /dev/sdX: 59.48 GiB, 63864569856 bytes, 124735488 sectors
Disk model: MassStorageClass
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
identifier: 0x5ebf1617

Device     Boot Start       End   Sectors  Size Id Type
/dev/sdX1       16384 124735487 124719104 59.5G 83 Linux

Command (m for help): w

The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.


Finally, the file system needs to be resized on the disk to fill the now larger partition. Do that as follows:

$ sudo e2fsck -f /dev/sdX1                                                    
e2fsck 1.46.5 (30-Dec-2021)                                                                                                                                 
root: recovering journal                                                                                                                                    
Pass 1: Checking inodes, blocks, and sizes                                                                                                                  
Pass 2: Checking directory structure                                                                                                                        
Pass 3: Checking directory connectivity                                                                                                                     
Pass 4: Checking reference counts                                                                                                                           
Pass 5: Checking group summary information                                                                                                                  
root: 43155/947488 files (0.1% non-contiguous), 674097/1893632 blocks

$ sudo resize2fs /dev/sdX1                                                    
resize2fs 1.46.5 (30-Dec-2021)                                                                                                                              
Resizing the filesystem on /dev/sdX1 to 15589888 (4k) blocks.                                                                                               
The filesystem on /dev/sdX1 is now 15589888 (4k) blocks long.

$ sync


Again, numbers and output should differ slightly depending on your card.

Your rootfs image should now fill the entire SD card and is ready to boot.

Boot the board with a bootable SD card

Setting the Boot Mode

Make sure the BOOT SELECT DIP switch on the carrier board is set correctly before you power on the board.

SW3
 0 : Boot from SD card
 1 : Boot from eMMC


Automatic device tree selection in U-Boot

As shown in the Build Results table above, we have different kernel device trees, corresponding to our different H/W configurations.
We implemented a script in U-Boot's environment, which sets the fdt_file environment variable based on the detected hardware.

Enable/Disable automatic device tree selection

To enable the automatic device tree selection in U-Boot (already enabled by default):

$ setenv fdt_file undefined
$ saveenv

To disable the automatic device tree selection in U-Boot, set the device tree file manually:

$ setenv fdt_file YOUR_DTB_FILE
$ saveenv

Useful example: To list all files in the /boot directory (where the dtb files are by default) of an SD card:

$ ls mmc 1:1 /boot

Flash images to NAND/eMMC

Please refer to Debian NAND Flash Burning guide.