Difference between revisions of "Getting Started with Linux"

From wiki.emacinc.com
Jump to: navigation, search
m (Reverted edits by Jgreene (talk) to last revision by Mdean)
m (Updated to use new templates.)
 
(24 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{todo|Review; (10.29.13-21:50->MD+)(11.08.13-18:55->MD+)|Klint Youngmeyer|project=oe 4,oe 5,ky,FinalDraft, md}}
+
{{todo|Complete;(10.29.13-21:50->MD+);(11.08.13-18:55->MD+);(11.12.13-18:45->MD+);(12.30.13-16:45->MG+);(1.3.14-15:30->ER+)(03.04.14-15:05->BS-);(03.07.14-10:45->BS+)(03.10.14-15:05->BS+)(11.11.2015-18:15->MD+)|Klint Youngmeyer|project=oe 4,oe 5,ky, md,bs,Complete}}
  
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.<br />
+
{{#seo:
 +
|title=Getting Started with Linux
 +
|titlemode=append
 +
|keywords=EMAC,EMAC OE Linux,Linux Shell,BusyBox,Linux Programming
 +
|description=Getting started with Linux and useful tools to use.
 +
}}
  
Once you have gained this basic grounding 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 the 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 of the development process.  With such insight and understanding, your creation can truly shine.
+
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 some history of Linux. Links to resources of the tools available within Linux are provided as well.<br />
 +
 
 +
Reading through this guide and the associated links will help 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 as a reference. 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?==
 
