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

/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值