基于IMX6Q移植linux4.19.47——初步移植

1.下載最新的內核:

https://www.kernel.org/

我在移植的时候最新的4.x的内核版本是4.19.47的所以就基于这个版本来移植吧!

 

2.解压下载的内核:

tar -xvf linux-4.19.47.tar.xz

 

3.添加编译工具和芯片架构:

vim Makefile

在文件开头添加

ARCH=arm                                                          
CROSS_COMPILE=arm-linux-gnueabihf-   

添加完成后Makefile开头部分如下:

# SPDX-License-Identifier: GPL-2.0
VERSION = 4
PATCHLEVEL = 19
SUBLEVEL = 47
EXTRAVERSION =
NAME = "People's Front"
ARCH=arm                                                          
CROSS_COMPILE=arm-linux-gnueabihf-   

4.使用默认的配置进行初步配置

 make imx_v6_v7_defconfig


5.使用make menuconfig进行进一步配置

make menuconfig

选择
  │ │        Boot options  --->                                          
    去除  [ ]   Support for the traditional ATAGS boot data passing

如下:

-*- Flattened Device Tree support                                │ │  
  │ │    [ ]   Support for the traditional ATAGS boot data passing        │ │  
  │ │    (0) Compressed ROM boot loader base address                      │ │  
  │ │    (0) Compressed ROM boot loader BSS address                       │ │  
  │ │    [ ] Use appended device tree blob to zImage (EXPERIMENTAL)       │ │  
  │ │    (noinitrd console=ttymxc0,115200) Default kernel command string  │ │  
  │ │    [*] Kexec system call (EXPERIMENTAL)                             │ │  
  │ │    [ ] Build kdump crash kernel (EXPERIMENTAL)                      │ │  
  │ │    -*- Auto calculation of the decompressed kernel image address    │ │  
  │ │    [ ] UEFI runtime support   

选择

   System Type  ---> 

        [*] Freescale i.MX family  --->

去除所有的soc支持只保留[*]   i.MX6 Quad/DualLite support

配置完成,返回配置首页并保存退出

6.定制设备树文件,由于移植uboot的时候使用的是基于一个arm2的公板,所以移植内核的时候还是选择它

cp arch/arm/boot/dts/imx6q-arm2.dts arch/arm/boot/dts/tqimx6q.dts

修改设备树

arch/arm/boot/dts/tqimx6q.dts

发现文件末尾有关于串口的配置,

&uart2 {
        pinctrl-names = "default";
        pinctrl-0 = <&pinctrl_uart2>;
        fsl,dte-mode;
        uart-has-rtscts;
        status = "okay";
};

&uart4 {uart2
        pinctrl-names = "default";
        pinctrl-0 = <&pinctrl_uart4>;
        status = "okay";
};

但是是uart2和uart4的,我想使用的却是uart1,所以删除uart4的信息,并根据硬件修改uart2的信息为uart1,由于uart1使用的引脚和

pinctrl_usdhc3有冲突所以先屏蔽掉pinctrl_usdhc3的这两个引脚,最后完整的设备树文件如下

/*
 * Copyright 2011 Freescale Semiconductor, Inc.
 * Copyright 2011 Linaro Ltd.
 *
 * The code contained herein is licensed under the GNU General Public
 * License. You may obtain a copy of the GNU General Public License
 * Version 2 or later at the following locations:
 *
 * http://www.opensource.org/licenses/gpl-license.html
 * http://www.gnu.org/copyleft/gpl.html
 */

/dts-v1/;
#include 
#include "imx6q.dtsi"

/ {
	model = "Freescale i.MX6 Quad Armadillo2 Board";
	compatible = "fsl,imx6q-arm2", "fsl,imx6q";

	memory@10000000 {
		reg = <0x10000000 0x80000000>;
	};

	regulators {
		compatible = "simple-bus";
		#address-cells = <1>;
		#size-cells = <0>;

		reg_3p3v: regulator@0 {
			compatible = "regulator-fixed";
			reg = <0>;
			regulator-name = "3P3V";
			regulator-min-microvolt = <3300000>;
			regulator-max-microvolt = <3300000>;
			regulator-always-on;
		};

		reg_usb_otg_vbus: regulator@1 {
			compatible = "regulator-fixed";
			reg = <1>;
			regulator-name = "usb_otg_vbus";
			regulator-min-microvolt = <5000000>;
			regulator-max-microvolt = <5000000>;
			gpio = <&gpio3 22 0>;
			enable-active-high;
		};
	};

	leds {
		compatible = "gpio-leds";

		debug-led {
			label = "Heartbeat";
			gpios = <&gpio3 25 0>;
			linux,default-trigger = "heartbeat";
		};
	};
};

