Linux Kernel And Driver Development Training Linux Kernel .

2y ago
77 Views
11 Downloads
5.53 MB
469 Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Rosemary Rios
Transcription

Linux Kernel and Driver Development TrainingLinux Kernel and DriverDevelopment TrainingFree ElectronsFree ElectronsEmbedded LinuxDevelopers Copyright 2004-2015, Free Electrons.Creative Commons BY-SA 3.0 license.Latest update: March 22, 2015.Document updates and sources:http://free- electrons.com/doc/training/linux- kernelCorrections, suggestions, contributions and translations are welcome!Send them to feedback@free-electrons.comFree Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com1/469

Rights to copy Copyright 2004-2015, Free ElectronsLicense: Creative Commons Attribution - Share Alike egalcodeYou are free:I to copy, distribute, display, and perform the workI to make derivative worksI to make commercial use of the workUnder the following conditions:I Attribution. You must give the original author credit.I Share Alike. If you alter, transform, or build upon this work, you may distributethe resulting work only under a license identical to this one.I For any reuse or distribution, you must make clear to others the license terms ofthis work.I Any of these conditions can be waived if you get permission from the copyrightholder.Your fair use and other rights are in no way affected by the above.Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com2/469

Hyperlinks in the documentThere are many hyperlinks in the documentIRegular hyperlinks:http://kernel.org/IKernel documentation links:Documentation/kmemcheck.txtILinks to kernel source files and directories:drivers/inputinclude/linux/fb.hILinks to the declarations, definitions and instances of kernelsymbols (functions, types, data, structures):platform get irq()GFP KERNELstruct file operationsFree Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com3/469

Free Electrons at a glanceIEngineering company created in 2004(not a training company!)ILocations: Orange, Toulouse, Lyon (France)IServing customers all around the worldSee http://free-electrons.com/company/customers/IHead count: 9Only Free Software enthusiasts!IFocus: Embedded Linux, Linux kernel, Android Free Software/ Open Source for embedded and real-time systems.IActivities: development, training, consulting, technicalsupport.IAdded value: get the best of the user and developmentcommunity and the resources it offers.Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com4/469

Free Electrons on-line resourcesIIIIIIIAll our training materials:http://free-electrons.com/docs/Technical blog:http://free-electrons.com/blog/Quarterly listinfo/newsletterNews and discussions (Google ):https://plus.google.com/ FreeElectronsDevelopersNews and discussions ns-4501089Quick news (Twitter):http://twitter.com/free electronsLinux Cross Reference - browse Linux kernel sources on-line:http://lxr.free-electrons.comFree Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com5/469

Generic course informationGeneric courseinformationFree ElectronsEmbedded LinuxDevelopersFree Electrons Copyright 2004-2015, Free Electrons.Creative Commons BY-SA 3.0 license.Corrections, suggestions, contributions and translations are welcome!Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com6/469

Hardware used in this training sessionBeagleBone Black, from CircuitCoI Texas Instruments AM335x (ARM Cortex-A8)I Powerful CPU, with 3D acceleration,additional processors (PRUs) and lots ofperipherals.I 512 MB of RAMI 2 GB of on-board eMMC storage(4 GB in Rev C)I USB host and USB device portsI microSD slotI HDMI portI 2 x 46 pins headers, with access to manyexpansion buses (I2C, SPI, UART and more)I A huge number of expansion boards, calledcapes. See http://beagleboardtoys.com/.Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com7/469

Shopping list: hardware for this courseI BeagleBone Black - Multiple distributors:See http://beagleboard.org/Products/I Nintendo Nunchuck with UEXT connector:Olimex: http://j.mp/1dTYLfsI Breadboard jumper wires - Male ends:Olimex: http://j.mp/IUaBsrI USB Serial Cable - Male ends:Olimex: http://j.mp/1eUuY2KI USB Serial Cable - Female ends:Olimex: http://j.mp/18Hk8yFI Note that both USB serial cables are the same.Only the gender of their connector changes.Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com8/469

Participate!During the lectures.IDon’t hesitate to ask questions. Other people in the audiencemay have similar questions too.IThis helps the trainer to detect any explanation that wasn’tclear or detailed enough.IDon’t hesitate to share your experience, for example tocompare Linux / Android with other operating systems usedin your company.IYour point of view is most valuable, because it can be similarto your colleagues’ and different from the trainer’s.IYour participation can make our session more interactive andmake the topics easier to learn.Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com9/469

