您的位置:首页 > 运维架构 > Linux

移植最新的linux4.9.9内核(适配fs4412平台)

2018-03-04 15:22 561 查看
移植最新的linux4.9内核适配fs4412(samsung exynos4412平台验证通过)

1.源码下载

官网下载最新的linux4.9.9内核:

http://www.kernel.org/pub/linux/kernel/



第三个数字是修订版本号

2.解压

tar xvf linux-4.9.9.tar.xz


解压也需要时间,需要耐心等待,注意不要打断解压过程。

3.配置

进入内核源码目录:
cd   linux-4.9.9


3.1 修改编译工具链

打开顶层的Makefile:

vi Makefile


修改:

ARCH  ?= $(SUBARCH)
CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%)


为:

ARCH  ?= arm
CROSS_COMPILE ?= arm-none-linux-gnueabi-


注:如果不修改编译工具链,默认使用编译x86的gcc编译器,如果不想修改Makefile也可以执行make时添加 如:

make uImage ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi-


3.2 导入默认的配置

make exynos_defconfig


实际上是执行了:cp arch/arm/configs/exynos_defconfig .config



3.3 配置内核

执行

make menuconfig




修改指定内核的调试串口:

进入:Kernel hacking
->Kernel low-level debugging functions (read help!)  选择
---> Kernel low-level debugging port (Use Samsung S3C UART 2 for low-level debug)  打开选择uart2


选择这个调试串口很重要,否则打印不出内核启动的相关信息(这个地方配置找了半天才找到,exynos默认没有打开此功能,没有打开此处会发现内核打印信息停止在Starting kernel …处)

4.编译

4.1 编译uImage镜像

make uImage -j2 LOADADDR=0X40008000


-j2表示双线程编译

LOADADDR=0X40008000 表示指定内核的加载地址(注:没有此选项编译生成uImage会报错)

最后提示以下错误。

Kernel: arch/arm/boot/Image is ready
Kernel: arch/arm/boot/zImage is ready
multiple (or no) load addresses:
This is incompatible with uImages
Specify LOADADDR on the commandline to build an uImage
make[1]: *** [arch/arm/boot/uImage] 错误 1
make: *** [uImage] 错误 2


经过漫长的等待,结果显示如下:



表示编译成功。

如果编译过程中提示缺少 mkimage 工具,需将编译的 uboot 源码中的tools/mkimage 拷贝到 ubuntu 的/bin 目录下。

cp u-boot-xxx/tools/mkimage /usr/bin


4.2 编译设备树

在编译设备树之前需要对设备树进行配置,在这里使用参考板 origen 的设备树文件:

$ cp arch/arm/boot/dts/exynos4412-origen.dts  arch/arm/boot/dts/exynos4412-liebao.dts


修改arch/arm/boot/dts/下的Makefile文件

$vi arch/arm/boot/dts/Makefile


在exynos4412-origen.dtb下添加exynos4412-liebao.dtb:



编译设备树:

$ make dtbs




如上图编译好了设备树文件:arch/arm/boot/dts/exynos4412-liebao.dtb

4.3 拷贝内核镜像和设备树文件到/tftp目录下

cp arch/arm/boot/uImage /tftpboot/
cp arch/arm/boot/dts/exynos4412-liebao.dtb /tftpboot/


5.下载镜像

5.1 修改uboot的启动参数

启动板子在系统倒计时是按任意键结束启动,输入如下内容修改 uboot 环境变量

#setenv serverip 192.168.1.104
#setenv ipaddr 192.168.1.160
#setenv bootcmd tftp 41000000 uImage\;tftp 42000000 exynos4412-liebao.dtb\;bootm
41000000 – 42000000
#setenv  bootargs  root=/dev/nfs  nfsroot=192.168.1.104:/source/rootfs  rw
console=ttySAC2,115200 init=/linuxrc ip=192.168.1.160
# saveenv


注:serverip 为ubuntu的服务器ip

ipaddr 为开发版的ip

输入boot命令,让uboot执行bootcmd命令:

#boot


