Yocto Build Linux: Difference between revisions

From Variscite Wiki
(Add Debian support)
No edit summary
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<!-- Set release according to "release" parameter in URL and use MORTY_V1.0_DART-6UL as default
<!-- Set release according to "release" parameter in URL and use RELEASE_MORTY_V1.0_DART-6UL as default
--> {{INIT_RELEASE_PARAM|RELEASE_MORTY_V1.0_DART-6UL}}<!--
--> {{INIT_RELEASE_PARAM|RELEASE_MORTY_V1.0_DART-6UL}}<!--
--> {{#lst:Yocto_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{#lst:Yocto_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{#lst:B2QT_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{#lst:B2QT_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{#lst:Debian_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{#lst:Debian_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{#vardefine:PLATFORM_OS|{{#varexists:DEBIAN_NAME|Debian|Yocto}}}} <!--
--> {{#vardefine:PLATFORM_OS|Yocto}} <!--
--> {{#vardefine:WORKDIR|~/{{#var:MACHINE_NAME}}-linux}} <!--
--> {{#vardefine:WORKDIR_ENV|$WORKDIR}}
    {{#vardefine:CUSTOMIZE_LINUX_KERNEL|Yocto Customizing the Linux kernel}} <!-- Default to Yocto
--> {{#varexists:DEBIAN_NAME |
    {{#vardefine:PLATFORM_OS|Debian}} }} <!--
--> {{PageHeader|Build Linux from source code}} {{DocImage|category1=Yocto|category2=Debian}} <!--
--> {{PageHeader|Build Linux from source code}} {{DocImage|category1=Yocto|category2=Debian}} <!--
--> [[category:{{#var:HARDWARE_NAME}}]] __toc__
--> [[category:{{#var:HARDWARE_NAME}}]] __toc__
{{note|It is recommended to build the kernel image using {{#switch:{{#var:PLATFORM_OS}}|Debian=the Debian build script|#default=Yocto}} (see the {{Varlink|{{#var:PLATFORM_OS}} Customizing the Linux kernel|{{#var:RELEASE_LINK}}|Customizing the Linux kernel}} page) instead of using the direct method described in this page.<br>
{{note|It is recommended to build the kernel image using Yocto (see the {{Varlink|{{#var:CUSTOMIZE_LINUX_KERNEL}}|{{#var:RELEASE_LINK}}|Customizing the Linux kernel}} page) instead of using the direct method described in this page.<br>
This is because some of the {{#var:PLATFORM_OS}} packages may depend on the kernel, like the WiFi module that is built from outside of the kernel source tree on some of the {{#var:PLATFORM_OS}} releases.}}
This is because some of the Yocto packages may depend on the kernel, like the WiFi module that is built from outside of the kernel source tree on some of the {{#var:PLATFORM_OS}} releases.}}


= Toolchain installation for out of {{#var:PLATFORM_OS}} builds =
= Toolchain installation for out of Yocto builds =
{{#switch:{{#var:PLATFORM_OS}}
To install the toolchain, follow the {{Varlink2|Yocto Toolchain installation|{{#var:RELEASE_LINK}}}} guide.
|Yocto=
To install the toolchain, follow {{Varlink2|Yocto Toolchain installation|{{#var:RELEASE_LINK}}}}.
|Debian=
To install the toolchain, please go through the following steps of the {{varlink|Debian Build Release Stage|{{#var:RELEASE_LINK}}|Debian Build Release}} guide:
# {{varlink|Debian Build Release Stage#Setup Development Environment|{{#var:RELEASE_LINK}}|Setup Development Environment}}
# {{varlink|Debian Build Release Stage#Installing required packages|{{#var:RELEASE_LINK}}|Installing required packages}}
# {{varlink|Debian Build Release Stage#Download Debian build script|{{#var:RELEASE_LINK}}|Download Debian build script}}
# {{varlink|Debian Build Release Stage#Deploy sources|{{#var:RELEASE_LINK}}|Deploy sources}}


You have a development environment from this point, including the cross-compiler and the packages needed to compile the kernel.
= Setup the environment: =
}}
 
Setup a working directory
$ export WORKDIR={{#var:WORKDIR}}
$ mkdir ${WORKDIR}
 
= Build Linux out of Yocto tree =
 
== Fetch {{#var:KERNEL_REPO_NAME}} source code: ==


= Build Linux out of {{#var:PLATFORM_OS}} tree =
{{GIT_FETCH|NAME=KERNEL|WORKDIR={{#var:WORKDIR_ENV}}|USE_BRANCH=y}}


Get the Linux source code:  
== Build Kernel, Modules, and DTBs: ==
$ git clone {{#var:KERNEL_GIT}}
$ cd {{#var:KERNEL_REPO_NAME}}
$ git checkout {{#var:KERNEL_BRANCH}}


Build the Linux kernel:
Setup the environment:
{{#switch:{{#var:PLATFORM_OS}}
|Yocto=
<br>
  $ source {{#var:TOOLCHAIN_LOCATION}}{{#switch: {{#var:SOC_SERIES}}|imx8|mx93=<br>$ unset LDFLAGS|}}
  $ source {{#var:TOOLCHAIN_LOCATION}}{{#switch: {{#var:SOC_SERIES}}|imx8|mx93=<br>$ unset LDFLAGS|}}
|Debian=
<br>
$ export ARCH={{#var:ARCH}}
$ export CROSS_COMPILE={{#var:BUILD_FOLDER}}/toolchain/{{#var:TOOLCHAIN}}/{{#var:CROSS_COMPILE}}
}}


Clean and prepare the kernel:
$ cd ${WORKDIR}/{{#var:KERNEL_REPO_NAME}}
  $ make mrproper
  $ make mrproper
  $ make {{#var:KERNEL_DEFCONFIG}}
  $ make {{#var:KERNEL_DEFCONFIG}}
Line 48: Line 43:
  $ make menuconfig
  $ make menuconfig


Build kernel parts:
  Build everything:
  Build everything:
  $ make -j4
  $ make -j$(nproc)
 
  Build {{#var:KERNEL_IMAGE}} only:
  Build {{#var:KERNEL_IMAGE}} only:
  $ make -j4 {{#var:KERNEL_BUILD_PARAMS}} {{#var:KERNEL_IMAGE}}
  $ make -j$(nproc) {{#var:KERNEL_BUILD_PARAMS}} {{#var:KERNEL_IMAGE}}
   
   
  Build modules only:
  Build modules only:
  $ make -j4 {{#var:KERNEL_BUILD_PARAMS}} modules
  $ make -j$(nproc) {{#var:KERNEL_BUILD_PARAMS}} modules
   
   
  Build device trees only:
  Build device trees only:
  $ make -j4 dtbs
  $ make -j$(nproc) dtbs
<!-- Attach DTB section from specific release-->
<!-- Attach DTB section from specific release-->
{{#lst:{{#var:PLATFORM_OS}}_Platform_Customization|{{#var:KERNEL_DTB_SECTION}}}}
{{#lst:Yocto_Platform_Customization|{{#var:KERNEL_DTB_SECTION}}}}
 
== Install kernel modules to temporary directory ==
{{#vardefine:KERNEL_ROOTFS|{{#var:WORKDIR_ENV}}/rootfs}}
{{#vardefine:KERNEL_ARCH|{{#switch:{{#var:HARDWARE_NAME}}
    |DART-6UL
    |VAR-SOM-MX7
    |VAR-SOM-MX6=arm
    |#default=arm64
}}}}
 
Create a temporary directory to install the modules:
Optional: delete any old installation from previous builds:
$ rm -rf {{#var:KERNEL_ROOTFS}}
Create new directory:
$ mkdir -p {{#var:KERNEL_ROOTFS}}
 
Install the modules to the temporary rootfs:
$ cd ${WORKDIR}/{{#var:KERNEL_REPO_NAME}} && \
  make ARCH={{#var:KERNEL_ARCH}} \
    INSTALL_MOD_STRIP=1 \
    INSTALL_MOD_PATH={{#var:KERNEL_ROOTFS}} \
    modules_install
 
{{#ifeq: {{#var:WIFI_IW612_SUPPORT}}|yes|
= Build external modules =
 
== Build and install iw61x wifi driver support to temporary rootfs ==
 
External kernel modules must be compiled against the exact kernel version (commit ID) that is deployed on the target. Follow the steps below to compile and install the mandatory external drivers for the {{#var:MACHINE_NAME}}.
 
'''NXP Wi-Fi linux Driver'''
 
Follow the steps below to compile and install the driver for the NXP iw61x chipset.
 
Fetch the driver:
 
{{GIT_FETCH|NAME=NXP_WLAN_SDK|WORKDIR={{#var:WORKDIR_ENV}}|USE_COMMIT=y}}
 
Build the driver:
$ cd ${WORKDIR}/{{#var:NXP_WLAN_SDK_MAKE_DIR}} &&
  make -j$(nproc) KERNELDIR={{#var:WORKDIR_ENV}}/{{#var:KERNEL_REPO_NAME}}
 
Install the driver to the temporary modules directory:
 
$ make -j$(nproc) \
    KERNELDIR=${WORKDIR}/{{#var:KERNEL_REPO_NAME}} \
    -C ${WORKDIR}/{{#var:KERNEL_REPO_NAME}} \
    M=${WORKDIR}/{{#var:NXP_WLAN_SDK_MAKE_DIR}} \
    INSTALL_MOD_PATH=${WORKDIR}/rootfs \
    INSTALL_MOD_STRIP=1 \
    modules_install
}}


Notes:<br>
Notes:<br>
Line 66: Line 115:
{{note|If you just want to make a change in the device tree, you can compile and replace it without replacing the kernel image and modules.}}
{{note|If you just want to make a change in the device tree, you can compile and replace it without replacing the kernel image and modules.}}


= Install the built kernel on an SD card =
= Install the built kernel images, modules, and device trees on an SD card =


Copy the {{#var:KERNEL_IMAGE}} and device trees to the SD card boot partition, and install the modules in the SD card rootfs partition.<br>
Copy the {{#var:KERNEL_IMAGE}} and device trees to the SD card boot partition, and install the modules in the SD card rootfs partition.<br>
Line 73: Line 122:
  <br>
  <br>
  Install the kernel image and modules:
  Install the kernel image and modules:
$ cd ${WORKDIR}/{{#var:KERNEL_REPO_NAME}}
  $ kver=$(strings arch/arm64/boot/Image <nowiki>|</nowiki> grep -i "Linux version" <nowiki>|</nowiki> awk '{print $3}')
  $ kver=$(strings arch/arm64/boot/Image <nowiki>|</nowiki> grep -i "Linux version" <nowiki>|</nowiki> awk '{print $3}')
  $ sudo cp arch/arm64/boot/{{#var:KERNEL_IMAGE}} /media/user/rootfs/boot/{{#var:KERNEL_IMAGE}}-${kver}
  $ sudo cp arch/arm64/boot/{{#var:KERNEL_IMAGE}} /media/user/rootfs/boot/{{#var:KERNEL_IMAGE}}-${kver}
  $ sudo ln -fs /boot/{{#var:KERNEL_IMAGE}}-${kver} /media/user/rootfs/boot/{{#var:KERNEL_IMAGE}}
  $ sudo ln -fs /boot/{{#var:KERNEL_IMAGE}}-${kver} /media/user/rootfs/boot/{{#var:KERNEL_IMAGE}}
  $ sudo make ARCH=arm64 modules_install INSTALL_MOD_PATH=/media/user/rootfs
  $ sudo cp {{#var:KERNEL_ROOTFS}}/* /media/user/rootfs
   
   
  Install the device trees:
  Install the device trees:
Line 83: Line 133:
  <br>
  <br>
  Install the kernel image and modules:
  Install the kernel image and modules:
$ cd ${WORKDIR}/{{#var:KERNEL_REPO_NAME}}
  $ cp arch/arm/boot/{{#var:KERNEL_IMAGE}} /media/user/{{#var:EMMC_FAT_PARTITION_NAME}}
  $ cp arch/arm/boot/{{#var:KERNEL_IMAGE}} /media/user/{{#var:EMMC_FAT_PARTITION_NAME}}
  $ sudo make ARCH=arm modules_install INSTALL_MOD_PATH=/media/user/rootfs
  $ sudo cp {{#var:KERNEL_ROOTFS}}/* /media/user/rootfs
   
   
  Install the device trees:
  Install the device trees:
  {{#ifeq: {{#var:HARDWARE_NAME}} | DART-6UL | $ cp arch/arm/boot/dts/imx6ul*var*.dtb /media/user/{{#var:EMMC_FAT_PARTITION_NAME}}}}
  {{#switch: {{#var:HARDWARE_NAME}}
  {{#ifeq: {{#var:HARDWARE_NAME}} | VAR-SOM-MX7 | $ cp arch/arm/boot/dts/imx7*var*.dtb /media/user/{{#var:EMMC_FAT_PARTITION_NAME}}}}
|DART-6UL=$ sudo cp arch/arm/boot/dts/imx6ul*var*.dtb /media/user/{{#var:EMMC_FAT_PARTITION_NAME}}
  {{#ifeq: {{#var:HARDWARE_NAME}} | VAR-SOM-MX6 | $ cp arch/arm/boot/dts/imx6q*var*.dtb /media/user/{{#var:EMMC_FAT_PARTITION_NAME}}<br>$ cp arch/arm/boot/dts/imx6dl*var*.dtb /media/user/{{#var:EMMC_FAT_PARTITION_NAME}}}}
  |VAR-SOM-MX7=$ sudo cp arch/arm/boot/dts/imx7*var*.dtb /media/user/{{#var:EMMC_FAT_PARTITION_NAME}}
  |VAR-SOM-MX6=$ sudo cp arch/arm/boot/dts/{imx6q*var*.dtb,imx6dl*var*.dtb} /media/user/{{#var:EMMC_FAT_PARTITION_NAME}}
}}
 
Notes:<br>
Notes:<br>
* If you are using our {{Varlink2|{{#var:PLATFORM_OS}} Recovery SD card|{{#var:RELEASE_LINK}}}}, and you want the NAND flash/eMMC installation process to be updated as well as the SD card boot itself, you need to also update the /opt/images/{{#var:PLATFORM_OS}} directory.
* If you are using our {{Varlink2|{{#var:PLATFORM_OS}} Recovery SD card|{{#var:RELEASE_LINK}}}}, and you want the NAND flash/eMMC installation process to be updated as well as the SD card boot itself, you need to also update the /opt/images/{{#var:PLATFORM_OS}} directory.
* You should always properly unmount your SD card before physically removing it.
* You should always properly unmount your SD card before physically removing it.
}}
{{#switch: {{#var:SOC_SERIES}}
|imx8
|imx9=
= Install the built kernel images, modules, and device trees using SSH on a running target =
The example below uses ssh to install the kernel on a running device.
First, export a variable with the ip address of your target device:
$ export TARGET_IP=192.168.0.205
Then, copy the kernel image and device trees to the temporary directory, send them to the target using ssh, and install them with the correct user permissions:
$ mkdir -p {{#var:KERNEL_ROOTFS}}/boot && \
  cp ${WORKDIR}/{{#var:KERNEL_REPO_NAME}}/arch/arm64/boot/dts/freescale/*imx*var*.dtb {{#var:KERNEL_ROOTFS}}/boot && \
  cp ${WORKDIR}/{{#var:KERNEL_REPO_NAME}}/arch/arm64/boot/{{#var:KERNEL_IMAGE}} {{#var:KERNEL_ROOTFS}}/boot/ && \
  ssh root@${TARGET_IP} 'mkdir /tmp/rootfs' && \
  tar czf - -C {{#var:KERNEL_ROOTFS}} . {{!}} ssh root@${TARGET_IP} 'tar xzf - -C /tmp/rootfs && chown -R root:root /tmp/rootfs && cp -a /tmp/rootfs/* / && rm -r /tmp/rootfs'
}}
}}

Latest revision as of 09:49, 26 July 2024

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

This page is using the default release RELEASE_MORTY_V1.0_DART-6UL.
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
Build Linux from source code
It is recommended to build the kernel image using Yocto (see the Customizing the Linux kernel page) instead of using the direct method described in this page.
This is because some of the Yocto packages may depend on the kernel, like the WiFi module that is built from outside of the kernel source tree on some of the Yocto releases.

Toolchain installation for out of Yocto builds

To install the toolchain, follow the Yocto Toolchain installation guide.

Setup the environment:

Setup a working directory

$ export WORKDIR=~/imx6ul-var-dart-linux
$ mkdir ${WORKDIR}

Build Linux out of Yocto tree

Fetch linux-2.6-imx source code:

$ cd $WORKDIR
$ git clone https://github.com/varigit/linux-2.6-imx.git -b imx-rel_imx_4.1.15_2.0.0_ga-var02 linux-2.6-imx
$ cd linux-2.6-imx && \
  git checkout imx-rel_imx_4.1.15_2.0.0_ga-var02 && \
  cd ../

Build Kernel, Modules, and DTBs:

Setup the environment:

$ source /opt/fslc-x11/2.2.1/environment-setup-armv7at2hf-neon-fslc-linux-gnueabi

Clean and prepare the kernel:

$ cd ${WORKDIR}/linux-2.6-imx
$ make mrproper
$ make imx6ul-var-dart_defconfig
Customize the kernel configuration (optional step):
$ make menuconfig

Build kernel parts:

Build everything:
$ make -j$(nproc)

Build zImage only:
$ make -j$(nproc)  zImage

Build modules only:
$ make -j$(nproc)  modules

Build device trees only:
$ make -j$(nproc) dtbs
Build only the device tree for DART-6UL with i.MX6UL SOC, eMMC and WiFi:
$ make -j4 imx6ul-var-dart-emmc_wifi.dtb

Build only the device tree for DART-6UL with i.MX6UL SOC, eMMC and SD card:
$ make -j4 imx6ul-var-dart-sd_emmc.dtb

Build only the device tree for DART-6UL with i.MX6UL SOC, NAND flash and WiFi:
$ make -j4 imx6ul-var-dart-nand_wifi.dtb

Build only the device tree for DART-6UL with i.MX6UL SOC, NAND flash and SD card:
$ make -j4 imx6ul-var-dart-sd_nand.dtb

Build only the device tree for DART-6UL with i.MX6ULL SOC, eMMC and WiFi:
$ make -j4 imx6ull-var-dart-emmc_wifi.dtb

Build only the device tree for DART-6UL with i.MX6ULL SOC, eMMC and SD card:
$ make -j4 imx6ull-var-dart-sd_emmc.dtb

Build only the device tree for DART-6UL with i.MX6ULL SOC, NAND flash and WiFi:
$ make -j4 imx6ull-var-dart-nand_wifi.dtb

Build only the device tree for DART-6UL with i.MX6ULL SOC, NAND flash and SD card:
$ make -j4 imx6ull-var-dart-sd_nand.dtb


Install kernel modules to temporary directory

Create a temporary directory to install the modules:

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

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

Install the modules to the temporary rootfs:

$ cd ${WORKDIR}/linux-2.6-imx && \
  make ARCH=arm \
    INSTALL_MOD_STRIP=1 \
    INSTALL_MOD_PATH=$WORKDIR/rootfs \
    modules_install


Notes:

If you replace the kernel image (zImage) on your system, you also need to reinstall the kernel modules, and vice versa.
If you just want to make a change in the device tree, you can compile and replace it without replacing the kernel image and modules.

Install the built kernel images, modules, and device trees on an SD card

Copy the zImage and device trees to the SD card boot partition, and install the modules in the SD card rootfs partition.
Assuming the boot partition is mounted on /media/user/BOOT-VAR6UL and the rootfs partition is mounted on /media/user/rootfs:

Install the kernel image and modules:
$ cd ${WORKDIR}/linux-2.6-imx
$ cp arch/arm/boot/zImage /media/user/BOOT-VAR6UL
$ sudo cp $WORKDIR/rootfs/* /media/user/rootfs

Install the device trees:
$ sudo cp arch/arm/boot/dts/imx6ul*var*.dtb /media/user/BOOT-VAR6UL

Notes:

  • If you are using our Yocto Recovery SD card, and you want the NAND flash/eMMC installation process to be updated as well as the SD card boot itself, you need to also update the /opt/images/Yocto directory.
  • You should always properly unmount your SD card before physically removing it.