mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
bak
This commit is contained in:
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "buildroot"]
|
||||
path = buildroot
|
||||
url = https://github.com/buildroot/buildroot
|
||||
6
Config.in
Normal file
6
Config.in
Normal 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
10
Makefile
Normal 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
|
||||
@@ -5,5 +5,5 @@
|
||||
1. [kmod](kmod.md)
|
||||
1. Examples
|
||||
1. [Host](host/)
|
||||
|
||||
TODO: use Buildroot as in this answer http://stackoverflow.com/a/38813400/895245 to install and test modules on QEMU.
|
||||
1. Buildroot
|
||||
1. [hello](hello.c)
|
||||
|
||||
1
buildroot
Submodule
1
buildroot
Submodule
Submodule buildroot added at 083c0735e9
1
external.desc
Normal file
1
external.desc
Normal file
@@ -0,0 +1 @@
|
||||
name: KERNEL_MODULE
|
||||
20
external.mk
Normal file
20
external.mk
Normal 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
13
hello.c
Normal 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
10
run
Executable 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
|
||||
Reference in New Issue
Block a user