This commit is contained in:
Ciro Santilli
2017-05-09 19:59:56 +01:00
parent 8eb878c24e
commit 338756a029
9 changed files with 67 additions and 3 deletions

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "buildroot"]
path = buildroot
url = https://github.com/buildroot/buildroot

6
Config.in Normal file
View File

@@ -0,0 +1,6 @@
config BR2_PACKAGE_KERNEL_MODULE
bool "kernel_module"
help
Kernel module hello world.
http://example.com/

10
Makefile Normal file
View File

@@ -0,0 +1,10 @@
obj-m += hello.o
ccflags-y := -Wno-declaration-after-statement -std=gnu99
.PHONY: all clean
all:
$(MAKE) -C '$(LINUX_DIR)' M='$(PWD)' modules
clean:
$(MAKE) -C '$(LINUX_DIR)' M='$(PWD)' clean

View File

@@ -4,6 +4,6 @@
1. [Build](build.md) 1. [Build](build.md)
1. [kmod](kmod.md) 1. [kmod](kmod.md)
1. Examples 1. Examples
1. [Host](host/) 1. [Host](host/)
1. Buildroot
TODO: use Buildroot as in this answer http://stackoverflow.com/a/38813400/895245 to install and test modules on QEMU. 1. [hello](hello.c)

1
buildroot Submodule

Submodule buildroot added at 083c0735e9

1
external.desc Normal file
View File

@@ -0,0 +1 @@
name: KERNEL_MODULE

20
external.mk Normal file
View File

@@ -0,0 +1,20 @@
################################################################################
#
# kernel_module
#
################################################################################
KERNEL_MODULE_VERSION = 1.0
KERNEL_MODULE_SITE = ..
KERNEL_MODULE_SITE_METHOD = local
define KERNEL_MODULE_BUILD_CMDS
$(MAKE) -C '$(@D)' LINUX_DIR='$(LINUX_DIR)' PWD='$(@D)' CC='$(TARGET_CC)' LD='$(TARGET_LD)'
endef
define KERNEL_MODULE_INSTALL_TARGET_CMDS
$(INSTALL) -D -m 0755 '$(@D)/kernel_module.ko' '$(TARGET_DIR)/kernel_module.ko'
endef
$(eval $(kernel-module))
$(eval $(generic-package))

13
hello.c Normal file
View File

@@ -0,0 +1,13 @@
#include <linux/module.h>
#include <linux/kernel.h>
int init_module(void)
{
printk(KERN_INFO "hello init\n");
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "hello cleanup\n");
}

10
run Executable file
View File

@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -e
cd buildroot
make BR2_EXTERNAL="$(pwd)/.." qemu_x86_64_defconfig
echo '
BR2_TOOLCHAIN_EXTERNAL=y
BR2_PACKAGE_KERNEL_MODULE=y
' >> .config
make BR2_JLEVEL="$(($(nproc) - 2))"
qemu-system-x86_64 -M pc -kernel output/images/bzImage -drive file=output/images/rootfs.ext2,if=virtio,format=raw -append root=/dev/vda -net nic,model=virtio -net user