Home Automation, Networking, and Entertainment Lab
Dept. of Computer Science and Information Engineering National Cheng Kung University
Chia Che Lee
Embedded Linux on ARM
Department of Computer Science and Information EngineeringNational Cheng Kung University 2HANEL
OUTLINETool chainsBootloaderBuilding Linux kernelLinux device driverGUI
Department of Computer Science and Information EngineeringNational Cheng Kung University 3HANEL
Tool chainsA collection of tools used to develop for a particular hardware target (e.g. embedded system)Often used in the context of building software on one system which will be installed or run on someother device (e.g. embedded system) the chain of tools usually consists of such items as a particular version of a compiler, libraries, assembler, special headers, etc.
Department of Computer Science and Information EngineeringNational Cheng Kung University 4HANEL
Tool chainsThe Advantage of understanding tool-chain :
Any project that requires an embedded processor also requires software-development tools.Be advantage to develop new embedded system by developing own tool-chain
Department of Computer Science and Information EngineeringNational Cheng Kung University 5HANEL
Tool chains
The role of toolchain
Department of Computer Science and Information EngineeringNational Cheng Kung University 6HANEL
Tool chains
Compile flow chart
Source code
Source code
Source code
Assembly code
Assembly code
Assembly code
object code
object code
object code
Executable code
code
compiler compiler compiler
Assembler Assembler Assembler
LinkerLibraries
Department of Computer Science and Information EngineeringNational Cheng Kung University 7HANEL
Tool chains
Why using the GNU Tool-chain
GNU is a complete, Unix-like operating system that has been in development for just over twenty yearsGNU software is known for it's stability and standard complianceGNU tool-chain is open source which be easy to modify
Department of Computer Science and Information EngineeringNational Cheng Kung University 8HANEL
Tool chainsThe GNU toolchain consists :
Compiler gccAssembler binutils : asLinker-- binutils : ldLibrary glibcDebugger-- gdb
Department of Computer Science and Information EngineeringNational Cheng Kung University 9HANEL
Tool chains
gcc - GNU Compiler Collection
gcc is a full-featured ANSI C compiler with support for C, C++, Objective C, Java, and FortranGCC provides many levels of source code error checking , produces debugging information, and can perform many different optimizations to the resulting object code
Department of Computer Science and Information EngineeringNational Cheng Kung University 10HANEL
Tool chains
gcc - GNU Compiler Collection
The GNU Compiler for Java is now integrated and supported: GCJ can compile Java source or Java bytecodesto either native code or Java class filesGCC now supports the Intel IA-64 processor, so completely free software systems will be able to run on the IA-64 architecture as soon as it is released.
Department of Computer Science and Information EngineeringNational Cheng Kung University 11HANEL
Tool chains
GNU Binutils
Binutils are a collection of binary tools like assembler, linker, disassembler .Binutils is to create and manipulate binary executable files.The main tools for Binutils
ld - the GNU linker.as - the GNU assembler.
Department of Computer Science and Information EngineeringNational Cheng Kung University 12HANEL
Tool chains
GNU C Library
Any Unix-like operating system needs a C library ( defines the system calls'' and other basic facilities such as open, malloc, printf, exit... )The GNU C library is used as the C library in the GNU system and most systems with the Linux kernel.The GNU C library is a large blob of glue code, which tries to give it's best to hide kernel specific functions from you. (e.g. You can use the same function name and do not care the difference between different kernel )
Department of Computer Science and Information EngineeringNational Cheng Kung University 13HANEL
Tool chains
What is GDB
GDB : The GNU Project DebuggerAllows you to see what is going on `inside' another program while it executes Allows you to see what another program was doing at the moment it crashedGDB can run on most popular UNIX and Microsoft Windows variants.
Department of Computer Science and Information EngineeringNational Cheng Kung University 14HANEL
Tool chains
GDB
Supported LanguagesCC++PascalObjective-CMany other languages
Department of Computer Science and Information EngineeringNational Cheng Kung University 15HANEL
BootloaderBootloader is mainly responsible for loading the kernel, it is an very important componentMany bootloaders can be used with Linux on various hardware
LOIOGRUBLinuxBIOSRedbootU-boot
Department of Computer Science and Information EngineeringNational Cheng Kung University 16HANEL
Bootloader
Department of Computer Science and Information EngineeringNational Cheng Kung University 17HANEL
BootloaderThe simple code will be execute after you power on your target ( Sometimes we call it boot monitor )Embedded System bootloader should do:1. Initialize Hardware: processor and memory2. Loading kernel image and execute kernel
(sometimes it need to transfer parameter to linux kernel)
Department of Computer Science and Information EngineeringNational Cheng Kung University 18HANEL
Bootloader
Department of Computer Science and Information EngineeringNational Cheng Kung University 19HANEL
Bootloader
reset;;Reset Code;(in assembly)Jmp hw_init
Hw_init;Hardware;Initialization;(in assembly).Jmp startup
Startup;;startup code;(in assembly)Call main
NoOS/OS Code
Main(){/*The C/C++ program start here*/}
Boot Loader
Department of Computer Science and Information EngineeringNational Cheng Kung University 20HANEL
Bootloader
Part1Jump 0x00900000
Part2Initialize the actual hardwareSet cpu mode
Part3Disable all interruptsCopy any initialized data from ROM to RAMZero the uninitialized data areaAllocation space for and initialize the stackInitialize the processors stack pointerCreate and initialize the heapExecute the constructors and initializers for all global variables (C++)Enable interruptsCall main
Part4Program C/C++ code
Department of Computer Science and Information EngineeringNational Cheng Kung University 21HANEL
Bootloader
Department of Computer Science and Information EngineeringNational Cheng Kung University 22HANEL
Building Linux kernel
Three different host/target architectures are available for the development of embedded Linux systems:
Linked setupRemovable storage setupStandalone setup
Your actual setup may belong to more than one category or may even change categories over time, depending on your requirements and development methodology
Department of Computer Science and Information EngineeringNational Cheng Kung University 23HANEL
Building Linux kernel
Linked Setup
The target and the host are permanently linked together using a physical cable
This link is typically a serial cable or an Ethernet linkAll transfers occur via the link
*Cross-platform development environment
Host
*Bootloader
*Kernel
*Root filesystem
Target
Department of Computer Science and Information EngineeringNational Cheng Kung University 24HANEL
Building Linux kernel
Linked Setup(cont)
The kernel could be available via Trivial File Transfer Protocol (TFTP)The root filesystem could also be NFS mounted instead of being on a storage media in the target
Using an NFS-mounted root filesystem is actually perfect during development, because it avoids having to constantly copy program modifications between the host and the target
The physical link can also be used for debugging purposes
Many embedded systems provide both Ethernet and RS232 link capabilities
Department of Computer Science and Information EngineeringNational Cheng Kung University 25HANEL
Building Linux kernel
Removable Storage Setup
A storage device is written by the host, is then transferred into the target, and is used to boot the device
*Cross-platform development environment
Host
*Bootloader
Target
*Secondary bootloader
*Kernel
*Root filesystem
Department of Computer Science and Information EngineeringNational Cheng Kung University 26HANEL
Building Linux kernel
Removable Storage Setup
(cont)
The target contains only a minimal bootloader
The rest of the components are stored on a removable storage media, such as a CompactFlash IDE device or any other type of drive
Instead of a fixed flash chip, the target could contain a socket where a flash chip could be easily inserted and removed
The chip would be programmed by a flash programmer on the host and inserted into the socket in the target for normal operation
Department of Computer Science and Information EngineeringNational Cheng Kung University 27HANEL
Building Linux kernel
Removable Storage Setup
(cont)
This setup is mostly popular during the initial phases of embedded system development
You may find it more practical to move on to a linked setup once the initial development phase is over
you can avoid the need to physically transfer a storage device between the target and the host every time a change has to be made to the kernel or the root filesystem
Department of Computer Science and Information EngineeringNational Cheng Kung University 28HANEL
Building Linux kernel
Standalone Setup
The target is a self-contained development system and includes all the required software to boot, operate, and develop additional software
This setup is similar to an actual workstation, except the underlying hardware is not a conventional workstation but rather the embedded system itself
*Bootloader*Kernel*Full root filesystem*Native development environment
Target
Department of Computer Science and Information EngineeringNational Cheng Kung University 29HANEL
Building Linux kernel
Standalone Setup(cont)
This type of setup is quite popular with developers building high-end PC-based embedded systems, such as high-availability systems
They can use standard off-the-shelf Linux distributions on the embedded systemOnce development is done, they then work at trimming down the distribution and customizing it for their purposes
This gets developers around having to build their own root filesystems and configure the systems' startup
It requires that they know the particular distribution they are using inside out
Department of Computer Science and Information EngineeringNational Cheng Kung University 30HANEL
Building Linux kernel
There are some broad characteristics expected from the hardware to run a Linux system:
1. Linux requires at least a 32-bit CPU containing a memory management unit (MMU)
2. a sufficient amount of RAM must be available to accommodate the system.
3. minimal I/O capabilities are required if any development is to be carried out on the target with reasonable debugging facilities.
Department of Computer Science and Information EngineeringNational Cheng Kung University 31HANEL
Building Linux kernel
There are three different setups used to bootstrap an embedded Linux system:
Solid state storage mediaDiskNetwork
Department of Computer Science and Information EngineeringNational Cheng Kung University 32HANEL
Building Linux kernel
Solid state storage media
Bootloader
Boot parameter
Kernel Root file system
Department of Computer Science and Information EngineeringNational Cheng Kung University 33HANEL
Building Linux kernel
Disk
Department of Computer Science and Information EngineeringNational Cheng Kung University 34HANEL
Building Linux kernel
Department of Computer Science and Information EngineeringNational Cheng Kung University 35HANEL
Building Linux kernel
Networkthe kernel resides on a solid state storage media or a disk, and the root filesystem is mounted via NFSonly the bootloader resides on a local storage media. The kernel is then downloaded via TFTP, and the root filesystem is mounted via NFS
Department of Computer Science and Information EngineeringNational Cheng Kung University 36HANEL
Building Linux kernel
Hardware
Kernel LevelHardware Level
Hardware control (HAL)
Linux
device drivers
character block
buffer cache
file subsystem
System Call InterfaceKernel Level
User Level
Libraries
User program s
IPC
Scheduler
M em ory m anagem ent
Department of Computer Science and Information EngineeringNational Cheng Kung University 37HANEL
Device Driver
Department of Computer Science and Information EngineeringNational Cheng Kung University 38HANEL
Device driverClasses of Devices and Modules
Character devicesBlock devicesNetwork interfaces
Department of Computer Science and Information EngineeringNational Cheng Kung University 39HANEL
Device driver
Character devices
A character (char) device is one that can be accessed as a stream of bytes (like a file)Driver usually implements at least the open, close, read, and write system calls.The text console (/dev/console) and the serial ports (/dev/ttyS0) are examples of char devices.char devices are just data channels, which you can only access sequentially.
Department of Computer Science and Information EngineeringNational Cheng Kung University 40HANEL
Device driver
Block devices
Like char devices, block devices are accessed by filesystem nodes in the /dev directory. A block device is something that can host a filesystem, such as a disk.
Department of Computer Science and Information EngineeringNational Cheng Kung University 41HANEL
Device driver
Network interfaces
Any network transaction is made through an interface, that is, a device that is able to exchange data with other hosts.Network interface was look as a QueueThe Unix way to provide access to interfaces is still by assigning a unique name to them (such as eth0).
Department of Computer Science and Information EngineeringNational Cheng Kung University 42HANEL
Hello World
Department of Computer Science and Information EngineeringNational Cheng Kung University 43HANEL
Kernel module vs
Application
Whereas an application performs a single task from beginning to end, a module registers itself in order to serve future requests, and its main function terminates immediately.
the task of the function init_module(the modules entry point) is to prepare for later invocation of the modules functions.The second entry point of a module, cleanup_module, gets invoked just before the module is unloaded.
Department of Computer Science and Information EngineeringNational Cheng Kung University 44HANEL
Department of Computer Science and Information EngineeringNational Cheng Kung University 45HANEL
Init_module()Init_module()for each facility, there is a specific kernel function that accomplishes this registration. The arguments passed to the kernel registration functions are usually a pointer to a data structure describing the new facility and the name of the facility being registered.
Department of Computer Science and Information EngineeringNational Cheng Kung University 46HANEL
cleanup_module
cleanup_module()To unload a module, use the rmmodcommand. Its task is much simpler thanloading, since no linking has to be performed. The command invokes the delete_module system call, which calls cleanup_module in the module itself if the usage count is zero or returns an error otherwise.
Department of Computer Science and Information EngineeringNational Cheng Kung University 47HANEL
I/O RegionsThe job of a typical driver is, for the most part, writing and reading I/O ports and I/O memory. Access to I/O ports and I/O memory (collectively called I/O regions) happens both at initialization time and during normal operations.
Department of Computer Science and Information EngineeringNational Cheng Kung University 48HANEL
I/O Port
A typical /proc/ioports file on a recent PC that is running version 2.4 of the kernel will look like the following:0000-001f : dma10020-003f : pic10040-005f : timer0060-006f : keyboard0080-008f : dma page reg00a0-00bf : pic200c0-00df : dma200f0-00ff : fpu0170-0177 : ide101f0-01f7 : ide002f8-02ff : serial(set)0300-031f : NE20000376-0376 : ide103c0-03df : vga+03f6-03f6 : ide003f8-03ff : serial(set)1000-103f : Intel Corporation 82371AB PIIX4 ACPI1000-1003 : acpi1004-1005 : acpi1008-100b : acpi100c-100f : acpi1100-110f : Intel Corporation 82371AB PIIX4 IDE1300-131f : pcnet_cs1400-141f : Intel Corporation 82371AB PIIX4 ACPI1800-18ff : PCI CardBus #021c00-1cff : PCI CardBus #045800-581f : Intel Corporation 82371AB PIIX4 USBd000-dfff : PCI Bus #01d000-d0ff : ATI Technologies Inc 3D Rage LT Pro AGP-133
Department of Computer Science and Information EngineeringNational Cheng Kung University 49HANEL
I/O MemoryI/O memory information is available in the /proc/iomem file.
Department of Computer Science and Information EngineeringNational Cheng Kung University 50HANEL
Chars DriversMajor and Minor NumbersSpecial files for char drivers are Major and Minor Numbers identified by a cin the first column of the output of ls l. Block devices appear in /dev as well, but they are identified by a b.Use ls l /dev commend to check.
Department of Computer Science and Information EngineeringNational Cheng Kung University 51HANEL
Chars DriversThe kernel uses the major number at open time to dispatch execution to the appropriate driverThe minor number is used only by the driver specified by the major number
mknod /dev/scull0 c 254 0
creates a char device (c) whose major number is 254 and whose minor number is 0.
Department of Computer Science and Information EngineeringNational Cheng Kung University 52HANEL
GUIQT & QT EmbeddedDirectFB
Department of Computer Science and Information EngineeringNational Cheng Kung University 53HANEL
GUI
QT & QT Embedded
Qt is a C++ class library for writing GUI applications that run on UNIX, Windows 95/98, and Windows NT platforms Qt/Embedded, the embedded Linux port of Qt, is a complete and self-contained C++ GUI and platform development tool for Linux-based embedded development.
Department of Computer Science and Information EngineeringNational Cheng Kung University 54HANEL
GUI
QT & QT Embedded
Department of Computer Science and Information EngineeringNational Cheng Kung University 55HANEL
GUI
DirectFB
Department of Computer Science and Information EngineeringNational Cheng Kung University 56HANEL
GUI
DirectFB
Embedded Linux on ARMOUTLINETool chainsTool chainsTool chainsThe role of toolchainTool chainsCompile flow chartTool chains Why using the GNU Tool-chainTool chainsTool chainsgcc - GNU Compiler CollectionTool chainsgcc - GNU Compiler CollectionTool chainsGNU BinutilsTool chains GNU C LibraryTool chains What is GDBTool chainsGDBBootloaderBootloaderBootloaderBootloaderBootloaderBootloaderBootloaderBuilding Linux kernelBuilding Linux kernel Linked SetupBuilding Linux kernel Linked Setup(cont)Building Linux kernel Removable Storage SetupBuilding Linux kernel Removable Storage Setup(cont)Building Linux kernel Removable Storage Setup(cont)Building Linux kernel Standalone SetupBuilding Linux kernel Standalone Setup(cont)Building Linux kernelBuilding Linux kernelBuilding Linux kernelBuilding Linux kernelBuilding Linux kernelBuilding Linux kernelBuilding Linux kernelDevice DriverDevice driverDevice driver Character devicesDevice driver Block devicesDevice driver Network interfacesHello WorldKernel module vs ApplicationInit_module()cleanup_moduleI/O RegionsI/O PortI/O MemoryChars DriversChars DriversGUIGUI QT & QT EmbeddedGUI QT & QT EmbeddedGUIDirectFBGUIDirectFB
Top Related