移植Linux 6.3.5系统到imx6ull开发板

本章主要是移植Linux 6.3.5版本到imx6ull 开发板,目前手上的板子是正点原子MINI开发板(V1.8)

1.下载Linux源码包

下载链接:官网会慢些,镜像地址更快

linux-6.3.5.tar.gz:
http://mirrors.163.com/kernel/
https://mirrors.edge.kernel.org/pub/
https://mirror.bjtu.edu.cn/kernel/linux/kernel/

2.解压源码包
tar -zxvf linux-6.3.5.tar.gz
3.清理工程

在编译Linux之前,我们先对源码工程进行清理一下

make clean
4.编译
4.1.选择imx6ull默认配置文件

配置文件所在文件夹:arch/arm/configs ls查看配置文件有哪些,一眼看见imx系列有imx_v4_v5_defconfig和imx_v6_v7_defconfig两个默认的配置文件,但是我们选择哪个进行配置编译呢?

toto@toto:~/workspace/kernel/linux-6.3.5$ ls arch/arm/configs/
am200epdkit_defconfig   exynos_defconfig      milbeaut_m10v_defconfig  omap2plus_defconfig  socfpga_defconfig
aspeed_g4_defconfig     footbridge_defconfig  mmp2_defconfig           orion5x_defconfig    sp7021_defconfig
aspeed_g5_defconfig     gemini_defconfig      moxart_defconfig         oxnas_v6_defconfig   spear13xx_defconfig
assabet_defconfig       h3600_defconfig       mps2_defconfig           pxa168_defconfig     spear3xx_defconfig
at91_dt_defconfig       hisi_defconfig        multi_v4t_defconfig      pxa3xx_defconfig     spear6xx_defconfig
axm55xx_defconfig       imxrt_defconfig       multi_v5_defconfig       pxa910_defconfig     spitz_defconfig
bcm2835_defconfig       imx_v4_v5_defconfig   multi_v7_defconfig       pxa_defconfig        stm32_defconfig
clps711x_defconfig      imx_v6_v7_defconfig   mv78xx0_defconfig        qcom_defconfig       sunxi_defconfig
collie_defconfig        integrator_defconfig  mvebu_v5_defconfig       realview_defconfig   tegra_defconfig
davinci_all_defconfig   ixp4xx_defconfig      mvebu_v7_defconfig       rpc_defconfig        u8500_defconfig
dove_defconfig          jornada720_defconfig  mxs_defconfig            s3c6400_defconfig    versatile_defconfig
dram_0x00000000.config  keystone_defconfig    neponset_defconfig       s5pv210_defconfig    vexpress_defconfig
dram_0xc0000000.config  lpae.config           netwinder_defconfig      sama5_defconfig      vf610m4_defconfig
dram_0xd0000000.config  lpc18xx_defconfig     nhk8815_defconfig        sama7_defconfig      vt8500_v6_v7_defconfig
ep93xx_defconfig        lpc32xx_defconfig     omap1_defconfig          shmobile_defconfig   wpcm450_defconfig

网上查询了一下得知:imx_v4_v5_defconfig用于arm-v4,v5架构,而imx_v6_v7_defconfig用于arm-v6,v7架构的处理器 而imx6ull是arm-v7架构的,因此我们选择imx_v6_v7_defconfig进行配置编译。

4.2.编译

修改Makefile文件,在如下地方添加如下两行

# Cross compiling and selecting different set of gcc/bin-utils
# ---------------------------------------------------------------------------
#
# When performing cross compilation for other architectures ARCH shall be set
# to the target architecture. (See arch/* for the possibilities).
# ARCH can be set during invocation of make:
# make ARCH=ia64
# Another way is to have ARCH set in the environment.
# The default ARCH is the host where make is executed.
 
# CROSS_COMPILE specify the prefix used for all executables used
# during compilation. Only gcc and related bin-utils executables
# are prefixed with $(CROSS_COMPILE).
# CROSS_COMPILE can be set on the command line
# make CROSS_COMPILE=ia64-linux-
# Alternatively CROSS_COMPILE can be set in the environment.
# Default value for CROSS_COMPILE is not to prefix executables
# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
ARCH        ?= arm
CROSS_COMPILE ?= arm-linux-gnueabihf-

