Ошибки кросс-компиляции программы модуля ядра C - PullRequest
0 голосов
/ 25 октября 2019

Я разработал модуль ядра Linux, который я хочу вставить в свое ядро. Но когда я пытаюсь выполнить кросс-компиляцию, происходит много ошибок, которые я не смог решить.

Это код модуля:

#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/device.h>  
#include <linux/kernel.h>
#include <linux/uaccess.h>
#include <linux/input.h>



MODULE_LICENSE("GPL");      
MODULE_AUTHOR("Gaston");  
MODULE_DESCRIPTION("A simple Linux char driver"); 
MODULE_VERSION("0.1"); 

#define BTN_FILE_PATH "/dev/input/event0"
#define MAX 256

static char message[MAX] =""; 


int file;
size_t  rb;
int yalv;
struct input_event  ev[64];
char *str = BTN_FILE_PATH;



ssize_t exer_open(struct inode *pinode, struct file *pfile) {

    printk(KERN_INFO "Device has been opened\n");

    if((file = exer_open(str, O_RDONLY)) < 0) {
        printk("simplekey: File can not open");
        return(-1);
    }

    return 0;
}



ssize_t exer_read(struct file *pfile, char __user *buffer, size_t length, loff_t *offset) {

    rb= exer_read(file, &ev, sizeof(ev));

        if (rb < (int) sizeof(struct input_event)) {
            printk("simplekey: short read");
            return(-1);
        }

        for (yalv = 0;
            yalv < (int) (rb / sizeof(struct input_event));
            yalv++) {
            if (ev[yalv].type == EV_KEY) {

                /* Change state on button pressed */
                if (ev[yalv].value == 0)
                    eval_keycode(ev[yalv].code);
            }
        }

    return 0;
}


ssize_t exer_write(struct file *pfile, const char __user *buffer, size_t length, loff_t *offset) {
    if (length > MAX)
        return -EINVAL;

    if (copy_from_user(message, buffer, length) != 0)
        return -EFAULT;

    printk(KERN_INFO "Received %s characters from the user\n", message);
    return 0;

}   


ssize_t exer_close(struct inode *pinode, struct file *pfile) {

    exer_close(file);
    printk(KERN_INFO "Device successfully closed\n");
    return 0;
}


struct file_operations exer_file_operations = { 
    .owner = THIS_MODULE,
    .open = exer_open,
    .read = exer_read,
    .write = exer_write,
    .release = exer_close,
};


int exer_simple_module_init(void) {

    printk(KERN_INFO "Initializing the LKM\n");
    register_chrdev(240, "Simple Char Drv", &exer_file_operations);
    return 0;
}


void exer_simple_module_exit(void) {

    unregister_chrdev(240, "Simple Char Drv");
}

module_init(exer_simple_module_init);
module_exit(exer_simple_module_exit);

И это его Makefile:

ifneq ($(KERNELRELEASE),)

ccflags-y += -I /opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/src/kernel/include/linux
obj-m += exer_simple_char_drv.o

else

# default to build against running kernel if KDIR not
# specified:
KDIR ?= /home/gaston/linux4sam/poky/build-microchip/tmp/work/sama5d27_som1_ek_sd-poky-linux-gnueabi/linux-at91/4.14+gitAUTOINC+b733e44da2-r0/build

default:
        $(MAKE) -C $(KDIR) M=$$PWD

endif

И вот ошибки, которые я получаю при запуске Make для компиляции:

/home/gaston/ledshared/exer_simple_char_drv.c: In function ‘exer_open’:
/home/gaston/ledshared/exer_simple_char_drv.c:34:23: error: passing argument 1 of ‘exer_open’ from incompatible pointer type [-Werror=incompatible-pointer-types]
  if((file = exer_open(str, O_RDONLY)) < 0) {
                       ^~~
/home/gaston/ledshared/exer_simple_char_drv.c:30:9: note: expected ‘struct inode *’ but argument is of type ‘char *’
 ssize_t exer_open(struct inode *pinode, struct file *pfile) {
         ^~~~~~~~~
/home/gaston/ledshared/exer_simple_char_drv.c: In function ‘exer_read’:
/home/gaston/ledshared/exer_simple_char_drv.c:48:16: warning: passing argument 1 of ‘exer_read’ makes pointer from integer without a cast [-Wint-conversion]
  rb= exer_read(file, &ev, sizeof(ev));
                ^~~~
/home/gaston/ledshared/exer_simple_char_drv.c:44:9: note: expected ‘struct file *’ but argument is of type ‘int’
 ssize_t exer_read(struct file *pfile, char __user *buffer, size_t length, loff_t *offset) {
         ^~~~~~~~~
/home/gaston/ledshared/exer_simple_char_drv.c:48:22: error: passing argument 2 of ‘exer_read’ from incompatible pointer type [-Werror=incompatible-pointer-types]
  rb= exer_read(file, &ev, sizeof(ev));
                      ^
/home/gaston/ledshared/exer_simple_char_drv.c:44:9: note: expected ‘char *’ but argument is of type ‘struct input_event (*)[64]’
 ssize_t exer_read(struct file *pfile, char __user *buffer, size_t length, loff_t *offset) {
         ^~~~~~~~~
/home/gaston/ledshared/exer_simple_char_drv.c:48:6: error: too few arguments to function ‘exer_read’
  rb= exer_read(file, &ev, sizeof(ev));
      ^~~~~~~~~
/home/gaston/ledshared/exer_simple_char_drv.c:44:9: note: declared here
 ssize_t exer_read(struct file *pfile, char __user *buffer, size_t length, loff_t *offset) {
         ^~~~~~~~~
/home/gaston/ledshared/exer_simple_char_drv.c:62:6: error: implicit declaration of function ‘eval_keycode’ [-Werror=implicit-function-declaration]
      eval_keycode(ev[yalv].code);
      ^~~~~~~~~~~~
/home/gaston/ledshared/exer_simple_char_drv.c: In function ‘exer_close’:
/home/gaston/ledshared/exer_simple_char_drv.c:101:13: warning: passing argument 1 of ‘exer_close’ makes pointer from integer without a cast [-Wint-conversion]
  exer_close(file);
             ^~~~
/home/gaston/ledshared/exer_simple_char_drv.c:99:9: note: expected ‘struct inode *’ but argument is of type ‘int’
 ssize_t exer_close(struct inode *pinode, struct file *pfile) {
         ^~~~~~~~~~
/home/gaston/ledshared/exer_simple_char_drv.c:101:2: error: too few arguments to function ‘exer_close’
  exer_close(file);
  ^~~~~~~~~~
/home/gaston/ledshared/exer_simple_char_drv.c:99:9: note: declared here
 ssize_t exer_close(struct inode *pinode, struct file *pfile) {

^ ~~~~~~~~~

Может кто-нибудь помочьЯ пожалуйста. Спасибо

...