Skip to content

Yocto Build Linux from source code -

Introduction

This guide walks through the process for manually building and installing Linux from source. It is derived from TI's Build Linux guide

Fetch source code and install dependencies

This section describes the one time process to install the toolchains and fetch the necessary source code for building Linux.

Install Toolchains to home directory

cd ~
wget https://developer.arm.com/-/media/Files/downloads/gnu/11.3.rel1/binrel/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf.tar.xz && \
   tar -Jxvf arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-linux-gnueabihf.tar.xz -C $HOME && \
   wget https://developer.arm.com/-/media/Files/downloads/gnu/11.3.rel1/binrel/arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu.tar.xz && \
   tar -Jxvf arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu.tar.xz -C $HOME

Fetch Source Code

Setup a working directory

export WORKDIR=~/am62x-var-som-linux
mkdir ${WORKDIR}

Fetch the Linux source:

cd $WORKDIR
git clone https://github.com/varigit/ti-linux-kernel -b ti-linux-6.1.y_09.02.01.10_var01 ti-linux-kernel

Fetch the kernel driver for the PowerVR Rogue GPU:

cd $WORKDIR
git clone https://git.ti.com/cgit/graphics/ti-img-rogue-driver -b linuxws/kirkstone/k6.1/23.3.6512818 ti-img-rogue-driver
cd ti-img-rogue-driver && \
  git checkout c89c1efa4a1ee5da64fd525f45e9e33728cf6181 && \
  cd ../

Build Linux out of Yocto tree

After fetching the source code and installing dependencies, you may return to $WORKDIR anytime and follow these steps to build Linux:

Setup the environment:

Export the working directory

export WORKDIR=~/am62x-var-som-linux

Export variables for building Linux

export PATH=$HOME/arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu/bin:$PATH

Build Kernel image, modules, and device trees:

Change to kernel directory:

cd $WORKDIR/ti-linux-kernel

Configure the Kernel:

Clean directory:
make mrproper

Create .config from am62x_var_defconfig
make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- -j$(nproc) am62x_var_defconfig

Optional: Make changes to .config and save to am62x_var_defconfig
make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- -j$(nproc) menuconfig
make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- -j$(nproc) savedefconfig
cp defconfig arch/arm64/configs/am62x_var_defconfig

Build Kernel:

Build All:
make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- -j$(nproc)

Build Image only:
make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- -j$(nproc) Image

Build modules only:
make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- -j$(nproc) modules

Build device trees only:
make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- -j$(nproc) dtbs

Build Kernel drivers for the PowerVR Rogue GPU:

cd ${WORKDIR}/ti-img-rogue-driver
make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- -j$(nproc) \
    KERNELDIR=${WORKDIR}/ti-linux-kernel \
    BUILD=release PVR_BUILD_DIR=am62_linux \
    WINDOW_SYSTEM=lws-generic

Install new kernel

Create a directory to install the kernel, device trees, and modules:

Optional: delete any old installation from previous builds:
rm -rf $WORKDIR/rootfs

Create new directory:
mkdir -p $WORKDIR/rootfs/boot

Copy the Image and device trees to the rootfs:

cd $WORKDIR/ti-linux-kernel
cp arch/arm64/boot/Image $WORKDIR/rootfs/boot/
cp arch/arm64/boot/dts/ti/k3*am*var-som*.dtb $WORKDIR/rootfs/boot/dtb/

Install the modules to the rootfs:

make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- -j$(nproc) \
    modules_install INSTALL_MOD_PATH=$WORKDIR/rootfs

Install the GPU driver to the rootfs:

cd $WORKDIR/ti-img-rogue-driver
make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- -j$(nproc) \
    KERNELDIR=${WORKDIR}/ti-linux-kernel \
    BUILD=release PVR_BUILD_DIR=am62_linux \
    -C ${WORKDIR}/ti-linux-kernel M=${WORKDIR}/ti-img-rogue-driver/binary_am62_linux_lws-generic_release/target_aarch64/kbuild \
    INSTALL_MOD_PATH=${WORKDIR}/rootfs \
    modules_install

Deploy new kernel

You can deploy $WORKDIR/rootfs to a running device:

Option 1: Copy to a local SD card mounted at /media/user/rootfs/:
sudo cp -r $WORKDIR/rootfs/* /media/user/rootfs/

Option 2: Copy to a running device over ethernet
tar czf - -C $WORKDIR/rootfs . | ssh root@<ip address> 'tar xzf - --no-same-owner -C /'