Skip to content

Spin42/kmod_loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KmodLoader

Loads and unloads out-of-tree Linux kernel modules via insmod/rmmod.

KmodLoader provides idempotent kernel module lifecycle management for embedded Linux and Nerves systems that need to load .ko files from non-standard paths. It wraps the low-level insmod and rmmod commands with proper error handling, /proc/modules introspection, device node polling, and pseudo-filesystem mounting.

Why not modprobe?

modprobe relies on module dependency metadata in /lib/modules/<version>/, which doesn't exist for out-of-tree modules copied from vendor partitions. insmod loads a .ko directly by path, which is what we need.

Installation

Add kmod_loader to your list of dependencies in mix.exs:

def deps do
  [
    {:kmod_loader, "~> 0.1.0"}
  ]
end

Usage

Loading a module

# Load a kernel module from a .ko file
:ok = KmodLoader.insmod("/lib/modules/my_driver.ko")

# Load idempotently (skip if already loaded)
:ok = KmodLoader.insmod("/lib/modules/my_driver.ko", skip_if_loaded: true)

Unloading a module

:ok = KmodLoader.rmmod("my_driver")

Checking if a module is loaded

true = KmodLoader.loaded?("my_driver")

# Hyphens are normalized to underscores automatically
true = KmodLoader.loaded?("my-driver")

Waiting for a device node

After loading a driver, you may need to wait for its device node to appear:

:ok = KmodLoader.System.wait_for_device("/dev/wmtdetect", 10)

Mounting pseudo-filesystems

Idempotently mount pseudo-filesystems like configfs or debugfs:

:ok = KmodLoader.System.mount_pseudo_fs("configfs", "/sys/kernel/config")
:ok = KmodLoader.System.mount_pseudo_fs("debugfs", "/sys/kernel/debug")

API Overview

Function Description
KmodLoader.insmod/2 Load a .ko kernel module by path
KmodLoader.rmmod/1 Unload a kernel module by name
KmodLoader.loaded?/1 Check if a module is loaded via /proc/modules
KmodLoader.System.safe_cmd/2 Execute a system command with error handling
KmodLoader.System.wait_for_device/2 Poll for a device node to appear
KmodLoader.System.mount_pseudo_fs/2 Idempotently mount a pseudo-filesystem
KmodLoader.System.mounted?/1 Check if a path is a mount point

License

MIT

About

Load and unload kernel modules in Elixir

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages