I need to port a PCIe Linux driver to Oracle Solaris 11.2 (previously OpenSolaris). Before the driver was tested under kernel 2.6.32-36.
Fortunately, the driver was implemented in such a way that one portion is OS/platform specific (PCI registration, memory allocation etc.) and the other half was written in OS independent way, i.e. that part should be relatively easy to port.
My question is about Linux-specific portion, written according to steps in https://www.kernel.org/doc/Documentation/PCI/pci.txt, so I'm assuming Solaris might have similar approach? What should I pay attention to when porting to Solaris, what device driver parts are completely different in Solaris and nedd to be re-implemented then ported?
UPDATE
After reading several materials about Solaris driver model, I still don't understand the purpose and applicability of STREAMS framework, is it extension for character devices or for the network devices, eg. Ethernet cards?
Solaris 11.2 driver documentation is here.
Here are some links that might also be useful:
http://docs.oracle.com/cd/E19253-01/817-5789/
http://www.oracle.com/technetwork/systems/articles/write-dev-driver-jsp-140901.html
http://www.bolthole.com/solaris/drivers/TIPS.html
http://blog.csdn.net/hotsolaris/article/details/1763716
Related
MTD memory technology devices is driver part dealing with flash kind of memory.
MMC is also flash memory in it's driver core it also has functions to deal with configuring boot partition. What is the difference between these two in their features and functionality and when to use which driver apis
I am a newbie to linux device driver.
If my customized embedded system hosts embedded linux in the SD/MMC card, do I have to look for and modify the files present in kernel source in the path /drivers/mtd or /drivers/mmc or both to adopt my hardware for functionalities like partitioning the card,formatting the card to required filesystem etc,..? If /drivers/mmc is needed to look for, then inside it /drivers/mmc/host or /drivers/mmc/core is needed for the functionalities related to hosting the OS with my above said needs.
Please anybody clarify my doubt.
This my doubt and not related to any of my experiments
I am making my own operating system for fun. I'm reading and learning a lot from the Intel's 64bit and IA-32 architecture manual which is helpful for developing an operating system.
But one thing that I just can't find anywhere is how to make device drivers. The only posts I can find about device drivers on the internet are about making Linux or Windows drivers. But it's different from making drivers for my own kernel.
Can someone experienced please point me into the right direction, enlighten me where I can learn making my own device drivers for my own operating system?
For a start, simple keyboard or mouse drivers are enough, but I will appreciate anything, be it simple keyboard drivers, or complex network drivers
TL;DR: I need a solid source explaining how to make device drivers for my own kernel. I can't find any and hope that someone have stumbled upon one
(I'm not asking "how to make drivers?", but rather asking "can I have links to books/posts about making drivers?")
All a kernel-mode device driver is, is code executing under the kernel, which is not treated as the "main" kernel image itself - consider it as an "extension" to the main kernel image. On Windows for example, kernel-mode device drivers (which tend to use the *.sys file extension, which is also belonging to the Portable Executable (PE) Format) are treated as modules to ntoskrnl.exe (which is the main kernel image on Windows).
The idea is that your kernel-mode device drivers will have access to routines exported by your main kernel image (e.g. if you want to implement mechanisms like kernel-mode callbacks). You could start by making your own simple format for your kernel to understand, and then you can start implementing export support appropriate for your own file format (for the main kernel image) and import support (for the other kernel-mode software to make use of the APIs which it should have access to, provided by the main kernel image).
You'll have a lot of work to do if you want a good design implementation.
I want to clarify before the question that I am not an established professional programmer in any position at any firm. This is solely to satisfy curiosity, and will not pertain to any task or project at this time.
As I understand it, firmware is software placed on hardware to grant it autonomous functionality from instructions, which is given through some form of input; As long as the input stream is readable, which is made possible through drivers. Drivers are software packages with pre-written reference libraries that recognize a specific set of instructions for each possible function in the attached device.
NOTE: not quoted, so I'm aware that this could be inaccurate.
What I want to know is how firmware or drivers are placed on devices without installation through an OS or storage medium; such as a DVD or USB? Specifically firmware installed by manufacturers, like bios and keyboard drivers that are present on all computers. I'm assuming these are less or not reliant on compilation in order to function properly, which is the sole reason I'm asking this question.
Can firmware be developed without compilation?
References
Demystifying Firmware
C++ Kernel Development
Starting Firmware Development
These just explain that an OS is a type of firmware, and that firmware is primarily developed in C with Assembly and C++ as plausible alternatives; pertaining to kernel development as well.
Yes, especially in the larger components. An example involving lua is http://nodelua.org/doc/index/
However, firmware development is typically an extremely memory (and frequently CPU) constrained environment.
C (or traditionally, assembler) is often preferred because it can produce extremely small executables, and is very efficient in stack usage. This matters when you're counting memory in bytes, or kilobytes.
Using a non-compiled language means you need to include a tiny interpreter, and you might not be able to set aside enough memory for this.
You've made an edit, wherein you suggest that an "OS is a type of firmware".
This can be true, in a manner of speaking.
Often firmware itself can consist of an operating system, with components. As an example, the firmware in some home internet routers will contain an OS (which might very well be linux!), however it is still regarded as firmware. There is a bit of a grey area between a computer that is an "embedded device with firmware", vs that of a 'regular computer with regular software', but generally firmware is a computer system running in a very constrained environment, often with very specific uses.
NetBSD includes Lua in it's kernel. Many systems have been developed that do not use Assembly (except for a small part of it), C, or C++, but instead use some other language - though it is typically still compiled for size and performance reasons.
As for the actual transfer of firmware (whatever the form it may be in), this depends on the device in question.
Some devices require that the firmware be burned into the components. (In ROM, though there are various types of ROM and some can be rewritten).
Other devices require that the firmware be transferred when the device is turned on.
And yet others have SDCards or battery-backed RAM or whatever that allow storing the firmware across reboots.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to learn linux kernel device driver programming. So can anyone please post good tutorials pages or links here. I am new to linux kernel environment. I have searched for it but I don't know how to start and which one to read for easy understanding basics. Thanks in advance.
Depends on your current skills. If you're really new to Linux, perhaps you should start with user space system programming with Advanced Linux Programming. You'll get good knowledge of Unix system calls and other concepts such as signals, processes/threads and so on with this free resource. This is a must (understanding the user space API) if you're developing on the kernel side since the role of a kernel is providing services to users in a secure way.
Otherwise one often cited book is Linux Device Drivers, Third Edition (LDD3). Keep in mind that this edition was written at the time of Linux 2.6.10 and some things changed since then. This article shows the differences as 2.6 evolved (until 2.6.31, that is, so not very useful). I should mention martinezjavier/ldd3, which contains example drivers of LDD3 updated for more recent kernels (thanks to 42n4 for pointing that out).
Another interesting book that's not as often cited is Essential Linux Device Drivers. You won't find a free version of this one, but it still features an interesting approach. What I like about this one is it covers lots of different device types and is up-to-date as of 2.6.24, which is a bit better than LDD.
Finally, one great book about the kernel itself (not specifically for drivers) is Understanding the Linux Kernel, 3rd Edition. This covers in-depth kernel facilities and internal mechanisms. It's up-to-date as of 2.6.11.
As for online tutorials, I found this post on Pete's Blog is a really great example. Not only does it show how to create a character device (the most easy kernel driver type, i.e. the one you should start with), it uses modern Linux kernel features in an easy to understand fashion, including:
use of udev
use of a kernel data structure (FIFO)
use of kernel synchronization (mutex)
use of Sysfs with custom attributes
module options for insmod
Plus: it's aimed at Linux 3.0, which means it's more up-to-date compared to other resources.
You might also like this post about how to create Sysfs entries manually, although the Linux device model will take care of registering your device as a Sysfs entry if you don't need additional nodes or attributes.
Edit: I should add that the best way to learn real Linux device driver programming is to look at actual drivers. There are thousands of drivers in drivers. Start reading and understanding the concept of simple ones like drivers/leds and you will see how rewarding this is.
The site with very important links:
http://elinux.org/Device_drivers
Great tutorial with real examples (ends with an usbpen formatted with our own file system - search for author further articles):
http://www.linuxforu.com/tag/linux-device-drivers-series/
http://sysplay.in/index.php?pagefile=lfy_articles
Source code of famous LDD3 book ported to newest kernels:
https://github.com/martinezjavier/ldd3/
Videos:
https://www.youtube.com/playlist?list=PL16941B715F5507C5
Maybe other cources:
http://www.skilledup.com/courses?keyword=linux+kernel&price_filter=0..0
Some examples:
http://www.staerk.de/thorsten/index.php/My_Tutorials/Writing_Linux_kernel_modules
http://www.freesoftwaremagazine.com/articles/drivers_linux
http://techblog.aasisvinayak.com/kernel-module-programming-tutorial/
http://www.linuxforu.com/2009/05/a-voyage-to-the-kernel-day-11/
Books (without mentioned in this thread LDD3):
http://www.coopj.com/ with an updated source code http://www.coopj.com/LPD/
KernelHacking:
http://kernelnewbies.org/KernelHacking
Visual map of the linux kernel: http://www.makelinux.net/kernel_map/
Linux and kernel books for beginners:
http://www.kroah.com/lkn/
http://swift.siphos.be/linux_sea/
You might be interested in the newly released Linux Driver Templates. As the name suggests, it provides templates and demonstrates frequently used Linux facilities to get started quickly.
I understand it is a delayed response !!
You can pick any book, those are really great books suggested above.
But you need to really work practically. Try to be involved into Kernel as much as possible.
Mostly you need to look into kernel source code itself.
And the most interesting document you can find in Documentation folder under Kernel tree.
best book for learning device driver programming is
"LDD"
Professional Linux Kernel Architecture is a good read also.
The best source is the linux man pages but they are somewhat critical to understand for a beginner, Directly programming device drivers is not a easy task. I recommend you to go through pointers and structures through following books
Basic C Books 1. Programming C - Byron gottfried 2. The C Programming Language - Dennis Ritchie
Intermediate Books 1. Pointers on C Kenneth Reek 2. Expert C Programming Deep Secrets - Linden
Coming to device Drivers I have uploaded the Kernel Source documentation in pdf format https://drive.google.com/folderview?id=0B7iRyndFhHldR3hjOHpOZTdKTjA&usp=sharing Youcan download from this link.
Device Drivers Basics (User mode Programming)
Linux Programming interface - Michael Kerrisk
Beginning Linux Programming Wrox Publishers
Device Drivers (Kernel Deleopment) 1. Linux Kernel Development - Robert Love 2. Linux Kernel Internals - m beck
Device Drivers (Driver Programming) 1. Linux Device Drivers - Third Edition (Free Download is available for 2.6 Kernel) 2. Essential Linux Device Drivers - Venkateswaran
For Basic Driver Knowledge Follow this site http://www.tldp.org/LDP/khg/HyperNews/get/devices/devices.html
My Experience is First of all we must gain a sound knowledge on C Programming, mainly Structures and Pointers before going through Driver Programming otherwise it will be bit cumbersome to understand driver programming.
Comming to Startup :-
User space programming
Basics of gcc generating proprocessed, assembler and object files using gcc commands analysis of object files using different object tools, Basic programming in linux, threads(locks, synchronization techniques), signals, processes(fork, exec), timers(Posix). This will help you lot in understanding kernel concepts.
Kernel Programming
Understanding the kernel source tree, different branches and their importance, using ctags and cscope to browse kernel source code, this will help you in kernel source browsing.
Driver Programming
First of all Learn different driver classes, char, block etc.,
Next learn the device protocols, transmission and reception, the product manual is the best source for going through this.
Then start writing the simple char driver for example RTC (a port mapped device), IOAPIC (A memory mapped device), then go to USB, PCI, Network, I2C, SPI etc., if you want the help you can find the skeleton code for all this in kernel source tree.
I saw a question on Linux Kernel. While reading that I had this doubt.
The Windows NT branch of windows has a Hybrid Kernel. It's neither a monolithic kernel where all services run in kernel mode or a Micro kernel where everything runs in user space. This provides a balance between the protection gained from a microkernel and the performance that can be seen in a monolithis kernel (as there are fewer user/kernel mode context switches).
As an example, device drivers and the Hardware Abstraction layer run in kernel node but the Workstation service runs in user mode. The wikipedia article on Hybrid Kernels has a good overview.
The Windows Internals book gives an explanation for the hybrid approach
... The Carnegie Mellon University Mach
operating system, a contemporary
example of a microkernel architecture,
implements a minimal kernel that
comprises thread scheduling, message
passing, virtual memory, and device
drivers. Everything else, including
various APIs, file systems, and
networking, runs in user mode.
However, commercial implementations of
the Mach microkernel operating system
typically run at least all file system,
networking, and memory management
code in kernel mode. The reason is
simple: the pure microkernel design is
commercially impractical because it’s
too inefficient.
According to Wikipedia it's a Hybrid kernel. Which may or may not be just marketing speak for about the same as a monolithic one. The graphic on the latter page does make some things clearer, though.
Most importantly, almost no program on Windows uses the kernel API directly. And the complete Windows API subsystem resides in user space which is a rather large part of the OS as we see it. And in more recent versions Microsoft began to pull more and more device drivers from kernel space into user space (which is especially a good idea with certain drivers, such as for video cards which are probably as complex as an operating system on their own).
hyru hybrid kernel is the name of the Kernel that Windows systems after Windows 98, before that it was a GUI overlaid on DOS using a monolithic Kernel.