Created
July 5, 2013 23:18
-
-
Save starwing/5937805 to your computer and use it in GitHub Desktop.
a kernel module used to read chipid of cubieboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <linux/init.h> | |
#include <linux/module.h> | |
#include <linux/kernel.h> | |
#include <linux/io.h> | |
#include <linux/proc_fs.h> | |
#include <linux/seq_file.h> | |
/* procfs routines */ | |
int chipid_show(struct seq_file *p, void *v) { | |
#define SW_VA_SID_IO_BASE ((const volatile void __iomem*)0xf1c23800) | |
return seq_printf(p, "Chipid\t\t: %08x-%08x-%08x-%08x\n", | |
readl(SW_VA_SID_IO_BASE), | |
readl(SW_VA_SID_IO_BASE + 0x4), | |
readl(SW_VA_SID_IO_BASE + 0x8), | |
readl(SW_VA_SID_IO_BASE + 0xC) | |
); | |
} | |
int chipid_single_open(struct inode *inode, struct file *file) { | |
return single_open(file, chipid_show, NULL); | |
} | |
struct file_operations chipid_single_seq_file_operations = { | |
.open = chipid_single_open, | |
.read = seq_read, | |
.llseek = seq_lseek, | |
.release = single_release, | |
}; | |
struct proc_dir_entry *entry = NULL; | |
/* initialize routines */ | |
static int __init chipid_init(void) | |
{ | |
printk(KERN_ALERT "chipid module loading ...\n"); | |
entry = proc_create("chipid", 0, NULL, &chipid_single_seq_file_operations); | |
if (entry) { | |
printk(KERN_ALERT "chipid module load ok, entry = %p\n", entry); | |
return 0; | |
} | |
return -EFAULT; | |
} | |
static void __exit chipid_exit(void) | |
{ | |
printk(KERN_ALERT "chipid module unloading ..., entry = %p\n", entry); | |
if (entry) { | |
remove_proc_entry("chipid", NULL); | |
printk(KERN_ALERT "chipid module unloaded.\n"); | |
entry = NULL; | |
} | |
} | |
MODULE_AUTHOR("Xavier-Wang"); | |
MODULE_LICENSE("Dual BSD/GPL"); | |
MODULE_DESCRIPTION("kernel module used to get chipid of cubieboard!\n"); | |
MODULE_ALIAS("retrieve chipid from procfs"); | |
module_init(chipid_init); | |
module_exit(chipid_exit); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
obj-m := chipid.o |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sw@sw-acer:~/Work/Code/procfsk$ make -C /usr/src/linux-headers-3.8.0-25-generic SUBDIRS=$PWD modules | |
make:进入目录'/usr/src/linux-headers-3.8.0-25-generic' | |
CC [M] /home/sw/Work/Code/procfsk/chipid.o | |
Building modules, stage 2. | |
MODPOST 1 modules | |
CC /home/sw/Work/Code/procfsk/chipid.mod.o | |
LD [M] /home/sw/Work/Code/procfsk/chipid.ko | |
make:离开目录“/usr/src/linux-headers-3.8.0-25-generic” | |
sw@sw-acer:~/Work/Code/procfsk$ sudo insmod chipid.kosw@sw-acer:~/Work/Code/procfsk$ cat /proc/chipid | |
Chipid : 63682074-65645f69-682a2076-2c766564 | |
sw@sw-acer:~/Work/Code/procfsk$ sudo rmmod chipid sw@sw-acer:~/Work/Code/procfsk$ | |
sw@sw-acer:~/Work/Code/procfsk$ dmesg | tail | |
[354923.091725] type=1400 audit(1373061974.062:42): apparmor="DENIED" operation="open" parent=3490 profile="/usr/bin/evince" name="/media/sw/Private/Downloads/vilua.love" pid=29762 comm="pool" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0 | |
[354923.092409] type=1400 audit(1373061974.062:43): apparmor="DENIED" operation="open" parent=3490 profile="/usr/bin/evince" name="/media/sw/Private/Downloads/Soundbanks.for.Guitar.Pro.6.rar.emule.td" pid=29762 comm="pool" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0 | |
[358156.365857] chipid module loading .../n | |
[358156.365875] chipid module load ok/nchipid module unloaded/n | |
[358575.034287] chipid module loading .../n<1>[358592.043926] chipid module unloading ..., entry = ce6bf480 | |
[358592.043931] chipid module unloaded. | |
[358947.262917] chipid module loading ... | |
[358947.262942] chipid module load ok, entry = e5430ae0 | |
[358970.715428] chipid module unloading ..., entry = e5430ae0 | |
[358970.715434] chipid module unloaded. | |
sw@sw-acer:~/Work/Code/procfsk$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
因为就这两天要把sd卡还给同学,所以打算睡觉前在nand上再编译一次,结果忘记编译前screen一下。
如果关掉工作站(省电)就会断开ssh, cb上的make就挂了。。。
终于编译完了,睡觉去。