韦东山Linux视频第1期_裸板_UBoot_文件系统_驱动初步第10课第3节 内核启动流程分析之Makefile.WMV

 1. 编译内核分三步:

  make xxx_defconfig [linux/arch/arm/configs/s3c2410_defconfig]

  make menuconfig 或者使用厂商配置好的ok_config即可, cp ok_config linux/.config

    执行该命令时,从Kconfig里面读取菜单选项,形成可视化菜单。 执行后,根据用户自己配置,改写 .config文件。如果厂商已经配置好ok_config,可以不经过这一步选配,直接拷贝过来即可,cp ok_config linux/.config.

    到此时, 生成了几个.cmd文件和.c以及.config,从而指导后面的编译选择.【各级子Makefile一般根据.config 里面的宏定义选项,选择是否编译以及是否编译为模块 。】

      试下make distclean{

        CLEAN scripts/basic
        CLEAN scripts/kconfig
        CLEAN include/config
        CLEAN .config

      }

make

  主Makefile以及各级Makefile 引用.config 里面的宏定义选项(同时还要引用各级写好的Kbuild/kconfig),生成宏定义头文件( 如 /include/linux/autoconf.h :#define CONFIG_ARM 1 )并编译内核。

==================================================

2. 根据Makefile, vmlinux.lds文件,分析编译文件是哪些:

/* linux-2.6.22.6\arch\arm\Makefile */
zImage Image xipImage bootpImage uImage: vmlinux /* linux-2.6.22.6\Makefile ; include $(srctree)/arch/$(ARCH)/Makefile*/
all: vmlinux
vmlinux: $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) $(kallsyms.o) FORCE >>>
vmlinux-lds := arch/$(ARCH)/kernel/vmlinux.lds
{
lds和代码分析示例: in lds:
.text.head : {
_stext = .;
_sinittext = .;
*(.text.head)
} in head.S:
.section ".text.head", "ax"
.type stext, %function
code...
} vmlinux-init := $(head-y) $(init-y)
{
head-y := arch/arm/kernel/head.o arch/arm/kernel/init_task.o /* linux-2.6.22.6\arch\arm\Makefile */
init-y := init/built-in.o ; /*init/文件夹下面的所有代码被编译成init/built-in.o */
} vmlinux-main := $(core-y) $(libs-y) $(drivers-y) $(net-y)
{
core-y := usr/built-in.o kernel/built-in.o mm/built-in.o fs/built-in.o ipc/built-in.o security/built-in.o crypto/built-in.o block/built-in.o
libs-y := $(libs-y1) $(libs-y2)
libs-y1 := lib/lib.a
libs-y2 := lib/built-in.o
drivers-y := drivers/built-in.o sound/built-in.o
net-y := net/built-in.o
}

 

==================================================

3. 关于编译选项的格式:

.如果一个驱动直接编译进内核,直接按照以下方式书写:
obj-y += generic_serial.o vme_scc.o
obj-y += a.o

.如果一个驱动要编译成模块,一个模块由1个源文件编译而成:

obj-m += a.o

.如果一个驱动要编译成模块,且一个模块由多个源文件编译而成, 其编译过程为:

obj-m += ab.o
ab-objs := a.o b.o
编译过程:
a.c -> a.o
b.c -> b.o
a.o b.o -> ab.o -> ab.ko

参考:\linux-2.6.22.6\Documentation\kbuild

    Example:
#drivers/isdn/i4l/Makefile
obj-$(CONFIG_ISDN) += isdn.o
isdn-objs := isdn_net_lib.o isdn_v110.o isdn_common.o $(obj-m) specify object files which are built as loadable
kernel modules. A module may be built from one source file or several source
files. In the case of one source file, the kbuild makefile
simply adds the file to $(obj-m). Example:
#drivers/isdn/i4l/Makefile
obj-$(CONFIG_ISDN_PPP_BSDCOMP) += isdn_bsdcomp.o Note: In this example $(CONFIG_ISDN_PPP_BSDCOMP) evaluates to 'm' If a kernel module is built from several source files, you specify
that you want to build a module in the same way as above. Kbuild needs to know which the parts that you want to build your
module from, so you have to tell it by setting an
$(<module_name>-objs) variable. Example:
#drivers/isdn/i4l/Makefile
obj-$(CONFIG_ISDN) += isdn.o
isdn-objs := isdn_net_lib.o isdn_v110.o isdn_common.o In this example, the module name will be isdn.o. Kbuild will
compile the objects listed in $(isdn-objs) and then run
"$(LD) -r" on the list of these files to generate isdn.o.

