导航:首页 > 源码编译 > linux内核编译手册

linux内核编译手册

发布时间:2023-02-20 22:23:59

linux内核编译的具体操作过程及注意问题

你好,楼主:
1、配置.config文件,将你要编译的配置XXX_config准备好,使用make XXX_config来进行配置;
2、这时你就可以在内核根目录下进行make menuconfig来使用图形界面配置内核选项,配置后保存即可;
3、最后只需要使用make或者make uImage生成相应的镜像即可。
注意问题多在config这里,如果配置时报错,可尝试make clobber来清除原来的依赖关系。

⑵ Linux内核API完全参考手册的目录

前言 本书使用方法第1章 Linux内核API分析必备知识 1Linux内核编程注意事项 1本书中模块编译Makefile模板 1内核调试函数printk 2内核编译与定制 4温馨提示 10参考文献 11第2章 Linux内核模块机制API 12函数:__mole_address ( ) 12函数:__mole_ref_addr ( ) 14函数:__mole_text_address ( ) 16函数:__print_symbol ( ) 18函数:__symbol_get ( ) 20函数:__symbol_put ( ) 22函数:find_mole ( ) 24函数:find_symbol ( ) 27函数:mole_is_live ( ) 30函数:mole_put ( ) 32函数:mole_refcount ( ) 34函数:sprint_symbol ( ) 36函数:symbol_put_addr ( ) 38函数:try_mole_get ( ) 40函数:use_mole ( ) 42参考文献 44第3章 Linux进程管理内核API 45函数:__task_pid_nr_ns( ) 45函数:find_get_pid( ) 47函数:find_pid _ns( ) 49函数:find_task_by_pid_ns( ) 51函数:find_task_by_pid_type _ns( ) 53函数:find_task_by_vpid( ) 55函数:find_vpid( ) 57函数:get_pid( ) 59函数:get_task_mm( ) 60函数:is_container_init( ) 63函数:kernel_thread( ) 65函数:mmput( ) 67函数:ns_of_pid( ) 69函数:pid_nr( ) 71函数:pid_task( ) 73函数:pid_vnr( ) 75函数:put_pid( ) 77函数:task_active_pid_ns( ) 79函数:task_tgid_nr_ns( ) 81参考文献 83第4章 Linux进程调度内核API 84函数:__wake_up( ) 84函数:__wake_up_sync( ) 87函数:__wake_up_sync_key( ) 89函数:abort_exclusive_wait( ) 91函数:add_preempt_count( ) 95函数:add_wait_queue( ) 97函数:add_wait_queue_exclusive( ) 100函数:autoremove_wake_function( ) 102函数:complete( ) 106函数:complete_all( ) 108函数:complete_done( ) 111函数:current_thread_info( ) 113函数:default_wake_function( ) 115函数:do_exit( ) 118函数:finish_wait( ) 120函数:init_waitqueue_entry( ) 123函数:init_waitqueue_head( ) 125函数:interruptible_sleep_on( ) 127函数:interruptible_sleep_on_timeout( ) 130函数:preempt_notifier_register ( ) 133函数:preempt_notifier_unregister ( ) 136函数:prepare_to_wait( ) 139函数:prepare_to_wait_exclusive( ) 142函数:remove_wait_queue( ) 146函数:sched_setscheler( ) 149函数:set_cpus_allowed_ptr( ) 152函数:set_user_nice( ) 155函数:sleep_on( ) 158函数:sleep_on_timeout( ) 160函数:sub_preempt_count( ) 162函数:task_nice( ) 164函数:try_wait_for_completion( ) 166函数:wait_for_completion( ) 169函数:wait_for_completion_interruptible( ) 172函数:wait_for_completion_interruptible_ timeout( ) 175函数:wait_for_completion_killable( ) 179函数:wait_for_completion_timeout( ) 182函数:wake_up_process( ) 184函数:yield( ) 187参考文献 188第5章 Linux中断机制内核API 189函数:__set_irq_handler( ) 189函数:__tasklet_hi_schele( ) 191函数:__tasklet_schele( ) 194函数:disable_irq( ) 196函数:disable_irq_nosync( ) 196函数:disable_irq_wake( ) 198函数:enable_irq( ) 201函数:enable_irq_wake( ) 203函数:free_irq( ) 205函数:kstat_irqs_cpu( ) 207函数:remove_irq( ) 209函数:request_irq( ) 213函数:request_threaded_irq( ) 216函数:set_irq_chained_handler( ) 219函数:set_irq_chip( ) 221函数:set_irq_chip_data( ) 225函数:set_irq_data( ) 227函数:set_irq_handler( ) 229函数:set_irq_type( ) 232函数:set_irq_wake( ) 234函数:setup_irq( ) 237函数:tasklet_disable( ) 239函数:tasklet_disable_nosync( ) 241函数:tasklet_enable( ) 243函数:tasklet_hi_enable( ) 244函数:tasklet_hi_schele( ) 246函数:tasklet_init( ) 248函数:tasklet_kill( ) 250函数:tasklet_shele( ) 252函数:tasklet_trylock( ) 254函数:tasklet_unlock( ) 255参考文献 257第6章 Linux内存管理内核API 258函数:__free_pages( ) 258函数:__get_free_pages( ) 258函数:__get_vm_area( ) 260函数:__krealloc( ) 262函数:alloc_pages( ) 265函数:alloc_pages_exact( ) 268函数:alloc_vm_area( ) 270函数:do_brk( ) 272函数:do_mmap( ) 273函数:do_mmap_pgoff( ) 276函数:do_munmap( ) 279函数:find_vma( ) 281函数:find_vma_intersection( ) 284函数:free_pages( ) 286函数:free_pages_exact( ) 287函数:free_vm_area( ) 288函数:get_unmapped_area( ) 288函数:get_user_pages( ) 290函数:get_user_pages_fast( ) 292函数:get_vm_area_size( ) 294函数:get_zeroed_page( ) 295函数:kcalloc( ) 297函数:kfree( ) 299函数:kmalloc( ) 299函数:kmap_high( ) 301函数:kmem_cache_alloc( ) 303函数:kmem_cache_create( ) 305函数:kmem_cache_destroy( ) 308函数:kmem_cache_free( ) 308函数:kmem_cache_zalloc( ) 309函数:kmemp( ) 311函数:krealloc( ) 313函数:ksize( ) 315函数:kstrp( ) 318函数:kstrnp( ) 319函数:kunmap_high( ) 321函数:kzalloc( ) 321函数:memp_user( ) 323函数:mempool_alloc( ) 325函数:mempool_alloc_pages( ) 327函数:mempool_alloc_slab( ) 329函数:mempool_create( ) 331函数:mempool_create_kzalloc_pool ( ) 333函数:mempool_destroy( ) 334函数:mempool_free( ) 335函数:mempool_free_pages( ) 335函数:mempool_free_slab( ) 336函数:mempool_kfree( ) 336函数:mempool_kmalloc( ) 337函数:mempool_kzalloc( ) 339函数:mempool_resize( ) 341函数:nr_free_buffer_pages( ) 343宏:page_address( ) 345宏:page_cache_get( ) 346宏:page_cache_release( ) 348函数:page_zone( ) 349宏:probe_kernel_address( ) 352函数:probe_kernel_read( ) 354函数:probe_kernel_write( ) 355函数:vfree( ) 357函数:vma_pages( ) 358函数:vmalloc( ) 359函数:vmalloc_to_page( ) 361函数:vmalloc_to_pfn( ) 363函数:vmalloc_user( ) 365参考文献 366第7章 Linux内核定时机制API 368函数:__round_jiffies( ) 368函数:__round_jiffies_relative( ) 369函数:__round_jiffies_up( ) 371函数:__round_jiffies_up_relative( ) 373函数:__timecompare_update( ) 375函数:add_timer( ) 377函数:current_kernel_time( ) 378函数:del_timer( ) 380函数:del_timer_sync( ) 382函数:do_gettimeofday( ) 384函数:do_settimeofday( ) 386函数:get_seconds( ) 388函数:getnstimeofday( ) 390函数:init_timer( ) 391函数:init_timer_deferrable( ) 393函数:init_timer_deferrable_key( ) 395函数:init_timer_key( ) 398函数:init_timer_on_stack( ) 400函数:init_timer_on_stack_key( ) 402函数:mktime( ) 404函数:mod_timer( ) 406函数:mod_timer_pending( ) 408函数:ns_to_timespec( ) 410函数:ns_to_timeval( ) 412函数:round_jiffies( ) 414函数:round_jiffies_relative( ) 416函数:round_jiffies_up( ) 418函数:round_jiffies_up_relative( ) 420函数:set_normalized_timespec( ) 422函数:setup_timer( ) 424函数:setup_timer_key( ) 426函数:setup_timer_on_stack( ) 428函数:setup_timer_on_stack_key( ) 430函数:timecompare_offset( ) 432函数:timecompare_transform( ) 435函数:timecompare_update( ) 436函数:timer_pending( ) 439函数:timespec_add_ns( ) 441函数:timespec_compare( ) 442函数:timespec_equal( ) 444函数:timespec_sub( ) 446函数:timespec_to_ns( ) 448函数:timeval_compare( ) 450函数:timeval_to_ns( ) 452函数:try_to_del_timer_sync( ) 453参考文献 456第8章 Linux内核同步机制API 457函数:atomic_add( ) 457函数:atomic_add_negative( ) 458函数:atomic_add_return( ) 460函数:atomic_add_unless( ) 461宏:atomic_cmpxchg( ) 463函数:atomic_dec( ) 464函数:atomic_dec_and_test( ) 466函数:atomic_inc( ) 467函数:atomic_inc_and_test( ) 469宏:atomic_read( ) 470宏:atomic_set( ) 471函数:atomic_sub( ) 472函数:atomic_sub_and_test( ) 474函数:atomic_sub_return( ) 475函数:down( ) 477函数:down_interruptible( ) 479函数:down_killable( ) 481函数:down_read( ) 483函数:down_read_trylock( ) 485函数:down_timeout( ) 487函数:down_trylock( ) 489函数:down_write( ) 491函数:down_write_trylock( ) 492函数:downgrade_write( ) 494宏:init_rwsem( ) 496宏:read_lock( ) 498函数:read_seqbegin( ) 499函数:read_seqretry( ) 500宏:read_trylock( ) 503宏:read_unlock( ) 504宏:rwlock_init( ) 505函数:sema_init( ) 508宏:seqlock_init( ) 509宏:spin_can_lock( ) 511宏:spin_lock( ) 513宏:spin_lock_bh( ) 514宏:spin_lock_init ( ) 516宏:spin_lock_irq( ) 518宏:spin_lock_irqsave( ) 520宏:spin_trylock( ) 522宏:spin_unlock( ) 525宏:spin_unlock_bh( ) 526宏:spin_unlock_irq( ) 526宏:spin_unlock_irqrestore( ) 527宏:spin_unlock_wait( ) 527函数:up( ) 529函数:up_read( ) 531函数:up_write( ) 532宏:write_lock( ) 532函数:write_seqlock( ) 534函数:write_sequnlock( ) 534宏:write_trylock( ) 535宏:write_unlock( ) 537参考文献 537第9章 Linux文件系统内核API 539函数:__mnt_is_readonly( ) 539函数:current_umask( ) 541函数:d_alloc( ) 542函数:d_alloc_root( ) 544函数:d_delete( ) 547函数:d_find_alias( ) 547函数:d_invalidate( ) 549函数:d_move( ) 550函数:d_validate( ) 551函数:dput( ) 553函数:fget( ) 554函数:find_inode_number( ) 557函数:generic_fillattr( ) 559函数:get_empty_filp( ) 561函数:get_fs_type( ) 563函数:get_max_files( ) 565函数:get_super( ) 566函数:get_unused_fd( ) 569函数:have_submounts( ) 570函数:I_BDEV( ) 572函数:iget_locked( ) 573函数:inode_add_bytes( ) 575函数:inode_get_bytes( ) 576函数:inode_needs_sync( ) 578函数:inode_set_bytes( ) 580函数:inode_setattr( ) 581函数:inode_sub_bytes( ) 584函数:invalidate_inodes( ) 586函数:is_bad_inode( ) 587函数:make_bad_inode( ) 588函数:may_umount( ) 590函数:may_umount_tree( ) 591函数:mnt_pin( ) 593函数:mnt_unpin( ) 594函数:mnt_want_write( ) 596函数:new_inode( ) 596函数:notify_change( ) 598函数:put_unused_fd( ) 600函数:register_filesystem( ) 602函数:unregister_filesystem( ) 604函数:unshare_fs_struct( ) 604函数:vfs_fstat( ) 606函数:vfs_getattr( ) 608函数:vfs_statfs( ) 610参考文献 613第10章 Linux设备驱动及设备管理API 614函数:__class_create( ) 614函数:__class_register( ) 615函数:cdev_add( ) 616函数:cdev_alloc( ) 617函数:cdev_del( ) 619函数:cdev_init( ) 624宏:class_create( ) 628函数:class_destroy( ) 629宏:class_register( ) 631函数:class_unregister( ) 632函数:device_add( ) 637函数:device_create( ) 638函数: device_del( ) 640函数:device_destroy( ) 640函数:device_initialize( ) 646函数:device_register( ) 652函数:device_rename( ) 652函数:device_unregister( ) 657函数:get_device( ) 663函数:put_device( ) 663函数:register_chrdev( ) 667函数:register_keyboard_notifier( ) 668函数:unregister_chrdev( ) 669函数:unregister_keyboard_notifier( ) 675部分相关函数说明 679参考文献 679附录 Linux内核API快速检索表 680

