Passing command line Arguments / Parameters to Linux kernel module

In Our previous post, “Writing first Linux kernel Module and understanding Kernel module compilation, loading and unloading” We learned how to write a simple Linux kernel module. Lets see an example of how to pass the loading time parameters to the kernel module. The load time parameter passing is very helpful to enable / disable … Read more

How initrd is mounted by Linux kernel

Lets first try to understand what are the ways to mount the root file system, Altough the documentation from Documentation/early-userspace/README inside kernel source code is bit outdated, it is still has valid information as below, The kernel has currently 3 ways to mount the root filesystem: a) all required device and filesystem drivers compiled into … Read more

How kernel images are built / compiled

/bin/bash scripts/link-vmlinux.sh arm-linux-gnueabihf-ld -EL -p –no-undefined -X –pic-veneer –build-id LD vmlinux.o scripts/mod/modpost -m -a -o ./Module.symvers -S vmlinux.o GEN .version /bin/bash ./scripts/mkcompile_h include/generated/compile.h \“arm” “y” “” “arm-linux-gnueabihf-gcc -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-dwarf2-cfi-asm -mabi=aapcs-linux -mno-thumb-interwork -mfpu=vfp -funwind-tables -marm -D__LINUX_ARM_ARCH__=6 -march=armv6k -mtune=arm1136j-s -msoft-float -Uarm -fno-delete-null-pointer-checks -O2 –param=allow-store-data-races=0 -Wframe-larger-than=1024 -fno-stack-protector -Wno-unused-but-set-variable -fomit-frame-pointer -fno-var-tracking-assignments … Read more

Kernel startup entry point / how Linux kernel boots

We will consider our hardware platform as ARM, so the kernel startup entry point code is at arch/arm/kernel/head.S This is normally called from the decompressor code. The requirementsare: MMU = off, D-cache = off, I-cache = dont care, r0 = 0,r1 = machine nr, r2 = atags or dtb pointer. This code is mostly position … Read more

How Linux Kernel Module Loading works ?

The kernel bus drivers probe for devices. For every detected device, the kernel creates an internal device structure and the driver core sends an event to udev. Devices identify themselves by an id, which tells what kind of device it is. Usually these id’s consist of vendor and product id and other susbsytem specific values. … Read more

Understanding Linux kernel likely and unlikely macros

Linux kernel defines likely and unlikely macros in kernel source code include/linux/compiler.h as # define likely(x) __builtin_expect(!!(x), 1) # define unlikely(x) __builtin_expect(!!(x), 0) As per GCC documentation, __builtin_expect has been described as, if (__builtin_expect (x, 0)) foo (); indicates that we do not expect to call foo, since we expect x to be zero. Since … Read more

Understanding sysfs and USB

Reference’s 1) http://www.makelinux.net/ldd3/chp-13-sect-2.shtml 2) Allen Stern’s description $ cd /sys/bus/usb/devices /sys/bus/usb/devices# ls -al usb* usb1 -> ../../../devices/pci0000:00/0000:00:1d.7/usb1 usb2 -> ../../../devices/pci0000:00/0000:00:1d.0/usb2 usb3 -> ../../../devices/pci0000:00/0000:00:1d.1/usb3 usb4 -> ../../../devices/pci0000:00/0000:00:1d.2/usb4 usb5 -> ../../../devices/pci0000:00/0000:00:1d.3/usb5 This shows that it has 5 root hubs. Now, lets try to correlate it with lsusb. A simple shell script which will print only RootHubs available … Read more

Understanding Linux Device Tree Syntax (DTS)

DTB = Devicetree blob. Compact binary representation of the devicetree.DTC = Devicetree compiler. An open source tool used to create DTB files from DTS files.DTS = Devicetree syntax. A textual representation of a devicetree consumed by the DTC. See Appendix A Devicetree Source Format (version 1) A boot program (bootloader) loads a devicetree into a … Read more

How to recreate dts file from a running embedded target

As we have seen in “How to cross compile static dtc for ARM” we are able to get the DTC cross compiled statically which we will push to the embedded target which exposes the device tree from proc file system. Using this statically compiled dtc, we will reverse engineer to create human readable DTS file … Read more