Coder Social home page Coder Social logo

ansanjay / kerneldev101 Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 1.0 990 KB

Comprehensive beginner's guide to kernel development: Dive into core concepts, hands-on tutorials, and best practices. Whether you're a novice or looking to refresh your skills, this repository offers essential resources to start your kernel programming journey

Makefile 32.72% C 67.28%
kernel-development kernel-modules learning-resources linux-kernel kernel-architecture kernel-beginners kernel-guide kernel-tutorials

kerneldev101's Introduction

Basics of Kernel Programming

This README provides a concise introduction to the basics of kernel programming, covering the fundamentals of device drivers, kernel modules, and more.

What is a Device Driver?

A device driver, often simply referred to as a 'driver,' is a software component that facilitates interaction between the computer's OS and a hardware device.

+----------+     +----------+     +----------+
|   User   |     |  Kernel  |     | Hardware |
+----------+     +----------+     +----------+
     ^                ^                ^
     |                |                |
User Interface   Kernel Interface   Hardware Interface

A device driver essentially serves as the mediator with:

  • One side communicating with the kernel
  • One side interfacing with the hardware
  • One side interacting with the user

What is a Kernel Module?

Traditionally, to add functionalities to the kernel, it had to be recompiled and the system rebooted. Kernel Modules change this by allowing code to be dynamically loaded and unloaded from the kernel upon demand.

Terminology:

  • Loadable Kernel Modules (LKM): Another name for Kernel Modules.
  • Extension: .ko which stands for Kernel Object.

Standard Location:

By default, modules are stored in /lib/modules/<kernel version> on the root file system.

Device Driver vs Kernel Modules:

While every device driver is a kernel module, not all kernel modules are device drivers. Kernel modules serve various purposes, including:

  1. Device Drivers
  2. File Systems
  3. System Calls
  4. Network drivers (e.g., those implementing TCP/IP)
  5. TTY line disciplines (for terminal devices)

Advantages:

  1. Memory efficient as they can be loaded/unloaded on demand.
  2. No need to reboot after every modification.
  3. Bugs in modules don't necessarily halt the system.
  4. Easier debugging and maintenance.
  5. Simplified management for multiple machines.

Disadvantages:

  1. Consumes more memory due to module management.
  • Module management consumes unpageable kernel memory.
  • A basic kernel with a number of modules loaded will consume more memory than a equivalent kernel module with the drivers compiled into the kernel image itself.
  1. Modules load late in the boot process , so essential features must be in the base kernel.
  • so all core functionality should be in the base kernel.
  1. Static kernels prevent run-time modifications, enhancing security.

Configuration:

To support modules, the kernel should have the CONFIG_MODULES=y option enabled.

Types:

  1. In-Source Tree: Present within the Linux Kernel Source Code.
  2. Out-of-Tree: Absent from the Linux Kernel Source Code, though they can eventually become in-tree modules.

Basic Commands:

  • List Modules: lsmod (Info derived from /sys/modules).

  • gives infor on size of module.

  • used by field explains the dependency

  • Module Information: modinfo provides detailed information about a module.

Module information for module ip6_tables

Module information for module cec

Note -

  • parm : acceptable parameter for the module
  • intree : It's an intree module

With this foundation, you're ready to delve deeper into the fascinating world of kernel programming.

kerneldev101's People

Contributors

anamikasanjay avatar ansanjay avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

ankurvaishley

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.