⑶ Linux 2.6.34内核编译

Linux-2.6.34内核编译指南
2010-06-11 22:45 作者:玮琦 页面排版:玮琦

对linux内核的编译来说是每个编译者都必须掌握的一个阶段,但是编译内核是有相对一些难度的,也许你可能不知如何着手,请不必为此烦恼或者放弃,经过一些归纳和总结我编写了比较详细的步骤,从而可以为广大的爱好者以及新手能带来更好的帮助和深入的了解

一、下载内核
到www.kernel.org 下载新内核到 /usr/src
下载建议最好下载比当前已安装版本高的内核我下载的是 linux-2.6.34.tar.bz2( 原来的内核是 2.6.18-128.e15-i686)
★ 我察看当前内核的版本

[root@localhost~]#uname -a
Linux localhost.localdomain 2.6.18-128.e15-i686 #1 SMP Tue Jun 8 10:30:55 CST 2010 i686 i686 i386 GNU/Linux
然后将其解压到/usr/src目录下,使用下面的命令解压得到linux-2.6.34:
[root@localhost~]#tar -jxvf linux-2.6.34.tar.bz2
[root@localhost~]#bzip2 -d linux-2.6.34.tar.bz2

如果所下载的是.tar.gz(.tgz)文件,请使用下面的命令:

