Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learning Embedded Linux Using the Yocto Project

You're reading from  Learning Embedded Linux Using the Yocto Project

Product type Book
Published in Jun 2015
Publisher
ISBN-13 9781784397395
Pages 334 pages
Edition 1st Edition
Languages
Authors (2):
Alexandru Vaduva Alexandru Vaduva
Profile icon Alexandru Vaduva
Vaduva Jan Alexandru Vaduva Jan Alexandru
View More author details

Table of Contents (20) Chapters

Learning Embedded Linux Using the Yocto Project
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Introduction Cross-compiling Bootloaders Linux Kernel The Linux Root Filesystem Components of the Yocto Project ADT Eclipse Plug-ins Hob, Toaster, and Autobuilder Wic and Other Tools Real-time Security Virtualization CGL and LSB Index

Chapter 4. Linux Kernel

In this chapter, you will not only learn about the Linux kernel in general, but also specific things about it. The chapter will start with a quick presentation of the history of Linux and its role and will then continue with an explanation of its various features. The steps used to interact with the sources of the Linux kernel will not be omitted. You will only be presented with the steps necessary to obtain a Linux kernel image from a source code, but also information about what porting for an new ARM machine implies, and some of the methods used to debug various problems that could appear when working with the Linux kernel sources in general. In the end, the context will be switched to the Yocto Project to show how the Linux kernel can be built for a given machine, and also how an external module can be integrated and used later from a root filesystem image.

This chapter will give you an idea of the Linux kernel and Linux operating system. This presentation would...

The role of the Linux kernel


With an impressive numbers of code lines, the Linux kernel is one of the most prominent open source projects and at the same time, the largest available one. The Linux kernel constitutes a piece of software that helps with the interfacing of hardware, being the lowest-level code available that runs in everyone's Linux operating system. It is used as an interface for other user space applications, as described in the following diagram:

The main roles of the Linux kernel are as follows:

  • It provides a set of portable hardware and architecture APIs that offer user space applications the possibility to use necessary hardware resources

  • It helps with the management of hardware resources, such as a CPU, input/output peripherals, and memory

  • It is used for the management of concurrent accesses and the usage of necessary hardware resources by different applications.

To make sure that the preceding roles are well understood, an example will be very useful. Let's consider that...

Delving into the features of the Linux kernel


This section will introduce a number of features available inside the Linux kernel. It will also cover information about each of them, how they are used, what they represent, and any other relevant information regarding each specific functionality. The presentation of each feature familiarizes you with the main role of some of the features available inside the Linux kernel, as well as the Linux kernel and its source code in general.

On a more general note, some of the most valuable features that the Linux kernel has are as follows:

  • Stability and reliability

  • Scalability

  • Portability and hardware support

  • Compliance with standards

  • Interoperability between various standards

  • Modularity

  • Ease of programming

  • Comprehensive support from the community

  • Security

The preceding features does not constitute actual functionalities, but have helped the project along its development process and are still helping it today. Having said this, there are a lot of features that...

Interrupts


An interrupt is a representation of an event that changes the succession of instructions performed by the processor. Interrupts imply an electric signal generated by the hardware to signal an event that has happened, such as a key press, reset, and so on. Interrupts are divided into more categories depending on their reference system, as follows:.

  • Software interrupts: These are usually exceptions triggered from external devices and user space programs

  • Hardware interrupts: These are signals from the system that usually indicate a processor specific instruction

The Linux interrupt handling layer offers an abstraction of interrupt handling for various device drivers through comprehensive API functions. It is used to request, enable, disable, and free interrupts, making sure that portability is guaranteed on multiple platforms. It handles all available interrupt controller hardware.

The generic interrupt handling uses the __do_IRQ() handler, which is able to deal with all the available...

Timers


Around the Linux kernel, there are a great number of functions that are influenced by time. From the scheduler to the system uptime, they all require a time reference, which includes both absolute and relative time. For example, an event that needs to be scheduled for the future, represents a relative time, which, in fact, implies that there is a method used to count time.

The timer implementation can vary depending on the type of the event. The periodical implementations are defined by the system timer, which issues an interrupt at a fixed period of time. The system timer is a hardware component that issues a timer interrupt at a given frequency to update the system time and execute the necessary tasks. Another one that can be used is the real-time clock, which is a chip with a battery attached that keeps counting time long after the system was shut down. Besides the system time, there are dynamic timers available that are managed by the kernel dynamically to plan events that run...

Linux kernel interaction


Until now, you were introduced to some of features of the Linux kernel. Now, it is time to present more information about the development process, versioning scheme, community contributions, and and interaction with the Linux kernel.