编译kernel:编译的更多相关文章

  1. hi3531 SDK 编译 kernel, 修改 参数

    开发环境用户指南上这么写的 3.1 内核源代码 成功安装Hi3531 SDK后,内核源代码已存放于SDK目录下的osdrv/目录中,用户可 直接进入目录进行相关操作. 3.2 配置内核 如果对内核和H ...

  2. am335x uboot, kernel 编译

    一.设置环境变量 // 写在家目录下面的 .bashrc 里面 export KERNEL_PATH=~/aplex/kernel3.2.0 // kernel 路径 export UBOOT_PAT ...

  3. I.MX6 linux kernel编译错误处理

    /******************************************************************************** * I.MX6 linux kern ...

  4. Android6.0内核移植(2):kernel编译内核

    普通步骤是:用来编译整个Android源码 source build/envsetup.sh lunch sabresd_6dq-user make -j20 不过每次这样太繁琐,下面来单独编译ker ...

  5. linux 编译kernel与svn版本冲突解决方法 [drivers/gpu/mali/mali/common/mali_kernel_core.o] 错误 1

    问题: 系统正常编译linux系统kernel,安装svn后,kernel编译出错. 错误: CHK     include/linux/version.h  CHK     include/gene ...

  6. JIT(动态编译)和AOT(静态编译)编译技术比较

    Java 应用程序的性能经常成为开发社区中的讨论热点.因为该语言的设计初衷是使用解释的方式支持应用程序的可移植性目标,早期 Java 运行时所提供的性能级别远低于 C 和 C++ 之类的编译语言.尽管 ...

  7. 预编译加速编译(precompiled_header),指定临时文件生成目录,使项目文件夹更干净(MOC_DIR,RCC_DIR, UI_DIR, OBJECTS_DIR),#pragma execution_character_set("UTF-8")"这个命令是在编译时产生作用的,而不是运行时

    预编译加速编译 QT也可以像VS那样使用预编译头文件来加速编译器的编译速度.首先在.pro文件中加入: CONFIG += precompiled_header 然后定义需要预编译的头文件: PREC ...

  8. apktool 反编译 回编译

    下载apktool 安装好Java环境 拷贝apk 拷贝game.apk到当前文件夹.apk随便指定 反编译 反编译完成.生成game目录 game目录内容 回编译 回编译完成.生成build和dis ...

  9. Apache 安装 静态编译 动态编译

    2014-09-19 09:53 (分类:Linux) 排名第一的web服务器. (linux环境:CentOS release 6.5 (Final)) 安装出错:如下 configure: err ...

  10. Build Android-x86 ICS 4 Virtualbox from Google Virtualbox Target and Intel Kernel 编译体验

    最近一直在研究android源码的编译,应该说研究的很辛苦,最难的是下源码,总是不停的断掉,最后感谢公司的高网速,找到方法后12G的源码只花了1个小时就下完了. 参考以下网址:http://softw ...

随机推荐

  1. SDWebImage 常用方法

    SDWebImage是iOS中一款处理图片的框架, 使用它提供的方法, 一句话就能让UIImageView自动去加载并显示网络图片.特别是在UITableViewCell中有UIImageView需要 ...

  2. HTML5 总结-Web存储-7

    HTML 5 Web 存储 在客户端存储数据 HTML5 提供了两种在客户端存储数据的新方法: localStorage - 没有时间限制的数据存储 sessionStorage - 针对一个 ses ...

  3. Android 开发笔记 “广播组件使用”

    在Activity中,注册广播的一个Demo. 总共分3步 第一步:定义一个BroadcastReceiver广播接收类: private BroadcastReceiver mBroadcastRe ...

  4. JavaScript时钟实例

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  5. ASP.NET 定时通知

    ASP.NET 定时通知 using System; using System.Collections.Generic; using System.Linq; using System.Web; us ...

  6. cpu有哪些架构

    原文:http://blog.csdn.net/wyzxg/article/details/5027738 author:skatetime:2009/12/17 这几天在下载RPM包的时候,总会看见 ...

  7. 基于visual Studio2013解决C语言竞赛题之0301函数求值

     题目 解决代码及点评 #include <stdio.h> #include <stdlib.h> #include <math.h> void main() ...

  8. STL set的用法

    要使用set需要事先引入一个头文件 #include<set> set是一个不允许重复的集合,如果要重复可以使用multiset. 1.set的插入[set.insert();],会返回P ...

  9. LA-3135 - Argus(优先队列)

    3135 - Argus A data stream is a real-time, continuous, ordered sequence of items. Some examples incl ...

  10. Memcached初体验及原理解说

    1.简单介绍 Memcached 是一个 高性能的 分布式 内存对象缓存系统,用于动态Web应用降低数据库负载,提升性能. 2.试用场景 1.变化频繁,具有不稳定性的数据 (比方用户在线状态.在线人数 ...