新闻| 论坛| 博客| 在线研讨会
Mainline Linux 和 U-Boot编译
toradex| 2023-08-25 16:42:04 阅读:416 发布文章

By Toradex胡珊逢

Toradex自从Linux BSP v6开始在使用32位处理器的Arm模块如iMX6iMX6ULLiMX7上提供mainline/upstream kernel部分64位处理器模块如Verdin iMX8M Mini/Plus也提供实验性支持。文章将以季度发布版本Linux BSP V6.3.0为例介绍如何下载和编译mainline/upstream Linux kernelU-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.0Toradex 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

----------------------------------

在电脑上使用下面命令并checkoutv6.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为对应的季度发布版本号。在页面中可以看到如下内容:

----------------------------------

----------------------------------

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

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

----------------------------------

$ 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下载即可。

MainlineLinux和u-boot编译_web5621.png

MainlineLinux和u-boot编译_web5623.png

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下载源码,并checkoutv2022.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文件夹后,在其中下载和checkoutU-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位处理器的模块,默认配置如下:

lcolibri_imx6_defconfig

lcolibri-imx6ull_defconfig

lcolibri-imx6ull-emmc_defconfig

lcolibri_imx7_defconfig

lcolibri_imx7_emmc_defconfig

lapalis_imx6_defconfig

Apalis iMX6为例

----------------------------------

$ make mrproper

$ make apalis_imx6_defconfig

----------------------------------

最后编译U-Boot

----------------------------------

$ make -j$(nproc)

----------------------------------


*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。

参与讨论
登录后参与讨论
推荐文章
最近访客