SlideShare a Scribd company logo
1 of 52
Download to read offline
Table of content
Chapter 1 Linux administration............................................................................................................5
Unix & Linux history...........................................................................................................................6
Why Linux............................................................................................................................................7
Different Linux distributions................................................................................................................7
Linux System Structure........................................................................................................................7
Linux System Principles.......................................................................................................................8
Exploring Ubuntu GUI.........................................................................................................................8
Filesystem Hierarchy Standard............................................................................................................8
Introduction to the command line........................................................................................................9
Getting Help.........................................................................................................................................9
Browsing and exploring filesystem......................................................................................................9
Creating files and directories..............................................................................................................10
Copying and moving files..................................................................................................................10
Removing files and directories...........................................................................................................10
Administrating users and groups........................................................................................................10
Administrating users and groups........................................................................................................11
Install Packages on Ubuntu................................................................................................................11
Text Editors GUI-based editors..........................................................................................................11
Text Editors (vi / vim)........................................................................................................................11
Text Editors........................................................................................................................................12
Text Files Utilities..............................................................................................................................12
Wildcard Characters...........................................................................................................................12
System Info Commands.....................................................................................................................13
System Info Commands.....................................................................................................................13
System Info Commands.....................................................................................................................13
Managing and securing files and permissions....................................................................................14
Managing and securing files and permissions....................................................................................14
Managing and securing files and permissions....................................................................................14
Piping & Redirection..........................................................................................................................15
Redirection.........................................................................................................................................15
Searching inside text files...................................................................................................................16
Searching for files..............................................................................................................................16
Process Management..........................................................................................................................17
System Monitor..................................................................................................................................17
Process Management..........................................................................................................................17
Archiving & Compression..................................................................................................................18
Shell Scripting....................................................................................................................................18
Creating and Running Scripts.............................................................................................................18
Variables.............................................................................................................................................19
Bash Comparison Operators...............................................................................................................19
Conditional statements.......................................................................................................................19
Conditional statements.......................................................................................................................20
Loops..................................................................................................................................................20
Example..............................................................................................................................................20
Calculator...........................................................................................................................................21
Shell Sessions.....................................................................................................................................21
Islam nabil mahmoud 20130890 1 Electrical&computers Dept Industrial training 2 ITR 102
Start-up scripts....................................................................................................................................22
Start-up scripts....................................................................................................................................22
Start-up scripts....................................................................................................................................22
chapter 2 Embedded Linux................................................................................................................23
Embedded Linux................................................................................................................................23
Why OS for Embedded ?....................................................................................................................23
Why Embedded not Normal OS ?......................................................................................................24
Why Linux ?.......................................................................................................................................24
Why companies need Embedded Linux Engineers?..........................................................................24
Devices running Embedded Linux.....................................................................................................24
Some definitions.................................................................................................................................24
Embedded Linux systems components..............................................................................................25
Booting sequence...............................................................................................................................25
How to build?.....................................................................................................................................26
Auto-Build tools.................................................................................................................................26
Building from scratch.........................................................................................................................26
Auto-Build tools.................................................................................................................................26
Buildroot.............................................................................................................................................26
Tips for Working on Linux.................................................................................................................27
Packages required for development...................................................................................................27
Selecting Hardware for Embedded Linux systems............................................................................27
Types of HW platforms......................................................................................................................28
Tips for Selecting HW........................................................................................................................28
Embedded Linux SW Components....................................................................................................28
Where to get Cross-ToolChain...........................................................................................................29
Building Cross-ToolChain..................................................................................................................29
Cross-ToolChain components............................................................................................................29
crosstool-ng........................................................................................................................................30
crosstool-ng Build..............................................................................................................................31
Using Cross-ToolChain......................................................................................................................31
Installing Cross Toolchain..................................................................................................................32
Compile a simple program.................................................................................................................32
Bootloader..........................................................................................................................................32
Bootloader on Embedded...................................................................................................................32
Kernel Compilation............................................................................................................................33
Kernel patching..................................................................................................................................33
Linux source dir..................................................................................................................................33
Linux source dir..................................................................................................................................34
Kernel Compilation............................................................................................................................34
HW Emulators....................................................................................................................................35
Qemu..................................................................................................................................................35
Filesystems.........................................................................................................................................35
Root Filesystem..................................................................................................................................35
Rootfs via network (NFS)..................................................................................................................36
Initramfs.............................................................................................................................................36
Devices...............................................................................................................................................36
Device Types......................................................................................................................................36
Device file example............................................................................................................................37
Islam nabil mahmoud 20130890 2 Electrical&computers Dept Industrial training 2 ITR 102
Building full ARM system with Busybox..........................................................................................37
Create your FS directories..................................................................................................................37
Create the configuration files.............................................................................................................38
Create the configuration files.............................................................................................................38
Create the configuration files.............................................................................................................38
Linux Kernel.......................................................................................................................................39
Linux Commands...............................................................................................................................39
Linux Commands (BusyBox).............................................................................................................39
Busybox..............................................................................................................................................39
Create the root fs image file...............................................................................................................40
Run Qemu emulator...........................................................................................................................40
Chapter 3 yocto..................................................................................................................................40
What is Yocto?....................................................................................................................................41
Why Yocto?........................................................................................................................................41
Yocto Project Organization................................................................................................................41
Yocto Project Organization................................................................................................................41
Yocto Key Concept (recipe)...............................................................................................................42
Yocto Project Workflow.....................................................................................................................42
Yocto Project Members......................................................................................................................43
Linaro.............................................................................................................................................43
Xilinx..............................................................................................................................................43
Broadcom.......................................................................................................................................43
AMD...............................................................................................................................................43
LG Electronics................................................................................................................................43
Renesas...........................................................................................................................................44
Long Term Support Initiative (LTSI).............................................................................................44
Juniper Networks............................................................................................................................44
O.S. Systems...................................................................................................................................44
Huawei............................................................................................................................................45
Mentor Graphics.............................................................................................................................45
Timesys...........................................................................................................................................45
Texas Instruments...........................................................................................................................45
OpenEmbedded eV.........................................................................................................................46
MontaVista Software......................................................................................................................46
Intel Corporation............................................................................................................................46
Freescale Semiconductor................................................................................................................46
Enea AB..........................................................................................................................................46
Wind River Systems.......................................................................................................................47
Dell.................................................................................................................................................47
Using Yocto........................................................................................................................................48
Yocto First Shot..................................................................................................................................48
Yocto Build Configuration Files........................................................................................................48
Poky directory structure.....................................................................................................................49
Yocto for RaspberryPi........................................................................................................................49
Minicom.............................................................................................................................................49
Bitbake Utility....................................................................................................................................50
Bitbake Utility....................................................................................................................................50
Yocto Layers.......................................................................................................................................50
Islam nabil mahmoud 20130890 3 Electrical&computers Dept Industrial training 2 ITR 102
Layers.................................................................................................................................................51
Creating Layers..................................................................................................................................51
Board Support Packages (BSP)..........................................................................................................51
Yocto Recipes.....................................................................................................................................51
Recipe Build Steps.............................................................................................................................52
Recipe Example..................................................................................................................................53
Yocto Image........................................................................................................................................53
Image Example...................................................................................................................................53
Yocto SDK..........................................................................................................................................54
Poky SDK...........................................................................................................................................54
Generating Poky SDK........................................................................................................................54
Using Poky SDK................................................................................................................................54
References..........................................................................................................................................55
Islam nabil mahmoud 20130890 4 Electrical&computers Dept Industrial training 2 ITR 102
Chapter 1 Linux administration
Contents of chapter 1 :-
Unix & Linux history
Why Linux
Different Linux distributions
Graphical installation of Linux
Linux System Structure
Exploring Ubuntu GUI
Root Filesystem Hierarchy Standard (FHS)
Introduction to the command line
Getting Help (man pages)
Browsing and exploring filesystem.
Creating files and directories.
Copying and moving files.
Removing files and directories.
Administrating users and groups
Install Packages on Ubuntu
Text Editors
Text Files Utilities
Wildcard Characters
System Info Commands
Managing and securing files and permissions
Piping & Redirection
Searching inside text files
Searching for files
Process management
Archiving and compression
Shell Scripting
Shell Sessions
Start-up scripts
Islam nabil mahmoud 20130890 5 Electrical&computers Dept Industrial training 2 ITR 102
Unix & Linux history
In the 60s and early 70s, programmers were used to distribute the source code with their
programs. Unix, a family of multitasking, multiuser computer operating systems, was developed in
the 1970s at the Bell Labs research center by Ken Thompson, Dennis Ritchie, and others.
But, things started to change in the late 70s/early 80s when manufacturers stopped to
provide source code.
Richard M. Stallman had been working as a hacker at the Artificial Intelligence Laboratory(AI Lab)
of the Massachusetts Institute of Technology (MIT) He had modified the software of the printer was
used in the lab The printer was changed in 1980 for a brand new model,
and Stallman wanted to changed the software again but he was refused access to the source code.
This event convinced him that people need to be free to modify the software they use.
On September 27, 1983, Stallman announced the GNU Project.
The GNU Project aims at developing a complete operating system offering the freedoms to run,
study, modify and distribute it. By the early 1990s there was almost enough available
software to create a full operating system. However, the GNU kernel, called Hurd, failed to attract
enough development effort, leaving GNU incomplete. MINIX, a Unix-like system intended for
academic use, was released by Andrew S. Tanenbaum, Operating Systems: Design and
Implementation in 1987.
n 1991, in Finland, a student, Linus Torvalds, began a project that later became the Linux
kernel. He wrote the program specifically for the hardware he was using 80386 processor.
Development was done on MINIX using the GNU C compiler. As Torvalds wrote in his book 'Just
for Fun', he eventually ended up writing an operating system kernel. On 25 August 1991 (age 21),
he announced this system in a Usenet posting to the newsgroup "comp.os.minix."
In 1992, he suggested releasing the kernel under the GNU General Public License. In the
middle of December 1992 he published version 0.99 using the GNU GPL. Linux and GNU
developers worked to integrate GNU components with Linux to make a fully
functional and free operating system. GNU/Linux 1992 (complete, open source, UNIX-
like operating system)
https://www.gnu.org/gnu/linux-and-gnu.html
Why Linux
Free, Safe, Robust. Source code of all related SW is available.
Ported to a large variety of CPU architectures (X86, ARM, PowerPC, .....).
Large device drivers coverage. Hosting huge number of languages & libraries.
Software is highly modularized, making it easy to build something new. Due to its low cost and
ease of customization, Linux has been shipped in many embedded devices (smartphones,
network devices, PDAs, IVI, GPS devices, ....).
Large Community.
Islam nabil mahmoud 20130890 6 Electrical&computers Dept Industrial training 2 ITR 102
Linux is everywhere. It's on your servers and in your phones, cars, watches, toasters, refrigerators...
and desktops. You need to switch to Linux if You love free stuff You’re obsessed with customizing
things You love creating things
You love being part of a group and working with others You love the idea of choice
http://www.linuxfoundation.org/world-without-linux
http://www.makeuseof.com/tag/linux-everywhere-10-
things-didnt-know-penguin-powered/
Different Linux distributions
Major Linux distributions families
RedHat RedHat Enterprise
Centos
Fedora
Debian
Debian
Ubuntu
SUSE SUSE Enterprise Open SUSE
Linux System Structure
BootLoader (grub, uboot, vivi)
Kernel (www.kernel.org)
Filesystem (FHS)
init process
shell (bash & ash & sh)
Services manager
Scripts & Environment variables
Linux commands
Applications (user apps, GUI, …)
Linux System Principles
Everything is a file (including hardware).
Consists of small, single-purpose programs.
Ability to chain programs together to perform
complex tasks.
Users usually avoids user interfaces.
Islam nabil mahmoud 20130890 7 Electrical&computers Dept Industrial training 2 ITR 102
Configuration data stored in text.
Exploring Ubuntu GUI
Gnome & Kde (X Window system)
Windows & Workspaces
Ubuntu Help
Common applications
gedit >> Text Editor
nautilus >> File Explorer
........
Terminal
Virtual console
Filesystem Hierarchy Standard
/ root directory
/bin commands & executable files
/sbin system commands & executable files
/boot kernel & bootloader
/dev hardware device files (nodes)
/etc configuration files and startup scripts
/home users home directories
/root root home directory
/lib shared library files
/media mount points for storage media
/opt third parity applications
/proc virtual process files
/usr other users applications & libraries
/var files that change a lot
Introduction to the command line
Sample commands
cd change directory
ls list files in current directory
pwd print current working directory
mv move & rename
Islam nabil mahmoud 20130890 8 Electrical&computers Dept Industrial training 2 ITR 102
Getting Help
man command
info command
command –help
Browsing and exploring filesystem
cd change directory
cd dir-name go to dir
cd – go previous
cd . go to current
cd .. go up
pwd print current working directory
ls list files in current directory
ls –l long list
ls –lh long list, human read
ls another-path list another folder
ls –a list all with hidden
Absolute and Relative Path names.
Creating files and directories
touch create a new file
touch file-name
touch file1 file2 file3
mkdir create a directory
mkdir dir-name
mkdir dir1 dir2 dir3
Islam nabil mahmoud 20130890 9 Electrical&computers Dept Industrial training 2 ITR 102
Copying and moving files
cp copy files and directories
cp source destination
cp –p source destination preserve
cp –a source destination with contents
mv move & rename files & directories
mv source destination
If in same dir, it’s considered rename.
If to another partition or directory, it’s considered move.
Removing files and directories
rmdir remove empty directory
rmdir empty-dir-name
rm remove files and dirs
rm file-name
rm –r dir-name
Administrating users and groups
Management of users and groups accounts is an important task for all system admins.
You can manage this process from GUI or from terminal.
Configuration files related to this task:
/etc/passwd
/etc/shadow
/etc/group
Administrating users and groups
Useful commands
id
Displays effective user id, user name, group id, group name.
whoami
Displays the current effective user
su [–] [username]
Switch between user accounts
exit
Exit from current session
sudo command
Run command with root priviliges
Islam nabil mahmoud 20130890 10 Electrical&computers Dept Industrial training 2 ITR
102
Install Packages on Ubuntu
Install packages from main repositories (automatically)
apt-get install app-name >> install new app
apt-get update >> update list of pkgs
apt-get remove app-name >> remove app
Install packages from deb files (manually)
dpkg -i pkg-name.deb
Install from source code
./configure [options] (not always)
make
make install
Text Editors GUI-based editors
gedit
Terminal-based editors
nano
Simplest text based editor.
vi / vim
More powerful but complex
Text Editors (vi / vim)
Default editor in all UNIX operating systems.
vi in Linux is usually vim (vi improved)
Supports syntax highlighting.
VI three basic modes
Command mode
Perform commands to delete, copy, ...
Edit mode
Enter text into the file
Last line mode
To access it, enter a colon (:) while in the command mode
Text Editors
Open file
vi filename
Enter edit (insert) mode (i)
Exit edit (insert) mode (Esc)
On command mode you can
Exit without saving changes (:q!)
Islam nabil mahmoud 20130890 11 Electrical&computers Dept Industrial training 2 ITR
102
Save changes and exit (:wq)
Save changes and stay (:w)
Delete a full line, go to line then press (dd)
......................
Text Files Utilities
Viewing file contents
cat file-name
more file-name or less file-name
Scrolling keys for the more command
Space bar: moves forward on screen
b: move back one screen
/string: search forward for pattern
n: find the next occurrence
q: quit and return to the shell prompt
head –n file-name
tail file-name
Wildcard Characters
Asterisk(*): represents 0 or more character
ls f*
Question mark(?) character represents any
single character
ls file?
Square bracket([ ]): represent a range of
characters for a single character position
ls [a-f]*
System Info Commands
whoami
print effective current user
hostname
show or set the system's host name
date
print or set the system date and time
uptime
Tell how long the system has been running
uname
print system information
Islam nabil mahmoud 20130890 12 Electrical&computers Dept Industrial training 2 ITR
102
System Info Commands
free
Display amount of free and used memory
df
report file system disk space usage
file file-name
file type
du file-name
estimate file space usage
du -sh file-or-folder-name
System Info Commands
lsusb
list USB devices
lspci
list all PCI devices
lscpu
display information about the CPU architecture
lsmod
list loaded modules
Managing and securing files and permissions
Each file has an owner and assigned to a group. Linux allows users to set permissions on files
and directories to protect them. Permissions are assigned to File owner Members of the group the
file assigned to All other users Permissions can only be changed by the owner and root.
Managing and securing files and permissions
Permissions on files and directories
Permission Files Access Directories Access Read You can display file contents
and copy the file You can list the directory contents Write You can modify the file
contents If you also have execute access, you can add and
delete files in the directory Execute You can execute the file if it is
an executable You can use the cd command to access the directory
Islam nabil mahmoud 20130890 13 Electrical&computers Dept Industrial training 2 ITR
102
Managing and securing files and permissions
To display the permissions on files
ls –l
- | --- | --- | ---
- | rwx | rwx | rwx
t | own | grp | other
Managing and securing files and permissions
To change permissions on file
chmod
Symbolic mode
chmod u+x file
chmod g+w file
chmod u-r file
Numeric (octal) mode
chmod 555 file
chmod 755 file
chmod 214 file
To change the ownership of file
chown new-owner file-name
Only root can change ownership of files.
To change group of file
chgrp new-group file-name
To change owner & group together
chown new-owner:new-group file-name
Piping & Redirection
Piping makes use of interprocess
communication.
Piping is to take the output of first command as
an input to the second command.
Piping two commands format:
First command | second command
Examples
cat file-name | less
cat file-name | tail
Islam nabil mahmoud 20130890 14 Electrical&computers Dept Industrial training 2 ITR
102
Redirection
It’s to redirect the output channel to a text file to use as log or any other usage.
There’s two main output channels
Standard output channel
command > file
Standard error channel
command 2> file
To redirect both channels
command &> file
The Black hole is used to redirect output to NO-WHERE
/dev/null
Searching inside text files
To make a horizontal search in a text file
grep (selection)
It prints all the lines matching a pattern
grep search-pattern file-name
To print all lines without the matching pattern
grep -v pattern file-name
It can be used with piping
cat file-name | grep pattern
Searching inside text files
To find a definite column from a text file which is organized in fields delimited with a predefined character.
cut (projection)
Remove sections from each line of file and print only the required field
cut -d”delimiter” -f”field-num” file-name
cut -d: -f1 /etc/passwd
grep & cut can be used to search in text using
selection & projection (same databases concept)
Example: Print the shell for a user
grep root /etc/passwd | cut -d: -f
wc file-name
Displays the number of characters, words, and lines in a file
Islam nabil mahmoud 20130890 15 Electrical&computers Dept Industrial training 2 ITR
102
Searching for files
To locate the location for a command and all its other files
(help,....)
whereis command
To locate only the binary file
whereis -b
command
To find files by name in the whole system
locate
file-name
Very fast tool, as it searches in a database
Command used to update the file names database
updatedb
To search for files in a directory hierarchy
Find path-to-search –name search-word
Process Management
The Linux process divides CPU time into time slices, in which each process will get a turn to run,
higher priority processes first. User can affect the priority by setting the niceness
value for a process . Niceness values range from -20 to +19. Most processes run with a niceness
value of 0 (no change). Smaller numbers are higher priority and vice versa.
Users can adjust this value down as far as +19 but can not increase it. Root can increase the priority
of a process as high as -20
System Monitor
GUI tool to monitor all running processes
top
Terminal-based tool to display all running Linux tasks
ps
Report a snapshot of the current processes in the
current session.
ps
axu
process from all running sessions
pidof prog-name
find the process ID of a running program
pstree
Display a tree of processes
Islam nabil mahmoud 20130890 16 Electrical&computers Dept Industrial training 2 ITR
102
nice -n priority command
Assign a niceness value to a new process
nice -n 19 ./largeScript.sh
renice -n priority -p pid
Assign a niceness value to a running process
renice -n 10 -p 941
Process Management
kill send a signal to a process
kill pid >> to terminate a process
kill -s signal-number pid
killall kill processes by name
killall process-nam
Archiving & Compression
The GNU version of the tar archiving utility
To make an archive without compression
tar cf archive.tar file(s)
To make a compressed archive
tar cjf archive.tar.bz2 file(s)
tar czf archive.tar.gz file(s)
To extract an archive
tar xvf myfile.tar
tar xvf myfile.tar.bz2
tar xvfz myfile.tar.gz
Islam nabil mahmoud 20130890 17 Electrical&computers Dept Industrial training 2 ITR
102
Shell Scripting
Basic Script Architecture
The first line is
#!(shell-path)
It may contains one or more of these
variables definition
read variables from user
loops
conditional statements
print output to terminal
pipe & redirection to other files
Creating and Running Scripts
Scripts are normal text files with x permission
touch scriptname
chmod 777 scriptname
chmod u+x scriptname
To run a script:
full path
./scriptname
sh scriptname
bash scriptname
Variables
Define a variable
variablename=VALUE
Print a variable to screen
echo $variablename
System variables:
Normal: has to be changed with each user
HOME PWD SHELL
Environmental: changes with login shell only with ( su - )
PATH
env
print environmental variables
read
take a value from the user to a variable
read variablename
read –p “string” variablename
Islam nabil mahmoud 20130890 18 Electrical&computers Dept Industrial training 2 ITR
102
Bash Comparison Operators
Equal (=)
Not equal (!=)
Less than (-lt)
Greater than (-gt)
Conditional statements
if statement
if [ condition ]
then
###things to do
elif [ another-cond. ]
then
###things to do
else
###things to do
fi
Conditional statements
case statement
case $variablename in
value_1)
###things to do;;
value_2)
###things to do;;
*)
###default action;;
esac
Loops
for loop
for VARIABLE in ARRAY
do
###things on each value
done
while loop
while [ condition ]
do
###things to do
done
Islam nabil mahmoud 20130890 19 Electrical&computers Dept Industrial training 2 ITR
102
Example
User Login
#!/bin/bash
user_name="islam"
password="13"
read -p "User Name: " login_name
read –p "Password: " login_pass
echo ""
if [ $login_name = $user_name ]; then
if [ $login_pass = $password ]; then
echo "Now you are logged in....."
else
echo "Error, wrong password, try again"
fi
else
echo "Error, user name doesn't exist"
fi
Calculator
#!/bin/bash
read –p "Enter First Number: " f_num
read –p "Enter Second Number: " s_num
read –p "Enter Operation(+,-,x,/): " op
case $op in
+)
echo "$f_num + $s_num = $[$f_num+$s_num]";;
-)
echo "$f_num $s_num = $[$f_num-$s_num]";;
x)
echo "$f_num x $s_num = $[$f_num*$s_num]";;
/)
echo "$f_num / $s_num = $[$f_num/$s_num]";;
esac
Islam nabil mahmoud 20130890 20 Electrical&computers Dept Industrial training 2 ITR
102
Shell Sessions
There are four shell types:
Interactive non-login shells
Like opening normal terminal
Interactive login shells
when logging from tty or when logging in from a terminal
Non-interactive non-login shells
Typical Shell Script
Non-interactive login shells
A non-interactive shell is invoked with the --login option
Start-up scripts
Start-up scripts are scripts of commands
executed at login. They are used to:
Set up the environment
Establish commonly used aliases
Run programs
Start-up scripts
~/.profile
It gets executed automatically by the login shell when one logs-in from the textual console or GUI.
~/.bash_profile or ~./bash_login
If one of these files exist, bash executes it rather then "~/.profile" when it is started as a login shell. (Bash
will prefer "~/.bash_profile" to "~/.bash_login"). However, these files won't influence a graphical session
by default.
~/.bashrc
This file will be executed in each and every invocation of bash as well as while logging in to the graphical
environment. And it’s executed after profile script.
Start-up scripts
/etc/profile
This file gets executed whenever a bash login shell is entered as well as by the DisplayManager when the
desktop session loads.
/etc/bash.bashrc
This is the system-wide version of the ~/.bashrc file. By default this file is executed whenever a user
enters a shell or the desktop environment.
Islam nabil mahmoud 20130890 21 Electrical&computers Dept Industrial training 2 ITR
102
chapter 2 Embedded Linux
LinuxUnix (Ken Thompson & Dennis Ritchie) AT&T company 1969 FSF & GNU (Gnu is Not
Unix) & GPL (Richard Stallman) 1984 Hurd Kernel Linux (LinusTorvalds) 1991 GNU/Linux 1992
(complete, open source, UNIX- like operating system)
https://www.gnu.org/gnu/linux-and-gnu.html
Embedded Linux
Embedded Linux is the use of Linux in embedded computer systems. Adapting the Linux kernel and
customizing the user-land libraries and utilities to embedded applications such as those in use in
consumer electronics, military, medical, industrial, network, and auto industries.
Creating an Embedded Linux based system is like a puzzle. Putting the right pieces together
will create the final image.
Why OS for Embedded ?
Make use of micro-processor capabilities (Multi- Tasking ...).
Easy to program.
System scalability.
Why Embedded not Normal OS ?
Systems with small and limited resources.
Special-Purpose systems.
Real-Time systems.
Why Linux ?
Inexpensive, robust, easy to program, open source.
Ported to a variety of CPU architectures.
Large device drivers coverage.
Why companies need Embedded Linux Engineers?
“When you bake it at the factory that’s what it does forever. “
Tim Bird, Sony Entertainment
Islam nabil mahmoud 20130890 22 Electrical&computers Dept Industrial training 2 ITR
102
Devices running Embedded Linux
Some definitions
Cross Compiler
A cross compiler is a compiler capable of creating executable code for a platform other than the one
on which the compiler is running.
Toolchain
Set of programming tools that are used to create a product (typically another computer program),
used in chain. A simple software development ToolChain consists of a compiler and linker to
transform the source code into an executable program, libraries to provide interfaces
to the operating system, and a debugger. Cross-ToolChain is used and runs on your workstation
but generates binaries for your target.
Embedded Linux systems components
Cross-compilation ToolChain
Compiler, debugger, libraries, headers, extra tools.
Boot Loader (grub, lilo, uboot)
Started by the hardware.
Responsible for basic initialization, loading and executing the
kernel.
Islam nabil mahmoud 20130890 23 Electrical&computers Dept Industrial training 2 ITR
102
Linux Kernel
Contains the process and memory management, network stack,
device drivers, and many other core OS responsibilities, and
provides services to userspace applications.
C Library (glibc, uclibc, ....)
The interface between the kernel and the userspace applications.
User Land
Services manager
Configuration files
Common system commands
User application(s)
Booting sequence
Bootloader
Executed by the hardware at a fixed location in ROM / Flash Initializes support for the device
where the kernel image is found (local storage, network, removable media)
Loads the kernel image in RAM and execute.
Linux Kernel
Uncompresses itself Initializes the kernel core and statically compiled drivers (required to access
the root filesystem) Mounts the root filesystem (specified by the root kernel parameter) Executes
the first userspace program (specified by the init kernel parameter)
User Land
First userspace program Configures userspace and starts up system services and any installed user
interface (graphical or terminal based).
How to build?
From scratch The original way, you need to build every single
component from scratch, from its source code. Applying your configurations, compiler options,
building each component of the system, then integrate all these parts together.
Auto-Build tools
Automated tools in the form of “build scripts”, written by the experts in this field to make it easy
for everyone to build a full embedded Linux system with the minimal knowledge of building
process.
Islam nabil mahmoud 20130890 24 Electrical&computers Dept Industrial training 2 ITR
102
Building from scratch
Components you need to build
Cross-Toolchain (ready or need to be built)
BootLoader
Linux Kernel configuration and cross compiling
Root filesystem hierarchy
System commands (BusyBox)
Startup scripts and variables
Old ... But not obsolete . (Terminator Genisys)
Auto-Build tools
Different tools are available to automate the process of building a target system, including
the kernel, and sometimes the toolchain. They automatically download, configure,
compile and install all the components in the right order. They already contain a large number of
packages, that should fit your main requirements, and are easily extensible.
Buildroot
It’s a set of Makefiles and patches that simplifies and automates the process of building a complete
Linux system for an embedded system, by using cross-compilation.
Useful mainly while working with small or embedded systems, using various CPU
architectures – including x86, ARM, MIPS, and PowerPC
Auto-Build tools
Yocto
It is a Linux Foundation workgroup It's a complete embedded Linux development
environment with tools, metadata, and documentation - everything you need
The Yocto Project has the objective of attempting to improve the lives of developers of
customized Linux systems supporting the ARM, MIPS, PowerPC and x86/x86 64 architectures.
Tips for Working on Linux
Read instructions and tips carefully.
Always read error messages carefully, in particular the first one which is issued.
Never stay stuck with a strange problem more than 5 minutes.
If you ran commands from a root shell by mistake, your regular user may no longer be able to
handle the corresponding generated files. In this case, use the
chown –R command to give the new files back to your regular user. Most regular tasks
(such as downloading, extracting sources, compiling...) can be done as a regular user.
Islam nabil mahmoud 20130890 25 Electrical&computers Dept Industrial training 2 ITR
102
Packages required for development
sudo apt-get install ncurses-dev bison texinfo 
flex autoconf automake libtool libexpat1-dev 
libncurses5-dev patch curl cvs build-essential 
subversion gawk python-dev gperf socat unzip 
gcc-arm-linux-gnueabi qemu-system chrpath xterm 
wget git-core diffstat gcc-multilib libsdl1.2-dev
Selecting Hardware for Embedded Linux systems
Processor and Arch.
The Linux kernel and most other architecture- dependent component support a wide range of
32 and 64 bits architectures, that has MMU. x86 and x86-64, as found on PC platforms, but also
embedded systems (multimedia, industrial) ARM, with hundreds of different SoC
(multimedia, industrial) PowerPC (mainly real-time, industrial applications)
And others. http://elinux.org/Processors
RAM & Storage
RAM: a very basic Linux system can work within 8 MB of RAM, but a more realistic system will
usually require at least 32 MB of RAM. Depends on the type and size of applications.
Storage: a very basic Linux system can work within 4 MB of storage, but usually more is
needed. Flash storage is supported, both NAND and NOR
flash, with specific filesystems. Block storage including SD/MMC cards and eMMC.
Communication
The Linux kernel has support for many common communication busses
USB
SPI (Serial Peripheral Interface)
CAN (Controller Area Network)
1-wire
And also extensive networking support
Ethernet, Wi, Bluetooth, CAN, etc.
IPv4, IPv6, TCP, UDP, etc.
Firewalling, advanced routing.
Islam nabil mahmoud 20130890 26 Electrical&computers Dept Industrial training 2 ITR
102
Types of HW platforms
Evaluation platforms from the SoC vendor. Usually expensive, but many peripherals are built-in.
Generally unsuitable for real products. Component on Module, a small board with only
CPU/RAM/flash and a few other core components, with connectors to access all other peripherals.
Can be used to build end products for small to medium quantities.
Custom platform. Schematics for evaluation boards or development platforms are more and more
commonly freely available, making it easier to develop custom platforms. (Open Hardware)
Tips for Selecting HW
Make sure the hardware you plan to use is already supported by the Linux kernel, and has
an open-source bootloader. Having support in the official versions of the
projects (kernel, bootloader) is a lot better: quality is better, and new versions are available.
Some SoC vendors and/or board vendors do not contribute their changes back to the mainline
Linux kernel.
Embedded Linux SW Components
Cross-compilation ToolChain
Bootloader
Linux Kernel
System libraries (C library)
Filesystem with other libraries & apps.
Where to get Cross-ToolChain
http://elinux.org/Toolchains
Codesourcery, ready-made
http://www.mentor.com/embedded-software/codesourcery
Linaro, ready made
http://www.linaro.org/
Buildroot, tool to build
http://www.buildroot.net/
Crosstool-NG, tool to build
http://crosstool-ng.org/
Islam nabil mahmoud 20130890 27 Electrical&computers Dept Industrial training 2 ITR
102
Building Cross-ToolChain
Cross-ToolChain
Three machines must be distinguished when discussing toolchain creation
The build machine, where the toolchain is built. The host machine, where the toolchain will be
executed. The target machine, where the binaries created by the toolchain are executed.
Cross-ToolChain components
binutils Kernel Headers
C/C++ libs GCC Compiler
GDB (optional)
Binutils
Binutils is a set of tools to generate and manipulate
binaries for a given CPU architecture
as, the assembler, that generates binary code from assembler source code
ld, the linker ar, ranlib, to generate .a archives, used for libraries objdump, readelf, size, nm, strings,
to inspect binaries. Very useful analysis tools! strip, to strip useless parts of binaries in order to
reduce their size
http://www.gnu.org/software/binutils/
Kernel Headers
The C library and compiled programs needs to interact with the kernel
Available system calls and their numbers Constant definitions
Data structures, etc. Therefore, compiling the C library requires
kernel headers, and many applications also require them.
GCC
GNU Compiler Collection, the famous free software compiler
Can compile C, C++, Ada, Fortran, Java, Objective-C, Objective-C++, and generate code
for a large number of CPU architectures, including ARM, AVR, Blackfin, CRIS, FRV, M32,
MIPS, MN10300, PowerPC, SH, v850, i386, x86 64, IA64, Xtensa, etc.
http://gcc.gnu.org/
C Library
The C library is Interface between the applications and the kernel Provides the well-known standard
C API to ease application development Several C libraries are available:
glibc, uClibc, eglibc, dietlibc, newlib, etc. The choice of the C library must be made at the
time of the cross-compiling toolchain generation, as the GCC compiler is compiled against a
specific c C library.
We will use uClibc: http://www.uclibc.org/
Islam nabil mahmoud 20130890 28 Electrical&computers Dept Industrial training 2 ITR
102
crosstool-ng
crosstool-NG aims at building toolchains. Toolchains are made of different pieces of
software, each being quite complex and requiring specially crafted options to build and
work seamlessly. This is usually not that easy, even in the not-so-trivial case of native
toolchains. The work reaches a higher degree of complexity when it comes to cross-compilation,
where it can become quite a nightmare...
http://crosstool-ng.org
crosstool-ng
Untar the source code, then build it
./configure --enable-local
make
You can use help
./ct-ng help
./ct-ng list-samples
We will use
./ct-ng arm-unknown-linux-uclibcgnueabi
crosstool-ng
You can configure it again
./ct-ng menuconfig
In Path and misc options:
Prefix directory
Change Maximum log level to see to DEBUG
In Toolchain options:
Set Tuple’s alias to arm-linux
crosstool-ng
In Debug facilities:
Enable gdb, strace and ltrace.
Remove the other options (dmalloc and duma).
In gdb options:
Make sure that the Cross-gdb and Build a static
gdbserver options are enabled; the other options
are not needed. Set gdb version to 7.4.1
crosstool-ng Build
Create in you home directory
src
>> save the tarballs it will download
x-tools >> the outbut
./ct-ng build
And wait
Islam nabil mahmoud 20130890 29 Electrical&computers Dept Industrial training 2 ITR
102
Using Cross-ToolChain
Now you have your own built toolchain from ARM arch. Inside x-tools directory.
Add the bin directory to your PATH environment
variable to be able to use it from anywhere
export PATH=$PATH:PATH_TO_BIN_INSIDE_TOOLCHAIN
You can add this line to bash startup script to be global every time you log in.
sudo gedit /etc/bash.bashrc
Installing Cross Toolchain
If you successfully built your own cross- toolcahin using crosstool-ng, now you’re ready
to use it and compile the Linux kernel. If not, you can use the ready-made ARM croos-
toolcahin made for Ubuntu, by installing this package
sudo apt-get install gcc-arm-linux-gnueabi
Compile a simple program
Compile any C program to check the toolchain
arm-linux-gnueabi-gcc hello.c -o hello
Or by using static compiling
arm-linux-gnueabi-gcc -static hello.c -o hellostatic
You can view the file type
file hello
Bootloader
A piece of code responsible for Basic hardware initialization
Loading of an application binary, usually a kernel, from flash storage, network, non-volatile storage.
Execution of the application. most bootloaders provide a shell with various
commands implementing deferent operations. Loading of data from storage or network, memory
inspection, hardware diagnostics and testing, etc.
Bootloader on X86
GRUB, Grand Unied Bootloader, the most BIOS
powerful one http://www.gnu.org/software/grub/
From ROM >>Stage 1 First 512 bytes >>from raw storage>> Stage 2 Raw storage
>>Kernel From filesystem
Bootloader on Embedded
1 st type When powered, the CPU starts executing code at a fixed address.
The hardware design must ensure that a NOR flash chip is wired so that it is accessible at that
address. The first stage bootloader must be programmed at this address in the NOR.
Islam nabil mahmoud 20130890 30 Electrical&computers Dept Industrial training 2 ITR
102
Unpractical, not common anymore
Bootloader on Embedded
2 st type
The CPU has an integrated boot code in ROM. Boot code is able to load a first stage bootloader
from a storage device (MMC, NAND, ....) Bootloader is provided either by the CPU vendor or
through community projects
Generic Bootloaders
There are several open-source generic bootloaders, the most popular one is U-Boot
U-Boot, the universal bootloader by Denx, The most used on ARM, also used on PPC, MIPS,
x86, m68k, NIOS, etc.
http://www.denx.de/wiki/U-Boot
U-Boot
Free software project.
License: GPLv2
The latest development source code is available
in a Git repository: http://git.denx.de/?p=u-boot.git;a=summary
Since the end of 2008, it follows a fixed-interval release schedule. Every two months, a new
version is released.
Kernel Compilation
Where to get Linux Kernel source
https://www.kernel.org/
You can download any Linux version according to your needs.
We’ll use version 3.0.35
https://www.kernel.org/pub/linux/kernel/v3.0/linu x-3.0.35.tar.bz2
Kernel patching
Changes to the kernel sources are distributed as patch files. The patch utility is used to apply a
series of edits to a set of source files. So, for example, if you have the 2.0.29 kernel source
tree and you wanted to move to the 2.0.30 source tree, you would obtain the 2.0.30 patch
file and apply the patches (edits) to that source tree:
patch -p1 < patch-2.0.30
Linux source dir
arch
The arch subdirectory contains all of the architecture specific kernel code. It has further
subdirectories, one per supported architecture, for example i386 and alpha.
Islam nabil mahmoud 20130890 31 Electrical&computers Dept Industrial training 2 ITR
102
include
The include subdirectory contains most of the include files needed to build the kernel code. It too
has further subdirectories including one for every architecture supported. The include/asm
subdirectory is a soft link to the real include directory needed for this architecture, for example
include/asm-i386. To change architectures you need to edit the kernel makefile and rerun the
Linux kernel configuration program.
init
This directory contains the initialization code for the kernel and it is a very good place to start
looking at how the kernel works.
Linux source dir
mm
This directory contains all of the memory management code. The
architecture specific memory management code lives down in
arch/*/mm/, for example arch/i386/mm/fault.c.
drivers
All of the system's device drivers live in this directory. They are further
sub-divided into classes of device driver, for example block.
ipc
This directory contains the kernels inter-process communications code.
modules
This is simply a directory used to hold built modules.
fs
All of the file system code. This is further sub-divided into directories,
one per supported file system, for example vfat and ext2.
Linux source dir
kernel
The main kernel code. Again, the architecture specific kernel code is in arch/*/kernel. net
The kernel's networking code. lib This directory contains the kernel's library code. The
architecture specific library code can be found in arch/*/lib/. scripts
This directory contains the scripts (for example awk and tk scripts) that are used
when the kernel is configured.
Islam nabil mahmoud 20130890 32 Electrical&computers Dept Industrial training 2 ITR
102
Kernel Compilation
Configure the Linux kernel using your toolcahin
make vexpress_defconfig ARCH=arm CROSS_COMPILE=YOUR-PREFIX
Edit the default configuration
make menuconfig ARCH=arm CROSS_COMPILE= YOUR-PREFIX
Build the kernel image
make all ARCH=arm CROSS_COMPILE=YOUR-PREFIX
You will find the kernel image in
arch/arm/boot/zImage
HW Emulators
Hardware emulation is the process of imitating the behavior of one or more pieces of hardware
(typically a system under design) with another piece of hardware, typically a special purpose
emulation system.
Qemu
QEMU is a generic and open source machine emulator and virtualizer.
QEMU lets you run another operating system on top of your existing OS.
When used as a machine emulator, QEMU can run OSes and programs made for one machine
(e.g. an ARM board) on a different machine (e.g. your own PC). By using dynamic translation, it
achieves very good performance.
Qemu
Install Qemu on Ubuntu
sudo apt-get install qemu-system
To run the ARM image kernel inside Qemu, we will make a small system containing one single
process. We will need the zImage Kernel & initrd image filesystem with init process to run
Compile a simple C program arm-linux-gcc -static hello.c -o init
Generate the initramfs image
echo init | cpio -o --format=newc > initramfs
Put the zImage & initramfs together and
execute the command
qemu-system-arm -M vexpress-a9  -kernel zImage -initrd initramfs  -append "console=tty1“
The Linux system should start and execute the
single process init. Or you can just start the kernel only
qemu-system-arm -M vexpress-a9  –kernel zImage  -append "console=tty1"
Filesystems
Filesystems are used to organize data in directories and files on storage devices or on
network. Filesystems are mounted in a specific location (mount point).
Single global hierarchy of files. This allows applications to access files and directories easily.
Islam nabil mahmoud 20130890 33 Electrical&computers Dept Industrial training 2 ITR
102
Root Filesystem
the first mounted filesystem under /
It is mounted directly by the kernel, according to the root= kernel option.
When no root fs found, the kernel panics.
It can be mounted from
Partition on Hard Disk
Partition on Flash Memory
Partition on SD Card
Partition on NAND Flash
From the network, using NFS protocol
Rootfs via network (NFS)
Once networking works, your root filesystem
could be a directory on your GNU/Linux
development host, exported by NFS (Network
File System).
Easy to update files on the root filesystem
Ability to have huge filesystem size
Host NFS server >>Ethernet >>Target NFS client Built into kernel
Initramfs
A compressed (cpio) archive of the filesystem. Initramfs is used to be loaded into memory
together with the kernel.
Used for Fast booting of very small root filesystems. As the filesystem is completely loaded at boot
time, application startup is very fast. As an intermediate step before switching to a real root
filesystem. This is always used on the kernel of desktop/server distributions to keep the kernel
image size reasonable. It is also possible to have initramfs integrated into the kernel image
Devices
One of the kernel important role is to allow applications to access hardware devices
In the Linux kernel, most devices are presented to userspace applications through two different
abstractions
Character device
Block device
Islam nabil mahmoud 20130890 34 Electrical&computers Dept Industrial training 2 ITR
102
Device Types
Block devices A device composed of fixed-sized blocks, that can be read and written to store data.
Used for hard disks, USB keys, SD cards, etc.
Character devices Originally, an infinite stream of bytes, with no
beginning, no end, no size. Used for serial ports, terminals, sound cards, video
acquisition devices.
Device files
“Everything is a file” allows applications to manipulate all “system objects” with the normal
file API (open, read, write, close)
All device files are by convention stored in the /dev directory.
Special type of files.
Device file example
Serial device
c rw- rw- --- 1 root root 4, 64 2014-01-25 08:56 /dev/ttyS0
Example C code that uses the usual file API to
write data to serial port
int fd;
fd = open(“/dev/ttyS0”, O_RDWR);
write(fd, “Hello”, 5);
close(fd);
Building full ARM system with Busybox
Create your working directory
Open a new Terminal, you will be right now inside
your home directory. Assume that the user name
currently running is (islam), you will be in:
/home/<username>
Create any directory to contain the whole OS files and enter it
mkdir minios
cd minios
mkdir tools system
cd system
Now you are in:
/home/<username>/minios/system
Islam nabil mahmoud 20130890 35 Electrical&computers Dept Industrial training 2 ITR
102
Create your FS directories
Execute this commands:
mkdir -p bin boot dev etc lib proc root 
sbin media sys tmp var usr etc/init.d 
usr/bin usr/sbin usr/lib
Now you have the main filesystem directories to
contain the whole system.
Create the configuration files
Inside the ARM_SYSTEM_DIR
gedit etc/init.d/rcS
#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
export PATH
/bin/mount -t proc proc /proc
/bin/mount -t sysfs sysfs /sys
/sbin/mdev -s
/bin/hostname EmbeddedLinuxMiniOS
/bin/echo “ “
/bin/echo “ Y A T T A “
/bin/echo “ My First Embedded Linux “
/bin/echo “ “
Change the rcS file permissions
chmod +x etc/init.d/rcS
Create the configuration files
gedit etc/group
copy and paste this line inside it:
root:x:0:
gedit etc/passwd
copy and paste this line inside it:
root:x:0:0:root:/root:/bin/sh
gedit etc/shadow
copy and paste this line inside it:
root::10:0:0:0:::
Islam nabil mahmoud 20130890 36 Electrical&computers Dept Industrial training 2 ITR
102
Create the configuration files
Inside (etc), create these files & fill them with
these contents:
gedit etc/profile
export PS1='EmbeddedLinuxMiniOS #'
export USER=`id -un`
export HISTSIZE=1000
echo "ya welcome ya welcome ^__^"
echo " "
After Finishing back to the main dir:
/home/<username>/minios/
Linux Kernel
The same zImage kernel already built.
Just copy the zImage binary file to your working
directory under /home/<username>/minios/tools
Linux Commands
Any Linux distribution need some basic commands to operate correctly, like (mount, ls,
pwd, ifconfig, cd, mkdir, touch, file, rm, vi) and more. We need these commands, so there are
two ways to get them: Getting the source code for each command needed, compile it separately and
copy it to any bin directory inside the distribution.
Using BusyBox.
Linux Commands (BusyBox)
BusyBox combines tiny versions of many common UNIX utilities into a single small executable. It
provides replacements for most of the utilities you usually find in GNU fileutils, shellutils, etc. The
utilities in BusyBox generally have fewer options than their full-featured GNU cousins; however,
the options that are included provide the expected functionality and behave very much like their
GNU counterparts. BusyBox provides a fairly complete environment for any small or embedded
system.
Get Busybox:
https://busybox.net/downloads/busybox-1.24.0.tar.bz2
Busybox
Put the tar file in your
/home/<username>/minios/tools dir and open a
new Terminal and go to this dir:
tar xvf busybox-1.24.0.tar.bz2
cd busybox-1.24.0/
Inside Busybox source dir, configure & cross-
Islam nabil mahmoud 20130890 37 Electrical&computers Dept Industrial training 2 ITR
102
compile for ARM
make ARCH=arm CROSS_COMPILE=YOUR-PREFIX defconfig
Command to start building
make CONFIG_PREFIX=/home/<username>/minios/system 
ARCH=arm CROSS_COMPILE=YOUR-PREFIX install
Shared Libraries
We will need the shared libraries as we
compiled busybox as a dynamic binary file.
We can get these libraries from the cross-
toolchain we’re using.
If you’re using Ubuntu toolchain, run this
command to copy required libs to your system
dir:
cp -a /usr/arm-linux-gnueabi/lib/* 
/home/<username>/minios/system/lib/
Create the root fs image file
Inside the ARM_SYSTEM_DIR
“/home/<username>/minios/system”
find . | cpio -o --format=newc > ../tools/rootfs.img
Now you have the kernel image & the root fs image
Run Qemu emulator
Go to the tools directory
“/home/<username>/minios/tools”
qemu-system-arm -M vexpress-a9 
-kernel zImage -initrd rootfs.img 
–append "root=/dev/ram rdinit=/sbin/init"
Now you got a console running, and can try any
command or app installed.
Islam nabil mahmoud 20130890 38 Electrical&computers Dept Industrial training 2 ITR
102
Chapter 3 yocto
Contents
What is Yocto?
Why Yocto?
Organization of Yocto project
Building full image with Yocto (Qemu)
Building full image for Raspberry Pi
Bitbake
Creating new layers
Writing new recipes
Customizing images
Building SDKs
What is Yocto?
It's not an embedded Linux distribution - It creates a custom one for you.
It is a Linux Foundation workgroup
www.yoctoproject.org
It's a complete embedded Linux development environment with tools, metadata, and
documentation - everything you need to create custom Linux-based systems for embedded
products regardless of hardware architecture.
Why Yocto?
Develop using one common Linux OS for different architectures.
Re-use your software stack with future devices. Changing hardware platforms with updating just
one line in a config file and rebuild.
Base your work on a validated collection of software and libraries.
Developers spend lots of time porting or making build systems, leaves less time and resources to
develop value- adding software features.
Yocto Project Organization
Yocto Project uses a build system based on the OpenEmbedded (OE) project, which uses the
BitBake tool, to construct complete Linux images. The BitBake and OE components are combined
together to form Poky, a reference build system. OpenEmbedded Core (OE) – The overall build
architecture used by the Yocto Project.
BitBake – Task executor and scheduler.
meta-yocto – Reference policy/distro configuration
and reference hardware support layer.
Islam nabil mahmoud 20130890 39 Electrical&computers Dept Industrial training 2 ITR
102
Yocto Project Organization
Configuration (*.conf) – global definitions of variables.
Classes (*.bbclass) – encapsulation and
inheritance of build logic, packaging, etc.
Recipes (*.bb) – the logical units of
software/images to build.
Poky – A pre-prepared combination of the build
system components needed; also the name of
our reference distro in meta-yocto
Poky = Bitbake + OE-core + meta-yocto + docs
Yocto Key Concept (recipe)
The Yocto Project provides tools and metadata for creating custom Linux images.
These images are created from a repository of 'baked' recipes.
A recipe is a set of instructions for building packages:
Where to obtain the upstream sources and which patches to apply
Dependencies (on libraries or other recipes)
Configuration/compilation options
Define which files go into what output packages
Islam nabil mahmoud 20130890 40 Electrical&computers Dept Industrial training 2 ITR
102
Yocto Project Workflow
Yocto Project Members
Linaro
Linaro’s mission is to bring together industry and the open
source community to work on key projects, deliver great
tools, reduce industry wide fragmentation and redundant
effort, and provide commo
Yes
Xilinx
Xilinx is the world’s leading provider of All
Programmable FPGAs, SoCs, MPSoCs and 3D ICs,
enabling the next generation of smarter, connected, and
differentiated systems and networks.
Yes
Islam nabil mahmoud 20130890 41 Electrical&computers Dept Industrial training 2 ITR
102
Broadcom
Broadcom Corporation (NASDAQ: BRCM), a FORTUNE
500® company, is a global leader and innovator in
semiconductor solutions for wired and wireless
communications.
Yes
AMD
AMD (NYSE: AMD) designs and integrates technology
that powers millions of intelligent devices, including
personal computers, tablets, game consoles and cloud
servers that define the new era of surr
Yes
LG Electronics
LG Electronics Inc.
Yes
Renesas
As a specialist semiconductor manufacturer, operations
are centered on three product categories developed
worldwide—Microcontroller Units (MCUs), Analog and
Power Devices, and System on Chips (SoC)
Yes
Long Term Support Initiative
(LTSI)
LTSI is an industry-wide project created and supported by
Hitachi, LG Electronics, NEC, Panasonic, Qualcomm
Atheros, Renesas Electronics Corporation, Samsung
Electronics, Sony and Toshiba and hoste
Yes
Islam nabil mahmoud 20130890 42 Electrical&computers Dept Industrial training 2 ITR
102
Juniper Networks
Juniper Networks is in the business of network innovation.
Yes
O.S. Systems
O.S. Systems specialized in multi-platform BSPs and
Embedded Operating System development and
customization for Linux and Windows platforms, offers
consulting development services.
Yes
Huawei
Huawei is a leading global information and
communications technology (ICT) solutions provider.
Yes
Mentor Graphics
Mentor Embedded Linux combines the freedom of open
source software, the flexibility of extreme customizability
and the security of full commercial support in a powerful,
easy-to-use package.
Yes
Timesys
TimeSys provides easy-to-use, customizable embedded
Linux solutions, full commercial support, professional
services and training to embedded developers targeting
Yes
Islam nabil mahmoud 20130890 43 Electrical&computers Dept Industrial training 2 ITR
102
Linux as their go-to-market
Texas Instruments
Texas Instruments is a global semiconductor design &
manufacturing company. Innovate with 80000+ analog
ICs & embedded processors, software & largest
sales/support staff.
Yes
OpenEmbedded eV
The OpenEmbedded Project provides a software
framework to create Linux distributions aimed for, but not
restricted to, embedded devices.
Yes
MontaVista Software
MontaVista Software is a company that develops
embedded Linux system software, development tools, and
related software.
Yes
Intel Corporation
Intel® Corporation is an American multinational
semiconductor chip maker corporation headquartered in
Santa Clara, California.
Yes
Islam nabil mahmoud 20130890 44 Electrical&computers Dept Industrial training 2 ITR
102
Freescale Semiconductor
Freescale Semiconductor (NYSE:FSL) is a global leader
in embedded processing solutions, providing industry
leading products that are advancing the automotive,
consumer, industrial and networ
Yes
Enea AB
ENEA is a global information technology company with
its headquarters in Kista, Sweden. ENEA provides real-
time operating systems and consulting services.
Yes
Wind River Systems
Wind River Systems, Inc. is a company providing
embedded systems, development tools for embedded
systems, middleware, and other types of software.
Yes
Dell
For more than 28 years, Dell has empowered countries,
communities, customers and people everywhere to use
technology to realize their dreams.
Islam nabil mahmoud 20130890 45 Electrical&computers Dept Industrial training 2 ITR
102
Using Yocto
Required Packages
Ubutnu dev packages for Yocto development
sudo apt-get install gawk wget 
git-core diffstat unzip texinfo 
gcc-multilib build-essential chrpath 
socat libsdl1.2-dev xterm minicom
Yocto First Shot
Download Yocto source
https://www.yoctoproject.org/downloads
Current final release: YP Core - Jethro 2.0
Untar the downloaded file
$ tar xvf poky-jethro-14.0.0.tar.bz2
Source the poky default environment script
$ source poky-jethro-14.0.0/oe-init-build-env
build
Configure (if you want) your conf file:
$ vim conf/local.conf
Start the build process (and wait ....)
$ bitbake core-image-minimal
Run Qemu emulator with output image
$ runqemu qemuarm
Yocto Build Configuration Files
conf/bblayers.conf
Contains locations for all layers needed for your build
process.
BBLAYERS ?= " 
/home/user/yocto/poky/metayocto 
conf/local.conf
Set your build options, choose target machine, add or
remove features from your build image. Configuration variables can be overridden here.
BB_NUMBER_THREADS = "threads"
How many tasks BitBake should perform in parallel.
PARALLEL_MAKE = "j threads"
How many processes should be used when compiling.
MACHINE ?= "raspberrypi"
The machine the target is built for.
DL_DIR ?= <downloaddirpath>
Sources download directory
Islam nabil mahmoud 20130890 46 Electrical&computers Dept Industrial training 2 ITR
102
Poky directory structure
bitbake: the BitBake utility itself.
documentation: documentation sources.
scripts: various support scripts (e.g, runqemu)
meta/conf: important configuration files,
bitbake.conf, reference distro config, machine
configs for QEMU architectures.
meta/classes: BitBake classes.
meta/recipes-* : recipes for all packages & libs
Yocto for RaspberryPi
Yocto for Raspberry Pi
Inside your poky sources folder, download these extra two layers
git clone http://git.yoctoproject.org/git/meta-raspberrypi
git clone https://github.com/dv1/meta-gstreamer1.0.git
Add these new layers paths to your bblayers.conf file
Edit local.conf to change MACHINE
MACHINE ?= "raspberrypi"
Build the minimal image for RaspberryPi
bitbake rpi-hwup-image
bitbake rpi-hwup-image -c populate_sdk
Write the image to SD Card
dd if=tmp/deploy/images/raspberrypi/rpi-hwup-image-raspberrypi.rpi-sdimg of=/dev/sdb
Minicom
A program used to communicate with almost every embedded kit via serial, to see booting
process or give commands to the U-Boot or Linux Shell.
Using Minicom Connect the USB-to-Serial cable between your board and PC
$ sudo minicom -s enters setup mode, first time only
Select Serial port setup and set the serial device, baudrate, save your configuration and exit setup
mode.
Islam nabil mahmoud 20130890 47 Electrical&computers Dept Industrial training 2 ITR
102
Bitbake Utility
BitBake can be used to run a full build for a given
target with
bitbake [target]
But it can be more precise, with optional options:
-c <task>
execute the given task
-s
list all locally available packages and their versions
-f
force the given task to be run
world
keyword for all packages
-b <recipe> execute recipe (without resolving dependencies).
Bitbake Utility
bitbake -c listtasks <recipe>
Gives a list of the available tasks for that recipe.
Tasks are prefixed with do_.
bitbake -c menuconfig virtual/kernel
Execute the task menuconfig on the default
selected kernel package.
bitbake -c fetchall <image-name>
Download all package sources and their
dependencies for that image.
For a full description: bitbake –help
Yocto Layers
Layers
The Yocto Project build system is composed of layers.
A layer is a logical collection of recipes representing the core, a Board Support Package
(BSP), or an application stack.
A layer is a collection of packages and build tasks, in the form of set of files and directories
and can be created by hand.
Yocto Layers Stack
Developers-Specific Layer
Commercial Layer
UI - Optional Layer
Hardware Specific BSP
Yocto Layer Metadata (meta-yocto)
OpenEmbedded Core Metadata (oe-core)
Islam nabil mahmoud 20130890 48 Electrical&computers Dept Industrial training 2 ITR
102
Layers
A list of existing and maintained layers can be found at
http://layers.openembedded.org/layerindex/branch/master/layers/
To integrate any layer with yours, just download it, put it on any location on your disk, a good
practice is to save it where all others layers are stored. The only requirement is to let BitBake
know about the new layer by editing
[Build-Dir]/conf/bblayers.conf
Creating Layers
When making modifications to the existing recipes or when adding new packages, it is a
good practice not to modify Poky. Instead you can create your own layers.
yocto-layer command
By default yocto-layer creates the new layer in the
current directory.
$ yocto-layer create <layer-name>
This will create the required layer base structure,
and by default, all metadata matching ./recipes-
*/*/*.bb will be parsed by the BitBake build engine
Board Support Packages (BSP)
BSPs are layers to enable support for specific
hardware platforms.
Defines machine configuration for the “board”.
Adds machine-specific recipes and
customizations.
Kernel config
Graphics drivers
Additional recipes to support hardware features
Yocto Recipes
Recipe (.bb)
A recipe is a set of instructions to describe how to retrieve, patch, compile, install and generate
binary packages for a given application. It also defines what build or runtime
dependencies are required. It also contains functions that can be run (fetch,
configure, compile...) which are called tasks.
Recipe (.bb)
Recipe skeleton
SUMMARY = “ ”
DISCRIPTION = “ ”
HOMEPAGE = “ ”
LICENSE = “ ”
SRC_URI = “ ”
SRC_URI[md5sum] = “ ”
Islam nabil mahmoud 20130890 49 Electrical&computers Dept Industrial training 2 ITR
102
inherit stuff
do_compile() { ......... }
do_install() { ......... }
SRC_URI defines where and how to retrieve the needed
elements. It is a set of URI schemes pointing to the resource
locations (local or remote).
Recipe Build Steps
Building recipes involves executing the following
functions, which can be overridden when
needed for customizations.
do_fetch
do_unpack
do_patch
do_configure
do_compile
do_install
do_package
do_rootfs
Recipe Example
DESCRIPTION = “Hello world program”
HOMEPAGE = “http://blabla.org”
PRIORITY = “optional”
SECTION = “examples”
LICENSE = “GPLv2”
SRC_URI = “file://hello.c”
do_compile() {
${CC} ${CFLAGS} ${LDFLAGS} -o hello ${WORKDIR}/hello.c
}
do_install() {
install -d ${D}${bindir}
install -m 0755 hello ${D}${bindir}
}
Yocto Image
An image is the top level recipe and is used alongside the machine definition.
An image is no more than a recipe, it inherits the core-image class.
An image is architecture agnostic and defines
how the root filesystem is built, with what packages.
By default, several images are provided in Poky:
meta*/recipes*/images/*.bb
Islam nabil mahmoud 20130890 50 Electrical&computers Dept Industrial training 2 ITR
102
Image Example
# Base this image on core-image-minimal
include recipes-core/images/core-image-minimal.bb
# Include more packages in rootfs
IMAGE_INSTALL += " 
Pkg-name 
“
Yocto SDK
SDK
An SDK (Software Development Kit) is a set of tools allowing the development of applications
for a given target (operating system, platform, environment...).
It generally provides a set of tools including:
Compilers or cross-compilers.
Linkers.
Library headers.
Debuggers.
Custom utilities.
Poky SDK
The Poky SDK is an application development SDK, which can be generated to provide a full
environment compatible with the target. It includes a toolchain, libraries headers and all
the needed tools. This SDK can be installed on any computer and
is self-contained. The presence of Poky is not required for the SDK to fully work.
Generating Poky SDK
Generic SDK
bitbake meta-toolchain
Image-based SDK
bitbake -c populate_sdk image-name
Output will be in build/tmp/deploy/sdk,
in the form of shell script. Executing this script
on any machine, will install the SDK.
Using Poky SDK
To install an SDK, retrieve the generated script
and execute it.
The SDK will be by default under
/opt/poky/<version>/
To use the SDK, a script is available to set up the
environment:
source /opt/poky/<version>/environment-setup-i586-poky-linux
To compile an application:
$CC -o example example.c
Islam nabil mahmoud 20130890 51 Electrical&computers Dept Industrial training 2 ITR
102
References
Free-Electrons training materials
http://free-electrons.com/training/
Yocto Project documentation
https://www.yoctoproject.org/documentation
Yocto Project quick start guide
yocto-project-qs
Bitbake user manual
bitbake-user-manual
Yocto Project development manual
dev-manual
Islam nabil mahmoud 20130890 52 Electrical&computers Dept Industrial training 2 ITR
102

More Related Content

What's hot

GIGA MASTER-FINAL
GIGA MASTER-FINALGIGA MASTER-FINAL
GIGA MASTER-FINAL
Max Genske
 
Hp networking-and-cisco-cli-reference-guide june-10_ww_eng_ltr
Hp networking-and-cisco-cli-reference-guide june-10_ww_eng_ltrHp networking-and-cisco-cli-reference-guide june-10_ww_eng_ltr
Hp networking-and-cisco-cli-reference-guide june-10_ww_eng_ltr
Felippe Costa
 
Verio Web Hosting Virtual Server Handbook
Verio Web Hosting Virtual Server HandbookVerio Web Hosting Virtual Server Handbook
Verio Web Hosting Virtual Server Handbook
webhostingguy
 
Verio Web Hosting Virtual Server Handbook
Verio Web Hosting Virtual Server HandbookVerio Web Hosting Virtual Server Handbook
Verio Web Hosting Virtual Server Handbook
webhostingguy
 
Building embedded linux systems
Building embedded linux systemsBuilding embedded linux systems
Building embedded linux systems
trx2001
 
The MySQL Cluster API Developer Guide
The MySQL Cluster API Developer GuideThe MySQL Cluster API Developer Guide
The MySQL Cluster API Developer Guide
webhostingguy
 
Parallels Plesk Panel 9 Client's Guide
Parallels Plesk Panel 9 Client's GuideParallels Plesk Panel 9 Client's Guide
Parallels Plesk Panel 9 Client's Guide
webhostingguy
 

What's hot (18)

Sg247137
Sg247137Sg247137
Sg247137
 
Kotlin notes for professionals
Kotlin notes for professionalsKotlin notes for professionals
Kotlin notes for professionals
 
MySQL Query Browser
MySQL Query BrowserMySQL Query Browser
MySQL Query Browser
 
GIGA MASTER-FINAL
GIGA MASTER-FINALGIGA MASTER-FINAL
GIGA MASTER-FINAL
 
Hp networking-and-cisco-cli-reference-guide june-10_ww_eng_ltr
Hp networking-and-cisco-cli-reference-guide june-10_ww_eng_ltrHp networking-and-cisco-cli-reference-guide june-10_ww_eng_ltr
Hp networking-and-cisco-cli-reference-guide june-10_ww_eng_ltr
 
Verio Web Hosting Virtual Server Handbook
Verio Web Hosting Virtual Server HandbookVerio Web Hosting Virtual Server Handbook
Verio Web Hosting Virtual Server Handbook
 
Verio Web Hosting Virtual Server Handbook
Verio Web Hosting Virtual Server HandbookVerio Web Hosting Virtual Server Handbook
Verio Web Hosting Virtual Server Handbook
 
A Gentle Introduction to ROS Jason M. O’Kane ~hmftj
A Gentle Introduction to ROS Jason M. O’Kane  ~hmftjA Gentle Introduction to ROS Jason M. O’Kane  ~hmftj
A Gentle Introduction to ROS Jason M. O’Kane ~hmftj
 
Connect now
Connect nowConnect now
Connect now
 
Building embedded linux systems
Building embedded linux systemsBuilding embedded linux systems
Building embedded linux systems
 
Linux training
Linux trainingLinux training
Linux training
 
The MySQL Cluster API Developer Guide
The MySQL Cluster API Developer GuideThe MySQL Cluster API Developer Guide
The MySQL Cluster API Developer Guide
 
cs-2002-01
cs-2002-01cs-2002-01
cs-2002-01
 
Parallels Plesk Panel 9 Client's Guide
Parallels Plesk Panel 9 Client's GuideParallels Plesk Panel 9 Client's Guide
Parallels Plesk Panel 9 Client's Guide
 
Cesvip 2010 first_linux_module
Cesvip 2010 first_linux_moduleCesvip 2010 first_linux_module
Cesvip 2010 first_linux_module
 
sg247413
sg247413sg247413
sg247413
 
Google guidelines
Google guidelinesGoogle guidelines
Google guidelines
 
R Exts
R ExtsR Exts
R Exts
 

Similar to emb

Linux_kernelmodule
Linux_kernelmodule Linux_kernelmodule
Linux_kernelmodule
sudhir1223
 
The_Linux_Users_Guide.pdf
The_Linux_Users_Guide.pdfThe_Linux_Users_Guide.pdf
The_Linux_Users_Guide.pdf
Mertin2
 
New linux course_modules
New linux course_modulesNew linux course_modules
New linux course_modules
gopallinux
 
New linux course_modules
New linux course_modulesNew linux course_modules
New linux course_modules
sanmugamk
 
Get more out of your san with ibm tivoli storage manager sg246687
Get more out of your san with ibm tivoli storage manager sg246687Get more out of your san with ibm tivoli storage manager sg246687
Get more out of your san with ibm tivoli storage manager sg246687
Banking at Ho Chi Minh city
 
Beginning linux-programming
Beginning linux-programmingBeginning linux-programming
Beginning linux-programming
Kunal Dawn
 
Kali Linux Revealed - Mastering the Penetration Testing (Raphaël Hertzog, Jim...
Kali Linux Revealed - Mastering the Penetration Testing (Raphaël Hertzog, Jim...Kali Linux Revealed - Mastering the Penetration Testing (Raphaël Hertzog, Jim...
Kali Linux Revealed - Mastering the Penetration Testing (Raphaël Hertzog, Jim...
SomiMukerjee
 
Experiences with oracle 10g database for linux on z series sg246482
Experiences with oracle 10g database for linux on z series sg246482Experiences with oracle 10g database for linux on z series sg246482
Experiences with oracle 10g database for linux on z series sg246482
Banking at Ho Chi Minh city
 
Expert oracle database architecture
Expert oracle database architectureExpert oracle database architecture
Expert oracle database architecture
airy6548
 
Tape automation with ibm e server xseries servers redp0415
Tape automation with ibm e server xseries servers redp0415Tape automation with ibm e server xseries servers redp0415
Tape automation with ibm e server xseries servers redp0415
Banking at Ho Chi Minh city
 
Ref arch for ve sg248155
Ref arch for ve sg248155Ref arch for ve sg248155
Ref arch for ve sg248155
Accenture
 

Similar to emb (20)

fundamentals of linux
fundamentals of linuxfundamentals of linux
fundamentals of linux
 
fundamentals of linux
fundamentals of linuxfundamentals of linux
fundamentals of linux
 
Linux-Perf.pdf
Linux-Perf.pdfLinux-Perf.pdf
Linux-Perf.pdf
 
Linux_kernelmodule
Linux_kernelmodule Linux_kernelmodule
Linux_kernelmodule
 
0501 linux-server-configuration
0501 linux-server-configuration0501 linux-server-configuration
0501 linux-server-configuration
 
The_Linux_Users_Guide.pdf
The_Linux_Users_Guide.pdfThe_Linux_Users_Guide.pdf
The_Linux_Users_Guide.pdf
 
Complete ad troubleshooting
Complete ad troubleshootingComplete ad troubleshooting
Complete ad troubleshooting
 
New linux course_modules
New linux course_modulesNew linux course_modules
New linux course_modules
 
New linux course_modules
New linux course_modulesNew linux course_modules
New linux course_modules
 
Get more out of your san with ibm tivoli storage manager sg246687
Get more out of your san with ibm tivoli storage manager sg246687Get more out of your san with ibm tivoli storage manager sg246687
Get more out of your san with ibm tivoli storage manager sg246687
 
IBM enterprise Content Management
IBM enterprise Content ManagementIBM enterprise Content Management
IBM enterprise Content Management
 
LaCie Network Space 2
LaCie Network Space 2LaCie Network Space 2
LaCie Network Space 2
 
Beginning linux-programming
Beginning linux-programmingBeginning linux-programming
Beginning linux-programming
 
Kali Linux Revealed - Mastering the Penetration Testing (Raphaël Hertzog, Jim...
Kali Linux Revealed - Mastering the Penetration Testing (Raphaël Hertzog, Jim...Kali Linux Revealed - Mastering the Penetration Testing (Raphaël Hertzog, Jim...
Kali Linux Revealed - Mastering the Penetration Testing (Raphaël Hertzog, Jim...
 
Experiences with oracle 10g database for linux on z series sg246482
Experiences with oracle 10g database for linux on z series sg246482Experiences with oracle 10g database for linux on z series sg246482
Experiences with oracle 10g database for linux on z series sg246482
 
Expert oracle database architecture
Expert oracle database architectureExpert oracle database architecture
Expert oracle database architecture
 
redp5222.pdf
redp5222.pdfredp5222.pdf
redp5222.pdf
 
sg246506
sg246506sg246506
sg246506
 
Tape automation with ibm e server xseries servers redp0415
Tape automation with ibm e server xseries servers redp0415Tape automation with ibm e server xseries servers redp0415
Tape automation with ibm e server xseries servers redp0415
 
Ref arch for ve sg248155
Ref arch for ve sg248155Ref arch for ve sg248155
Ref arch for ve sg248155
 

More from Islam Nabil (11)

Resume islam-nabil
Resume islam-nabilResume islam-nabil
Resume islam-nabil
 
Islam CV
Islam CV Islam CV
Islam CV
 
Resume 2018
Resume 2018Resume 2018
Resume 2018
 
Resume 2018
Resume 2018Resume 2018
Resume 2018
 
Ros rov talk
Ros rov talk Ros rov talk
Ros rov talk
 
ROS ROV AUV
ROS ROV AUVROS ROV AUV
ROS ROV AUV
 
Islam Bio
Islam Bio Islam Bio
Islam Bio
 
Intro to linux
Intro to linux Intro to linux
Intro to linux
 
Final
Final Final
Final
 
Resume
ResumeResume
Resume
 
Final report NTI FPGA&RTOS&Cadeance ICFB&
Final report NTI FPGA&RTOS&Cadeance ICFB&Final report NTI FPGA&RTOS&Cadeance ICFB&
Final report NTI FPGA&RTOS&Cadeance ICFB&
 

emb

  • 1. Table of content Chapter 1 Linux administration............................................................................................................5 Unix & Linux history...........................................................................................................................6 Why Linux............................................................................................................................................7 Different Linux distributions................................................................................................................7 Linux System Structure........................................................................................................................7 Linux System Principles.......................................................................................................................8 Exploring Ubuntu GUI.........................................................................................................................8 Filesystem Hierarchy Standard............................................................................................................8 Introduction to the command line........................................................................................................9 Getting Help.........................................................................................................................................9 Browsing and exploring filesystem......................................................................................................9 Creating files and directories..............................................................................................................10 Copying and moving files..................................................................................................................10 Removing files and directories...........................................................................................................10 Administrating users and groups........................................................................................................10 Administrating users and groups........................................................................................................11 Install Packages on Ubuntu................................................................................................................11 Text Editors GUI-based editors..........................................................................................................11 Text Editors (vi / vim)........................................................................................................................11 Text Editors........................................................................................................................................12 Text Files Utilities..............................................................................................................................12 Wildcard Characters...........................................................................................................................12 System Info Commands.....................................................................................................................13 System Info Commands.....................................................................................................................13 System Info Commands.....................................................................................................................13 Managing and securing files and permissions....................................................................................14 Managing and securing files and permissions....................................................................................14 Managing and securing files and permissions....................................................................................14 Piping & Redirection..........................................................................................................................15 Redirection.........................................................................................................................................15 Searching inside text files...................................................................................................................16 Searching for files..............................................................................................................................16 Process Management..........................................................................................................................17 System Monitor..................................................................................................................................17 Process Management..........................................................................................................................17 Archiving & Compression..................................................................................................................18 Shell Scripting....................................................................................................................................18 Creating and Running Scripts.............................................................................................................18 Variables.............................................................................................................................................19 Bash Comparison Operators...............................................................................................................19 Conditional statements.......................................................................................................................19 Conditional statements.......................................................................................................................20 Loops..................................................................................................................................................20 Example..............................................................................................................................................20 Calculator...........................................................................................................................................21 Shell Sessions.....................................................................................................................................21 Islam nabil mahmoud 20130890 1 Electrical&computers Dept Industrial training 2 ITR 102
  • 2. Start-up scripts....................................................................................................................................22 Start-up scripts....................................................................................................................................22 Start-up scripts....................................................................................................................................22 chapter 2 Embedded Linux................................................................................................................23 Embedded Linux................................................................................................................................23 Why OS for Embedded ?....................................................................................................................23 Why Embedded not Normal OS ?......................................................................................................24 Why Linux ?.......................................................................................................................................24 Why companies need Embedded Linux Engineers?..........................................................................24 Devices running Embedded Linux.....................................................................................................24 Some definitions.................................................................................................................................24 Embedded Linux systems components..............................................................................................25 Booting sequence...............................................................................................................................25 How to build?.....................................................................................................................................26 Auto-Build tools.................................................................................................................................26 Building from scratch.........................................................................................................................26 Auto-Build tools.................................................................................................................................26 Buildroot.............................................................................................................................................26 Tips for Working on Linux.................................................................................................................27 Packages required for development...................................................................................................27 Selecting Hardware for Embedded Linux systems............................................................................27 Types of HW platforms......................................................................................................................28 Tips for Selecting HW........................................................................................................................28 Embedded Linux SW Components....................................................................................................28 Where to get Cross-ToolChain...........................................................................................................29 Building Cross-ToolChain..................................................................................................................29 Cross-ToolChain components............................................................................................................29 crosstool-ng........................................................................................................................................30 crosstool-ng Build..............................................................................................................................31 Using Cross-ToolChain......................................................................................................................31 Installing Cross Toolchain..................................................................................................................32 Compile a simple program.................................................................................................................32 Bootloader..........................................................................................................................................32 Bootloader on Embedded...................................................................................................................32 Kernel Compilation............................................................................................................................33 Kernel patching..................................................................................................................................33 Linux source dir..................................................................................................................................33 Linux source dir..................................................................................................................................34 Kernel Compilation............................................................................................................................34 HW Emulators....................................................................................................................................35 Qemu..................................................................................................................................................35 Filesystems.........................................................................................................................................35 Root Filesystem..................................................................................................................................35 Rootfs via network (NFS)..................................................................................................................36 Initramfs.............................................................................................................................................36 Devices...............................................................................................................................................36 Device Types......................................................................................................................................36 Device file example............................................................................................................................37 Islam nabil mahmoud 20130890 2 Electrical&computers Dept Industrial training 2 ITR 102
  • 3. Building full ARM system with Busybox..........................................................................................37 Create your FS directories..................................................................................................................37 Create the configuration files.............................................................................................................38 Create the configuration files.............................................................................................................38 Create the configuration files.............................................................................................................38 Linux Kernel.......................................................................................................................................39 Linux Commands...............................................................................................................................39 Linux Commands (BusyBox).............................................................................................................39 Busybox..............................................................................................................................................39 Create the root fs image file...............................................................................................................40 Run Qemu emulator...........................................................................................................................40 Chapter 3 yocto..................................................................................................................................40 What is Yocto?....................................................................................................................................41 Why Yocto?........................................................................................................................................41 Yocto Project Organization................................................................................................................41 Yocto Project Organization................................................................................................................41 Yocto Key Concept (recipe)...............................................................................................................42 Yocto Project Workflow.....................................................................................................................42 Yocto Project Members......................................................................................................................43 Linaro.............................................................................................................................................43 Xilinx..............................................................................................................................................43 Broadcom.......................................................................................................................................43 AMD...............................................................................................................................................43 LG Electronics................................................................................................................................43 Renesas...........................................................................................................................................44 Long Term Support Initiative (LTSI).............................................................................................44 Juniper Networks............................................................................................................................44 O.S. Systems...................................................................................................................................44 Huawei............................................................................................................................................45 Mentor Graphics.............................................................................................................................45 Timesys...........................................................................................................................................45 Texas Instruments...........................................................................................................................45 OpenEmbedded eV.........................................................................................................................46 MontaVista Software......................................................................................................................46 Intel Corporation............................................................................................................................46 Freescale Semiconductor................................................................................................................46 Enea AB..........................................................................................................................................46 Wind River Systems.......................................................................................................................47 Dell.................................................................................................................................................47 Using Yocto........................................................................................................................................48 Yocto First Shot..................................................................................................................................48 Yocto Build Configuration Files........................................................................................................48 Poky directory structure.....................................................................................................................49 Yocto for RaspberryPi........................................................................................................................49 Minicom.............................................................................................................................................49 Bitbake Utility....................................................................................................................................50 Bitbake Utility....................................................................................................................................50 Yocto Layers.......................................................................................................................................50 Islam nabil mahmoud 20130890 3 Electrical&computers Dept Industrial training 2 ITR 102
  • 4. Layers.................................................................................................................................................51 Creating Layers..................................................................................................................................51 Board Support Packages (BSP)..........................................................................................................51 Yocto Recipes.....................................................................................................................................51 Recipe Build Steps.............................................................................................................................52 Recipe Example..................................................................................................................................53 Yocto Image........................................................................................................................................53 Image Example...................................................................................................................................53 Yocto SDK..........................................................................................................................................54 Poky SDK...........................................................................................................................................54 Generating Poky SDK........................................................................................................................54 Using Poky SDK................................................................................................................................54 References..........................................................................................................................................55 Islam nabil mahmoud 20130890 4 Electrical&computers Dept Industrial training 2 ITR 102
  • 5. Chapter 1 Linux administration Contents of chapter 1 :- Unix & Linux history Why Linux Different Linux distributions Graphical installation of Linux Linux System Structure Exploring Ubuntu GUI Root Filesystem Hierarchy Standard (FHS) Introduction to the command line Getting Help (man pages) Browsing and exploring filesystem. Creating files and directories. Copying and moving files. Removing files and directories. Administrating users and groups Install Packages on Ubuntu Text Editors Text Files Utilities Wildcard Characters System Info Commands Managing and securing files and permissions Piping & Redirection Searching inside text files Searching for files Process management Archiving and compression Shell Scripting Shell Sessions Start-up scripts Islam nabil mahmoud 20130890 5 Electrical&computers Dept Industrial training 2 ITR 102
  • 6. Unix & Linux history In the 60s and early 70s, programmers were used to distribute the source code with their programs. Unix, a family of multitasking, multiuser computer operating systems, was developed in the 1970s at the Bell Labs research center by Ken Thompson, Dennis Ritchie, and others. But, things started to change in the late 70s/early 80s when manufacturers stopped to provide source code. Richard M. Stallman had been working as a hacker at the Artificial Intelligence Laboratory(AI Lab) of the Massachusetts Institute of Technology (MIT) He had modified the software of the printer was used in the lab The printer was changed in 1980 for a brand new model, and Stallman wanted to changed the software again but he was refused access to the source code. This event convinced him that people need to be free to modify the software they use. On September 27, 1983, Stallman announced the GNU Project. The GNU Project aims at developing a complete operating system offering the freedoms to run, study, modify and distribute it. By the early 1990s there was almost enough available software to create a full operating system. However, the GNU kernel, called Hurd, failed to attract enough development effort, leaving GNU incomplete. MINIX, a Unix-like system intended for academic use, was released by Andrew S. Tanenbaum, Operating Systems: Design and Implementation in 1987. n 1991, in Finland, a student, Linus Torvalds, began a project that later became the Linux kernel. He wrote the program specifically for the hardware he was using 80386 processor. Development was done on MINIX using the GNU C compiler. As Torvalds wrote in his book 'Just for Fun', he eventually ended up writing an operating system kernel. On 25 August 1991 (age 21), he announced this system in a Usenet posting to the newsgroup "comp.os.minix." In 1992, he suggested releasing the kernel under the GNU General Public License. In the middle of December 1992 he published version 0.99 using the GNU GPL. Linux and GNU developers worked to integrate GNU components with Linux to make a fully functional and free operating system. GNU/Linux 1992 (complete, open source, UNIX- like operating system) https://www.gnu.org/gnu/linux-and-gnu.html Why Linux Free, Safe, Robust. Source code of all related SW is available. Ported to a large variety of CPU architectures (X86, ARM, PowerPC, .....). Large device drivers coverage. Hosting huge number of languages & libraries. Software is highly modularized, making it easy to build something new. Due to its low cost and ease of customization, Linux has been shipped in many embedded devices (smartphones, network devices, PDAs, IVI, GPS devices, ....). Large Community. Islam nabil mahmoud 20130890 6 Electrical&computers Dept Industrial training 2 ITR 102
  • 7. Linux is everywhere. It's on your servers and in your phones, cars, watches, toasters, refrigerators... and desktops. You need to switch to Linux if You love free stuff You’re obsessed with customizing things You love creating things You love being part of a group and working with others You love the idea of choice http://www.linuxfoundation.org/world-without-linux http://www.makeuseof.com/tag/linux-everywhere-10- things-didnt-know-penguin-powered/ Different Linux distributions Major Linux distributions families RedHat RedHat Enterprise Centos Fedora Debian Debian Ubuntu SUSE SUSE Enterprise Open SUSE Linux System Structure BootLoader (grub, uboot, vivi) Kernel (www.kernel.org) Filesystem (FHS) init process shell (bash & ash & sh) Services manager Scripts & Environment variables Linux commands Applications (user apps, GUI, …) Linux System Principles Everything is a file (including hardware). Consists of small, single-purpose programs. Ability to chain programs together to perform complex tasks. Users usually avoids user interfaces. Islam nabil mahmoud 20130890 7 Electrical&computers Dept Industrial training 2 ITR 102
  • 8. Configuration data stored in text. Exploring Ubuntu GUI Gnome & Kde (X Window system) Windows & Workspaces Ubuntu Help Common applications gedit >> Text Editor nautilus >> File Explorer ........ Terminal Virtual console Filesystem Hierarchy Standard / root directory /bin commands & executable files /sbin system commands & executable files /boot kernel & bootloader /dev hardware device files (nodes) /etc configuration files and startup scripts /home users home directories /root root home directory /lib shared library files /media mount points for storage media /opt third parity applications /proc virtual process files /usr other users applications & libraries /var files that change a lot Introduction to the command line Sample commands cd change directory ls list files in current directory pwd print current working directory mv move & rename Islam nabil mahmoud 20130890 8 Electrical&computers Dept Industrial training 2 ITR 102
  • 9. Getting Help man command info command command –help Browsing and exploring filesystem cd change directory cd dir-name go to dir cd – go previous cd . go to current cd .. go up pwd print current working directory ls list files in current directory ls –l long list ls –lh long list, human read ls another-path list another folder ls –a list all with hidden Absolute and Relative Path names. Creating files and directories touch create a new file touch file-name touch file1 file2 file3 mkdir create a directory mkdir dir-name mkdir dir1 dir2 dir3 Islam nabil mahmoud 20130890 9 Electrical&computers Dept Industrial training 2 ITR 102
  • 10. Copying and moving files cp copy files and directories cp source destination cp –p source destination preserve cp –a source destination with contents mv move & rename files & directories mv source destination If in same dir, it’s considered rename. If to another partition or directory, it’s considered move. Removing files and directories rmdir remove empty directory rmdir empty-dir-name rm remove files and dirs rm file-name rm –r dir-name Administrating users and groups Management of users and groups accounts is an important task for all system admins. You can manage this process from GUI or from terminal. Configuration files related to this task: /etc/passwd /etc/shadow /etc/group Administrating users and groups Useful commands id Displays effective user id, user name, group id, group name. whoami Displays the current effective user su [–] [username] Switch between user accounts exit Exit from current session sudo command Run command with root priviliges Islam nabil mahmoud 20130890 10 Electrical&computers Dept Industrial training 2 ITR 102
  • 11. Install Packages on Ubuntu Install packages from main repositories (automatically) apt-get install app-name >> install new app apt-get update >> update list of pkgs apt-get remove app-name >> remove app Install packages from deb files (manually) dpkg -i pkg-name.deb Install from source code ./configure [options] (not always) make make install Text Editors GUI-based editors gedit Terminal-based editors nano Simplest text based editor. vi / vim More powerful but complex Text Editors (vi / vim) Default editor in all UNIX operating systems. vi in Linux is usually vim (vi improved) Supports syntax highlighting. VI three basic modes Command mode Perform commands to delete, copy, ... Edit mode Enter text into the file Last line mode To access it, enter a colon (:) while in the command mode Text Editors Open file vi filename Enter edit (insert) mode (i) Exit edit (insert) mode (Esc) On command mode you can Exit without saving changes (:q!) Islam nabil mahmoud 20130890 11 Electrical&computers Dept Industrial training 2 ITR 102
  • 12. Save changes and exit (:wq) Save changes and stay (:w) Delete a full line, go to line then press (dd) ...................... Text Files Utilities Viewing file contents cat file-name more file-name or less file-name Scrolling keys for the more command Space bar: moves forward on screen b: move back one screen /string: search forward for pattern n: find the next occurrence q: quit and return to the shell prompt head –n file-name tail file-name Wildcard Characters Asterisk(*): represents 0 or more character ls f* Question mark(?) character represents any single character ls file? Square bracket([ ]): represent a range of characters for a single character position ls [a-f]* System Info Commands whoami print effective current user hostname show or set the system's host name date print or set the system date and time uptime Tell how long the system has been running uname print system information Islam nabil mahmoud 20130890 12 Electrical&computers Dept Industrial training 2 ITR 102
  • 13. System Info Commands free Display amount of free and used memory df report file system disk space usage file file-name file type du file-name estimate file space usage du -sh file-or-folder-name System Info Commands lsusb list USB devices lspci list all PCI devices lscpu display information about the CPU architecture lsmod list loaded modules Managing and securing files and permissions Each file has an owner and assigned to a group. Linux allows users to set permissions on files and directories to protect them. Permissions are assigned to File owner Members of the group the file assigned to All other users Permissions can only be changed by the owner and root. Managing and securing files and permissions Permissions on files and directories Permission Files Access Directories Access Read You can display file contents and copy the file You can list the directory contents Write You can modify the file contents If you also have execute access, you can add and delete files in the directory Execute You can execute the file if it is an executable You can use the cd command to access the directory Islam nabil mahmoud 20130890 13 Electrical&computers Dept Industrial training 2 ITR 102
  • 14. Managing and securing files and permissions To display the permissions on files ls –l - | --- | --- | --- - | rwx | rwx | rwx t | own | grp | other Managing and securing files and permissions To change permissions on file chmod Symbolic mode chmod u+x file chmod g+w file chmod u-r file Numeric (octal) mode chmod 555 file chmod 755 file chmod 214 file To change the ownership of file chown new-owner file-name Only root can change ownership of files. To change group of file chgrp new-group file-name To change owner & group together chown new-owner:new-group file-name Piping & Redirection Piping makes use of interprocess communication. Piping is to take the output of first command as an input to the second command. Piping two commands format: First command | second command Examples cat file-name | less cat file-name | tail Islam nabil mahmoud 20130890 14 Electrical&computers Dept Industrial training 2 ITR 102
  • 15. Redirection It’s to redirect the output channel to a text file to use as log or any other usage. There’s two main output channels Standard output channel command > file Standard error channel command 2> file To redirect both channels command &> file The Black hole is used to redirect output to NO-WHERE /dev/null Searching inside text files To make a horizontal search in a text file grep (selection) It prints all the lines matching a pattern grep search-pattern file-name To print all lines without the matching pattern grep -v pattern file-name It can be used with piping cat file-name | grep pattern Searching inside text files To find a definite column from a text file which is organized in fields delimited with a predefined character. cut (projection) Remove sections from each line of file and print only the required field cut -d”delimiter” -f”field-num” file-name cut -d: -f1 /etc/passwd grep & cut can be used to search in text using selection & projection (same databases concept) Example: Print the shell for a user grep root /etc/passwd | cut -d: -f wc file-name Displays the number of characters, words, and lines in a file Islam nabil mahmoud 20130890 15 Electrical&computers Dept Industrial training 2 ITR 102
  • 16. Searching for files To locate the location for a command and all its other files (help,....) whereis command To locate only the binary file whereis -b command To find files by name in the whole system locate file-name Very fast tool, as it searches in a database Command used to update the file names database updatedb To search for files in a directory hierarchy Find path-to-search –name search-word Process Management The Linux process divides CPU time into time slices, in which each process will get a turn to run, higher priority processes first. User can affect the priority by setting the niceness value for a process . Niceness values range from -20 to +19. Most processes run with a niceness value of 0 (no change). Smaller numbers are higher priority and vice versa. Users can adjust this value down as far as +19 but can not increase it. Root can increase the priority of a process as high as -20 System Monitor GUI tool to monitor all running processes top Terminal-based tool to display all running Linux tasks ps Report a snapshot of the current processes in the current session. ps axu process from all running sessions pidof prog-name find the process ID of a running program pstree Display a tree of processes Islam nabil mahmoud 20130890 16 Electrical&computers Dept Industrial training 2 ITR 102
  • 17. nice -n priority command Assign a niceness value to a new process nice -n 19 ./largeScript.sh renice -n priority -p pid Assign a niceness value to a running process renice -n 10 -p 941 Process Management kill send a signal to a process kill pid >> to terminate a process kill -s signal-number pid killall kill processes by name killall process-nam Archiving & Compression The GNU version of the tar archiving utility To make an archive without compression tar cf archive.tar file(s) To make a compressed archive tar cjf archive.tar.bz2 file(s) tar czf archive.tar.gz file(s) To extract an archive tar xvf myfile.tar tar xvf myfile.tar.bz2 tar xvfz myfile.tar.gz Islam nabil mahmoud 20130890 17 Electrical&computers Dept Industrial training 2 ITR 102
  • 18. Shell Scripting Basic Script Architecture The first line is #!(shell-path) It may contains one or more of these variables definition read variables from user loops conditional statements print output to terminal pipe & redirection to other files Creating and Running Scripts Scripts are normal text files with x permission touch scriptname chmod 777 scriptname chmod u+x scriptname To run a script: full path ./scriptname sh scriptname bash scriptname Variables Define a variable variablename=VALUE Print a variable to screen echo $variablename System variables: Normal: has to be changed with each user HOME PWD SHELL Environmental: changes with login shell only with ( su - ) PATH env print environmental variables read take a value from the user to a variable read variablename read –p “string” variablename Islam nabil mahmoud 20130890 18 Electrical&computers Dept Industrial training 2 ITR 102
  • 19. Bash Comparison Operators Equal (=) Not equal (!=) Less than (-lt) Greater than (-gt) Conditional statements if statement if [ condition ] then ###things to do elif [ another-cond. ] then ###things to do else ###things to do fi Conditional statements case statement case $variablename in value_1) ###things to do;; value_2) ###things to do;; *) ###default action;; esac Loops for loop for VARIABLE in ARRAY do ###things on each value done while loop while [ condition ] do ###things to do done Islam nabil mahmoud 20130890 19 Electrical&computers Dept Industrial training 2 ITR 102
  • 20. Example User Login #!/bin/bash user_name="islam" password="13" read -p "User Name: " login_name read –p "Password: " login_pass echo "" if [ $login_name = $user_name ]; then if [ $login_pass = $password ]; then echo "Now you are logged in....." else echo "Error, wrong password, try again" fi else echo "Error, user name doesn't exist" fi Calculator #!/bin/bash read –p "Enter First Number: " f_num read –p "Enter Second Number: " s_num read –p "Enter Operation(+,-,x,/): " op case $op in +) echo "$f_num + $s_num = $[$f_num+$s_num]";; -) echo "$f_num $s_num = $[$f_num-$s_num]";; x) echo "$f_num x $s_num = $[$f_num*$s_num]";; /) echo "$f_num / $s_num = $[$f_num/$s_num]";; esac Islam nabil mahmoud 20130890 20 Electrical&computers Dept Industrial training 2 ITR 102
  • 21. Shell Sessions There are four shell types: Interactive non-login shells Like opening normal terminal Interactive login shells when logging from tty or when logging in from a terminal Non-interactive non-login shells Typical Shell Script Non-interactive login shells A non-interactive shell is invoked with the --login option Start-up scripts Start-up scripts are scripts of commands executed at login. They are used to: Set up the environment Establish commonly used aliases Run programs Start-up scripts ~/.profile It gets executed automatically by the login shell when one logs-in from the textual console or GUI. ~/.bash_profile or ~./bash_login If one of these files exist, bash executes it rather then "~/.profile" when it is started as a login shell. (Bash will prefer "~/.bash_profile" to "~/.bash_login"). However, these files won't influence a graphical session by default. ~/.bashrc This file will be executed in each and every invocation of bash as well as while logging in to the graphical environment. And it’s executed after profile script. Start-up scripts /etc/profile This file gets executed whenever a bash login shell is entered as well as by the DisplayManager when the desktop session loads. /etc/bash.bashrc This is the system-wide version of the ~/.bashrc file. By default this file is executed whenever a user enters a shell or the desktop environment. Islam nabil mahmoud 20130890 21 Electrical&computers Dept Industrial training 2 ITR 102
  • 22. chapter 2 Embedded Linux LinuxUnix (Ken Thompson & Dennis Ritchie) AT&T company 1969 FSF & GNU (Gnu is Not Unix) & GPL (Richard Stallman) 1984 Hurd Kernel Linux (LinusTorvalds) 1991 GNU/Linux 1992 (complete, open source, UNIX- like operating system) https://www.gnu.org/gnu/linux-and-gnu.html Embedded Linux Embedded Linux is the use of Linux in embedded computer systems. Adapting the Linux kernel and customizing the user-land libraries and utilities to embedded applications such as those in use in consumer electronics, military, medical, industrial, network, and auto industries. Creating an Embedded Linux based system is like a puzzle. Putting the right pieces together will create the final image. Why OS for Embedded ? Make use of micro-processor capabilities (Multi- Tasking ...). Easy to program. System scalability. Why Embedded not Normal OS ? Systems with small and limited resources. Special-Purpose systems. Real-Time systems. Why Linux ? Inexpensive, robust, easy to program, open source. Ported to a variety of CPU architectures. Large device drivers coverage. Why companies need Embedded Linux Engineers? “When you bake it at the factory that’s what it does forever. “ Tim Bird, Sony Entertainment Islam nabil mahmoud 20130890 22 Electrical&computers Dept Industrial training 2 ITR 102
  • 23. Devices running Embedded Linux Some definitions Cross Compiler A cross compiler is a compiler capable of creating executable code for a platform other than the one on which the compiler is running. Toolchain Set of programming tools that are used to create a product (typically another computer program), used in chain. A simple software development ToolChain consists of a compiler and linker to transform the source code into an executable program, libraries to provide interfaces to the operating system, and a debugger. Cross-ToolChain is used and runs on your workstation but generates binaries for your target. Embedded Linux systems components Cross-compilation ToolChain Compiler, debugger, libraries, headers, extra tools. Boot Loader (grub, lilo, uboot) Started by the hardware. Responsible for basic initialization, loading and executing the kernel. Islam nabil mahmoud 20130890 23 Electrical&computers Dept Industrial training 2 ITR 102
  • 24. Linux Kernel Contains the process and memory management, network stack, device drivers, and many other core OS responsibilities, and provides services to userspace applications. C Library (glibc, uclibc, ....) The interface between the kernel and the userspace applications. User Land Services manager Configuration files Common system commands User application(s) Booting sequence Bootloader Executed by the hardware at a fixed location in ROM / Flash Initializes support for the device where the kernel image is found (local storage, network, removable media) Loads the kernel image in RAM and execute. Linux Kernel Uncompresses itself Initializes the kernel core and statically compiled drivers (required to access the root filesystem) Mounts the root filesystem (specified by the root kernel parameter) Executes the first userspace program (specified by the init kernel parameter) User Land First userspace program Configures userspace and starts up system services and any installed user interface (graphical or terminal based). How to build? From scratch The original way, you need to build every single component from scratch, from its source code. Applying your configurations, compiler options, building each component of the system, then integrate all these parts together. Auto-Build tools Automated tools in the form of “build scripts”, written by the experts in this field to make it easy for everyone to build a full embedded Linux system with the minimal knowledge of building process. Islam nabil mahmoud 20130890 24 Electrical&computers Dept Industrial training 2 ITR 102
  • 25. Building from scratch Components you need to build Cross-Toolchain (ready or need to be built) BootLoader Linux Kernel configuration and cross compiling Root filesystem hierarchy System commands (BusyBox) Startup scripts and variables Old ... But not obsolete . (Terminator Genisys) Auto-Build tools Different tools are available to automate the process of building a target system, including the kernel, and sometimes the toolchain. They automatically download, configure, compile and install all the components in the right order. They already contain a large number of packages, that should fit your main requirements, and are easily extensible. Buildroot It’s a set of Makefiles and patches that simplifies and automates the process of building a complete Linux system for an embedded system, by using cross-compilation. Useful mainly while working with small or embedded systems, using various CPU architectures – including x86, ARM, MIPS, and PowerPC Auto-Build tools Yocto It is a Linux Foundation workgroup It's a complete embedded Linux development environment with tools, metadata, and documentation - everything you need The Yocto Project has the objective of attempting to improve the lives of developers of customized Linux systems supporting the ARM, MIPS, PowerPC and x86/x86 64 architectures. Tips for Working on Linux Read instructions and tips carefully. Always read error messages carefully, in particular the first one which is issued. Never stay stuck with a strange problem more than 5 minutes. If you ran commands from a root shell by mistake, your regular user may no longer be able to handle the corresponding generated files. In this case, use the chown –R command to give the new files back to your regular user. Most regular tasks (such as downloading, extracting sources, compiling...) can be done as a regular user. Islam nabil mahmoud 20130890 25 Electrical&computers Dept Industrial training 2 ITR 102
  • 26. Packages required for development sudo apt-get install ncurses-dev bison texinfo flex autoconf automake libtool libexpat1-dev libncurses5-dev patch curl cvs build-essential subversion gawk python-dev gperf socat unzip gcc-arm-linux-gnueabi qemu-system chrpath xterm wget git-core diffstat gcc-multilib libsdl1.2-dev Selecting Hardware for Embedded Linux systems Processor and Arch. The Linux kernel and most other architecture- dependent component support a wide range of 32 and 64 bits architectures, that has MMU. x86 and x86-64, as found on PC platforms, but also embedded systems (multimedia, industrial) ARM, with hundreds of different SoC (multimedia, industrial) PowerPC (mainly real-time, industrial applications) And others. http://elinux.org/Processors RAM & Storage RAM: a very basic Linux system can work within 8 MB of RAM, but a more realistic system will usually require at least 32 MB of RAM. Depends on the type and size of applications. Storage: a very basic Linux system can work within 4 MB of storage, but usually more is needed. Flash storage is supported, both NAND and NOR flash, with specific filesystems. Block storage including SD/MMC cards and eMMC. Communication The Linux kernel has support for many common communication busses USB SPI (Serial Peripheral Interface) CAN (Controller Area Network) 1-wire And also extensive networking support Ethernet, Wi, Bluetooth, CAN, etc. IPv4, IPv6, TCP, UDP, etc. Firewalling, advanced routing. Islam nabil mahmoud 20130890 26 Electrical&computers Dept Industrial training 2 ITR 102
  • 27. Types of HW platforms Evaluation platforms from the SoC vendor. Usually expensive, but many peripherals are built-in. Generally unsuitable for real products. Component on Module, a small board with only CPU/RAM/flash and a few other core components, with connectors to access all other peripherals. Can be used to build end products for small to medium quantities. Custom platform. Schematics for evaluation boards or development platforms are more and more commonly freely available, making it easier to develop custom platforms. (Open Hardware) Tips for Selecting HW Make sure the hardware you plan to use is already supported by the Linux kernel, and has an open-source bootloader. Having support in the official versions of the projects (kernel, bootloader) is a lot better: quality is better, and new versions are available. Some SoC vendors and/or board vendors do not contribute their changes back to the mainline Linux kernel. Embedded Linux SW Components Cross-compilation ToolChain Bootloader Linux Kernel System libraries (C library) Filesystem with other libraries & apps. Where to get Cross-ToolChain http://elinux.org/Toolchains Codesourcery, ready-made http://www.mentor.com/embedded-software/codesourcery Linaro, ready made http://www.linaro.org/ Buildroot, tool to build http://www.buildroot.net/ Crosstool-NG, tool to build http://crosstool-ng.org/ Islam nabil mahmoud 20130890 27 Electrical&computers Dept Industrial training 2 ITR 102
  • 28. Building Cross-ToolChain Cross-ToolChain Three machines must be distinguished when discussing toolchain creation The build machine, where the toolchain is built. The host machine, where the toolchain will be executed. The target machine, where the binaries created by the toolchain are executed. Cross-ToolChain components binutils Kernel Headers C/C++ libs GCC Compiler GDB (optional) Binutils Binutils is a set of tools to generate and manipulate binaries for a given CPU architecture as, the assembler, that generates binary code from assembler source code ld, the linker ar, ranlib, to generate .a archives, used for libraries objdump, readelf, size, nm, strings, to inspect binaries. Very useful analysis tools! strip, to strip useless parts of binaries in order to reduce their size http://www.gnu.org/software/binutils/ Kernel Headers The C library and compiled programs needs to interact with the kernel Available system calls and their numbers Constant definitions Data structures, etc. Therefore, compiling the C library requires kernel headers, and many applications also require them. GCC GNU Compiler Collection, the famous free software compiler Can compile C, C++, Ada, Fortran, Java, Objective-C, Objective-C++, and generate code for a large number of CPU architectures, including ARM, AVR, Blackfin, CRIS, FRV, M32, MIPS, MN10300, PowerPC, SH, v850, i386, x86 64, IA64, Xtensa, etc. http://gcc.gnu.org/ C Library The C library is Interface between the applications and the kernel Provides the well-known standard C API to ease application development Several C libraries are available: glibc, uClibc, eglibc, dietlibc, newlib, etc. The choice of the C library must be made at the time of the cross-compiling toolchain generation, as the GCC compiler is compiled against a specific c C library. We will use uClibc: http://www.uclibc.org/ Islam nabil mahmoud 20130890 28 Electrical&computers Dept Industrial training 2 ITR 102
  • 29. crosstool-ng crosstool-NG aims at building toolchains. Toolchains are made of different pieces of software, each being quite complex and requiring specially crafted options to build and work seamlessly. This is usually not that easy, even in the not-so-trivial case of native toolchains. The work reaches a higher degree of complexity when it comes to cross-compilation, where it can become quite a nightmare... http://crosstool-ng.org crosstool-ng Untar the source code, then build it ./configure --enable-local make You can use help ./ct-ng help ./ct-ng list-samples We will use ./ct-ng arm-unknown-linux-uclibcgnueabi crosstool-ng You can configure it again ./ct-ng menuconfig In Path and misc options: Prefix directory Change Maximum log level to see to DEBUG In Toolchain options: Set Tuple’s alias to arm-linux crosstool-ng In Debug facilities: Enable gdb, strace and ltrace. Remove the other options (dmalloc and duma). In gdb options: Make sure that the Cross-gdb and Build a static gdbserver options are enabled; the other options are not needed. Set gdb version to 7.4.1 crosstool-ng Build Create in you home directory src >> save the tarballs it will download x-tools >> the outbut ./ct-ng build And wait Islam nabil mahmoud 20130890 29 Electrical&computers Dept Industrial training 2 ITR 102
  • 30. Using Cross-ToolChain Now you have your own built toolchain from ARM arch. Inside x-tools directory. Add the bin directory to your PATH environment variable to be able to use it from anywhere export PATH=$PATH:PATH_TO_BIN_INSIDE_TOOLCHAIN You can add this line to bash startup script to be global every time you log in. sudo gedit /etc/bash.bashrc Installing Cross Toolchain If you successfully built your own cross- toolcahin using crosstool-ng, now you’re ready to use it and compile the Linux kernel. If not, you can use the ready-made ARM croos- toolcahin made for Ubuntu, by installing this package sudo apt-get install gcc-arm-linux-gnueabi Compile a simple program Compile any C program to check the toolchain arm-linux-gnueabi-gcc hello.c -o hello Or by using static compiling arm-linux-gnueabi-gcc -static hello.c -o hellostatic You can view the file type file hello Bootloader A piece of code responsible for Basic hardware initialization Loading of an application binary, usually a kernel, from flash storage, network, non-volatile storage. Execution of the application. most bootloaders provide a shell with various commands implementing deferent operations. Loading of data from storage or network, memory inspection, hardware diagnostics and testing, etc. Bootloader on X86 GRUB, Grand Unied Bootloader, the most BIOS powerful one http://www.gnu.org/software/grub/ From ROM >>Stage 1 First 512 bytes >>from raw storage>> Stage 2 Raw storage >>Kernel From filesystem Bootloader on Embedded 1 st type When powered, the CPU starts executing code at a fixed address. The hardware design must ensure that a NOR flash chip is wired so that it is accessible at that address. The first stage bootloader must be programmed at this address in the NOR. Islam nabil mahmoud 20130890 30 Electrical&computers Dept Industrial training 2 ITR 102
  • 31. Unpractical, not common anymore Bootloader on Embedded 2 st type The CPU has an integrated boot code in ROM. Boot code is able to load a first stage bootloader from a storage device (MMC, NAND, ....) Bootloader is provided either by the CPU vendor or through community projects Generic Bootloaders There are several open-source generic bootloaders, the most popular one is U-Boot U-Boot, the universal bootloader by Denx, The most used on ARM, also used on PPC, MIPS, x86, m68k, NIOS, etc. http://www.denx.de/wiki/U-Boot U-Boot Free software project. License: GPLv2 The latest development source code is available in a Git repository: http://git.denx.de/?p=u-boot.git;a=summary Since the end of 2008, it follows a fixed-interval release schedule. Every two months, a new version is released. Kernel Compilation Where to get Linux Kernel source https://www.kernel.org/ You can download any Linux version according to your needs. We’ll use version 3.0.35 https://www.kernel.org/pub/linux/kernel/v3.0/linu x-3.0.35.tar.bz2 Kernel patching Changes to the kernel sources are distributed as patch files. The patch utility is used to apply a series of edits to a set of source files. So, for example, if you have the 2.0.29 kernel source tree and you wanted to move to the 2.0.30 source tree, you would obtain the 2.0.30 patch file and apply the patches (edits) to that source tree: patch -p1 < patch-2.0.30 Linux source dir arch The arch subdirectory contains all of the architecture specific kernel code. It has further subdirectories, one per supported architecture, for example i386 and alpha. Islam nabil mahmoud 20130890 31 Electrical&computers Dept Industrial training 2 ITR 102
  • 32. include The include subdirectory contains most of the include files needed to build the kernel code. It too has further subdirectories including one for every architecture supported. The include/asm subdirectory is a soft link to the real include directory needed for this architecture, for example include/asm-i386. To change architectures you need to edit the kernel makefile and rerun the Linux kernel configuration program. init This directory contains the initialization code for the kernel and it is a very good place to start looking at how the kernel works. Linux source dir mm This directory contains all of the memory management code. The architecture specific memory management code lives down in arch/*/mm/, for example arch/i386/mm/fault.c. drivers All of the system's device drivers live in this directory. They are further sub-divided into classes of device driver, for example block. ipc This directory contains the kernels inter-process communications code. modules This is simply a directory used to hold built modules. fs All of the file system code. This is further sub-divided into directories, one per supported file system, for example vfat and ext2. Linux source dir kernel The main kernel code. Again, the architecture specific kernel code is in arch/*/kernel. net The kernel's networking code. lib This directory contains the kernel's library code. The architecture specific library code can be found in arch/*/lib/. scripts This directory contains the scripts (for example awk and tk scripts) that are used when the kernel is configured. Islam nabil mahmoud 20130890 32 Electrical&computers Dept Industrial training 2 ITR 102
  • 33. Kernel Compilation Configure the Linux kernel using your toolcahin make vexpress_defconfig ARCH=arm CROSS_COMPILE=YOUR-PREFIX Edit the default configuration make menuconfig ARCH=arm CROSS_COMPILE= YOUR-PREFIX Build the kernel image make all ARCH=arm CROSS_COMPILE=YOUR-PREFIX You will find the kernel image in arch/arm/boot/zImage HW Emulators Hardware emulation is the process of imitating the behavior of one or more pieces of hardware (typically a system under design) with another piece of hardware, typically a special purpose emulation system. Qemu QEMU is a generic and open source machine emulator and virtualizer. QEMU lets you run another operating system on top of your existing OS. When used as a machine emulator, QEMU can run OSes and programs made for one machine (e.g. an ARM board) on a different machine (e.g. your own PC). By using dynamic translation, it achieves very good performance. Qemu Install Qemu on Ubuntu sudo apt-get install qemu-system To run the ARM image kernel inside Qemu, we will make a small system containing one single process. We will need the zImage Kernel & initrd image filesystem with init process to run Compile a simple C program arm-linux-gcc -static hello.c -o init Generate the initramfs image echo init | cpio -o --format=newc > initramfs Put the zImage & initramfs together and execute the command qemu-system-arm -M vexpress-a9 -kernel zImage -initrd initramfs -append "console=tty1“ The Linux system should start and execute the single process init. Or you can just start the kernel only qemu-system-arm -M vexpress-a9 –kernel zImage -append "console=tty1" Filesystems Filesystems are used to organize data in directories and files on storage devices or on network. Filesystems are mounted in a specific location (mount point). Single global hierarchy of files. This allows applications to access files and directories easily. Islam nabil mahmoud 20130890 33 Electrical&computers Dept Industrial training 2 ITR 102
  • 34. Root Filesystem the first mounted filesystem under / It is mounted directly by the kernel, according to the root= kernel option. When no root fs found, the kernel panics. It can be mounted from Partition on Hard Disk Partition on Flash Memory Partition on SD Card Partition on NAND Flash From the network, using NFS protocol Rootfs via network (NFS) Once networking works, your root filesystem could be a directory on your GNU/Linux development host, exported by NFS (Network File System). Easy to update files on the root filesystem Ability to have huge filesystem size Host NFS server >>Ethernet >>Target NFS client Built into kernel Initramfs A compressed (cpio) archive of the filesystem. Initramfs is used to be loaded into memory together with the kernel. Used for Fast booting of very small root filesystems. As the filesystem is completely loaded at boot time, application startup is very fast. As an intermediate step before switching to a real root filesystem. This is always used on the kernel of desktop/server distributions to keep the kernel image size reasonable. It is also possible to have initramfs integrated into the kernel image Devices One of the kernel important role is to allow applications to access hardware devices In the Linux kernel, most devices are presented to userspace applications through two different abstractions Character device Block device Islam nabil mahmoud 20130890 34 Electrical&computers Dept Industrial training 2 ITR 102
  • 35. Device Types Block devices A device composed of fixed-sized blocks, that can be read and written to store data. Used for hard disks, USB keys, SD cards, etc. Character devices Originally, an infinite stream of bytes, with no beginning, no end, no size. Used for serial ports, terminals, sound cards, video acquisition devices. Device files “Everything is a file” allows applications to manipulate all “system objects” with the normal file API (open, read, write, close) All device files are by convention stored in the /dev directory. Special type of files. Device file example Serial device c rw- rw- --- 1 root root 4, 64 2014-01-25 08:56 /dev/ttyS0 Example C code that uses the usual file API to write data to serial port int fd; fd = open(“/dev/ttyS0”, O_RDWR); write(fd, “Hello”, 5); close(fd); Building full ARM system with Busybox Create your working directory Open a new Terminal, you will be right now inside your home directory. Assume that the user name currently running is (islam), you will be in: /home/<username> Create any directory to contain the whole OS files and enter it mkdir minios cd minios mkdir tools system cd system Now you are in: /home/<username>/minios/system Islam nabil mahmoud 20130890 35 Electrical&computers Dept Industrial training 2 ITR 102
  • 36. Create your FS directories Execute this commands: mkdir -p bin boot dev etc lib proc root sbin media sys tmp var usr etc/init.d usr/bin usr/sbin usr/lib Now you have the main filesystem directories to contain the whole system. Create the configuration files Inside the ARM_SYSTEM_DIR gedit etc/init.d/rcS #!/bin/sh PATH=/sbin:/bin:/usr/sbin:/usr/bin export PATH /bin/mount -t proc proc /proc /bin/mount -t sysfs sysfs /sys /sbin/mdev -s /bin/hostname EmbeddedLinuxMiniOS /bin/echo “ “ /bin/echo “ Y A T T A “ /bin/echo “ My First Embedded Linux “ /bin/echo “ “ Change the rcS file permissions chmod +x etc/init.d/rcS Create the configuration files gedit etc/group copy and paste this line inside it: root:x:0: gedit etc/passwd copy and paste this line inside it: root:x:0:0:root:/root:/bin/sh gedit etc/shadow copy and paste this line inside it: root::10:0:0:0::: Islam nabil mahmoud 20130890 36 Electrical&computers Dept Industrial training 2 ITR 102
  • 37. Create the configuration files Inside (etc), create these files & fill them with these contents: gedit etc/profile export PS1='EmbeddedLinuxMiniOS #' export USER=`id -un` export HISTSIZE=1000 echo "ya welcome ya welcome ^__^" echo " " After Finishing back to the main dir: /home/<username>/minios/ Linux Kernel The same zImage kernel already built. Just copy the zImage binary file to your working directory under /home/<username>/minios/tools Linux Commands Any Linux distribution need some basic commands to operate correctly, like (mount, ls, pwd, ifconfig, cd, mkdir, touch, file, rm, vi) and more. We need these commands, so there are two ways to get them: Getting the source code for each command needed, compile it separately and copy it to any bin directory inside the distribution. Using BusyBox. Linux Commands (BusyBox) BusyBox combines tiny versions of many common UNIX utilities into a single small executable. It provides replacements for most of the utilities you usually find in GNU fileutils, shellutils, etc. The utilities in BusyBox generally have fewer options than their full-featured GNU cousins; however, the options that are included provide the expected functionality and behave very much like their GNU counterparts. BusyBox provides a fairly complete environment for any small or embedded system. Get Busybox: https://busybox.net/downloads/busybox-1.24.0.tar.bz2 Busybox Put the tar file in your /home/<username>/minios/tools dir and open a new Terminal and go to this dir: tar xvf busybox-1.24.0.tar.bz2 cd busybox-1.24.0/ Inside Busybox source dir, configure & cross- Islam nabil mahmoud 20130890 37 Electrical&computers Dept Industrial training 2 ITR 102
  • 38. compile for ARM make ARCH=arm CROSS_COMPILE=YOUR-PREFIX defconfig Command to start building make CONFIG_PREFIX=/home/<username>/minios/system ARCH=arm CROSS_COMPILE=YOUR-PREFIX install Shared Libraries We will need the shared libraries as we compiled busybox as a dynamic binary file. We can get these libraries from the cross- toolchain we’re using. If you’re using Ubuntu toolchain, run this command to copy required libs to your system dir: cp -a /usr/arm-linux-gnueabi/lib/* /home/<username>/minios/system/lib/ Create the root fs image file Inside the ARM_SYSTEM_DIR “/home/<username>/minios/system” find . | cpio -o --format=newc > ../tools/rootfs.img Now you have the kernel image & the root fs image Run Qemu emulator Go to the tools directory “/home/<username>/minios/tools” qemu-system-arm -M vexpress-a9 -kernel zImage -initrd rootfs.img –append "root=/dev/ram rdinit=/sbin/init" Now you got a console running, and can try any command or app installed. Islam nabil mahmoud 20130890 38 Electrical&computers Dept Industrial training 2 ITR 102
  • 39. Chapter 3 yocto Contents What is Yocto? Why Yocto? Organization of Yocto project Building full image with Yocto (Qemu) Building full image for Raspberry Pi Bitbake Creating new layers Writing new recipes Customizing images Building SDKs What is Yocto? It's not an embedded Linux distribution - It creates a custom one for you. It is a Linux Foundation workgroup www.yoctoproject.org It's a complete embedded Linux development environment with tools, metadata, and documentation - everything you need to create custom Linux-based systems for embedded products regardless of hardware architecture. Why Yocto? Develop using one common Linux OS for different architectures. Re-use your software stack with future devices. Changing hardware platforms with updating just one line in a config file and rebuild. Base your work on a validated collection of software and libraries. Developers spend lots of time porting or making build systems, leaves less time and resources to develop value- adding software features. Yocto Project Organization Yocto Project uses a build system based on the OpenEmbedded (OE) project, which uses the BitBake tool, to construct complete Linux images. The BitBake and OE components are combined together to form Poky, a reference build system. OpenEmbedded Core (OE) – The overall build architecture used by the Yocto Project. BitBake – Task executor and scheduler. meta-yocto – Reference policy/distro configuration and reference hardware support layer. Islam nabil mahmoud 20130890 39 Electrical&computers Dept Industrial training 2 ITR 102
  • 40. Yocto Project Organization Configuration (*.conf) – global definitions of variables. Classes (*.bbclass) – encapsulation and inheritance of build logic, packaging, etc. Recipes (*.bb) – the logical units of software/images to build. Poky – A pre-prepared combination of the build system components needed; also the name of our reference distro in meta-yocto Poky = Bitbake + OE-core + meta-yocto + docs Yocto Key Concept (recipe) The Yocto Project provides tools and metadata for creating custom Linux images. These images are created from a repository of 'baked' recipes. A recipe is a set of instructions for building packages: Where to obtain the upstream sources and which patches to apply Dependencies (on libraries or other recipes) Configuration/compilation options Define which files go into what output packages Islam nabil mahmoud 20130890 40 Electrical&computers Dept Industrial training 2 ITR 102
  • 41. Yocto Project Workflow Yocto Project Members Linaro Linaro’s mission is to bring together industry and the open source community to work on key projects, deliver great tools, reduce industry wide fragmentation and redundant effort, and provide commo Yes Xilinx Xilinx is the world’s leading provider of All Programmable FPGAs, SoCs, MPSoCs and 3D ICs, enabling the next generation of smarter, connected, and differentiated systems and networks. Yes Islam nabil mahmoud 20130890 41 Electrical&computers Dept Industrial training 2 ITR 102
  • 42. Broadcom Broadcom Corporation (NASDAQ: BRCM), a FORTUNE 500® company, is a global leader and innovator in semiconductor solutions for wired and wireless communications. Yes AMD AMD (NYSE: AMD) designs and integrates technology that powers millions of intelligent devices, including personal computers, tablets, game consoles and cloud servers that define the new era of surr Yes LG Electronics LG Electronics Inc. Yes Renesas As a specialist semiconductor manufacturer, operations are centered on three product categories developed worldwide—Microcontroller Units (MCUs), Analog and Power Devices, and System on Chips (SoC) Yes Long Term Support Initiative (LTSI) LTSI is an industry-wide project created and supported by Hitachi, LG Electronics, NEC, Panasonic, Qualcomm Atheros, Renesas Electronics Corporation, Samsung Electronics, Sony and Toshiba and hoste Yes Islam nabil mahmoud 20130890 42 Electrical&computers Dept Industrial training 2 ITR 102
  • 43. Juniper Networks Juniper Networks is in the business of network innovation. Yes O.S. Systems O.S. Systems specialized in multi-platform BSPs and Embedded Operating System development and customization for Linux and Windows platforms, offers consulting development services. Yes Huawei Huawei is a leading global information and communications technology (ICT) solutions provider. Yes Mentor Graphics Mentor Embedded Linux combines the freedom of open source software, the flexibility of extreme customizability and the security of full commercial support in a powerful, easy-to-use package. Yes Timesys TimeSys provides easy-to-use, customizable embedded Linux solutions, full commercial support, professional services and training to embedded developers targeting Yes Islam nabil mahmoud 20130890 43 Electrical&computers Dept Industrial training 2 ITR 102
  • 44. Linux as their go-to-market Texas Instruments Texas Instruments is a global semiconductor design & manufacturing company. Innovate with 80000+ analog ICs & embedded processors, software & largest sales/support staff. Yes OpenEmbedded eV The OpenEmbedded Project provides a software framework to create Linux distributions aimed for, but not restricted to, embedded devices. Yes MontaVista Software MontaVista Software is a company that develops embedded Linux system software, development tools, and related software. Yes Intel Corporation Intel® Corporation is an American multinational semiconductor chip maker corporation headquartered in Santa Clara, California. Yes Islam nabil mahmoud 20130890 44 Electrical&computers Dept Industrial training 2 ITR 102
  • 45. Freescale Semiconductor Freescale Semiconductor (NYSE:FSL) is a global leader in embedded processing solutions, providing industry leading products that are advancing the automotive, consumer, industrial and networ Yes Enea AB ENEA is a global information technology company with its headquarters in Kista, Sweden. ENEA provides real- time operating systems and consulting services. Yes Wind River Systems Wind River Systems, Inc. is a company providing embedded systems, development tools for embedded systems, middleware, and other types of software. Yes Dell For more than 28 years, Dell has empowered countries, communities, customers and people everywhere to use technology to realize their dreams. Islam nabil mahmoud 20130890 45 Electrical&computers Dept Industrial training 2 ITR 102
  • 46. Using Yocto Required Packages Ubutnu dev packages for Yocto development sudo apt-get install gawk wget git-core diffstat unzip texinfo gcc-multilib build-essential chrpath socat libsdl1.2-dev xterm minicom Yocto First Shot Download Yocto source https://www.yoctoproject.org/downloads Current final release: YP Core - Jethro 2.0 Untar the downloaded file $ tar xvf poky-jethro-14.0.0.tar.bz2 Source the poky default environment script $ source poky-jethro-14.0.0/oe-init-build-env build Configure (if you want) your conf file: $ vim conf/local.conf Start the build process (and wait ....) $ bitbake core-image-minimal Run Qemu emulator with output image $ runqemu qemuarm Yocto Build Configuration Files conf/bblayers.conf Contains locations for all layers needed for your build process. BBLAYERS ?= " /home/user/yocto/poky/metayocto conf/local.conf Set your build options, choose target machine, add or remove features from your build image. Configuration variables can be overridden here. BB_NUMBER_THREADS = "threads" How many tasks BitBake should perform in parallel. PARALLEL_MAKE = "j threads" How many processes should be used when compiling. MACHINE ?= "raspberrypi" The machine the target is built for. DL_DIR ?= <downloaddirpath> Sources download directory Islam nabil mahmoud 20130890 46 Electrical&computers Dept Industrial training 2 ITR 102
  • 47. Poky directory structure bitbake: the BitBake utility itself. documentation: documentation sources. scripts: various support scripts (e.g, runqemu) meta/conf: important configuration files, bitbake.conf, reference distro config, machine configs for QEMU architectures. meta/classes: BitBake classes. meta/recipes-* : recipes for all packages & libs Yocto for RaspberryPi Yocto for Raspberry Pi Inside your poky sources folder, download these extra two layers git clone http://git.yoctoproject.org/git/meta-raspberrypi git clone https://github.com/dv1/meta-gstreamer1.0.git Add these new layers paths to your bblayers.conf file Edit local.conf to change MACHINE MACHINE ?= "raspberrypi" Build the minimal image for RaspberryPi bitbake rpi-hwup-image bitbake rpi-hwup-image -c populate_sdk Write the image to SD Card dd if=tmp/deploy/images/raspberrypi/rpi-hwup-image-raspberrypi.rpi-sdimg of=/dev/sdb Minicom A program used to communicate with almost every embedded kit via serial, to see booting process or give commands to the U-Boot or Linux Shell. Using Minicom Connect the USB-to-Serial cable between your board and PC $ sudo minicom -s enters setup mode, first time only Select Serial port setup and set the serial device, baudrate, save your configuration and exit setup mode. Islam nabil mahmoud 20130890 47 Electrical&computers Dept Industrial training 2 ITR 102
  • 48. Bitbake Utility BitBake can be used to run a full build for a given target with bitbake [target] But it can be more precise, with optional options: -c <task> execute the given task -s list all locally available packages and their versions -f force the given task to be run world keyword for all packages -b <recipe> execute recipe (without resolving dependencies). Bitbake Utility bitbake -c listtasks <recipe> Gives a list of the available tasks for that recipe. Tasks are prefixed with do_. bitbake -c menuconfig virtual/kernel Execute the task menuconfig on the default selected kernel package. bitbake -c fetchall <image-name> Download all package sources and their dependencies for that image. For a full description: bitbake –help Yocto Layers Layers The Yocto Project build system is composed of layers. A layer is a logical collection of recipes representing the core, a Board Support Package (BSP), or an application stack. A layer is a collection of packages and build tasks, in the form of set of files and directories and can be created by hand. Yocto Layers Stack Developers-Specific Layer Commercial Layer UI - Optional Layer Hardware Specific BSP Yocto Layer Metadata (meta-yocto) OpenEmbedded Core Metadata (oe-core) Islam nabil mahmoud 20130890 48 Electrical&computers Dept Industrial training 2 ITR 102
  • 49. Layers A list of existing and maintained layers can be found at http://layers.openembedded.org/layerindex/branch/master/layers/ To integrate any layer with yours, just download it, put it on any location on your disk, a good practice is to save it where all others layers are stored. The only requirement is to let BitBake know about the new layer by editing [Build-Dir]/conf/bblayers.conf Creating Layers When making modifications to the existing recipes or when adding new packages, it is a good practice not to modify Poky. Instead you can create your own layers. yocto-layer command By default yocto-layer creates the new layer in the current directory. $ yocto-layer create <layer-name> This will create the required layer base structure, and by default, all metadata matching ./recipes- */*/*.bb will be parsed by the BitBake build engine Board Support Packages (BSP) BSPs are layers to enable support for specific hardware platforms. Defines machine configuration for the “board”. Adds machine-specific recipes and customizations. Kernel config Graphics drivers Additional recipes to support hardware features Yocto Recipes Recipe (.bb) A recipe is a set of instructions to describe how to retrieve, patch, compile, install and generate binary packages for a given application. It also defines what build or runtime dependencies are required. It also contains functions that can be run (fetch, configure, compile...) which are called tasks. Recipe (.bb) Recipe skeleton SUMMARY = “ ” DISCRIPTION = “ ” HOMEPAGE = “ ” LICENSE = “ ” SRC_URI = “ ” SRC_URI[md5sum] = “ ” Islam nabil mahmoud 20130890 49 Electrical&computers Dept Industrial training 2 ITR 102
  • 50. inherit stuff do_compile() { ......... } do_install() { ......... } SRC_URI defines where and how to retrieve the needed elements. It is a set of URI schemes pointing to the resource locations (local or remote). Recipe Build Steps Building recipes involves executing the following functions, which can be overridden when needed for customizations. do_fetch do_unpack do_patch do_configure do_compile do_install do_package do_rootfs Recipe Example DESCRIPTION = “Hello world program” HOMEPAGE = “http://blabla.org” PRIORITY = “optional” SECTION = “examples” LICENSE = “GPLv2” SRC_URI = “file://hello.c” do_compile() { ${CC} ${CFLAGS} ${LDFLAGS} -o hello ${WORKDIR}/hello.c } do_install() { install -d ${D}${bindir} install -m 0755 hello ${D}${bindir} } Yocto Image An image is the top level recipe and is used alongside the machine definition. An image is no more than a recipe, it inherits the core-image class. An image is architecture agnostic and defines how the root filesystem is built, with what packages. By default, several images are provided in Poky: meta*/recipes*/images/*.bb Islam nabil mahmoud 20130890 50 Electrical&computers Dept Industrial training 2 ITR 102
  • 51. Image Example # Base this image on core-image-minimal include recipes-core/images/core-image-minimal.bb # Include more packages in rootfs IMAGE_INSTALL += " Pkg-name “ Yocto SDK SDK An SDK (Software Development Kit) is a set of tools allowing the development of applications for a given target (operating system, platform, environment...). It generally provides a set of tools including: Compilers or cross-compilers. Linkers. Library headers. Debuggers. Custom utilities. Poky SDK The Poky SDK is an application development SDK, which can be generated to provide a full environment compatible with the target. It includes a toolchain, libraries headers and all the needed tools. This SDK can be installed on any computer and is self-contained. The presence of Poky is not required for the SDK to fully work. Generating Poky SDK Generic SDK bitbake meta-toolchain Image-based SDK bitbake -c populate_sdk image-name Output will be in build/tmp/deploy/sdk, in the form of shell script. Executing this script on any machine, will install the SDK. Using Poky SDK To install an SDK, retrieve the generated script and execute it. The SDK will be by default under /opt/poky/<version>/ To use the SDK, a script is available to set up the environment: source /opt/poky/<version>/environment-setup-i586-poky-linux To compile an application: $CC -o example example.c Islam nabil mahmoud 20130890 51 Electrical&computers Dept Industrial training 2 ITR 102
  • 52. References Free-Electrons training materials http://free-electrons.com/training/ Yocto Project documentation https://www.yoctoproject.org/documentation Yocto Project quick start guide yocto-project-qs Bitbake user manual bitbake-user-manual Yocto Project development manual dev-manual Islam nabil mahmoud 20130890 52 Electrical&computers Dept Industrial training 2 ITR 102