&gpmi {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_gpmi_nand>;
	status = "disabled"; /* gpmi nand conflicts with SD */
};

&iomuxc {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_hog>;

	imx6q-arm2 {
		pinctrl_hog: hoggrp {
			fsl,pins = <
				MX6QDL_PAD_EIM_D25__GPIO3_IO25 0x80000000
			>;
		};

		pinctrl_enet: enetgrp {
			fsl,pins = <
				MX6QDL_PAD_KEY_COL1__ENET_MDIO		0x1b0b0
				MX6QDL_PAD_KEY_COL2__ENET_MDC		0x1b0b0
				MX6QDL_PAD_RGMII_TXC__RGMII_TXC		0x1b030
				MX6QDL_PAD_RGMII_TD0__RGMII_TD0		0x1b030
				MX6QDL_PAD_RGMII_TD1__RGMII_TD1		0x1b030
				MX6QDL_PAD_RGMII_TD2__RGMII_TD2		0x1b030
				MX6QDL_PAD_RGMII_TD3__RGMII_TD3		0x1b030
				MX6QDL_PAD_RGMII_TX_CTL__RGMII_TX_CTL	0x1b030
				MX6QDL_PAD_ENET_REF_CLK__ENET_TX_CLK	0x1b0b0
				MX6QDL_PAD_RGMII_RXC__RGMII_RXC		0x1b030
				MX6QDL_PAD_RGMII_RD0__RGMII_RD0		0x1b030
				MX6QDL_PAD_RGMII_RD1__RGMII_RD1		0x1b030
				MX6QDL_PAD_RGMII_RD2__RGMII_RD2		0x1b030
				MX6QDL_PAD_RGMII_RD3__RGMII_RD3		0x1b030
				MX6QDL_PAD_RGMII_RX_CTL__RGMII_RX_CTL	0x1b030
				MX6QDL_PAD_GPIO_6__ENET_IRQ		0x000b1
			>;
		};

		pinctrl_gpmi_nand: gpminandgrp {
			fsl,pins = <
				MX6QDL_PAD_NANDF_CLE__NAND_CLE		0xb0b1
				MX6QDL_PAD_NANDF_ALE__NAND_ALE		0xb0b1
				MX6QDL_PAD_NANDF_WP_B__NAND_WP_B	0xb0b1
				MX6QDL_PAD_NANDF_RB0__NAND_READY_B	0xb000
				MX6QDL_PAD_NANDF_CS0__NAND_CE0_B	0xb0b1
				MX6QDL_PAD_NANDF_CS1__NAND_CE1_B	0xb0b1
				MX6QDL_PAD_SD4_CMD__NAND_RE_B		0xb0b1
				MX6QDL_PAD_SD4_CLK__NAND_WE_B		0xb0b1
				MX6QDL_PAD_NANDF_D0__NAND_DATA00	0xb0b1
				MX6QDL_PAD_NANDF_D1__NAND_DATA01	0xb0b1
				MX6QDL_PAD_NANDF_D2__NAND_DATA02	0xb0b1
				MX6QDL_PAD_NANDF_D3__NAND_DATA03	0xb0b1
				MX6QDL_PAD_NANDF_D4__NAND_DATA04	0xb0b1
				MX6QDL_PAD_NANDF_D5__NAND_DATA05	0xb0b1
				MX6QDL_PAD_NANDF_D6__NAND_DATA06	0xb0b1
				MX6QDL_PAD_NANDF_D7__NAND_DATA07	0xb0b1
				MX6QDL_PAD_SD4_DAT0__NAND_DQS		0x00b1
			>;
		};

		pinctrl_uart1: uart1grp {
			fsl,pins = <
				MX6QDL_PAD_SD3_DAT6__UART1_RX_DATA	0x1b0b1
                                MX6QDL_PAD_SD3_DAT7__UART1_TX_DATA	0x1b0b1
			>;
		};

		pinctrl_usbotg: usbotggrp {
			fsl,pins = <
				MX6QDL_PAD_GPIO_1__USB_OTG_ID		0x17059
			>;
		};

		pinctrl_usdhc3: usdhc3grp {
			fsl,pins = <
				MX6QDL_PAD_SD3_CMD__SD3_CMD		0x17059
				MX6QDL_PAD_SD3_CLK__SD3_CLK		0x10059
				MX6QDL_PAD_SD3_DAT0__SD3_DATA0		0x17059
				MX6QDL_PAD_SD3_DAT1__SD3_DATA1		0x17059
				MX6QDL_PAD_SD3_DAT2__SD3_DATA2		0x17059
				MX6QDL_PAD_SD3_DAT3__SD3_DATA3		0x17059
				MX6QDL_PAD_SD3_DAT4__SD3_DATA4		0x17059
				MX6QDL_PAD_SD3_DAT5__SD3_DATA5		0x17059
				//MX6QDL_PAD_SD3_DAT6__SD3_DATA6		0x17059
				//MX6QDL_PAD_SD3_DAT7__SD3_DATA7		0x17059
			>;
		};

		pinctrl_usdhc3_cdwp: usdhc3cdwp {
			fsl,pins = <
				MX6QDL_PAD_NANDF_CS0__GPIO6_IO11 0x80000000
				MX6QDL_PAD_NANDF_CS1__GPIO6_IO14 0x80000000
			>;
		};

		pinctrl_usdhc4: usdhc4grp {
			fsl,pins = <
				MX6QDL_PAD_SD4_CMD__SD4_CMD		0x17059
				MX6QDL_PAD_SD4_CLK__SD4_CLK		0x10059
				MX6QDL_PAD_SD4_DAT0__SD4_DATA0		0x17059
				MX6QDL_PAD_SD4_DAT1__SD4_DATA1		0x17059
				MX6QDL_PAD_SD4_DAT2__SD4_DATA2		0x17059
				MX6QDL_PAD_SD4_DAT3__SD4_DATA3		0x17059
				MX6QDL_PAD_SD4_DAT4__SD4_DATA4		0x17059
				MX6QDL_PAD_SD4_DAT5__SD4_DATA5		0x17059
				MX6QDL_PAD_SD4_DAT6__SD4_DATA6		0x17059
				MX6QDL_PAD_SD4_DAT7__SD4_DATA7		0x17059
			>;
		};
	};
};

