瑞芯微Rockchip开发者社区
直播中

偶是糕富帅

12年用户 787经验值
私信 关注
[问答]

怎样在Firefly-RK3399上去编写第一个驱动程序呢

怎样在Firefly-RK3399上去编写第一个驱动程序呢?

回帖(1)

许伟星

2022-3-4 13:59:04
Firefly-RK3399第一个驱动程序编制

编写程序 hello_module.c

#include
#include

MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("ZWWANG");

static int hello_init(void)
{
        printk(KERN_EMERG "HELLO WORLD enter!n");
        return 0;
}

static void hello_exit(void)
{
        printk(KERN_EMERG "HELLO WORLD exit!n");
      
}

module_init(hello_init);
module_exit(hello_exit);

编写Makefile

#!/bin/bash

CROSS_COMPILE:= aarch64-linux-gnu-
ARCH:= arm64
CC:= $(CROSS_COMPILE)gcc
LD:= $(CROSS_COMPILE)ld

obj-m += hello_module.o


KERNELDIR := /home/zwwang/sdk/linux-sdk/kernel


all:
                make -C $(KERNELDIR) M=$(PWD) modules
clean:
        rm -f *.o
        rm -f *.symvers
        rm -f *.order
        rm -f *.ko
        rm -f *.mod.c

编译

在hello_module 的文件夹下使用

make

编译程序
结果:

make -C /home/zwwang/sdk/linux-sdk/kernel M=/home/zwwang/testDriver/hello_mod modules
make[1]: Entering directory '/home/zwwang/sdk/linux-sdk/kernel'
  CC [M]  /home/zwwang/testDriver/hello_mod/hello_module.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/zwwang/testDriver/hello_mod/hello_module.mod.o
  LD [M]  /home/zwwang/testDriver/hello_mod/hello_module.ko
make[1]: Leaving directory '/home/zwwang/sdk/linux-sdk/kernel'

查看目录中已经产生

hello_module.ko

执行

把ko文件放入目标主机
加载模块

sudo insmod hello_module.ko

查看模块

cat /proc/modules

lsmod

卸载模块

sudo rmmod hello_module
举报

更多回帖

发帖
×
20
完善资料,
赚取积分