How to interface your kernel module via the sysfs

In my previous blog, The first ever driver that I wrote | Ups and Downs (rajatasthana.com), I had created a very simple misc char device driver. It interacted with the user space using the simple_read_from_buffer() and simple_write_to_buffer() APIs. That is one way to interact with the user space processes, but there are other and much better ways to do this. In this blog, lets explore how can we interface a kernel module using the sys filesystem!

Continue reading ⟶

The first ever driver that I wrote

The first ever driver that I wrote was a misc char driver. It supported read and write functions and showed up in dev/rastonit. When the device node was written to, the data sent was checked and if it didn’t match with my name, it returned an error. I had written it out of kernel source tree, as a loadable kernel module, so the device was was registered when the module was loaded and the device was unregistered when the module was unloaded.

Continue reading ⟶

Physical memory organization and memory allocation and deallocation!

One of the best that has ever happened to me was that I got an opportunity to take part in the Eudyptula challenge! In that challenge, there are problems around memory allocation and deallocation, which made to explore how the kernel manages the physical memory, and the algorithms and APIs involved in the allocation and deallocation of memory. Lets get started! Physical Memory Organization Lets begin by understanding some terms:

Continue reading ⟶

Whatever Little I know about the Linux Device Model!

I know very little about the Linux Device Model, but whatever I am writing in this blog is whatever I kept in my mind and anyway got started writing my first device driver, a very very simple misc char device driver! I hope this helps anyone who is starting out… With that disclaimer, lets get started!! What is a device driver? A device driver is the interface between the OS and a hardware device.

Continue reading ⟶

Whatever I know about Memory Management!

So, remember that when a printf function call happens, we eventually make a write system call to write to the stdout. When a system call happens, we move from the user space to the kernel space — and as we know, for every thread alive there are two stacks for it, a user space and a kernel space. But, following is the process we have seen till now: and this uses all the memory available.

Continue reading ⟶

My understanding of Process and Threads!

I really have a weak memory, and am very forgetful! So, I just want to write this down so that I can come back and look at this, or even correct some facts which I might have interpreted wrongly (on that note, if you find something that is not correct, please correct me!) With that out of the way, lets get started! What is a Process and what is a thread?

Continue reading ⟶

The first kernel module that I wrote

The first program I ever wrote was a C program to print “Hello, world” on stdout; and that was exactly what my first kernel module did. It wrote “Hello world”, but this time to the kernel log buffer. This module did one extra thing though, it wrote “Goodbye world” to the kernel log buffer when removed from the kernel memory. Alright! lets go ahead and look at this kernel module…

Continue reading ⟶

What I know about the LKM Framework

Linux Kernel is a monolithic kernel. What I mean by this statement is that all the kernel components live in and share the kernel address space, and this address space is the virtual address space. Now, lets imagine that we want to write a new device driver for a certain hardware chip. One way to do this is to update the kernel source tree with the new code, build it and then test it.

Continue reading ⟶

Building the Linux Kernel from source

The aim of this blog is to describe the process of building the Linux Kernel from source. There are certain steps involved in the process, and they are: Obtain the source code configure the Linux Kernel build the kernel image and modules installing the built kernel modules setup the GRUB bootloader and initramfs image customizing the GRUB bootloader menu Step 1 — Obtaining the Linux Kernel source There are two ways in which we can obtain the Linux Kernel source code:

Continue reading ⟶

Writing a no code accountability tracker

Well hello friends! I had started a few personal projects a while back and they are not going anywhere. I usually work on them whenever I get sudden boost of energy or motivation, and that just happens once in a blue moon! The last time I worked on my project was 4 months ago! This has to change! I have been reading atomic habbits along with some friends of mine!

Continue reading ⟶