&fec {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_enet>;
	phy-mode = "rgmii";
	interrupts-extended = <&gpio1 6 IRQ_TYPE_LEVEL_HIGH>,
			      <&intc 0 119 IRQ_TYPE_LEVEL_HIGH>;
	fsl,err006687-workaround-present;
	status = "okay";
};

&usbotg {
	vbus-supply = <®_usb_otg_vbus>;
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_usbotg>;
	disable-over-current;
	status = "okay";
};

&usdhc3 {
	cd-gpios = <&gpio6 11 GPIO_ACTIVE_LOW>;
	wp-gpios = <&gpio6 14 GPIO_ACTIVE_HIGH>;
	vmmc-supply = <®_3p3v>;
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_usdhc3
		     &pinctrl_usdhc3_cdwp>;
	status = "okay";
};

&usdhc4 {
	non-removable;
	vmmc-supply = <®_3p3v>;
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_usdhc4>;
	status = "okay";
};

&uart1 {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_uart1>;
	fsl,dte-mode;
	uart-has-rtscts;
	status = "okay";
};

 7. 配置完成,编译内核

make LOADADDR=12000000 uImage


8.编译定制的设备树

 make tqimx6q.dtb

9.拷贝这两个文件到tftp服务器

cp arch/arm/boot/uImage ~/tftpboot/

cp arch/arm/boot/dts/tqimx6q.dtb ~/tftpboot/

10.下载内核和设备树

tftp 12000000 uImage

tftp 18000000 tqimx6q.dtb

11.设置uboot中的启动变量并保存

setenv bootargs console=ttymxc0,115200

saveenv

12.启动内核

bootm 12000000 - 18000000   

串口输入如下                                                
## Booting kernel from Legacy Image at 12000000 ...                             
   Image Name:   Linux-4.19.47                                                  
   Image Type:   ARM Linux Kernel Image (uncompressed)                          
   Data Size:    8171848 Bytes = 7.8 MiB                                        
   Load Address: 12000000                                                       
   Entry Point:  12000000                                                       
   Verifying Checksum ... OK                                                    
## Flattened Device Tree blob at 18000000                                       
   Booting using the fdt blob at 0x18000000                                     
   Loading Kernel Image ... OK                                                  
   Using Device Tree in place at 18000000, end 1800b53a                         
                                                                                
Starting kernel ...

在Starting kernel ...后就没有输出了,后来查看了一下串口相关的设备树的参数的意义修改uart1如下

&uart1 {
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_uart1>;
    status = "okay";
};

删除的依据是

./Documentation/devicetree/bindings/serial/fsl-imx-uart.txt中的

