Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

03 module task #119

Open
wants to merge 4 commits into
base: Maryna.Malakhova
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions 03_module/simple_module/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
TARGET = msimplemodule
obj-m += $(TARGET).o
default:
$(MAKE) -C $(BUILD_KERNEL) M=$(CURDIR) modules

clean:
$(MAKE) -C $(BUILD_KERNEL) M=$(CURDIR) clean

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makefile expects BUILD_KERNEL being defined in environment,
but neither code, nor commit message don't explain this.

51 changes: 51 additions & 0 deletions 03_module/simple_module/log.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/mnt # uname -a
Linux (none) 4.19.176 #4 SMP Tue Mar 16 12:55:37 EET 2021 armv7l GNU/Linux
/mnt # lsmod
/mnt # insmod msimplemodule.ko
[ 400.031994] simple module: iparam = -1
insmod: can't insert 'msimplemodule.ko': Operation not permitted
/mnt #
/mnt #
/mnt #
/mnt # dmesg -c
[ 400.031994] simple module: iparam = -1
/mnt #
/mnt # lsmod
/mnt #
/mnt #
/mnt # insmod msimplemodule.ko iparam=0
[ 477.652962] simple module: iparam = 0
/mnt # dmesg -c
[ 477.652962] simple module: iparam = 0
/mnt #
/mnt #
/mnt # lsmod
msimplemodule 16384 0 - Live 0xbf020000 (O)
/mnt # rmmod msimplemodule.ko
/mnt # insmod msimplemodule.ko iparam=1
[ 498.952910] simple module: iparam = 1
insmod: can't insert 'msimplemodule.ko': Operation not permitted
/mnt #
/mnt #
/mnt #
/mnt # lsmod
/mnt # dmesg -c
[ 498.952910] simple module: iparam = 1
/mnt # insmod msimplemodule.ko iparam=-1
[ 518.104298] simple module: iparam = -1
insmod: can't insert 'msimplemodule.ko': Operation not permitted
/mnt # dmesg -c
[ 518.104298] simple module: iparam = -1
/mnt #
/mnt #
/mnt # lsmod
/mnt # insmod msimplemodule.ko iparam=0
[ 531.005574] simple module: iparam = 0
/mnt #
/mnt #
/mnt #
/mnt # lsmod
msimplemodule 16384 0 - Live 0xbf038000 (O)
/mnt # dmesg
[ 531.005574] simple module: iparam = 0
/mnt # rmmod msimplemodule.ko
31 changes: 31 additions & 0 deletions 03_module/simple_module/msimplemodule.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: GPL-3.0
#define pr_fmt(fmt) "%s: " fmt, KBUILD_MODNAME
#include <linux/init.h> // Macros used to mark up functions __init __exit
#include <linux/module.h> // Core header for loading LKMs into the kernel
#include <linux/kernel.h> // Contains types, macros, functions for the kernel
#include <linux/moduleparam.h>

static int iparam = -1;
module_param(iparam, int, 0);

static int __init hello_init(void)
{
pr_debug("loading started\n");
pr_info("iparam = %d\n", iparam);
iparam = iparam > 0 ? -iparam : iparam;
return iparam;
}

static void __exit hello_exit(void)
{
pr_debug("module exits\n");
}


module_init(hello_init);
module_exit(hello_exit);

MODULE_AUTHOR("Malakhova.Maryna <[email protected]>");
MODULE_DESCRIPTION("Simple Kernel module");
MODULE_LICENSE("GPL");
MODULE_VERSION("0.1");