Getting Started with Linux

From wiki.emacinc.com
Revision as of 18:08, 2 January 2014 by Mdean (talk | contribs) (Undo revision 2659 by Mgloff (talk))
Jump to: navigation, search
TODO: {{#todo:Review; (10.29.13-21:50->MD+);(11.08.13-18:55->MD+);(11.12.13-18:45->MD+);(12.30.13-16:45->MG+)|Klint Youngmeyer|oe 4,oe 5,ky, md,Review}}

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. This guide provides some background information, and even a tiny bit of the history of Linux. Links to resources of the tools available within Linux are provided as well.

Reading through this guide and the associated links will prepare the novice Linux user to start developing applications for EMAC OE based products. This guide also serves as a place to come back to for a refresher. While most of the EMAC OE Linux documentation requires minimal prerequisite knowledge, some of the topics will require comfort with the Linux operating system.

What is Linux?

Linux is a fully formed operating system 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 a fast, secure operating system. It is the definitive operating system of choice for supercomputers around the world, according to TOP500.org supercomputer list statistics (choose the Operating System category). 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, DVRs, TVs 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.

The open nature of the operating system combined with the popularity it enjoys ensures it will continue to be around for a long time to come. Effort spent learning the Linux operating system will not be wasted. 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. Development of features in Linux is quick, driven by the needs of the community, and developed through collective skills. Care is exercised in drastically changing core functionality, leading to a more stable system.

Since all of the source code is available to everyone, an individual can make fixes or customizations to their system. However, the change may not be adopted into an official release if the community at large doesn't feel the change is worth having or may break other types of systems. In this way, opensource software is approved for use by everyone.

As an embedded developer, opportunities to contribute to the community may be rare. However, understanding the way the community works provides insight into how Linux was created and continues to be developed.

There are many resources available for learning how to use Linux and its shell. Presented here is just the small subset of these resources to get started. Once the basics of Linux are understood, the EMAC specific material on the wiki will provide information about EMAC OE Linux devices that cannot be found elsewhere.

The Very Beginning With Linux

When using an operating system for the first time, some time must be spent to become familiar with the operating environment. This process begins with installing the operating system (if not already done), progresses through exploring the desktop environment on the OS, and continues with exploring the various applications available for performing different tasks. To become comfortable with a new operating system requires an open mind and willingness to learn. This series of documents will serve as a guide to getting started.

Getting Started With the Linux Shell

Those familiar will PCs are generally unaccustomed to using a command prompt to perform many tasks. Linux, however, is derived from Unix and uses the command prompt heavily. The C programming language was developed in parallel with Unix in support of it. At the time this took place, programming was an expected duty of anyone using a computer. The shell was developed to be the primary interface to the computer. 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 of an easier to use operating systems.

Many processes performed on Linux systems are done so with shell scripts. Tools used for systems administration tasks, such as performing backups and configuring the network interfaces, are shell scripts. 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).
  • Much, much more.

There is virtually no limit to what can be accomplished with the Linux shell. Different shells are available, the most common being bash, the Bourne-Again Shell. This was derived from sh, the Bourne shell (Bourne is the name of the developer who created sh). 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, is 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, it is included in EMAC OE systems by default. The following is a series of guides on using the Linux shell. This understanding is essential for mastering embedded Linux.

Useful Shell Tools and Methods

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. The ls command, equivalent to the dir command within Microsoft operating systems, is a separate program. This design decision allows the tools to grow independently of the shells, and allows development effort to be concentrated into each program separately, as well as each shell separately. This promotes a unified set of tools for working in the shell regardless of which shell is in use.

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 provides important information about the most important of the tools available within a Linux shell. It is recommended to spend some time learning the commands described therein.

BusyBox

Because of the constraints of an embedded system, a single tool which includes much of this functionality is desirable. BusyBox incorporates functionality from over 200 utilities, and puts them into a single binary executable. It uses the command name passed to it to determine which functionality to perform. On EMAC OE systems, symbolic links are used to point the name of the command to the BusyBox executable

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.

To keep the BusyBox binary small, not all functionality is available with the BusyBox commands, although the most important features are implemented. The standalone tools have grown to have many options that are not necessary for an embedded system.

For example, on a current Linux desktop distribution, the ls command has 62 arguments which can be used to customize its behavior. The BusyBox version strips the number of available options down to 26. This allows for the most common used of the command to be used without adding unnecessary complexity.

==Initialization and Scripting Information==Since the init system uses shell scripts to initialize devices, start up daemons (equivalent to services on Microsoft operating systems), perform miscellaneous tasks, 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 embedded work.

The first link below gives a nice overview of the boot and initialization process. This will help in making an embedded machine start up and run as expected. The remaining links guide a beginner through advanced coverage of scripting in bash.

General Linux Programming

The standard C and C++ libraries are supported on Linux. Existing knowledge and books pertaining to these languages will be helpful as long as they aren't specific to one vendor's version of the languages. Other libraries used, i.e. Qt, will provide their own documentation, which isn't linked to here.

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

There are very useful gcc-specific keywords and macros available in gcc, as well. A little known macro, _ _FUNCTION_ _, is available in gcc and has some variations. It has recently gained support in other compilers as well. This macro can be very useful for debug and log messages. More information can be found on gcc's website. The gcc documentation provides information about the other extensions it includes, as well.

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.

See Also