Optional properties:
- fsl,dte-mode : Indicate the uart works in DTE mode. The uart works
                  in DCE mode by default.

和./Documentation/devicetree/bindings/serial/serial.txt中

uart-has-rtscts: The presence of this property indicates that the
    UART has dedicated lines for RTS/CTS hardware flow control, and that
    they are available for use (wired and enabled by pinmux configuration).
    This depends on both the UART hardware and the board wiring.
    Note that this property is mutually-exclusive with "cts-gpios" and
    "rts-gpios" above, unless support is provided to switch between modes
    dynamically.

13重新编译设备树

make tqimx6q.dtb

cp arch/arm/boot/dts/tqimx6q.dtb ~/tftpboot/

14.下载并运行

tftp 12000000 uImage

tftp 18000000 tqimx6q.dtb

bootm 12000000 - 18000000   

启动成功

## Booting kernel from Legacy Image at 12000000 ...                                                                                                    
   Image Name:   Linux-4.19.47                                                                                                                         
   Image Type:   ARM Linux Kernel Image (uncompressed)                                                                                                 
   Data Size:    8171848 Bytes = 7.8 MiB                                                                                                               
   Load Address: 12000000                                                                                                                              
   Entry Point:  12000000                                                                                                                              
   Verifying Checksum ... OK                                                                                                                           
## Flattened Device Tree blob at 18000000                                                                                                              
   Booting using the fdt blob at 0x18000000                                                                                                            
   Loading Kernel Image ... OK                                                                                                                         
   Using Device Tree in place at 18000000, end 1800b505                                                                                                
                                                                                                                                                       
Starting kernel ...                                                                                                                                    
                                                                                                                                                       
[    0.000000] Booting Linux on physical CPU 0x0                                                                                                       
[    0.000000] Linux version 4.19.47 (xcl@xcl-K46CB) (gcc version 7.3.1 20180425 [linaro-7.3-2018.05 revision d29120a424ecfbc167ef90065c0eeb7f91977701]
 (Linaro GCC 7.3-2018.05)) #1 SMP Sat Jun 1 21:14:30 CST 2019                                                                                          
[    0.000000] CPU: ARMv7 Processor [412fc09a] revision 10 (ARMv7), cr=10c5387d                                                                        
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache                                                                
[    0.000000] OF: fdt: Machine model: Freescale i.MX6 Quad Armadillo2 Board                                                                           
[    0.000000] Memory policy: Data cache writealloc                                                                                                    
[    0.000000] cma: Reserved 64 MiB at 0x8c000000                                                                                                      
[    0.000000] random: get_random_bytes called from start_kernel+0x8c/0x48c with crng_init=0                                                           
[    0.000000] percpu: Embedded 18 pages/cpu s41896 r8192 d23640 u73728                                                                                
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 522752                                                                           
[    0.000000] Kernel command line: console=ttymxc0,115200                                                                                             
[    0.000000] Dentry cache hash table entries: 131072 (order: 7, 524288 bytes)                                                                        
[    0.000000] Inode-cache hash table entries: 65536 (order: 6, 262144 bytes)                                                                          
[    0.000000] Memory: 1989124K/2097152K available (11264K kernel code, 840K rwdata, 3496K rodata, 1024K init, 7642K bss, 42492K reserved, 65536K cma-r
eserved, 1245184K highmem)                                                                                                                             
[    0.000000] Virtual kernel memory layout:                                                                                                           
[    0.000000]     vector  : 0xffff0000 - 0xffff1000   (   4 kB)                                                                                       
[    0.000000]     fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)                                                                                       
[    0.000000]     vmalloc : 0xf0800000 - 0xff800000   ( 240 MB)                                                                                       
[    0.000000]     lowmem  : 0xc0000000 - 0xf0000000   ( 768 MB)                                                                                       
[    0.000000]     pkmap   : 0xbfe00000 - 0xc0000000   (   2 MB)                                                                                       
[    0.000000]     modules : 0xbf000000 - 0xbfe00000   (  14 MB)                                                                                       
[    0.000000]       .text : 0x(ptrval) - 0x(ptrval)   (12256 kB)                                                                                      
[    0.000000]       .init : 0x(ptrval) - 0x(ptrval)   (1024 kB)                                                                                       
[    0.000000]       .data : 0x(ptrval) - 0x(ptrval)   ( 841 kB)                                                                                       
[    0.000000]        .bss : 0x(ptrval) - 0x(ptrval)   (7643 kB)                                                                                       
[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1 

............

 

               

 

 

                                       

 

 

你可能感兴趣的:(linux移植)