Linux驅動之Ubuntu下下載內核源碼——學習筆記(7)

PC操作系統:Ubuntu 16.04 LTS
內核版本:4.15.0-45-generic
編譯器:gcc 7.5.0

主要是方便驗證一些驅動的小問題。


一、下載內核源碼

1、查看Ubuntu當前所使用的內核版本

執行命令 uname -r 可以查詢。
在這裏插入圖片描述

2、查看一下可以下載的內核源碼版本

執行命令 apt-cache search linux-source 可以查詢。
在這裏插入圖片描述
可以看到有4.15.0版本的源碼可以下。

3、下載源碼及解壓

(1)執行命令 sudo apt-get install linux-source-4.15.0 進行下載。

在這裏插入圖片描述

(2)源碼會被下載在 /usr/src/ 目錄下。

在這裏插入圖片描述

(3)解壓到指定目錄

這裏我解壓到自己的 home 目錄。
在這裏插入圖片描述
在這裏插入圖片描述

4、配置及編譯

(1)配置
  • 運行 make menuconfig 命令,提示需要安裝 ncurses 然後再重新嘗試。
hrx@hrx-pc:~/linux-source-4.15.0$ make menuconfig
  HOSTCC  scripts/basic/fixdep
 *** Unable to find the ncurses libraries or the
 *** required header files.
 *** 'make menuconfig' requires the ncurses libraries.
 *** 
 *** Install ncurses (ncurses-devel) and try again.
 *** 
scripts/kconfig/Makefile:202: recipe for target 'scripts/kconfig/dochecklxdialog' failed
make[1]: *** [scripts/kconfig/dochecklxdialog] Error 1
Makefile:547: recipe for target 'menuconfig' failed
make: *** [menuconfig] Error 2

  • 安裝 ncurses 。執行 sudo apt-get install ncurses-dev 命令之後再次 make menuconfig 。出現配置界面則一切順利。
    在這裏插入圖片描述
  • 根據需要進行內核配置,配置完選擇 Save 然後默認將配置存爲 .config 。然後選擇 Exit 退出配置界面。
(2)編譯
  • 可以運行 make help 查看可以進行 make 的命令以及作用。
  • 編譯內核使用 make bzImage ,在 make help 可以查得到。
    在這裏插入圖片描述
  • 根據提示安裝 libelf-devlibssl-dev,然後再 make bzImage 生成內核文件。
sudo apt-get install libelf-dev libssl-dev

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章