Embedded Linux PDF
Embedded Linux PDF
July 2005
Darshak Vasavada
([email protected])
AllGo Embedded Systems Pvt Ltd, Bangalore, India.
www.allgosystems.com
Linux for Embedded Systems
2005, Darshak Vasavada
Kernel mode
system call interface
File Sub-system
IPC
Process
Control Sched
Char Block
Sub-system MM
Device drivers
hardware Hardware
Introduction Process File
Constants
Data
Stack
Scheduler function2
ISR3
function3
T1 T2
Rx ISR
Message queue
T3 Tx ISR
DMA
Double buffer
ISRs
scheduler
high priority
low priority
idle
t
RTOS Flash
ROM or any
Linker prog storage
CMD
Initialization 1 RTOS
code & data
Boot code Task1 code
Task2 code
RAM image Task3 code
ISRs
Constants
Data
Task1 stack
Task2 stack
Task3 stack
System calls
ISR
T3 ISR Drivers
D Hardware
Boot
Code Cross Flash Flash
Compile Programmer
Boot Boot code
Image
Kernel + rootfs
Monolith kernel
Flash + device drivers (code,
data, stack)
Target
Host CPU+RAM+Flash
JTAG,
UART or
Ethernet
Boot loader
Kernel + apps
(sometimes)
Compiler tools
development tools
Build
OS sources
Application sources
Images
Debugger
TTY
Introduction Process File
while (1);
for (i = 0; ...
System calls j = ...
printf (...
write (1, )
return 0;
}
_syscall (WRITE, )
trap handler:
Kernel mode switch (ARG[0])
case WRITE: write read fork
write functionality
case READ:
read functionality
case FORK: hardware interface
fork functionality
... hardware
return 0;
}
interrupt handler Kernel mode
Handling device
Transmitting data
Receiving data
Acknowledging interrupts
fp = fopen (...,
fscanf (fp, ...
main (){
int i, j; return 0;
Timer }
for (i = 0; ... Interrupt
j = ... User mode
printf (...
return 0; Kernel
timer handler
}
mode
Scheduler
Exception: ...
segmentation
violation return 0;
}
User mode
Kernel mode
system call interface
File Sub-system
IPC
FILE ProcessPROCESS
Control Sched
SUB-SYSTEM
Char Block SUB-SYSTEM
Sub-system MM
Device drivers
hardware Hardware
Introduction Process File
Configure
Build
Sched
Drivers Real-time
system
IPC/ITC Modules
Run
shm que Drv struct
sem sig Interrupt
Symbol table
Data:
Global and static variables
Section header
Global and static constants
(tables, strings) Section data
Section header
Headers, symbolic information etc.
Section data
Section data
global = 1; start = 0x2000, length = 0x4
local = 0; global
printf (hello, world!\n); Section data
return 0; start = 0x2004, length = 0x40
Data: Data
Globals, statics loaded in the memory
Heap
Heap
Space for allocating run-time memory
Stack Stack
main ()
{
int local;
global = 1;
local = 0;
printf (hello, world!\n);
return 0;
}
text P1 stack
P2 text
P3 stack
P1 text
P2 data
P2 text
data P1 data
P2 data
P2 stack
Page table
P11 text
stack
text P1 stack
P2 text
P3 stack
P1 text
P2 text
P2 text
data P1 data
P1 data
P2 stack
Page table
P11 text
stack
0x10000 1a 2b 23 47
0x10000 11 22 33 44 0x10004 72 46 7d 48
0x10004 55 66 77 88 Stack Stack
0x10008 d9 ba ca 9c
0x10008 99 aa bb cc FFFFFFFF
Quiz:
I am debugging P1. I place a break-point and when the break-point hits:
1. I examine location 0x10003, what contents should I see?
2. If I see the list at location 0x101, what instruction should I find?
3. How can I list the opcodes of process2?
int num;
while (1)
printf (*(%p) = %d\n, &num, num);
return 0;
}
regions
Proc text 4k
A data 8k
stack 4k
Proc text 4k
B data 8k
stack 4k
$ ls 1 bash running,
reads command ls
f.c
f.h bash calls fork
bash continues running copy of bash running
f.o
exec (/bin/ls,
a.out bash calls wait
ls running
$ bash waiting
bash comes out of wait ls calls exit
bash continues running
Quiz:
1. When will the above code print exec successful?
Level 3 Zzz
Level 2
Level 1 Zzz
fd[1] fd[0]
P1 P2
fd[0] fd[1]
if (fork()) {
Used in shell:
/* parent */
write (fd[1], buf, num_bytes); cat foo | grep bar
process_1 () process_2 ()
{ {
sem_wait sem_wait
Critical region Critical region
sem_post sem_post
} }
main ()
{
signal (SIGINT, sigint_handler);
while (1)
;
}
Introduction Process File
Configure
Build
Sched
Drivers Real-time
system
IPC/ITC Modules
Run
shm que Drv struct
sem sig Interrupt
Directory
Directory is a file too
Contains information about the files
Inode number
File name
$ cc bb.c o bb
$ ln s bb ls
$ ln s bb cp
$ ls
(runs ls)
$ cp f1 f2
(runs cp)
Introduction Process File
Configure
Build
Sched
Drivers Real-time
system
IPC/ITC Modules
Run
shm que Drv struct
sem sig Interrupt
void cleanup_module(void)
{
printk("<1>Goodbye cruel world\n");
}
* For Linux v2.4.
[email protected] AllGo Embedded Systems
ASPICES 2005, Indian Institute of Science 124
http://www.allgosystems.com
How to insert the module? (#)
gcc c hello.c
Creates hello.o
insmod hello.o
Adds hello.o to the kernel.
Also executes init_module function
Typically used to register a device driver
rmmod hello.o
Removes hello.o from the kernel
Also executes cleanup_module function
Typically used to unregister a device driver
#: different in 2.6
main ()
{
int fd;
Device table
Kernel mode
return; return;
} }
** : ignores kernel/user space distinciton
Introduction Process File
Configure
Build
Sched
Drivers Real-time
system
IPC/ITC Modules
Run
shm que Drv struct
sem sig Interrupt