View Single Post
Old 08-13-2008, 05:28 AM   #1
illiad_fan
Member
illiad_fan began at the beginning.
 
Posts: 13
Karma: 10
Join Date: Jul 2008
Device: Illiad
How to compile new driver for Iliad

Hi all,
I'm learning to write driver for Linux, and then install it to Iliad.
parlelport.c
Code:
/* Necessary includes for drivers */
#include <linux/init.h>
//#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h> /* printk() */
#include <linux/slab.h> /* kmalloc() */
#include <linux/fs.h> /* everything... */
#include <linux/errno.h> /* error codes */
#include <linux/types.h> /* size_t */
#include <linux/proc_fs.h>
#include <linux/fcntl.h> /* O_ACCMODE */
#include <linux/ioport.h>
#include <asm/system.h> /* cli(), *_flags */
#include <asm/uaccess.h> /* copy_from/to_user */
#include <asm/io.h> /* inb, outb */
MODULE_LICENSE("Dual BSD/GPL");
/* Function declaration of parlelport.c */
int port_number = 0x0165;
const char* port_name = "parlelport";

int parlelport_open(struct inode *inode, struct file *filp);
int parlelport_release(struct inode *inode, struct file *filp);
ssize_t parlelport_read(struct file *filp, char *buf,
                       size_t count, loff_t *f_pos);
ssize_t parlelport_write(struct file *filp, char *buf,
                       size_t count, loff_t *f_pos);
void parlelport_exit(void);
int parlelport_init(void);
/* Structure that declares the common */
/* file access fcuntions */
struct file_operations parlelport_fops = {
  read: parlelport_read,
  write: parlelport_write,
  open: parlelport_open,
  release: parlelport_release
};
/* Driver global variables */
/* Major number */
int parlelport_major = 61;
/* Control variable for memory */
/* reservation of the parallel port*/
int port;
module_init(parlelport_init);
module_exit(parlelport_exit);

int parlelport_init(void) {
  int result;
  /* Registering device */
  result = register_chrdev(parlelport_major, port_name,
      &parlelport_fops);
  if (result < 0) {
    printk(
      "<1>parlelport: cannot obtain major number %d\n",
      parlelport_major);
    return result;
  }

  /* Registering port */
/*
  port = check_region(port_number, 1);
  if (port) {
    printk("<1>parlelport: cannot reserve 0x378\n");
    result = port;
    goto fail;
  }
  request_region(port_number, 1, port_name);
*/

  printk("<1>Inserting parlelport module\n");
  return 0;
  fail:
    parlelport_exit();
    return result;
}

void parlelport_exit(void) {
  /* Make major number free! */
  unregister_chrdev(parlelport_major, port_name);

  /* Make port free! */
  if (!port) {
    //release_region(port_number,1);
  }

  printk("<1>Removing parlelport module\n");
}

int parlelport_open(struct inode *inode, struct file *filp) {
  /* Success */
  return 0;
}

int parlelport_release(struct inode *inode, struct file *filp) {
  /* Success */
  return 0;
}

ssize_t parlelport_read(struct file *filp, char *buf,
  size_t count, loff_t *f_pos) {
  /* Buffer to read the device */
  char parlelport_buffer;
  
  /* Reading port */
  parlelport_buffer = inb(port_number);

  /* We transfer data to user space */
  copy_to_user(buf,&parlelport_buffer,1);
  /* We change the reading position as best suits */
  if (*f_pos == 0) {
    *f_pos+=1;
    return 1;
  } else {
    return 0;
  }
}

ssize_t parlelport_write( struct file *filp, char *buf,
  size_t count, loff_t *f_pos) {
  char *tmp;
  /* Buffer writing to the device */
  char parlelport_buffer;
  tmp=buf+count-1;
  copy_from_user(&parlelport_buffer,tmp,1);

  /* Writing to the port */
  outb(parlelport_buffer,port_number);

  return 1;
}
Makefile
Code:
obj-m += parlelport.o

all:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
I use command make to compile and insmod to install this driver on Ubuntu 8 ok. But now I don't know how to compile this driver for Iliad because when I install the ko file to Iliad, I got error different architecture.
After that I try to compile this driver on crosstool for Iliad, but not sucessful. Is there any one know how to do this? Please help me!
Thank you very much.
illiad_fan is offline   Reply With Quote