# Linux for Embedded and Real-time programming
## Chapter 1
### How and why does linux fit in?
Linux is a GPOS in the model of Unix. A GPOS is way to big to be considered for Real-time applications and the schedulers are not based on priority meaning Hard-real time could fail.
### Open source
* Open source is not shareware, meaning theres no obligation to pay the copyright holder for it.
* Open source is not public domain, which refers to software which is not copyrighted.
> Free refers to the freedom to use the software, and not always free of cost.
* Open source is subject to the terms of an Object Source license (GNU Public License).
### Portable and Scalable
Originially developed for x86 but with clear distinctions of portable sections that can be recompiled for any architecture. Some of the supported architectures for porting are:
* ARM
* Sparc
* MIPS
A typical linux installation usally requires around a couple of gigabytes of disk and 256 megabytes of RAM, which is usally way to much to ask for an embedded system. It is not very difficult to scale the linux kernel to use around 2 Mbytes of flash memory instead.
### Where is Linux Embedded?
started in 2005 with the TiVo. Embedded Linux can now be found everywhere in all sorts of applications from consumer products to robots and outer space.
## Chapter 2, introducing Linux
### Features
According to the book the most important features of the Linux OS are the following:
* Multitasking
The linux Scheduler implements true, preemptive multitasking in the sense that a higher priority process made ready by the occurence of an asynchronous event will preempt the currently running process. However, the stock linux kernel itself is not **preemptible**. So a process may not be preempted while it is executing a kernel service. One of the reasons linux is not suitable for real-time systems, as the kernel services can be rather long.
* Multiprocessing
Linux offers extensive support for true symmetric multiprocessing (SMP) where multiple processors are tightly coupled through a shared memory bus.
* Protected Memory
Each Linux process operates in its own private memory space and is not allowed to directly access the memory space of another process. This prevents a wild pointer in one process to damaging memory space of another process.
* Hierarchical File System
On top of the traditional file systems used for PC's, Linux adds
* Links
* Device-independent I/O
### Protected mode architecture
Basically same architecture as ARM uses for virtualization. 4 privilege levels with increasing and decreasing access to certain control systems.
### Paging
kanske ta från något annat ställe
### The Linux Process Model
The basic strucutral element in Linux is a **process**. A process consists of executable code and a collection of resources like data, file descriptors and so on. Resources are protected meaning processess cant access eachothers resources. To communicate between two processess one must use Linux's interprocess communication mechanisms such as shared memory regions and pipes.
This gives good security but in the cost of excessive ovearhead.
On top of processes lies **threads**. Threads are software only. A process can contain multiple threads and all threads within a process share the same resources. This is often refered to as **lightweight tasking**. Lightweight tasking is what most RTOS's uses.
see **fork()**
and **execve()**
### Linux Filesystem
File names in Linux systems are casesensitive meaning Foobar, foobar and fooBar are different files. This makes sorting casesensitive too.
Because linux is multiuser every file has a set of permissions for example
> -rw-r--r-- Gustaf secrets
Gustaf is the owner, secrets is a group etc.
### Root
Every Linux system has a special user called root. Root has admin priviliges and therefore discards the set permissions of a file.
### /proc filesystem
### Filesystem Hierarchy Standard (FHS)
fortsätt här