UCM-iMX7: Linux: Kernel

From Compulab Mediawiki
Jump to: navigation, search

Overview

The Linux kernel for UCM-iMX7 provides support for on-board peripherals/interfaces of UCM-iMX7 system-on-module (SoM) and SBC-UCM-iMX7 Single Board Computer. It is recommended to use the most recent Linux package released. It can be downloaded from the product web page. Unzip the downloaded Linux package to a directory on your host workstation. The following discussion uses /path/to/ucm-imx7-linux/ template for this location. Please use the real path to the Linux package instead.

Building kernel for UCM-iMX7

Getting kernel sources

Linux git tree can be cloned or downloaded as a tarball from Freescale public git repository. The instructions below assume that the /home/development/ucm-imx7/kernel directory has been created for UCM-iMX7 kernel development.

Snapshot download

  • Extract the downloaded archive linux-2.6-imx-rel_imx_4.1.15_1.2.0_ga.tar.gz
cd /home/development/ucm-imx7/kernel
tar xpf /path/to/downloaded/linux-2.6-imx-rel_imx_4.1.15_1.2.0_ga.tar.gz
mv linux-2.6-imx-rel_imx_4.1.15_1.2.0_ga linux-ucm-imx7
  • Apply the UCM-iMX7 patch
cd /home/development/ucm-imx7/kernel/linux-ucm-imx7
patch -p1 < /path/to/ucm-imx7-linux/kernel/linux-4.1.15-ucm-imx7-*.patch

Git clone

  • Install git version control system.
  • Create a clone of the FreeScale Linux kernel tree
cd /home/development/ucm-imx7/kernel
git clone git://git.freescale.com/imx/linux-2.6-imx.git linux-ucm-imx7
  • Create a branch for UCM-iMX7 development. The UCM-iMX7 patches are generated vs. rel_imx_4.1.15_1.2.0_ga tag in the Linux tree. It is recommended to use exactly the same baseline to avoid merge conflicts.
cd /home/development/ucm-imx7/kernel/linux-ucm-imx7
git checkout -b development rel_imx_4.1.15_1.2.0_ga
  • Apply the UCM-iMX7 patch
