How to start developing and debugging the Linux Kernel? - linux

I want to start some Linux development for my research. Writing few simple scheduling algorithms and test them. I have few questions:
1) How do you develop for the linux kernel? IDE? How do you import the kernel files and see how they are related or connected?
2) Once you write your code, how do you simulate/debug it? I mean one can't just build the kernel for 20 - 30 minutes, make a new image and change boot.ini each time. This is a lenghty process plus you can't simulate or debug just observe if it works or not.
3) Is there A guide for starting developing in Linux. I find the lack of documentation surprising
I am developing for ARM-based boards
Excuse my ignorance.
Thanks

How do you develop for Linux kernel?
There are many components in the Linux kernel. Typically, kernel is divided into core and driver parts.
Core includes scheduling, MMU, memory management, process management etc
Drivers includes file system, networking, peripheral device drivers, USB etc
IDE is not a must to develop kernel code. For kernel veterans, VIM/nano is also OK. The development environment is up to you. If you are new to the kernel code, you want to build the function relationship views, some tools can be helpful:
Source Insight (Commercial)
vim + ctags (http://vim.wikia.com/wiki/Single_tags_file_for_a_source_tree)
How to debug it?
There are many Linux favors/distributions. You can use Software emulator or Hardware boards to debug the kernel. Android is based on Linux and there are many mobile phones or development boards that support Android. iOS is also derived from Linux and it is its own debug method.
Where to find the kernel documents?
For kernel part, there are many readme articles in kernel source tree. e.g. http://lxr.free-electrons.com/source/Documentation/debugging-via-ohci1394.txt
printk is powerful enough for newbies.
For ARM part, there are many articles in infocenter.arm.com
Debugging Linux kernels using DS-5
http://infocenter.arm.com/help/topic/com.arm.doc.den0024a/ch18s03s03.html?resultof=%22%6b%65%72%6e%65%6c%22%20

Related

What is SoC (system on chip)? Does Renesas V850 have a system on it?

I have experience writing a C program and burning the program into a chip using an IDE provided by the chip manufacturer.
I also heard that there is a concept called SoC, which means an operating system, like Linux, is running on a chip. In this case, I can run my program on the chip just like on a Linux PC.
I don't really know the differences between these two kinds of chips. Are they the same? Can I install Linux on every chip?
And I have to use a chip called Renesas V850 in my work. Which kind of chip is this V850?
SoC is just a marketing term for 'more than a processor on a chip'. It doesn't mean Linux or operating system.
Years ago, each part of a system was on its own chip: processor, serial port, memory, ADC, DAC, etc. You had a PCB and a schematic that tied them all together.
Over time, more and more got integrated into the processor, particularly for application-specific processors and microcontrollers. Today, pretty much only big iron processors like Intel and AMD flagship processors are stand-alone, and even then there's some x86 chip produced that are 'SoC's (like the AMD Geode line, if that's still around). Everything else has USB ports, serial ports, ADCs, DACs, even wireless radios integrated into the same die.
As for 'what is a Renasas v850?' You'd do better to google that and read the product documentation. It isn't an ARM or MIPs core, and it doesn't appear to support the mainline Linux kernel, only μClinux.
The Renesas V850 Wikipedia page states that the Linux kernel support for v850 has been absent since version 2.6.27 (which released in 2008).
Typically, you need to know what group your chip belongs to and to read more about it on Renesas website. They provide all the documentation you may need. There is also a section for application notes and sample code that may also help.

Linux network driver port to ARM

