Mainline Linux 和 U-Boot编译

By Toradex胡珊逢

Toradex 自从 Linux BSP v6 开始在使用 32位处理器的 Arm 模块如 iMX6、iMX6ULL、iMX7 上提供 mainline/upstream kernel ,部分 64位处理器模块如 Verdin iMX8M Mini/Plus 也提供实验性支持。文章将以季度发布版本 Linux BSP V6.3.0 为例介绍如何下载和编译 mainline/upstream Linux kernel 和 U-Boot。

Linux

下载 kernel 源码

内核源码可以从官网 https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git 下载。但考虑到国内网络情况,推荐从国内的镜像站点下载,如 https://mirrors.tuna.tsinghua.edu.cn/git/linux-stable.git。默认下载时会获取最新的 upstream 内核版本。可根据模块上运行 Linux 的版本 checkout 到对应版本源码。在模块上的 Linux 中运行 uname 命令,可以看到当前版本是 6.1.37。后面的 6.3.0 是 Toradex Linux BSP 季度发布版本。季度发布版本是经过充分的自动化和人工测试后发布的,可用于对应模块的生产环境。


root@apalis-imx6:~# uname -a

Linux apalis-imx6 6.1.37-6.3.0+git.0f4ac6b4c5f0 #1 SMP Sat Jul 1 11:16:27 UTC 2023 armv7l armv7l armv7l GNU/Linux


在电脑上使用下面命令并 checkout 到 v6.1.37。


$ git clone https://mirrors.tuna.tsinghua.edu.cn/git/linux-stable.git

$ git checkout v6.1.37


下载和应用补丁

mainline/upstream kernel 通常还需要一些补丁。它们可以从 meta-toradex-bsp-common 中下载,后续其版本也需要对应到一样的季度版本。首先打开网址 https://git.toradex.com/cgit/toradex-manifest.git/tree/bsp/pinned-tdx.xml?h=6.3.0。结尾的 6.3.0 为对应的季度发布版本号。在页面中可以看到如下内容:


<project name="meta-toradex-bsp-common.git" path="layers/meta-toradex-bsp-common" remote="tdx" revision="f7ff10a3b560dcf4e258115da679d1f864e09837" upstream="kirkstone-6.x.y"/>


可以看到 meta-toradex-bsp-common.git 在季度发布版本 6.3.0 对应的 hash 是 f7ff10a3b560dcf4e258115da679d1f864e09837。通常建议使用最新发布的季度版本,获得问题修复和功能完善。因此,下载时请修改季度发布版本号和 hash 值。

进入上面下载的 Linux 源码目录后创建 patch 文件夹,并在其中下载 meta-toradex-bsp-common,checkout 对应用版本。


$ cd linux-stable/

$ mkdir patch

$ cd patch

$ git clone https://git.toradex.com/cgit/meta-toradex-bsp-common.git

$ cd meta-toradex-bsp-common

$ git checkout f7ff10a3b560dcf4e258115da679d1f864e09837


将 meta-toradex-bsp-common/recipes-kernel/linux/linux-toradex-mainline-git 的所有 patch 文件复制到 patch 目录下。


