Linux System Configuration (Part 1)

In Circuit Cellar’s June issue, Bob Japenga, in his Embedded in Thin Slices column, launches a series of articles on Linux system configuration. Part 1 of the series focuses on configuring the Linux kernel. “Linux kernels have hundreds of parameters you can configure for your specific application,” he says.

Linux system configurationPart 1 is meant to help designers of embedded systems plan ahead. “Many of the options I discuss cost little in terms of memory and real-time usage,” Japenga says in Part 1. “This article will examine the kinds of features that can be configured to help you think about these things during your system design. At a minimum, it is important for you to know what features you have configured if you are using an off-the-shelf Linux kernel or a Linux kernel from a reference design. Of course, as always, I’ll examine this only in thin slices.”

In the following excerpt from Part 1, Japenga explains why it’s important to be able to configure the kernel. (You can read the full article in the June issue, available online for single-issue purchase or membership download.)

Why Configure the Kernel?
Certainly if you are designing a board from scratch you will need to know how to configure and build the Linux kernel. However, most of us don’t build a system from scratch. If we are building our own board, we still use some sort of reference design provided by the microprocessor manufacturer. My company thinks these are awesome. The reference designs usually come with a prebuilt kernel and file system.

Even if you use a reference design, you almost always change something. You use different memory chips, physical layers (PHY), or real-time clocks (RTCs). In those cases, you need to configure the kernel to add support for these hardware devices. If you are fortunate enough to use the same hardware, the reference design’s kernel may have unnecessary features and you are trying to reduce the memory footprint (which is needed not just because of your on-board memory but also because of the over-the-air costs of updating, as I mentioned in the introduction). Or, the reference design’s kernel may not have all of the software features you want.

For example, imagine you are using an off-the-shelf Linux board (e.g., a Raspberry Pi or BeagleBoard.org’s BeagleBone). It comes with everything you need, right? Not necessarily. As with the reference design, it may use too many resources and you want to trim it, or it may not have some features you want. So, whether you are using a reference design or an off-the-shelf single-board computer (SBC), you need to be able to configure the kernel.

Linux Kernel Configuration
Many things about the Linux kernel can be tweaked in real time. (This is the subject of a future article series.) However, some options (e.g., handling Sleep mode and support for new hardware) require a separate compilation and kernel build. The Linux kernel is written in the C programming language, which supports code that can be conditionally compiled into the software through what is called a preprocessor #define

A #define is associated with each configurable feature. Configuring the kernel involves selecting the features you want with the associated #define, recompiling, and rebuilding the kernel.

Okay, I said I wasn’t going to tell you how to configure the Linux kernel, but here is a thin slice: One file contains all the #defines. Certainly, one could edit that file. But the classic way is to invoke menuconfig. Generally you would use the make ARCH=arm menuconfig command to identify the specific architecture.

There are other ways to configure the kernel—such as xconfig (QT based), gconfig (GTK+ based), and nconfig (ncurses based)—that are graphical and purport to be a little more user-friendly. We have not found anything unfriendly with using the classical method. In fact, since it is terminal-based, it works well when we remotely log in to the device.

Photo 1—This opening screen includes well-grouped options for easy menu navigation.

Photo 1—This opening screen includes well-grouped options for easy menu navigation.

Photo 1 shows the opening screen for one of our configurations. The options are reasonably well grouped to enable you to navigate the menus. Most importantly, the mutual dependencies of the #defines are built into the tool. Thus if you choose a feature that requires another to be enabled, that feature will also automatically be selected.

In addition to the out-of-the-box version, you can easily tailor all the configuration tools if you are adding your own drivers or drivers you obtain from a chip supplier. This means you can create your own unique menus and help system. It is so simple that I will leave it to you to find out how to do this. The structure is defined as Kconfig, for kernel configuration.

An Organized Space for Programming, Writing, and Soldering

AndersonPhoto1

Photo 1—This is Anderson’s desk when he is not working on any project. “I store all my ‘gear’ in a big plastic bin with several smaller bins inside, which keeps the mess down. I have a few other smaller storage bins as well hidden here and there,” Anderson explained.

AndersonPhoto2

Photo 2—Here is Anderson’s area set up for soldering and running his oscilloscope. “I use a soldering mat to protect my desk surface,” he says. “The biggest issue I have is the power cords from different things getting in my way.”

Al Anderson’s den is the location for a variety of ongoing projects—from programming to writing to soldering. He uses several plastic bins to keep his equipment neatly organized.

Anderson is the IT Director for Salish Kootenai College, a small tribal college based in Pablo, MT. He described some of his workspace features via e-mail:

I work on many different projects. Lately I have been doing more programming. I am getting ready to write a book on the Xojo development system.

Another project I have in the works is using a Raspberry Pi to control my hot tub. The hot tub is about 20 years old, and I want to have better control over what it is doing. Plus I want it to have several features. One feature is a wireless interface that would be accessible from inside the house. The other is a web control of the hot tub so I can turn it on when we are still driving back from skiing to soak my tired old bones.

I am also working on a home yard sprinkler system. I laid some of the pipe last fall and have been working on and off with the controller. This spring I will put in the sprinkler heads and rest of the pipe. I tend to like working with small controllers (e.g., the Raspberry Pi, BeagleBoard’s BeagleBone, and Arduino) and I have a lot of those boards in various states.

Anderson’s article about a Raspberry Pi-based monitoring device will appear in Circuit Cellar’s April issue. You can follow him on Twitter at @skcalanderson.