Practical lab guidelinesDuring practical labs.IWe cannot support more than 8 workstations at once (eachwith its board and equipment). Having more would make thewhole class progress slower, compromising the coverage of thewhole training agenda (exception for public sessions: up to 10people).ISo, if you are more than 8 participants, please form up to 8working groups.IOpen the electronic copy of your lecture materials, and use itthroughout the practical labs to find the slides you need again.IDon’t copy and paste from the PDF slides.The slides contain UTF-8 characters that look the same asASCII ones, but won’t be understood by shells or compilers.Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com10/469

Cooperate!As in the Free Software and Open Source community, cooperationduring practical labs is valuable in this training session:IIf you complete your labs before other people, don’t hesitateto help other people and investigate the issues they face. Thefaster we progress as a group, the more time we have toexplore extra topics.IExplain what you understood to other participants whenneeded. It also helps to consolidate your knowledge.IDon’t hesitate to report potential bugs to your instructor.IDon’t hesitate to look for solutions on the Internet as well.Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com11/469

Command memento sheetIThis memento sheet givescommand examples for the mosttypical needs (looking for files,extracting a tar archive.)IIt saves us 1 day of UNIX / Linuxcommand line training.IOur best tip: in the command lineshell, always hit the Tab key tocomplete command names and filepaths. This avoids 95% of typingmistakes.IGet an electronic copy inux/command memento.pdfFree Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com12/469

vi basic commandsIThe vi editor is very useful tomake quick changes to files in anembedded target.IThough not very user friendly atfirst, vi is very powerful and itsmain 15 commands are easy tolearn and are sufficient for 99% ofeveryone’s needs!IGet an electronic copy inux/vi memento.pdfIYou can also take the quick tutorialby running vimtutor. This is aworthy investment!Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com13/469

Practical lab - Training SetupPrepare your lab environmentIDownload the lab archiveIEnforce correct permissionsFree Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com14/469

Linux Kernel IntroductionLinux KernelIntroductionFree ElectronsEmbedded LinuxDevelopersFree Electrons Copyright 2004-2015, Free Electrons.Creative Commons BY-SA 3.0 license.Corrections, suggestions, contributions and translations are welcome!Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com15/469

Linux Kernel IntroductionLinux featuresFree Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com16/469

HistoryIIThe Linux kernel is one component of a system, which alsorequires libraries and applications to provide features to endusers.The Linux kernel was created as a hobby in 1991 by a Finnishstudent, Linus Torvalds.ILinux quickly started to be used as the kernel for free softwareoperating systemsILinus Torvalds has been able to create a large and dynamicdeveloper and user community around Linux.INowadays, more than one thousand people contribute to eachkernel release, individuals or companies big and small.Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com17/469

Linux kernel key featuresIPortability and hardwaresupport. Runs on mostarchitectures.ISecurity. It can’t hide itsflaws. Its code is reviewedby many experts.IScalability. Can run onsuper computers as well ason tiny devices (4 MB ofRAM is enough).IStability and reliability.IModularity. Can includeonly what a system needseven at run time.IEasy to program. You canlearn from existing code.Many useful resources onthe net.ICompliance to standardsand interoperability.IExhaustive networkingsupport.Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com18/469

Linux kernel in the systemFree Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com19/469

Linux kernel main rolesIManage all the hardware resources: CPU, memory, I/O.IProvide a set of portable, architecture and hardwareindependent APIs to allow user space applications andlibraries to use the hardware resources.Handle concurrent accesses and usage of hardwareresources from different applications.IIExample: a single network interface is used by multiple userspace applications through various network connections. Thekernel is responsible to “multiplex” the hardware resource.Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com20/469

System callsIIThe main interface between the kernel and user space is theset of system callsAbout 300 system calls that provide the main kernel servicesIFile and device operations, networking operations,inter-process communication, process management, memorymapping, timers, threads, synchronization primitives, etc.IThis interface is stable over time: only new system calls canbe added by the kernel developersIThis system call interface is wrapped by the C library, anduser space applications usually never make a system calldirectly but rather use the corresponding C library functionFree Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com21/469

