系统移植-(三)kernel内核源码的配置和编译过程

内核 -源码目录

在这里插入图片描述
1.在ubuntu的家目录下创建kernel文件夹,将共享文件夹下的内核源码拷贝到kernel下
mkdir kernel
cd kernel
cp /mnt/hgfs/share/kernel-3.4.39-ok.tar.bz2 ./

2.对内核源码进行解压缩:
tar -vxf kernel-3.4.39-ok.tar.bz2

内核的配置

(1)make clean/disclean:清除编译产生的中间文件和检查makefile是否正确无误。
make mrproper :清除更彻底、干净
(2)ctags -R 或 make tags:在顶层kernel目录下创建tags索引文件

(一)配置交叉编译工具链

因为kernel要移植到ARM_目标板,因此需要配置交叉编译工具:
打开内核源码顶层目录下的Makefile,搜索:/CROSS_COMPILE

195 ARCH        ?= 
196 CROSS_COMPILE   ?= 
修改为:
195 ARCH        ?= arm
196 CROSS_COMPILE   ?= arm-none-linux-gnueabi-

注意:arm-none-linux-gnueabi-中,字符 ’ - ’ 后面不可有空格。

(二)README:解读内核配置过程

138 BUILD directory for the kernel:  //内核编译目录
139 
140    When compiling the kernel all output files will per default be
141    stored together with the kernel source code.
142    Using the option "make O=output/dir" allow you to specify an alternate
143    place for the output files (including .config).
144    Example:
145      kernel source code:    /usr/src/linux-3.N
146      build directory:       /home/name/build/kernel
147 
148    To configure and build the kernel use:	//配置和编译内核源码用以下命令:
149    cd /usr/src/linux-3.N
150    make O=/home/name/build/kernel menuconfig
151    make O=/home/name/build/kernel
152    sudo make O=/home/name/build/kernel modules_install install
153 
154    Please note: If the 'O=output/dir' option is used then it must be
155    used for all invocations of make.

157 CONFIGURING the kernel:   //内核的配置
158 
159    Do not skip this step even if you are only upgrading one minor
160    version.  New configuration options are added in each release, and
161    odd problems will turn up if the configuration files are not set up
162    as expected.  If you want to carry your existing configuration to a
163    new version with minimal work, use "make oldconfig", which will
164    only ask you for the answers to new questions.

//即使您只升级了一个次要的版本,也不要跳过这一步。每个版本都增加了新的配置选项,
如果配置文件没有按照预期设置好,就会出现奇怪的问题。
如果您想将现有的配置以最少的工作量转移到新版本中,
那么使用“make oldconfig”,它将只向您询问新问题的答案。

165 
166  - Alternate configuration commands are:	//配置命令的选择:
167     "make config"      Plain text interface.	//纯文本界面
168     "make menuconfig"  Text based color menus, radiolists & dialogs.   //彩色菜单对话框
179     "make defconfig"   Create a ./.config file by using the default
180                symbol values from either arch/$ARCH/defconfig
181                or arch/$ARCH/configs/${PLATFORM}_defconfig,
182                depending on the architecture.   //通过默认架构配置内核

183     "make ${PLATFORM}_defconfig"	//配置内核源码支持当前架构的硬件平台
184               Create a ./.config file by using the default
185               symbol values from
186               arch/$ARCH/configs/${PLATFORM}_defconfig.
187               Use "make help" to get a list of all available
188               platforms of your architecture.
//使用arch/$ arch/ configs/${PLATFORM}_defconfig中的默认符号值来创建一个当前目录下的.config文件。
使用“make help”可获取当前架构中所有可用平台的列表。

200    You can find more information on using the Linux kernel config tools
201    in Documentation/kbuild/kconfig.txt.   
你可以在Documentation/kbuild/kconfig.txt中找到更多关于使用Linux内核配置工具的信息。

(1)配置内核源码支持当前的硬件平台

1)方法一:make help

linux@ubuntu:~/kernel/kernel-3.4.39$ make help
make + 目标:
Cleaning targets:
  clean		  - Remove most generated files but keep the config and
                    enough build support to build external modules
  mrproper	  - Remove all generated files + config + various backup files
  distclean	  - mrproper + remove editor backup and patch files

Configuration targets:
  config	  - Update current config utilising a line-oriented program
  nconfig     - Update current config utilising a ncurses menu based program
 defconfig	  - New config with default from ARCH supplied defconfig
 menuconfig   - Text based color menus, radiolists & dialogs.   //彩色菜单对话框
 
Other generic targets://其他通用的目标
  all		  - Build all targets marked with [*]
* vmlinux	  - Build the bare kernel
* modules	  - Build all modules

Architecture specific targets (arm):
* zImage        - Compressed kernel image (arch/arm/boot/zImage)
  Image         - Uncompressed kernel image (arch/arm/boot/Image)
* xipImage      - XIP kernel image, if configured (arch/arm/boot/xipImage)
  uImage        - U-Boot wrapped zImage

fs6818_defconfig         - Build for fs6818

2)方法二:make ${PLATFORM}_defconfig

"make ${PLATFORM}_defconfig"
 arch/$ARCH/configs/${PLATFORM}_defconfig.

进入 arch/arm/configs/目录下,能找到支持自己平台板子的文件:{PLATFORM}_defconfig.
因为${PLATFORM}_defconfig文件必须根据源码目录下的Makefile配置才能生成.config文件。

