MT7688开发板/openwrt系统-helloworld例程

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lllxxxyyy0/article/details/84190570

第一个例程,helloworld

驱动代码如下:

#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("Hanson He");

static int __init hello_init(void)
{
        printk(KERN_ALERT "Hello world\n");
        return 0;
}
static void __exit hello_exit(void)
{
        printk(KERN_ALERT " Hello world exit\n");
}
module_init(hello_init);
module_exit(hello_exit);

Makefile如下:

KERN_DIR = /home/wooya/work/openwrt-hiwooya-stable/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7688/linux-3.18.45
TOOLCHAIN = "/home/wooya/work/openwrt-hiwooya-stable/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mipsel-openwrt-linux-"

all:
    make -C $(KERN_DIR) ARCH=mips CROSS_COMPILE=$(TOOLCHAIN) M=$(PWD) modules
    
clean:
    rm -f *.ko
    rm -f *.o
    rm -f *.mod.c
    rm -f *.mod.o
    rm -f *.order
    rm -f *.sysvers

obj-m    +=hello.o

make 后生成hello.ko 文件,通过fileZilla软件把hello.ko文件发送到开发板

root@hi-wooya:/# ls
beep_test             mnt                   sbin
bin                   orisunli_beep_drv.ko  sys
dev                   orisunli_test_drv.ko  tmp
etc                   overlay               usr
hello.ko              proc                  var
hello_ext.ko          rom                   www
lib                   root
root@hi-wooya:/# 

开发板中已有hello.ko文件,加载文件

root@hi-wooya:/# insmod hello.ko
[ 1682.130000] Hello world
root@hi-wooya:/# 

查看加载好的文件

root@hi-wooya:/# lsmod

hello                    480  0 

加载成功

卸载驱动hello

root@hi-wooya:/# rmmod hello
[ 1822.430000]  Hello world exit
root@hi-wooya:/# 

卸载成功,再用lsmod查看,发现加载的hello驱动已经没有了

猜你喜欢

转载自blog.csdn.net/lllxxxyyy0/article/details/84190570