最小的linux内核编译,Linux最小内核移植
class="markdown_views prism-github-gist">
Linux內核編譯
本篇博客來自凌云實驗室開發板介紹及其燒錄學習筆記
1.內核介紹
一種開源電腦操作系統內核。它是一個用C語言寫成,符合POSIX標準的類Unix操作系統。也就是,最上面是用戶(或應用程序)空間,程序執行的地方。**函數庫(glibc或uclibc)**提供了連接內核的系統調用接口,還提供了在用戶空間應用程序和內核之間進行轉換的機制。區別于51,stm32單片機等,每個用戶空間的進程都使用自己的虛擬地址空間,而內核則占用多帶帶的地址空間。
2.內核下載
現在內核更新的比較快,我們為s3c2440選擇3.0版本。附上內核下載鏈接。
3.文件準備
博主使用的是三星的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]
4.內核修改編譯
下載源代碼后,修改成自己單片機相應的類型
一般為開發板型號
其他型號都不需要選擇,只選擇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]$
5. 有趣的三角
擬寫一個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]$
6.可能遇到的問題
#####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
7.燒錄到開發板
內核生成后,我們可以嘗試將這個.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 (guowenxue@centos6.localdomain) (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)**這樣的錯誤,這時候就是缺少根文件系統了,下一步,將根文件系統樹燒進內核中綁定一起就以可以將系統跑起來,這里文件系統的制作鏈接。
總結
以上是生活随笔為你收集整理的最小的linux内核编译,Linux最小内核移植的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux安装oem环境,【OEM】 o
- 下一篇: qt 4.8.4 linux,Tslib