Pseudo filesystemsILinux makes system and kernel information available in userspace through pseudo filesystems, sometimes also calledvirtual filesystemsIPseudo filesystems allow applications to see directories andfiles that do not exist on any real storage: they are createdand updated on the fly by the kernelThe two most important pseudo filesystems areIIIproc, usually mounted on /proc:Operating system related information (processes, memorymanagement parameters.)sysfs, usually mounted on /sys:Representation of the system as a set of devices and buses.Information about these devices.Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com22/469

Inside the Linux kernelFree Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com23/469

Supported hardware architecturesISee the arch/ directory in the kernel sourcesIMinimum: 32 bit processors, with or without MMU, and gccsupportI32 bit architectures (arch/ subdirectories)Examples: arm, avr32, blackfin, c6x, m68k, microblaze,mips, score, sparc, umI64 bit architectures:Examples: alpha, arm64, ia64, tileI32/64 bit architecturesExamples: powerpc, x86, sh, sparcIFind details in kernel sources: arch/ arch /Kconfig,arch/ arch /README, or Documentation/ arch /Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com24/469

Embedded Linux Kernel UsageEmbedded LinuxKernel UsageFree ElectronsEmbedded LinuxDevelopersFree Electrons Copyright 2004-2015, Free Electrons.Creative Commons BY-SA 3.0 license.Corrections, suggestions, contributions and translations are welcome!Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com25/469

Embedded Linux Kernel UsageLinux kernel sourcesFree Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com26/469

Location of kernel sourcesIThe official versions of the Linux kernel, as released by LinusTorvalds, are available at http://www.kernel.orgIIIMany chip vendors supply their own kernel sourcesIIIIThese versions follow the development model of the kernelHowever, they may not contain the latest development from aspecific area yet. Some features in development might not beready for mainline inclusion yet.Focusing on hardware support firstCan have a very important delta with mainline LinuxUseful only when mainline hasn’t caught up yet.Many kernel sub-communities maintain their own kernel, withusually newer but less stable featuresIIArchitecture communities (ARM, MIPS, PowerPC, etc.),device drivers communities (I2C, SPI, USB, PCI, network,etc.), other communities (real-time, etc.)No official releases, only development trees are available.Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com27/469

Getting Linux sourcesIIThe kernel sources are available fromhttp://kernel.org/pub/linux/kernel as full tarballs(complete kernel sources) and patches (differences betweentwo kernel versions).However, more and more people use the git version controlsystem. Absolutely needed for kernel development!IIIIFetch the entire kernel sources and historygit clone alds/linux.gitCreate a branch that starts at a specific stable versiongit checkout -b name-of-branch v3.11Web interface available at ds/linux.git/tree/.Read more about Git at http://git-scm.com/Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com28/469

Linux kernel size (1)ILinux 3.10 sources:Raw size: 573 MB (43,000 files, approx 15,800,000 lines)gzip compressed tar archive: 105 MBbzip2 compressed tar archive: 83 MB (better)xz compressed tar archive: 69 MB (best)IMinimum Linux 3.17 compiled kernel size, booting on theARM Versatile board (hard drive on PCI, ext2 filesystem, ELFexecutable support, framebuffer console and input devices):876 KB (compressed), 2.3 MB (raw)IWhy are these sources so big?Because they include thousands of device drivers, manynetwork protocols, support many architectures andfilesystems.IThe Linux core (scheduler, memory management.) is prettysmall!Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com29/469

Linux kernel size (2)As of kernel version 3.10.Idrivers/: 49.4%Iarch/: 21.9%Ifs/: 6.0%Iinclude/: 4.7%Isound/: 4.4%IDocumentation/: 4.0%Inet/: 3.9%Ifirmware/: 1.0%Ikernel/: 1.0%Itools/: 0.9%Iscripts/: 0.5%Imm/: 0.5%Icrypto/: 0.4%Isecurity/: 0.4%Ilib/: 0.4%Iblock/: 0.2%I.Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com30/469

Practical lab - Get Linux Kernel Source CodeIClone the mainline Linux sourcetree with gitFree Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com31/469

Kernel Source CodeKernel SourceCodeFree ElectronsEmbedded LinuxDevelopersFree Electrons Copyright 2004-2015, Free Electrons.Creative Commons BY-SA 3.0 license.Corrections, suggestions, contributions and translations are welcome!Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com32/469

Kernel Source CodeLinux Code and Device DriversFree Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com33/469

