Getting Started with Linux

From wiki.emacinc.com
Revision as of 18:26, 8 November 2013 by Mdean (talk | contribs) (Rejected the last text change (by Jgreene) and restored revision 1025 by Jgreene)
Jump to: navigation, search
TODO: {{#todo:Review; (10.29.13-21:50->MD+)|Klint Youngmeyer|oe 4,oe 5,ky,FinalDraft, md}}

To develop software effectively for a platform it is important to gain an understanding of the operating system in use on that platform. Embedded Linux is the operating system in use for most EMAC products. For this reason we at EMAC have put together material that can be used to gain understanding and insight into the Linux operating system. In this guide we provide some background information, and even a tiny bit of history, to give you the background knowledge you need to gain insight. We then provide you with some links to resources which will allow you to gain an understanding of the tools available within Linux.

Once you have gained this basic ground of insight and understanding you will be well prepared to delve into the EMAC documentation to explore the opportunities available to you within the EMAC OE Linux platform. Should you find yourself struggling through any of the EMAC OE documentation, returning to this page to refresh yourself on the basics of Linux may be just what you need to get past that hurdle. While we do our best in the EMAC OE Linux documentation to keep the prerequisite knowledge to a minimum, some of the topics we address will require comfort with Linux to gain the greatest insight and understanding. With such insight and understanding your creation can truly shine.

What is Linux?

Linux is a fully formed operating system, not to be underestimated. It is a very capable system, and is fundamentally based upon the design of Unix. As such, there is much heritage present within both the design of the Linux operating system and its user base. A great deal of effort has been put into making it the fast, secure operating system it is today. It is the definitive operating system of choice for supercomputers around the world, according to [supercomputer listing statistics] (choose the Operating System category to see this). It is the host operating system for the majority of the largest search engines, monetary exchange systems, retail stores and social sites on the Internet. It can be found running in many home routers, PVR's, TV's and other devices. Linux is in use handling telecommunications systems, running planetary explorer robots, and providing the host operating system for millions of smartphones. This large user base continues to drive the innovation and pace of development of the Linux operating system and its applications.

It's safe to say that Linux is here to stay. The open nature of the operating system combined with the popularity it enjoys ensures that it will continue to be around for a long time to come. Effort spent learning the Linux operating system is effort well spent. While minor details of the operating system will inevitably change over time, the overall shape, scope and focus of the operating system are well defined. Linux has a tradition of not changing anything too quickly, and only changing things if the community deems it truly important to do so. No one person or entity drives these changes. They're driven by the large user and developer base.

To be clearer: should a single person decide to change something, there is nothing to stop the person from doing so since all the source code is available to everyone. In fact this happens quite often. However, unless the community at large feels that the change is worth having, the change will not be adopted. This is the way opensource software is filtered. The community takes the good changes and discards the bad. Egos are often bruised by this process but the benefits go to the community of users as a whole.

Granted, as an embedded developer, you probably have no interest in contributing to the community. However, understanding the way the community works provides insight into where it all came from and where it's going. The above description is by no means complete but should serve to provide useful insight. Hopefully it will enhance your understanding of what you read and learn over the course of your project(s) and/or career working with Embedded Linux.

With that background in mind you will hopefully have a positive attitude towards learning Linux. Fortunately there are many resources available for learning how to use Linux and its shell. Presented here is just a small subset of these resources that we at EMAC have found to be rather good. We're sure we haven't found all the good ones, and it's very possible we have missed some of the best. These are just the best we know about and are prefaced here with some useful background information to get you started.

Once you have learned from the resources presented here, don't forget to come back for the EMAC specific material elsewhere on our wiki. The majority of the remaining content on our wiki comes from us and would be difficult (if not impossible) to find elsewhere.

We hope you will enjoy your learning experience.

The Very Beginning With Linux

When using a new operating system for the first time, some time must be spent acclimating oneself to the new operating environment. This process begins with installing the operating system (if it wasn't already done for you); progresses through exploring the desktop environment; and continues to exploring the various applications available for performing various tasks. This very important step should not be overlooked. Every operating system is its own creature. Becoming comfortable with a new operating system requires an open mind focused towards seeing computing through the eyes of the people behind it. This series of documents will serve as a gentle guide into that.

Getting Started With the Linux Shell

People coming from PCs are generally unaccustomed to using a command prompt to perform many tasks. Linux, however, is derived from Unix. Unix was designed by programmers for programmers. The C programming language was developed in parallel with Unix by the same team of developers. The Unix operating system and the C programming language developed in support of each other. At that time, programming was an expected duty of anyone using a computer. The shell was developed to be the primary interface to the computer for these programming savvy people. The Linux shell came about with a great deal of motivation from Unix, but with the inspiration of a new generation of programmers, many of whom started with a PC or other non-Unix operating system. This new generation of programmers became fascinated by the old ways of Unix but carried with them expectations rooted in the easier to use operating systems from which they came. As a result the Linux shell was born and has become arguably the most sophisticated shell currently available on any operating system.

Learning the Linux shell, and shell scripting, is essential. Many processes are performed on Linux systems with shell scripts. Many of the standard tools used for systems administration tasks, such as performing backups and configuring the network interfaces, are actually shell scripts. Even the initialization system used to bring the Linux operating system up from boot to a fully functioning desktop or server is a series of shell scripts (on most Linux distributions, including EMAC OE).

Shell scripts can:

  • Use named pipes.
  • Communicate raw data over TCP sockets.
  • Spawn child processes.
  • Operate concurrently.
  • Respond to signals.
  • Communicate over GPIO.
  • Communicate over SPI.
  • Communicate over I2C.
  • Control hardware, such as the LCD backlight.
  • Automatically perform tasks when a file or directory is created, changed or deleted (search for inotify).
  • And much, much more!

There is virtually no limit to what can be accomplished with the Linux shell. In fact, there isn't even a limit on the shell used. The most commonly used shell is bash, the Bourne-Again Shell. This was derived from sh, the Bourne shell (Bourne is the name of the fellow who created it). Other popular shells include:

  • The Korn shell, ksh, a close relative of bash.
  • The C shell, csh, which is designed to have similarity to the C programming language.
  • The Tiny C shell, tcsh, a streamlined version of the C shell.
  • The Z shell, zsh, which is intended to be the most sophisticated shell. It has yet to be perfected, however.
  • The Almquist shell, ash, a small, fast shell which is based on the Bourne shell. It is popular in embedded systems because of its speed and small size, and is the default shell for many embedded Linux systems.

Since bash has become the most popular shell on Linux, and it and a streamlined version of it are available in the EMAC OE firmware, it is the focus for the documentation towards which we direct you. The following series of guides on using the Linux shell should not be missed. They will provide much valuable insight into how to work with your Linux desktop. This understanding is essential for mastering embedded Linux.

Useful Shell Tools and Methods

Knowing how to use a shell in and of itself may be nice, but it's far more useful once you also know the plethora of tools available for your use within the shell. There are a great number of commands available within Linux, and their usefulness is enhanced by the fact that they were designed to be used in combination with each other as easily as they can be used standalone. The names of the commands tend to mirror the names of the C library functions which implement similar or identical behavior. This makes moving back and forth between using the shell and programming in C under Linux a very natural process. It also means the process of learning the shell and related tools provides insight into the C library functions available for Linux.

The tools in the Linux shell mostly exist as programs, rather than being built into the shell. Even the ls command, which is equivalent to the dir command within Microsoft operating systems, is a separate program. This design decision was made in Unix, and carried over to Linux.

The design decision to implement the utility functionality in small, separate programs proved to be a big design win. It allowed the tools to grow independently of the shells, and allowed development effort to be concentrated into each program separately, as well as each shell separately, and promoted a unified set of tools for working in the shell regardless of which shell was in use. However, the constraints of an embedded system inspired the creation of a single tool which includes much of this functionality within it. Hence, BusyBox was born.

While BusyBox incorporates many of the tools into one package, the shell remains separate and the commands carry the same names and arguments as the standalone equivalents. To keep the BusyBox binary small, though, not all functionality is available with the BusyBox commands. BusyBox does implement the most important features of the tools found in a normal Linux system. The standalone tools have grown to have so many options over the many years they've been in use, however, that not all of the functionality is needed within an embedded system. When learning the shell tools for Linux, one should keep in mind that not all of the arguments learned will be available within a BusyBox environment.

This limitation isn't severe. On a current Linux desktop distribution, the ls command (which performs the same type of task as the dir command on Microsoft operating systems) has 62 arguments which can be used to customize its behavior. 62 distinct arguments is more than anyone can reasonably be expected to need within an embedded environment. In fact, most people will never use that many in a desktop or server environment. This is the motivation behind streamlining the commands for embedded systems.

The first link provided below describes a tool which allows one to have many terminals open in parallel, and move back and forth between them. It is a very useful tool when performing a lot of work with the shell, and should at least be noted for future use. The second link is essential. It provides important information about the most important of the plethora of tools available within a Linux shell. EMAC strongly recommends spending some time learning the commands described therein.

Very Important Initialization and Scripting Information

Shell scripting is very important in embedded Linux systems. Since the init system uses shell scripts to initialize devices, start up daemons (equivalent to services on Microsoft operating systems), perform miscellaneous tasks (such as creating a filesystem and copying files into a ramdisk on an embedded system), and start programs (such as the login shell and, presumably, the embedded application you create), it is necessary to learn at least a little bit of shell scripting for your embedded work.

The first link below gives a nice overview of the boot and initialization process. This should be studied to ensure you will be able to make your embedded machine start up and run as expected. The remaining links give a beginner through advanced coverage of scripting in bash. The first two should be studied. The remaining one can be studied as well, if time permits, but works as a great reference for all things pertaining to bash scripting.

General Linux Programming

The standard C and C++ libraries are supported on Linux. Your existing knowledge and books pertaining to these languages will serve you well so long as they aren't specific to one vendor's version of the languages. The other libraries you choose will provide their own documentation, which isn't linked to here. You will need to find the documentation for these libraries from the library providers. If you chose the Qt option, for instance, the provider of Qt is Digia.

The compiler used for EMAC OE systems is gcc (the GNU Compiler Collection). The compiler provides extensive documentation online. The documentation is specific to the compiler version you use. Below are links to the compiler versions used for EMAC OE:



Programming for the Linux kernel itself should be learned from a combination of the latest available books on the topic, the links provided below, and the linux-x.x.x/Documentation/ directory in the source tree for the Linux kernel.

BusyBox (Provides Many of the Tools for Embedded Linux Systems)

Often called the Swiss Army Knife of Embedded Linux, BusyBox provides a great number of tools for use in the shell which would normally be distributed among many separate programs. In all, it incorporates functionality from over 200 utilities, and puts them into a single binary executable. Cleverly, it uses the information in argv[0] to determine the name which was used to execute it, and performs the functionality expected from that name. It exists with many names, but only one copy in flash, through the use of either symbolic links or hard links. On EMAC OE systems symbolic links are used to achieve this.



This approach allows a wealth of functionality to be provided in a minimum of space. This space savings also allows Linux to keep the executable in its cache (not to be confused with the L1/L2/L3 hardware caches), which enables it to execute very quickly.

BusyBox goes hand-in-hand with the ash shell but it can be used with the bash shell, the csh shell or any of the other Linux shells as well. Regardless of what shell you choose for your machine getting acquainted with BusyBox will be very beneficial. If you look hard enough you may even be surprised at the other places you find it running. Many home routers, for instance, run BusyBox. More and more televisions and Bluray players do as well (although you may not be able to get a console on them). BusyBox will only continue to grow in commonality as embedded devices powerful enough to run Linux become cheaper with the inevitable shrinking of processor die sizes.

The following links will help you get to know this powerful tool:

See Also