[Android] michael.the.don:
This is just a compilation about the topic and i have made it as much as noob friendly as i can. i will write it part wise when i get time. Hope it helps the community. if i missed something or wrote something wrong please point me out.

Do not forget to hit thanks if this helped :D

Linux Kernel and its Structure

PART I

Introduction:-

The Linux Kernel is as we all know is on of the most prominent example of free and open source software. Linux kernel is one of the most popular operating system kernel widely used by Linux distributions and variety of mobile devices. If was the result of a hobby of Finnish student Linus Torvalds and in 1991 he gave the birth to the Linux Kernel which redefined the concept of free and open source software.

The Linux Kernel is released under GNU General Public License version 2(GPLv2) and due to which more then a thousand people contribute to each kernel release. The large and dynamic developer and user community around Linux helps it to rapidly accumulate developers and users to adopt code from other free software projects to use with the Linux Kernel.

The main features of Linux Kernel are :-

1.Multitasking: several programs running at the same time.

2.Multiuser: several users on the same machine at the same time (and license for two users)

3.Scalibility: can run on super computers as well as tiny devices.

4. Multithreading: has native kernel support for multiple independent threads of control within a single process memory space and even has memory protection between processes, so that one program can't bring the whole system down.

demand loads executable: Linux only reads from disk those parts of a program that are actually used.

5.Free and open source:- All source code is available, including the whole kernel and all drivers, the development tools and all user programs; also, all of it can	be freely distributed.

6.Multiple virtual consoles: several independent login sessions through the console, you switch by pressing a hot-key combination.

7.Supports several common filesystems, including minix, Xenix, and all the common system V filesystems, and has an advanced filesystem of its own.

8.An extensive networking support.

9.Modulatiry: Loads only those modules that are needed by the system, even at	runtime.

10 Easy to code: Almost all the resources are available free, so users and	developers can learn form existing codes already contributed by the	community.

Defining System Calls:-

The main interface between the Linux Kernel and the user space is a set of system calls. Normally the system provides a library or API such as glibc, that provides the wrapper functions for the system calls. Kernel services like file operations, networking operations inter-process communications, threads, memory mapping etc are provided by over 300 system calls.

At present the system call interface is stable and only new system calls can be added by the Kernel developers. The user space applications usually never make a system call directly but rather it uses the corresponding C library function.

Getting Linux Kernel Sources:-

The Linux kernel Sources are free and open source as it is distributed by the GNU General Public License v2, you can get the source as released by Linus Torvalds at

https://www.kernel.org

There are various versions available namely Prepatch, Minline, Stable, Longterm depending on the maintainers and stability status.

Thought many of the chip vendors supply their own kernel sources as you already have seen in case of Google device kernels maintained and distributed by Google. There are many sub-communities that maintain their own kernel, with usually new features or specific features, and my be stable or unstable.

The Linux Kernel sources can be downloaded at

https://kernel.org/pub/linux/kernel/{version}/{branch}

as a full tarballs and patches.

But you can also get the kernel using the git version control system. Detailed description of the git version control system can be found here -

http://git-scm.com/

The Linux kernel size vary from 500Mb to around 1Gb but you can get the kernel as archive in gzip, bzip2, xz depending upon the compression rate. The Linux core is pretty small but it contains thousands of device drivers, network protocol, many architectures, filesystems, documentations, firmware, scripts etc, so the large size of the Linux kernel.

The Linux Kernel is implemented in C as like all the UNIX system. A little assembly language is also used, but no C++ is used in the Linux Kernel. All the codes are compiled by gcc and a few alternative compilers, but ANSI C compile cannot compile the Linux Kernel as gcc specific extensions are used in the kernel code.

The main feature of the Linux kernel is that it has to be standalone, which means no user space code or part can be used in the Linux Kernel. The user space is then implemented on the top of the Linux Kernel. The Linux Kernel has to supply its own library implementations, and no standard C library functions are used in the kernel. But it provides its own similar C library.

The Linux Kernel is designed to be portable, and the kernel provides macros and functions to abstract the architecture specific details. The Linux Kernel never uses floating point unit as some of the architecture may not be compatible with it. The internal kernel API is not stable and can undergo changes between releases and so if you have to use the API then keep track of all the API available for the specific kernel release. An out-of-the tree compiled driver for a older version of the kernel may not work on the recent ones. Though the kernel to user space API does not change as it may break the existing scripts and program running in the user space.

GPL licensing and open source drivers:-

As mentioned earlier the Linux Kernel is licensed under the GNU General Public License version 2, which gives you the right to study, use, modify and share it without any cost. However it states that if the code is redistributed or shared modified or unmodified then it will be under the same license. More information about the GPLv2 can be found at -

http://www.gnu.org/licenses/gpl-2.0.html

Thought there are a lot of propriety drivers that are available for different hardware. You cannot distribute a binary kernel that includes statistically compiled propriety drivers. Most of the common form of the propriety drivers can be found in the case of graphics cards, though open source drivers are also available for the same.

The main advantage of GPL licensed drivers is that you do not have to write the whole driver from scratch and you can reuse the code for similar free software. The GPL licensed drivers can be easily distributed inside a compiled kernel for example a Linux distribution. Free community contribution, support, testing can be attained. And the code becomes much more stable as many people review the code and contribute to it. Many device driver codes are also implemented in the user space. This is possible as the Linux Kernel provides a mechanism that allows the user space application to access the hardware directly. Certain drivers are handled partly in kernel space and partly in user space.

The user space drivers have a lot of advantages as you need no kernel coding skills to write a user space driver. User space drivers can be written in any language and they can even be kept propriety. The driver code can be killed and debugged without crashing the kernel, and moreover it can be swapped out for a much stable version without changing the kernel.