顯示具有 driver 標籤的文章。 顯示所有文章
顯示具有 driver 標籤的文章。 顯示所有文章

星期四, 9月 10, 2009

Study LDD3 on Debian

在 Debian 上建立學習 Linux Device Driver 的環境

aptitude install build-essential
aptitude install linux-headers-2.6.30-1-686
aptitude install linux-headers-2.6.30-1-common
aptitude install linux-kbuild-2.6.30
如此會在 /usr/src 安裝好編繹 kernel module 的環境

接著按照 LLD3 上寫的第一個範例 hello.c
#include
#include
MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void)
{
printk(KERN_ALERT "Hello, world\n");
return 0;
}

static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, cruel world\n");
}

module_init(hello_init);
module_exit(hello_exit);
為它編寫一個 Makefile
ifneq ($(KERNELRELEASE),)
obj-m := hello.o
else
KERNELDIR ?= /usr/src/linux
PWD := $(shell pwd)
RM = rm -rf
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif
clean:
$(RM) *.ko *.o *.mod.c .*.cmd Module.* modules.* .tmp_versions
接著下 make 就可以編出 hello.ko 了 :D

星期六, 12月 06, 2008

ati2dvag problem

遇到 Windows XP 藍白畫面上面只看得懂 ati2dvag ,目前一般解決方法有兩個:

  • 重新安裝 ATI driver。啟動 Windows 於安全模式 (在 Windows 顯示前按下 F8),到 Windows 新增移除程式中移除 ATI 相關的所有東西。移除 DAO/MDAC 元件。你可以到 ATI 的網站下載 ATI 的移除工具來做這件事。完整的移除程序在 ATI 的網站的這裡
  • 到控制台 > 系統 > 硬體 > 裝置管理員 > 系統裝置 > PCI standard PCI-to-PCI bridge,按右鍵,選,更新驅動程式 > 從清單或特殊位置安裝 > 不要搜尋,我將選擇要安裝的驅動程式 > PCI standard PCI-to-PCI bridge。

參考來源:
http://www.modernstreet.com/general/ati2dvag-problem/

Ati2dvag problem

If you ever experienced your computer freezing/crashing without warning all of a sudden, with a blue screen on your monitor saying your computer was “caught in an infinite loop”, plus there is a mention of the word - “ati2dvag”, it means your computer has caught the ati2dvag bug. This bug seems to affect ATI video cards.

I was having this problem on and off since last year, but it got really bad a few days ago. If you have not yet experienced this problem, then keep your fingers crossed and consider yourself fortunate, because this is a REALLY annoying problem that does not have a sure solution or cure, and can give you enough fits to trash your old faithful PC.

The usual symptoms of the ati2dvag problem are:

  • PC crashes without warning, sometimes the display shows weird patterns before the crash.
  • Resolution may revert to the lowest resolution settings upon restarting your PC.
  • The CPU temperature may shoot up prior to crashing.
  • PC may not be able to reboot back after the crash, unless you turn off the power supply unit of your PC and switch it back on again.
  • Your PC tells you (sometimes only) that the ati2dvag driver has failed to function.

This is a universal problem afflicting thousands of PCs worldwide and can occur in totally new or old computers; it doesn’t discriminate. Imagine the frustration of buying a new PC only to have it crash on you after a few weeks and thereafter.

There have been many hypothesis’ postulated. Some say it is a very stealthy virus, some say it is an incompatibility with Windows XP SP2 and ATI, some say it is a problem with the hardware acceleration settings in the ATI graphic card, others say it is a problem within Windows XP itself…etc.

The 2 most common “solutions” are:

  • Reinstall the ATI driver. You are advised to launch Windows in Safe Mode (press F8 before Windows boots), go to Windows Add/Remove programs and uninstall everything ATI. Remove the DAO/MDAC component as well. You can use the ATI removal tool utility which can be downloaded from the ATI website. The complete set of instructions on removing ATI can be found here on the ATI website.
  • Go to System Devices in My Computer > Properties > Hardware, and locate the option, PCI standard PCI-to-PCI bridge. This could under other names on your PC, so contact your PC vendor if you’re unsure. Right click, and select the “update driver” option. Manually search and install the PCI standard PCI-to-PCI bridge.

ATI and Microsoft have never issued public statements regarding this ati2dvag issue up till this day. There is no definitive prevention or cure of this problem also. What works for some may not work for others….I’ve reinstalled the drivers and now it only crashes while I’m playing some graphics intensive game.

If you think this is a trivial problem, look at a forum thread on this problem which has been running for 3 years with no “real” fix to date. It’s about time ATI and Microsoft consider this problem serious enough to warrant a concerted investigation into why this problem happens, and come out with the best possible fix.

星期三, 3月 12, 2008

O’Reilly, “Linux Device Drivers” 的讀法

以下摘自 Jollen 的 Howto Learn Linux Device Driver

O’Reilly, “Linux Device Drivers” 的讀法

如果您是Linux驅動程式的初學者,想要以這本書來自學驅動程式,又要在最短時間內掌握整個Linux驅動程式的精神,那麼有幾個方向提供您做參考:
  • 不要依照章節順序來閱讀
  • 不要地毯式的閱讀(即:不要依照章節與段落順序)
這本書的觀念解釋的非常清楚,但是最主要的Linux驅動程式觀念都在字元型驅動程式的章節裡,因此依照字元型驅動程式的主題來閱讀會比較適當。建議順序如下:

  1. Virtual File System (VFS)
  2. 'open' and 'release' system calls
  3. 'open' and 'release' driver function
  4. Wait Queues
  5. Blocking and Nonblocking read/write
  6. kmalloc(), copy_to_user(), copy_from_user()
  7. I/O ports
  8. ioctl()
  9. 'ioctl' driver function
  10. Reentrant codes (function)
  11. Semaphore
  12. Kernel Timer, Asynchronous Notification
  13. Pre-Defined Task Queues
  14. User-Defined Task Queues
  15. Writing an Interrupt Handler
  16. PCI Device Driver
  17. Spinlocks
  18. Bottom-half and Tasklets

此建議順序即是Jollen教育訓練課程所使用的投影片主題順序,自學的朋友,應該參考此建議順序,規劃一套屬於自己的閱讀計畫,如此便能加速學習Linux驅動程式。


結語
我們條列說明Linux驅動程式的核心觀念,以利讀者掌握學習方向:

  1. Device file 是user application與Linux驅動程式溝通的媒介。
  2. Device file 有一個不重覆的識別號碼,稱為major number,並有自己的minor number用來表示自己的子裝置。
  3. 不同的Linux驅動程式,均「支援」一個device file;更精確的說法是,不同的Linux驅動程式,均「對應」一個「major number」。
  4. Device file 即是VFS層。
  5. Linux驅動程式的核心為file operations,此即「Linux 驅動程式物件」。
  6. User application透過system call與device file 來與驅動程式溝通,user application必須先呼叫open system call來「開啟驅動程式」。
  7. 不同的system call C函數,會透過Linux kernel對應,並由Linux kernel callback驅動程式裡相對應的 system call實作函數。
  8. 驅動程式裡個別的system call實作函數,是由file operations所定義的。
  9. File operations 即struct file_operations,struct file_operations定義system call的名稱與實作函數的對應,此對應關係使用「函數指標」來實作。