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$ |
因为就这两天要把sd卡还给同学,所以打算睡觉前在nand上再编译一次,结果忘记编译前screen一下。
如果关掉工作站(省电)就会断开ssh, cb上的make就挂了。。。
终于编译完了,睡觉去。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
还有一部分(不多,但也不能忽略不计)的时间是花在shell上。
之前的想法是: bash, sed, awk... 这些东西有什么用? 我需要深入学习的只是少数 真正的 编程语言而已。
但大致应该是在学git的时候, 我感觉到一件事: 这套东西是一套用代码而不是文字描述要做什么的方法。
就像讨论其他编程语言的各种问题一样, 用文字很难准确描述, 上代码才是王道。
比如"将/proc/config.gz"的内容解压到.config, 再修改或添加CONFIG_STRICT_DEVMEM=y一行",如果再附带一条shell命令:
$ zcat /proc/config.gz | sed 's|^CONFIG_STRICT_DEVMEM=.*$|CONFIG_STRICT_DEVMEM=n|w/dev/stderr' > .config
读者(可能就是半年后的自己)只要看明白其中任意一项就可以知道要做什么了。甚至不需要看明白, 只要把这个命令复制到终端里执行就可以了, 之后在慢慢体会去。
另外,我还有(也许是坏的)习惯将命令输出的内容作一些变换。
比如将"/usr/src/linux-headers-3.8.0-25-generic"中的3.8.0-25-generic再替换回$(uname -r), "63682074-65645f69-682a2076-2c766564"替换成星号, 将"[354923.092409]"给删除掉,等等。
尽量在其他环境下重复执行指令能有相同的输出。
还会将[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
这种与问题无关的杂乱信息给去掉。
$ ls -1 /boot/config* | sed "s|$(uname -r)|"'$(uname -r)|'
/boot/config-$(uname -r)
$ sed -r -n 's|^Chipid\t\t: [0-9a-z]{8}-[0-9a-z]{8}-[0-9a-z]{8}-[0-9a-z]{8}$|Chipid\t\t: -**-**-**|p' /proc/cpuinfo
Chipid : ***-**-**-*******
$ dmesg | sed '$!d;s|^[[ 0-9]+.[0-9]+] ||'
去掉dmesg的时间戳还可以 $ echo N | sudo tee /sys/module/printk/parameters/time
具体config-后跟的是什么,chipid是多少,dmesg的最后一条的时间戳其实都是噪音信息。