Skip to content

Commit

Permalink
support and doc for creating dkms debian package, added sysfs class f…
Browse files Browse the repository at this point in the history
…ile for udev
  • Loading branch information
Christoph committed Jul 12, 2013
1 parent 7eab8a4 commit 9f17807
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 21 deletions.
19 changes: 8 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
ifeq ($(KERNELRELEASE),)
#Outside Kbuild Part

KERNELDIR ?= /usr/src/raspberry_kernel/linux-source-3.6.11+
PWD := $(shell pwd)
KDIR ?= /lib/modules/`uname -r`/build
$(info Running Makefile outside Kbuild-System)

.PHONY: build clean

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

clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c modules.order Module.symvers .tmp_versions

load:
-rmmod pinbus
insmod pinbus.ko
-mknod /dev/pinbus c `grep pinbus /proc/devices | cut -d ' ' -f 1` 0
else
#Kbuild Part

$(info Building with KERNELRELEASE = ${KERNELRELEASE})
obj-m := pinbus.o

endif

16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# pinbus


## how to setup ubuntu

```
Expand All @@ -18,3 +17,18 @@ make scripts
cd /module/dir/in/homeverzeichnis
make
```

## build dkms
checkout this dir to /usr/src/pinbus-0.23
sudo dkms add -m pinbus -v 0.23
sudo dkms build -m pinbus -v 0.23


## build debian dkms package
sudo dkms mkdsc -m pinbus -v 0.23 --source-only
sudo dkms mkdeb -m pinbus -v 0.23 --source-only

cp /var/lib/dkms/pinbus/0.23/deb/pinbus-dkms_0.23_all.deb .
sudo dkms remove pinbus/0.23 --all
sudo rm -rf /var/lib/dkms/pinbus/

10 changes: 10 additions & 0 deletions dkms.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
PACKAGE_NAME="pinbus-dkms"
PACKAGE_VERSION="0.23"
CLEAN="rm -f *.*o"
BUILT_MODULE_NAME=pinbus
DEST_MODULE_LOCATION="/updates"
REMAKE_INITRD="no"
AUTOINSTALL="yes"

#MAKE="make KERNELDIR=/lib/modules/${kernelver}/build"
#BUILT_MODULE_LOCATION=src/
26 changes: 17 additions & 9 deletions pinbus.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@

/*
* TODO:
* start clock_irq only when device is open
* global device pointer for free in module_exit
*
*/

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sched.h>
Expand All @@ -19,9 +12,11 @@
#include <linux/slab.h>
#include <linux/gpio.h>
#include <linux/interrupt.h>
#include <linux/device.h>

/*------------------------------------------------------------------------------------------*\
\*------------------------------------------------------------------------------------------*/
#define DEVICE_NAME "pinbus"
#define dbg(level, format, arg...) do { if ( unlikely(pinbus_enable_dbg >= level) ) printk(KERN_WARNING ":[%s]: " format "\n", __FUNCTION__, ##arg); } while ( 0 )

#define NR_PINBUS_DEVS 1
Expand Down Expand Up @@ -71,6 +66,7 @@ struct pinbus_dev {
};

static struct pinbus_dev *g_pinbus_dev = NULL;
static struct class *pinbus_class = NULL;

/*------------------------------------------------------------------------------------------*\
\*------------------------------------------------------------------------------------------*/
Expand Down Expand Up @@ -191,7 +187,7 @@ static int pinbus_init(void){

printk(KERN_INFO "Loading Pinbus Module\n");

result = alloc_chrdev_region(&dev, 0, NR_PINBUS_DEVS, "pinbus");
result = alloc_chrdev_region(&dev, 0, NR_PINBUS_DEVS, DEVICE_NAME);
pinbus_major = MAJOR(dev);
if (result < 0)
return result;
Expand All @@ -206,6 +202,11 @@ static int pinbus_init(void){
cdev_init(&g_pinbus_dev->cdev, &pinbus_fops);
g_pinbus_dev->cdev.owner = THIS_MODULE;
g_pinbus_dev->cdev.ops = &pinbus_fops;

/* register sysfs class for udev */
pinbus_class = class_create(THIS_MODULE, DEVICE_NAME);
device_create( pinbus_class, NULL, devno, NULL, DEVICE_NAME);

atomic_set(&g_pinbus_dev->device_available, 1);
init_waitqueue_head(&g_pinbus_dev->wait_for_data);

Expand Down Expand Up @@ -244,12 +245,19 @@ static int pinbus_init(void){

static void pinbus_exit(void) {

int devno = MKDEV( pinbus_major, 0);
printk(KERN_INFO "Shutting down Pinbus Module\n");

/* unregister sysfs class for udev */
device_destroy( pinbus_class, devno );
class_destroy( pinbus_class );
pinbus_class = NULL;

free_irq(busy_irq_number, g_pinbus_dev);
free_irq(stat_irq_number, g_pinbus_dev);
cdev_del(&g_pinbus_dev->cdev);
kfree(g_pinbus_dev);
unregister_chrdev_region(MKDEV (pinbus_major, 0), NR_PINBUS_DEVS);
unregister_chrdev_region( devno, NR_PINBUS_DEVS);
printk(KERN_INFO "Shutting down Pinbus Module successful\n");

}
Expand Down

0 comments on commit 9f17807

Please sign in to comment.