启动的打印如下:

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 192.168.1.104; our IP address is 192.168.1.60
Filename 'uImage'.
Load address: 0x41000000
Loading: *T T T #################################################################
#################################################################
#################################################################
#################################################################
####################################################
205.1 KiB/s
done
Bytes transferred = 4573088 (45c7a0 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 192.168.1.104; our IP address is 192.168.1.60
Filename 'exynos4412-liebao.dtb'.
Load address: 0x42000000
Loading: *####
476.6 KiB/s
done
Bytes transferred = 52784 (ce30 hex)
## Booting kernel from Legacy Image at 41000000 ...
Image Name:   Linux-4.9.9
Image Type:   ARM Linux Kernel Image (uncompressed)
Data Size:    4573024 Bytes = 4.4 MiB
Load Address: 40008000
Entry Point:  40008000
Verifying Checksum ... OK
## Flattened Device Tree blob at 42000000
Booting using the fdt blob at 0x42000000
Loading Kernel Image ... OK
OK
Loading Device Tree to 4fff0000, end 4ffffe2f ... OK

Starting kernel ...

Uncompressing Linux... done, booting the kernel.
[    0.000000] Booting Linux on physical CPU 0xa00
[    0.000000] Linux version 4.9.9 (linux@ubuntu) (gcc version 4.6.4 (crosstool-NG hg+default-2685dfa9de14 - tc0002) ) #1 SMP PREEMPT Sat Mar 3 20:41:48 PST 2018
[    0.000000] CPU: ARMv7 Processor [413fc090] revision 0 (ARMv7), cr=10c5387d
......
111.033366] CPU: 1 PID: 0 Comm: swapper/1 Not tainted 4.9.9 #1
[  111.103933] 5fc0: c0108404 c0108408 60000053 ffffffff
[  111.108971] [<c010b0cc>] (__irq_svc) from [<c0108408>] (arch_cpu_idle+0x30/0x3c)
[  111.116352] [<c0108408>] (arch_cpu_idle) from [<c01520e8>] (cpu_startup_entry+0x1a8/0x264)
[  111.124594] [<c01520e8>] (cpu_startup_entry) from [<4010156c>] (0x4010156c)
[  111.131543] ---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)


出现了上面的错误:

看最后一行是内核奔溃了,不能够挂载在未知块设备上的根文件系统。

实际上是我们的网卡的驱动没有移植导致的(因为命令行参数:bootargs root=/dev/nfs nfsroot=192.168.1.104:/source/rootfs rw ip=192.168.1.60 init=/linuxrc console=ttySAC2,115200已经指定了nfs的根文件系统)

6.移植网卡

6.1 增加DM9000网卡的设备树节点信息

vi arch/arm/boot/dts/exynos4412-liebao.dts


添加如下内容:

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];
};
};


注:一定要在跟节点中增加节点,否则设备树编译会报错。



在这里我们选择chosen后面增加网卡节点。

6.2 修改时钟

修改文件 driver/clk/clk.c

修改

static bool clk_ignore_unused;




static bool clk_ignore_unused = true;


不配置时钟编译报错。

6.3 配置内核

具体配置如下:

网络协议的配置:

[*] Networking support --->
Networking options --->
<*> Packet socket
<*> Unix domain sockets
[*] TCP/IP networking
[*] IP: kernel level autoconfiguration




网卡驱动的配置:

Device Drivers --->
[*] Network device support --->
[*] Ethernet driver support (NEW) --->
<*> DM9000 support




Nfs服务和根文件系统配置:

File systems --->
[*] Network File Systems (NEW) --->
<*> NFS client support
[*] NFS client support for NFS version 3
[*] NFS client support for the NFSv3 ACL protocol extension
[*] Root file system on NFS




6.4 编译内核

make uImage -j2 LOADADDR=0X40008000


6.5 编译设备树

make dtbs


6.6 拷贝文件到/tftp

 cp arch/arm/boot/uImage /tftpboot/
cp arch/arm/boot/dts/exynos4412-liebao.dtb /tftpboot/


启动开发板,通过 NFS 方式挂载根文件系统

最后如下显示表示移植成功:



mount查看挂载情况:



可以发现已经挂载上了nfs根文件系统。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  内核 linux 移植 fs4412