Yocto Customizing the Linux kernel: Difference between revisions

From Variscite Wiki
(Use YOCTO_ENV_SETUP_X to consolidate setup-environment and var-setup-release.sh commands)
No edit summary
 
(54 intermediate revisions by 6 users not shown)
Line 1: Line 1:
<!-- Set release according to "release" parameter in URL and use PYRO_V1.0_VAR-SOM-MX6 as default
<!-- Set release according to "release" parameter in URL and use PYRO_V1.0_VAR-SOM-MX6 as default
--> {{#vardefine:RELEASE_PARAM|{{#urlget:release}}}} <!--
--> {{INIT_RELEASE_PARAM|RELEASE_PYRO_V1.0_VAR-SOM-MX6}}<!--
--> {{#lst:Yocto_Platform_Customization|{{#var:RELEASE_PARAM|RELEASE_PYRO_V1.0_VAR-SOM-MX6}}}} <!--
--> {{#lst:Yocto_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{#lst:Debian_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{#lst:B2QT_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{#vardefine:BUILD_PAGE|Yocto_Build_Release}}  {{#vardefine:PLATFORM_OS|Yocto}}        <!-- Default to Yocto
--> {{COMMON_YOCTO_VARS}} <!-- Include common yocto variables
--> {{#varexists:DEBIAN_NAME      | {{#vardefine:BUILD_PAGE|Yocto_Debian_Build_Release}} {{#vardefine:PLATFORM_OS|Debian}}  | }} <!-- Debian
--> {{#varexists:B2QT_BSP_VERSION | {{#vardefine:BUILD_PAGE|B2QT_Build_Release}}  {{#vardefine:PLATFORM_OS|Boot2Qt}} | }} <!-- B2Qt
--> {{#vardefine:DTS_DIR|arch/{{#switch: {{#var:SOC_SERIES}}|imx8|imx9=arm64|arm}}/boot/dts/{{#ifeq: {{#var:HARDWARE_NAME}}|
DART-MX8M|{{#ifeq: {{#var:YOCTO_NAME}}|Morty|variscite/|freescale/}}|{{#switch: {{#var:SOC_SERIES}} | imx8|imx9=freescale/|}}}}}} <!--
--> {{#vardefine:DTS_FILE|{{#switch: {{#var:HARDWARE_NAME}}
    |VAR-SOM-MX6=imx6qdl-var-som.dtsi
    |DART-6UL={{#var:EXAMPLE_DTSI}}
    |VAR-SOM-MX7=imx7d-var-som.dtsi
    |DART-MX8M={{#ifeq: {{#var:YOCTO_NAME}}|Morty | imx8m-var-dart-common.dtsi| {{#var:DTSI_CARRIER|fsl-imx8m-var-dart-common.dtsi}}}}
    |DART-MX8M-MINI={{#var:DTB_PREFIX|fsl-imx8mm-var-dart}}.dts
    |VAR-SOM-MX8=fsl-imx8qm-var-som-common.dtsi
    |VAR-SOM-MX8M-NANO={{#var:DTB_PREFIX|fsl-imx8mn-var-som}}.dts
    |DART-MX8M-PLUS={{#var:DTB_PREFIX|imx8mp-var-dart}}.dts
    |{{#var:DEFAULT_DTS|example-devicetree.dtsi}}}}}} <!-- Default works for SoMs that defined DEFAULT_DTB in YPC like VAR-SOM-MX8, VAR-SOM-MX93, and maybe others
--> {{PageHeader|{{#var:HARDWARE_NAME}} - Customizing the Linux kernel}} {{DocImage|category1=Yocto|category2={{#var:HARDWARE_NAME}}}} __toc__
--> {{PageHeader|{{#var:HARDWARE_NAME}} - Customizing the Linux kernel}} {{DocImage|category1=Yocto|category2={{#var:HARDWARE_NAME}}}} __toc__
<!-- Set local variables
If >= Dunfell, KBUILD_DEFCONFIG is used, and using an out of tree defconfig is slightly different.
--> {{#vardefine:EXTERNAL_DEFCONFIG | {{#ifexpr: {{#var:YOCTO_VERSION}} < 3.1 | my_defconfig | defconfig }} }} <!--
-->{{#vardefine:BUILD_FOLDER_DISTRO | {{ #varexists:BUILD_FOLDER_X11 | {{#var:BUILD_FOLDER_X11}} | {{ #varexists:BUILD_FOLDER_XWAYLAND | {{#var:BUILD_FOLDER_XWAYLAND}} | {{#var:BUILD_FOLDER_B2QT}} }} }} }}<!--
--> {{#vardefine:KERNEL_RECIPE_NAME | linux-variscite_{{#var: KERNEL_RECIPE_VER | % }} }} <!--
--> {{#vardefine:BB_ENV | {{#varexists: B2QT_GIT | MACHINE={{#var:MACHINE_NAME}} | }} }}
<br>
<br>
After customizing the kernel by following the below instructions, you can either bitbake your complete image (e.g. fsl-image-gui) and the updated kernel will be used, or you can bitbake the kernel alone by running "bitbake virtual/kernel" (see the {{Varlink|Yocto_Build_Release|{{#var:RELEASE_LINK}}|Build Yocto from source code}} page for the initial Yocto setup and for more info on using bitbake).
After customizing the kernel by following the below instructions, you can either bitbake your complete image (e.g. fsl-image-gui) and the updated kernel will be used, or you can bitbake the kernel alone by running "{{#var:BB_ENV}} bitbake virtual/kernel" (see the {{Varlink|{{#var:BUILD_PAGE}}|{{#var:RELEASE_LINK}}|Build {{#var:PLATFORM_OS}} from source code}} page for the initial setup and for more info on using bitbake).


= Configuring the kernel =
= Configuring the kernel =


The default kernel configuration file used by Yocto is part of the kernel source tree and is located at:
The default kernel configuration file used by Yocto is part of the kernel source tree and is located at:
  arch/{{#ifeq: {{#var:SOC_SERIES}}|imx8|arm64|arm}}/configs/{{#var:KERNEL_DEFCONFIG}}
  arch/{{#switch: {{#var:SOC_SERIES}}|imx8|imx9=arm64|arm}}/configs/{{#var:KERNEL_DEFCONFIG}}


<br>
<br>
To configure the kernel using Yocto:
To configure the kernel using Yocto:
* Follow steps 1-3 of the {{Varlink2|Yocto Build Release|{{#var:RELEASE_LINK}}}} page.
* Follow steps 1-3 of the {{Varlink|{{#var:BUILD_PAGE}}|{{#var:RELEASE_LINK}}|Build {{#var:PLATFORM_OS}} from source code}} page.
* Follow the first part of step 4 of the same page, to source the setup-environment script (stop after that - don't build any image). E.g.:
* Follow the first part of step 4 of the same page, to source the setup-environment script (stop after that - don't build any image). E.g.:
{{#lst:Yocto_Platform_Customization|YOCTO_ENV_SETUP_X}}
{{#lst:Yocto_Platform_Customization|YOCTO_ENV_SETUP_X}}
{{#vardefine:LOCAL_BUILD_FOLDER|{{#if:{{#var:BUILD_YOCTO_IN_DOCKER_CONTAINER}}|/workdir|{{#var:BUILD_FOLDER}}}}}}
{{#vardefine:SHELL_PROMPT|{{#if:{{#var:BUILD_YOCTO_IN_DOCKER_CONTAINER}}|vari@yocto-{{#var:DOCKER_CONTAINER_INFO}}:/workdir|{{#var:BUILD_FOLDER}}}}}}
{{#vardefine:EDITOR|{{#if:{{#var:BUILD_YOCTO_IN_DOCKER_CONTAINER}}|nano|gedit}}}}


* Run menuconfig and configure the kernel:
* Run menuconfig and configure the kernel:
  $ bitbake -c menuconfig virtual/kernel
{{#ifeq: {{#var:OS}} | Boot2Qt | {{#ifexpr: {{#var:YOCTO_VERSION}} >= 3.3 |
{{Note|'''Note:''' Starting from the B2Qt Hardknott release, the B2Qt standard toolchain's linker is now the gold linker, which is incompatible with the Linux kernel, causing menuconfig to fail when run from bitbake. Add the following line to <code>conf/local.conf</code> to run menuconfig:<br>
<pre>DISTRO_FEATURES:remove = "ld-is-gold"</pre> }} | }} | }}
  {{#var:SHELL_PROMPT}}/{{#var:BUILD_FOLDER_ENV}}$ {{#var:BB_ENV}} bitbake -c menuconfig virtual/kernel
When finished, save and exit.
When finished, save and exit.


The .config file is saved to {{#var:BUILD_FOLDER}}/{{#ifeq: {{#var:SOC_SERIES}}|imx8|{{#var:BUILD_FOLDER_XWAYLAND}}|{{#var:BUILD_FOLDER_X11}}}}/tmp/work/{{#var:MACHINE_NAME_}}{{#ifeq: {{#var:SOC_SERIES}}|imx8|-poky-linux|-fslc-linux-gnueabi}}/linux-variscite/{{#var:KERNEL_VER}}-r0/build/.config<br>
The .config file is saved to {{#var:LOCAL_BUILD_FOLDER}}/{{#var:BUILD_FOLDER_DISTRO}}/tmp/work/{{#var:MACHINE_NAME_}}{{#var:ARCH_PREFIX}}{{#var:ARCH_SUFFIX}}/linux-variscite/<kernel version>/build/.config<br>
<br>
<br>
* At this point, you can continue following the rest of step 4 of the {{Varlink2|Yocto Build Release|{{#var:RELEASE_LINK}}}} page to build your image with the newly configured kernel, or just build the kernel by running "bitbake virtual/kernel", or, you can follow the next steps to use this configuration permanently.
* At this point, you can continue following the rest of step 4 of the {{Varlink|{{#var:BUILD_PAGE}}|{{#var:RELEASE_LINK}}|Build {{#var:PLATFORM_OS}} from source code}} page to build your image with the newly configured kernel, or just build the kernel by running "{{#var:BB_ENV}} bitbake virtual/kernel", or, you can follow the next steps to use this configuration permanently.
<br>
<br>
To save the configuration in a defconfig format:
To save the configuration in a defconfig format:
  $ bitbake -c savedefconfig virtual/kernel
  {{#var:SHELL_PROMPT}}/{{#var:BUILD_FOLDER_ENV}}$ {{#var:BB_ENV}} bitbake -c savedefconfig virtual/kernel
The defconfig file is saved to {{#var:BUILD_FOLDER}}/{{#ifeq: {{#var:SOC_SERIES}}|imx8|{{#var:BUILD_FOLDER_XWAYLAND}}|{{#var:BUILD_FOLDER_X11}}}}/tmp/work/{{#var:MACHINE_NAME_}}{{#ifeq: {{#var:SOC_SERIES}}|imx8|-poky-linux|-fslc-linux-gnueabi}}/linux-variscite/{{#var:KERNEL_VER}}-r0/build/defconfig<br>
The defconfig file is saved to {{#var:LOCAL_BUILD_FOLDER}}/{{#var:BUILD_FOLDER_DISTRO}}/tmp/work/{{#var:MACHINE_NAME_}}{{#var:ARCH_PREFIX}}{{#var:ARCH_SUFFIX}}/linux-variscite/<kernel version>/build/defconfig<br>
<br>
<br>
To make the kernel recipe use this configuration permanently, you can do either of the following:<br>
To make the kernel recipe use this configuration permanently, you can do either of the following:<br>
* Use any of the three methods described in the [[#Making changes in the source code|Making changes in the source code]] section below to overwrite the default configuration file in the source tree, arch/{{#ifeq: {{#var:SOC_SERIES}}|imx8|arm64|arm}}/configs/{{#var:KERNEL_DEFCONFIG}}, and replace it with the above defconfig.
* Use any of the three methods described in the [[#Making changes in the source code|Making changes in the source code]] section below to overwrite the default configuration file in the source tree, arch/{{#switch: {{#var:SOC_SERIES}}|imx8|imx9=arm64|arm}}/configs/{{#var:KERNEL_DEFCONFIG}}, and replace it with the above defconfig.


* Make the kernel recipe use the defconfig from outside of the source tree:
* Make the kernel recipe use the defconfig from outside of the source tree:
Copy your defconfig:
Copy your defconfig:
  $ cd {{#var:BUILD_FOLDER}}/sources/{{#ifeq: {{#var:SOC_SERIES}}|imx8|meta-variscite-imx|meta-variscite-fslc}}/recipes-kernel/linux/
  {{#var:SHELL_PROMPT}}/{{#var:BUILD_FOLDER_ENV}}$ cd {{#var:LOCAL_BUILD_FOLDER}}/sources/{{#var:META_VARISCITE_REPO}}/recipes-kernel/linux/
$ mkdir -p files
{{#var:SHELL_PROMPT}}/sources/{{#var:META_VARISCITE_REPO}}/recipes-kernel/linux$ mkdir -p files
  $ cp {{#var:BUILD_FOLDER}}/{{#ifeq: {{#var:SOC_SERIES}}|imx8|{{#var:BUILD_FOLDER_XWAYLAND}}|{{#var:BUILD_FOLDER_X11}}}}/tmp/work/{{#var:MACHINE_NAME_}}{{#ifeq: {{#var:SOC_SERIES}}|imx8|-poky-linux|-fslc-linux-gnueabi}}/linux-variscite/{{#var:KERNEL_VER}}-r0/build/defconfig  files/my_defconfig
  {{#var:SHELL_PROMPT}}/sources/{{#var:META_VARISCITE_REPO}}/recipes-kernel/linux$ cp {{#var:LOCAL_BUILD_FOLDER}}/{{#var:BUILD_FOLDER_DISTRO}}/tmp/work/{{#var:MACHINE_NAME_}}{{#var:ARCH_PREFIX}}{{#var:ARCH_SUFFIX}}/linux-variscite/<kernel version>/build/defconfig  files/{{#var:EXTERNAL_DEFCONFIG}}


Create a linux-variscite_{{#var:KERNEL_VER}}.bbappend file:
Create a {{#var:KERNEL_RECIPE_NAME}}.bbappend file:
  $ gedit linux-variscite_{{#var:KERNEL_VER}}.bbappend
  {{#var:SHELL_PROMPT}}/sources/{{#var:META_VARISCITE_REPO}}/recipes-kernel/linux$ {{#var:EDITOR}} {{#var:KERNEL_RECIPE_NAME}}.bbappend


and append the following to it:
and append the following to it:
  SRC_URI += "file://my_defconfig"
 
  KERNEL_DEFCONFIG_{{#var:MACHINE_NAME}} = "${WORKDIR}/my_defconfig"
{{#ifexpr: {{#var:YOCTO_VERSION}} < 3.1 |&nbsp;
  SRC_URI += "file://{{#var:EXTERNAL_DEFCONFIG}}"
  KERNEL_DEFCONFIG{{#var:YOCTO_OVERRIDE_PREFIX}}{{#var:MACHINE_NAME}} = "${WORKDIR}/{{#var:EXTERNAL_DEFCONFIG}}"
|&nbsp;
SRC_URI += "file://{{#var:EXTERNAL_DEFCONFIG}}"
KBUILD_DEFCONFIG{{#var:YOCTO_OVERRIDE_PREFIX}}{{#var:MACHINE_NAME}} = ""
}}
{{#if: {{#var:BUILD_YOCTO_IN_DOCKER_CONTAINER}} | {{Note|'''Note:''' if, running {{#var:EDITOR}}, you see the error '''{{#var:EDITOR}}: command not found''' please install it with '''sudo apt install {{#var:EDITOR}}''' password '''ubuntu''' '''.}}}}


= Making changes in the source code =
= Making changes in the source code =
Line 52: Line 93:
<br>
<br>
'''Setup Yocto''':<br>
'''Setup Yocto''':<br>
* Follow steps 1-3 of the {{Varlink2|Yocto Build Release|{{#var:RELEASE_LINK}}}} page.
* Follow steps 1-3 of the {{Varlink|{{#var:BUILD_PAGE}}|{{#var:RELEASE_LINK}}|Build {{#var:PLATFORM_OS}} from source code}} page.
* Follow the first part of step 4 of the same page, to source the setup-environment script (stop after that - don't build any image). E.g.:
* Follow the first part of step 4 of the same page, to source the setup-environment script (stop after that - don't build any image). E.g.:
{{#lst:Yocto_Platform_Customization|YOCTO_ENV_SETUP_X}}
{{#lst:Yocto_Platform_Customization|YOCTO_ENV_SETUP_X}}
<br>
<br>
'''Get the source code''':<br>
'''Get the source code''':<br>
  $ bitbake -c unpack virtual/kernel
  {{#var:SHELL_PROMPT}}/{{#var:BUILD_FOLDER_ENV}}$ {{#var:BB_ENV}} bitbake -c patch virtual/kernel
  $ mkdir -p ../local_repos/{{#var:KERNEL_REPO_NAME}}
  {{#var:SHELL_PROMPT}}/{{#var:BUILD_FOLDER_ENV}}$ mkdir -p ../local_repos/{{#var:KERNEL_REPO_NAME}}
  $ cp -a tmp/work-shared/{{#var:MACHINE_NAME}}/kernel-source/. ../local_repos/{{#var:KERNEL_REPO_NAME}}
  {{#var:SHELL_PROMPT}}/{{#var:BUILD_FOLDER_ENV}}$ cp -a tmp/work-shared/{{#var:MACHINE_NAME}}/kernel-source/. ../local_repos/{{#var:KERNEL_REPO_NAME}}
  $ cd ../local_repos/{{#var:KERNEL_REPO_NAME}}
  {{#var:SHELL_PROMPT}}/{{#var:BUILD_FOLDER_ENV}}$ cd ../local_repos/{{#var:KERNEL_REPO_NAME}}
  $ git reset --hard
  {{#var:SHELL_PROMPT}}/local_repos/{{#var:KERNEL_REPO_NAME}}$ git reset --hard
  $ git clean -fdx
  {{#var:SHELL_PROMPT}}/local_repos/{{#var:KERNEL_REPO_NAME}}$ git clean -fdx
<br>
<br>
'''Make your changes in the source code and create a patch''':<br>
'''Make your changes in the source code and create a patch''':<br>
You can use either diff or patch file types.<br>
You can use either diff or patch file types.<br>
For example:
For example:
  $ cd {{#var:BUILD_FOLDER}}/local_repos/{{#var:KERNEL_REPO_NAME}}
  {{#var:SHELL_PROMPT}}/local_repos/{{#var:KERNEL_REPO_NAME}}$ {{#var:EDITOR}} {{#var:DTS_DIR}}{{#var:DTS_FILE}}
$ gedit arch/{{#ifeq: {{#var:SOC_SERIES}}|imx8|arm64|arm}}/boot/dts/{{#ifeq: {{#var:HARDWARE_NAME}}|DART-MX8M|{{#ifeq: {{#var:YOCTO_NAME}}|Morty|variscite/|freescale/}}|{{#ifeq: {{#var:SOC_SERIES}} | imx8 |freescale/|}}}}{{#ifeq: {{#var:HARDWARE_NAME}} | VAR-SOM-MX6 |imx6qdl-var-som.dtsi|}}{{#ifeq: {{#var:HARDWARE_NAME}} | DART-6UL |{{#var:EXAMPLE_DTSI}}|}}{{#ifeq: {{#var:HARDWARE_NAME}} | VAR-SOM-MX7 |imx7d-var-som.dtsi|}}{{#ifeq: {{#var:HARDWARE_NAME}} | DART-MX8M | {{#ifeq: {{#var:YOCTO_NAME}}|Morty | imx8m-var-dart-common.dtsi| {{#var:DTB_PREFIX|fsl-imx8mq-var-dart}}-common.dtsi}}|}}{{#ifeq: {{#var:HARDWARE_NAME}} | DART-MX8M-MINI |fsl-imx8mm-var-dart.dts|}}{{#ifeq: {{#var:HARDWARE_NAME}} | VAR-SOM-MX8 |fsl-imx8qm-var-som-common.dtsi|}}{{#ifeq: {{#var:HARDWARE_NAME}} | VAR-SOM-MX8M-NANO |{{#var:DTB_PREFIX|fsl-imx8mn-var-som}}.dts|}}{{#ifeq: {{#var:HARDWARE_NAME}} | DART-MX8M-PLUS |{{#var:DTB_PREFIX|imx8mp-var-dart}}.dts|}}
  edit and save
  edit and save
   
   
  $ git diff > my_device_tree_changes.diff
  {{#var:SHELL_PROMPT}}/local_repos/{{#var:KERNEL_REPO_NAME}}$ git diff > my_device_tree_changes.patch
<br>
<br>
'''Update the recipes to use your patch''':<br>
'''Update the recipes to use your patch''':<br>
Copy your patch:
Copy your patch:
  $ cd {{#var:BUILD_FOLDER}}/sources/{{#ifeq: {{#var:SOC_SERIES}}|imx8|meta-variscite-imx|meta-variscite-fslc}}/recipes-kernel/linux/
  {{#var:SHELL_PROMPT}}/local_repos/{{#var:KERNEL_REPO_NAME}}$ cd {{#var:LOCAL_BUILD_FOLDER}}/sources/{{#var:META_VARISCITE_REPO}}/recipes-kernel/linux/
$ mkdir -p files
{{#var:SHELL_PROMPT}}/sources/{{#var:META_VARISCITE_REPO}}/recipes-kernel/linux$ mkdir -p files
  $ cp {{#var:BUILD_FOLDER}}/local_repos/{{#var:KERNEL_REPO_NAME}}/my_device_tree_changes.diff files/
  {{#var:SHELL_PROMPT}}/sources/{{#var:META_VARISCITE_REPO}}/recipes-kernel/linux$ cp {{#var:LOCAL_BUILD_FOLDER}}/local_repos/{{#var:KERNEL_REPO_NAME}}/my_device_tree_changes.patch files/


Create a linux-variscite_{{#var:KERNEL_VER}}.bbappend file:
Create a {{#var:KERNEL_RECIPE_NAME}}.bbappend file:
  $ gedit linux-variscite_{{#var:KERNEL_VER}}.bbappend
  {{#var:SHELL_PROMPT}}/sources/{{#var:META_VARISCITE_REPO}}/recipes-kernel/linux$ {{#var:EDITOR}} {{#var:KERNEL_RECIPE_NAME}}.bbappend


and append the following line to it:
and append the following line to it:
  SRC_URI += "file://my_device_tree_changes.diff"
  SRC_URI += "file://my_device_tree_changes.patch"


== Use a local repository ==
== Use a local repository ==
Line 89: Line 129:
<br>
<br>
'''Setup Yocto''':<br>
'''Setup Yocto''':<br>
* Follow steps 1-3 of the {{Varlink2|Yocto Build Release|{{#var:RELEASE_LINK}}}} page.
* Follow steps 1-3 of the {{Varlink|{{#var:BUILD_PAGE}}|{{#var:RELEASE_LINK}}|Build {{#var:PLATFORM_OS}} from source code}} page.
* Follow the first part of step 4 of the same page, to source the setup-environment script (stop after that - don't build any image). E.g.:
* Follow the first part of step 4 of the same page, to source the setup-environment script (stop after that - don't build any image). E.g.:
$ cd {{#var:BUILD_FOLDER}}
{{#lst:Yocto_Platform_Customization|YOCTO_ENV_SETUP_X}}
$ MACHINE={{#var:MACHINE_NAME}} DISTRO={{#var:BUILD_DISTRO}} {{#var:BUILD_SCRIPT}} {{#ifeq: {{#var:SOC_SERIES}}|imx8|-b {{#var:BUILD_FOLDER_XWAYLAND}}|{{#var:BUILD_FOLDER_X11}}}}
<br>
<br>
'''Get the source code''':<br>
'''Get the source code''':<br>
  $ bitbake -c unpack virtual/kernel
  {{#var:SHELL_PROMPT}}/{{#var:BUILD_FOLDER_ENV}}$ {{#var:BB_ENV}} bitbake -c patch virtual/kernel
  $ mkdir -p ../local_repos/{{#var:KERNEL_REPO_NAME}}
  {{#var:SHELL_PROMPT}}/{{#var:BUILD_FOLDER_ENV}}$ mkdir -p ../local_repos/{{#var:KERNEL_REPO_NAME}}
  $ cp -a tmp/work-shared/{{#var:MACHINE_NAME}}/kernel-source/. ../local_repos/{{#var:KERNEL_REPO_NAME}}
  {{#var:SHELL_PROMPT}}/{{#var:BUILD_FOLDER_ENV}}$ cp -a tmp/work-shared/{{#var:MACHINE_NAME}}/kernel-source/. ../local_repos/{{#var:KERNEL_REPO_NAME}}
  $ cd ../local_repos/{{#var:KERNEL_REPO_NAME}}
  {{#var:SHELL_PROMPT}}/{{#var:BUILD_FOLDER_ENV}}$ cd ../local_repos/{{#var:KERNEL_REPO_NAME}}
  $ git reset --hard
  {{#var:SHELL_PROMPT}}/local_repos/{{#var:KERNEL_REPO_NAME}}$ git reset --hard
  $ git clean -fdx
  {{#var:SHELL_PROMPT}}/local_repos/{{#var:KERNEL_REPO_NAME}}$ git clean -fdx
<br>
<br>
'''Make your changes in the source code and commit them:'''<br>
'''Make your changes in the source code and commit them:'''<br>
After making changes in the source code ''you need to commit them''.<br>
After making changes in the source code ''you need to commit them''.<br>
For example:
For example:
  $ cd {{#var:BUILD_FOLDER}}/local_repos/{{#var:KERNEL_REPO_NAME}}
  {{#var:SHELL_PROMPT}}/local_repos/{{#var:KERNEL_REPO_NAME}}$ {{#var:EDITOR}} {{#var:DTS_DIR}}{{#var:DTS_FILE}}
$ gedit arch/{{#ifeq: {{#var:SOC_SERIES}}|imx8|arm64|arm}}/boot/dts/{{#ifeq: {{#var:HARDWARE_NAME}}|DART-MX8M|{{#ifeq: {{#var:YOCTO_NAME}}|Morty|variscite/|freescale/}}|{{#ifeq: {{#var:SOC_SERIES}} | imx8 |freescale/|}}}}{{#ifeq: {{#var:HARDWARE_NAME}} | VAR-SOM-MX6 |imx6qdl-var-som.dtsi|}}{{#ifeq: {{#var:HARDWARE_NAME}} | DART-6UL |{{#var:EXAMPLE_DTSI}}|}}{{#ifeq: {{#var:HARDWARE_NAME}} | VAR-SOM-MX7 |imx7d-var-som.dtsi|}}{{#ifeq: {{#var:HARDWARE_NAME}} | DART-MX8M | {{#ifeq: {{#var:YOCTO_NAME}}|Morty | imx8m-var-dart-common.dtsi| {{#var:DTB_PREFIX|fsl-imx8m-var-dart}}-common.dtsi}}|}}{{#ifeq: {{#var:HARDWARE_NAME}} | DART-MX8M-MINI |fsl-imx8mm-var-dart.dts|}}{{#ifeq: {{#var:HARDWARE_NAME}} | VAR-SOM-MX8 |fsl-imx8qm-var-som-common.dtsi|}}{{#ifeq: {{#var:HARDWARE_NAME}} | VAR-SOM-MX8M-NANO |{{#var:DTB_PREFIX|fsl-imx8mn-var-som}}.dts|}}{{#ifeq: {{#var:HARDWARE_NAME}} | DART-MX8M-PLUS |{{#var:DTB_PREFIX|imx8mp-var-dart}}.dts|}}
  edit and save
  edit and save
   
   
  $ git commit -a -m "my device tree changes"
  {{#var:SHELL_PROMPT}}/local_repos/{{#var:KERNEL_REPO_NAME}}$ git commit -a -m "my device tree changes"


  To list all of the commits:
  To list all of the commits:
  $ git log
  {{#var:SHELL_PROMPT}}/local_repos/{{#var:KERNEL_REPO_NAME}}$ git log


  Get the latest commit id:
  Get the latest commit id:
  $ git rev-parse HEAD
  {{#var:SHELL_PROMPT}}/local_repos/{{#var:KERNEL_REPO_NAME}}$ git rev-parse HEAD
<br>
<br>
'''Update the recipes to use the local repository instead of the default one:'''<br>
'''Update the recipes to use the local repository instead of the default one:'''<br>
  $ cd {{#var:BUILD_FOLDER}}/sources/{{#ifeq: {{#var:SOC_SERIES}}|imx8|meta-variscite-imx|meta-variscite-fslc}}/recipes-kernel/linux/
  {{#var:SHELL_PROMPT}}/local_repos/{{#var:KERNEL_REPO_NAME}}$ cd {{#var:LOCAL_BUILD_FOLDER}}/sources/{{#var:META_VARISCITE_REPO}}/recipes-kernel/linux/


Create a linux-variscite_{{#var:KERNEL_VER}}.bbappend file:
Create a {{#var:KERNEL_RECIPE_NAME}}.bbappend file:
  $ gedit linux-variscite_{{#var:KERNEL_VER}}.bbappend
  {{#var:SHELL_PROMPT}}/sources/{{#var:META_VARISCITE_REPO}}/recipes-kernel/linux$ {{#var:EDITOR}} {{#var:KERNEL_RECIPE_NAME}}.bbappend


and append the following lines to it (see the previous section for listing the commits or getting the latest commit id):
and append the following lines to it (see the previous section for listing the commits or getting the latest commit id):


  KERNEL_SRC = <nowiki>"git://${BSPDIR}/local_repos/</nowiki>{{#var:KERNEL_REPO_NAME}}<nowiki>;protocol=file"</nowiki>
  KERNEL_SRC = <nowiki>"git://${BSPDIR}/local_repos/</nowiki>{{#var:KERNEL_REPO_NAME}}<nowiki>;protocol=file"</nowiki>
  SRCBRANCH = "{{#var:KERNEL_BRANCH}}" ''(or your own created branch)''
  SRCBRANCH{{#var:YOCTO_OVERRIDE_PREFIX}}{{#var:MACHINE_NAME}} = "{{#var:KERNEL_BRANCH}}" ''(or your own created branch)''
  SRCREV = "''The commit id you'd like to use''"
  SRCREV{{#var:YOCTO_OVERRIDE_PREFIX}}{{#var:MACHINE_NAME}} = "''The commit id you'd like to use''"
<br>
<br>
{{note|For the SRCREV value you can also use "${AUTOREV}" during development to get the latest commit of the branch<br>
{{note|For the SRCREV value you can also use "${AUTOREV}" during development to get the latest commit of the branch<br>
(If you do so, make sure to run "bitbake -c cleansstate virtual/kernel" before rebuilding the kernel)}}
(If you do so, make sure to run "{{#var:BB_ENV}} bitbake -c cleansstate virtual/kernel" before rebuilding the kernel)}}


== Use your own remote repository on github ==
== Use your own remote repository on github ==
Line 144: Line 182:
'''Update the recipes to use your remote repository instead of the default one''':<br>
'''Update the recipes to use your remote repository instead of the default one''':<br>
<br>
<br>
  $ cd {{#var:BUILD_FOLDER}}/sources/{{#ifeq: {{#var:SOC_SERIES}}|imx8|meta-variscite-imx|meta-variscite-fslc}}/recipes-kernel/linux/
Create a {{#var:KERNEL_RECIPE_NAME}}.bbappend file:
 
  {{#var:SHELL_PROMPT}}/sources/{{#var:META_VARISCITE_REPO}}/recipes-kernel/linux$ {{#var:EDITOR}} {{#var:KERNEL_RECIPE_NAME}}.bbappend
Create a linux-variscite_{{#var:KERNEL_VER}}.bbappend file:
$ gedit linux-variscite_{{#var:KERNEL_VER}}.bbappend


and append the following lines to it (see the previous section for listing the commits or getting the latest commit id):
and append the following lines to it (see the previous section for listing the commits or getting the latest commit id):
Line 156: Line 192:
<br>
<br>
{{note|For the SRCREV value you can also use "${AUTOREV}" during development to get the latest commit of the branch<br>
{{note|For the SRCREV value you can also use "${AUTOREV}" during development to get the latest commit of the branch<br>
(If you do so, make sure to run "bitbake -c cleansstate virtual/kernel" before rebuilding the kernel)}}
(If you do so, make sure to run "{{#var:BB_ENV}} bitbake -c cleansstate virtual/kernel" before rebuilding the kernel)}}

Latest revision as of 18:35, 24 October 2024

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

This page is using the default release RELEASE_PYRO_V1.0_VAR-SOM-MX6.
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-MX6 - Customizing the Linux kernel



After customizing the kernel by following the below instructions, you can either bitbake your complete image (e.g. fsl-image-gui) and the updated kernel will be used, or you can bitbake the kernel alone by running " bitbake virtual/kernel" (see the Build Yocto from source code page for the initial setup and for more info on using bitbake).

Configuring the kernel

The default kernel configuration file used by Yocto is part of the kernel source tree and is located at:

arch/arm/configs/imx_v7_var_defconfig


To configure the kernel using Yocto:

  • Follow steps 1-3 of the Build Yocto from source code page.
  • Follow the first part of step 4 of the same page, to source the setup-environment script (stop after that - don't build any image). E.g.:
$ cd ~/var-fslc-yocto
$ MACHINE=var-som-mx6 DISTRO=fslc-x11 . setup-environment build_x11



  • Run menuconfig and configure the kernel:
~/var-fslc-yocto/build_x11$  bitbake -c menuconfig virtual/kernel

When finished, save and exit.

The .config file is saved to ~/var-fslc-yocto/build_x11/tmp/work/var_som_mx6-fslc-linux-gnueabi/linux-variscite/<kernel version>/build/.config

  • At this point, you can continue following the rest of step 4 of the Build Yocto from source code page to build your image with the newly configured kernel, or just build the kernel by running " bitbake virtual/kernel", or, you can follow the next steps to use this configuration permanently.


To save the configuration in a defconfig format:

~/var-fslc-yocto/build_x11$  bitbake -c savedefconfig virtual/kernel

The defconfig file is saved to ~/var-fslc-yocto/build_x11/tmp/work/var_som_mx6-fslc-linux-gnueabi/linux-variscite/<kernel version>/build/defconfig

To make the kernel recipe use this configuration permanently, you can do either of the following:

  • Use any of the three methods described in the Making changes in the source code section below to overwrite the default configuration file in the source tree, arch/arm/configs/imx_v7_var_defconfig, and replace it with the above defconfig.
  • Make the kernel recipe use the defconfig from outside of the source tree:

Copy your defconfig:

~/var-fslc-yocto/build_x11$ cd ~/var-fslc-yocto/sources/meta-variscite-fslc/recipes-kernel/linux/
~/var-fslc-yocto/sources/meta-variscite-fslc/recipes-kernel/linux$ mkdir -p files
~/var-fslc-yocto/sources/meta-variscite-fslc/recipes-kernel/linux$ cp ~/var-fslc-yocto/build_x11/tmp/work/var_som_mx6-fslc-linux-gnueabi/linux-variscite/<kernel version>/build/defconfig  files/my_defconfig

Create a linux-variscite_%.bbappend file:

~/var-fslc-yocto/sources/meta-variscite-fslc/recipes-kernel/linux$ gedit linux-variscite_%.bbappend

and append the following to it:

 

SRC_URI += "file://my_defconfig"
KERNEL_DEFCONFIG_var-som-mx6 = "${WORKDIR}/my_defconfig"


Making changes in the source code

Choose one of the following three methods to customize the Linux kernel and build it using Yocto:

Add your own patches on top of our source code

Using this method Yocto will take the source code from our default remote repository, and apply your patches to it before building it:

Setup Yocto:

  • Follow steps 1-3 of the Build Yocto from source code page.
  • Follow the first part of step 4 of the same page, to source the setup-environment script (stop after that - don't build any image). E.g.:
$ cd ~/var-fslc-yocto
$ MACHINE=var-som-mx6 DISTRO=fslc-x11 . setup-environment build_x11


Get the source code:

~/var-fslc-yocto/build_x11$  bitbake -c patch virtual/kernel
~/var-fslc-yocto/build_x11$ mkdir -p ../local_repos/linux-2.6-imx
~/var-fslc-yocto/build_x11$ cp -a tmp/work-shared/var-som-mx6/kernel-source/. ../local_repos/linux-2.6-imx
~/var-fslc-yocto/build_x11$ cd ../local_repos/linux-2.6-imx
~/var-fslc-yocto/local_repos/linux-2.6-imx$ git reset --hard
~/var-fslc-yocto/local_repos/linux-2.6-imx$ git clean -fdx


Make your changes in the source code and create a patch:
You can use either diff or patch file types.
For example:

~/var-fslc-yocto/local_repos/linux-2.6-imx$ gedit arch/arm/boot/dts/imx6qdl-var-som.dtsi
edit and save

~/var-fslc-yocto/local_repos/linux-2.6-imx$ git diff > my_device_tree_changes.patch


Update the recipes to use your patch:
Copy your patch:

~/var-fslc-yocto/local_repos/linux-2.6-imx$ cd ~/var-fslc-yocto/sources/meta-variscite-fslc/recipes-kernel/linux/
~/var-fslc-yocto/sources/meta-variscite-fslc/recipes-kernel/linux$ mkdir -p files
~/var-fslc-yocto/sources/meta-variscite-fslc/recipes-kernel/linux$ cp ~/var-fslc-yocto/local_repos/linux-2.6-imx/my_device_tree_changes.patch  files/

Create a linux-variscite_%.bbappend file:

~/var-fslc-yocto/sources/meta-variscite-fslc/recipes-kernel/linux$ gedit linux-variscite_%.bbappend

and append the following line to it:

SRC_URI += "file://my_device_tree_changes.patch"

Use a local repository

Using this method Yocto will take the kernel source from a local repository instead of our remote ones on github:

Setup Yocto:

  • Follow steps 1-3 of the Build Yocto from source code page.
  • Follow the first part of step 4 of the same page, to source the setup-environment script (stop after that - don't build any image). E.g.:
$ cd ~/var-fslc-yocto
$ MACHINE=var-som-mx6 DISTRO=fslc-x11 . setup-environment build_x11


Get the source code:

~/var-fslc-yocto/build_x11$  bitbake -c patch virtual/kernel
~/var-fslc-yocto/build_x11$ mkdir -p ../local_repos/linux-2.6-imx
~/var-fslc-yocto/build_x11$ cp -a tmp/work-shared/var-som-mx6/kernel-source/. ../local_repos/linux-2.6-imx
~/var-fslc-yocto/build_x11$ cd ../local_repos/linux-2.6-imx
~/var-fslc-yocto/local_repos/linux-2.6-imx$ git reset --hard
~/var-fslc-yocto/local_repos/linux-2.6-imx$ git clean -fdx


Make your changes in the source code and commit them:
After making changes in the source code you need to commit them.
For example:

~/var-fslc-yocto/local_repos/linux-2.6-imx$ gedit arch/arm/boot/dts/imx6qdl-var-som.dtsi
edit and save

~/var-fslc-yocto/local_repos/linux-2.6-imx$ git commit -a -m "my device tree changes"
To list all of the commits:
~/var-fslc-yocto/local_repos/linux-2.6-imx$ git log
Get the latest commit id:
~/var-fslc-yocto/local_repos/linux-2.6-imx$ git rev-parse HEAD


Update the recipes to use the local repository instead of the default one:

~/var-fslc-yocto/local_repos/linux-2.6-imx$ cd ~/var-fslc-yocto/sources/meta-variscite-fslc/recipes-kernel/linux/

Create a linux-variscite_%.bbappend file:

~/var-fslc-yocto/sources/meta-variscite-fslc/recipes-kernel/linux$ gedit linux-variscite_%.bbappend

and append the following lines to it (see the previous section for listing the commits or getting the latest commit id):

KERNEL_SRC = "git://${BSPDIR}/local_repos/linux-2.6-imx;protocol=file"
SRCBRANCH_var-som-mx6 = "imx-rel_imx_4.1.15_2.0.0_ga-var02" (or your own created branch)
SRCREV_var-som-mx6 = "The commit id you'd like to use"


For the SRCREV value you can also use "${AUTOREV}" during development to get the latest commit of the branch
(If you do so, make sure to run " bitbake -c cleansstate virtual/kernel" before rebuilding the kernel)

Use your own remote repository on github

Using this method Yocto will take the source code from your own remote repository on github:

Create your own github account and upload your proprietary kernel to a new repository:
For example, you can fork our repository to your own account by visiting the following link and clicking on "Fork" at the top right of the screen.
Alternatively, you can clone our repository to your local machine, and push it later to your own account.

https://github.com/varigit/linux-2.6-imx/tree/imx-rel_imx_4.1.15_2.0.0_ga-var02


Update the recipes to use your remote repository instead of the default one:

Create a linux-variscite_%.bbappend file:

~/var-fslc-yocto/sources/meta-variscite-fslc/recipes-kernel/linux$ gedit linux-variscite_%.bbappend

and append the following lines to it (see the previous section for listing the commits or getting the latest commit id):

KERNEL_SRC = "git://github.com/your_account/linux-2.6-imx.git;protocol=git"
SRCBRANCH = "imx-rel_imx_4.1.15_2.0.0_ga-var02" (or your own created branch)
SRCREV = "The commit id you'd like to use"


For the SRCREV value you can also use "${AUTOREV}" during development to get the latest commit of the branch
(If you do so, make sure to run " bitbake -c cleansstate virtual/kernel" before rebuilding the kernel)