移植NXP Linux Kernel 5.15
2024-7-7
hongxi.zhu
1. 下载NXP Linux Kernel 5.15
仓库[nxp-imx/linux-imx]
git clone -b lf-5.15.y https://github.com/nxp-imx/linux-imx.git
2. 编译NXP Linux Kernel 5.15
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- distclean
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- imx_v7_defconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j16
3. 烧写NXP Linux Kernel 5.15
编译生成
arch/arm/boot/dts/imx6ull-14x14-evk-emmc.dtb
arch/arm/boot/zImage
使用tftp方式下载上面两个文件到板子上(uboot移植看前面的文章)
setenv bootargs 'console=ttymxc0,115200 root=/dev/mmcblk1p2 rootwait rw'
setenv bootcmd 'tftp 80800000 zImage; tftp 83000000 imx6ull-14x14-evk-emmc.dtb; bootz 80800000 - 83000000'
saveenv
boot
4. 适配正点原子Alpha板子
4.1 新建单板配置文件
cp ./arch/arm/configs/imx_v7_defconfig ./arch/arm/configs/imx6ull_alpha_emmc_defconfig
4.2 新建单板设备树文件
cp ./arch/arm/boot/dts/imx6ull-14x14-evk-emmc.dts ./arch/arm/boot/dts/imx6ull-14x14-alpha-emmc.dts
cp ./arch/arm/boot/dts/imx6ull-14x14-evk.dts ./arch/arm/boot/dts/imx6ull-14x14-alpha.dts
cp ./arch/arm/boot/dts/imx6ul-14x14-evk.dtsi ./arch/arm/boot/dts/imx6ul-14x14-alpha.dtsi
- 修改imx6ull-14x14-alpha.dts
/dts-v1/;#include "imx6ull.dtsi"
#include "imx6ul-14x14-alpha.dtsi"/ {model = "Freescale i.MX6 ULL 14x14 EVK Board";compatible = "fsl,imx6ull-14x14-evk", "fsl,imx6ull";
};
...
- 修改imx6ull-14x14-alpha-emmc.dts
#include "imx6ull-14x14-alpha.dts"&usdhc2 {pinctrl-names = "default", "state_100mhz", "state_200mhz";pinctrl-0 = <&pinctrl_usdhc2_8bit>;pinctrl-1 = <&pinctrl_usdhc2_8bit_100mhz>;pinctrl-2 = <&pinctrl_usdhc2_8bit_200mhz>;bus-width = <8>;non-removable;status = "okay";
};
- 修改dts目录下的Makefile, 添加imx6ull-14x14-alpha-emmc.dts
...imx6ull-14x14-evk.dtb \imx6ull-14x14-evk-emmc.dtb \imx6ull-14x14-alpha-emmc.dtb \imx6ull-14x14-evk-btwifi.dtb \imx6ull-14x14-evk-btwifi-sdio3_0.dtb \imx6ull-14x14-evk-gpmi-weim.dtb \...
4.3 编译
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- distclean
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- imx6ull_alpha_emmc_defconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j16
4.4 烧录
修改uboot中tftp配置
setenv bootargs 'console=ttymxc0,115200 root=/dev/mmcblk1p2 rootwait rw'
setenv bootcmd 'tftp 80800000 zImage; tftp 83000000 imx6ull-14x14-alpha-emmc.dtb; bootz 80800000 - 83000000'
saveenv
boot
正常引导效果:
=> setenv bootcmd 'tftp 80800000 zImage; tftp 83000000 imx6ull-14x14-alpha-emmc.dtb; bootz 80800000 - 83000000'
=> saveenv
Saving Environment to MMC... Writing to MMC(0)... OK
=>
=>
=> boot
ethernet@20b4000 Waiting for PHY auto negotiation to complete.... done
Using ethernet@20b4000 device
TFTP from server 192.168.3.32; our IP address is 192.168.3.38
Filename 'zImage'.
Load address: 0x80800000
Loading: #############################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################1.1 MiB/s
done
Bytes transferred = 9574272 (921780 hex)
Using ethernet@20b4000 device
TFTP from server 192.168.3.32; our IP address is 192.168.3.38
Filename 'imx6ull-14x14-alpha-emmc.dtb'.
Load address: 0x83000000
Loading: ###2 MiB/s
done
Bytes transferred = 35807 (8bdf hex)
Kernel image @ 0x80800000 [ 0x000000 - 0x921780 ]
## Flattened Device Tree blob at 83000000Booting using the fdt blob at 0x83000000Using Device Tree in place at 83000000, end 8300bbde
Modify /soc/bus@2200000/epdc@228c000 disabledStarting kernel ...[ 0.000000] Booting Linux on physical CPU 0x0
[ 0.000000] Linux version 5.15.71-dirty (hongxi@hongxi-virtual-machine) (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 PREEMPT Sun Jul 7 16:24:28 CST 2024
[ 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 ULL 14x14 EVK Board
[ 0.000000] Memory policy: Data cache writealloc
[ 0.000000] Reserved memory: created CMA memory pool at 0x96000000, size 160 MiB
[ 0.000000] OF: reserved mem: initialized node linux,cma, compatible id shared-dma-pool
[ 0.000000] Zone ranges:
[ 0.000000] Normal [mem 0x0000000080000000-0x000000009fffffff]
...
4.5 适配alpha的网口
4.5.1 修改设备树
arch/arm/boot/dts/imx6ul-14x14-alpha.dtsi
spi4 {compatible = "spi-gpio";pinctrl-names = "default";pinctrl-0 = <&pinctrl_spi4>;status = "okay";gpio-sck = <&gpio5 11 0>;gpio-mosi = <&gpio5 10 0>;num-chipselects = <1>;#address-cells = <1>;#size-cells = <0>;gpio_spi: gpio@0 {compatible = "fairchild,74hc595";gpio-controller;#gpio-cells = <2>;reg = <0>;registers-number = <1>;registers-default = /bits/ 8 <0x57>;spi-max-frequency = <100000>;};};...pinctrl_spi4: spi4grp { /*删除gpio5-7 gpio5-8的声明*/fsl,pins = <MX6UL_PAD_BOOT_MODE0__GPIO5_IO10 0x70a1MX6UL_PAD_BOOT_MODE1__GPIO5_IO11 0x70a1>;};/*eth1-phy reset*/pinctrl_enet1_reset: enet1resetgrp {fsl,pins = <MX6ULL_PAD_SNVS_TAMPER7__GPIO5_IO07 0x10B0 /*gpio5-7*/>;};/*eth2-phy reset*/pinctrl_enet2_reset: enet2resetgrp {fsl,pins = <MX6UL_PAD_SNVS_TAMPER8__GPIO5_IO08 0x10B0 /*gpio5-8*/>;};pinctrl_enet1: enet1grp {fsl,pins = <MX6UL_PAD_ENET1_RX_EN__ENET1_RX_EN 0x1b0b0MX6UL_PAD_ENET1_RX_ER__ENET1_RX_ER 0x1b0b0MX6UL_PAD_ENET1_RX_DATA0__ENET1_RDATA00 0x1b0b0MX6UL_PAD_ENET1_RX_DATA1__ENET1_RDATA01 0x1b0b0MX6UL_PAD_ENET1_TX_EN__ENET1_TX_EN 0x1b0b0MX6UL_PAD_ENET1_TX_DATA0__ENET1_TDATA00 0x1b0b0MX6UL_PAD_ENET1_TX_DATA1__ENET1_TDATA01 0x1b0b0MX6UL_PAD_ENET1_TX_CLK__ENET1_REF_CLK1 0x4001b031 /*eth1_phy clk*/>;};pinctrl_enet2: enet2grp {fsl,pins = <MX6UL_PAD_GPIO1_IO07__ENET2_MDC 0x1b0b0MX6UL_PAD_GPIO1_IO06__ENET2_MDIO 0x1b0b0MX6UL_PAD_ENET2_RX_EN__ENET2_RX_EN 0x1b0b0MX6UL_PAD_ENET2_RX_ER__ENET2_RX_ER 0x1b0b0MX6UL_PAD_ENET2_RX_DATA0__ENET2_RDATA00 0x1b0b0MX6UL_PAD_ENET2_RX_DATA1__ENET2_RDATA01 0x1b0b0MX6UL_PAD_ENET2_TX_EN__ENET2_TX_EN 0x1b0b0MX6UL_PAD_ENET2_TX_DATA0__ENET2_TDATA00 0x1b0b0MX6UL_PAD_ENET2_TX_DATA1__ENET2_TDATA01 0x1b0b0MX6UL_PAD_ENET2_TX_CLK__ENET2_REF_CLK2 0x4001b031 /*eth2_phy clk*/>;};
...
&fec1 {pinctrl-names = "default";pinctrl-0 = <&pinctrl_enet1 &pinctrl_enet1_reset>;phy-mode = "rmii";phy-handle = <ðphy0>;phy-supply = <®_peri_3v3>;phy-reset-gpios = <&gpio5 7 GPIO_ACTIVE_LOW>; /*增加gpio5-7 用于reset phy 0*/phy-reset-duration-us = <200>; /*增加reset的delay属性*/status = "okay";
};&fec2 {pinctrl-names = "default";pinctrl-0 = <&pinctrl_enet2 &pinctrl_enet2_reset>;phy-mode = "rmii";phy-handle = <ðphy1>;phy-supply = <®_peri_3v3>;phy-reset-gpios = <&gpio5 8 GPIO_ACTIVE_LOW>; /*增加gpio5-8 用于reset phy 1*/phy-reset-duration-us = <200>; /*增加reset的delay属性*/status = "okay";mdio {#address-cells = <1>;#size-cells = <0>;ethphy0: ethernet-phy@0 { /*地址和reg都改为0*/compatible = "ethernet-phy-id0022.1560";reg = <0>;micrel,led-mode = <1>;clocks = <&clks IMX6UL_CLK_ENET_REF>;clock-names = "rmii-ref";};ethphy1: ethernet-phy@1 { /*不改,原本就是1*/compatible = "ethernet-phy-id0022.1560";reg = <1>;micrel,led-mode = <1>;clocks = <&clks IMX6UL_CLK_ENET2_REF>;clock-names = "rmii-ref";};};
};
...
目前不使用这一路SPI,EVK的板子这是一路GPIO拓展的功能,alpha板子没有使用,直接disabled,当前也可以细化,gpio5-7 和gpio5-8这里只是拿来做CS,可以指定别的pin来做cs, 就可以继续用这路SPI。
4.5.2 驱动修改
修改phy的驱动
drivers/net/ethernet/freescale/fec_main.c
static int
fec_probe(struct platform_device *pdev)
{.../* add for alpha board LAN8720A start*/void __iomem *IMX6U_ENET1_TX_CLK;void __iomem *IMX6U_ENET2_TX_CLK;IMX6U_ENET1_TX_CLK = ioremap(0X020E00DC, 4);writel(0X14, IMX6U_ENET1_TX_CLK);IMX6U_ENET2_TX_CLK = ioremap(0X020E00FC, 4);writel(0X14, IMX6U_ENET2_TX_CLK);/* add for alpha board LAN8720A end*/fec_enet_get_queue_num(pdev, &num_tx_qs, &num_rx_qs);...
drivers/net/phy/smsc.c
#include <linux/of_gpio.h>
#include <linux/io.h>...static int smsc_phy_reset(struct phy_device *phydev)
{int err, phy_reset;int msec = 1;struct device_node *np;int timeout = 50000;int rc;if (phydev->mdio.addr == 0) {np = of_find_node_by_path("/soc/aips-bus@02100000/ethernet@02188000");} else if (phydev->mdio.addr == 1) {np = of_find_node_by_path("/soc/aips-bus@02000000/ethernet@020b4000");}if (!np) {return -1;}/* A sane reset duration should not be longer than 1s */err = of_property_read_u32(np, "phy-reset-duration", &msec);if (!err && msec > 1000)msec = 1;phy_reset = of_get_named_gpio(np, "phy-reset-gpios", 0);if (!gpio_is_valid(phy_reset))return -1;gpio_direction_output(phy_reset, 0);gpio_set_value(phy_reset, 0);msleep(msec);gpio_set_value(phy_reset, 1);...
开启内核SMSC厂商驱动支持
Device Drivers > Network device support > PHY Device support and infrastructure >SMSC PHYs
对应的config: CONFIG_SMSC_PHY=y
编译内核和设备树,运行效果:
root@ATK-IMX6U:~# ifconfig
eth0 Link encap:Ethernet HWaddr 88:bc:2f:03:ec:0binet addr:192.168.3.37 Bcast:192.168.3.255 Mask:255.255.255.0inet6 addr: fe80::8abc:2fff:fe03:ec0b/64 Scope:LinkUP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1RX packets:33 errors:0 dropped:0 overruns:0 frame:0TX packets:49 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000RX bytes:3529 (3.4 KiB) TX bytes:8573 (8.3 KiB)lo Link encap:Local Loopbackinet addr:127.0.0.1 Mask:255.0.0.0inet6 addr: ::1/128 Scope:HostUP LOOPBACK RUNNING MTU:65536 Metric:1RX packets:14 errors:0 dropped:0 overruns:0 frame:0TX packets:14 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000RX bytes:860 (860.0 B) TX bytes:860 (860.0 B)root@ATK-IMX6U:~# ping 192.168.3.32
PING 192.168.3.32 (192.168.3.32) 56(84) bytes of data.
64 bytes from 192.168.3.32: icmp_seq=1 ttl=64 time=3.57 ms
64 bytes from 192.168.3.32: icmp_seq=2 ttl=64 time=1.33 ms
64 bytes from 192.168.3.32: icmp_seq=3 ttl=64 time=1.33 ms
64 bytes from 192.168.3.32: icmp_seq=4 ttl=64 time=2.42 ms
^C
--- 192.168.3.32 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 1.332/2.166/3.576/0.928 ms