4. File systems
5. Embedded Linux Device Drivers
B y
Prantice Hall
Embedded Linux System Design & Development by P.
Raghvan, Amol Lad, Sriram Neelakandan
H i r e n
Garreles
Terminology
Source code: The version of software as it is
originally written (i.e., typed into a computer) by a
M e w a d a
data for relatively long periods of time (e.g., years
or even decades), such as hard disk drives (HDDs),
optical disks and magnetic tape.
H i r e n
in the system.
When a program is loaded into the memory and it
becomes a process, it can be divided into four
H i r e n
sections:
Stack: temporary data such as method/function parameters, return
address and local variables
Heap: dynamically allocated memory to a process during its run
B y
time.
Text: current activity represented by the value of Program Counter
and the contents of the processor's registers.
Data: global and static variables.
Terminology
Kernel: a program that constitutes the central core
of a computer operating system.
M e w a d a
Permissions on the file, Date and time of creation, last read and
change.
Date and time this information has been changed in the inode.
Number of links to this file (see later in this chapter).
B y
File size
An address defining the actual location of the file data.
file name and directory missing in inode. These are stored in the special directory files
File system
Get list of inode:
$ ls –I filename
M e w a d a
file name and directory missing in inode. These are stored in the special directory files
Embedded System
Single function
Execute single program, repeatedly
M e w a d a
Continually
reacts to changes in the system’s environment
Must compute certain results in real time without delay
Microsoft Windows CE
QNX Nuetrino
LynuxWorksTM’s LynxOS
B y
B y H i r e n M e w a d a
Embedded System
B y H i r e n M e w a d a
Embedded System
Embedded System and Linux
Embedded Linux system: does not involve Linux at
all.
M e w a d a
Linux system
Boot loader environment
User Space
Load and
Linux Kernel
B y
Hardware
Embedded System and Linux
User space: portion of system memory in which user
processes run.
M e w a d a
H i r e n
B y
Include programs that are written in C, Java, Python, Ruby, and other languages
Embedded System and Linux
Kernel Space: provides abstraction for security,
hardware, and internal data structures.
M e w a d a
hardware
B y
Remembering
What is CISC?
Which of the following offers external chips for
M e w a d a
memory and peripheral interface circuits?
a) Microcontroller b) Microprocessor c) Peripheral
system d) Embedded system
H i r e n
Super computer
H i r e n
B y
Why Linux?
Vendor independent : Same and common basic
components such as Linux kernel, libraries, basic utility.
M e w a d a
Time to market:
Availability of rich set of toolsets and utilities.
Application can be tested on Linux host and port this
application to the board.
H i r e n
operating systems.
What is Linux?
Linux / Unix is an operating system
A computer can be divided into 3 main functional
M e w a d a
layers:
Applications: the highest functional layer. This layer includes
software programs that run for a specific purpose.
Example: this power point presentation, an email tool, a web
browser
H i r e n
Toolset:
In embedded Linux more focus is paid to tools that are needed for
development, debugging, and profiling.
In embedded Linux focus is paid to a set of cross-development tools that
allow developers to build applications for their target on say x86-
based host systems.
H i r e n
are:
hardware specific: Changing computers meant
changing all the software so they could work with the
new hardware
single tasking: Only one job could be done at a time on
H i r e n
together
A new time-sharing operating system.
Lead to a multitasking, multi-user OS
However the Multics project became too large. It was difficult to
manage and the project ended in 1969
H i r e n
Unix:
Developed by Bell Labs from Multics to create an even more
progressive operating system, which they originally named Unics,
B y
platform
Story behind Linux development
University involvement: In 1969 Bell Labs released
Unix, for free, to the Engineering and Computer Science
M e w a d a
California, Berkeley.
Eventually there were 2 major versions of Unix: (1) Unix
System V (developed by AT&T) (2) Unix BSD
B y
(developed by UC Berkeley)
Story behind Linux development
Industry involvement: The graduate students
eventually went on to found successful start up
M e w a d a
free of charge.
Supported by the open source movement, in 1991
Linus Torvalds created a Unix operating system that is
meant to run on a desktop computer. He named it
H i r e n
Linux.
Linux today:
Used in many applications, from embedded systems to servers to
supercomputers
B y
Many people around the world maintain and enhance Linux, since it is an
open source product
Different packages of Linux are called distributions, and can be
downloaded and installed for free
Linux vs Unix
Unix is proprietary to each company that uses the Unix
platform. Some examples are IBM AIX, HP UX, SGI IRIX,
Sun Solaris, DEC Ultrix. These OS are all Unix based
M e w a d a
Unix”
License) – terms as freely available.
Free means not cost wise but based on freedom.
User can study, modify and redistribute it.
H i r e n
Program
& Data
M e w a d a
storage
H i r e n
Time
Day
B y
Anatomy of Embedded System
M e w a d a
H i r e n
B y
Boot process
BIOS: Basic input-output system
Performs system integrity checks (Power on self test (POST)),
Load and execute boot loader
M e w a d a
Single-User Mode:
to boot into the operating system as a superuser
Booting a system into this mode does not start
networking
H i r e n
interfaces
Booting process
BIOS reads the first sector of the hard disk
drive.
M e w a d a
subdirectories
• To locate and load a Linux kernel into RAM and turn control
of the computer over to the kernel.
B y
applied.
Stored in flash memory
Initialized the hardware – memory subsystem and
H i r e n
on any platform
Software program equivalent to BIOS except work
in embedded system.
Initialized critical hardware components i.e. SDRAM
H i r e n
controller, I/O controller, graphics controller.
Initialized system memory
B y
PowerPC or ARM based embedded Linux systems.
RedBoot (RedHat eCos derived, portable,
embedded system boot loader)
H i r e n
2nd stage
Initialize hardware components used in this stage
Check memory map
B y
FS, load
memory image Transfer control to Kernel
needed
jump to the entry
modules
point
Bootloader
Functional blocks:
Main function module
M e w a d a
Provide interface to send command to target board or to inform users
the status of target board
Initialize I/O port
Memory device driver module: Initialize memory
B y
Configure page size, memory size and other memory management
registers
Bootloader
MPC8548CDS
DRAM:
Require detail knowledge of DRAM architecture, chip and
hardware design
must be refreshed constantly
H i r e n
initialization.
Bootloader challenges
Flash and RAM:
Second complexity: to store the bootloader in
M e w a d a
nonvolatile memory but usually loaded into RAM for
faster execution.
No infrastructure is available when bootloader
H i r e n
gains control.
B y
Bootloader challenges
Image complexity:
Complete control over how the image is constructed
M e w a d a
and linked
Need to organize the startup code for specific
processor’s boot sequence
H i r e n
function
Remembering
Which is not the function of OS?
(a) Memory management (b) Disk management (c ) Virus
M e w a d a
protection
What is the initial stage of Linux boot process?
(a) System Startup b) Stage 1 boot loader (c) Kernel
H i r e n
(d) init
In stage 1 boot loader, the first _____ bytes are the
primary boot loader.
B y
list
Main component of Linux
Kernel:
the core of the OS, only one
M e w a d a
prints the shell prompt to indicate that it’s ready for your
input
interprets the command you type in
H i r e n
want to run.
Each utility has a unique name. It is one short word
or an abbreviation of a word.
H i r e n
finger
Information about your system or your terminal: tty,
stty, uname, clear
H i r e n
-brkint –imaxbel
uname: shows basic system information
-a option: shows all system information
M e w a d a
running. The mistaken characters and all the
backspacing characters to fix the typing mistakes
will all be recorded and appear as one long, ugly
B y
called sample
[testuser@abc ~]$ finger
Login Name tty Idle Login Time Office Office Phone
B y
typical meaning), it can also refer to an input
device (such as a scanner), an output device (such as
the monitor), a hardware component (such as the
H i r e n
Hirenmewada: ~/Documents/ls -l
total 20
-rw-rw-r-- 1 jaime jaime 31744 Feb 21 17:56 intro Linux.doc
-rw-rw-r-- 1 jaime jaime 41472 Feb 21 17:56 Linux.doc
drwxrwxr-x 2 jaime jaime 4096 Feb 25 11:50 course
H i r e n
=> tftp 600000 uImage Kernel image into target device memory
Speed: 1000, full duplex
………….
Done
Bytes transferred = 1838553 (1c0dd9 hex)
=> tftp c00000 dtb Board configuration file called a device tree
H i r e n
libraries and utilities that make linux.
Mount root and executes various codes
Do initialization process
Kernel has access to all physical memory
And have full authority to process
H i r e n
...
Looking up port of RPC 100005/1 on 192.168.0.9
VFS: Mounted root (nfs filesystem).
Freeing unused kernel memory: 152k init
INIT: version 2.86 booting
Enter in user space
B y
...
Operates in virtual memory space
login:
Need kernel services for further access
Advantage: error in one process can’t
trash the memory space of another
Kernel
The kernel is a program that
constitutes the central core of a
M e w a d a
Kernel Hardware
request
Shell
H i r e n
Process Memory IO
Scheduler manager Scheduler
Network
IPC
B y
Services
File Device
system IO driver
Hardware
Kernel
Abstraction layer : Protect user from the underlying
details of tracks, sectors, heads and free block of
M e w a d a
int main()
{
int fd, count; char buf[1000];
fd=open("mydata", O_RDONLY);
B y
$ cat /proc/version
B y
Downloading a kernel
Git command is used to download the kernel
$ sudo apt-get install git-core %install git
M e w a d a
$ git clone
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds
/linux-2.6.git linux-2.6
H i r e n
B y
Kernel Phase
Kernel handles all operating system
Memory management
M e w a d a
task scheduling
I/O
interprocess communication
H i r e n
Drivers to compile).
Compiling the kernel (i.e. typing a single command, and
watching...).
H i r e n
#include<stdio.h>
int main(void) make hello.o: Compile hello.c and generate hello.o file
{
printf(“Hello world/n”); make hello.exe:
return 0; convert hello.o file into executable file hello.exe
} make clean:
H i r e n
contained within its subdirectory.
arch/arm/Kconfig <<<<<< (top level Kconfig)
ifdef KBUILD_KCONFIG
|-> init/Kconfig
Kconfig := $(KBUILD_KCONFIG)
| ...
else
H i r e n
|-> arch/arm/mach-iop3xx/Kconfig
Kconfig := arch/$(SRCARCH)/Kconfig
|-> net/Kconfig
endif
| |--> net/ipv4/Kconfig
...
| | |--> net/ipv4/ipvs/Kconfig
gconfig: $(obj)/gconf
| ...
B y
$< $(Kconfig)
|-> drivers/pci/Kconfig
| ...
|-> drivers/usb/Kconfig
| |--> drivers/usb/core/Kconfig
| |--> drivers/usb/host/Kconfig
Kernel construction
Configuring the kernel: kconfig file
During the build process, the .config file is processes
M e w a d a
in C header file i.e. autoconfig.h
collection of definition with simple format.
H i r e n
B y
Kernel Compilation
Common files : System.map
M e w a d a
make bzImage
[root@hirenmewada linux]# ls -l arch/i386/boot/bzImage
-rw-r--r-- 1 root root 1064017 Sept 06 01:53 arch/i386/boot/bzImage
make modules
$ make ARCH=arm CROSS_COMPILE=xscale_be-
ixp4xx_defconfig
M e w a d a
zImage
Desired architecture is ARM
The tool chain required to build kernel is
B y
CROSS_COMPILE=xscale_be-
bzImage for x86, zImage for ARM, vmImage.gz for Blackfin etc
vmlinux: a standalone monolithic binary image. No
unresolved external references exists within the
M e w a d a
vmlinux binary
Consist of several composite binary images.
$ xscale_be-ld -EB -p --no-undefined -X -o vmlinux \
H i r e n
-T arch/arm/kernel/vmlinux.lds \
arch/arm/kernel/head.o \
arch/arm/kernel/init_task.o \
init/built-in.o \
--start-group \
B y
usr/built-in.o \
arch/arm/kernel/built-in.o \
arch/arm/mm/built-in.o \
arch/arm/common/built-in.
vmlinux: a standalone monolithic binary image. No
unresolved external references exists within the
M e w a d a
vmlinux binary
Consist of several composite binary images.
$ xscale_be-ld -EB -p --no-undefined -X -o vmlinux \ Output file
H i r e n
-T arch/arm/kernel/vmlinux.lds \
arch/arm/kernel/head.o \ Linker script file to
arch/arm/kernel/init_task.o \ Link kernel binary images
init/built-in.o \
--start-group \
B y
usr/built-in.o \
arch/arm/kernel/built-in.o \
arch/arm/mm/built-in.o \
arch/arm/common/built-in.
vmlinux: a standalone monolithic binary image. No
unresolved external references exists within the
M e w a d a
vmlinux binary
Consist of several composite binary images.
$ xscale_be-ld -EB -p --no-undefined -X -o vmlinux \
H i r e n
-T arch/arm/kernel/vmlinux.lds \
arch/arm/kernel/head.o \ Architecture specific
arch/arm/kernel/init_task.o \ low-level kernel initialization
init/built-in.o \
--start-group \ Initial thread and task
B y
decide you don't like the way Linux does something and override an
existing system call with an LKM of your own.
Network drivers: interprets a network protocol. It feeds and
B y
AS arch/arm/boot/compressed/head.o
GZIP arch/arm/boot/compressed/piggy.gz
AS arch/arm/boot/compressed/piggy.o
CC arch/arm/boot/compressed/misc.o
B y
AS arch/arm/boot/compressed/head-xscale.o
AS arch/arm/boot/compressed/big-endian.o
LD arch/arm/boot/compressed/vmlinux
OBJCOPY arch/arm/boot/zImage
Kernel: arch/arm/boot/zImage is ready
Architecture object
M e w a d a
H i r e n
B y
Bootstrap loader is created assembling all object files and wrapped with kernel image
Bootstrap loader
A second stage loader
Perform checksum verification of the kernel image,
M e w a d a
Bootloader :
H i r e n
Bootstrap loader:
B y
Flash
memory
H i r e n
relocation
Environment Specific initialization
Head.o: a kernel entry point
Very generic (without any machine dependency )
M e w a d a
in main.c
MMU initialization: Physical addresses are replaced
by virtual addresses
M e w a d a
bootprocess
Kernel is “printk.o”. (found in /kernle/printk.c)
line utilities.
Commands enabled in busybox are avaibale to the users.
sh : shell file
Lib:
H i r e n
Das U-boot
Das U-boot
Configuring U-Boot: make <platform>_config
Edit configure file specific to the hardware
M e w a d a
(…/inlcude/configs/<platform>.h)
Configuration variable have two forms:
Config_xxxx : user configurable and enable specific U-
H i r e n
Boot operation
Config_sys_xxx: hardware specific and need
knowledge of hardware platform.
B y
Das U-boot
U-Boot monitor command:
CONFIG_CMD_FLASH :Flash memory commands
M e w a d a
(such as a Linux kernel image) from a TFTP server.
B y H i r e n M e w a d a
IP add
Booting from Disk
Booting a kernel image from disk
diskboot 0x400000 0:0
M e w a d a
B y
Porting U-Boot
More than 460 different board config files.
Each board has board-specific file in
M e w a d a
../board/vendor/<boardname>
For a new board: modify the existing one
Include directory:
H i r e n
contains startup code for cpu core, clear and starts some
registers.
B y
The lib_<arch> directory:
Board.c : memory map initialization, u-Boot pepripheal
M e w a d a
<boardname>_config : unconfig
@./mkconfig $(@:_config=) <architecture> <core> <boardname>
H i r e n
B y
U-boot image format
Mkimage utility is utilized to create header file for U-
Boot loader and prepend to supplied kernel.
i r e n M e w a d a