Programming languageIIImplemented in C like all Unix systems. (C was created toimplement the first Unix systems)A little Assembly is used too:IIIICPU and machine initialization, exceptionsCritical library routines.No C used, see http://www.tux.org/lkml/#s15-3All the code compiled with gccIIIMany gcc specific extensions used in the kernel code, anyANSI C compiler will not compile the kernelA few alternate compilers are supported (Intel and Marvell)See sions.htmlFree Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com34/469

No C libraryIThe kernel has to be standalone and can’t use user spacecode.IUser space is implemented on top of kernel services, not theopposite.IKernel code has to supply its own library implementations(string utilities, cryptography, uncompression .)ISo, you can’t use standard C library functions in kernel code.(printf(), memset(), malloc(),.).IFortunately, the kernel provides similar C functions for yourconvenience, like printk(), memset(), kmalloc(), .Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com35/469

PortabilityIThe Linux kernel code is designed to be portableIAll code outside arch/ should be portableTo this aim, the kernel provides macros and functions toabstract the architecture specific detailsIIEndiannessIIIIIIIcpu to be32()cpu to le32()be32 to cpu()le32 to cpu()I/O memory accessMemory barriers to provide ordering guarantees if neededDMA API to flush and invalidate caches if neededFree Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com36/469

No floating point computationIINever use floating point numbers in kernel code. Your codemay be run on a processor without a floating point unit (likeon certain ARM CPUs).Don’t be confused with floating point related configurationoptionsIIThey are rel

I The Linux kernel is one component of a system, which also requires libraries and applications to provide features to end users. I The Linux kernel was created as a hobby in 1991 by a Finnish student, Linus Torvalds. I Linux quickly started to be used as the

Related Documents:

Anatomy of a linux kernel development Questions : – How to work kernel code? – How to write C code on the kernel? – How to building and install the kernel on old version linux? – How to release the linux kernel? – How to fixes bugs (patch) on kernel trees? Goal : –

Other Linux resources from O’Reilly Related titles Building Embedded Linux Systems Linux Device Drivers Linux in a Nutshell Linux Pocket Guide Running Linux Understanding Linux Network Internals Understanding the Linux Kernel Linux Books Resource Center linu

Linux in a Nutshell Linux Network Administrator’s Guide Linux Pocket Guide Linux Security Cookbook Linux Server Hacks Linux Server Security Running Linux SELinux Understanding Linux Network Internals Linux Books Resource Center linux.oreilly.comis a complete catalog of O’Reilly’s books on Linux and Unix and related technologies .

Thomas Petazzoni I CTO and Embedded Linux engineer at Free Electrons I Embedded Linux development: kernel and driver development, system integration, boot time and power consumption optimization, consulting, etc. I Embedded Linux training, Linux driver development training and Android system development training, with materialsFile Size: 1MB

Sep 25, 2009 · Oracle Enterprise Linux 5 Update 2 (Kernel 2.6.18 or later) Red Hat Enterprise Linux 4 Update 7 (Kernel 2.6.9 or later) Red Hat Enterprise Linux 5 Update 2 (Kernel 2.6.18 or later) SUSE Linux Enterprise Server 10 SP2 (Kernel 2.6.16.21 or later) SUSE Linux Enterprise Server 11 (2.6.27.19 or later)!! ACFS and ADVM are ONLY supported on RHEL 5 and .

What if Linux Kernel Panics Kexec: system call to load and boot into another kernel from the currently running kernel (4.9.74). crashkernel 128M [normal kernel cmdline] irqpoll, nosmp, reset_devices [crash kernel cmdline] --load-panic option Kdump: Linux mechanism to dump machine memory content on kernel panic.

n Linux is a modular, UNIX -like monolithic kernel. n Kernel is the heart of the OS that executes with special hardware permission (kernel mode). n "Core kernel" provides framework, data structures, support for drivers, modules, subsystems. n Architecture dependent source sub -trees live in /arch. CS591 (Spring 2001) Booting and Kernel .

Dosen Jurusan Pendidikan Akuntansi Fakultas Ekonomi Universitas Negeri Yogyakarta CP: 08 222 180 1695 Email : adengpustikaningsih@uny.ac.id. 23-2. 23-3 PREVIEW OF CHAPTER Intermediate Accounting IFRS 2nd Edition Kieso, Weygandt, and Warfield 23. 23-4 6. Identify sources of information for a statement of cash flows. 7. Contrast the direct and indirect methods of calculating net cash flow from .