编译指令

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- distclean             /*清理工程*/
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- imx_v6_v7_defconfig /*选择配置文件*/
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j8                   /*提高编译速率,采用8线程编译*/
4.3.编译报错(我用的是正点原子的Ubuntu Linux镜像,所以不会出现该问题)

经过1个小时的编译,结果报错了,如下;

LD [M]  drivers/siox/siox-bus-gpio.ko
  LD [M]  net/bluetooth/bnep/bnep.ko
  KSYMS   .tmp_vmlinux.kallsyms2.S
  AS      .tmp_vmlinux.kallsyms2.S
  LD      vmlinux
  NM      System.map
  SORTTAB vmlinux
  OBJCOPY arch/arm/boot/Image
  Kernel: arch/arm/boot/Image is ready
  AS      arch/arm/boot/compressed/head.o
  LDS     arch/arm/boot/compressed/vmlinux.lds
  LZO     arch/arm/boot/compressed/piggy_data
/bin/sh: 1: lzop: not found
  CC      arch/arm/boot/compressed/misc.o
arch/arm/boot/compressed/Makefile:162: recipe for target 'arch/arm/boot/compressed/piggy_data' failed
make[2]: *** [arch/arm/boot/compressed/piggy_data] Error 127
make[2]: *** 正在删除文件“arch/arm/boot/compressed/piggy_data”
make[2]: *** 正在等待未完成的任务....
arch/arm/boot/Makefile:58: recipe for target 'arch/arm/boot/compressed/vmlinux' failed
make[1]: *** [arch/arm/boot/compressed/vmlinux] Error 2
arch/arm/Makefile:301: recipe for target 'zImage' failed
make: *** [zImage] Error 2

原因:lzop库未找到 解决方法:手动安装lzop库

sudo apt-get install lzop
4.4.编译通过
toto@toto:~/workspace/kernel/linux-6.3.5$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j8
  CALL    scripts/checksyscalls.sh
  Kernel: arch/arm/boot/Image is ready
  CC      arch/arm/boot/compressed/string.o
  AS      arch/arm/boot/compressed/hyp-stub.o
  CC      arch/arm/boot/compressed/decompress.o
  LZO     arch/arm/boot/compressed/piggy_data
  CC      arch/arm/boot/compressed/fdt_rw.o
  CC      arch/arm/boot/compressed/fdt_ro.o
  CC      arch/arm/boot/compressed/fdt_wip.o
  CC      arch/arm/boot/compressed/fdt.o
  CC      arch/arm/boot/compressed/fdt_check_mem_start.o
  AS      arch/arm/boot/compressed/lib1funcs.o
  AS      arch/arm/boot/compressed/ashldi3.o
  AS      arch/arm/boot/compressed/bswapsdi2.o
  AS      arch/arm/boot/compressed/piggy.o
  LD      arch/arm/boot/compressed/vmlinux
  OBJCOPY arch/arm/boot/zImage
  Kernel: arch/arm/boot/zImage is ready
4.5.下载验证

将编译好的zImage和imx6ull-14x14-evk.dtb下载到开发板上 1.从网络启动 Linux 系统,设置u-boot下bootcmd和bootargs,

setenv bootargs 'console=ttymxc0,115200 root=/dev/mmcblk1p2 rootwait rw'
setenv bootcmd 'tftp 80800000 zImage; tftp 83000000 imx6ull-14x14-evk.dtb; bootz 80800000 - 83000000'
saveenv

重启开发板,串口打印信息如下;

