08-13-2008, 05:28 AM | #1 |
Member
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; } 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 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. |
08-14-2008, 05:45 PM | #2 | |
Evangelist
Posts: 423
Karma: 1517132
Join Date: Jun 2006
Location: Madrid, Spain
Device: quaderno, remarkable2, yotaphone2, prs950, iliad, onhandpc, newton
|
Quote:
Anyway, you are right in that you have to compile the driver using an arm toolchain. You must take care of the following: 1. Use the same kernel sources that iRex used (same patches; if that is not possible, then you can just "fake" the version string with a reasonably similar kernel source tree) 2. Use the same ".config" in the kernel sources tree, and do a "make oldconfig dep" to prepare the sources. 3. Use a Makefile prepared for out-of-tree drivers. I have used in the past one ripped from the bttv modules. Mine is as follows: Code:
# Makefile for this module # # Sanely ripped from bttv driver ;-) # # Modified for kernel 2.4.x ################################################# # config # currently running kernel #CURRENT=$(shell uname -r) CURRENT=2.4.18 # where the kernel sources are located KERNEL_LOCATION=/usr/src/linux-$(CURRENT) ################################################# # some magic for using linux kernel settings # when compiling module(s) # Independent modules M_OBJS = mydriver.o # Modules on whom other relay to work MX_OBJS = # Flags, defines (-Dname) and other usefull stuff EXTRA_CFLAGS = -I/usr/src/extra_headers -DLINUX here: DIR=`pwd`; (cd $(KERNEL_LOCATION); make SUBDIRS=$$DIR modules) install: su -c "cp -v $(M_OBJS) $(MX_OBJS) /lib/modules/$(CURRENT)/misc" modules: mydriver.o clean: -rm -f $(M_OBJS) $(MX_OBJS) .*.o.flags *~ include $(KERNEL_LOCATION)/Rules.make Hope that helps. P.S: In the wiki page for compiling a toolchain for the iliad there are instruction on where to download the kernel sources for the iliad. See https://wiki.mobileread.com/wiki/Note...sing_crosstool |
|
Advert | |
|
08-17-2008, 05:01 AM | #3 |
Member
Posts: 13
Karma: 10
Join Date: Jul 2008
Device: Illiad
|
Thank you very much, it works.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to compile for Kindle DX? | cdisou | Kindle Developer's Corner | 5 | 10-22-2011 07:30 AM |
Compile from Source | krischik | Calibre | 8 | 06-04-2010 08:17 AM |
iLiad Compile GTK application on Iliad. Help | vschmidt | iRex Developer's Corner | 9 | 11-25-2008 01:49 AM |
iLiad Anyone able to compile liberregxml? | Adam B. | iRex Developer's Corner | 11 | 10-27-2008 07:08 PM |
iLiad Writing driver for GPS Compact Flash on Iliad | illiad_fan | iRex Developer's Corner | 6 | 08-20-2008 03:35 AM |