三、内核移植
版本 | 作者 | 时间 | 备注 |
---|---|---|---|
V 1.0 | bug设计工程师 | 2021/11/10 | 创建文件 |
软件 | 网盘链接 |
---|---|
0交叉编译工具 | 链接:https://pan.baidu.com/s/1yFO2NDMet9_b1E1q1rMwEA提取码:42kl |
uboot源码 | 同上 |
linux源码 | 同上 |
文件系统工具 | 同上 |
tftp工具 | 同上 |
3.1 内核的配置和编译
1、编译内核
-
将内核源码放入 /root/linux/2linux里面
-
解压内核
tar xvf linux-3.14.tar.xz
-
进入内核目录
cd linux-3.14
-
修改内核顶层目录下的 Makefile
gedit Makefile
将199行左右的
ARCH ?= $(SUBARCH)CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%)
修改为:
ARCH ?= arm
CROSS_COMPILE ?= arm-none-linux-gnueabi- -
拷贝标准板配置文件
make exynos_defconfig
-
打开内核配置图形界面(该界面需要ncurses-dev库的支持)
sudo apt-get install ncurses-dev
make menuconfig
-
配置内核消息的打印串口为串口2
System Type —>
(2) S3C UART to use for low-level messages //按回车进去修改
保存退出
-
将前面编译的 uboot 源码中的 tools/mkimage 拷贝到ubuntu 的/usr/bin 目录下
并且增加执行权限
cp /root/linux/1uboot/u-boot-2013.01/tools/mkimage /usr/bin/
chmod 777 /usr/bin/mkimage
-
编译内核
make uImage
通过上述操作我们能够在 arch/arm/boot 目录下生成一个 uImage 文件,这就是经过压缩的内核镜像。
2、生成设备树
-
生成设备树文件,以参考板 origen 的设备数文件为参考
cp arch/arm/boot/dts/exynos4412-origen.dts arch/arm/boot/dts/exynos4412-etc4412.dts
-
arch/arm/boot/dts/Makefile 中添加exynos4412-etc4412.dts的支持
gedit arch/arm/boot/dts/Makefile
在69行
exynos4412-origen.dtb
下面添加
exynos4412-etc4412.dtb \
-
编译设备树文件
make dtbs
3、测试
-
拷贝内核和设备树文件到Windows下面的tftpboot 目录下
arch/arm/boot/uImage 拷贝到Windows下面的tftpboot 目录下
arch/arm/boot/dts/exynos4412-etc4412.dtb 拷贝到Windows下面的tftpboot 目录下
-
打开Windows下面的tftp服务器
-
修改开发板uboot 参数
setenv serverip 172.16.1.116
setenv ipaddr 172.16.1.123
setenv gatewayip 172.16.1.1
setenv netmask 255.255.255.0
setenv bootcmd tftp 41000000 uImage; tftp 42000000 exynos4412-etc4412.dtb; bootm 41000000 - 42000000
saveenv
注意: 172.16.1.116 对应电脑的 ip ,172.16.1.123 对应板子的 ip这两个 ip 应该根据自己的实际情况适当修改
-
重启开发板(不要按其他键,uboot自动加载内核)看到如下信息,说明内核启动成功
dm9000 i/o: 0x5000000, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 11:22:33:44:55:66
operating at 100M full duplex mode
Using dm9000 device
TFTP from server 172.16.1.58; our IP address is 172.16.1.231
Filename ‘uImage’.
Load address: 0x41000000
Loading: #################################################################
#################################################################
##########################################################
710.9 KiB/s
done
Bytes transferred = 2756576 (2a0fe0 hex)
dm9000 i/o: 0x5000000, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 11:22:33:44:55:66
operating at 100M full duplex mode
Using dm9000 device
TFTP from server 172.16.1.58; our IP address is 172.16.1.231
Filename ‘exynos4412-etc4412.dtb’.
Load address: 0x42000000
Loading: ###
299.8 KiB/s
done
Bytes transferred = 33546 (830a hex)Booting kernel from Legacy Image at 41000000 …
Image Name: Linux-3.14.0
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2756512 Bytes = 2.6 MiB
Load Address: 40008000
Entry Point: 40008000
Verifying Checksum … OKFlattened Device Tree blob at 42000000
Booting using the fdt blob at 0x42000000
Loading Kernel Image … OK
OK
Loading Device Tree to 4fff4000, end 4ffff309 … OKStarting kernel …
[ 0.000000] Booting Linux on physical CPU 0xa00
[ 0.000000] Linux version 3.14.0 (root@lyb-virtual-machine) (gcc version 4.6.4 (crosstool-NG hg+default-2685dfa9de14 - tc0002) ) #1 SMP PREEMPT Tue Nov 9 15:00:47 CST 2021
[ 0.000000] CPU: ARMv7 Processor [413fc090] revision 0 (ARMv7), cr=10c5387d
[ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[ 0.000000] Machine model: Insignal Origen evaluation board based on Exynos4412
[ 0.000000] Memory policy: Data cache writealloc
[ 0.000000] CPU EXYNOS4412 (id 0xe4412011)
[ 0.000000] Running under secure firmware.
[ 0.000000] PERCPU: Embedded 7 pages/cpu @eefb6000 s7424 r8192 d13056 u32768
[ 0.000000] Built 1 zonelists in Zone order, mobility grouping on. Total pages: 256528
[ 0.000000] Kernel command line: root=/dev/nfs nfsroot=192.168.3.97:/busybox-1.22.1/_install rw console=ttySAC2,115200 init=/linuxrc ip=192.168.3.140
[ 0.000000] PID hash table entries: 4096 (order: 2, 16384 bytes)
[ 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: 1017340K/1032192K available (3698K kernel code, 227K rwdata, 1120K rodata, 223K init, 263K bss, 14852K reserved, 270336K highmem)
[ 0.000000] Virtual kernel memory layout:…
3.2 以太网卡驱动移植
-
修改设备树,支持以太网
gedit arch/arm/boot/dts/exynos4412-etc4412.dts
在pinctrl@11000000前面第50行添加如下代码
srom-cs1@5000000 { compatible = "simple-bus"; #address-cells = <1>; #size-cells = <1>; reg = <0x5000000 0x1000000>; ranges; ethernet@5000000 { compatible = "davicom,dm9000"; reg = <0x5000000 0x2 0x5000004 0x2>; interrupt-parent = <&gpx0>; interrupts = <6 4>; davicom,no-eeprom; mac-address = [00 0a 2d a6 55 a2]; }; };
-
修改文件 drivers/clk/clk.c文件
gedit drivers/clk/clk.c
将529行的
static bool clk_ignore_unused;
修改为
static bool clk_ignore_unused = true;
-
配置内核支持网卡
make menuconfig
配置如下
[*] Networking support ---> Networking options ---> <*> Packet socket <*> Unix domain sockets [*] TCP/IP networking [*] IP: kernel level autoconfiguration Device Drivers ---> [*] Network device support ---> [*] Ethernet driver support ---> <*> DM9000 support File systems ---> [*] Network File Systems (NEW) ---> <*> NFS client support [*] NFS client support for NFS version 2 [*] NFS client support for NFS version 3 [*] NFS client support for the NFSv3 ACL protocol extension [*] Root file system on NFS(NEW)
-
编译内核和设备树
make uImage
make dtbs
-
如果需要测试,3.1章的3测试部分(一般不需要测试,后面NFS文件系统挂在需要网络支持)
3.3 SD 卡驱动移植
-
修改设备树,支持SD卡
gedit arch/arm/boot/dts/exynos4412-etc4412.dts
将132行左右的
sdhci@12530000 {
bus-width = <4>;
pinctrl-0 = <&sd2_clk &sd2_cmd &sd2_bus4 &sd2_cd>;
pinctrl-names = “default”;
vmmc-supply = <&mmc_reg>;
status = “okay”;
};改为
sdhci@12530000 { bus-width = <4>; pinctrl-0 = <&sd2_clk &sd2_cmd &sd2_bus4>; cd-gpios = <&gpx0 7 0>; cd-inverted = <0>; pinctrl-names = "default"; /*vmmc-supply = <&mmc_reg>;*/ status = "okay"; };
-
配置内核支持SD卡驱动
make menuconfig
配置如下
Device Drivers ---> <*> MMC/SD/SDIO card support --- <*> Secure Digital Host Controller Interface support <*> SDHCI support on Samsung S3C SoC File systems ---> DOS/FAT/NT Filesystems ---> <*> MSDOS fs support <*> VFAT (Windows-95) fs support (437) Default codepage for FAT (iso8859-1) Default iocharset for FAT -*- Native language support ---> <*> Codepage 437 (United States, Canada) <*> Simplified Chinese charset (CP936, GB2312) <*> ASCII (United States) <*> NLS ISO 8859-1 (Latin 1; Western European Languages) <*> NLS UTF-8
-
编译内核和设备树
make uImage
make dtbs
-
如果需要测试,3.1章的3测试部分(需要后面做完文件系统才能测试)
启动开发板,通过 NFS 方式挂载根文件系统。
把 SD 卡插到 ETC4412 的 SD 卡槽里,在串口终端可以看到如下图所示:
使用下面命令可以查看SD卡的信息:
mount -t vfat /dev/mmcblk1p1 /mnt)
3.4 USB 驱动移植
-
修改设备树,支持USB
gedit arch/arm/boot/dts/exynos4412-etc4412.dts
在pinctrl@11000000前面第65行左右添加如下代码
usbphy: usbphy@125B0000 { #address-cells = <1>; #size-cells = <1>; compatible = "samsung,exynos4x12-usb2phy"; reg = <0x125B0000 0x100>; ranges; clocks = <&clock 2>, <&clock 305>; clock-names = "xusbxti", "otg"; usbphy-sys { reg = <0x10020704 0x8 0x1001021c 0x4>; }; }; ehci@12580000 { status = "okay"; usbphy = <&usbphy>; }; usb3503@08 { compatible = "smsc,usb3503"; reg = <0x08 0x4>; connect-gpios = <&gpm3 3 1>; intn-gpios = <&gpx2 3 1>; reset-gpios = <&gpm2 4 1>; initial-mode = <1>; };
-
配置内核支持SD卡驱动
make menuconfig
配置如下
Device Drivers ---> SCSI device support ---> <*> SCSI device support <*> SCSI disk support <*> SCSI generic suppor [*] USB support ---> <*> EHCI HCD (USB 2.0) support <*> EHCI support for Samsung S5P/EXYNOS SoC Series <*> USB Mass Storage support <*> USB3503 HSIC to USB20 Driver USB Physical Layer drivers ---> <*> Samsung USB 2.0 PHY controller Driver
-
编译内核和设备树
make uImage
make dtbs
-
如果需要测试,3.1章的3测试部分(需要后面做完文件系统才能测试)
启动开发板,通过 NFS 方式挂载根文件系统。
测试启动目标板并在目标板上完成如下操作:
插入 U 盘显示如下:输入一下命令可以看到U盘信息:
$ mount -t vfat /dev/sda1 /mnt
3.5 LCD 驱动移植
Exynos4412 内部集成了一个显示控制器 FIMD( Fully Interactive Mobile Display, 完全交互式移动显示设备)。该控制器支持三种接口,分别是 RGB 接口、 indirect-i80 接口和 YUV 接口。在 ETC4412 开发板上使用的是 RGB 接口连接外部的 LCD 屏。
-
修改设备树,支持USB
gedit arch/arm/boot/dts/exynos4412-etc4412.dts
将190左右的
fimd@11c00000 { pinctrl-0 = <&lcd_clk &lcd_data24 &pwm1_out>; pinctrl-names = "default"; status = "okay"; }; display-timings { native-mode = <&timing0>; timing0: timing { clock-frequency = <47500000>; hactive = <1024>; vactive = <600>; hfront-porch = <64>; hback-porch = <16>; hsync-len = <48>; vback-porch = <64>; vfront-porch = <16>; vsync-len = <3>; }; };
修改为
fimd: fimd@11c00000 { pinctrl-0 = <&lcd_clk &lcd_data24 &pwm1_out>; pinctrl-names = "default"; status = "okay"; display-timings { native-mode = <&timing0>; timing0: timing { hsync-active = <0>; vsync-active = <0>; de-active = <0>; pixelclk-active = <1>; clock-frequency = <51206400>; hactive = <1024>; vactive = <600>; hfront-porch = <150>; hback-porch = <160>; hsync-len = <10>; vback-porch = <22>; vfront-porch = <12>; vsync-len = <1>; }; }; };
-
配置内核支持LCD驱动
make menuconfig
Device Drivers ---> Graphics support ---> <*> Direct Rendering Manager (XFree86 4.1.0 and higher DRI support) ---- <*> DRM Support for Samsung SoC EXYNOS Series [*] Exynos DRM FIMD
-
修改drivers/gpu/drm/exynos/exynos_drm_drv.c代码
gedit drivers/gpu/drm/exynos/exynos_drm_drv.c
在#include "exynos_drm_iommu.h"后面33行左右添加下面代码
#include <linux/io.h> #include <linux/ioport.h> #include <mach/map.h> #define CLK_SRC_LCD0 (S5P_VA_CMU + 0xC234) #define CLK_SRC_MASK_LCD (S5P_VA_CMU + 0xC334) #define CLK_DIV_LCD (S5P_VA_CMU + 0xC534) #define CLK_DIV_STAT_LCD (S5P_VA_CMU + 0xC634) #define CLK_GATE_IP_LCD (S5P_VA_CMU + 0xC934) #define CLK_GATE_BLOCK (S5P_VA_CMU + 0xC970) #define LCDBLK_CFG (S3C_VA_SYS + 0x0210) void exynos_drm_fbclk_preinit(void) {/* FIMD0_SEL = SCLKVPLL, 350000000 */ __raw_writel((__raw_readl(CLK_SRC_LCD0) & ~(0x0F)) | (0x08), CLK_SRC_LCD0); /* FIMD0_RATIO = 3, SCLK_FIMD0 = MOUTFIMD0/(FIMD0_RATIO + 1) */ __raw_writel((__raw_readl(CLK_DIV_LCD) & ~(0x0F)) | (0x04), CLK_DIV_LCD); /* unmask output clock of MUXFIMD0 */ __raw_writel(__raw_readl(CLK_SRC_MASK_LCD) | 0x1, CLK_SRC_MASK_LCD); __raw_writel(__raw_readl(CLK_GATE_IP_LCD) | 0x1, CLK_GATE_IP_LCD); __raw_writel(__raw_readl(CLK_GATE_BLOCK) | (0x1 << 4), CLK_GATE_BLOCK); /* select fimd */ __raw_writel(__raw_readl(LCDBLK_CFG) | (0x1 << 1), LCDBLK_CFG); }
在 exynos_drm_fbdev_init(dev)函数调用前添加exynos_drm_fbclk_preinit()函数调用
exynos_drm_fbclk_preinit(); //该行为添加代码 ret = exynos_drm_fbdev_init(dev); //下面这些事文件本身有代码 if (ret) { DRM_ERROR("failed to initialize drm fbdev\n"); goto err_drm_device; }
-
编译内核和设备树
make uImage
make dtbs
-
参考3.1章的3测试部分进行测试,看到如下信息
…
[ 1.560000] exynos-ehci 12580000.ehci: irq 102, io mem 0x12580000
[ 1.575000] exynos-ehci 12580000.ehci: USB 2.0 started, EHCI 1.00
[ 1.580000] hub 1-0:1.0: USB hub found
[ 1.580000] mmc1: unrecognised EXT_CSD revision 8
[ 1.580000] mmc1: error -22 whilst initialising MMC card
[ 1.590000] hub 1-0:1.0: 3 ports detected
[ 1.595000] drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
[ 1.625000] dm9000 5000000.ethernet eth0: link down
[ 1.825000] dm9000 5000000.ethernet eth0: link up, 100Mbps, full-duplex, lpa 0xCDE1
[ 1.830000] IP-Config: Guessing netmask 255.255.255.0
[ 1.830000] IP-Config: Complete:
[ 1.830000] device=eth0, hwaddr=00:0a:2d:a6:55:a2, ipaddr=192.168.3.140, mask=255.255.255.0, gw=255.255.255.255
[ 1.830000] host=192.168.3.140, domain=, nis-domain=(none)
[ 1.830000] bootserver=255.255.255.255, rootserver=192.168.3.97, rootpath=
[ 1.830000] clk: Not disabling unused clocks
[ 1.905000] usb 1-3: new high-speed USB device number 2 using exynos-ehci
[ 2.040000] hub 1-3:1.0: USB hub found
[ 2.040000] hub 1-3:1.0: 3 ports detected…