如果時間用不完,或是懶得架Cross Compiler環境的話,可以試試用網樂通編譯驅動,不過缺點是編譯速度有點慢,只是小驅動的話其實只需要在網樂通上面直接編譯就可以了~
查詢核心版本並下載Kernel原始碼
首先需要知道核心版本為多少,並且將原始碼放入裡面才能順利編譯:
root@debian-wheezy-sh4:~# <span style="color: #ff0000;">uname -r</span><br /> <span style="color: #ff0000;"> 2.6.32.59_stm24_0211-PDK7105-32BITS</span><br />
由此可知~網樂通的Kernel版本名稱是2.6.32.59_stm24_0211-PDK7105-32BITS
,所以就在/usr/src/
放入原始碼並且資料夾名稱改為2.6.32.59_stm24_0211-PDK7105-32BITS
root@debian-wheezy-sh4:~# <span style="color: #ff0000;">cd /usr/src/</span><br /> root@debian-wheezy-sh4:/usr/src# <span style="color: #ff0000;">wget https://github.com/suzuke/kernel-pdk7105/archive/master.zip</span><br /> root@debian-wheezy-sh4:/usr/src# <span style="color: #ff0000;">unzip master.zip #如果找不到unzip請自行安裝:apt-get install unzip</span><br /> root@debian-wheezy-sh4:/usr/src# <span style="color: #ff0000;">mv kernel-pdk7105-master 2.6.32.59_stm24_0211-PDK7105-32BITS #更名資料夾</span>
整理原始碼
再來~進入原始碼的資料夾並且執行make mrproper
來確保原始碼的乾淨~
root@debian-wheezy-sh4:~# <span style="color: #ff0000;">cd /usr/src/2.6.32.59_stm24_0211-PDK7105-32BITS/</span><br /> root@debian-wheezy-sh4:/usr/src/2.6.32.59_stm24_0211-PDK7105-32BITS# <span style="color: #ff0000;">make mrproper</span>
執行完畢後,原本需要使用make menuconfig
來設定Kernel,但是本人太懶了,直接去網樂通Debian系統裡面抓「.config」過來編譯核心:
root@debian-wheezy-sh4:~# <span style="color: #ff0000;">cd /usr/src/2.6.32.59_stm24_0211-PDK7105-32BITS/</span><br /> root@debian-wheezy-sh4:/usr/src/2.6.32.59_stm24_0211-PDK7105-32BITS# <span style="color: #ff0000;">wget http://s1.becoder.org/nextvod/config.gz</span><br /> root@debian-wheezy-sh4:/usr/src/2.6.32.59_stm24_0211-PDK7105-32BITS# <span style="color: #ff0000;">gunzip config.gz</span><br /> root@debian-wheezy-sh4:/usr/src/2.6.32.59_stm24_0211-PDK7105-32BITS# <span style="color: #ff0000;">mv config .config</span><br /> root@debian-wheezy-sh4:/usr/src/2.6.32.59_stm24_0211-PDK7105-32BITS# <span style="color: #ff0000;">make headers_install INSTALL_HDR_PATH= /usr/src/2.6.32.59_stm24_0211-PDK7105-32BITS/ <a style="color: #ff0000;" href="http://next.fishome.tw/bbs/read.php?tid=248&fid=37&page=1#449" target="_blank">#產生header檔</a>,建議多下幾次指令避免缺檔</span><br />
準備編譯
網樂通原始碼已經整理得差不多了,再來是編譯驅動模組的準備:
root@debian-wheezy-sh4:~# <span style="color: #ff0000;">mkdir /lib/modules/2.6.32.59_stm24_0211-PDK7105-32BITS/</span><br /> root@debian-wheezy-sh4:~# <span style="color: #ff0000;">ln -s /usr/src/2.6.32.59_stm24_0211-PDK7105-32BITS/ /lib/modules/2.6.32.59_stm24_0211-PDK7105-32BITS/build</span><br /> root@debian-wheezy-sh4:~# <span style="color: #ff0000;">ln -s /usr/src/2.6.32.59_stm24_0211-PDK7105-32BITS/ /lib/modules/2.6.32.59_stm24_0211-PDK7105-32BITS/src</span>
完成後~就可以使用網樂通直接編譯驅動了~不過~需要用些方法繞過Vermagic的驗證才能順利掛載驅動喔(.ko檔)
修改Vermagic字串
如果沒有修改Vermagic,這樣編出來 .ko 的Vermagic和編出來核心的字串會不同,這部份還要再請教其他先進,不過目前我使用的方法是直接繞過Vermagic,直接修改Kernel原始碼,讓編譯出來.ko的Vermagic和核心相同:
root@debian-wheezy-sh4:~# <span style="color: #ff0000;">cd /usr/src/2.6.32.59_stm24_0211-PDK7105-32BITS/</span><br /> root@debian-wheezy-sh4:/usr/src/2.6.32.59_stm24_0211-PDK7105-32BITS# <span style="color: #ff0000;">cp include/linux/vermagic.h include/linux/vermagic.h.bak #備份檔案</span><br /> root@debian-wheezy-sh4:/usr/src/2.6.32.59_stm24_0211-PDK7105-32BITS# <span style="color: #ff0000;">vi include/linux/vermagic.h</span>
進入後應該會看到像這樣的文字,找到「UTS_RELEASE」:
<span style="color: #ff00ff;">#define VERMAGIC_STRING<br /> </span><span style="color: #ff0000;"><em><strong>UTS_RELEASE</strong></em> " "<br /> </span><span style="color: #ff00ff;">MODULE_VERMAGIC_SMP<br /> MODULE_VERMAGIC_PREEMPT</span><br /> <span style="color: #ff00ff;">MODULE_VERMAGIC_MODULE_UNLOAD<br /> MODULE_VERMAGIC_MODVERSIONS </span><br /> <span style="color: #ff00ff;">MODULE_ARCH_VERMAGIC</span>
修改為:
<span style="color: #ff00ff;">#define VERMAGIC_STRING</span><br /> <span style="color: #ff0000;"><strong><em>"2.6.32.59_stm24_0211-PDK7105-32BITS"</em></strong> " " #網樂通uname -r出現的版本</span><br /> <span style="color: #ff00ff;">MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT</span><br /> <span style="color: #ff00ff;">MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS</span><br /> <span style="color: #ff00ff;">MODULE_ARCH_VERMAGIC</span><br />
存檔後就可以用網樂通開始編譯驅動了~!
例如這篇~[網樂通] 使用Cross Compiler編出網樂通核心&小米隨身WIFI驅動 直接去抓驅動包進網樂通後~解壓縮後就可以直接make了:make ARCH=sh4
,不需要修改Makefile,只不過要記得新增小米隨身WIFI的ID進去:
root@debian-wheezy-sh4:~# <span style="color: #ff0000;">wget http://cdn-cw.mediatek.com/Downloads/linux/DPO_MT7601U_LinuxSTA_3.0.0.4_20130913.tar.bz2</span><br /> (http://s1.becoder.org/nextvod/DPO_MT7601U_LinuxSTA_3.0.0.4_20130913.tar.bz2)<br /> root@debian-wheezy-sh4:~# <span style="color: #ff0000;">tar jxvf DPO_MT7601U_LinuxSTA_3.0.0.4_20130913.tar.bz2</span><br /> root@debian-wheezy-sh4:~# <span style="color: #ff0000;">cd DPO_MT7601U_LinuxSTA_3.0.0.4_20130913</span><br /> root@debian-wheezy-sh4:~/DPO_MT7601U_LinuxSTA_3.0.0.4_20130913# <span style="color: #ff0000;">vi common/rtusb_dev_id.c</span>
<span style="color: #ff00ff;">#ifdef MT7601U</span><br /> {USB_DEVICE(<span style="color: #ff0000;">0x148f,0x6370</span>)}, <span style="color: #0000ff;">/* Ralink 6370 */</span><br /> {USB_DEVICE(<span style="color: #ff0000;">0x148f,0x7601</span>)}, <span style="color: #0000ff;">/* MT 6370 */</span><br /> <em><strong>{USB_DEVICE(<span style="color: #ff0000;">0x2717,0x4106</span>)}, <span style="color: #0000ff;">/* Xiaomi Wifi */</span> </strong></em>#新增這行<br /> <span style="color: #ff0000;">#endif</span> <span style="color: #0000ff;">/* MT7601U */</span>