I have a Linux network driver that was originally written for 2.4 kernel. It works perfect.
I want to port it to kernel 2.6.31 and then to ARM Linux with same kernel i.e. 2.6.31. I have actually done some minor changes to the driver so that it is able to compile under kernel 2.6.31 and it also loads and unloads without crashing. It also cross compiles for the ARM Linux. But I am unable to test it on ARM so far.
How do I check that the driver is fully compatible with the target kernel, and what considerations shall be made to make it compatible with ARM.
The driver is a virtual network device driver.
Thanks in advance.
Maybe you could use Qemu ( http://wiki.qemu.org/Main_Page) to emulate an ARM platform to be able to test your driver.
You cannot check the driver like that - you have to consider the API changes within 2.6.x series kernel. The changes are quite significant and the overall of the API's from the 2.4 series which is not currently in use.
I would suggest you to go here to the Amazon book store for this book in particular. The book is called 'Essential Linux Device Drivers', by Sreekrishnan Venkateswaran. A very well detailed explanation that will be your guidance in ensuring it works properly.
Since you mentioned the device driver is a network, presumably char device (You're not accessing it in blocks), well, the good news is that the 2.6.x series kernel APIs for the character devices are significantly easier and more centralized to focus on - in fact a lot of the framework is already in place in which the author of said book explains very clearly.
By the way, the book focusses on the latter 2.6.x series after 2.6.19, so this will help you clue in on what needs to be done to ensure your driver works.
You did not specify the ARM chipset you're targetting?
As for testing... well.. perhaps the best way to do this, this is dependant on how you answer the above question to you regarding ARM chipset - if its ARMv6, then perhaps, a cheap android handset that you can easily unlock and root, and pop the kernel in there and see what happens - sorry for sounding contrived but that's the best thing I can think of and that's what pops into my head, to enable you to test it out for ease of testing :)
PS: A lot of cheap ARMv6 handsets would have kernel 2.6.32 running Froyo if that's of any help!

How to use QEMU for learning ARM Linux kernel development?

I want to learn it like developing some device driver etc and use QEMU for this because i have no hardware board for ARM like beagle board. What you guys suggest? Can i use Qemu simulator to learn Linux kernel on ARM targets? or any other option i should try ?
It depends on what you want to learn: hardware or software. If you really want to experiment with the different GPIO output to implement things like servo motor control, LED light blinking and display, a cheap board (eg, Raspberry Pi, about USD25) is much preferred.
But if you want to learn software in general, qemu is definitely much faster, and it lets you see the internal of what is happening. Experimenting with hardware will require oscilloscope etc. But experiment with software will depends on the error output of what others has implemented in their software.
As for drivers development, first version should be rapidly developed on QEMU. But testing which naturally involved hardware, should be done on the hardware.
Bottomline is: x86 is so much faster, that cross-crompilation is always done on x86 before it gets booted on the ARM board. Compiling on the board is too time consuming, and sometimes it may involved considerable amount of storage space for development libraries and source codes.
I used Qemu a while back to develop device drivers for an embedded programming class. It worked quite well. At the time we were learning device driver programming and then transitioning to Gumstix boards. I don't remember exactly what core we were using, but Qemu worked well.
I haven't done any ARM development, so I don't know if it is the best choice for learning ARM. But if you are new to drivers, it is probably a good place to start.
QEMU + Buildroot is great combination for ARM kernel development
Here is my setup that supports (mostly) both x86 and ARM: https://github.com/cirosantilli/linux-kernel-module-cheat
The kernel, toolchain, userland and QEMU are amazingly portable, that going from x86 to ARM is almost trivial.
Actually, you will seldom touch arch specifics, so you might as well start with x86.
I haven't played with ARM devices yet, only x86, but I bet it will be equally easy (i.e. not trivial due to lack of tutorials, but doable).

Paravirtualizing linux on an ARM platform

I want to learn how to port linux to an ARM platform, and I am wondering if you guys have any tips or resources on how to do that? Everything from writing the boot file to setting up the interrupt vector, writing the linker script and having the executable system running.
I was thinking of buying a developer board to learn this, maybe Beagle board as it uses an ARM cortex processor and has a big user community. Is this a good idea? I am not very familiar with linux or porting operating systems in general, so any tips on how to get started would be nice!
What I want to do in the end is to virtualize all the linux kernels privileged operations to run in a hypervisor. Currently I have a hypervisor that is run beneath freeRTOS. All freeRTOS privileged operations (very few operations) have been changed to trap into the hypervisor by generating a SWI interrupt which leads to the hypervisor. What I want to do is too extend it to Linux instead which is more complex and alot bigger.
Best regards
Mr Gigu
You might want to check out the way it's done in L4Linux.
I would say start here...
http://elinux.org/BeagleBoard
From what I have seen, the Beagle Board seems to be one of the most widely supported boards 'community-wise' at this level.
As far as your questions goes, I am not totally sure what it is. If you are diving into all this embedded OS and linux stuff and want to have fun, that board is the probably way to go if you have some background with embedded development (which it seems you do). As far as professional development, not so sure...

Learning kernel hacking and embedded development at home? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I was always attracted to the world of kernel hacking and embedded systems.
Has anyone got good tutorials (+easily available hardware) on starting to mess with such stuff?
Something like kits for writing drivers etc, which come with good documentation and are affordable?
Thanks!
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.
An absolute must is this book by Rubini. (available both as a hardcopy or a free soft copy)
He gives implementations of several dummy drivers that don't require that you have any hardware other than your pc. So for getting started in kernel development it's the easiest way to go.
As for doing embedded work I would recommend purchasing one of the numerous SBC (single board computers) that are out there. There are a number of these that are based on x86 processors, usually with PC/104 interfaces (electrically PC/104 is identical to the ISA bus standard, but based on stackable connectors rather than edge connectors - very easy to interface custom hardware to)
They usually have vga connectors that make it easier to do debugging.
For embedded Linux hacking, simple Linksys WRT54G router that you can buy everywhere is a development platform on its own http://en.wikipedia.org/wiki/Linksys_WRT54G_series:
The WRT54G is notable for being the first consumer-level network device that had its firmware source code released to satisfy the obligations of the GNU GPL. This allows programmers to modify the firmware to change or add functionality to the device. Several third-party firmware projects provide the public with enhanced firmware for the WRT54G.
I've tried installing OpenWrt and DD-WRT firmware on it. You can check those out as a starting point for hacking on a low-cost platform.
For starters, the best way is to read a lot of code. Since Linux is Open Source, you'll find dozens of drivers. Find one that works in some ways like what you want to write. You'll find some decent and relatively easy-to-understand code (the loopback device, ROM fs, etc.)
You can also use the lxr.linux.no, which is the Linux code cross-referenced. If you have to find out how something works, and need to look into the code, this is a good and easy way.
There's also an O'Reilly book (Understanding the Linux Kernel, the 3rd edition is about the 2.6 kernels) or if you want something for free, you can use the Advanced Linux Programing book (http://www.advancedlinuxprogramming.com/). There are also a lot of specific documentation about file systems, networking, etc.
Some things to be prepared for:
you'll be cross-compiling. The embedded device will use a MIPS, PowerPC, or ARM CPU but won't have enough CPU power, memory, or storage to compile its own kernel in a reasonable amount of time.
An embedded system often uses a serial port as the console, and to lower the cost there is usually no connector soldered onto production boards. Debugging kernel panics is very difficult unless you can solder on a serial port connector, you won't have much information about what went wrong.
The Linksys NSLU2 is a low-cost way to get a real embedded system to work with, and has a USB port to add peripherals. Any of a number of wireless access points can also be used, see the OpenWrt compatibility page. Be aware that current models of the Linksys WRT54G you'll find in stores can no longer be used with Linux: they have less RAM and Flash in order to reduce the cost. Cisco/Linksys now uses vxWorks on the WRT54G, with a smaller memory footprint.
If you really want to get into it, evaluation kits for embedded CPUs start at a couple hundred US dollars. I'd recommend not spending money on these unless you need it professionally for a job or consulting contract.
I am completely beginner in kernel hacking :) I decided to buy two books "Linux Program Development: a guide with exercises" and "Writing Linux Device Drivers: a guide with exercises" They are very clearly written and provide good base to further learning.

Resources