[    2.469400] platform regulatory.0: Falling back to sysfs fallback for: regulatory.db
[    2.477276] ALSA device list:
[    2.480344]   No soundcards found.
[    2.485955] /dev/root: Can't open blockdev
[    2.490552] VFS: Cannot open root device "mmcblk1p2" or unknown-block(179,2): error -6
[    2.498729] Please append a correct "root=" boot option; here are the available partitions:
[    2.507139] 0100           65536 ram0 
[    2.507171]  (driver?)
[    2.513427] 0101           65536 ram1 
[    2.513457]  (driver?)
[    2.519697] 0102           65536 ram2 
[    2.519730]  (driver?)
[    2.525878] 0103           65536 ram3 
[    2.525904]  (driver?)
[    2.532141] 0104           65536 ram4 
[    2.532171]  (driver?)
[    2.538374] 0105           65536 ram5 
[    2.538403]  (driver?)
[    2.544549] 0106           65536 ram6 
[    2.544574]  (driver?)
[    2.550841] 0107           65536 ram7 
[    2.550872]  (driver?)
[    2.557018] 0108           65536 ram8 
[    2.557043]  (driver?)
[    2.563254] 0109           65536 ram9 
[    2.563283]  (driver?)
[    2.569508] 010a           65536 ram10 
[    2.569537]  (driver?)
[    2.575771] 010b           65536 ram11 
[    2.575797]  (driver?)
[    2.582113] 010c           65536 ram12 
[    2.582145]  (driver?)
[    2.588435] 010d           65536 ram13 
[    2.588464]  (driver?)
[    2.594697] 010e           65536 ram14 
[    2.594723]  (driver?)
[    2.601037] 010f           65536 ram15 
[    2.601065]  (driver?)
[    2.607313] b300         7634944 mmcblk1 
[    2.607339]  driver: mmcblk
[    2.614243] b308            4096 mmcblk1boot0 
[    2.614272]  (driver?)
[    2.621211] b310            4096 mmcblk1boot1 
[    2.621243]  (driver?)
[    2.628142] b318        15558144 mmcblk0 
[    2.628171]  driver: mmcblk
[    2.635045]   b319        15556608 mmcblk0p1 ab37899a-01
[    2.635076] 
[    2.641989] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(179,2)
[    2.650483] ---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(179,2) ]---
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(179,2)

也就是提示内核崩溃,因为 VFS(虚拟文件系统)不能挂载根文件系统,因为根文件系统目录不存在。即使根文件系统目录存在,如果根文件系统目录里面是空的依旧会提示内核崩溃。这个就是根文件系统缺失导致的内核崩溃,但是内核是启动了的,只是根文件系统不存在而已。 本来开发板的eMMC默认是格式化分区好了,linux成功启动后就能成功挂载根文件系统,但是我们是为了学习的,eMMC的分区也应该知道怎么弄。因此在u-boot将eMMC分区擦除,后面自己手动来格式化分区eMMC。Linux系统启动后就会看到上面的信息“Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(179,2)”,提示内核崩溃。 跟文件系统的制作和加载将在下一篇文章进行详细介绍。

5.Linux中添加自己的开发板

下面我们来学习如何在Linux中添加自己的开发板信息。 在Linux中添加自己的开发板信息跟在u-boot中添加自己的开发板是一样的。

5.1.添加开发板默认配置文件

将 arch/arm/configs 目录下的 imx_v6_v7_mfg_defconfig 重新复制一份,命名为imx_toto_defconfig,命令如下:

cd arch/arm/configs
cp imx_v6_v7_defconfig imx_toto_defconfig

后面 imx_toto_defconfig 就是我们开发板的默认配置文件了,使用如下命令进行配置开发板对应的Linux内核:

make imx_toto_defconfig
5.2.添加开发板对应的设备树文件

添加适合 imx6ull 开发板的设备树文件,进入目录 arch/arm/boot/dts 中,可以看到Linux中有很多imx6ull版本的设备树文件

toto@toto:~/workspace/kernel/linux-6.3.5/arch/arm/boot/dts$ ls imx6ull
imx6ull-14x14-evk.dtb                  imx6ull-colibri-wifi.dtsi              imx6ull-opos6ul.dtsi
imx6ull-14x14-evk.dts                  imx6ull-colibri-wifi-eval-v3.dtb       imx6ull-phytec-phycore-som.dtsi
imx6ull-colibri-aster.dtb              imx6ull-colibri-wifi-eval-v3.dts       imx6ull-phytec-segin.dtsi
imx6ull-colibri-aster.dts              imx6ull-colibri-wifi-iris.dtb          imx6ull-phytec-segin-ff-rdk-emmc.dtb
imx6ull-colibri-aster.dtsi             imx6ull-colibri-wifi-iris.dts          imx6ull-phytec-segin-ff-rdk-emmc.dts
imx6ull-colibri.dtsi                   imx6ull-colibri-wifi-iris-v2.dtb       imx6ull-phytec-segin-ff-rdk-nand.dtb
imx6ull-colibri-emmc-aster.dtb         imx6ull-colibri-wifi-iris-v2.dts       imx6ull-phytec-segin-ff-rdk-nand.dts
imx6ull-colibri-emmc-aster.dts         imx6ull-dhcom-drc02.dtb                imx6ull-phytec-segin-lc-rdk-nand.dtb

