Title: Embedded Linux Development on ARM Processor
1Embedded Linux Development on ARM Processor
- Training by
- Mr. Siriroj Jungthawan
- Embedded Systems Engineer
- Design Gateway Co.,Ltd.
2Agenda
- Part 1
- Embedded System
- Embedded Linux
- Software and Tool for Embedded Linux
- Part 2
- JAMP-II Board
- Setup tools and Develop
3Embedded System
4Embedded System
Store Program
Control System
System Function
5Basic Embedded System
6Advanced Embedded System
7Operating System
Process
8Embedded OS sourcing trends
Ref. www.linuxdevices.com
9Linux Advantage
- Free license
- Open-source
- Robust TCP/IP stack
- Large community
- Support many processor architectures (32/64 bit)
- i.e. ARM, MIPS, PowerPC, x86, v850, SH
10Embedded Processor Trends
Ref. www.linuxdevices.com
11Embedded Linux
12Embedded Linux
- Supported from manufacturers to ported Linux to
their microprocessor - Freescale, Atmel, Cirrus Logic
- Multi-Processing
- Utilize small memory and storage
- Highly customizable
- Development based on C Language
13Embedded Linux Type
- Kernel.org Original Linux kernel
- uCLinux No MMU Architecture
- RTLinux Real Time Scheduler
- Linux Distributor
- Montavista, TimeSys, Koan, Wind River
14Embedded Linux OS sourcing trends
Ref. www.linuxdevices.com
15Embedded Linux System
SD card
USB
IDE
VGA
CF
Flash
SD-RAM
Serial
FPGA
Audio
CPU
Ethernet
PS2
16Software and Tool for Embedded Linux
17Embedded Linux Components
18Compiler
19Compile Step
20Compiler (Toolchain)
- Compiler types
- Native Compiler same processor architecture
- i.e. gcc, tcc, sdcc
- Cross Compiler different processor architecture
- i.e. arm-linux-gcc, ppc-linux-gcc ,
mipsel-linux-gcc - arch-system-gcc
- Steps to build compiler and other tools
- Download source code
- Configure (select architecture)
- Compile source code
21Source code for Compiler
- GNU binary utilities (binutils)
- GNU compiler collection (gcc)
- C library
- Glibc for Linux
- Uclibc for embedded Linux
- Newlib for embedded system
- Linux Kernel Headers (2.2, 2.4, 2.6)
- GNU debugger (gdb)
22Boot Loader
23Boot Loader
- Low level system setup (CPU, Serial)
- Detect Peripheral Device (Flash)
- Configured by command line
- Support protocol for transfer data
- Serial X-modem, Y-modem, Kermit
- Ethernet TFTP
24Boot Step
- ROM boot
- Default system setup
- i.e. CPU speed, device address
- Load data from flash to SDRAM
- Run data from SDRAM
ROM
- Boot loader
- Setup CPU speed, Bus speed, Bus size
- Detect, Setup and test Peripheral Device
- Run boot script or console mode
25Console Feature
- Set parameter and Boot script
- Read/Write/Compare data to RAM
- Copy data with RAM and Flash
- Download data from Serial, Ethernet
- Test Image
26Boot Loader
- Popular Bootloader for Embedded Linux
- Redboot, U-boot
- Popular supported architectures
- x86(PC), PowerPC(Mac), ARM and MIPS
27Linux Kernel
28Linux Kernel
29Kernel Module
- For adding more feature to Linux Kernel
- Support new device driver
- Support new file system type
- Support new protocol
- Kernel module operation
- insmod insert a module into Linux Kernel
- rmmod remove a module from Linux Kernel
- lsmod show the status of modules in Linux
Kernel - modprobe (Ref. /etc/modprobe.conf)
30Root File System
31Root File System RootFS
- RootFS Area for storing all Linux data
- Command (ls, mv, rm)
- Device node (/dev/console, /dev/tty)
- Configure File (.conf)
- library (.a, .so)
- Kernel module object (.ko)
- Symbolic link (Shortcut on Windows)
- Application (Firefox, vsFTPd)
- Note File type can checked by Command file
32Linux RootFS Hierarchy
33Directory of Root File System
- / Root node
- /bin Essential command binaries
- /dev Device node
- /etc Host-specific system configuration
- /home User home directories (optional)
- /lib Essential shared libraries and kernel
modules - /media Mount point for removable media
- /mnt Mount point for mounting a filesystem
temporarily - /proc Mount point for Kernel and process
information virtual filesystem - /root Home directory for the root user (optional)
- /sbin Essential system binaries
- /sys Mount point sysfs for exporting kernel
objects infrastructure - /tmp Temporary files
- /usr Secondary hierarchy
- /var Variable data
34File System Types
- Structure for Data on Storage
- MS-DOS(FAT), FAT32, NTFS, ISO9660
- File systems for Embedded Linux
- EXT2 The Second Extended File system, Typical
file system in Linux - EXT3 The Third Extended File system, the
ext2 file system enhanced with journaling
capabilities - JFFS Journaling Flash File System used for
Flash memory (MTD) - NFS Network file system, used for
network drive from other host
35Media for Root File System
- Storage (EXT2, EXT3)
- Hard disk, Ram disk, USB Flash drive, MMC/SD card
- Memory Technology Devices MTD (JFFS/JFFS2)
- NOR Flash, NAND Flash, OneNAND Flash, SPI Flash
- Network (NFS)
- Network Device from NFS server on other PC
36Device Driver
37Device Driver
38Device Control
- Bus Interface in system
- Bus Interface PCI, IDE, SCSI, PCMCIA
- Serial Bus Interface 1-wire, I2C, SPI, USB
- Device in system
- Port serial port, parallel port
- User Interface Keyboard, Mouse, Joystick, touch
screen - Storage HDD, MMC/SD, Flash (MTD)
- Network Ethernet, Wireless LAN, Bluetooth
- Sound (OSS, ALSA)
- Graphics (Frame Buffer)
- Etc Real Time Clock, Watchdog, GPIO, ADC, PWM
39Device Class
- Character Devices
- Serial port, Frame Buffer, Sound
- Block Devices
- Hard disk, Flash memory, CDROM
- Network Devices
- Ethernet, Wireless LAN
40How to access device
- Application must access device through device
node - /dev/ttyS0
- /dev/sda1
- Access device node by File operation
- open(), read(), write(), close(), ioctl()
41Device node
- Device type
- chr_dev (character devices)
- blk_dev (block devices)
- Device number
- Major number 1-239, 240-254 (local/experimental
use), 255 (reserved) - Minor number 0-255
- Device node Example
- /dev/sda1, /dev/ttyS0 , /dev/ttyS1, /dev/zero
- brw-r----- 1 root root 8, 1 Sep 6 2007
sda1 - crw-rw---- 1 root root 4, 64 Sep 6 2007
ttyS0 - crw-rw---- 1 root root 4, 65 Sep 6 2007
ttyS1 - crw-rw-rw- 1 root root 1, 5 Sep 6 2007
zero - Ref. Kernel Source/Documentation/devices.txt
42Application
43Application
- Developed by C/C language
- Standard C library
- File Operation
- Network Operation
- Device Access Operation
- Thread, Signal (interrupt software)
- Inter Process Communication IPC
- Other Library
- libjpeg, libz, libfreetype
44Library Executed Type
- Library Type
- Static library Archive Object (libpng.a)
- ar rcs libpng.a png.o pngerror.o pngmem.o
- Share library Share Object (libpng.so)
- Executed Type
- statically linked (gcc -static)
- dynamically linked
45QA Part 1
46JAMP-II Board
47JAMP-II Box Content
- JAMP-II board
- Serial cable
- LAN cross cable
- Adapter 5 Volt
- Document and SDK CD
- VMware DVD
- Registration card
48Embedded Linux System
SD card
USB
IDE
VGA
CF
Flash
SD-RAM
Serial
FPGA
Audio
CPU
Ethernet
PS2
49Board Overview
- 180 MHz ARM920T core
- 64MB SD RAM
- 4 MB Parallel Flash
- 1 Mb EEPROM
- 3 Serial port (support RS485)
- 1 USB 2.0 Full speed host
- 1 USB 2.0 Full speed device
- 1 MMC/SD card socket
- 1 CF socket
- 1 ATA IDE 40pin port
- 10/100 Ethernet
- Audio Input/output
- FPGA Spartan 3E 500K gates
- 4 Mb Serial Flash
- 2 port PS2
- 1 port VGA
50Serial Console Setup
Setup 115200 8N1 non-flow
51Hardware Setup
52(No Transcript)
53(No Transcript)
54(No Transcript)
55Course Overview
56Course Overview
- Setup OS and Service
- Setup SDK
- Setup Firmware First-Time
- Setup, Build and Update U-boot
- Setup, Build and Update Linux Kernel
- Setup, Build and Update RootFS
- Update PROM FPGA
57Setup OS and Service
58Setup OS and Service
- Setup OS (Fedora Core 4)
- Setup Network (Ethernet)
- Setup Service (Daemon)
- sshd service (Secure Shall)
- vsftpd service (File Transfer Protocol)
- nfs service (Network File System)
- samba service (Window Share File)
- tftp service (Trivial File Transfer Protocol)
59Setup OS (Fedora Core 4)
- Install Fedora Core 4 on PC
- Installation type workstation
- Package Installation Default Customize ..
- Package Group Selection Server
- Server Configuration Tools
- Windows File Server
- FTP Server
- Legacy Network Server ? tftp-server
60Setup OS (Fedora Core 4)
Setup from CD/DVD
61Setup OS (Fedora Core 4)
Select Workstation
62Setup OS (Fedora Core 4)
Select Costomize software package..
63Setup OS (Fedora Core 4)
VMplayer play VMimage
64Setup OS (Fedora Core 4)
VMplayer Login root/dg, Password abc123
65Setup Network (Ethernet)
setup
66Setup Network (Ethernet)
Select Network Configufation ? Ethernet
67Setup Network (Ethernet)
service network restart
68Setup Service (daemon)
setup
69Setup Service (daemon)
select System services
70Setup Service (daemon)
service sshd, vsftpd, nfs, smb xinetd status
71Setup Service (daemon)
Transfer data by vsFTPd service
72Setup Service (daemon)
Transfer data by Samba service
73JAMP-II Development Step
74Setup SDK
75Setup SDK
- Setup SDK
- Install cross-compiler
- Install dg-arm-linux
- Setup Source code
- Compiler Source code
- Move Firmware JAMP-II into directory ./firmware
- Export Path of cross-compiler
76 ./setup
77JAMP-II Firmware
- loader.bin (First stage boot on ram)
- boot.bin (First stage boot on flash)
- u-boot.bin and u-boot.gz (Boot loader)
- zImage (Linux kernel)
- initrd.gz (image rootfs on SD-RAM)
- root_jffs2.img (image rootfs on nor flash)
- promdata.bin (configure FPGA on SPI flash)
- Firmware in path ./firmware
78 vim .bash_profile (/root/, /home/dg/)
79Setup Firmware First-Time
80Setup Firmware first-Time
- Switch Boot mode
- Set jumper (J30) pin 1-2
- Push reset button
- Load Firmware by 1K X-modem protocol on serial
- Load loader.bin
- Load u-boot.bin
- Flash Firmware by Kermit on serial or TFTP on
Ethernet - Flash boot.bin
- Flash u-boot.gz
81JAMP-II Development Step
82Setup and Build U-boot
83Setup and Build U-boot
- Clean source
- make mrproper
- Select Platform
- make jamp2_config
- Built U-boot
- make
84 make jamp2_config
85 gzip -9 -c u-boot.bin gt u-boot.gz
86Update U-boot
87Update U-boot
- Unprotect and erase area flash memory
- U-Bootgt protect off 10010000 1002ffff
- U-Bootgt erase 10010000 1002ffff
- Fill memory area
- U-Bootgt mw.b 20008000 ff 20000
- Download u-boot.gz into board
- U-Bootgt tftp 20008000 u-boot.gz
- Copy from SD-RAM to flash memory
- U-Bootgt cp.b 20008000 10010000 20000
88(No Transcript)
89Setup and Build Kernel
90Setup and Build Kernel
- Configure Linux Kernel
- Process management multitask
- Memory management virsual memory, swap
- File system ext2, ext3, vfat, jffs2, nfs
- Device control flash, serial, audio, Ethernet
- Networking TCP/IP, IPv4, IPv6, IPX
- Kernel Command Line
- Option for kernel module
- ltgt, built in to kernel. (press y)
- lt gt, remove it. (press n)
- ltMgt make it to module. (press m)
91Setup and Build Kernel
- Show make option of Linux Kernel
- make help
- Load Default Configure JAMPII
- make at91rm9200dk_defconfig
- Configure Linux Kernel
- make menuconfig
- Compile Linux Kernel
- make
- Compile Kernel Module
- make modules_install INSTALL_MOD_PATH./
92 make at91rm9200dk_defconfig
93 make menuconfig
94(No Transcript)
95 make
96 cp arch/arm/boot/zImage /tftpboot/
97 make modules_install INSTALL_MOD_PATH./
98Update Linux Kernel
99Update Linux Kernel
- Erase area flash memory
- U-Bootgt erase 10030000 1016ffff
- Fill memory area
- U-Bootgt mw.b 20008000 ff 140000
- Download zImage into board
- U-Bootgt tftp 20008000 zImage
- Copy from SD-RAM to flash memory
- U-Bootgt cp.b 20008000 10030000 140000
100(No Transcript)
101Setup and Build RootFS
102Setup and Build RootFS
- Setup and Build RootFS
- Skeleton of RootFS
- Binary command (Busybox)
- Configure file (text file)
- busybox is tools for build command
- buildroot is tools for build root file system
103Build RootFS on Ramdisk
- Create raw data
- dd if/dev/zero ofinitrd bs1k count4k
- Create file system into raw data
- mkfs.ext2 -b 1024 -F initrd
- Create node and mount to raw data
- mkdir ./node_initrd
- mount t ext2 o loop initrd ./node_initrd
- Copy data from rootfs path into node of initrd
- cp R ROOTFS ./node_initrd
- Un-mount from raw data
- unmount ./node_initrd
- Compress raw data
- gzip -9 c initrd gt initrd.gz
- Initrd initial ramdisk
104Build RootFS on MTD
- Create RootFS type jffs2
- mkfs.jffs2 -e 0x10000 -o rootfs.jffs2 -r
ROOTFS - -e erase size of flash
- -o output to file name
- -r node of RootFS
105Build RootFS on NFS
- Configure NFS drive on PC
- Edit /etc/exports
- add ROOTFS (rw,sync,no_root_squash)
- Restart NFS service for check configure
- service nfs restart
- Create node and Test mount NFS drive
- mkdir ./node_nfs
- mount o nolock SERVER_IPROOTFS ./node_nfs
- Un-mount NFS drive
- umount ./node_nfs
106Update RootFS
107Update RootFS
- Erase area flash memory
- U-Bootgt erase 10170000 103fffff
- Fill memory area
- U-Bootgt mw.b 20410000 ff 290000
- Download initrd.gz into board
- U-Bootgt tftp 20410000 initrd.gz
- Copy from SD-RAM to flash memory
- U-Bootgt cp.b 20410000 10170000 1c0000
108(No Transcript)
109Update PROM FPGA
110Update PROM FPGA
- Unprotect area flash memory
- U-Bootgt protect off D0000000 D0083FFF
- Fill memory area
- U-Bootgt mw.b 20008000 ff 84000
- Download promdata.bin into board
- U-Bootgt tftp 20008000 promdata.bin
- Copy from SD-RAM to flash memory
- U-Bootgt cp.b 20008000 D0000000 84000
111(No Transcript)
112QA Part 2
113Embedded Linux Development on ARM Processor
- Training by
- Mr. Siriroj Jungthawan
- Embedded Systems Engineer
- Design Gateway Co.,Ltd.
114Agenda
- Part 1
- Application Development
- Makefile
- Access File Programming
- Network Programming
- Access Device Programming
- Part 2
- Device Driver Development
- Character Device Driver
115JAMP-II Development Step
116Application Development
117Build Application
- Source code
- Source file (.c, .cpp)
- Header file (.h, .hpp)
- Library
- Static Library (.o, .a)
- Dynamic Library (.so)
- Makefile
- Application (Execute File)
- Hint user can check dynamic library of
Application by command ldd
118(No Transcript)
119(No Transcript)
120(No Transcript)
121Makefile
122Makefile for Application
- Comment ()
- comment line
- Macro
- CROSS_COMPILE arm-linux-
- CC (CROSS_COMPILE)gcc
- Target
- hello hello.o
- (CC) -o hello hello.o
123Makefile for Application
- CROSS arm-linux-
- CC (CROSS)gcc
- all hello
- compile application
- hello hello.o
- (CC) -o hello hello.o
- hello.o hello.c
- (CC) -c hello.c
- clean application
- clean
- rm .o hello
124Access File Programming
125Access File Programming
- Example Access_File
- include ltstdio.hgt
- FILE fopen(const char path, const char mode)
- size_t fread(void ptr, size_t size, size_t
nmemb, FILE stream) - size_t fwrite(const void ptr, size_t size,
size_t nmemb, FILE stream) - int fprintf(FILE stream, const char format,
...) - int fscanf(FILE stream, const char format,
...) - int fflush(FILE stream)
- int fclose(FILE stream)
126Network Programming
127Network Programming
- Example Server_client
- include ltsys/socket.hgt
- include ltnetinet/in.hgt
- include ltarpa/inet.hgt
- int socket(int domain, int type, int protocol)
- int bind(int sockfd, struct sockaddr my_addr,
socklen_t addrlen) - int listen(int sockfd, int backlog)
- int accept(int sockfd, struct sockaddr
client_addr, socklen_t addrlen) - int connect(int sockfd, const struct sockaddr
server_addr, socklen_t addrlen) - ssize_t recv(int sockfd, void buf, size_t len,
int flags) - ssize_t send(int sockfd, const void buf, size_t
len, int flags) - int shutdown(int sockfd, int how)
128Access Device Programming
129Serial Port Programming
- Example Serial_port
- include ltfcntl.hgt
- include ltunistd.hgt
- include ltsys/ioctl.hgt
- include lttermios.hgt
- int open(const char pathname, int flags)
- ssize_t read(int fd, void buf, size_t count)
- ssize_t write(int fd, const void buf, size_t
count) - int ioctl(int fd, int request, ...)
- int close(int fd)
- int tcgetattr(int fd, struct termios termios_p)
- int tcsetattr(int fd, int optional_actions,
struct termios termios_p)
130QA Part 1
131Device Driver Development
132Building Device Driver
- Kernel Source Path
- ./dg-arm-linux-1.0.3/linux-2.6.16.16
- Source code
- Source file (.c, .cpp)
- Header file (.h, .hpp)
- Makefile
- Kernel module (.ko)
- Device Node
- mknod /dev/memop c 245 0
133Basic Kernel module
- include ltlinux/init.hgt
- include ltlinux/module.hgt
- int (init)(void)
- void (exit)(void)
- module_init(init)
- module_exit(exit)
- Ref .. ./basic_dev/hello_module.ko
134(No Transcript)
135(No Transcript)
136(No Transcript)
137Character Device Driver
138Character Devices
- include ltlinux/fs.hgt
- include ltlinux/cdev.hgt
- define MAJOR(dev) ((unsigned int) ((dev) gtgt
MINORBITS)) - define MINOR(dev) ((unsigned int) ((dev)
MINORMASK)) - define MKDEV(ma,mi) (((ma) ltlt MINORBITS) (mi))
- int alloc_chrdev_region(dev_t , unsigned,
unsigned, const char ) - int register_chrdev_region(dev_t, unsigned, const
char ) - void unregister_chrdev_region(dev_t, unsigned)
- void cdev_init(struct cdev , struct
file_operations ) - int cdev_add(struct cdev , dev_t, unsigned)
- void cdev_del(struct cdev )
139Character Devices(cont.)
- struct file_operations
- struct module owner
- ssize_t (read) (struct file , char __user ,
size_t, loff_t ) - ssize_t (write) (struct file , const char
__user , size_t, loff_t ) - int (ioctl) (struct inode , struct file ,
unsigned int, unsigned long) - int (mmap) (struct file , struct
vm_area_struct ) - int (open) (struct inode , struct file )
- int (release) (struct inode , struct file )
- ...
140Communication with hardware
Allocation and mapping Kernel space to User space
Allocation and mapping Hardware to Kernel space
141Communication with hardware
- I/O Memory Allocation
- struct resource request_mem_region (unsigned
long start, unsigned long len, const char name) - void release_mem_region (unsigned long start,
unsigned long len) - int check_mem_region (unsigned long start,
unsigned long len) - I/O Memory Mapping
- void ioremap (unsigned long phys_addr, unsigned
long size) - void ioremap_nocache (unsigned long phys_addr,
unsigned long size) - void iounmap (void addr)
142Communication with hardware
- Accessing I/O Memory
- unsigned char readb(void addr)
- unsigned short readw(void addr)
- unsigned long readl(void addr)
- void writeb(unsigned char data, void addr)
- void writew(unsigned short data, void addr)
- void writel(unsigned long data, void addr)
- Accessing I/O Memory (String Operation)
- void readsb(void addr, void data, int len)
- void readsw(void addr, void data, int len)
- void readsl(void addr, void data, int len)
- void writesb(void addr, const void data, int
len) - void writesw(void addr, const void data, int
len) - void writesl(void addr, const void data, int
len)
143(No Transcript)
144Access Data betweenKernel space and User space
- Open/Close
- int open(const char pathname, int flags)
- int close(int fd)
- Read/Write
- ssize_t read(int fd, void buf, size_t count)
- ssize_t write(int fd, const void buf, size_t
count) - Control device
- int ioctl(int fd, int request, void argp)
- Memory map
- void mmap(void start, size_t length, int prot
, int flags, int fd, off_t offset) - int munmap(void start, size_t length)
145(No Transcript)
146QA Part 2
147Welcome to Embedded Linux World
Thank you
- siriroj_at_design-gateway.com
148Appendix
149Toolchain Cross-compiler
- Shell-Script for built GCC
- Crosstool (GNU C Library glibc)
- http//www.kegel.com/crosstool/download
- uClibc (micro C library uclibc)
- http//www.uclibc.org/downloads
- Binary
- Gnutools (New C library Newlib)
- http//ecos.sourceware.org/mirror.html
150Boot Loader Link
- Red-boot
- original
- http//ecos.sourceware.org/mirror.html
- U-boot
- original
- http//www.denx.de/wiki/UBoot/WebHome
151Linux Kernel Link
- Linux kernel
- original
- http//www.kernel.org/pub/linux/kernel/v2.6/
- patch for JAMP-II board
- http//www.design-gateway.com/forum/viewforum.php
?f24 - patch for at91rm9200 Other board
- http//maxim.org.za/at91_26.html
152Device Driver
- Ref.
- http//lwn.net/Kernel/LDD3/
153Application
- Ref.
- Beginning Linux Programming
- Professional Linux Programming
- Advanced Linux Programming
- http//www.advancedlinuxprogramming.com/downloads
.html