$ cp meta-toradex-bsp-common/recipes-kernel/linux/linux-toradex-mainline-git/*.patch ./


在 patch 目录下使用 git am 命令给 kernel 打补丁。注意必须要以固定的顺序打补丁。补丁顺序可以参看 meta-toradex-bsp-common/recipes-kernel/linux/linux-toradex-mainline_git.bb 文件。


SRC_URI:append = " \

file://0001-thermal-imx-Update-critical-temp-threshold.patch \

file://0001-Revert-drm-panel-simple-drop-use-of-data-mapping-pro.patch \

file://0001-arm-dts-colibri-imx6-usb-dual-role-switching.patch \

file://0002-arm-dts-colibri-imx6-move-vbus-supply-to-module-leve.patch \

file://0003-arm-dts-colibri-imx6-specify-usbh_pen-gpio-being-act.patch \

file://0001-arm-dts-colibri-imx6ull-keep-peripherals-disabled.patch \

file://0002-arm-dts-colibri-imx6ull-enable-default-peripherals.patch \

file://0001-ARM-dts-colibri-imx6ull-Enable-dual-role-switching.patch \

file://0002-drivers-chipidea-disable-runtime-pm-for-imx6ul.patch \

file://0001-ARM-dts-apalis-imx6-Disable-usb-over-current.patch \

file://0002-ARM-dts-colibri-imx6-Disable-usb-over-current.patch \

file://0003-ARM-dts-colibri-imx6ull-Disable-usb-over-current.patch \

file://0004-ARM-dts-colibri-imx7-Disable-usb-over-current.patch \

file://0001-arm64-dts-imx8mm-verdin-Add-yavia-carrier-board.patch \

file://0002-arm64-dts-imx8mp-verdin-Add-yavia-carrier-board.patch \

file://0001-media-v4l2-async-fix-binding-async-subdevs-with-mult.patch \

file://0002-media-i2c-ov5640-Implement-get_mbus_config.patch \

file://0001-Revert-media-v4l2-async-Use-endpoints-in-__v4l2_asyn.patch \

"


在 patch 文件夹里执行面命令,期间不应该出现任何错误和冲突。


$ cd patch

$ git am 0001-thermal-imx-Update-critical-temp-threshold.patch \

0001-Revert-drm-panel-simple-drop-use-of-data-mapping-pro.patch \

0001-arm-dts-colibri-imx6-usb-dual-role-switching.patch \

0002-arm-dts-colibri-imx6-move-vbus-supply-to-module-leve.patch \

0003-arm-dts-colibri-imx6-specify-usbh_pen-gpio-being-act.patch \

0001-arm-dts-colibri-imx6ull-keep-peripherals-disabled.patch \

0002-arm-dts-colibri-imx6ull-enable-default-peripherals.patch \

0001-ARM-dts-colibri-imx6ull-Enable-dual-role-switching.patch \

0002-drivers-chipidea-disable-runtime-pm-for-imx6ul.patch \

0001-ARM-dts-apalis-imx6-Disable-usb-over-current.patch \

0002-ARM-dts-colibri-imx6-Disable-usb-over-current.patch \

0003-ARM-dts-colibri-imx6ull-Disable-usb-over-current.patch \

0004-ARM-dts-colibri-imx7-Disable-usb-over-current.patch \

0001-arm64-dts-imx8mm-verdin-Add-yavia-carrier-board.patch \

0002-arm64-dts-imx8mp-verdin-Add-yavia-carrier-board.patch \

0001-media-v4l2-async-fix-binding-async-subdevs-with-mult.patch \

0002-media-i2c-ov5640-Implement-get_mbus_config.patch \

0001-Revert-media-v4l2-async-Use-endpoints-in-__v4l2_asyn.patch


kernel 配置

内核配置文件 .config 也可以从 Toradex Artifactory 下载,并使用对应的季度发布版本的编译文件。打开 Toradex Artifactory 网页,在左边的 Artifact Repository Browser 中点开 oe-release,选择 Linux BSP v6 对应的 kirkstone-6.x.y。依次打开 kirkstone-6.x.y/release/7/apalis-imx6/tdx-xwayland-upstream/tdx-reference-multimedia-image/oedeploy/。release 下面一般可以选择最大序列的,这对应最新的发布版本。右击 kernel-config 下载即可。

将 kernel-config 复制到刚才下载的内核源码目录,命名为 .config ,用其作为 Linux 的默认配置。如果需要修改,后面还可以使用 make menuconfig 命令。


$ cd linux-stable/

$ mv kernel-config .config

$ make olddefconfig


准备好源码、补丁和内核配置文件,接下来就可以编译了,具体方法参考这里

U-Boot

下载 U-Boot 源码

首先从 https://source.denx.de/u-boot/u-boot.git 下载源码,并 checkout 到 v2022.07 版本,也是 Linux BSP v6 所使用的 U-Boot 版本。


$ git clone https://source.denx.de/u-boot/u-boot.git

$ cd u-boot

$ git checkout v2022.07


下载和应用补丁

Upstream/mainline U-Boot 同样也需要相关补丁,和上面一样由 meta-toradex-bsp-common 提供。按照前面的方法在 u-boot 目录中建立 patch 文件夹后,在其中下载和 checkout。U-Boot 补丁位于 meta-toradex-bsp-common/recipes-bsp/u-boot/u-boot-toradex 目录下。将里面的 patch 文件复制到 u-boot/patch 目录下。


$ cd u-boot

$ mkdir patch

$ cd patch

$ git clone https://git.toradex.com/cgit/meta-toradex-bsp-common.git

$ cd meta-toradex-bsp-common

$ git checkout f7ff10a3b560dcf4e258115da679d1f864e09837

$ cp meta-toradex-bsp-common/recipes-bsp/u-boot/u-boot-toradex/*.patch ./


注意必须要以固定的顺序打补丁。补丁顺序可以参看 U-Boot meta-toradex-bsp-common/recipes-bsp/u-boot/u-boot-toradex_2022.07.bb 文件。


TDX_PATCHES = " \

file://0001-toradex-tdx-cfg-block-use-only-snprintf.patch \

file://0002-toradex-tdx-cfg-block-use-defines-for-string-length.patch \

file://0003-toradex-tdx-cfg-block-extend-assembly-version.patch \

file://0004-toradex-tdx-cfg-block-add-new-toradex-oui-range.patch \

file://0005-toradex-tdx-cfg-block-add-0068-i.mx-8m-mini-sku.patch \

file://0006-toradex-common-Remove-stale-comments-about-modules-a.patch \

file://0007-toradex-common-Use-ARRAY_SIZE-macro.patch \

file://0008-toradex-tdx-cfg-block-Cleanup-interactive-cfg-block-.patch \

file://0009-toradex-common-Remove-stale-function-declaration.patch \

file://0010-toradex-common-Remove-ifdef-usage-for-2nd-ethaddr.patch \

file://0011-toradex-tdx-cfg-block-Use-official-SKU-names.patch \

file://0012-toradex-common-Improve-product-serial-print-during-b.patch \

file://0013-configs-colibri-imx7-Enable-bootd-command.patch \

file://0001-ARM-imx8mp-verdin-imx8mp-Add-memory-size-detection.patch \

file://0001-apalis-colibri_imx6-imx6ull-_imx7-update-env-memory-.patch \

file://0001-configs-colibri-imx7-Fix-bad-block-table-in-flash-co.patch \

file://0001-colibri_imx6-fix-RALAT-and-WALAT-values.patch \

"


在 patch 文件夹里执行面 git am 命令,期间不应该出现任何错误和冲突。


$ git am 0001-toradex-tdx-cfg-block-use-only-snprintf.patch \

0002-toradex-tdx-cfg-block-use-defines-for-string-length.patch \

0003-toradex-tdx-cfg-block-extend-assembly-version.patch \

0004-toradex-tdx-cfg-block-add-new-toradex-oui-range.patch \

0005-toradex-tdx-cfg-block-add-0068-i.mx-8m-mini-sku.patch \

0006-toradex-common-Remove-stale-comments-about-modules-a.patch \

0007-toradex-common-Use-ARRAY_SIZE-macro.patch \

0008-toradex-tdx-cfg-block-Cleanup-interactive-cfg-block-.patch \

0009-toradex-common-Remove-stale-function-declaration.patch \

0010-toradex-common-Remove-ifdef-usage-for-2nd-ethaddr.patch \

0011-toradex-tdx-cfg-block-Use-official-SKU-names.patch \

0012-toradex-common-Improve-product-serial-print-during-b.patch \

0013-configs-colibri-imx7-Enable-bootd-command.patch \

0001-ARM-imx8mp-verdin-imx8mp-Add-memory-size-detection.patch \

0001-apalis-colibri_imx6-imx6ull-_imx7-update-env-memory-.patch \

0001-configs-colibri-imx7-Fix-bad-block-table-in-flash-co.patch \

0001-colibri_imx6-fix-RALAT-and-WALAT-values.patch


U-Boot 配置

对于 32位处理器的模块,默认配置如下:

l colibri_imx6_defconfig

l colibri-imx6ull_defconfig

l colibri-imx6ull-emmc_defconfig

l colibri_imx7_defconfig

l colibri_imx7_emmc_defconfig

l apalis_imx6_defconfig

以 Apalis iMX6 为例。


$ make mrproper

$ make apalis_imx6_defconfig


最后编译 U-Boot。


make -j(nproc)


相关推荐
Mr. Cao code7 小时前
Docker:颠覆传统虚拟化的轻量级革命
linux·运维·ubuntu·docker·容器
抓饼先生8 小时前
Linux control group笔记
linux·笔记·bash
挺6的还8 小时前
25.线程概念和控制(二)
linux
您的通讯录好友8 小时前
conda环境导出
linux·windows·conda
代码AC不AC9 小时前
【Linux】vim工具篇
linux·vim·工具详解
码农hbk10 小时前
Linux signal 图文详解(三)信号处理
linux·信号处理
bug攻城狮10 小时前
Skopeo 工具介绍与 CentOS 7 安装指南
linux·运维·centos
宇宙第一小趴菜10 小时前
08 修改自己的Centos的软件源
linux·运维·centos
bug攻城狮10 小时前
彻底禁用 CentOS 7.9 中 vi/vim 的滴滴声
linux·运维·服务器·centos·vim
XMYX-010 小时前
Linux 物理机如何区分 SSD 与 HDD ——以 DELL PERC H730 Mini 为例
linux·运维