1.16k likes | 1.17k Views
Discover the features, benefits, and considerations of using Embedded Linux as an operating system for your embedded systems. Learn about its modular design, support for multiple peripherals and standard protocols, real-time capabilities, and the advantages of the Linux kernel.
E N D
Basic Operation System Concept ANDES Confidential
OS Flavors • Desktop • Windows (9X, XP Home, XP/2000 Pro, vista) • Mac • Server • Windows (XP/2000 Server &Advanced Server) • Unix Varieties • Embedded • Linux • uCLinux ANDES Confidential
What is an Embedded OS? • An "embedded system" is any computer system or computing device that performs a dedicated function or is designed for use with a specific embedded software application. • Embedded systems may use a ROM-based operating system or they may use a disk-based system, like a PC. But an embedded system is not usable as a commercially viable substitute for general purpose computers or devices. ANDES Confidential
What makes a good Embedded OS? • Modular • size • CPU support • Device drivers • etc, etc, etc... ANDES Confidential
Who are the Embedded OS players? • Wind River Systems • VxWorks • pSOS • QNX Software Systems • QNX • Palm Computing • PalmOS • Symbian • SymbianOS ANDES Confidential
How to Select a Right Embedded OS? • Productions requirement is pushing the embedded system. • Productions need TCP/IP • If not use the OS existing TCP/IP ,the reliability and portability will be severely tested. • Choose an OS with lots standard protocol. ANDES Confidential
Considerations of OS • Multiple peripherals and lots standard protocols need to be followed . • Self made driver will cause manpower and finance higher cost. • Driver: use IPC (inter-process communication ) of OS to talk with Interrupt Service ANDES Confidential
What is Real Time? • A real time system is one in which the correctness of the computations not only depends upon the logical correctness of the computation but also upon the time at which the result is produced. If the timing constraints of the system are not met, system failure is said to have occurred. • Real time in operating systems: • The ability of the operating system to provide a required level of service in a bounded response time. ANDES Confidential
What makes a good RTOS? • Multi-threaded and pre-emptible • Thread priority has to exist because no deadline driven OS exists • Must support predictable thread synchronization mechanisms • A system of priority inheritance must exist ANDES Confidential
Linux • The name "Linux" comes from the Linux kernel, originally written in 1991 by Linus Torvalds. The rest of the system, including utilities and libraries, usually comes from the GNU operating system announced in 1983 by Richard Stallman. The GNU contribution is the basis for the Free Software Foundation's preferred name GNU/Linux. ANDES Confidential
Linux (cont.) • Linux is a generic term referring to Unix-like computer operating systems based on the Linux kernel. Their development is one of the most prominent examples of free and open source software collaboration; typically all the underlying source code can be used, freely modified, and redistributed by anyone under the terms of the GNU and other free licenses. ANDES Confidential
What’s so special about Linux? • Source code freely available • Robust and reliable • Modular, configurable, scalable • Superb support for networking and Internet • No runtime licenses • Large pool of skilled developers • Need “MMU” to protect process. • Virtual address was sent to MMU to map to the real physical address • Through the mapping to protect multiple process operation ANDES Confidential
Embedded Linux • Embedded Linux is the use of a Linuxoperating system in embedded computer systems such as mobile phones, personal digital assistants, media players, set-top boxes, and other consumer electronics devices, networking equipment, machine control, industrial automation, navigation equipment and medical instruments. • Embedded versions of Linux are designed for devices with relatively limited resources, such as cell phones and set-top boxes. Due to concerns such as cost and size, embedded devices usually have much less RAM and secondary storage than desktop computers, and are likely to use flash memory instead of a hard drive. ANDES Confidential
Embedded Linux (cont.) • The advantages of embedded Linux over other embedded operating systems include • no royalties or licensing fees • a stable kernel • a support base that is not restricted to the employees of a single software company • employees have the ability to modify and redistribute the source code. ANDES Confidential
Linux Kernel • The most important element of Embedded Linux is its core, called the Linux Kernel • The Linux Kernel is maintained and distributed by Linus Trovalds, who initially wrote the Kernel when he was a student at the University of Helsinki • Unlike proprietary Operating Systems, its source code is available for anyone to freely use, distribute, or modify • The latest released version of the Linux Kernel is version 2.6, though development of the Linux Kernel is of course ongoing and newer versions become available on a regular basis ANDES Confidential
Linux Kernel (cont.) • Like any Operating System, the Linux Kernel is responsible for managing resources (memory and I/O), contains device drivers, networking stack, file system, and performs other OS tasks • Linux implements different privilege levels, where a module, which is a Kernel function runs in kernel space (supervisor mode), and user applications run in user space (user mode) • Linux can mange both multiple processesand multiple processors. ANDES Confidential
GNU • GNU is an acronym for GNU’s Not Unix, and is pronounced guh-noo • The GNU project was started in 1983 with the goal of creating a UNIX flavored operating system which was freely distributable • GNU is not Linux! GNU is used in conjunction with the Linux kernel to form a completely operational Operating System. This GNU/Linux combination (distribution) is often mistakenly called Linux ANDES Confidential
The First Linux C Program /*hello.c*/ #include <stdio.h> int main() { printf(“This is the first Linux C program\n”); return 0; } # gcc –o hello hello.c # ./hello ANDES Confidential
General Public License • The GNU General Public License, or GPL as it is otherwise known is the free software license under which Linux is written and distributed • The GPL grants the recipient of a computer program the following rights: • The freedom to run the program for any purpose • The freedom to study how the program works and to modify it • The freedom to redistribute copies of the program • The freedom to improve the program, and to redistribute the improvements to the public • The GPL is in contrast to the end-user licenses that plague proprietary software, which rarely grant the end-user any rights ANDES Confidential
The GNU Toolchain • Linux relies on the GNU development toolchain • A toolchainis series of programming tools (assembler, compiler, linker, etc.) which are used to create another computer program • The tools are used sequentially, or in a chain, in such a way that the output of one program becomes the input of another one, hence the term toolchain ANDES Confidential
The GNU Toolchain (cont.) • The GNU toolchainis an overall term given to the series of programming tools developed by the • GNU project, The projects include: • GNU make – Build and compilation automation • GNU Compiler Collection (GCC) – Compilers for several programming languages • GNU Binutils – Linker, assembler, and other tools • GNU Debugger (GDB) – Interactive debugger • Other related projects are: • GNU C Library – A standard C library • CVS – Concurrent Version System ANDES Confidential
Makefile target…: dependencies <tab>command <tab>command . . . ANDES Confidential
Makefile Example hello:hello.o gcc -o hello hello.o hello.o:hello.c gcc -c hello.c ANDES Confidential
Linux Device Drivers • Most Linux users are happily unaware of the complexities associated with the underlying hardware • But every piece of the underlying hardware requires a device driver be written for it, and this is a job embedded system designers bravely undertake • In the Linux Kernel there are many concurrent processes which tend to various system resources, such as memory, I/O, or the file system (http://www.pathname.com/fhs) ANDES Confidential
Resource Management • Process Management • It’s the Kernels task to manage processes, to ensure that they can communicate with each other, and that they are scheduled, created and disposed of properly • Memory Management • The Kernel is also responsible for handling memory resources, providing a virtual address space and memory management • Filesystem • Filesystem is a major component of a UNIX (and Linux) operating system. Almost every resource in UNIX can be treated as a filesystem ANDES Confidential
Resource Management (cont.) • Device Control • The Kernel implements a device driver for every hardware resource which is available on the system, ranging from hard drives to Timer modules • Networking • Finally, the Kernel is responsible for providing a networking stack to the higher-level operating system functions ANDES Confidential
Kernel Modules • Kernel functions are called modules, and they are loaded and unloaded from memory using the instmod and rmmod calls • Unlike traditional functions which are loaded and executed completely, a kernel modules registers itself using the instmod call in order to specify which services it is capable of providing and terminates itself afterwards ANDES Confidential
Example of a Kernel Module #include <module.h> int init_module (void) { printk(“<1>Hello, initializing module…\n”); return(0); } void cleanup_module(void) { printk(“<1>Thank you, & goodbye…\n”); } >gcc –c test.c >instmod test.o Hello, initializing module… > ANDES Confidential
Memory Management • Linux employs three memory management schemes • Logical Address, where each address contains a segment and an offset • Linear Address, a single 32-bit unsigned integer to address memory from 0 to 4 GB • Physical Address, the actual addressing scheme on the system bus (the physical address provided to a flash chip for instance) • The kernel translates a logical address into a linear address through segmentation, and further translates it into a physical address through paging • Linux prefers paging over segmentation ANDES Confidential
Process Management • Linux uses 5 states to manage processes • TASK_RUNNING: Process is either executing, or is waiting to run • TASK_INTERRUPTABLE: The process is suspended until a certain condition is met • TASK_UNINTERRUPTABLE: Task is suspended until a condition is met and is uninterruptable until the condition is met • TASK_STOPPED: Process execution has been terminated • TASK_ZOMBIE: The process has been terminated but the parent may still need information pertaining to it and therefore the OS can’t discard the process ANDES Confidential
Process Management (cont.) • Processes created in Linux have a parent/child relationship, and sibling relationships between child processes • Process 1 (init) is the parent of all other processes • The way Unix has traditionally handled creation of child processes was that the resources available to a parent process were duplicated and a copy was provided to the child process • However, this is an inefficient mechanism, specially if the parent depends on a large pool of resources and creates many child processes • These include stack, memory, current working directory, nice value, etc. ANDES Confidential
Interrupt and Exception Handling • There are two sources of interrupts in Linux, synchronous and asynchronous • Synchronous interrupts, better known as exceptions, are generated by the CPU control unit • Asynchronous interrupts (known as interrupts) are generated by hardware resources, such as serial module, or timers • Interrupts are grouped into three different categories of critical, non-critical, and deferrable non-critical • The address of all the interrupt service routines must be programmed into the Interrupt Descriptor Table (IDT) ANDES Confidential
Interrupt and Exception Handling (cont.) • The nature of an asynchronous interrupt is that it happens at any time • If it happens during a time when the kernel is busy performing an important function, then the kernel must do the following: • Switch over and execute as much of the interrupt service routine as necessary • Switch back and finish the remainder of the task it was performing before the interrupt occurred • Switch back yet again and finish the remainder of the interrupt service routine • The first half of the interrupt service routine is referred to as the top half, while the second half is referred to as the bottom half ANDES Confidential
Introduction • An Interruption is a control flow change of normal instruction execution generated by an Interrupt or an Exception. • When an interruption happens, the processor • Stops processing current flow of instructions, • Saves enough states for later resuming of the interrupted current flow, • Disable interrupts, • Enters SuperUser Mode, and • Starts executing a software interruption handler. ANDES Confidential
Interrupt • An interrupt is usually defined as an event that alters the sequence of instructions executed by a processor. • An interrupt is a control flow change event generated by an asynchronous internal or external source. • Timers and I/O devices; for instance, the arrival of a keystroke from a user sets off an interrupt. • Interrupts can come anytime, when the kernel may want to finish something else it was trying to do. • The kernel's goal is to handle the interrupt as soon as possible and defer as much processing as it can. ANDES Confidential
Exception • Exceptions are caused by programming errors or anomalous conditions that must be handled by the kernel. • An exception is a control flow change event generated by instruction execution. • Divide by 0, page fault. ANDES Confidential
Interruption Vector • There are 2 modes for Andes Interruption Vectored Entry Points • Internal Vectored Interrupt Controller (IVIC) mode • External Vectored Interrupt Controller (EVIC) mode ANDES Confidential
Offset Entry Point 0 Reset/NMI 1 TLB Fill 2 PTE Not Present TLB Misc 3 4 TLB VLPT Miss 5 Machine Error Debug Related 6 General Exception 7 8 System Call HW0 ~ HW5 9~14 15 SW0 Interruption Vector (IVIC) ANDES Confidential
User Program Interruption Continue Execution software hardware Kernel Stuff e.g. scheduling Hardware Interruption Handling Interruption Handler Trap to Entry Point Software Interruption Handling Flow of Interruption Handling ANDES Confidential
Sample Program void main() { // trap general exception using Privileged instruction mfsr asm ("mfsr $r0, $cr0"); return; } # nds32-elf-gcc test.c –o test ANDES Confidential
Step by Step Trace • Find address of the mfsr instruction # nds32-elf-objdump -d testprogram | less • Search for mfsr 00008510 <main>: 8510: 51 ff ff f8 addi $sp,$sp,#-8 8514: 15 cf 80 01 swi $fp,[$sp+#4] 8518: 83 9f mov55 $fp,$sp 851a: 64 00 00 02 mfsr $r0,$CPU_VER 851e: 83 fc mov55 $sp,$fp 8520: 05 cf 80 01 lwi $fp,[$sp+#4] 8524: 51 ff 80 08 addi $sp,$sp,#8 8528: 4a 00 78 20 ret $lp • The trap address will be 0x851a ANDES Confidential
Step by Step Trace • Copy the test program and re-pack rootfs. • Boot Linux on AndeSight • Set breakpoint at the founded address in GDB. • Execute the test program. • After hitting the breakpoint, do “si” gdb command to execute the next instruction. • Trap to General Exception Entry Point 0x70. ANDES Confidential
Kernel Exception Handling • Linux kernel then handles this exception. • eh_dispatch_general() • You can modify this handler to handle the exception. • e.g. redo the instruction, terminate the process, handle the instruction by kernel, etc. ANDES Confidential
μC/OS-II (Real-Time Kernel) on Andes platform ANDES Confidential
Outline • μC/OS II Concept • Real-Time Systems Concepts • APIs provided by μC/OS II • Merge μC/OS –II and andes demo program • Example: networking demo program explanation • Lab : networking demo on μC/OS –II ANDES Confidential
μC/OS II Feature • Open source code • Memory footprint is about 20K for a fully functional kernel. • Preemptive priority-driven real-time scheduling • Portable: Support many platforms:Andes,x86,Arm,Mips… • ROMable: Was designed for embedded applications. It’s easy as part of a product • Scalable: you can use only the services that you need in your application. • Multi-tasking: can manage up to 64 tasks, however, the current version of the software reserves eight (8) of these tasks for system use. • Deterministic: Execution time of all μC/OS-II functions and services are deterministic. • Task stacks: Each task requires its own stack, however, μC/OS-II allows each task to have a different stack size. • Services: provides a number of system services such as mailboxes, queues, semaphores, fixed-sized memory partitions, time related functions, etc. • Interrupt Management: Interrupts can be nested up to 255 levels deep. • Robust and reliable: ANDES Confidential
μC/OS II vs Non OS • Advantages: • Allow real-time applications to be designed and expanded easily. • Simplify the design process by splitting the application code into separate tasks. • With a preemptive real-time kernel, all time-critical events are handled as quickly and as efficiently as possible. • Disadvantages: • Extra cost of kernel: more ROM/RAM • 2 to 4 percent additional CPU overhead. ANDES Confidential