==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 [[http://i.top500.org/stats|TOP500.org 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.<br />
+
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 [http://top500.org/statistics/list/ 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 embedded 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.<br />
 
 
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 it will continue to be around for a long time to come.  Effort spent learning the Linux operating system will not be effort 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.  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.<br />
 
 
 
To be more clear, 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 often.  However, the change simply will not be adopted if the community at large doesn't feel the change is worth having.  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.<br />
 
  
Granted, as an embedded developer, you likely 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.<br />
+
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.<br />
  
With the background just given 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 the 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.<br />
+
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.<br />
  
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.<br />
+
As an embedded application 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.  
  
We hope you will enjoy your learning experience.
+
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. <br />
  
 
==The Very Beginning With Linux==
 
==The Very Beginning With Linux==
  
When using a new operating system for the first time, some time must be spent to acclimate oneself with one's new operating environment. This process begins with installing the operating system (if it wasn't done for you), progresses through exploring the desktop environment on the OS, and continues with exploring the various applications available for performing different tasks.This very important step should not be overlooked.  Every operating system is its own creature.  To become comfortable with a new operating system requires an open mind focused towards seeing computing through the eyes of the people behind the operating system being newly experienced. This series of documents will serve as a gentle guide into this foray.
+
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.
 
* [http://polishlinux.org/installation/ Installing Linux]
 
* [http://polishlinux.org/installation/ Installing Linux]
 
* [http://polishlinux.org/first-steps/ Taking Your First Steps in Linux]
 
* [http://polishlinux.org/first-steps/ Taking Your First Steps in Linux]
Line 29: Line 33:
  
 
==Getting Started With the Linux Shell==
 
==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 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 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.<br />
 
  
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).<br />
+
Those familiar will current desk-top 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.<br />
 +
 
 +
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).<br />
  
 
Shell scripts can:
 
Shell scripts can:
Line 46: Line 51:
 
* Much, much more.<br />
 
* Much, much more.<br />
  
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:
+
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 Korn shell, ''ksh'', a close relative of ''bash''.
 
* The C shell, ''csh'', which is designed to have similarity to the C programming language.
 
* 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 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 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.<br />
+
* 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.<br />
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.<br />
+
 
 +
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.<br />
  
 
* [http://polishlinux.org/console/ Using Linux from the Console]
 
* [http://polishlinux.org/console/ Using Linux from the Console]
Line 60: Line 66:
  
 
==Useful Shell Tools and Methods==
 
==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.<br />
 
  
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.<br />
+
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.<br />
 +
 
  
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.<br />
+
{{ note | To get additional information on many Linux commands use the following syntax: <br /> {{ icli |Command --help}} <br /> for additional information on a command: <br />{{ icli |man Command}} }}
  
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.<br />
 
  
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.  Sixty two 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.<br />
+
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. <br />
  
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.<br />
+
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.<br />
  
 
* [http://polishlinux.org/howtos/screen-tips-tricks/ Screen Tips & Tricks]
 
* [http://polishlinux.org/howtos/screen-tips-tricks/ Screen Tips & Tricks]
 
* [http://www.tldp.org/LDP/GNU-Linux-Tools-Summary/html/index.html Linux Command-Line Tools]
 
* [http://www.tldp.org/LDP/GNU-Linux-Tools-Summary/html/index.html Linux Command-Line Tools]
==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.<br />
+
==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<br />
  
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.<br />
+
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.
 +
 
 +
* [http://en.wikipedia.org/wiki/BusyBox#Commands List of BusyBox Commands]
 +
* [http://spblinux.de/2.0/doc/busybox.html Help With BusyBox Commands]  '''NOTE''': May show some commands which are not available in the EMAC OE build.
 +
* [http://www.busybox.net/ BusyBox Homepage]
 +
* [http://www.ibm.com/developerworks/library/l-busybox/ Building BusyBox]
 +
 
 +
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. <br />
 +
 
 +
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.<br />
 +
 
 +
==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.<br />
 +
 
 +
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 provide a guide for beginner through advanced coverage of scripting in ''bash''.<br />
  
 
* [http://polishlinux.org/linux/the-linux-saga-boot-loader-initrd-sys-v/ The Bootloader and Init System on Desktop Linux]
 
* [http://polishlinux.org/linux/the-linux-saga-boot-loader-initrd-sys-v/ The Bootloader and Init System on Desktop Linux]
Line 86: Line 107:
  
 
==General Linux Programming==
 
==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.<br />
 
  
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:
+
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. <br />
 +
 
 +
EMAC OE systems use the''gcc'' (the GNU Compiler Collection) compiler. 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:
 
* [http://gcc.gnu.org/onlinedocs/gcc-4.2.4/gcc/ GCC 4.2.4 Manual] [http://gcc.gnu.org/onlinedocs/gcc-4.2.4/gcc.pdf (in PDF format)] - Used with the SoM-9M10M, SoM-9G45M, SoM-9260M, and SoM-9G20M.
 
* [http://gcc.gnu.org/onlinedocs/gcc-4.2.4/gcc/ GCC 4.2.4 Manual] [http://gcc.gnu.org/onlinedocs/gcc-4.2.4/gcc.pdf (in PDF format)] - Used with the SoM-9M10M, SoM-9G45M, SoM-9260M, and SoM-9G20M.
* [http://gcc.gnu.org/onlinedocs/gcc-4.3.6/gcc/ GCC 4.3.x Manual] [http://gcc.gnu.org/onlinedocs/gcc-4.3.6/gcc.pdf (in PDF format)] - Used with the SoM-9307M, SoM-9302, PPC-E7.<br />
+
* [http://gcc.gnu.org/onlinedocs/gcc-4.3.6/gcc/ GCC 4.3.x Manual] [http://gcc.gnu.org/onlinedocs/gcc-4.3.6/gcc.pdf (in PDF format)] - Used with the SoM-3517M.<br />
 
 
  
{{Fmbox | type =  | text = '''TIP''': If you have been using one vendor's compiler for a significant amount of time, using ''gcc'' may provide some pleasant surprises.  When writing software with ''gcc'', it can prove fruitful to write test programs to check to see whether alternate forms of syntax you've seen may be used in ''gcc''.  Often times, ''gcc'' will support the most natural syntax for various programming tasks, even if other popular compilers don't do so.<br /><br />
+
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 [http://gcc.gnu.org/onlinedocs/gcc/Function-Names.html on ''gcc'''s website.] The ''gcc'' documentation provides information about the other extensions it includes, as well.<br />
 
 
There are very useful ''gcc''-specific keywords and macros available in ''gcc'', as well.  The ''_ _FUNCTION_ _'' macro has been available in ''gcc'' for many years, and has some variations. It has recently gained support in other compilers as well (case may vary), but may not be well-known yet. This macro can be very useful for debug and log messages.  More information about this can be found [http://gcc.gnu.org/onlinedocs/gcc/Function-Names.html on ''gcc'''s website.] The ''gcc'' documentation provides information about the other extensions it includes, as well.}}<br />
 
  
 
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.
 
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.
 
* [http://www.linuxprogrammingblog.com/ Small But Growing Site on Linux Programming]
 
* [http://www.linuxprogrammingblog.com/ Small But Growing Site on Linux Programming]
 
* [http://www.tldp.org/LDP/lkmpg/2.6/html/index.html Linux Kernel Module Programming]
 
* [http://www.tldp.org/LDP/lkmpg/2.6/html/index.html Linux Kernel Module Programming]
 
==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 for this.<br />
 
 
 
{{Fmbox | type =  | text = '''TIP''': Symbolic links are basically pointers, like the ones used for data structures in RAM, but point to filesystem locations instead of memory addresses.  Just as you may have as many pointers to one memory location as you like (within resource limits, since each pointer takes an amount of RAM equal to the register size), you can have as many symbolic links to a file as you like (again, within resource limits), but the size of a filesystem inode (which is filesystem-dependant) replaces the overhead of the register size, and the limit is the amount of space available for inodes in the filesystem (most filesystems reserve space for inodes), rather than available RAM.}}<br />
 
 
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.<br />
 
 
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.<br />
 
 
The following links will [[help]] you get to know this powerful tool:
 
* [http://en.wikipedia.org/wiki/BusyBox#Commands List of BusyBox Commands]
 
* [http://spblinux.de/2.0/doc/busybox.html Help With BusyBox Commands] **NOTE**: May show some commands which are not available in the EMAC OE build.
 
* [http://www.busybox.net/ BusyBox Homepage]
 
* [http://www.ibm.com/developerworks/library/l-busybox/ Building BusyBox]
 
  
 
==See Also==
 
==See Also==
  
 
* [[Getting Started with EMAC Embedded Linux Development]]
 
* [[Getting Started with EMAC Embedded Linux Development]]
 
  
 
[[Category:Linux]]
 
[[Category:Linux]]

Latest revision as of 19:18, 11 November 2015

TODO: {{#todo:Complete;(10.29.13-21:50->MD+);(11.08.13-18:55->MD+);(11.12.13-18:45->MD+);(12.30.13-16:45->MG+);(1.3.14-15:30->ER+)(03.04.14-15:05->BS-);(03.07.14-10:45->BS+)(03.10.14-15:05->BS+)(11.11.2015-18:15->MD+)|Klint Youngmeyer|oe 4,oe 5,ky, md,bs,Complete}}

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 some 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 help 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 as a reference. 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 embedded 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 application 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 current desk-top 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.




NOTE
To get additional information on many Linux commands use the following syntax:
root@som9x25:~# Command --help
for additional information on a command:
root@som9x25:~# man Command


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 provide a guide for 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) compiler. 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