linux编译内核实验,实验六 Linux内核编译实验.doc
實驗六 Linux內核編譯
講師:楊行
【實驗目的】
1、掌握Linux內核編譯
2、了解Linux內核Makefile
3、了解Linux內核Kbuild系統
【實驗原理】
網站可以下載標準內核文件;
本次實驗使用的內核源碼詳見,ARM裸板驅動開發課程所發的arm_linux文件夾;
編譯內核
1 內核源碼目錄分析
2 內核編譯主要過程;
du -hs linux-.tar.gz
tar xzvf linux--mini2440tar.gz -C /
find -name "*" | wc –l
tree
cp config_mini2440_w35 .config
make menuconfig
make zImage
3 編譯主要過程講解
將所有目標連接為: LD vmlinux
去除vmlinux生成純二進制文件 OBJCOPY arch/arm/boot/Image
提示鏡像文件編譯生成 Image Kernel: arch/arm/boot/Image is ready
匯編編譯程序啟動頭 AS arch/arm/boot/compressed/head.o
壓縮源碼Image: GZIP arch/arm/boot/compressed/piggy.gz
匯編編譯產生壓縮程序 AS arch/arm/boot/compressed/piggy.o
鏈接 LD arch/arm/boot/compressed/vmlinux
純二進制文件生成: OBJCOPY arch/arm/boot/zImage
最終生成: Kernel: arch/arm/boot/zImage is ready
/linux-/arch/arm/boot$ du -hs Image
/linux-/arch/arm/boot$ du -hs zImage
4 運行內核
copy zImage 到tftpboot目錄中;
tftp 下載zImage到0到0址后;
使用bootm 0啟動內核;
查看內核是否可以正常啟動;
未能啟動內核的原因有兩種:
第一種:未配置網絡文件系統;
第二種:未正確設置u-boot啟動參數;
4.1 配置nfs文件系統
1. sudo apt-get install nfs-kernel-server
2. sudo vim /etc/exports
+
/nfsroot *(rw,sync,no_root_squash)
3. sudo /etc/init.d/portmap restart
4. sudo /etc/init.d/nfs-kernel-server restart
5. showmount –e
切換到/home/spring/arm_linux/mini2440/src目錄下:
6 sudo tar xvf nfsroot.tar -C /
4.2 設置u-boot的啟動參數
在u-boot命令行模式下:
set bootargs root=/dev/nfs rw nfsroot=:/nfsroot ip=30 console=ttySAC0,115200
save
5 編寫測試程序hello.c
#include
int main()
{ printf("hello world!\n");
while(1);
}
5.1 在PC機上面編譯hello.c
arm-linux-gcc –c helo.c –o hello.o
arm-linux-gcc hello.o –o hello
cp hello /nfsroot
5.2 在mini2440平臺上后臺運行hello,并使用命令殺死hello進程
/sq1415 # ls
hello
/sq1415 # ./hello &
/sq1415 # hello world!
/sq1415 #
/sq1415 # ps -a |grep hello
729 0 0:50 ./hello
731 0 0:00 grep hello
/sq1415 # kill -9 729
/sq1415 # jobs
[1]+ Killed ./hello
/
總結
以上是生活随笔為你收集整理的linux编译内核实验,实验六 Linux内核编译实验.doc的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux权限值前面的d,linux中r
- 下一篇: linux 补丁脚本,Linux上打pa