導航:首頁 > 源碼編譯 > 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內核編譯手冊相關的資料

熱點內容
趣質貓app是什麼 瀏覽:59
皮帶壓縮機經常吸不上 瀏覽:201
西部隨行版怎樣加密 瀏覽:996
釘釘上如何壓縮圖片 瀏覽:924
cad輸入命令不顯示窗口 瀏覽:618
小米視頻加密之後怎麼看 瀏覽:76
超級程序員劉芳閱讀 瀏覽:832
顧家九爺在哪個app 瀏覽:820
我的世界怎麼在聯機大廳做伺服器 瀏覽:290
分手程序員 瀏覽:447
php將html導出為word 瀏覽:801
騰訊加密視頻能破解嗎 瀏覽:1007
反編譯後導入eclipse 瀏覽:948
買阿里雲伺服器有郵箱嗎 瀏覽:825
pdf卡片2004 瀏覽:309
e算量加密鎖檢測不到 瀏覽:777
python串口讀取數據類型 瀏覽:760
17年新款寶來壓縮機不跳 瀏覽:107
王者打著為什麼伺服器升級 瀏覽:847
aliyunlinux安裝 瀏覽:981