———————————————————————————————————————
主机操作系统:Centos 6.7
交叉编译器环境:arm-linux-gcc-4.5.4
交叉编译器:buildroot-2012.08
开发板平台: FL2440
Linux内核版本: linux-3.0
下载工具:TFTP32
调试终端:SECURE-CRT
Bootloader:U-boot-2010.09
———————————————————————————————————————
1.1先了解一下自己内核及交叉编译器的版本不要盲目操作
1.2下载并解压缩linux-3.0.tar.bz2源代码
首先到 Linux Kernel 官方网站www.kernel.org下载得到linux-3.0-rc4.tar.bz2文件,把它放到一个你有权限读写的文件夹,运行下面命令解压缩并进入解压后的文件夹:
[leiyuxing@centos6 linux-3.0]$$ tar -xjf linux-3.0.tar.bz2
[leiyuxing@centos6 kernel]$ ls
linux-3.0 linux-3.0.tar.bz2
[leiyuxing@centos6 kernel]$ cd linux-3.0
[leiyuxing@centos6 linux-3.0]$ ls
1.3配置内核编译参数
1. 首先修改顶层目录的Makefile文件
$ vim Makefile
这里首要便是交叉编译器环境变量和选择开发平台类型
然后要将生成的zimage拷贝到当前目录,再手动增加mkimage工具来自动把Zimage生成可执行的.bin文。
注:内核编译之后会生成两个文件。一个Image,一个Zimage。image为内核映像文件,而Zimage为内核映像压缩文件。Image大约为4M,而Zimage不到2M。
2. 修改晶振频率
因为我使用的是FL2440的开发板,根据datesheet可知晶振频率为12M。所以下一步修改晶振频率。
$ vim arch/arm/mach-s3c2440/mach-smdk2440.c
3. 修改驱动的串口
$ vim drivers/tty/serial/samsung.c
[leiyuxing@centos6 linux-3.0]$cp arch/arm/configs/mini2440_defconfig .config
[leiyuxing@centos6 linux-3.0]$ ls
[leiyuxing@centos6 linux-3.0]$ ll .config
-rw-rw-r--. 1 leiyuxing leiyuxing 50276 7月 20 00:23 .config
参考mini2440的.config文件作为我们的默认.config文件。改好之后再
$ Make menuconfig
打开文本窗口来选定即将要编译的模块,保存后会将里面的信息保存到同时生成的.config配置文件中。
另外:make menuconfig时出来的文本窗口中的信息是通过读取在内核源代码目录下的Kconfig文件来配置的。根据Makefile文件来编译,而Makefile文件中的变量则通过.config来进行赋值操作。仅仅在Kconfig中添加选项
4.修改MACHINE ID设备编号
OK,同样因为是做FL2440的内核,所以我们选择三星SMDK2440这个开发板。
因为我U-boot中使用的machine id为1999,而且我使用的是s3c2440这个板子。
将mini2440和和s3c2440的machineID对调。
$ vim arch/arm/tools/mach-types
配置就绪之后
make
显示成功
此时已经会生成一个linux-s3c2440.bin的可执行二进制文件。
[leiyuxing@centos6 linux-3.0]$ ls
arch fs linuxrom-s3c2440.bin
block include MAINTAINERS REPORTING-BUGS virt
COPYING init Makefile samples vmlinux
CREDITS ipc mm scripts vmlinux.o
crypto Kbuild modules.builtin security
Documentation Kconfig modules.order sound
drivers kernel Module.symvers System.map
firmware lib net tools
5.对nandflash进行分区
[leiyuxing@centos6 linux-3.0]$ vim arch/arm/plat-s3c24xx/common-smdk.c
板子上nandflash是256M,给bootloader1M用来启动,内核15M以及40M的根文件系统。其他自由分配。
注意:此时若要再进行分区就要选择相应的文件系统。Nandflash比较常用的有yaffs2,ubifs,cramfs以及initramfs等等。
$ make
此时能编译成功,但是生成的linux-s3c2440.bin文件依旧不能在板子上跑起来。
因为内核启动时首先挂载的是根文件系统,我们还没有做根文件系统给予内核支持,系统会出错而退出启动。
[leiyuxing@centos6 linux-3.0]$ make
开发板会自动启动uboot,你需要在一秒钟内通过终端进入到u-boot
[fl2440@lingyun]# pri
bootargs=console=ttyS0,115200 mem=64M rw loglevel=7
bootcmd=nand read 30008000 100000 800000; bootm 30008000
bbl=tftp 30008000 u-boot-s3c2440.bin;nand erase 0 100000;nand write 30008000 0 40000
blx=tftp 30008000 linuxrom-s3c2440.bin;nand erase 100000 F00000;nand write 30008000 100000 F00000
tb=tftp 30008000 linuxrom-s3c2440.bin; bootm 30008000
bootdelay=2
baudrate=115200
ethaddr=08:00:3e:26:0a:51
ipaddr=192.168.1.168
serverip=192.168.1.2
netmask=255.255.255.0
stdin=serial
stdout=serial
stderr=serial
ethact=dm9000
Environment size: 519/131068 bytes
pri后发现网络已配置好
[fl2440@lingyun]# run blx(运行blx,blx为快捷键)
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:00:3e:26:0a:51
could not establish link
operating at 100M full duplex mode
Using dm9000 device
TFTP from server 192.168.1.2; our IP address is 192.168.1.168
Filename 'linuxrom-s3c2440.bin'.
Load address: 0x30008000
Loading: ###############################################################
#################################################################
Erasing at 0xfe0000 -- 100% complete.
OK
NAND write: device 0 offset 0x100000, size 0xf00000
Skip bad block 0x005c0000
15728640 bytes written: OK
[fl2440@lingyun]# rest
resetting ...
*** Warning - bad CRC or NAND, using default environment
In: serial
Out: serial
Err: serial
Net: dm9000
Hit any key to stop autoboot: 2 Skipping bad block 0x005c0000
8388608 bytes read: OK
## Booting kernel from Legacy Image at 30008000 ...
Image Name: Linux Kernel
Created: 2016-07-20 7:56:12 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2267628 Bytes = 2.2 MiB
Load Address: 30008040
Entry Point: 30008040
Verifying Checksum ... OK
Loading Kernel Image ... OK
OK
Starting kernel ...
Linux version 3.0.0 (leiyuxing@centos6.7.localdomain) (gcc version 4.5.4 (Buildroot 2012.08) ) #2 Wed Jul 20 11:20:02 CST 2016
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: SMDK2440
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C24XX Clocks, Copyright 2004 Simtec Electronics
S3C244X: core 405.000 MHz, memory 101.250 MHz, peripheral 50.625 MHz
CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 16256
Kernel command line: console=ttyS0,115200 mem=64M rw loglevel=7
PID hash table entries: 256 (order: -2, 1024 bytes)
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 64MB = 64MB total
Memory: 60168k/60168k available, 5368k reserved, 0K highmem
Virtual kernel memory layout:
vector : 0xffff0000 - 0xffff1000 ( 4 kB)
fixmap : 0xfff00000 - 0xfffe0000 ( 896 kB)
DMA : 0xffc00000 - 0xffe00000 ( 2 MB)
vmalloc : 0xc4800000 - 0xf6000000 ( 792 MB)
lowmem : 0xc0000000 - 0xc4000000 ( 64 MB)
modules : 0xbf000000 - 0xc0000000 ( 16 MB)
.init : 0xc0008000 - 0xc002b000 ( 140 kB)
.text : 0xc002b000 - 0xc0445000 (4200 kB)
.data : 0xc0446000 - 0xc0469d60 ( 144 kB)
.bss : 0xc0469d84 - 0xc04a1a90 ( 224 kB)
SLUB: Genslabs=13, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
NR_IRQS:85
irq: clearing pending ext status 00080800
irq: clearing subpending status 00000002
Console: colour dummy device 80x30
console [ttyS0] enabled
Calibrating delay loop... 201.52 BogoMIPS (lpj=503808)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
gpiochip_add: gpios 288..303 (GPIOK) failed to register
gpiochip_add: gpios 320..334 (GPIOL) failed to register
gpiochip_add: gpios 352..353 (GPIOM) failed to register
NET: Registered protocol family 16
S3C Power Management, Copyright 2004 Simtec Electronics
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C244X: Clock Support, DVS off
厤乭ash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
NetWinder Floating Point Emulator V0.97 (extended precision)
NTFS driver 2.1.30 [Flags: R/W].
JFFS2 version 2.2. (NAND) 漏 2001-2006 Red Hat, Inc.
ROMFS MTD (C) 2007 Red Hat, Inc.
msgmni has been set to 117
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
Console: switching to colour frame buffer device 60x53
fb0: s3c2410fb frame buffer device
暆ネ褧蓵?
NET: Registered protocol family 17
lib80211: common routines for IEEE802.11 drivers
Registering the dns_resolver key type
drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
Root-NFS: no NFS server address
VFS: Unable to mount root fs via NFS, trying floppy.
VFS: Cannot open root device "(null)" or unknown-block(2,0)
Please append a correct "root=" boot option; here are the available partitions:
1f00 1024 mtdblock0 (driver?)
1f01 15360 mtdblock1 (driver?)
1f02 65536 mtdblock2 (driver?)
1f03 81920 mtdblock3 (driver?)
1f04 49152 mtdblock4 (driver?)
1f05 49152 mtdblock5 (driver?)
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)
Backtrace:
[<c00392cc>] (dump_backtrace+0x0/0x110) from [<c0359ff8>] (dump_stack+0x18/0x1c)
r6:00008000 r5:c3812000 r4:c046a1e0 r3:c044fa94
[<c0359fe0>] (dump_stack+0x0/0x1c) from [<c035a058>] (panic+0x5c/0x17c)
[<c0359ffc>] (panic+0x0/0x17c) from [<c0008e34>] (mount_block_root+0x1c8/0x208)
r3:00000000 r2:20000013 r1:c3827f58 r0:c03ea6d8
r7:c03ea73c
[<c0008c6c>] (mount_block_root+0x0/0x208) from [<c000901c>] (mount_root+0xac/0xd0)
[<c0008f70>] (mount_root+0x0/0xd0) from [<c00091ac>] (prepare_namespace+0x16c/0x1c0)
r4:c0469e00
[<c0009040>] (prepare_namespace+0x0/0x1c0) from [<c0008a28>] (kernel_init+0xe4/0x118)
r5:c002385c r4:c0469da0
[<c0008944>] (kernel_init+0x0/0x118) from [<c004a7f8>] (do_exit+0x0/0x624)
r5:c0008944 r4:00000000
此时在开发板上发现两半只企鹅,说明linux内核移植成功
linux内核移植过程中遇到的问题及解决方案:
问题一:
解决方法:
路径不对,将上述路径改为/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-
问题二:
LD [M] net/xfrm/xfrm_user.ko
cp arch/arm/boot/zImage . -f
mkimage -A arm -O linux -T kernel -C none -a 30008040 -n "Linux Kernel" -d zImage \ linuxrom-s3c2440.bin
/bin/sh: mkimage: command not found
make: *** [all] 错误 127
解决方法:
[leiyuxing@centos6 ~]$ cd ./fl2440/bootloader/u-boot-2010.09/tools
[leiyuxing@centos6 tools]$ sudo cp mkimage /bin
问题三:做好的linuxrom-s3c2440.bin没法转出
解决方法:/opt/buildroot-2012.08.packet/buildroot-2012.08/arm920t/usr/bin/arm-linux-
将+ mkimage -A arm -O linux -T kernel -C none -a 30008040 -n "Linux Kernel" -d zImage\去掉“/”改为mkimage -A arm -O linux -T kernel -C none -a 30008040 -n "Linux Kernel" -d zImage linuxrom-s3c2440.bin
问题四:
在修改代码时用用空格对其造成编译时错误
解决方法:
在修改代码时用Tab键对齐