Linux内核编译
本篇博客来自凌云实验室开发板介绍及其烧录学习笔记
一种开源电脑操作系统内核。它是一个用C语言写成,符合POSIX标准的类Unix操作系统。也就是,最上面是用户(或应用程序)空间,程序执行的地方。**函数库(glibc或uclibc)**提供了连接内核的系统调用接口,还提供了在用户空间应用程序和内核之间进行转换的机制。区别于51,stm32单片机等,每个用户空间的进程都使用自己的虚拟地址空间,而内核则占用单独的地址空间。
现在内核更新的比较快,我们为s3c2440选择3.0版本。附上内核下载链接。
博主使用的是三星的ARM9 S3C2440,该cpu是以armv4t指令集的ARM920t,跑ARM Linux的开发板时,以SMDK2440为模板支持相应的硬件。建立整体框架。
[klaus@localhost ~]$ mkdir fl2440
[klaus@localhost ~]$ cd fl2440/
[klaus@localhost fl2440]$ mkdir -p {crosstool,bootloader,linux/{kernel,rootfs},driver,3rdparty,program,images}
[klaus@localhost fl2440]$ tree
.
├── 3rdparty
├── bootloader
├── crosstool
├── driver
├── images
├── linux
│ ├── kernel
│ └── rootfs
└── program
9 directories, 0 files
[klaus@localhost fl2440]
下载源代码后,修改成自己单片机相应的类型
一般为开发板型号
其他型号都不需要选择,只选择s3c2440 and s3c2442 Machines
不同需要,比如更改串口驱动设备,自己的交叉编译器等等。
编译前可以查看一下C文件和汇编文件的多少,当然我这个是内核生成之后的文件个数。
[klaus@localhost linux-3.0]$ find -name *.c | wc -l
16563
[klaus@localhost linux-3.0]$ find -name *.S | wc -l
1226
[klaus@localhost linux-3.0]$
拟写一个shell脚本,博主会在另一篇文章详细讲解,文章链接在这里。
#!/bin/bash
make
mkimage -A arm -O linux -T kernel -C none -a 30008000 -e 30008040 -n "Linux Kernel" -d arch/arm/boot/zImage linuxrom-s3c2440.bin
chmod a+x linuxrom-s3c2440.bin
执行脚本后就可以查看生成结果了
[klaus@localhost linux-3.0]$ chmod a+x build.sh
[klaus@localhost linux-3.0]$ ./build.sh
... ... ...
Image Name: Linux Kernel
Created: Thu Mar 15 11:58:01 2018
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2314180 Bytes = 2259.94 kB = 2.21 MB
Load Address: 30008000
Entry Point: 30008040
[klaus@localhost linux-3.0]$ ls
arch CREDITS firmware ipc lib mm net scripts tools vmlinux.o
block crypto fs Kbuild linuxrom-s3c2440.bin modules.builtin README security usr
build.sh Documentation include Kconfig MAINTAINERS modules.order REPORTING-BUGS sound virt
COPYING drivers init kernel Makefile Module.symvers samples System.map vmlinux
[klaus@localhost linux-3.0]$
#####1)格式错误
... ... ...
[klaus@localhost linux-3.0]$ make s3c2410_defconfig
make: *** /home/klaus/fl2440/linux/linux-3.0/arch/arm: Is a directory. Stop.
解决办法,在改文件路径时,多空格少换号都不行,要严格注意
export KBUILD_BUILDHOST := $(SUBARCH)
ARCH ?=arm
CROSS_COMPILE ?=/opt/x-tools/arm920t/bin/arm-linux-
楼主我出现这个问题是因为我多打了一个空格,arm后面。
####2)缺少依赖
... ... ...
IHEX2FW firmware/emi62/spdif.fw
IHEX2FW firmware/emi62/midi.fw
./build.sh:line 3:mkimage:command not found
chmod:cannot access `linuxrom-s3c2440.bin`:No such file or directory
[klaus@localhost linux-3.0]$
可能是缺少uboot-tools之间这个依赖,可以直接下载这个安装包进行安装
[klaus@localhost ~]$ wget http://rpmfind.net/linux/epel/6/x86_64/Packages/u/uboot-tools-2011.03-1.el6.x86_64.rpm
[klaus@localhost ~]$ sudo rpm -ivh uboot-tools-2011.03-1.el6.x86_64.rpm
内核生成后,我们可以尝试将这个.bin文件烧录到现有的开发板上去,看看现象会怎样
这里在u-boot界面采用tftp下载到开发板
U-Boot 2010.09 (May 05 2017 - 19:48:28)
DRAM: 64 MiB
NAND: 256 MiB
In: serial
Out: serial
Err: serial
Net: dm9000
Hit any key to stop autoboot: 0
[fl2440@lingyun]#
[fl2440@lingyun]# run tb
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 00:11:22:33:44:55
could not establish link
Using dm9000 device
TFTP from server 192.168.100.8; our IP address is 192.168.100.18
Filename 'linuxrom-s3c2440.bin'.
Load address: 0x30008000
Loading: #################################################################
#################################################################
##########################################################
done
Bytes transferred = 2752308 (29ff34 hex)
## Booting kernel from Legacy Image at 30008000 ...
Image Name: Linux Kernel
Created: 2017-06-19 22:03:17 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2752244 Bytes = 2.6 MiB
Load Address: 30008000
Entry Point: 30008040
Verifying Checksum ... OK
XIP Kernel Image ... OK
OK
Starting kernel ...
Uncompressing Linux... done, booting the kernel.
Linux version 3.0.0 ([email protected]) (gcc version 4.5.4 (Buildroot 2012.08) ) #2 Tue Jun 20 06:03:14 CST 2017
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
... ... ...
arp_tables: (C) 2002 David S. Miller
TCP cubic registered
NET: Registered protocol family 17
lib80211: common routines for IEEE802.11 drivers
Registering the dns_resolver key type
s3c-rtc s3c2410-rtc: setting system clock to 2017-10-31 02:57:07 UTC (1509418627)
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 40960 mtdblock2 (driver?)
1f03 81920 mtdblock3 (driver?)
1f04 81920 mtdblock4 (driver?)
1f05 40960 mtdblock5 (driver?)
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)
Backtrace:
[] (dump_backtrace+0x0/0x110) from [] (dump_stack+0x18/0x1c)
r6:00008000 r5:c38ac000 r4:c056dd40 r3:c05446d4
[] (dump_stack+0x0/0x1c) from [] (panic+0x5c/0x17c)
[] (panic+0x0/0x17c) from [] (mount_block_root+0x1c8/0x208)
r3:00000000 r2:20000013 r1:c3819f58 r0:c04c32ed
r7:c04c3351
[] (mount_block_root+0x0/0x208) from [] (mount_root+0xac/0xd0)
[] (mount_root+0x0/0xd0) from [] (prepare_namespace+0x160/0x1b4)
r4:c056d680
[] (prepare_namespace+0x0/0x1b4) from [] (kernel_init+0xe4/0x118)
r5:c0025d3c r4:c056d620
[] (kernel_init+0x0/0x118) from [] (do_exit+0x0/0x624)
r5:c00088f0 r4:00000000
系统会报出 **Unable to mount root fs on unknown-block(2,0)**这样的错误,这时候就是缺少根文件系统了,下一步,将根文件系统树烧进内核中绑定一起就以可以将系统跑起来,这里文件系统的制作链接。