Difference between revisions of "Getting Started with Linux"
m (Updated to use new templates.) |
|||
(91 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
− | {{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|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. | + | {{#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. | ||
+ | }} | ||
+ | |||
+ | 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 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 /> | |
− | + | 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 /> | |
− | + | 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 /> | |
− | + | 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. | |
− | Once | + | 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 | + | |
+ | 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 25: | Line 33: | ||
==Getting Started With the Linux Shell== | ==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.<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 42: | Line 51: | ||
* Much, much more.<br /> | * Much, much more.<br /> | ||
− | There is virtually no limit to what can be accomplished with the Linux shell. | + | 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. | + | * 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. | + | * 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, | + | |
+ | 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 56: | Line 66: | ||
==Useful Shell Tools and Methods== | ==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.<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}} }} | |
− | |||
− | + | 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 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] | ||
− | |||
− | + | ==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. | + | 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 82: | Line 107: | ||
==General Linux Programming== | ==General Linux Programming== | ||
− | |||
− | The | + | 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- | + | * [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 /> |
− | |||
− | + | 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. | ||
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] | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==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
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.
Contents
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.
- List of BusyBox Commands
- Help With BusyBox Commands NOTE: May show some commands which are not available in the EMAC OE build.
- BusyBox Homepage
- 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.
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.
- The Bootloader and Init System on Desktop Linux
- Bash For Beginners
- Bash Scripting
- Advanced Bash Scripting
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:
- GCC 4.2.4 Manual (in PDF format) - Used with the SoM-9M10M, SoM-9G45M, SoM-9260M, and SoM-9G20M.
- GCC 4.3.x Manual (in PDF format) - Used with the SoM-3517M.
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.