Basics of Embedded Linux
Basics of Embedded Linux
A Quick Look
Reference Books (1)
Reference Books (2)
Reference Books (3)
Agenda
• Basic Information
• Input and Output Interface
• Booting Embedded Linux
• Modular Device Driver
Basics
Of Version
Linux
Dir Tree
Basic Linux Commands
• ls dir
• cd change dir
• rmdir remove dir
• mkdir make dir
• rm –rf remove file
• cp -rf copy file
• ps -e list process
• cat abc.txt display abc.txt
Embedded Linux
• Run on Limited Resource
• Real Time
• Dedicated Device Drivers
Agenda
• Basic Information
• Input and Output Interface
• Booting Embedded Linux
• Modular Device Driver
Process and Virtual Addressing
GUI Applications
Applications
GUI
Kernel
Device Driver
Hardware
Linux on PC
Memory
#
#
#hello world :-( PC User Apps
#
#
Keybo Kernel
a rd
IO
Devices
Disk File File System
System
File system on disk
Linux on Embedded System
Memory
User Apps
CPU IO
Kernel
RAM ROM
File System
Kernel Kernel
Device
Driver Display Adaptor Keyboard Driver
#
# Keybo
#hello world :-( a rd
#
#
UI on Embedded System
Printf Scanf
Kernel Kernel
Device
Driver Display Adaptor Keyboard Driver
LCD Button
Touch
UART
Replacing Replacing screen
Displayer Keyboard
LED UART
Network Network
UI on UART
Printf Scanf
Kernel
Kernel
Device
Driver UART Driver
Txd Rxd
Agenda
• Basic Information
• Input and Output Interface
• Booting Embedded Linux
• Modular Device Driver
ROM
RAM
Control Bus
Data Bus
Address Bus
Hardware
CPU
System Bootloader
Kernel
Memory ROM
Rootdisk
Usage
(Static)
RAM
System Bootloader
Kernel
Memory ROM
Rootdisk
Usage
(Running) Kernel
Rootdisk
RAM
User
Memory
Debugging Using RS232 Port
Ethernet
RS232
Debugging Using The Ethernet
Ethernet
RS232
Booting Scheme
• Local Booting
– Release Version
• Remote Booting
– Debugging Version
Local Linux
Booting kernel
(U-Boot on
RAM
MPC860)
RAM Disk
0x0xffe00000
u-boot
Zipped Linux
ROM kernel
Zipped root
image
Remote Booting (U-Boot on MPC860)
Zipped Linux
Linux
kernel 192.168.0.3
kernel
DHCP server
NFS server
0x0xffe00000
Bootloader ROM
Kernel
Rootdisk
• Init Board
– Also support some basic
debugging function
• Loading Kernel
– From ROM or From
Remote Server RAM
• Load Root Image
• Starting Kernel
Bootloader
• Redboot
• U-boot
• Homemade bootloader
Kernel Transplant
Root Disk
Device Driver
File System
Device Driver
HelloDev.c
#define MODULE
#include <linux/module.h>
int init_module(void)
{
printk("<1>Hello, world\n");
return 0;
}
void cleanup_module(void)
{
printk("<1>Goodbye cruel world\n");
}
Run it
insmod –f HelloDev.o
lsmod
rmmod –f HelloDev
Complex File
Driver Model
Device Driver
fopen(…)
fread(…)
fwrite(…)
fclose(…)
…
LEDDEV.c (1)
fopen(…) struct file_operations
LEDDEV_fops =
{
fread(…)
read: LEDDEV_read,
write: LEDDEV_write,
fwrite(…)
open: LEDDEV_open,
release:
fclose(…) LEDDEV_release,
};
…
ssize_t LEDDEV_write(struct file *filp,
File_A
One of the inputted
parameter when
calling “open” Device Driver
function
API
void print_i(int i)
{
First Linux
printf("i=%d\n", i); Application
}
int main()
{
int i;
printf("Hello world!\n");
for (i = 1; i<10; i++)
{
print_i(i);
}
}
Makefile For First Linux
Application
all: Hello_PC
Ethernet
GDB
Cable
开发板
GBD Server
Download File To
Development Board
PC
Development
1010010 Board
1101100
1111011
1110101 ROM
1101010
NFS
PC
With NFS Server
Development
Ethernet Board
1111011 Cable
1110101 (Running
1101010 Linux)
GUI
Small
Net & Extension
Development Tools
Bootloader
Linux System Call
Rx_IRQ
Serial
FIFO
Communication
Device
RxD
CPU
Core
FIFO TxD
Tx_IRQ
Code Structure
fread() fwrite()
Write
Read
Tx_Chain
Rx_Chain
Rx_Node
Tx_Node
Rx_ISR Tx_ISR
Tx & Rx FIFO
Below
Code Detail
Tx_ISR Rx_ISR
{ {
if Tx_chain empty get data from FIFO
return Create Rx_Node
else Put Rx_Note to chain
take off a Tx_Node return
sent data in the TX_Node to }
FIFO
return
}
Code Detail
Write() Read()
{ {
Copy data to kernel While (Rx_Chain empty)
space; {
Create Tx_Node; if BLOCK_READ
put Tx_node to Tx_Chain; sleep();
if (first Tx_Node) else
Send it immediately; return 0;
return; }
} get off one Rx_Node;
Copy data to user space;
return read bytes;
}