Anda di halaman 1dari 55

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
ard
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

File system on chip


UI
Printf Scanf

Kernel Kernel
Device
Driver Display Adaptor Keyboard Driver

#
# Keybo
#hello world :-( ard
#
#
UI on Embedded System
Printf Scanf

Kernel Kernel
Device
Driver Display Adaptor Keyboard Driver

Any Output Any Input


Device Device
Linux on Embedded System

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

RAM TFTP server


Zipped kernel
Linux image
(/home/TFTPdir/uImage)

NFS server
0x0xffe00000

u-boot MyIP: 192.168.0.253 Root Image for


Server IP: 192.168.0.3 MPC860 Linux
ROM Kernel Name: uImage (/home/NFSdir/)
NFS position: /home/NFSdir
Function of Bootloader

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: LEDDEV_release,
fclose(…) };


ssize_t LEDDEV_write(struct file *filp,

LEDDEV.c (2) const char *buf,


size_t count,
int LEDDEV_open(struct inode *inode, loff_t *f_pos)
struct file *filp) {
{ int i;
… struct LEDDEV_Data *Data = filp->private_data;
} for (i=0; i<count; i++)
{
int LEDDEV_release(struct inode *inode, switch (*((char*)(buf+i)))
struct file *filp) {
{ case '1':

} Data->LED_on();
printk("LED is on\n");
ssize_t LEDDEV_read (struct file *filp, char *buf, break;
size_t count, loff_t *f_pos) case '0':
{ Data->LED_off();
int i;
struct LEDDEV_Data *Data = filp->private_data; printk("LED is off\n")
for (i=0; i<count; i++) break;
*((char*)(buf+i)) = Data->Flag; default:
return count; break;
} }
}
return count;
}
Install and Un-install
Device Driver
• insmod Install module driver device
• rmmod Remove module driver device
• lsmod List all installed module driver device

• cat /proc/device List device Major Number


Associate Device
Driver With a File
• mknod File_A c 123 0
File_C
• mknod File_B c 123 1
• mknod File_C c 123 2 File_B
Major Number

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 Applicat
ion
all: Hello_PC

Hello_armHello_PC: Hello.c Generate PC version


gcc -g -o $@ $< Code

Hello_arm: Hello.c Generate ARM version


arm-elf-linux-gcc -g -o $@ $< Code

clean: rm -f Hello_PC Hello_arm


Remote
Debugging Remote PC
Running Linux

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 space While (Rx_Chain empty)
; {
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;
}

Anda mungkin juga menyukai