2016年11月16日水曜日

FON2405E カスタムファーム用のドライバ開発(準備)

FON2405EのGPIOを使ってシリアル通信をさせるため、いろいろ回り道をしながら挑戦を続けてきた。
今回は、RalinkSDKで作った FON2405E用カスタムファームに向けたドライバ開発について。

1.カスタムファームの変更

まずは、カーネルコンフィングの変更
[make menuconfig]で、[Loadable module support]以降を適当に有効化しておく
Enable loadable module supportとか。
これを忘れていて、make時にprintkとかが定義されていないと怒られた。ハマった。
http://stackoverflow.com/questions/31195516/error-building-android-kernel-module-on-ubuntu-14-04

その他に、insmodとかlsmodとか必要に応じで、有効にしておく。

ファームができたら、FONに入れておく。

2.テスト用ドライバの作成

とりあえず、準備なので何でも良い。やっつけコードを、末尾に記載。

3.Makefileの準備

 ここがいろいろ試行錯誤した。
HOME:= /home/adeno/fongpio/sdk3301/RT288x_SDK
ARCH := mips
CROSS_COMPILE := /opt/buildroot-gcc342/bin/mipsel-linux-
KPATH := $(HOME)/source/linux-2.6.21.x
obj-m += my1st.o
all:
make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KPATH) M=$(PWD) modules
clean:
make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KPATH) M=$(PWD) clean
view raw Makefile hosted with ❤ by GitHub

4.いざ、Make


一撃! うれしい!! 未使用変数の注意が出ているけど、知っているやつなので、放置。

これで、my1st.koができた。

5.NFSマウント

SDKのマニュアルどおり。
mount -o nolock 10.10.10.3:/var/lib/tftpboot /mnt
でOK

6.insmodしてみる

作成したmy1st.koをinsmodすると・・・。


よかったーーー。 ちゃんとprintkも動いている。
あきらめずに続けてよかった。
ラズベリー・パイで下準備しておいて本当によかった。

#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/types.h>
#include <linux/kdev_t.h>
#include <linux/errno.h>
#include <linux/cdev.h>
#include <linux/sched.h>
#include <linux/stat.h>
#include <linux/io.h>
#include <linux/ioport.h>
#include <linux/init.h>
#include <linux/version.h>
#include <linux/device.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <asm/uaccess.h>
#include <linux/timer.h>
MODULE_AUTHOR("Adeno");
MODULE_LICENSE("Dual BSD/GPL");
#define MYSFR9_VERSION "0.1"
#define MYSFR9_NUM_DEVS 1 /* このドライバが制御するデバイスの数 */
#define MYSFR9_DEVNAME "My1st" /* このデバイスドライバの名称 */
#define MYSFR9_MAJOR 0 /* メジャー番号だが自動設定なので0 */
#define MYSFR9_MINOR 0 /* マイナー番号のベース番号 */
static int _mysfr9_major = MYSFR9_MAJOR;
static int _mysfr9_minor = MYSFR9_MINOR;
static struct cdev *mysfr9_cdev_array = NULL;
static struct class *mysfr9_class = NULL;
/*プロトタイプ宣言*/
//カーネルへの登録関係
//デバイスに対する処理
static int mysfr9_open(struct inode *inode, struct file *filep);
static int mysfr9_release(struct inode *inode, struct file *filep);
static ssize_t mysfr9_write(struct file *filep,const char __user *buf, size_t count, loff_t *f_pos);
static ssize_t mysfr9_read(struct file *filep,char __user *buf,size_t count, loff_t *f_pos);
//File Operations構造体
struct file_operations mysfr9_fops = {
.open = mysfr9_open,
.release = mysfr9_release,
.write = mysfr9_write,
.read = mysfr9_read,
};
///////////////////////////////////////////////////////////////////////////////////////////////////
//デバイスドライバがロードされた時の処理
static int mysfr9_init(void)
{
/* 開始のメッセージ */
printk(KERN_INFO "%s Ver.%s loading...\n", MYSFR9_DEVNAME,MYSFR9_VERSION );
return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
//デバイスドライバがアンロードされた時の処理
static void mysfr9_exit(void)
{
printk( KERN_INFO "[%s] driver unregister sccessed.\n",MYSFR9_DEVNAME);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
//デバイスに対する処理
static int mysfr9_open(struct inode *inode, struct file *filep)
{
printk(KERN_INFO "[%s] Device open sccessed.\n",MYSFR9_DEVNAME);
return 0;
}
static int mysfr9_release(struct inode *inode, struct file *filep)
{
printk(KERN_INFO "[%s] Device release sccessed.\n",MYSFR9_DEVNAME);
return 0;
}
static ssize_t mysfr9_write(struct file *filep,const char __user *buf, size_t count, loff_t *f_pos)
{
return 0;
}
static ssize_t mysfr9_read(struct file *filep,char __user *buf,size_t count, loff_t *f_pos){
return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
//initの登録
module_init(mysfr9_init);
//exitの登録
module_exit(mysfr9_exit);
view raw my1st.c hosted with ❤ by GitHub

0 件のコメント:

コメントを投稿