The development process

Linux kernel is a well known open source project. To make sure that developers know how to interact with it, information about how the git interaction is done with this project, and at the same time, some information about its development and release procedures will be presented. The project has evolved and its development processes and release procedures have evolved with it.

Before presenting the actual development process, a bit of history will be necessary. Until the 2.6 version of the Linux kernel project, one release was made every two or three years, and each of them was identified by even middle numbers, such as 1.0.x, 2.0.x, and 2.6.x. The development branches were instead defined using even numbers, such...

Kernel sources


The official location for the Linux kernel is available at http://www.kernel.org, but there a lot of smaller communities that contribute to the Linux kernel with their features or even maintain their own versions.

Although the Linux core contains the scheduler, memory management, and other features, it is quite small in size. The extremely large number of device drivers, architectures and boards support together with filesystems, network protocols and all the other components were the ones that made the size of the Linux kernel really big. This can be seen by taking a look at the size of the directories of the Linux.

The Linux source code structure contains the following directories:

  • arch: This contains architecture-dependent code

  • block: This contains the block layer core

  • crypto: This contains cryptographic libraries

  • drivers: This gathers all the implementation of the device drivers with the exception of the sound ones

  • fs: This gathers all the available implementations of filesystem...

Devices and modules


As I mentioned previously, the Linux kernel has a lot of kernel modules and drivers that are already implemented and available inside the source code of the Linux kernel. A number of them, being so many, are also available outside the Linux kernel source code. Having them outside not only reduces the boot time by not initializing them at boot time, but is done instead at the request and needs of users. The only difference is that the loading and unloading of the modules requires root access.

Loading and interacting with the Linux kernel modules requires logging information to be made available. The same happens for any kernel module dependencies. The logging information is available through the dmesg command and the level of logging enables manual configuration using the loglevel parameter or it can be disabled with the quite parameter. Also for the kernel dependencies, information about them is available inside the /lib/modules/<kernel-version>/modules.dep file...

Debugging a kernel


Having to debug the Linux kernel is not the most easy task, but it needs to be accomplished to make sure that the development process moves forward. Understanding the Linux kernel is, of course, one of the prerequisites. Some of the available bugs are very hard to solve and may be available inside the Linux kernel for a long period of time.

For most of the trivial ones, some of the following steps should be taken. First, identify the bug properly; it is not only useful when define the problem, but also helps with reproducing it. The second step involves finding the source of the problem. Here, I am referring to the first kernel version in which the bug was first reported. Good knowledge about the bug or the source code of the Linux kernel is always useful, so make sure that you understand the code before you start working on it.

The bugs inside the Linux kernel have a wide spread. They vary from a variable not being stored properly to race conditions or hardware management...

The Yocto Project reference


Moving on to the Yocto Project, we have recipes available for every kernel version available inside the BSP support for each supported board, and recipes for kernel modules that are built outside the Linux kernel source tree.

The Atmel SAMA5D3-Xplained board uses the linux-yocto-custom kernel. This is defined inside the conf/machine/sama5d3-xplained.conf machine configuration file using the PREFERRED_PROVIDER_virtual/kernel variable. No PREFERRED_VERSION is mentioned, so the latest version is preferred; in this case, we are talking about the linux-yocto-custom_3.10.bb recipe.

The linux-yocto-custom_3.10.bb recipe fetches the kernel sources available inside Linux Torvalds' git repository. After a quick look at the sources once the do_fetch task is finished, it can be observed that the Atmel repository was, in fact, fetched. The answer is available inside the linux-yocto-custom_3.10.bbappend file, which offers another SR_URI location. Other useful information you...

Summary


In this chapter, you learned about the Linux kernel in general, about its features and methods of interacting with it. There was also information about debugging and porting features. All this was done to make sure that you would get enough information about the whole ecosystem before interacting with it. It is my opinion that if you understand the whole picture first, it will become easier to focus on the more specific things. This is also one of the reasons that the Yocto Project reference was kept toward the end. You were introduced to how a Linux kernel recipe and a Linux kernel external module are defined and used later by a given machine. More information on Linux kernels will also be available in the next chapter, which will gather all the previously presented information and will show you how a developer can interact with a Linux operating system image.

Besides this information, in the next chapter, there will be an explanation about the organization of the root file system...

lock icon The rest of the chapter is locked
You have been reading a chapter from
Learning Embedded Linux Using the Yocto Project
Published in: Jun 2015 Publisher: ISBN-13: 9781784397395
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}