跳到主要內容

發表文章

目前顯示的是有「Linux Kernel」標籤的文章

Show Physical Memory Address of the kernel module

Introduction 我希望透過寫一個kernel module,讓user在user space去顯示kernel space某個變數值的實體記憶體位置與數值。 Note: 由於這程式僅用於測試,因此不會特別去考慮更好的寫法;會補充這點是由於看書有看到更好的寫法。 How to? Source Code 包含以下內容: 在init時,我建立一個字元裝置用以接受user space的操作,並初始hello_buf。 當使用者執行cat /dev/hello時,會觸發file_operations的open與release,這裡我只實做open的對應行為: dump_physical_address。 dump_physical_address則是取得hello_buf的實體記憶體位置並dump出來。 exit就是釋放所有用到的資源。 #include <linux/init.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/string.h> #include <asm/io.h> #include <linux/fs.h>   MODULE_LICENSE ( "Dual BSD/GPL" ) ;   static char * hello_buf ;   static int dump_physical_address ( struct file * filp, struct vm_area_struct * vma ) { unsigned long virt_addr ; phys_addr_t phy_addr ; printk ( "damn \n " ) ; virt_addr = ( unsigned long ) hello_buf ; printk ( "Hello kernel: %lx, value: %c \n " , virt_addr, hello_buf [ 0 ] ) ; phy_addr = virt_to_phys ( ( void * )...

Build ixgvevf kernel module on CentOS6.7

確認環境 執行uname -a確認kernel版本,CentOS6.7如下: 2.6.32- 573 .el6.x86_64 安裝kernel-headers與kernel-devel 下載kernel-headers與kernel-devel rpm:(從此 link 找尋) kernel-devel-2.6.32- 573 .el6.centos.x86_64.rpm kernel-headers-2.6.32- 573 .el6.centos.x86_64.rpm 在build system安裝這兩個rpm: rpm -ivh kernel-devel-2.6.32- 573 .el6.centos.x86_64.rpm rpm -ivh kernel-headers-2.6.32- 573 .el6.centos.x86_64.rpm 安裝之後,要執行以下指令讓make能夠找到header code: ln -s / usr / src / kernels / 2.6.32- 573 .el6.centos.x86_64 / usr / src / linux 安裝gcc/rpm-build/make gcc與make為編譯用,rpm-build為產生kernel module rpm檔用;假如你要在其他機器透過rpm安裝此driver,可build rpm出來使用: yum install rpm-build gcc make 下載對應驅動 到Intel Download Center搜尋你要的驅動程式並下載: link 。我所下載版本為3.1.2,檔案名稱為ixgbevf-3.1.2.tar.gz。 編譯與打包 編譯 tar zxvf ixgbevf-3.1.2.tar.gz cd ixgbevf-3.1.2 / src make 如果沒意外,會產生ixgbevf.ko;可以透過insmod ixgbevf.ko載入它。 打包 這是從driver包內README看到的方法: rpmbuild -tb ixgbevf-3.1.2.tar.gz 在執行完指令且沒問題後,可以在以下位置找到你的東西: / root / rpmbuild / RPMS / x84_64 / ixgbevf-3.1.2- 1 .x86_64.rpm 如果安裝的系統...

Trace KConfig - Plug and Play support選項不能選

Problem 這問題的發生一開始是因為想存取某個isa io port卻出現ioperm的錯誤。透過cat /proc/ioports卻發現那些port並沒被linux找到。比較其它可行的機器後,發現這台搭配2.6.9 kernel的RHEL4u8(真的會有人用嗎?)根本沒找到任何pnp裝置。 我想: 那我自己去enable CONFIG_PNP吧! 不幸滴,透過make menuconfig指令卻無法對Device Drivers>Plug and Play support做選擇,這到底是怎回事? How to? 於是我開始Trace Makefile與Kconfig,看看是怎麼回事。首先至kernel source root下,看看drivers/pnp/Kconfig: default為y這行是我加的,只是想確認是否能讓.confg產生CONFIG_PNP=y的設定。但事實上,CONFIG_PNP是相依於CONFIG_ISA(CONFIG_PNP與CONFIG_ISAPNP都會在pnp.h或isapnp.h中被使用到)。接著我就開始trace CONFIG_ISA的定義,CONFIG_ISA的宣告在arch下。我關注的是arch/i386與arch/x84_64下的Kconfig。首先是arch/i386/Kconfig,看起來宣告正常,除了在VOYAGER、VISWS、XEN這三種版本的kernel上: 接著看64位元版本,arch/x86_64/Kconfig: 一開始註解就說明64位元不支援ISA,如果要enable必須自己去修kernel driver,這就是root cause。最後當然是請User升級kernel拉。 友藏內心獨白: linux的portable就是那坨config。

如何取得CentOS6.0 kernel完整source code?

How to?在我們使用yum install kernel-headers kernel-devel之後,還是無法看到所有的kernel source code。根據Reference 1的文章,首先到http://vault.centos.org/下載對應的kernel-source rpm。要取得CentOS6.0的就要下載http://vault.centos.org/6.0/updates/SRPMS/kernel-2.6.32-71.29.1.el6.src.rpm。 執行以下shell script去build rpm: yum install rpm-build redhat-rpm-config unifdef   wget http: // vault.centos.org / 6.0 / updates / SRPMS / kernel-2.6.32-71.29.1.el6.src.rpm rpm -i kernel-2.6.32-71.29.1.el6.src.rpm 2 >& 1 | grep -v mockb   cd ~ / rpmbuild / SPECS # kernel.spec according to the filename. rpmbuild -bp --target = ` uname -m ` kernel.spec 2 > prep-err.log | tee prep-out.log 可以去cat prep-err.log確認缺少的package並安裝在重新build。 經過漫長的等待,執行ls ~/rpmbuild/BUILD/kernel-2.6.32-71.29.1.el6/就可以看到你想要的東西了!