nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

Help me compile linux kernel module

This is a discussion on Help me compile linux kernel module within the Coding in General forums, part of the Development/Scripting category; Hello. Please, show me a correct Makefile for compiling a kernel module which consist of two *.c files. My .c ...


Go Back   nixCraft Linux Forum > Development/Scripting > Coding in General

Linux answers from nixCraft.


Coding in General Discussion on PHP/Perl/Python/Ruby/GNU C or C++. MySQL, PgSQL and (X)HTML or any other programming languages you want.

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 14-12-2009, 01:09 PM
Junior Member
User
 
Join Date: Dec 2009
OS: openSUSE
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
_oligarch is on a distinguished road
Default 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:

Code:
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:

Code:
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.

Last edited by nixcraft; 14-12-2009 at 02:30 PM. Reason: code tags
Reply With Quote
  #2 (permalink)  
Old 14-12-2009, 02:21 PM
Junior Member
User
 
Join Date: Dec 2009
OS: openSUSE
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
_oligarch is on a distinguished road
Default

how can I get access to hardware registers from kernel module?
Reply With Quote
  #3 (permalink)  
Old 14-12-2009, 02:31 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Have you tried our tutorial?
  1. Howto: Build Linux Kernel Module Against Installed Kernel w/o Full Kernel Source Tree
Make file is very sensitive about tabs.
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #4 (permalink)  
Old 14-12-2009, 03:41 PM
Junior Member
User
 
Join Date: Dec 2009
OS: openSUSE
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
_oligarch is on a distinguished road
Default

everything OK with tabs. 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 ?
Thank you.

Last edited by _oligarch; 14-12-2009 at 03:46 PM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Linux kernel deleted from /boot - how do I resinstall the kernel vaibhav.kanchan Getting started tutorials 2 25-03-2008 12:31 AM
compile a new kernel in RHEL 5 vikas027 CentOS / RHEL / Fedora 3 24-03-2008 09:56 PM
Linux disable kernel module / driver sweta Linux hardware 2 21-08-2007 12:38 AM
Kernel Compile mannrj45 Linux software 1 02-12-2006 08:32 PM
freebsd kernel module unload HellBoy All about FreeBSD/OpenBSD/NetBSD 2 05-01-2006 06:51 PM


All times are GMT +5.5. The time now is 10:15 AM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38