[root@localhost~]#tar -zxvf linux-2.6.34.tar.gz

为了不把原来的目录覆盖掉所以呢在当前路径下做一个链接为linux:

[root@localhost~]#ln -s /usr/src/linux-2.6.34 /usr/src/linux

二、配置内核
[root@localhost~]#make clean 清除原有不需要的模块和文件(垃息)
[root@localhost~]#make mrproper 清理源代码数
[root@localhost~]#make menuconfig 基于ncurse的图形配置界面,可以在文本下以菜单方式,进行配置。
Load an Alternate Configuration File,导入.config文件
注:内核配置有两种方法,一种是直接置入内核* ;另一种是编成模块M ;两种方法各有优点;直接编入内核的,比如设备的启动,不再需要加载模块的这一过程了;而编译成模块,则需要加载设备的内核支持的模块;但直接把所有的东西都编入内核也不是可行的,内核体积会变大,系统负载也会过重。我们编内核时最好把极为重要的编入内核;其它的如果您不明白的,最好用默认.
移动键盘上下左右键,按Enter 进入一个目录。把指针移动到Exit就退出当前目录到上级目录;
下面图形界面蓝色区域为选择区:
General setup -→
[*] Enable loadable mole support --->
-*- Enable the block layer -→
Processor type and features --->
Power management and ACPI options --->
Bus options (PCI etc.) --->
Executable file formats / Emulations --->
-*- Networking support --->
Device Drivers -→
Firmware Drivers --->
File systems --->
Kernel hacking -→
Security options --->
-*- Cryptographic API -→
[*] Virtualization -→
Library routines --->
---
Load an Alternate Configuration File
Save an Alternate Configuration File

<Select> < Exit > < Help >

修改完毕选择Save an Alternate Configuration File,然后退出配置
[root@localhost~]#cp ../kernels/2.6.18-128.e15-i686/.config /usr/src
★ 编辑配置文件.config

[root@localhost~]#vim .config

找到105行的"#CONFIG_SYSFS_DEPRECATED is not set"改为"CONFIG_SYSFS_DEPRECATED=y" 保存
假如不修改该行,在升级重新启动后会报如下的错,导致启动失败

Volume group "VolGroup00" not found

Unalbe to access resume device (/dev/VolGroup00/LogVol00)

mount: could not find filesystem '/dev/root'

setuproot:moving /dev failed: No such file or directory

setuproot:error mounting /proc: No such file or directory

setuproot:error mounting /sys: No such file or directory

switchroot: mount failed: No such file or directory

Kernel panic - not syncing:Attempted to kill init!

★ 编译开始,大概需要半个小时到一个小时的时间自己可以倒杯凉茶耐心候。

[root@localhost~]#make

★ 编译外挂模块和需要加载的模块安装

[root@localhost~]#make moles && make moles_install

这时候会出现3个警告[2]

WARNING: No mole dm-mem-cache found for kernel 2.6.34, continuing anyway

WARNING: No mole dm-message found for kernel 2.6.34, continuing anyway
WARNING: No mole dm-raid45 found for kernel 2.6.34, continuing anyway
经过测试,这3个警告不会影响内核的升级

★ 编译系统内核且生成新的内核文件

[root@localhost~]#make bzImage

[root@localhost~]#cp arch/x86/boot/bzImage /boot/vmlinuz-2.6.34

[root@localhost~]#mkinitrd /boot/initrd-2.6.34.img 2.6.34

[root@localhost~]# cp /boot/initrd-2.6.34.img /tmp

[root@localhost~]#cd /tmp/

[root@localhost~]#ls

[root@localhost~]#initrd-2.6.34.img

[root@localhost~]#mkdir newinitrd

[root@localhost~]# cd newinitrd/

[root@localhost~]# zcat ../initrd-2.6.34.img |cpio -i

[root@localhost~]# ls

bin dev etc init lib proc sbin sys sysroot

[root@localhost~]#vim init

★ 删掉重复的两行,有些情况下是没有就不要执行

echo "Loading dm-region-hash.ko mole"

insmod /lib/dm-region-hash.ko

echo "Loading dm-region-hash.ko mole"

insmod /lib/dm-region-hash.ko

★ 重新打包initrd

[root@localhost~]# find .|cpio -c -o > ../initrd

[root@localhost~]# cd ..

[root@localhost~]# gzip -9 < initrd > initrd-2.6.34.img

★ 将initrd重新复制到/boot目录下

[root@localhost~]#cp initrd-2.6.34.img /boot

★ 给 /boot/grub/grub.conf中添加一个新的启动项,

[root@localhost~]#vim /boot/grup/grup.conf

如我的 grub.conf 增加了
如下一段文字
title Red Hat(2.6.34)
root (hd0,5)
kernel /boot/vmlinuz-2.6.34 ro root=LABEL=/ rhgb quiet
initrd /boot/initrd-2.6.34.img

三、重新起动
[root@localhost~]# reboot
★ 启动成功后查看当前内核版本号

[root@localhost~]#uname -r
2.6.34
四、待解决的问题

★ Iptables启动失败

操作系统启动过程中出现下面的错误信息:

Applying ip6tables firewall rules: ip6tables-restore v1.3.5: ip6tables-restore:unable to initalizetable 'filter'

Error accurred at line: 3

Try "ip6tables-restore -h' or 'ip6tables-restore --help' for more information.

Applying iptables firewall rules: iptables-restore v1.3.5: iptables-restore:unable to initalizetable 'filter'

Error accurred at line: 3

Try "iptables-restore -h' or 'iptables-restore --help' for more information.

启动后尝试手动启动防火墙:

[root@localhost~]#service iptables status

防火墙已停

[root@localhost~]#service iptables start

正在卸载 Iiptables 模块:[确定]

应用 iptables 防火墙规则:iptables-restore v1.3.5: iptables-restore: unable to initializetable 'filter'

Error occurred at line: 3

