Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to make hello.ko kernel module under Linux?

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces how to make the hello.ko kernel module under Linux. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

1. Method 1

Compile ko files outside the kernel directory

1. Write hello module code # include # include # include MODULE_LICENSE ("GPL"); MODULE_AUTHOR ("kent"); static int _ _ init hello_init () {printk (KERN_ALERT "hello, world-this is the kernel speaking!\ n"); return 0;} static void _ exit hello_exit () {printk (KERN_ALERT "short is the life of a kernel module!\ n");} module_init (hello_init); module_exit (hello_exit) 2. Write the Makefile file ifneq of hello module ($(KERNELRELEASE)) ) obj-m:=hello.oelse KERNELDIR?=/opt/arm/linux-2.6.30.4/PWD: = $(shell pwd) modules: $(MAKE)-C $(KERNELDIR) mm $(PWD) modulesmodules_install: $(MAKE)-C $(KERNELDIR) M é n $(PWD) modules_installclean: rm-rf * .o * ~ core .depend. * .cmd * .ko * .mod.c .tmp _ versions.PHONY: modulesmodules_install cleanendif3, compile make

A hello.ko file will be generated in this directory

2. Method 2

Drivers/char compilation in memory directory

1. Write hello module code # include # include # include MODULE_LICENSE ("GPL"); MODULE_AUTHOR ("kent"); static int _ _ init hello_init () {printk (KERN_ALERT "hello, world-this is the kernel speaking!\ n"); return 0;} static void _ exit hello_exit () {printk (KERN_ALERT "short is the life of a kernel module!\ n");} module_init (hello_init); module_exit (hello_exit) 2. Add hello driver support for menu "Character devices" config HELLO tristate "hello driver" depends on ARCH_S3C2440 help this is my first driver.3 to the kernel source code. Modify the Makefile file FONTMAPFILE = cp437.uniobj-y + = mem.o random.o tty_io.o n_tty.o tty_ioctl.o tty_ldisc.o tty_buffer.o tty_port.oobj-$ (CONFIG_HELLO) + = hello.oobj-$ (CONFIG_LEGACY_PTYS) + = pty.oobj-$ (CONFIG_UNIX98_PTYS) + = pty.o4 in the same directory, configure kernel Device Drivers-- > Character devices-> hello driver5, Compile make SUBDIR=drivers/char/ modules

The drivers/char/ under the kernel directory generates the hello.ko file

Third, method three

Create another directory under the memory directory drivers/char

1. Create directory mkdir hellos2, write hello module code # include # include # include MODULE_LICENSE ("GPL"); MODULE_AUTHOR ("kent"); static int _ _ init hello_init () {printk (KERN_ALERT "hello, world-this is the kernel speaking!\ n"); return 0;} static void _ exit hello_exit () {printk (KERN_ALERT "short is the life of a kernel module!\ n");} module_init (hello_init) Module_exit (hello_exit) 3. Create the Makefile file vi Makefile# Makefile for the hellos driver#obj-$ (CONFIG_HELLOS) + = hellos.o4 in the hellos directory, modify the Kconfigmenu "Character devices" config HELLO tristate "hello driver" depends on ARCH_S3C2440 help this is my first driver.config HELLOS tristate "hellos driver" depends on ARCH_S3C2440 help this is my second driver.5 of the drivers/char directory, Modify the Makefileobj-y + = mem.o random.o tty_io.o n_tty.o tty_ioctl.o tty_ldisc.o tty_buffer.o tty_port.oobj-$ (CONFIG_HELLO) + = hello.oobj-$ (CONFIG_HELLOS) + = hellos/ # of the drivers/char directory. This is the hellos directory you just created. 6. Configure kernel Device Drivers-- > Character devices-> hellos driver7, compile make SUBDIR=drivers/char/ modules

The drivers/char/hellos/ under the kernel directory generates the hellos.ko file

Note: the kernel must make first, or an error will be reported.

On the Linux hello.ko kernel module production how to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report