Understanding Linux Kernel Module Programming

unit vi n.w
1 / 14
Embed
Share

Learn about Linux Kernel Module (LKM) programming, how to write and compile modules, and essential utilities for managing modules in the Linux kernel. Explore the steps to create and load LKMs efficiently.

  • Linux Kernel
  • Module Programming
  • LKM Steps
  • Kernel Utilities
  • Makefile

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Unit VI Recent and future trends in OS

  2. Linux Kernel Module Programming Kernel modules are piece of code, that can be loaded and unloaded from kernel on demand The kernel modules will have a .ko extension On a linux system, the kernel modules will reside inside /lib/modules/<kernel_version>/kernel/ directory

  3. Kernel Module Utilities lsmod - Lists modules that are loaded already (/proc/modules) insmod - Inserts module into kernel modinfo - Display module information rmmod - Removes module from kernel modprobe - Add or Remove modules from the kernel. modprobe is an intelligent command which will load/unload modules based on the dependency between modules.

  4. LKM steps Write a hello.c program and Makefile The program and Makefile should be kept in a single folder Execute following commands on terminal for loading and removing lkm - make - sudo insmod hello.ko - dmesg (contents of kernel buffer, reads /var/log/syslog) - lsmod - sudo rmmod hello - dmesg

  5. Files created after building the module hello.o Module object file before linking. hello.mod.c Contains module s information. hello.mod.o After compilation and linking of hello.mod.c. modules.order The order in which two or three modules get linked. Modules.symvers Symbol versions if any. hello.ko A module kernel object file after linking hello.o and hello.mod.o

  6. Makefile obj-m += hello.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean Use ref. lkm_building_external_module.pdf

  7. Makefile obj-m += hello.o -Creating a Kbuild File for an External Module make -C <path> -Change path during make M=(PWD) module Sysntaxmake -C $KDIR M=$PWD [target] -The default will build the module(s) located in the current directory, so a target does not need to be specified. All output files will also be generated in this directory. - module : The default target for external modules - clean : Remove all generated files in the module directory only

  8. printk() The kernel print function The major difference between printk() and printf() is the capability of the former to specify a loglevel Example - printk(KERN_WARNING "This is a warning!\n"); - printk(KERN_DEBUG "This is a debug notice!\n");

  9. Printk() Loglevels KERN_EMERG : An emergency condition; the system is probably dead KERN_ALERT : A problem that requires immediate attention KERN_CRIT : A critical condition KERN_ERR : An error KERN_WARNING : A warning KERN_NOTICE : A normal, but perhaps noteworthy, condition KERN_INFO : An informational message KERN_DEBUG : A debug message typically superfluous

  10. Embedded OS

  11. Nachos Nachos: Not Another Completely Heuristic Operating System Written by Tom Anderson and his students at UC Berkeley http://www.cs.washington.edu/homes/tom/nachos/

  12. Nachos 4.0 An educational OS used to teach kernel design and implementation do experiments Fact: Real hardware is difficult to handle. May break if handled wrong. Approach: Use a virtual MIPS machine Provide some basic OS elements

  13. Nachos 4.0

  14. MIPS MIPS (originally an acronym for Microprocessor without Interlocked Pipeline Stages) is a reduced instruction set computer (RISC) instruction set architecture (ISA) developed by MIPS Technologies (formerly MIPS Computer Systems, Inc.).

Related


More Related Content