Browse Source

first commit

encrypt 8 years ago
commit
50cf1ab4b8
3 changed files with 53 additions and 0 deletions
  1. 8 0
      .gitignore
  2. 16 0
      Makefile
  3. 29 0
      fake-device.c

+ 8 - 0
.gitignore

@@ -0,0 +1,8 @@
+*~
+*.ko
+*.mod*
+*.o
+*.cmd
+Module.symvers
+modules.order
+.tmp_versions/

+ 16 - 0
Makefile

@@ -0,0 +1,16 @@
+obj-m := fake-device.o
+KDIR  := /lib/modules/$(shell uname -r)/build
+PWD   := $(shell pwd)
+DEPMOD:=$(shell which depmod)
+# possible bug: maybe this will work only on debian based systems
+SYSMAP:= /boot/System.map-$(shell uname -r)
+
+default:
+	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
+
+install:
+	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules_install
+	$(DEPMOD) -ae -F $(SYSMAP)
+
+clean:
+	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) clean

+ 29 - 0
fake-device.c

@@ -0,0 +1,29 @@
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+
+static char *name = "fake-device";
+
+static struct platform_device *pdev;
+
+static int __init fake_device_init(void)
+{
+  printk(KERN_INFO "nameis %s", name);
+  pdev = platform_device_register_simple(name, 0, NULL, 0);
+  if (IS_ERR(pdev))
+    return PTR_ERR(pdev);  
+  
+  return 0;
+}
+
+static void __exit fake_device_exit(void)
+{
+  platform_device_unregister(pdev);
+}
+
+module_param(name, charp, 0644);
+MODULE_PARM_DESC(name, "Device name");
+
+module_init(fake_device_init)
+module_exit(fake_device_exit)
+MODULE_LICENSE("GPL");