Linux network driver port to ARM - linux

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!

Related

Linux - Nic's flags configuration

Context
Debian 64 bit. kernel 3.18.x
Litterally struggling to understand how a network driver is initialized.
I mean how to choose which flag to set. I dig in the kernel for days now to train myself. The card setup is the only point I miss.
I take the intel 82574 as an example. I downloaded the card's datasheet, saw many information but not a clue on how to setup the hardware.
Question
Where to start to know what flags to set ? The datasheet didn't helped me (i am not very experienced but willing to learn).
Please give me a starting point, a tip or anything to help me understand what is going on in the already written open sourced driver.
How can a developer knows how to initialize his nic ? (yes reinventing the wheel the time to understand)
You'll need to read the source code of the kernel module that handles your specific NIC.
EDIT: Of course, to develop such a module, you'd usually just use a register map as specified in a data sheet or application node; often, manufacturers develop their linux drivers themselves, so the driver developers might even be the same people that developed the chipset (because it's really handy to have a platform to test against -- it's impossible to test hardware without having something like a driver, so you might as well write a proper driver).
Furthermore, devices often come with code examples -- no one is going to build a device based on an IC that he has not seen in action.
If you've got access to neither proper documentation nor source, you can only reverse engineer - and that's an incredibly large field.
Using your example with the Intel 82574 Network Adapter, Intel provides a zip file of the source code used to build the Linux driver. The driver is like all drivers in that it hooks into the OS API for Networking.
The Linux networking API is document on both the linux.org site and discussed on popular Linux sites like lwn.org. Below is the link to lwn's chapter on Network drivers using the networking API called NAPI.
https://static.lwn.net/images/pdf/LDD3/ch17.pdf
You'll notice in the Intel igb driver source code that the NAPI net_device data structure is one of the first things that is setup. It registers the driver with the OS. This way the OS knows which igb functions to call when loading/unloading the driver, or when needing to send/receive data.
The igb functions read/modify/write the necessary bits in the 82574's memory-mapped registers that control and monitor the device. The device registers are all documented in the 82574 datasheet available on Intel's site. And this is usually the case for almost any networking company like Broadcom/Chelsio/Mellanox/Marvell.
Hope that helps a little more.

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!

Is there any way to recompile binaries from x86 to ARM on linux?

I'd like to collect some ideas about the solution of following problem.
I've got a TOF camera, and its driver for linux x86/64. It works fine. But in fact the camera would be used on an ARM based embedded device if that's possible.
Questions:
should I have to decompile the driver binaries and recompile with ARM compiler? is there any available decompiler tool?
is there any ARM>>x86 emulator which is available?
any other ideas?
ps: the pure source is very expensive, so I don't like to purchase it anyway :)
AFAIK, as of today, there's no such decompiler that will generate compilable code from machine code. You will have to manually fix (usually a LOT of fixes) the generated code. You can check this question for Linux decompilers.
Check QEmu. Underlying architecture is not relevant as long as you can execute it ;)
There's not much besides what you've stated.
What you're attempting is (in part) reverse engineering. RE is a complex process and requires great knowledge in the thing you're attempting to reverse; in your case camera drivers. If you have knowledge in this area, go ahead. If you don't, I wouldn't waste my time on it (or get the knowledge first ;))
See the following answer for details. It lists some of the problems you could encounter attempting to automate such a translation:
Convert object file to another architecture
Recently created Eltechs ExaGear Server, available on ARM as A Service, runs x86 applications on ARM devices.
It is new and proprietary, but it does exist.
If your driver is a kernel object, there is no emulator (to my knowledge) capable of running x86 kernel code inside ARM kernel. If your "driver" is in fact a userspace library hacked on top of a generic driver (v4l2, etc.), you may have luck with QEMU or Exagear mentioned here. As a side note, you will probably end up with an x86 application software, too, as calling an x86 library from ARM code is not supported by QEMU or Exagear out of the box.

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