Linux Device Driver Hacks

This blog will contain the code snippets that are needed to implement particular feature in kernel. I’ll mainly focus on code snippet rather than the explanation. Again! this blog may not be fully correct. You’re expected to “check the facts/code” before applying. Please correct me, if i’m wrong. I’ll be more happy to accept the changes. This Blog is not beginner friendly. Kernel MODULE MACRO Handling module parameters #include <linux/moduleparam.h> // No need to include this. 'linux/module.h' included it. module_param(name, type, perm); MODULE_PARM_DESC(myarr,"this is my array of int"); inmod module.ko param=value Char Device There are 2 way to create char device. Creating the device node through ‘kernel module’ or using mknod ...

June 11, 2026 · 2 min · Ankit

Understanding Forward Declarations in C

One of the best ways to learn systems programming is by reading real-world code. Recently, while reading the Linux kernel source, I noticed something interesting inside drivers/pinctrl/core.h: #include <linux/kref.h> #include <linux/list.h> #include <linux/mutex.h> #include <linux/radix-tree.h> #include <linux/types.h> #include <linux/pinctrl/machine.h> struct dentry; struct device; struct device_node; struct module; At first glance, these lines seem incomplete. We see declarations like struct device; but no actual definition. Where is the complete structure with all its members? Why didn’t file defining this structure isn’t included? ...

May 17, 2026 · 6 min · Ankit

C Memory Layout: Structs, Unions, and a Linux Kernel Patch

Overview C memory layout looks simple in isolation: structs store fields sequentially, unions overlap memory, and flexible array members allow variable-sized trailing storage. But combining these features can create subtle layout issues. While working on a Linux kernel selftest, I encountered a case where a union contained multiple structures, each ending with a flexible array member at different offsets. Although the code was functionally correct, this confused the compiler into treating the union as effectively variable-sized, triggering a layout warning. ...

May 4, 2026 · 11 min · Ankit

Configure U-boot For Beaglebone Black

Overview U-Boot (Universal Boot Loader) is the go-to bootloader for embedded Linux systems. If you’re working with the BeagleBone Black (BBB), building U-Boot from source gives you full control over the boot process, from initializing hardware to loading your kernel. This guide walks you through cross-compiling and installing U-Boot on the BBB from scratch. This blog will explain how to compile and install U-Boot, and then either manually boot from the U-Boot prompt or use uEnv.txt to autoboot the kernel. You can also use extlinux/extlinux.conf to boot the kernel. ...

April 22, 2026 · 7 min · Ankit

Build and Install Linux Kernel For Beaglebone Black

Overview The BeagleBone Black (BBB) uses an ARM Cortex-A8 32 bit processor, so the kernel must be cross-compiled on an x86 machine and then deployed to the board. This blog will assume that you already have a os[debian/ubuntu] installed on your sd card. We’ll: set up toolchain fetch kernel source configure for BBB build kernel + modules deploy to SD card / board 1. Prerequisites Make sure you have: Ubuntu (or any Linux host) Cross compiler for ARM (arm) Install required tools: ...

April 8, 2026 · 3 min · Ankit

Basics of debugging slab memory corruption via SLUB debug

Introduction Memory corruption can occur due to various bugs or defects: Uninitialized Memory Reads (UMR), Use After Free (UAF), Use After Return (UAR), double-free, memory leakage, or illegal Out Of Bounds (OOB) accesses that attempt to work upon (read/write/ execute) illegal memory regions. Since memory is dynamically allocated and freed via the kernel’s engine – the page allocator. This can lead to serious wastage (internal fragmentation) of memory. To mitigate this, the slab allocator (or slab cache) is layered upon it, serving two primary tasks – providing fragments of pages efficiently (within the kernel, allocation requests for small pieces of memory, from a few bytes to a couple of kilobytes), and serving as a cache for commonly used data structures. ...

February 4, 2026 · 7 min · Ankit

Linux Kernel Mentorship Program

Introduction I have been using Linux for the last two years and gradually developed an interest in systems programming and C. The mentorship prerequisites includes tasks like building and booting the Linux kernel, writing a basic kernel module, decoding stack traces, and modifying and booting a custom kernel build. Somehow, my application was accepted ;-). At first, the Linux Kernel seemed quite difficult to understand what was going on. We were initially told to choose two subsystems to work on. ...

December 8, 2025 · 3 min · Ankit

Install Ubuntu Server on Qemu

Installation of ubuntu server on qemu-x86_64 At First I want to run the custom modules on linux. But this is something that is not good to do on host machine. So i searched a lot of stuff. Tinkering with buildroot, after some days i was able to run the build on qemu. But i found out build actually didn’t have my basic tool like gnu make. Everytime i try to do something i need to find particular tool on menuconfig then make the build again. Learning was so slow. ...

August 16, 2025 · 2 min · Ankit