etc:users:jcmvbkbc:little-things:1
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| etc:users:jcmvbkbc:little-things:1 [2009/12/22 12:05] – создано jcmvbkbc | etc:users:jcmvbkbc:little-things:1 [2016/08/08 20:53] (current) – ↷ Page moved from users:jcmvbkbc:little-things:1 to etc:users:jcmvbkbc:little-things:1 kel | ||
|---|---|---|---|
| Line 7: | Line 7: | ||
| ===== Worklog ===== | ===== Worklog ===== | ||
| - | | + | |
| + | < | ||
| + | ├── bin/ | ||
| + | │ ├── busybox* | ||
| + | │ ├── cat -> busybox* | ||
| + | │ ├── df -> busybox* | ||
| + | │ ├── du -> busybox* | ||
| + | │ ├── insmod -> busybox* | ||
| + | │ ├── less -> busybox* | ||
| + | │ ├── ln -> busybox* | ||
| + | │ ├── ls -> busybox* | ||
| + | │ ├── lsmod -> busybox* | ||
| + | │ ├── mount -> busybox* | ||
| + | │ ├── rmmod -> busybox* | ||
| + | │ ├── sh -> busybox* | ||
| + | │ ├── top -> busybox* | ||
| + | │ └── vi -> busybox* | ||
| + | ├── dev/ | ||
| + | │ ├── pts/ | ||
| + | │ ├── console | ||
| + | │ ├── kmsg | ||
| + | │ ├── loop0 | ||
| + | │ ├── loop1 | ||
| + | │ ├── loop2 | ||
| + | │ ├── loop3 | ||
| + | │ ├── loop4 | ||
| + | │ ├── loop5 | ||
| + | │ ├── loop6 | ||
| + | │ ├── loop7 | ||
| + | │ ├── mem | ||
| + | │ ├── null | ||
| + | │ ├── ptmx | ||
| + | │ ├── random | ||
| + | │ ├── systty | ||
| + | │ ├── tty | ||
| + | │ ├── tty0 | ||
| + | │ ├── tty1 | ||
| + | │ ├── tty2 | ||
| + | │ ├── urandom | ||
| + | │ └── zero | ||
| + | ├── lib/ | ||
| + | │ └── modules/ | ||
| + | │ | ||
| + | ├── proc/ | ||
| + | ├── sbin/ | ||
| + | ├── sys/ | ||
| + | ├── tmp/ | ||
| + | ├── init* | ||
| + | └── test.ko | ||
| + | </ | ||
| + | * make /init like this: | ||
| + | < | ||
| + | #! /bin/sh | ||
| + | |||
| + | mount -t proc proc /proc | ||
| + | mount -t sysfs sysfs /sys | ||
| + | mount -t devpts devpts /dev/pts | ||
| + | |||
| + | while : | ||
| + | do | ||
| + | /bin/sh | ||
| + | done | ||
| + | </ | ||
| + | * get a linux, configure and compile it: | ||
| + | < | ||
| + | git clone git:// | ||
| + | make ARCH=i386 defconfig | ||
| + | # turn off networking as we don't need it | ||
| + | # turn on initramfs: | ||
| + | # General setup ---> | ||
| + | # [*] Initial RAM filesystem and RAM disk (initramfs/ | ||
| + | # | ||
| + | make ARCH=i386 menuconfig | ||
| + | make ARCH=i386 -j3 bzImage | ||
| + | </ | ||
| + | * make test.c, module source: | ||
| + | < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | static irqreturn_t test_irq_handler(int i, void *dev) | ||
| + | { | ||
| + | static spinlock_t lock = __SPIN_LOCK_UNLOCKED(lock); | ||
| + | unsigned long flags; | ||
| + | |||
| + | printk(KERN_INFO " | ||
| + | spin_lock_irqsave(& | ||
| + | printk(KERN_INFO " | ||
| + | spin_unlock_irqrestore(& | ||
| + | return IRQ_HANDLED; | ||
| + | } | ||
| + | |||
| + | static int test_irq; | ||
| + | static int test_irq_no; | ||
| + | #define IRQ_NO test_irq_no | ||
| + | |||
| + | module_param(test_irq_no, | ||
| + | MODULE_PARM_DESC(test_irq_no, | ||
| + | |||
| + | static int __init test_init(void) | ||
| + | { | ||
| + | int rc; | ||
| + | printk(KERN_INFO " | ||
| + | rc = request_irq(IRQ_NO, | ||
| + | printk(KERN_INFO " | ||
| + | if (!rc) | ||
| + | test_irq = IRQ_NO; | ||
| + | return 0; | ||
| + | } | ||
| + | |||
| + | static void __exit test_exit(void) | ||
| + | { | ||
| + | printk(KERN_INFO " | ||
| + | if (test_irq) | ||
| + | free_irq(test_irq, | ||
| + | } | ||
| + | |||
| + | module_init(test_init); | ||
| + | module_exit(test_exit); | ||
| + | |||
| + | MODULE_AUTHOR(" | ||
| + | MODULE_LICENSE(" | ||
| + | </ | ||
| + | * make a Makefile for it: | ||
| + | < | ||
| + | PWD = $(shell pwd) | ||
| + | EXTRA_CFLAGS += -Wall | ||
| + | |||
| + | obj-m += test.o | ||
| + | |||
| + | default: modules | ||
| + | |||
| + | modules clean: | ||
| + | make -C $(KDIR) M=$(PWD) $@ | ||
| + | </ | ||
| + | * compile it like this: make -C " | ||
| + | * copy test.ko to the rootfs / and rebuild bzImage | ||
| + | * run it in qemu: qemu -kernel bzImage | ||
| + | * load module inside the shell in qemu: insmod test.ko test_irq_no=1 | ||
| + | * press and release keys (irq 1 is keyboard interrupt) | ||
| + | * see it there: cat / | ||
| + | * unload it: rmmod test | ||
| + | |||
| + | Code: ftp:// | ||
| ===== Conclusion ===== | ===== Conclusion ===== | ||
| Line 13: | Line 159: | ||
| * spinlock re-acquisition locks up hard; | * spinlock re-acquisition locks up hard; | ||
| * qemu internal hardware objects are not that easily navigable -- to be continued; | * qemu internal hardware objects are not that easily navigable -- to be continued; | ||
| + | |||
| + | {{tag> | ||
etc/users/jcmvbkbc/little-things/1.1261472732.txt.gz · Last modified: 2009/12/22 12:05 by jcmvbkbc