Permalink
Browse files

Create some simple kernel modules for examples

* One is just a simple hello world kernel module
* The other is something Jeff Lance wanted built
  • Loading branch information...
1 parent 74d801d commit d60d5f20e67a527aaa1813af2391894ffbfd4af4 @jadonk committed Feb 12, 2013
Showing with 109 additions and 0 deletions.
  1. +109 −0 hacks/example-kernel-modules.patch
@@ -0,0 +1,109 @@
+From eaf4f7ea7d540bc8bb57283a8f68321ddb4401f4 Mon Sep 17 00:00:00 2001
+From: Jason Kridner <jdk@ti.com>
+Date: Tue, 12 Feb 2013 02:18:03 +0000
+Subject: [PATCH] hello: example kernel modules
+
+---
+ hello/Makefile | 7 +++++++
+ hello/hello.c | 18 ++++++++++++++++++
+ hello/write_cm.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
+ 3 files changed, 74 insertions(+), 0 deletions(-)
+ create mode 100644 hello/Makefile
+ create mode 100644 hello/hello.c
+ create mode 100644 hello/write_cm.c
+
+diff --git a/hello/Makefile b/hello/Makefile
+new file mode 100644
+index 0000000..4b23da7
+--- /dev/null
++++ b/hello/Makefile
+@@ -0,0 +1,7 @@
++obj-m := hello.o write_cm.o
++
++PWD := $(shell pwd)
++KDIR := ${PWD}/..
++
++default:
++ make -C $(KDIR) SUBDIRS=$(PWD) modules
+diff --git a/hello/hello.c b/hello/hello.c
+new file mode 100644
+index 0000000..157d490
+--- /dev/null
++++ b/hello/hello.c
+@@ -0,0 +1,18 @@
++#include <linux/module.h> /* Needed by all modules */
++#include <linux/kernel.h> /* Needed for KERN_INFO */
++#include <linux/init.h> /* Needed for the macros */
++
++static int __init hello_start(void)
++{
++ printk(KERN_INFO "Loading hello module...\n");
++ printk(KERN_INFO "Hello world\n");
++ return 0;
++}
++
++static void __exit hello_end(void)
++{
++ printk(KERN_INFO "Goodbye Mr.\n");
++}
++
++module_init(hello_start);
++module_exit(hello_end);
+diff --git a/hello/write_cm.c b/hello/write_cm.c
+new file mode 100644
+index 0000000..54f60b5
+--- /dev/null
++++ b/hello/write_cm.c
+@@ -0,0 +1,49 @@
++#include <linux/module.h>
++#include <linux/init.h>
++#include <asm/io.h>
++#include <linux/moduleparam.h>
++
++#define CM_ADDRESS_BASE 0x44E10000
++
++static void __iomem *ctrl_base;
++
++static unsigned int offset=0x40;
++static unsigned int value=0xffffffff;
++
++module_param(offset, int, S_IRUSR | S_IWUSR);
++MODULE_PARM_DESC(offset, "control module register offset");
++module_param(value, int, S_IRUSR | S_IWUSR);
++MODULE_PARM_DESC(value, "control module register value");
++
++static int __init my_init(void)
++{
++ volatile u32 j;
++
++ ctrl_base = ioremap(CM_ADDRESS_BASE, SZ_8K);
++ if (!ctrl_base) {
++ pr_err("control module ioremap failed\n");
++ return -ENOMEM;
++ }
++ j = __raw_readl(ctrl_base + offset);
++ printk(KERN_INFO "read contral module reg[0x%x] = %x\n", offset, j);
++
++ if(value != 0xffffffff)
++ {
++ __raw_writel(value, ctrl_base + 0x40);
++ j = __raw_readl(ctrl_base + 0x40);
++ printk(KERN_INFO "read back contral_status reg = %x\n", j);
++ }
++ return 0;
++}
++
++static void __exit my_exit(void)
++{
++ printk(KERN_INFO "Module Unloading\n");
++}
++
++module_init(my_init);
++module_exit(my_exit);
++
++MODULE_AUTHOR("Jeff Lance");
++MODULE_DESCRIPTION("CM register read/write");
++MODULE_LICENSE("GPL v2");
+--
+1.7.8.6
+

0 comments on commit d60d5f2

Please sign in to comment.