git am /path/to/ucm-imx7-linux/kernel/patches/*.patch

Building the kernel

The following discussion assumes a development environment is set up on your host workstation and Linaro GCC 5 crosstoolchain with the prefix arm-linux-gnueabihf- is installed on on it and its location is found in the PATH.

cd /home/development/ucm-imx7/kernel/linux-ucm-imx7
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabihf-
export DTB="imx7d-*ucm-imx7.dtb"
make ucm_imx7_defconfig
make menuconfig
make zImage modules ${DTB} && INSTALL_MOD_PATH=/home/development/ucm-imx7/rootfs make modules_install

In the example above:

  • Linux kernel image (zImage) will be created in /home/development/ucm-imx7/kernel/linux-ucm-imx7/arch/arm/boot
  • device tree blobs will be created in /home/development/ucm-imx7/kernel/linux-ucm-imx7/arch/arm/boot/dts
  • loadable kernel modules will be installed into the /home/development/ucm-imx7/rootfs/lib/modules directory.


When the UCM-iMX7 is booted with the kernel image created as described above and with networked root filesystem at /home/development/ucm-imx7/rootfs/, the system will be able to load the kernel modules properly, thus avoiding module version problems.

zImage, DTB files and modules locations

  • In the example above, the Linux kernel image (zImage) will be created in the /home/development/ucm-imx7/kernel/linux-ucm-imx7/arch/arm/boot directory.
# ls -al /home/development/ucm-imx7/kernel/linux-ucm-imx7/arch/arm/boot/zImage
  • DTB files
# cd /home/development/ucm-imx7/kernel/linux-ucm-imx7/arch/arm/boot/dts/
# ls -al ${DTB}
# cd -
  • The loadable kernel modules will be installed into the /home/development/ucm-imx7/rootfs/lib/modules directory.
# ls -al /home/development/ucm-imx7/rootfs/lib/modules

Kernel Version

  • In the example above, the Linux kernel release version number will be saved in /home/development/ucm-imx7/kernel/linux-ucm-imx7/include/config/kernel.release
# cat /home/development/ucm-imx7/kernel/linux-ucm-imx7/include/config/kernel.release

Prepare kernel and modules tarball

  • In the example below, the Linux kernel and modules are packed into the tar archive for deploying onto the UCM-iMX7.
# mkdir -p /home/development/ucm-imx7/rootfs/boot
# cp -v /home/development/ucm-imx7/kernel/linux-ucm-imx7/arch/arm/boot/zImage /home/development/ucm-imx7/rootfs/boot/
# cd /home/development/ucm-imx7/kernel/linux-ucm-imx7/arch/arm/boot/dts/
# cp -v ${DTB} /home/development/ucm-imx7/rootfs/boot/ 
# cd -
# tar -C /home/development/ucm-imx7/rootfs -czvf /home/development/ucm-imx7/linux-image-ucm-imx7.tar.gz .

Basic platform support

The UCM-iMX7 basic platform support is implemented in the imx7d-ucm-imx7.dtb file of the Linux kernel source tree. The extended interface support depends on carrier board used and thus is implemented in the Single Board Computer device tree files:

  • imx7d-sbc-ucm-imx7.dtb - for SBC-UCM-iMX7 Single Board Computer

These files contain:

  • default setup of multi-functional pins;
  • registration of the devices integrated in the UCM-iMX7 module;
  • definitions of platform-specific configuration for these devices.

Deploying the UCM-iMX7 kernel and modules

  • Boot up the UCM-iMX7 computer.
  • Copy the previously created linux-image-ucm-imx7.tar.gz to /root directory of the UCM-iMX7.

Mount boot partition

  • Use the below command to mount the boot partition for installing the UCM-iMX7 Linux kernel binary:
# boot_partition=`cat /proc/cmdline | awk '{ for (i=1;i<=NF;i++) { if($i~/^root=/) { print substr($i,6,length($i)-6)"1" } } }'`
# mount $boot_partition /boot

Back up old kernel

  • It is essential to backup the old (known to work) kernel binary.
# mkdir /boot/`uname -r`
# mv /boot/zImage* /boot/*.dtb /boot/`uname -r`/

Installing kernel and modules

Assuming that the linux-image-ucm-imx7.tar.gz tar ball has been copied to the UCM-iMX7 /root directory.

  • Extract and install the Linux kernel binary:
# tar -C / -xvf /root/linux-image-ucm-imx7.tar.gz

U-Boot Environment

MMC Boot Parameters

To boot from MMC/SD card type:

setenv mmcdev 0
setenv mmcblk mmcblk0p2

Continue to the Common Boot Parameters.

eMMC Boot Parameters

To boot from internal eMMC storage type:

setenv mmcdev 2
setenv mmcblk mmcblk2p2

Continue to the Common Boot Parameters.

Device Tree Blob

  • For SBC-UCM-iMX7 Single Board computer type:
setenv fdt_file imx7d-sbc-ucm-imx7.dtb

Common Boot Parameters

To boot Linux type:

setenv loadaddr 0x80800000
setenv fdt_addr 0x83000000
setenv image zImage
setenv bootargs console=ttymxc0,115200 root=/dev/${mmcblk} rw rootwait
mmc dev ${mmcdev}
load mmc ${mmcdev} ${loadaddr} ${image}
load mmc ${mmcdev} ${fdt_addr} ${fdt_file}
bootz ${loadaddr} - ${fdt_addr}

NFS Boot Parameters

To boot via network interface type:

dhcp
setenv loadaddr 0x80800000
setenv fdt_addr 0x83000000
setenv image zImage
setenv nfsserver <nfs server ip address>
setenv tftpserver <tftp server ip address>
setenv bootargs console=ttymxc0,115200 root=/dev/nfs rw ip=dhcp nfsroot=${nfsserver}:${nfsroot}
tftpboot ${loadaddr} ${tftpserver}:${image}
tftpboot ${fdt_addr} ${tftpserver}:${fdt_file}
bootz ${loadaddr} - ${fdt_addr}

See also