您的位置:首页 > 运维架构 > Linux

Linux内核移植(1)

2017-12-02 16:18 330 查看

Linux-3.8.3移植-前期准备

u-boot移植已经完成,而u-boot的使命才刚刚开始—–启动kernel

启动Linux内核,并非一朝一夕,势必要怀着探索的心态,去领会。

路漫漫其修远兮,吾将上下而求索

u-boot支持多种内核,像Linux、android、wince等,同时内核也分多种架构,像x86、arm、MIPS、PowerPC等。所以u-boot成功启动内核之前,必须要让其知道内核的一些关键属性。

1、mkimage工具

u-boot make之后,在u-boot-2013.04-rc1/tools下生成mkimage文件,而它的作用正是在Linux 内核镜像zImage的前面加上64个字节的头,从而生成新的内核镜像uImage,让u-boot能够识别要加载内核的类型、加载地址等。

eric@eric-PC:~/Documents/u-boot-2013.04-rc1/tools$ ls mk*
mkenvimage    mkenvimage.o   mkimage    mkimage.h
mkenvimage.c  mkexynosspl.c  mkimage.c  mkimage.o
eric@eric-PC:~/Documents/u-boot-2013.04-rc1/tools$ ./mkimage
Usage: ./mkimage -l image
-l ==> list image header information
./mkimage [-x] -A arch -O os -T type -C comp -a addr -e ep -n name -d data_file[:data_file...] image
-A ==> set architecture to 'arch'
-O ==> set operating system to 'os'
-T ==> set image type to 'type'
-C ==> set compression type 'comp'
-a ==> set load address to 'addr' (hex)
-e ==> set entry point to 'ep' (hex)
-n ==> set image name to 'name'
-d ==> use image data from 'datafile'
-x ==> set XIP (execute in place)
./mkimage [-D dtc_options] -f fit-image.its fit-image
./mkimage -V ==> print version information and exit
eric@eric-PC:~/Documents/u-boot-2013.04-rc1/tools$


其中arch,os,type等一些参数,则是u-boot成功启动内核的关键信息。

将mkimage工具复制到deepin系统用户bin目录下(需要root权限),供后续生成linux内核镜像uImage的时候使用。

eric@eric-PC:~/Documents/u-boot-2013.04-rc1/tools$ cp mkimage /usr/bin/
cp: 无法创建普通文件'/usr/bin/mkimage': 权限不够
eric@eric-PC:~/Documents/u-boot-2013.04-rc1/tools$ sudo cp mkimage /usr/bin/
[sudo] eric 的密码:
eric@eric-PC:~/Documents/u-boot-2013.04-rc1/tools$ ls /usr/bin/mk*
/usr/bin/mkfifo     /usr/bin/mkfontscale  /usr/bin/mkmanifest  /usr/bin/mksquashfs
/usr/bin/mkfontdir  /usr/bin/mkimage      /usr/bin/mk_modmap   /usr/bin/mkyaffs2image
eric@eric-PC:~/Documents/u-boot-2013.04-rc1/tools$


2、linux 内核源码下载

linux-3.8.3内核下载后,解压。

eric@eric-PC:~/Documents/linux-3.8.3$ ls
arch     crypto         fs       Kbuild   MAINTAINERS  README          security  virt
block    Documentation  include  Kconfig  Makefile     REPORTING-BUGS  sound
COPYING  drivers        init     kernel   mm           samples         tools
CREDITS  firmware       ipc      lib      net          scripts         usr


arch: 包含所有支持的核心,我们这里当然是arm了。

drivers:所有外设驱动,usb、mmc、gpio等

fs:支持的文件系统,fat、ext4等

3、修改linux根目录下Makefile

修改eric@eric-PC:~/Documents/linux-3.8.3/Makefile 195行

export KBUILD_BUILDHOST := $(SUBARCH)
ARCH        ?= arm
CROSS_COMPILE   ?= /usr/local/arm/arm-linux-gcc-4.4.3/bin/arm-linux-


注意:每行最后不能有空格,否则后面的编译,会出现类似如下错误。

eric@eric-PC:~/Documents/linux-3.8.3$ make menuconfig
make: *** /home/eric/Documents/linux-3.8.3/arch/arm: 是一个目录。 停止。


4、配置menuconfig

1、 linux 配置采用图形化界面,需要安装所依赖的ncurses libraries。

若没有成功安装ncurses库,则会出现如下错误信息:

eric@eric-PC:~/Documents/linux-3.8.3$ make menuconfig
HOSTCC  scripts/basic/fixdep
HOSTCC  scripts/kconfig/conf.o
*** Unable to find the ncurses libraries or the
*** required header files.
*** 'make menuconfig' requires the ncurses libraries.
***
*** Install ncurses (ncurses-devel) and try again.
***
/home/eric/Documents/linux-3.8.3/scripts/kconfig/Makefile:196: recipe for target 'scripts/kconfig/dochecklxdialog' failed
make[1]: *** [scripts/kconfig/dochecklxdialog] Error 1
Makefile:503: recipe for target 'menuconfig' failed
make: *** [menuconfig] Error 2


2、安装ncurses相关库

eric@eric-PC:~/Documents/linux-3.8.3$ sudo apt-get install libncurses*

eric@eric-PC:~/Documents/linux-3.8.3$ sudo apt-get install libncurses5-dev


3、以上安装完成,执行make menuconfig,

eric@eric-PC:~/Documents/linux-3.8.3$ make menuconfig


成功看到如下图形化界面



4、如果出现以下错误,则说明窗口太小,无法顺利呈现图形化界面。需要将终端窗口最大化,或者终端字体调小即可

recipe for target 'menuconfig' failed


至此,linux内核移植,已经成功迈出了第一步!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: