embedded linux on a r m

56
Home Automation, Networking, and Entertainment Lab Dept. of Computer Science and Information Engineering National Cheng Kung University Chia Che Lee 李嘉哲 Embedded Linux on ARM

Upload: emanuele-bonanni

Post on 22-May-2015

8.046 views

Category:

Technology


3 download

TRANSCRIPT

  • 1. Embedded Linux on ARMChia Che LeeHome Automation, Networking, and Entertainment Lab Dept. of Computer Science and Information Engineering National Cheng Kung University

2. Tool chains OUTLINEBootloaderBuilding Linux kernelLinux device driverGUI Department of Computer Science and Information Engineering HANEL National Cheng Kung University 2 3. A collection of tools used to develop for Tool chains 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 some other 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 EngineeringHANEL National Cheng Kung University 3 4. The Advantage of understanding Tool chains 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-chainDepartment of Computer Science and Information EngineeringHANEL National Cheng Kung University 4 5. Tool chains The role of toolchain Department of Computer Science and Information Engineering HANEL National Cheng Kung University 5 6. SourceSourceSource Tool chainscodecodecode Compile flow compilercompilercompilerchart AssemblyAssemblyAssemblycodecodecode AssemblerAssemblerAssemblerobjectobjectobjectcodecodecodeExecutablLibrariesLinker e code codeDepartment of Computer Science and Information EngineeringHANEL National Cheng Kung University 6 7. GNU is a complete, Unix-like operating Tool chains system that has been in developmentWhy using thefor just over twenty years GNU Tool-chainGNU software is known for it's stability and standard compliance GNU tool-chain is open source which be easy to modifyDepartment of Computer Science and Information Engineering HANELNational Cheng Kung University 7 8. The GNU toolchain consists : Tool chains Compiler gcc Assembler binutils : as Linker-- binutils : ld Library glibc Debugger-- gdbDepartment of Computer Science and Information EngineeringHANEL National Cheng Kung University 8 9. gcc is a full-featured ANSI C compiler Tool chains with support for C, C++, Objective C,gcc - GNUJava, and Fortran CompilerCollection GCC provides many levels of source code error checking , produces debugging information, and can perform many different optimizations to the resulting object codeDepartment of Computer Science and Information EngineeringHANEL National Cheng Kung University 9 10. The GNU Compiler for Java is now Tool chains integrated and supported: GCJ cangcc - GNUcompile Java source or Java bytecodes Compilerto either native code or Java class filesCollection GCC 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 EngineeringHANEL National Cheng Kung University 10 11. Binutils are a collection of binary tools Tool chains like assembler, linker, disassembler . GNU BinutilsBinutils 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 EngineeringHANEL National Cheng Kung University 11 12. Any Unix-like operating system needs a Tool chainsC library ( defines the system calls'' GNU C Libraryand other basic facilities such as open,malloc, printf, exit... )The GNU C library is used as the Clibrary in the GNU system and mostsystems with the Linux kernel.The GNU C library is a large blob ofglue code, which tries to give it's bestto hide kernel specific functions fromyou. (e.g. You can use the samefunction name and do not care thedifference between different kernel )Department of Computer Science and Information Engineering HANEL National Cheng Kung University 12 13. Tool chains GDB : The GNU Project Debugger What is GDB Allows 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 crashed GDB can run on most popular UNIX and Microsoft Windows variants. Department of Computer Science and Information EngineeringHANEL National Cheng Kung University 13 14. Supported Languages Tool chains CGDBC++ Pascal Objective-C Many other languagesDepartment of Computer Science and Information EngineeringHANEL National Cheng Kung University 14 15. Bootloader is mainly responsible for Bootloaderloading the kernel, it is an veryimportant componentMany bootloaders can be used withLinux on various hardwareLOIOGRUBLinuxBIOSRedbootU-bootDepartment of Computer Science and Information Engineering HANEL National Cheng Kung University 15 16. Bootloader Department of Computer Science and Information Engineering HANEL National Cheng Kung University 16 17. The simple code will be execute after Bootloaderyou power on your target ( Sometimeswe call it boot monitor )Embedded System bootloader shoulddo: 1. Initialize Hardware: processor and memory 2. Loading kernel image and execute kernel(sometimes it need to transfer parameterto linux kernel) Department of Computer Science and Information Engineering HANEL National Cheng Kung University 17 18. Bootloader Department of Computer Science and Information Engineering HANEL National Cheng Kung University 18 19. BootloaderBoot Loaderreset;;Reset Code;(in assembly)Jmp hw_init Hw_init;Hardware Main();Initialization {;(in assembly)/*The C/C++ program start here*/.}Jmp startupStartup;;startup code NoOS/OS Code;(in assembly)Call mainDepartment of Computer Science and Information Engineering HANEL National Cheng Kung University19 20. Part1 Jump 0x00900000 Bootloader Part2 Initialize the actual hardware Set cpu modePart3 Disable all interrupts Copy any initialized data from ROM to RAM Zero the uninitialized data area Allocation space for and initialize the stack Initialize the processors stack pointer Create and initialize the heap Execute the constructors and initializers for all global variables (C++) Enable interrupts Call mainPart4 Program C/C++ code Department of Computer Science and Information Engineering HANEL National Cheng Kung University 20 21. Bootloader Department of Computer Science and Information Engineering HANEL National Cheng Kung University 21 22. Three different host/target Building Linux kernel architectures are available for the development of embedded Linux systems: Linked setup Removable storage setup Standalone 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 Engineering HANELNational Cheng Kung University 22 23. The target and the host are Building Linux kernel permanently linked together using a physical cable Linked SetupThis link is typically a serial cable or an Ethernet link All transfers occur via the linkHostTarget *Cross-platform*Bootloader development*Kernel environment*Root filesystemDepartment of Computer Science and Information Engineering HANELNational Cheng Kung University 23 24. The kernel could be available via Trivial Building LinuxFile Transfer Protocol (TFTP) kernel The root filesystem could also be NFS Linked Setupmounted instead of being on a storage (cont) 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 EngineeringHANEL National Cheng Kung University 24 25. A storage device is written by the host, Building Linux kernel is then transferred into the target, and is used to boot the deviceRemovable Storage Setup Host Target *Cross-platform development *Bootloader environment *Secondary bootloader *Kernel *Root filesystem Department of Computer Science and Information Engineering HANELNational Cheng Kung University 25 26. The target contains only a minimal Building Linuxbootloader kernel The rest of the components are stored on aRemovableremovable storage media, such as a Storage Setup CompactFlash IDE device or any other type (cont) 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 operationDepartment of Computer Science and Information EngineeringHANEL National Cheng Kung University 26 27. This setup is mostly popular during the Building Linux kernel initial phases of embedded system developmentRemovableYou may find it more practical to move on Storage Setup to a linked setup once the initial (cont) 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 filesystemDepartment of Computer Science and Information EngineeringHANEL National Cheng Kung University 27 28. The target is a self-contained Building Linux kernel development system and includes all the required software to boot, operate,Standalone and develop additional software Setup This setup is similar to an actual workstation, except the underlying hardware is not a conventional workstation but rather the embedded system itself Target *Bootloader *Kernel *Full root filesystem *Native development environment Department of Computer Science and Information Engineering HANELNational Cheng Kung University 28 29. This type of setup is quite popular with Building Linuxdevelopers building high-end PC-based kernel embedded systems, such as high-Standalone availability systems Setup They can use standard off-the-shelf Linux (cont) distributions on the embedded system Once 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 outDepartment of Computer Science and Information EngineeringHANEL National Cheng Kung University 29 30. There are some broad characteristics Building Linux kernel 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 Engineering HANELNational Cheng Kung University 30 31. There are three different setups used Building Linux kernel to bootstrap an embedded Linux system: Solid state storage media Disk NetworkDepartment of Computer Science and Information Engineering HANELNational Cheng Kung University 31 32. Solid state storage media Building Linux kernelBootparameter Kernel Root file systemBootloaderDepartment of Computer Science and Information Engineering HANELNational Cheng Kung University 32 33. Building Linux Disk kernelDepartment of Computer Science and Information Engineering HANELNational Cheng Kung University 33 34. Building Linux kernelDepartment of Computer Science and Information Engineering HANELNational Cheng Kung University 34 35. Network Building Linux kernelthe kernel resides on a solid state storage media or a disk, and the root filesystem is mounted via NFS only the bootloader resides on a local storage media. The kernel is then downloaded via TFTP, and the root filesystem is mounted via NFSDepartment of Computer Science and Information Engineering HANELNational Cheng Kung University 35 36. U ser program s Building Linux kernel L ibraries U ser LevelK ernel L evelSystem C all Interface file subsystem IPC bufferSchedulercacheL inux M em ory m anagem ent characterblock device drivers H ardw are control (H A L )K ernel LevelH ardw are LevelDepartment of Computer Science and Information Engineering HANELH ardw areNational Cheng Kung University36 37. Device Driver Department of Computer Science and Information Engineering HANEL National Cheng Kung University 37 38. Classes of Devices and Modules Device driverCharacter devicesBlock devicesNetwork interfaces Department of Computer Science and Information Engineering HANEL National Cheng Kung University 38 39. A character (char) device is one that Device driver can be accessed as a stream of bytes Character devices (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 Engineering HANEL National Cheng Kung University 39 40. Like char devices, block devices are Device driveraccessed by filesystem nodes in the Block devices/dev directory. A block device issomething that can host a filesystem,such as a disk. Department of Computer Science and Information Engineering HANEL National Cheng Kung University 40 41. Any network transaction is made Device driverthrough an interface, that is, a deviceNetwork that is able to exchange data with interfacesother hosts.Network interface was look as a QueueThe Unix way to provide access tointerfaces is still by assigning a uniquename to them (such as eth0). Department of Computer Science and Information Engineering HANEL National Cheng Kung University 41 42. Hello World Department of Computer Science and Information Engineering HANEL National Cheng Kung University 42 43. Whereas an application performs a Kernel module single task from beginning to end, a vsmodule registers itself in order to serveApplication 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 EngineeringHANELNational Cheng Kung University 43 44. Department of Computer Science and Information Engineering HANEL National Cheng Kung University 44 45. Init_module() Init_module()for each facility, there is a specifickernel function that accomplishes thisregistration. The arguments passed tothe kernel registration functions areusually a pointer to a data structuredescribing the new facility and thename of the facility being registered. Department of Computer Science and Information EngineeringHANELNational Cheng Kung University 45 46. cleanup_module() cleanup_modu leTo unload a module, use the rmmod command. Its task is much simpler than loading, 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 EngineeringHANEL National Cheng Kung University 46 47. The job of a typical driver is, for the I/O Regionsmost part, writing and reading I/Oports and I/O memory.Access to I/O ports and I/O memory(collectively called I/O regions)happens both at initialization time andduring normal operations. Department of Computer Science and Information Engineering HANEL National Cheng Kung University 47 48. A typical /proc/ioports file on a recent PC that is runningversion 2.4 of the kernel will look like the following:0000-001f : dma1 I/O Port 0020-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-133Department of Computer Science and Information EngineeringHANEL National Cheng Kung University48 49. I/O memory information is available in I/O Memorythe /proc/iomem file. Department of Computer Science and Information Engineering HANEL National Cheng Kung University 49 50. Major and Minor Numbers Chars Drivers Special files for char drivers are Major and Minor Numbers identified by a c in 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 Engineering HANEL National Cheng Kung University 50 51. The kernel uses the major number at Chars Drivers open time to dispatch execution to the appropriate driver The minor number is used only by the driver specified by the major numbermknod /dev/scull0 c 254 0creates a char device (c) whose major number is 254 and whose minor number is 0.Department of Computer Science and Information Engineering HANEL National Cheng Kung University 51 52. QT & QT Embedded GUIDirectFB Department of Computer Science and Information Engineering HANEL National Cheng Kung University 52 53. Qt is a C++ class library for writing GUI GUI applications that run on UNIX, WindowsQT & QT95/98, and Windows NT platforms EmbeddedQt/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 EngineeringHANEL National Cheng Kung University 53 54. GUI QT & QT EmbeddedDepartment of Computer Science and Information EngineeringHANEL National Cheng Kung University 54 55. GUIDirectFBDepartment of Computer Science and Information EngineeringHANEL National Cheng Kung University 55 56. GUIDirectFBDepartment of Computer Science and Information EngineeringHANEL National Cheng Kung University 56