Learning Kernel Hacking and Embedded Development at Home

Learning kernel hacking and embedded development at home?

If you are completely new to kernel development, i would suggest not starting with hardware development and going to some "software-only" kernel modules like proc file / sysfs or for more complex examples filesystem / network development , developing on a uml/vmware/virtualbox/... machine so crashing your machine won't hurt so much :) For embedded development you could go for a small ARM Development Kit or a small Via C3/C4 machine, or any old PC which you can burn with your homebrew USB / PCI / whatever device.

A good place to start is probably Kernelnewbies.org - which has lots of links and useful information for kernel developers, and also features a list of easy to implement tasks to tackle for beginners.

Some books to read:

Understanding the Linux Kernel - a very good reference detailing the design of the kernel subsystems

Linux Device Drivers - is written more like a tutorial with a lot of example code, focusing on getting you going and explaining key aspects of the linux kernel. It introduces the build process and the basics of kernel modules.

Linux Kernel Module Programming Guide - Some more introductory material

As suggested earlier, looking at the linux code is always a good idea, especially as Linux Kernel API's tend to change quite often ... LXR helps a lot with a very nice browsing interface - lxr.linux.no

To understand the Kernel Build process, this link might be helpful:

Linux Kernel Makefiles (kbuild)

Last but not least, browse the Documentation directory of the Kernel Source distribution!

Here are some interesting exercises insolently stolen from a kernel development class:

  • Write a kernel module which creates the file /proc/jiffies reporting the current time in jiffies on every read access.
  • Write a kernel module providing the proc file /proc/sleep. When an application writes a number of seconds as ASCII text into this file ("echo 3 > /proc/sleep"), it should block for the specified amount of seconds. Write accesses should have no side effect on the contents of the file, i.e., on the read accesses, the file should appear to be empty (see LDD3, ch. 6/7)
  • Write a proc file where you can store some text temporarily (using echo "blah" > /proc/pipe) and get it out again (cat /proc/pipe), clearing the file. Watch out for synchronisation issues.
  • Modify the pipe example module to register as a character device /dev/pipe, add dynamic memory allocation for write requests.
  • Write a really simple file system.

Learning Kernel Programming

Try to get hold of Robert Love's book on Linux Kernel Programming. Its very concise and easy to follow.

After that or along with that, you may want to take a look at "Understanding the Linux kernel".But I wouldn't recommend it during the early stages.

Also, look at the Linux kernel programming guide. Since a lot can be learnt from programing kernel modules, that guide will help you. And yes, for a lot of information, consult the 'documentation' sub-directory of the Kernel sources tarball.

Tips for learning embedded linux

You will need:

1 - Boards: I started with a beagleboard. A new beaglebone black is available now. There's a large support community for the beagles; many howto pages here and here, and ready to install images. You can also build the image yourself (step 3). These boards have most of the peripherals that you may need to play with, and can also be used as extra computer !

2 - Books: As Mali noted, Linux is a fast moving object, but in the early phases of learning you will need a solid reference. I'd suggest "Embedded Linux Primer: A Practical Real-World Approach" as it has many examples and takes you step-by-step. There's also "Building Embedded Linux Systems".

3 - The firmware: a) toolchain, b) root filesystem and c) kernel image. "Buildroot" is the easiest to start with. Openembedded and Yocto have a very steep learning curve. "Embedded Linux Primer: A Practical Real-World Approach" has some examples on how to use buildroot.

learning linux drivers

Free software magazine has an article about that :

http://www.freesoftwaremagazine.com/articles/drivers_linux?page=0%2C0

this tutorial is downloadable as PDF.

This article describes the programming of a USB driver for a home made multicolored light. I think its quite interesting :)

http://www.linuxjournal.com/article/7353

For more "complete" drivers, I would look at the code of "serial" drivers (meaning driver for devices connected to a plain old serial port or USB port) because the data transfer between your computer and the device feels more natural.

How to get started with Linux kernel development

Linux Kernel Newbies, imho, is the best resource for who wants to start in linux kernel development.

Maybe you are interested to buy a book:

  • Linux Kernel Development 3rd edition 2010;
  • Understanding the linux kernel 3rd edition 2005;
  • Linux Device Drivers 3rd edition 2005.

Free resources (only a few of them):

  • Linux Kernel Hacking;
  • Hacking the Linux 2.6 kernel, Part 1: Getting ready;
  • Hacking the Linux 2.6 kernel, Part 2: Making your first hack;
  • Kernel coverage at LWN.net;
  • Unreliable Guide To Hacking The Linux Kernel;
  • The newbie's guide to hacking the Linux kernel;
  • vger.kernel.org - list services for the linux kernel developers

How to start learning Android kernel development

Android kernels (and basic build instructions how to build them) can be found at http://source.android.com/source/building-kernels.html. You need a rootable phone to install the custom kernels, and I would recommend Linux as a developer platform. Maybe better to write some USB drivers for beginning.

Learning Linux Kernel programming on a virtual machine on Ubuntu?

Yes you can safely test kernel modules on a virtual machine!
I'll give you some links that may help:
watch this site

  • http://free-electrons.com/

in particular this book:

  • http://free-electrons.com/doc/books/ldd3.pdf

Also this guide:
http://www.tldp.org/HOWTO/Module-HOWTO/



Related Topics



Leave a reply



Submit