Find the answer to your Linux question:
Results 1 to 3 of 3
Hello. Please, show me a correct Makefile for compiling a kernel module which consist of two *.c files. My .c files: module.c: //******************************************* #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> #include ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2009
    Posts
    3

    Help me compile linux kernel module


    Hello.
    Please, show me a correct Makefile for compiling a kernel module which consist of two *.c files.

    My .c files:

    module.c:
    //*******************************************
    #include <linux/module.h>
    #include <linux/kernel.h>
    #include <linux/init.h>
    #include <linux/interrupt.h>
    //-----------------------------------------------------------
    #define MODULE
    #define __KERNEL__
    //-----------------------------------------------------------
    MODULE_AUTHOR("Oligarch");
    MODULE_DESCRIPTION("Kernel module");
    //-----------------------------------------------------------
    static irqreturn_t ISI_interrupt(int irq, void * dev_id)
    {
    return IRQ_HANDLED;
    }
    //-----------------------------------------------------------
    int init_module()
    {
    printk("Kernel: Module startup\n");
    return 0;
    }
    //-----------------------------------------------------------
    void cleanup_module()
    {
    printk("Kernel: Module quit\n");
    return;
    }
    //-----------------------------------------------------------
    //*******************************************

    regs_map.c
    //*******************************************
    #include <stdint.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <unistd.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <sys/mman.h>
    #include <fcntl.h>
    //-------------------------------------------------
    #define ISI_MAP_SIZE 4096Ul
    #define ISI_MAP_MASK (ISI_MAP_SIZE - 1)
    #define ISI_BASE 0xFFFC0000
    //-------------------------------------------------
    typedef volatile unsigned int AT91_REG;
    //-------------------------------------------------
    typedef struct _AT91S_ISI {
    AT91_REG ISI_CR1;
    AT91_REG ISI_CR2;
    AT91_REG ISI_SR;
    AT91_REG ISI_IER;
    AT91_REG ISI_IDR;
    AT91_REG ISI_IMR;
    AT91_REG reserved1;
    AT91_REG reserved2;
    AT91_REG ISI_PSIZE;
    AT91_REG ISI_PDECF;
    AT91_REG ISI_PPFBD;
    AT91_REG ISI_CDBA;
    AT91_REG ISI_Y2R_SET0;
    AT91_REG ISI_Y2R_SET1;
    AT91_REG ISI_R2Y_SET0;
    AT91_REG ISI_R2Y_SET1;
    AT91_REG ISI_R2Y_SET2;
    } AT91S_ISI, *AT91PS_ISI;
    //-------------------------------------------------
    AT91PS_ISI isi;
    //-------------------------------------------------
    AT91S_ISI * isi_map(unsigned int isibase)
    {
    int fd;
    void * base;
    AT91S_ISI * _isi;
    off_t addr=isibase;
    if ((fd=open("/dev/mem",O_RDWR|O_SYNC))==-1){fprintf(stderr,"Cannot open ISI /dev/mem.\n");exit(EXIT_FAILURE);}
    base=mmap(0,ISI_MAP_SIZE,PROT_READ|PROT_WRITE,MAP_ SHARED,fd,addr&~ISI_MAP_MASK);
    if(base==(void *)-1){fprintf(stderr, "Cannot ISI mmap.\n");exit(EXIT_FAILURE);}
    _isi=base+(addr&ISI_MAP_MASK);
    return _isi;
    }
    //-------------------------------------------------

    //*******************************************


    I started to write an ISI module for AT91SAM9260 and encountered with compilation problems. I compile module good without regs_map.c file, but I can't compile it with regs_map.c. Show me a correct Makefile to do it, please.
    My old Makefile looks like:

    obj-m := module.o
    KDIR := /lib/modules/2.6.24/build
    PWD := $(shell pwd)
    CC := /home/sedyshev/arm-2007q1/bin/arm-none-linux-gnueabi-gcc
    TOOLCHAIN=/home/sedyshev/arm-2007q1/bin/arm-none-linux-gnueabi-
    default:
    $(MAKE) CROSS_COMPILE=$(TOOLCHAIN) ARCH=arm -C $(KDIR) M=$(PWD) modules

    Thank you.

  2. #2
    Just Joined!
    Join Date
    Dec 2009
    Posts
    3
    how can I get access to hardware registers from kernel module?

  3. #3
    Just Joined!
    Join Date
    Dec 2009
    Posts
    3
    I built kernel module before and it was working fine on my AT91SAM9260-EK. Now I want to write Image Sensor Interface driver for AT91SAM9260-EK, thus I need to get access to hardware registers. I know only phisical addresses of these registers. Can I just read and write to these adddresses or I should use another functionality ?

  4. $spacer_open
    $spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •