當前位置: 首頁 > 工業電子產品 > 其他電子產品 > 開發板,套件,編程器 > 開發板
發布日期:2022-10-14 點擊率:40
For English speaking readers, please visit: https://www.witimes.com/openwrt-porting-art-en/
相信本站的大部分讀者都知道OpenWRT與ART:OpenWRT是一款基于Linux的開源無線路由器系統,目前廣泛應用于很多廠商的無線設備;ART是Atheros Radio Test的簡寫,用于測試各種基于Qualcomm Atheros芯片設備的射頻指標。近期有朋友尋求OpenWRT中的ART驅動程序, 筆者費了九牛二虎之力終于將其搞定,在此做簡要總結,以便后續查閱。
1. 基于已有經驗,移植ART驅動程序必須指定相應的內核路徑與Toolchain路徑,修改makefile.artmod如下
KDIR := /home/tom/openwrt/trunk/build_dir/target-mips_34kc_uClibc-0.9.33.2/linux-ar71xx_generic/linux-3.18.7 PWD := $(shell pwd) ROOTDIR := $(PWD)/modules # Default architecture is MIPS ARC :=mips CROSS_CC :=/home/tom/openwrt/trunk/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-uclibc-
2. 未作任何代碼的更改情況下,開始編譯。
3. 出現error: unknown field 'ioctl' specified in initializer,此前在移植i.MX6 ART驅動程序時已經遇到過類似問題,在https://www.witimes.com/imx6-porting-art/一文中有介紹,修改modules/dk_func.c中dk_fops結構體中的ioctl為compat_ioctl,再次編譯未報出ioctl的錯誤。
3. 出現error: 'SPIN_LOCK_UNLOCKED' undeclared here (not in a function),修改modules/dk_event.c中的
spinlock_t driver_lock = SPIN_LOCK_UNLOCKED;
為
DEFINE_SPINLOCK(driver_lock);
4. 再次編譯,順利通過,在modules目錄下出現了art.ko。
5. 將art.ko上傳至web服務器,并使用wget命令下載至DUT中,并使用insmod art.ko命令插入內核模塊并運行nart.out,未出現任何異常。
6. 使用artgui Load DUT,出現如下錯誤:
deviceInit devIndex=0 device_fn=0 pdkInfo=0 Opening device /dev/dk0 Error: get version ioctl failed ! < 6006 ERROR Anwi driver load error. < 7502 CONTROL OFF < 7504 INFO |set|devid|| < 7504 INFO |set|mac|| < 7504 INFO |set|customer|| < 7506 CONTROL DONE load devid=-1; caldata=auto;
截圖如下
7. 又出現了可怕的錯誤“Error: get version ioctl failed !”,這個錯誤曾在我移植i.MX6 ART驅動程序時折磨了我很多天,同樣記錄在https://www.witimes.com/imx6-porting-art/一文中,當時更換為高版本ART后問題得到解決,然而這一次我采用同樣方法卻完全不奏效。既然無法避開,那就正面面對,徹查此問題。
8. 查看高版本ART代碼modules/dk_func.c中的dk_fops結構體,如下
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,31) static long dk_ioctl_new(struct file *file, unsigned int cmd, unsigned long arg) { struct inode *inode = file->f_path.dentry->d_inode; long ret; ret = dk_ioctl(inode, file, cmd, arg); return ret; } #endif
發現其定義了一個新的ioctl,在內核版本高于2.6.31時生效。
9. 此處引用自:http://blog.csdn.net/cbl709/article/details/7295772
今天調一個程序調了半天,發現應用程序的ioctl的cmd參數傳送到驅動程序的ioctl發生改變。而根據《Linux設備驅動》這個cmd應該是不變的。因為在Kernel 2.6.36 中已經完全刪除了struct file_operations 中的ioctl 函數指針,取而代之的是unlocked_ioctl ,所以我懷疑二者是不是兼容的。上網查了一些資料,很多文章只是泛泛談了一下,說在應用程序中ioctl是兼容的,不必變化。而在驅動程序中這個指針函數變了之后最大的影響是參數中少了inode ,所以應用程序ioctl是兼容的,但驅動程序中我們的ioctl函數必須變化,否則就會發生cmd參數的變化。
10. 仿照這段代碼,將低版本ART代碼modules/dk_func.c中的dk_fops結構體作出修改,如下
static long dk_ioctl_new(struct file *file, unsigned int cmd, unsigned long arg) { struct inode *inode = file->f_path.dentry->d_inode; long ret; ret = dk_ioctl(inode, file, cmd, arg); return ret; } static struct file_operations dk_fops = { owner: THIS_MODULE, open: dk_open, release: dk_release, mmap: dk_mmap, unlocked_ioctl: dk_ioctl_new };
11. 再次編譯,下載至DUT,并使用artgui Load DUT,一切正常。
下一篇: PLC、DCS、FCS三大控
上一篇: Allegro PCB設計模板