在顶层目录下,执行命令:make ${PLATFORM}_defconfig,来让当前的内核支持自己的硬件平台。
eg:make fs6818_defconfig
执行结果如下:

linux@ubuntu:kernel-3.4.39$ make fs6818_defconfig
HOSTCC  scripts/basic/fixdep
HOSTCC  scripts/kconfig/conf.o
SHIPPED scripts/kconfig/zconf.tab.c
SHIPPED scripts/kconfig/zconf.lex.c
SHIPPED scripts/kconfig/zconf.hash.c
HOSTCC  scripts/kconfig/zconf.tab.o
HOSTLD  scripts/kconfig/conf
# 
# configuration written to .config
#

执行完命令将板子的配置信息写入到内核源码顶层目录下的.config文件中。

.config文件解读
   1 #
   2 # Automatically generated file; DO NOT EDIT.
   3 # Linux/arm 3.4.39 Kernel Configuration
   4 #
   5 CONFIG_ARM=y
   6 CONFIG_HAVE_PWM=y
   7 CONFIG_SYS_SUPPORTS_APM_EMULATION=y
   8 CONFIG_GENERIC_GPIO=y               
   9 # CONFIG_ARCH_USES_GETTIMEOFFSET is not set
  10 CONFIG_GENERIC_CLOCKEVENTS=y
  11 CONFIG_GENERIC_CLOCKEVENTS_BROADCAST=y
  12 CONFIG_KTIME_SCALAR=y
  ...
 320 CONFIG_FS6818=y
~

CONFIG_FS6818=y:配置内核支持自己的板子FS6818

(2)make menuconfig:配置内核

make menuconfig:基于菜单选项方式对内核进行配置
注意:
(1)首次使用make menuconfig之前,需要先配置安装图形化界面的工具库:

	sudo apt-get install libncurses5-dev 

(2)出现下面错误:终端的字体太大,需要终端界面缩小一点

cripts/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

make menuconfig执行过程:

linux@ubuntu:~/kernel/kernel-3.4.39$ make menuconfig
  HOSTCC  scripts/kconfig/conf.o
  HOSTCC  scripts/kconfig/lxdialog/checklist.o
  HOSTCC  scripts/kconfig/lxdialog/inputbox.o
  HOSTCC  scripts/kconfig/lxdialog/menubox.o
  HOSTCC  scripts/kconfig/lxdialog/textbox.o
  HOSTCC  scripts/kconfig/lxdialog/util.o
  HOSTCC  scripts/kconfig/lxdialog/yesno.o
  HOSTCC  scripts/kconfig/mconf.o
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/mconf
scripts/kconfig/mconf Kconfig


*** End of the configuration.
*** Execute 'make' to start the build or try 'make help'.

在这里插入图片描述
注:空格或者Y/N:选择三态/布尔类型选项

(3)编译内核生成:uImage

make uImage 
time make uImage -jx

注:
time:回显编译的时间
-jx:使用多线程的方式进行编译;x:可以是2、4、6、8

  • 编译过程中可能出现的错误
"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存在于u-boot源码~/tools/目录下,
因此u-boot源码必须先进行编译之后才会有mkimage可执行程序。

  • 解决问题的方法:将u-boot源码的tools目录下的mkimage,拷贝到到ubuntu的/usr/bin目录下:
sudo cp ./tools/mkimage   /usr/bin
          u-boot目录      ubuntu目录

再次对内核源码进行编译即可通过。

(4)测试uImage:kernel顶层目录/arch/arm/boot/uImage

在ubuntu下,将kernel目录下的arch/arm/boot/uImage拷贝到~/tftpboot目录下,测试uImage是否可以正常启动,并且挂载根文件系统。

通过tftp的方式下载uImage到内存中,
通过nfs的方式挂载根文件系统。
注意:检查bootcmd和bootargs参数设置是否正确。

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
移植编译Linux驱动源码,你需要按照以下步骤进行操作: 1. 获取驱动源码:从适当的来源获取你所需的驱动程序的源代码。这可以是从硬件供应商提供的驱动程序包、官方Linux内核源码树或其他开源项目。 2. 准备交叉编译环境:在进行移植之前,你需要设置交叉编译环境,以便能够为目标平台生成可执行驱动。这包括安装交叉编译工具链和相关的库和头文件。 3. 配置内核:如果你的驱动程序依赖于特定的内核配置选项,你需要配置内核以包含这些选项。进入内核源码树目录,使用`make menuconfig`命令进行配置。 4. 移植代码:将驱动源码复制到目标平台上的适当位置。确保目标平台上有必要的依赖项和库。 5. 编写Makefile:根据你的驱动源码的结构,在驱动源码目录中创建一个Makefile文件。确保Makefile中正确设置了交叉编译工具链和目标平台信息。 6. 编译驱动:在驱动源码目录中运行`make`命令来编译驱动程序。如果一切顺利,将会生成一个可加载模块的二进制文件(.ko文件)。 7. 安装驱动:将生成的驱动模块文件拷贝到目标平台上适当的位置,如`/lib/modules/<kernel_version>/`目录,然后运行`depmod`命令更新模块依赖关系。 8. 加载驱动:使用`modprobe`命令加载驱动模块到内核中。你也可以在启动时自动加载驱动,通过修改`/etc/modules`或相关配置文件。 注意:以上步骤是一般的移植编译流程,具体步骤可能会因驱动程序的不同而有所不同。确保仔细阅读驱动程序的文档,并根据具体情况进行相应的配置和操作。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值