我们这里使用 imx6ull-14x14-evk.dts。拷贝 imx6ull-14x14-evk.dts,然后将其重命名为 imx6ull-toto.dts,命令如下:

cd arch/arm/boot/dts
cp imx6ull-14x14-evk.dts imx6ull-toto.dts

.dts 是设备树源码文件,编译 Linux 的时候会将其编译为.dtb 文件

5.3.修改设备树目录下的Makefile文件

打开 arch/arm/boot/dts/Makefile 文件,找 到 “ dtb-$(CONFIG_SOC_IMX6UL) ”配置项,在此配置项中加入“imx6ull-toto.dtb” ,如下所示:

dtb-$(CONFIG_SOC_IMX6UL) += \
    imx6ul-14x14-evk.dtb \
    imx6ul-ccimx6ulsbcexpress.dtb \
    imx6ul-ccimx6ulsbcpro.dtb \
    imx6ul-geam.dtb \
    imx6ul-isiot-emmc.dtb \
    imx6ul-isiot-nand.dtb \
    imx6ul-kontron-bl.dtb \
    imx6ul-kontron-bl-43.dtb \
    imx6ul-liteboard.dtb \
    imx6ul-tqma6ul1-mba6ulx.dtb \
    imx6ul-tqma6ul2-mba6ulx.dtb \
    imx6ul-tqma6ul2l-mba6ulx.dtb \
    imx6ul-opos6uldev.dtb \
    imx6ul-pico-dwarf.dtb \
    imx6ul-pico-hobbit.dtb \
    imx6ul-pico-pi.dtb \
    imx6ul-phytec-segin-ff-rdk-emmc.dtb \
    imx6ul-phytec-segin-ff-rdk-nand.dtb \
    imx6ul-prti6g.dtb \
    imx6ul-tx6ul-0010.dtb \
    imx6ul-tx6ul-0011.dtb \
    imx6ul-tx6ul-mainboard.dtb \
    imx6ull-14x14-evk.dtb \
    imx6ull-toto.dtb \

25行是我们添加的“imx6ull_toto.dtb”,这样编译 Linux 的时候就可以从 imx6ull-toto.dts 编译出 imx6ull-toto.dtb 文件了。

5.4.编译

现在Linux内核已经添加了imx6ull开发板,接下来就是编译测试。为了方便后续的编译,我们先进行编译脚本的创建,脚本内容如下:

vi build.sh
#!/bin/sh
 
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- distclean
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- imx_toto_defconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- all -j8

给编译脚本文件添加可执行权限:

chmod 777 build.sh

编译

./build.sh

下载验证

Starting kernel ...
 
[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 6.3.5-g43eca22d987f-dirty (toto@toto) (arm-linux-gnueabihf-gcc (Linaro GCC 7.5-2019.12) 7.5.0, GNU ld (Linaro_Binutils-2019.12) 2.28.2.20170706) #1 SMP Sat Jun 10 23:45:23 CST 2023
[    0.000000] CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=10c5387d
[    0.000000] CPU: div instructions available: patching division code
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[    0.000000] OF: fdt: Machine model: Freescale i.MX6 UltraLiteLite 14x14 EVK Board
[    0.000000] Memory policy: Data cache writealloc

Linux 内核启动成功,说明我们已经在Linux 内核源码中添加了imx6ull开发板。 至此Linux系统已经移植到imx6ull开发板,但是网络是否正常工作现在还不能知道,需要制作跟文件系统后,Linux启动后成功挂载跟文件系统后才能知道,下一篇将介绍跟文件系统的制作与eMMC的分区。

今天的内容到此就完了,感谢大家的收看,如有不正之处,欢迎批评指正,下期再见!
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值