Skip to content

Commit 8c8f468

Browse files
author
jason_yao
committed
update
1 parent c3caf87 commit 8c8f468

9 files changed

Lines changed: 1124 additions & 2 deletions

File tree

‎example/driver_Lab1/.demo.ko.cmd‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cmd_/home/jason-yao/data/linux_kernel_driver/example/driver_Lab1/demo.ko := ld -r -m elf_x86_64 -T /usr/src/linux-headers-3.2.0-48-generic/scripts/module-common.lds --build-id -o /home/jason-yao/data/linux_kernel_driver/example/driver_Lab1/demo.ko /home/jason-yao/data/linux_kernel_driver/example/driver_Lab1/demo.o /home/jason-yao/data/linux_kernel_driver/example/driver_Lab1/demo.mod.o

‎example/driver_Lab1/.demo.mod.o.cmd‎

Lines changed: 487 additions & 0 deletions
Large diffs are not rendered by default.

‎example/driver_Lab1/.demo.o.cmd‎

Lines changed: 529 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/home/jason-yao/data/linux_kernel_driver/example/driver_Lab1/demo.ko
2+
/home/jason-yao/data/linux_kernel_driver/example/driver_Lab1/demo.o

‎example/driver_Lab1/Makefile‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
obj-m := helloworld.o
1+
obj-m := demo.o
2+
all:
3+
make -Wall -C /lib/modules/`uname -r`/build M=`pwd` modules
4+
clean:
5+
make -C /lib/modules/`uname -r`/build M=`pwd` clean
6+

‎example/driver_Lab1/demo.c‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include <linux/init.h>
2+
#include <linux/kernel.h>
3+
#include <linux/module.h>
4+
#include <linux/fs.h>
5+
6+
static ssize_t drv_read(struct file* filp, char* buf, size_t count, loff_t* ppos) {
7+
printk("device read\n");
8+
return count;
9+
}
10+
11+
static ssize_t drv_write(struct file* filp, const char* buf, size_t count, loff_t* ppos) {
12+
printk("device write\n");
13+
return count;
14+
}
15+
16+
static int drv_open(struct inode* inode, struct file* filp) {
17+
printk("device open\n");
18+
return 0;
19+
}
20+
21+
static long drv_ioctl(struct file* filp, unsigned int cmd, unsigned long value) {
22+
printk("device ioctl\n");
23+
return 0;
24+
}
25+
26+
static int drv_release(struct inode* inode, struct file* filp) {
27+
printk("device close\n");
28+
return 0;
29+
}
30+
31+
struct file_operations drv_fops = {
32+
read:
33+
drv_read,
34+
write:
35+
drv_write,
36+
unlocked_ioctl:
37+
drv_ioctl,
38+
open:
39+
drv_open,
40+
release:
41+
drv_release,
42+
};
43+
44+
#define MAJOR_NUM 60
45+
#define MODULE_NAME "DEMO"
46+
47+
static int demo_init(void) {
48+
if (register_chrdev(MAJOR_NUM, "demo", &drv_fops) < 0) {
49+
printk("<1>%s: can't get major %d\n", MODULE_NAME, MAJOR_NUM);
50+
return (-EBUSY);
51+
}
52+
53+
printk("<1>%s: started\n", MODULE_NAME);
54+
return 0;
55+
}
56+
57+
static void demo_exit(void) {
58+
unregister_chrdev(MAJOR_NUM, "demo");
59+
printk("<1>%s: removed\n", MODULE_NAME);
60+
}
61+
62+
module_init(demo_init);
63+
module_exit(demo_exit);
64+
65+

‎example/driver_Lab1/demo.ko‎

5.44 KB
Binary file not shown.

‎example/driver_Lab1/demo.mod.c‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <linux/module.h>
2+
#include <linux/vermagic.h>
3+
#include <linux/compiler.h>
4+
5+
MODULE_INFO(vermagic, VERMAGIC_STRING);
6+
7+
struct module __this_module
8+
__attribute__((section(".gnu.linkonce.this_module"))) = {
9+
.name = KBUILD_MODNAME,
10+
.init = init_module,
11+
#ifdef CONFIG_MODULE_UNLOAD
12+
.exit = cleanup_module,
13+
#endif
14+
.arch = MODULE_ARCH_INIT,
15+
};
16+
17+
static const struct modversion_info ____versions[]
18+
__used
19+
__attribute__((section("__versions"))) = {
20+
{ 0x8495e121, "module_layout" },
21+
{ 0x6bc3fbc0, "__unregister_chrdev" },
22+
{ 0x57089f98, "__register_chrdev" },
23+
{ 0x27e1a049, "printk" },
24+
{ 0xb4390f9a, "mcount" },
25+
};
26+
27+
static const char __module_depends[]
28+
__used
29+
__attribute__((section(".modinfo"))) =
30+
"depends=";
31+
32+
33+
MODULE_INFO(srcversion, "4BD3E8921F6CF366C7C0D1B");

‎example/driver_Lab1/modules.order‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
kernel//home/shihyu/data/linux_kernel_driver/example/driver_Lab1/helloworld.ko
1+
kernel//home/jason-yao/data/linux_kernel_driver/example/driver_Lab1/demo.ko

0 commit comments

Comments
 (0)