1.常用函數改動 1)device_create() 作用: 創建設備節點 頭文件: #include <linux/device.h> 替代了2.6內核里的class_device_create()函數 2)device_destroy() 作用:卸載設備節點 頭文件:#include <linu ...
1.常用函數改動
1)device_create()
作用: 創建設備節點
頭文件: #include <linux/device.h>
替代了2.6內核里的class_device_create()函數
2)device_destroy()
作用:卸載設備節點
頭文件:#include <linux/device.h>
替代了2.6內核里的class_device_destroy()函數
3)usb_alloc_coherent()
作用:申請usb緩衝區,並保持記憶體和硬體cache一致性
替代了2.6內核里的usb_buffer_alloc ()函數
4)usb_free_coherent()
作用:釋放usb緩衝區
替代了2.6內核里的usb_buffer_free ()函數
5) blk_fetch_request()
作用:獲取塊設備里的一個申請(申請:主要用來讀寫塊讀設備的扇區)
替代了2.6內核里的elv_next_request()函數
6) bool __blk_end_request_cur(struct request *rq, int error)
作用:用來完成當前獲取的request結構體(具體使用參考:do_z2_request()函數)
當返回值為0則表示已完成了當前申請(若為真,則需要繼續處理當前申請,直到完成為止)
當error為0表示讀寫扇區成功,error<0表示失敗
替代了2.6內核里的end_request()函數
2.結構體改動
1) struct net_device結構體
改動方向: 2.6內核下的net_device結構體成員(與操作相關的),都放在3.4內核的net_device->net_device_ops結構體下
比如2.6內核下的net_device結構體成員:
net_device->hard_start_xmit(); //發包函數 net_device->tx_timeout(); //發包超時處理函數
對應3.4內核下:
net_device->net_device_ops->ndo_start_xmit(); //發包函數 net_device->net_device_ops->ndo_tx_timeout(); //發包超時處理函數
3.巨集改動
1)管腳巨集改動
S3C2410_GPA(0)~ S3C2410_GPM(0)
頭文件: #include <mach/regs-gpio.h>
替代了2.6內核里的S3C2410_GPA0~ S3C2410_GPM0
2)互斥信號量改動
static DEFINE_SEMAPHORE(name); //定義name變數為互斥信號量
替代了2.6內核里的DECLARE_MUTEX(name)定義巨集.
而獲取信號量down()函數和釋放信號量up()函數保持不變
(2.6內核下的信號量使用請參考:http://www.cnblogs.com/lifexy/p/7515488.html)
4.以移植LED為例
4.1首先直接修改Makefile
將以前的內核位置改為KERN_DIR = /work/system/linux-3.4.2
4.2然後直接make,根據以下錯誤信息來修改
first_drv.c:7:32: error: asm/arch/regs-gpio.h: No such file or directory first_drv.c:8:26: error: asm/hardware.h: No such file or directory first_drv.c: In function 'first_drv_write': first_drv.c:65: warning: ignoring return value of 'copy_from_user', declared with attribute warn_unused_result first_drv.c: In function 'first_drv_init': first_drv.c:152: error: implicit declaration of function 'class_create' first_drv.c:152: warning: assignment makes pointer from integer without a cast first_drv.c:155: error: implicit declaration of function 'class_device_create' first_drv.c:155: warning: assignment makes pointer from integer without a cast first_drv.c:160: warning: assignment makes pointer from integer without a cast first_drv.c: In function 'first_drv_exit': first_drv.c:170: error: implicit declaration of function 'class_destroy' first_drv.c:172: error: implicit declaration of function 'class_device_unregister'
根據上面錯誤信息,來修改led文件first_drv.c
1)去掉第7~8行:
//#include <asm/arch/regs-gpio.h> //#include <asm/hardware.h>
2)將class_device_create()函數改為device_create()
3)將class_device_unregister()函數改為device_create()
4)添加頭文件
#include <linux/device.h>
5)然後再次編譯測試程式,移植到板子上測試即可