Try `iptables-restore -h' or 'iptables-restore --help' for more information.

[失败]

★ Hidd(Bluetooth HID daemon)启动失败

Starting hidd: Can't open HIDP control socket: Address family not supported by protocol [FAILED]

[root@localhost~]# service hidd status

hidd 已死,但是 subsys 被锁

[root@localhost~]# service hidd start

正在启动 hidd:Can't open HIDP control socket: Address family not supported by protocol

⑷ linux编译内核步骤

一、准备工作
a) 首先,你要有一台PC(这不废话么^_^),装好了Linux。
b) 安装好GCC(这个指的是host gcc,用于编译生成运行于pc机程序的)、make、ncurses等工具。
c) 下载一份纯净的Linux内核源码包,并解压好。

注意,如果你是为当前PC机编译内核,最好使用相应的Linux发行版的源码包。

不过这应该也不是必须的,因为我在我的Fedora 13上(其自带的内核版本是2.6.33.3),就下载了一个标准的内核linux-2.6.32.65.tar.xz,并且顺利的编译安装成功了,上电重启都OK的。不过,我使用的.config配置文件,是Fedora 13自带内核的配置文件,即/lib/moles/`uname -r`/build/.config

d) 如果你是移植Linux到嵌入式系统,则还要再下载安装交叉编译工具链。

例如,你的目标单板CPU可能是arm或mips等cpu,则安装相应的交叉编译工具链。安装后,需要将工具链路径添加到PATH环境变量中。例如,你安装的是arm工具链,那么你在shell中执行类似如下的命令,假如有类似的输出,就说明安装好了。
[root@localhost linux-2.6.33.i686]# arm-linux-gcc --version
arm-linux-gcc (Buildroot 2010.11) 4.3.5
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for ing conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
注:arm的工具链,可以从这里下载:回复“ARM”即可查看。

二、设置编译目标

在配置或编译内核之前,首先要确定目标CPU架构,以及编译时采用什么工具链。这是最最基础的信息,首先要确定的。
如果你是为当前使用的PC机编译内核,则无须设置。
否则的话,就要明确设置。
这里以arm为例,来说明。
有两种设置方法():

a) 修改Makefile
打开内核源码根目录下的Makefile,修改如下两个Makefile变量并保存。
ARCH := arm
CROSS_COMPILE := arm-linux-

注意,这里cross_compile的设置,是假定所用的交叉工具链的gcc程序名称为arm-linux-gcc。如果实际使用的gcc名称是some-thing-else-gcc,则这里照葫芦画瓢填some-thing-else-即可。总之,要省去名称中最后的gcc那3个字母。

b) 每次执行make命令时,都通过命令行参数传入这些信息。
这其实是通过make工具的命令行参数指定变量的值。
例如
配置内核时时,使用
make ARCH=arm CROSS_COMPILE=arm-linux- menuconfig
编译内核时使用
make ARCH=arm CROSS_COMPILE=arm-linux-

注意,实际上,对于编译PC机内核的情况,虽然用户没有明确设置,但并不是这两项没有配置。因为如果用户没有设置这两项,内核源码顶层Makefile(位于源码根目录下)会通过如下方式生成这两个变量的值。
SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
-e s/arm.*/arm/ -e s/sa110/arm/ \
-e s/s390x/s390/ -e s/parisc64/parisc/ \
-e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
-e s/sh[234].*/sh/ )
ARCH?= $(SUBARCH)
CROSS_COMPILE ?=

经过上面的代码,ARCH变成了PC编译机的arch,即SUBARCH。因此,如果PC机上uname -m输出的是ix86,则ARCH的值就成了i386。

而CROSS_COMPILE的值,如果没配置,则为空字符串。这样一来所使用的工具链程序的名称,就不再有类似arm-linux-这样的前缀,就相当于使用了PC机上的gcc。

最后再多说两句,ARCH的值还需要再进一步做泛化。因为内核源码的arch目录下,不存在i386这个目录,也没有sparc64这样的目录。

因此顶层makefile中又构造了一个SRCARCH变量,通过如下代码,生成他的值。这样一来,SRCARCH变量,才最终匹配到内核源码arch目录中的某一个架构名。

SRCARCH := $(ARCH)

ifeq ($(ARCH),i386)
SRCARCH := x86
endif

ifeq ($(ARCH),x86_64)
SRCARCH := x86
endif

ifeq ($(ARCH),sparc64)
SRCARCH := sparc
endif

ifeq ($(ARCH),sh64)
SRCARCH := sh
endif

三、配置内核

内核的功能那么多,我们需要哪些部分,每个部分编译成什么形式(编进内核还是编成模块),每个部分的工作参数如何,这些都是可以配置的。因此,在开始编译之前,我们需要构建出一份配置清单,放到内核源码根目录下,命名为.config文件,然后根据此.config文件,编译出我们需要的内核。

但是,内核的配置项太多了,一个一个配,太麻烦了。而且,不同的CPU架构,所能配置的配置项集合,是不一样的。例如,某种CPU的某个功能特性要不要支持的配置项,就是与CPU架构有关的配置项。所以,内核提供了一种简单的配置方法。

以arm为例,具体做法如下。

a) 根据我们的目标CPU架构,从内核源码arch/arm/configs目录下,找一个与目标系统最接近的配置文件(例如s3c2410_defconfig),拷贝到内核源码根目录下,命名为.config。

注意,如果你是为当前PC机编译内核,最好拷贝如下文件到内核源码根目录下,做为初始配置文件。这个文件,是PC机当前运行的内核编译时使用的配置文件。
/lib/moles/`uname -r`/build/.config
这里顺便多说两句,PC机内核的配置文件,选择的功能真是多。不编不知道,一编才知道。Linux发行方这样做的目的,可能是想让所发行的Linux能够满足用户的各种需求吧。

b) 执行make menuconfig对此配置做一些需要的修改,退出时选择保存,就将新的配置更新到.config文件中了。

⑸ linux内核编译和根文件系统制作过程

内核编译:
make menuconfig配置相应的平台,然后保存退出直接make命令就可以编译了。

文件系统制作:
一般都用busybox开源软件来做,下载,解压,然后make menuconfig配置你想要的属性,然后保存退出,make就可以了,然后make install就会在目录下看到__install的目录就是你要的根文件系统目录了。

⑹ 如何配置编译在mini2440开发板上运行的linux内核

参考:http://www.it165.net/os/html/201409/9334.html

系统ubuntu12.04(非虚拟机下)
mini2440
CPU型号: S3C2440AL-40
Nanflash型号:K9F1G08
Norflash型号:SST39VF1601
LCD: 统宝 240 x 320
$: 普通账户
#:root账户
*当shell下输入路径时可使用tab键自动补全

(一)建立交叉编译环境

1.将mini2440光盘中的linux文件夹拷贝到 /home/lianghuiyong 并改名为Linux_share
(其中两个文档为我后面添加进去的)

2.Ctrl+Alt+T打开shell
3.$ su - root (切换root权限)
4.# cd /home/lianghuiyong/Linux_share
5.解压安装arm-linux-gcc编辑器
# tar xvzf arm-linux-gcc-4.4.3.tar.gz –C / //注意:C后面有个空格
执行该命令,将把 arm-linux-gcc 安装到/usr/loca/arm/4.4.3 目录。这句来自mini2440用户手册,我发现其实是安装到 /opt/FriendlyARM/toolchain/4.4.3 目录

6.# vim /root/.bashrc
7.在最后一行添加:export PATH=$PATH:/opt/FriendlyARM/toolschain/4.4.3/bin //opt/FriendlyARM/toolschain/4.4.3/bin 为arm-linux-gcc 环境变量
:wq保存退出。
# source ~/.bashrc
8.# sudo gedit /etc/environment
games后面添加标记部分

9.# arm-linux-gcc -v //gcc后面有空格

测试hello.c(这是在安装了第二部分的linux示例程序才有examples/hello目录)
# cd /opt/FriendlyARM/mini2440/examples/hello
# arm-linux-gcc -o hello hello.c
# ./hello

(二)安装源代码及其他工具
创建工作目录(以下都为root环境下):
# mkdir -p /opt/FriendlyARM/mini2440

1>>解压安装linux内核源代码
# cd /opt/FriendlyARM/mini2440
# tar xvzf /home/lianghuiyong/Linux_share/linux-2.6.32.2-mini2440-20100106.tar.gz

2>>解压安装嵌入式图形系统qtopia源代码
# cd /opt/FriendlyARM/mini2440
# tar xvzf /home/lianghuiyong/Linux_share/x86-qtopia.tgz
# tar xvzf /home/lianghuiyong/Linux_share/arm-qtopia.tgz

3>>解压安装嵌入式图形系统 QtE-4.6.1 源代码
# cd /opt/FriendlyARM/mini2440
# tar xvzf /home/lianghuiyong/Linux_share/arm-qte-4.6.3-20100802.tar.gz

4>>解压安装busybox 源代码
# cd /opt/FriendlyARM/mini2440
# tar xvzf /home/lianghuiyong/Linux_share/busybox-1.13.3-mini2440.tgz

5>>解压安装 Linux 示例程序
# cd /opt/FriendlyARM/mini2440
# tar xvzf /home/lianghuiyong/Linux_share/examples-20100108.tgz

6>>解压安装 vboot 源代码
# cd /opt/FriendlyARM/mini2440
# tar xvzf /home/lianghuiyong/Linux_share/vboot-src-20100106.tar.gz

7>>解压安装 bootloader 源代码
# cd /opt/FriendlyARM/mini2440
# tar xvzf /home/lianghuiyong/Linux_share/bootloader.tgz

8>>解压创建目标文件系统
# cd /opt/FriendlyARM/mini2440
#tar xvzf /home/lianghuiyong/Linux_share/rootfs_qtopia_qt4-20100816.tar.gz

9>>解压安装目标文件系统映象制作工具 mkyaffs2image
# cd /opt/FriendlyARM/mini2440
# tar xvzf /home/lianghuiyong/Linux_share/mkyaffs2image.tgz –C /

10>>解压安装LogoMaker
# cd /opt/FriendlyARM/mini2440
# tar xvzf /home/lianghuiyong/Linux_share/logomaker.tgz –C /

(三)定制linux内核及制作文件系统

config_mini2440_x35 – 适用于 Sony 3.5” LCD 的内核配置文件
config_mini2440_t35 – 适用于统宝 3.5” LCD 的内核配置文件
config_mini2440_l80 – 适用于 Sharp 8” LCD(或兼容)的内核配置文件
config_mini2440_n35 – 适用于 NEC3.5” LCD 的内核配置文件
config_mini2440_h43 – 适用于 4.3” LCD 的内核配置文件
config_mini2440_a70 – 适用于群创 7” LCD 的内核配置文件
config_mini2440_vga1024x768 – 适用于 VGA 显示输出(分辨率 1024x768)模块的内核
配置文件

1.配置缺省文件config_t35 (统宝240x320)

# cd /opt/FriendlyARM/mini2440/linux-2.6.32.2
# cp config_mini2440_t35 .config
# make menuconfig
出现界面
不做更改,exit退出。这样做是为了生成相应配置(统宝240x320)的头文件。

2.编译内核

在/opt/FriendlyARM/mini2440/linux-2.6.32.2 目录下编译内核
#make zImage
编译结束后,会在 arch/arm/boot 目录下生成 linux 内核映象文件:zImage(zImage 可下载到开发板测试)

3.定制linux内核(根据用户手册来走一遍)

# cd /opt/FriendlyARM/mini2440/linux-2.6.32.2
# make menuconfig
出现配置选项:

3.1配置cpu
主菜单-->System --> Type S3C2400 Machines --> FriendlyARM Mini2440 development board
3.2配置lcd驱动
主菜单-->Device Drivers-->Graphics support-->Support for frame buffer devices-->Backlight-->LCD select-->3.5 inch 240x320 Toppoly LCD

3.3配置触摸屏
主菜单-->Device Drivers-->Input device support-->Touchscreens-->Samsung s3c24410 touchscreen input driver

3.4配置usb鼠标和键盘
主菜单-->Device Drivers-->hid devices-->USB Human interface Device

3.5 配置优盘
主菜单-->Device Drivers-->SCSI device support--> SCSI disk

3.6配置万能驱动USB摄像头
主菜单-->Device Drivers-->Multimedia devices-->Video capture adapters -->V4L USB devices-->GSPCA based webcams-->ALi USB m 5602 Camera Driver

3.7 配置CMOS摄像头驱动
主菜单-->Device Drivers-->Multimedia devices-->Video capture adapters-->OV9650 on the s3c2440 driver

3.8配置网卡驱动
主菜单-->Netwoking support-->Networking options -->选择Unix和TCP/IP

主菜单-->Device Drivers-->Network device support-->Ethernet (10 or 100Mbit)-->
选择 <*> Generic Media Independent Interface device support
<*> DM9000 support

3.9 配置USB无线网卡驱动
主菜单-->Netwoking support-->wireless-->IEEE 802.11

主菜单-->Device Drivers-->Netwoking device support-->wireless LAN-->Wireless LAN(IEEE 802.11)-->Ralink driver support-->

3.10 配置音频驱动
主菜单-->Device Drivers-->Sound card supprt-->OSS Mixer API -->ALSA for Soc audio support-->SoC Audio for the samsung S3Cxxxx Chips

3.11 配置SD/MMC卡驱动
主菜单-->Device Drivers-->MMC/SD/SDIO card-->samsung S3C SD/MMC card

3.12 配置看门狗驱动支持
主菜单-->Device Drivers-->Watchdog Timer-->s3c2440 Watchdog

3.13 配置LED驱动
主菜单-->Device Drivers-->Character devices-->LED support for Mini2440

3.14 配置按键驱动
主菜单-->Device Drivers-->Character devices-->Buttons driver

3.15 配置PWM控制蜂鸣器驱动
主菜单-->Device Drivers-->Character devices-->buzzer driver for

3.16 配置AD转换驱动
主菜单-->Device Drivers-->Character devices-->ADC driver for

3.17 配置串口驱动
主菜单-->Device Drivers-->Character devices-->Serial drivers-->samsung S3C2440/S3C2442

3.18 如何配置RTC实时时钟驱动
主菜单-->Device Drivers-->Real Time Clock-->samsung S3C series SoC RTC

3.19 配置I2C-EEPROM驱动支持
主菜单-->Device Drivers-->I2C support -->I2C Hardware Bus support-->S3C2410 I2C Driver

3.20 配置yaff2s文件系统的支持
主菜单-->Device Drivers-->MTD-->NAND Device Support -->NAND FLASH Support
主菜单-->File systems-->Miscellaneous filesystems -->YAFFS2 file system support

3.21 配置EXT2/VFAT/ NFS等文件系统
主菜单-->File systems-->Network File Systems -->root file system on NFS

为了支持FAT32 文件系统.
主菜单-->File systems-->DOS/FAT/NT Filesystems -->VFAT (windows-95) fs support

关于mini2440 linux内核裁剪到此为止,退出后有一个是否保存提示,选择保存!

3.22 制作Linux logo

本来想使用Logomaker,结果生成的图片都是无数据的,这可能和系统内一些参数有关
使用命令方式制作logo:
在图片(open_show.png)目录下
# pngtopnm open_show.png > temp.ppm
# ppmquant 224 temp.ppm >temp2.ppm
# pnmnoraw temp2.ppm > logo.ppm
将目录下生成的logo.ppm改成linux_logo_clut224.ppm,替代linux2.6.32.2/drivers/video/logo 目录下的同名文件

⑺ 如何编译Linux内核

编译linux内核步骤:
1、安装内核
如果内核已经安装(/usr/src/目录有linux子目录),跳过。如果没有安装,在光驱中放入linux安装光盘,找到kernel-source-2.xx.xx.rpm文件(xx代表数字,表示内核的版本号),比如RedHat linux的RPMS目录是/RedHat/RPMS/目录,然后使用命令rpm -ivh kernel-source-2.xx.xx.rpm安装内核。如果没有安装盘,可以去各linux厂家站点或者www.kernel.org下载。
2、清除从前编译内核时残留的.o 文件和不必要的关联
cd /usr/src/linux
make mrproper
3、配置内核,修改相关参数,请参考其他资料
在图形界面下,make xconfig;字符界面下,make menuconfig。在内核配置菜单中正确设置个内核选项,保存退出
4、正确设置关联文件
make dep
5、编译内核
对于大内核(比如需要SCSI支持),make bzImage
对于小内核,make zImage
6、编译模块
make moles
7、安装模块
make moles_install
8、使用新内核
把/usr/src/linux/arch/i386/boot/目录内新生成的内核文件bzImage/zImage拷贝到/boot目录,然后修改/etc/lilo.conf文件,加一个启动选项,使用新内核bzImage/zImage启动。格式如下:
boot=/dev/hda
map=/boot/map
install=/boot/boot.b
prompt
timeout=50
linear
default=linux-new ### 告诉lilo缺省使用新内核启动linux ###
append="mem=256M"
image=/boot/vmlinuz-2.2.14-5.0
label=linux
read-only
root=/dev/hda5
image=/boot/bzImage(zImage)
label=linux-new
read-only
root=/dev/hda5
保留旧有的启动选项可以保证新内核不能引导的情况,还可以进入linux进行其他操作。保存退出后,不要忘记了最重要的一步,运行/sbin/lilo,使修改生效。
9、重新生成ram磁盘
如果您的系统中的/etc/lilo.conf没有使用了ram磁盘选项initrd,略过。如果您的系统中的/etc/lilo.conf使用了ram磁盘选项initrd,使用mkinitrd initrd-内核版本号,内核版本号命令重新生成ram磁盘文件,例如我的Redhat 6.2:
mkinitrd initrd-2.2.14-5.0 2.2.14-5.0
之后把/etc/lilo.conf中的initrd指向新生成的initrd-2.2.14-5.0文件:
initrd=/boot/initrd-2.2.14-5.0
ram磁盘能使系统性能尽可能的优化,具体参考/usr/src/linux/Documents/initrd.txt文件
10、重新启动,OK!

⑻ 编译Linux内核

Kernel packaging:
rpm-pkg - Build both source and binary RPM kernel packages
binrpm-pkg - Build only the binary kernel package
deb-pkg - Build the kernel as an deb package
tar-pkg - Build the kernel as an uncompressed tarball
targz-pkg - Build the kernel as a gzip compressed tarball
tarbz2-pkg - Build the kernel as a bzip2 compressed tarball

下面这些包装完后,连GLIBC都能正常编译,编个内核应该是小case了,当然,这些包中有一些内核是不需要的,不过装上也没问题
sudo apt-get install flex bison autoconf texinfo build-essential libncurses5-dev gawk

如果你不是x86下的,还需要配cross_compile,和arch

确保你能够正确编译linux内核,编好你的bzImage之后,然后用make deb-pkg即可。

具体的可以怎么编
在源代码目录下,打一个make help就行了

⑼ Linux内核配置与编译相关流程

linux内核配置与编译相关流程1、清除临时文件、中间文件和配置文件
make
clean
不删除配置文件。
make
mrproper
make
distclean
删除编辑的backup文件、补丁文件等2、确定目标系统的软硬件配置情况,比如CPU的类型,网卡的型号,所需要支持的网络协议。3、使用命令配置内核
make
config
基于文本模式的交互配置。
make
menuconfig
基于文本模式的菜单配置。
make
oldconfig
使用已有的配置文件(.config),但是会询问新增的配置选项。
make
xconfig
图形化的配置(需要安装图形化系统)。4、编译内核
make
zImage
make
bzImage
区别:在X86平台上,zImage只能用于小雨512k内核。如果需要获取详细编译信息,则在后面加上V=1.
编译好的内核位于arch/<cpu>/boot/目录下。
5、编译内核模块
make
moes
6、安装内核模块
make
moes_install
将编译好的内核模块从内核源代码目录到/lib/moes下。7、制作
init
ramdisk
mkinitrd
$initrd-$version
-$version内核安装(X86)1、cp
arch/X86/boot/bzImage
/boot/vmliuz
-$version2、cp
$initrd
/boot/3、修改etc/grub.conf

/etc/lilo.conf$version为所编译的内核版本号。

阅读全文

与linux内核编译手册相关的资料

热点内容
如何查看服务器映射的外网地址 浏览:975
图片刺绣算法 浏览:661
阿里云服务器没有实例 浏览:601
绵阳有没有什么app 浏览:844
怎么用游侠映射服务器 浏览:917
为什么无意下载的app无法删除 浏览:304
word2007打开pdf 浏览:117
php正则class 浏览:736
怎么在文件夹查找一堆文件 浏览:543
核酸报告用什么app 浏览:791
u8怎么ping通服务器地址 浏览:994
安卓什么手机支持背部轻敲调出健康码 浏览:870
程序员抽奖排行 浏览:744
扭蛋人生安卓如何下载 浏览:724
什么app文档资源多好 浏览:924
黑马程序员APP 浏览:148
掌阅小说是哪个app 浏览:47
如何把u盘的软件安装到安卓机 浏览:1000
php跑在什么服务器 浏览:126
编译器怎么跳转到下一行 浏览:454