Linux系统移植学习笔记2
二、linux内核的移植
1.linux内核的特点
1. linux内核是开源的,作者:linus (git : 版本管理工具)
2. 源码由C语言和汇编实现
3. linux内核支持多种硬件架构平台
4. linux内核采用模块化方式编写,分层思想
5. linux内核使用C和汇编代码实现,在内核中最好不要使用C++
6. linux内核具有很好的移植和裁剪特性,通过图形化界面的配置方式就可以完成裁剪
2.linux内核源码的获取
1. linux官方获取
https://mirrors.edge.kernel.org/pub/linux/kernel/
2. 芯片厂家获取
3. 开发板厂家获取
4. 公司主管获取
本次一直练习使用:kernel-3.4.39-ok.tar.bz2
3.linux内核的版本命名方式
主版本号.次版本号.修订版本号
主版本号:内核源码有较大的改动才会更新主版本号
次版本号:修订版本号用完升级次版本号
偶数:稳定版
奇数:测试版
修订版本号:内核代码只要有更新就会修改修订版本号
4.linux内核版本的选择
1. 不选太新
2. 不选太旧
3. 选择稳定版本
5.linux内核的配置和编译
1. 拷贝linux内核源码压缩包到ubuntu中
1)拷贝内核源码到ubuntu目录中
kernel-3.4.39.tar.bz2
2)解压缩内核源码
tar -vxf kernel-3.4.39.tar.bz2
3)进入内核源码目录
cd kernel-3.4.39
2. 分析内核源码的目录结构
平台相关代码:代码跟硬件相关
arch
平台无关代码:代码跟硬件无关
drivers
lib
include
net
fs
kernel
...
3. 获取配置和编译的命令
清除中间文件:
make clean
make distclean
配置linux内核:
make menuconfig 基于菜单选项的方式对内核进行配置
编译内核:
make modules 模块化编译内核
make uImage 编译生成uImage的内核镜像
make dtbs 编译生成设备树文件
make fs6818_defconfig 配置内核支持fs6818开发板
"make ${PLATFORM}_defconfig"
Create a ./.config file by using the default
symbol values from
arch/$ARCH/configs/${
PLATFORM}_defconfig.
Use "make help" to get a list of all available
platforms of your architecture.
根据arm/arm/configs目录下提供的缺省文件,
在内核源码的顶层目录下生成一个.config配置文件
6.对内核源码进行配置和编译
1. 配置交叉编译工具链
195 ARCH ?= arm
196 CROSS_COMPILE ?= arm-none-linux-gnueabi-
2. 执行make distclean清除中间文件
只需要执行一次,
3. 执行make fs6818_defconfig 配置内核源码支持fs6818平台
4. 执行make menuconfig 通过图形化界面对内核进行配置
问题1:make menuconfig
第一次使用make menuconfig 需要安装图形化界面的工具
配置之前需要安装图形图(make meuconfig):
sudo apt-get install libncurses5-dev
sudo apt-get install lib32z1 (64位)
问题2 :make menuconfig
scripts/kconfig/mconf Kconfig
Your display is too small to run Menuconfig!
It must be at least 19 lines by 80 columns.
make[1]: *** [menuconfig] Error 1
make: *** [menuconfig] Error 2
中断字体太大,缩小终端字体
Device Drivers --->
Character devices --->
[ ] FS6818 beep driver # 去掉*
FS6818 board device driver support --->
[ ] adc driver for farsight FS6818 all platform # 去掉*
[ ] pwm timer driver for farsight FS6818 # 去掉*
[ ] DS18B20 driver for farsight FS6818 # 去掉*
FS6818 extension device driver support --->
< > This is FS6818_LED! # 去掉*
[ ] zlg7290 driver support input device # 去掉*
5. 执行make uImage 生成uImage的内核镜像
问题3:make uImage
在编译的过程中可能出现如下错误:
"mkimage" command not found - U-Boot images will not be built
make[1]: *** [arch/arm/boot/uImage] Error 1
make: *** [uImage] Error 2
错误的原因:找不到mkimage命令,
根据提示分析出来mkimage应该存在uboot源码目录中
uboot源码必须进行编译之后才会有mkimage可执行程序
解决问题的方法:
将uboot源码的tools目录下的mkimage,
拷贝到到ubuntu的/usr/bin目录下:
sudo cp ~/uboot源码目录/tools/mkimage /