The Linux Kernel (2Ème Édition), O'reilly 2002
Total Page:16
File Type:pdf, Size:1020Kb
Embedded Systems and Applications Mail: [email protected] Web: http://stephane.lavirotte.com/ Université de Nice - Sophia Antipolis Embedded Systems and Applications Lecture Presentation 3/31/2010 Stéphane Lavirotte 2 Lecture Objectives and Organization 9 Purpose: – Deepening the knowledge on Operating Systems – Have an “inside” system vision – Studying the different components of an OS 9 Focus on testing – Illustration and case studies on Linux 9 Applied to Embedded Systems – And to embedded Software also 9 Organization – Lecture (1/3) – Practical Lab (2/3) 3/31/2010 Stéphane Lavirotte 3 Embedded Systems 9 Systems and Critical Systems – Business critical Î time-to-market Phone, audio, TV, DVD, games, … – Mission critical Î highest quality Trajectory et altitude, imagery, communications, … – Life critical Î validation et certification Pacemakers, insulin pump, surgeon robot, … – Safety critical Î validation et certification Piloting, brake, electronic distribution, … 9 Different kind of constraints – Everything can be seen as critical – We will not process validation in this lecture Design and Validation of Critical Systems 3/31/2010 Stéphane Lavirotte 4 Embedded Systems and Applications Lectures 9 Operating System Architecture – Architecture and Introduction – Configuring Linux and System Calls – Modules: adding new functionalities to kernel – Device drivers 9 Embedded Systems (“High Level”) – Building an embedded system – Optimizing an embedded system 3/31/2010 Stéphane Lavirotte 5 Bibliography 9 Books – D. Bovet and M. Cesati, Understanding the Linux Kernel (2ème édition), O'Reilly 2002. – J. Corbet , A. Rubini and G. Kroah-Hartman, Linux Device Drivers 3rd edition, O'Reilly 2001. http://lwn.net/Kernel/LDD3/ 9 Online Resources – http://www.tldp.org/guides.html, Gerard Beekmans, Linux From Scratch, Nov 2005. Peter Jay Salzman, Michael Burian, Ori Pomerantz, The Linux Kernel Module Programming Guide, Kernel 2.4 et 2.6, Jul 2004. Tigran Aivazian, Linux Kernel 2.4 Internals, Aug 2002. David A. Rusling, The Linux Kernel, Jan 1998. Michael K. Johnson, The Linux Kernel Hackers' Guide, Aug 1998. – http://www.linuxhq.com/lkprogram.html 9 Courses and Tutorials – Embedded Linux: http://free-electrons.com/ 9 Kernel Documentation – /usr/src/linux/Documentation/… – And “may the Sources be with you !!!” (grep, (e|c)tags, … 3/31/2010 Stéphane Lavirotte 6 Acknowledgement 9 This lecture was mde with the following sources : – Cours et exercices « Systèmes d’Exploitation Avancés » Erick Gallesio and Jean-Paul Rigault (1999-2004) Stéphane Lavirotte and Jean-Yves Tigli (2004-2008) – Cours et exercices Michael Opdenacker – Free Electrons (2004-2008) http://free-electrons.com/ 9 Thanks to: – Erick Gallesio – Fabrice Huet, Olivier – Michael Opdenacker – Jean-Paul Rigault – Jean-Yves Tigli 3/31/2010 Stéphane Lavirotte 7 Introduction and Architecture of an Operating System Stéphane Lavirotte Mail: [email protected] Web: http://stephane.lavirotte.com/ Université de Nice - Sophia Antipolis An OS: What for? 9 Features of an Operating System – Serving requests for processes System Calls: Read, Write, Open, … – Handle exceptions caused by physical processes Rerouting: Division by 0, stack overflow, … – Manage hardware interrupts Interrupts : keyboard / mouse, network, … – Provide a set of specific services Ensure maintenance tasks system – Memory paging management – Swap, and caches management – File systems management – … 3/31/2010 Stéphane Lavirotte 9 Architecture Overview 9 Layer Vision: Hardware Source: Linux, Pilotes de Périphériques (3rd edition) 3/31/2010 Stéphane Lavirotte 10 Architecture Overview elf a.out 9 A contemporary vision EXT3 Mapping NFS files Exec. Mapping Virtual VFS VFAT devices. Memory Interface Common Services Harddrive driver System Pilotes Processes Scheduler Block Tape Driver Real Time Streams Terminal Driver Network Driver 3/31/2010 Stéphane Lavirotte 11 Reminders Some reminders about Unix 3/31/2010 Stéphane Lavirotte 12 Root File System 9 /bin : Basic programs for all users 9 /boot: Image files for kernel boot 9 /dev: Special files to access devices 9 /etc: Configuration files for systems and applications 9 /home: Users’ directory of the machine 9 /lib: Shared libraries for system startup 9 /mnt: Mount points for temporary partitions 9 /proc: Virtual files; reflect the operation of the system 9 /root: Account for the super user 9 /sys: « Ditto » to /proc starting from 2.6 9 /tmp: Temporary files 9 /usr: Secondary hierarchy for applications 9 /var: Variable files (log, cache, …) 3/31/2010 Stéphane Lavirotte 13 Files 9 Everything is files – Data Storage – Access devices via /dev /dev/hdaX, /dev/hdbX, … : IDE hard drive /dev/sdaX, /dev/sdbX, … : SCSI hard drive, USB, … /dev/fdX, /dev/fdX, … : floppy disk /dev/videoX : graphics card graphique, TV tuner card, … /dev/i2cX : access to components connected I2C bus /dev/null, /dev/zero : destruction or generation of zero 9 Unless the network access – /sbin/ifconfig ethX – Configuration via /etc/network/interfaces or via ifconfig 9 Information about devices connected on the bus – lspci, lsusb, lspcmcia, … (also useful: lsinput) 3/31/2010 Stéphane Lavirotte 14 Memory Management 1/3 9 Unix relies on virtual memory 9 Processes do not have direct references to physical addresses – Each process has its virtual address space 9 The virtual addresses are translated into physical addresses – The MMU circuit operates to convert each reference Using a set of records that describe the conversion tables of the current process A conversion table is associated with each process – When changing context (= current process) load the MMU registers with new addresses tables 3/31/2010 Stéphane Lavirotte 15 Memory Management 2/3 9 Using virtual memory with 2 other techniques – Pagination The memory is divided into pieces The allocation is done by a whole number of pages Few external fragmentation (free space cut into small pieces) Internal fragmentation (to many allocations) Requires a hardware MMU – Segmentation Used to isolate pieces of memory They are not accessible by the running process Use of hardware registers If not respected: segmentation fault 9 These two techniques allow a memory protection – A process can not read/write memory of another 3/31/2010 Stéphane Lavirotte 16 Memory Management 3/3 9 Distinction between the memory used by the kernel and the one used by the processes 9 Kernel Space – kernel memory area – never put in swap 9 User Space – memory area for execution of user programs – to access the kernel space program user must go through system calls. 3/31/2010 Stéphane Lavirotte 17 Processes Memory 9 The memory of a process is divided into 3 zones – Stack: automatically grow Stack – Data : explicit grow – Text : fixed 9 Used by most language – In particular, the C language So used inside the kernel Data – Some exceptions : Fortran77, ... Text 9 Each process has (at least) one – It helps to remember the call parameters of functions Allows recursive calls – When the function execution ends Withdrawal call parameters Stacking of the return value 3/31/2010 Stéphane Lavirotte 18 Installing New Software 9 Methode “for the brave” – Get package .tar.gz – With luck, configured with automake – ./configure ; make ; make install 9 Package distribution – Major formats : .deb (Debian, Ubuntu, ...) .rpm (RedHat, Mandriva, ...) 9 Intelligent installation – Tools for major distributions .deb : dpkg, dselect, aptitude, … .rpm : rpm 3/31/2010 Stéphane Lavirotte 19 Packages Management 9 Despite dependencies, conflicts may exist 9 Dependency information often inadequate – RPM: simply claim without specifying where to look 9 Solution : packages repository – Website consisting of many packages Consistent with each Regular updates – Update command apt (Debian) yum/up2date (RedHat) synaptic : works with the 2 formats – Lauch : synaptic 3/31/2010 Stéphane Lavirotte 20 Some useful Utilities 9 wget – Get files from Internet: wget url 9 gpg – Verify file integrity: gpg --verify file.sign file.bz2 9 patch – Apply a patch to sources : patch –pn < file.diff 9 mount – Attach a new partition: mount [–t type] device 9 make – Compile sources: make target – Time optimization: make –j 4 (faster even on a single proc.) 9 dmesg – Access to kernel messages: dmesg 3/31/2010 Stéphane Lavirotte 21 Have a Look to Messages ! 9 When it does not work, let’s have a look to logs !! – Files are stored in /var/log 9 As root, launch – tail -f /var/log/messages 9 Syslogd Daemon – File /etc/syslog.conf Lines formed of couples Selector / Action – Simple selector : facility.priority • Notice: priority means level >= priority • Ex : mail.notice messages on the mail for all levels of emergency to record (except info and debug) – Extended selector • facility1,facility2.priority • facility.=priority; facility.!=priority … – Action : • /path/to/a/log/file, @machine.domaine, • user1,user2, * : wall(1) (all those connected) ... 3/31/2010 Stéphane Lavirotte 22 Syslog Configuration 9 All critical messages, except the kernel ones in a dedicated file .=crit;kern.none /var/adm/critical 9 All kernel messages to a dedicated file kern.* /var/adm/kernel 9 All kernel messages are sent to another machine and to the console kern.crit @finlandia kern.crit /dev/console 9 All the kernel messages (from info to critical) to a dedicated file kern.info;kern.!err /var/adm/kern.info 9 Messages of priority mail info to a tty, the other to a file mail.=info /dev/tty12 mail.*;mail.!=info /var/adm/mail