Porting Linux to ARM - linux

BACKGROUND
Off late, I am finding myself increasingly fascinated for better understanding of Linux. Additionally, I want to play around as well, to understand the nuances of it.
I am not a great Linux hacker. I know C,C++ etc,I have programmed in assembly for ARM and other processors, I know a bit theoretically of the workings of an OS, to a small extent of how Linux is structured (monolithic kernel etc).
Under this light, I am increasingly interested in how can a particular kernel be ported into an ARM based machine.
So my questions are:
What are the steps a developer need to take to port a kernel to an ARM based machine.
How should the development be, i.e should hardware be made first or development of both hw/sw should run parallely or any other method.
If anybody has link of "chronicling" of such an endeavour of designing an ARM based machine (or any other chip based machine) and then porting a kernel onto it, please do share it.

If you're truly interested in finding out what differentiates Linux on one arch from another then you should look at the contents of the arch/ directory in the kernel source tree.

Related

Linux kernel internals using ARM architecture as reference

Most of the linux kernel architecture books were written taking x86 architecture as reference (LKD by robert love or ULKI by bovett). Does there exist any book which explain linux kernel internals taking ARM architecture as reference.
Some basic questions are missing to really recommend you something and point you to useful resources:
what low level routines do you mean?
what are you going to do with that information?
The linux kernel is running on ARM already and most of the low level stuff is solved there and you shouldn't touch that unless you really know what you're doing. The linux kernel provides some generic low-level interfaces that its drivers stay portable without plattform specific snippets. Unless your intention is to add another ARM processor that is not supported yet you shouldn't need to dig around there.
If you want to add drivers or use components look into this device tree howto.
One major difference to X86 is the device tree/ open firmware stuff because System on Chip devices have often the same hardware mapped to different memory.
If you are looking for embedded kernel development you might also look into elinux.
Further reading is also provided in the linux-kernel tag wiki of stackoverflow.

Tweaking linux kernel

I am new to linux programming & interested to tweak linux kernel(though I am not sure, what to tweak, I am planning to write drivers for particular device). To learn internal of kernel, I have started from historic kernel release (first release).
My problem is, how to test whatever changes I am doing for development, without disturbing my current os environment.(ubuntu 12, 64 bit). Is there any way like virtual box, sandbox?
Along with these, if anybody send some good approaches to learn these things, I would be really greatful.
Thank You.
If you're new to linux programming then you really don't want to be tweaking the kernel. You really want to be an advanced programmer capable of programming drivers and complex software first.
But yes there is, you can can create a virtual machine using openbox or vmware. If you're really keen on tweaking the kernel you probably want to first just try compiling and configuring the kernel and seeing if that works.
Also make sure you're well acquainted with how the kernel works and advanced OS designs in general.
Search in google fr "Kernel configuration" you u will get many links how to configure your own kernel.
And one more thing do not use a outdated version of kernel ,always use latest stable release , because a lot of code and API is changed in new versions and no book in market is updated so ,, u have to read from kernel documentation. Thats the best way to learn the most updated information about linux kernel
Yes, you can test your changes on any of the commonly available virtual machines (VMs); that way, whatever changes you make to the VM kernel won't affect native OS.
Personally, I prefer using CentOS 64 bit on VMWare Player. With this setup, I got away with minimal system maintenance while was able to focus on the actual job at hand. Once the VM is up & running, you can download and compile one of the latest stable releases from kernel.org. Instructions on compiling your downloaded version of kernel could be found here and here; however, this may require little tweaking based on your actual setup. Once the VM is running on your desired version of kernel, using a combination of cscope and ctags will help you immensely in kernel code browsing.
Finally, if you want to become a serious kernel programmer and write your own device drivers, you need to get familiar with it in the first place. Below are a few excellent references -
Linux Device Driver by Corbet, Rubini, Kroah-Hartman, 3rd edition
Linux Kernel Development by Robert Love, 3rd edition
Understanding the Linux Kernel by Bovet, Cesati
Linux kernel source (ideally placed into your /usr/src/$(DESIRED_KERNEL) path, symlinked to /usr/src/linux)
Going through these books is a tedious job and chances are that you may hit the roadblock from time to time. kernelnewbies mailing list and StackOverflow are some of the few reliable places where people would be happy to answer to your queries.
Good luck!

Comparative analysis between libkvm on linux and NetBSD

I want to build a sample program and as an initial step to learn KVM I started it from the link below.
http://www.linuxjournal.com/magazine/linux-kvm-learning-tool?page=0,1
I see that this is quite an old post for KVM, but I realize that the very first program does not compiles as it asks to include libkvm.h, which is not in my Ubuntu 13.04 installation.
To prepare for this program I installed qemu-kvm,dkms and libvirt stuff.
I also verified that the user has kvm and libvirtd in the group.
I am running Ubuntu on virtual-box on a modern i7 processor windows host.
So I have two different questions here -
1) Since I dont find libkvm.h in my box, what is the way compile my program and learn this kind of programming. If you have any tutorials please forward.
2) I got know that there is another libkvm that is used in BSD style Unix (e.g NetBSD/FreeBSD) that is used to access kernel data-strucrtures. From internet I see that GDB uses that library to fetch info from kernel memory. KVM in linux is a tool to create virtual machines on a Linux box. Is my understanding correct or is there anything more to it? Please provide a comparative analysis between these two libraries, namely libkvm on linux and libkvm on BSD?
As you already said, Linux KVM is a virtualisation technique whereas BSD kvm is much older, the acronym even expands to something different, and is a library to access (not only) kernel data structures in a defined manner.
They are totally separate and different things that have absolutely nothing to do with each other except for sharing the same acronym.
As do, for example, Keyboard-Video-Mouse switches. I was confused by all those Linux people talking about a “KVM” thing suddenly, back when Linux-KVM first came out, and not meaning those.

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!

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...

Resources