Скачать презентацию Special Topics in Embedded System HW SW Design Korea Скачать презентацию Special Topics in Embedded System HW SW Design Korea

a0d65f1e71e3ffa09090c25ee89fd286.ppt

  • Количество слайдов: 145

Special Topics in Embedded System (HW/SW Design) Korea University of Technology & Education Dept. Special Topics in Embedded System (HW/SW Design) Korea University of Technology & Education Dept. of Computer Engineering Kyung-Sik Jang Korea University of Technology & Education

About This Course l Teaching schedule – Feb. 16 ~ 18, Every 09: 00 About This Course l Teaching schedule – Feb. 16 ~ 18, Every 09: 00 ~ 12: 00 – 9 hours – 50 min. lecture & 10 min. break l Prerequisite Knowledges – Basic understanding about Micro-processor – C programming skill – Operating system : Linux – Computer architecture Korea University of Technology & Education

Agenda l l l l l Introduction to Embedded System Embedded Platform ARM Processor Agenda l l l l l Introduction to Embedded System Embedded Platform ARM Processor Linux System Development (ARM+Linux) Bootloader Kernel Configuration File System (Ramdisk) Module Programming Device Driver Korea University of Technology & Education

Introduction to Embedded System Korea University of Technology & Education Introduction to Embedded System Korea University of Technology & Education

What’s Embedded System ? l All kinds of digital systems embedding microprocessor – performing What’s Embedded System ? l All kinds of digital systems embedding microprocessor – performing the functions specific to an application – opimized to the specific design goal l Comparison with the conventional system – Stand-alone computer vs. Computer embedded in Product – General Purpose Computer vs. Special Purpose Computer Korea University of Technology & Education

Why Embedded System ? l Design paradigm has changed H/W-Only (ASIC) High performance Flexibilty Why Embedded System ? l Design paradigm has changed H/W-Only (ASIC) High performance Flexibilty HW-SW Co-design S/W-Only Standalone (Firmware) OS Mounted Complicated Function Multitasking various types of networking Efficient HW resource management Korea University of Technology & Education

What’s your choice ? For intelligent light controller ? l For MP 3 player What’s your choice ? For intelligent light controller ? l For MP 3 player ? l For game machine such Nintendo DS ? l Fully-HW ? Fully-SW ? it’s natural ! SW + HW something special ? Embedded System Design Issues & Design Considerations Korea University of Technology & Education

Design Aspects of Embedded System l Design goal – High performance : realtime – Design Aspects of Embedded System l Design goal – High performance : realtime – Flexibility : easy to modify & upgrade l Design methodology – A co-design of hardware and software to perform the specific function l Difficulty – Not easy to co-design HW & SW – Requires high-level design expertises Korea University of Technology & Education

Design Considerations - 1 l Resource limitation – Constrained memory usage – Software customization Design Considerations - 1 l Resource limitation – Constrained memory usage – Software customization : reduction of code size, high performance coding l Portability – Small-sized : small packages – Battery operated : low power consumption Korea University of Technology & Education

Design Considerations - 2 l Short life-cycle of product – Easy to upgrade : Design Considerations - 2 l Short life-cycle of product – Easy to upgrade : flexible system l Low cost – Low material cost : survey on available chips, maintain supply-chain – Low design cost : design automation Design goal of : Trade-offs between design considerations Korea University of Technology & Education

Construction of Embedded System l Hardware components – Processor – Peripheral devices – Embedded Construction of Embedded System l Hardware components – Processor – Peripheral devices – Embedded hardware platform = Processor + Peripherals l Software components – System software – Middle-ware – Application software l Development tools Korea University of Technology & Education

HW Components - 1 l Processor – Micro processing unit (MPU) Computation-bound – Micro HW Components - 1 l Processor – Micro processing unit (MPU) Computation-bound – Micro controller unit (MCU) ü Control-bound – Digital signal processor (DSP) ü Audio, Video, – Application specific processor (ASP) : ü Java processor ü network processor ü crypto processor ü reconfigurable processor ü Korea University of Technology & Education

HW Components - 2 l Peripheral devices – perform a special I/O function or HW Components - 2 l Peripheral devices – perform a special I/O function or data processing task in order to speed up overall system’s throughput & reduce CPU’s load l ASSP device – Off-the-shelf product – network controller, video codec, USB controller, etc l ASIC device – Self-developed, field-programmed – High-cost & high-speed – fully customized Korea University of Technology & Education

SW Components l Software components – System software Operating system ü Device driver – SW Components l Software components – System software Operating system ü Device driver – Middle-ware ü Application specific libraries ü Multimedia, Java, etc – Application software ü What you want to do ü Korea University of Technology & Education

Development Tools l SW Development tools – Compiler, linker, debugger, std. library, – In-system Development Tools l SW Development tools – Compiler, linker, debugger, std. library, – In-system programmer l HW development tools – PCB artwork & analysis : thermal, vibration, fatigue life, convective air flow, stress, harness l Commercial vs. Free-ware – Development cost – Technical support – Continuous maintenance – Reliability Korea University of Technology & Education

Theoretical Flow of Co-Design System Specification Automated Design System Description Language Cost function Design Theoretical Flow of Co-Design System Specification Automated Design System Description Language Cost function Design Cost Prediction Partition & Design Space Exploration Design condition & constraints Hardware Description Language High-level Programming Language Hardware Synthesis Compilation RTL description Machine code Co-simulation Co-verification ASIC So. C, So. B Korea University of Technology & Education NV memory (Code) u. P + Memory + I/O’s

Practical Flow of Co-Design Specification Designer’s Expertise & Intuition Partition SW Micro-Processor Selection Manual Practical Flow of Co-Design Specification Designer’s Expertise & Intuition Partition SW Micro-Processor Selection Manual Design HW Bootloader/Startup OS-mount Peripheral Devices Selection (ASIC/ASSP) OS Kernel Customization HW Platform Design Device Driver Application Korea University of Technology & Education Standalone Application

Embedded Platform Korea University of Technology & Education Embedded Platform Korea University of Technology & Education

Embedded Platform l The base platform in which HW and SW components are integrated Embedded Platform l The base platform in which HW and SW components are integrated into more than one board l Self-developed or ready-made Korea University of Technology & Education

Hardware Platform Design – 1 l Embedded processor selection – Processor type : MPU, Hardware Platform Design – 1 l Embedded processor selection – Processor type : MPU, MCU, DSP, ASIP – Instruction set architecture : RISC, CISC – Processor architecture Von Neumann, Harvard ü DSP-feature : Dual-memory access, MAC, Floatingpoint – Memory : Flash, DRAM/SRAM ü Korea University of Technology & Education

Hardware Platform Design – 2 l Application specific peripheral devices – On-chip : integrated Hardware Platform Design – 2 l Application specific peripheral devices – On-chip : integrated in processor – Off-chip ü ü Rapid prototyping : EPLD, FPGA ASSP : Ethernet, USB, PCMCIA, LCD, Audio codec, Touch-screen. Korea University of Technology & Education

Hardware Platform Design – 3 l Hardware implementation – System-on-Board (So. B) : On-PCB Hardware Platform Design – 3 l Hardware implementation – System-on-Board (So. B) : On-PCB – System-on-Chip (So. C) : One-Chip I/O ROM I/O RAM Micro-processor So. B/So. C Korea University of Technology & Education

Embedded Processor l Intel – x 86 (386, 486, Pentium) l ARM – ARM Embedded Processor l Intel – x 86 (386, 486, Pentium) l ARM – ARM 7, ARM 9, Strong. ARM, ARM 10, ARM 11 l Motorola – Power. PC, 68 K / Cold. Fire, Mcore, Dragon Ball l MIPS Technologies – MIPS 32 4 K, 5 K l Hitachi – Super-H (SH-1, SH-2, SH-3, SH-4, SH-5) l Texas Instrument – TMS 320 (DSP), TMS 370 / MSP 430 (MCU) Korea University of Technology & Education

Embedded Software Design - 1 l Prepare boot-up program – Initialize hardwares : POST, Embedded Software Design - 1 l Prepare boot-up program – Initialize hardwares : POST, setup parameters – Boot operating system l Select operation system – customize OS kernel l Setup the development environment – Tool chain : Compiler / Debugger / In-circuit programmer – Processor-dependent l Develop device drivers if need – depends on OS & the types of peripheral devices – Read-made or self-developed Korea University of Technology & Education

Embedded Software Design - 2 l Check Libraries, APIs – Middle ware Functional libraries Embedded Software Design - 2 l Check Libraries, APIs – Middle ware Functional libraries for the specific application domain ü Support application software development – Human interface : CLI (command-line interface) or GUI ü l Program Application Software – Handheld devices : PDA, Cellular/Smart phone, MP 3 Player, – – – PMP, Game console Internet appliances, Factory automation, Office automation Automotive appliance : Car navigation, ECU Ubiquitous, wearable computing Sensor network – Korea University of Technology & Education

Embedded Operating System - 1 l Needs for OS – Multitasking – High-functionalities ü Embedded Operating System - 1 l Needs for OS – Multitasking – High-functionalities ü ü ü Networking & support multimedia Limitation of sequential programming Support & manage various types of i/o devices – Rapid development and Maintenance ü ü Easy to modify & download SW for changing new requirements from user & market Provide new creative & high-quality solutions in time Korea University of Technology & Education

Embedded Operating System - 2 l Linux Window CE Embedded Vx. Works / p. Embedded Operating System - 2 l Linux Window CE Embedded Vx. Works / p. SOS : real-time OS Palm. OS : PDA Net. BSD : used widely for comm. system e. COS : open source. Non-linux l Commercial vs. Free l l l – License policy Korea University of Technology & Education

ARM + Linux Platform l Most widely used embedded platform – Processor : ARM ARM + Linux Platform l Most widely used embedded platform – Processor : ARM processor – OS : Linux l Sample platforms – Assabet : Intel SA-1110 evaluation board – LART (Linux Advanced Radio Terminal) : Delft – – Univ. of Tech. (Netherlands) PLEB : Univ. of New South Wales (Australia) Itsy : DEC (Compaq) Western Research Lab Net. Winder : Corel Computer Others Korea University of Technology & Education

ARM Processor - 1 l 32 -bit processor families from ARM Inc. – Low-power ARM Processor - 1 l 32 -bit processor families from ARM Inc. – Low-power / High-performance – The most widely used 32 -bit micro-processor l ARM : www. arm. com – ARM : Advanced RISC Machine – Established in 1990. 11 as joint venture (England) – Fund : Apple Computer, VLSI Technology – Technology : Acorn Computer Group – Provide IP (Intellectual Property) of ARM ISA Korea University of Technology & Education

ARM Processor - 2 Total Embedded Core Market : 627 Million Dollars SIA and ARM Processor - 2 Total Embedded Core Market : 627 Million Dollars SIA and Semico Research Corp, Q 1 2003 Korea University of Technology & Education

Linux – 1 l Linux overview – Started by Linus B. Torvals – A Linux – 1 l Linux overview – Started by Linus B. Torvals – A clone of UNIX – Free : Copyright Copyleft l Kernel release – First version : 0. 01, (1991) – www. kernel. org l Numbering Linux version – (major). (minor). (patch level) – Minor : Even : stable release ü Odd : development release – Latest stable version : 2. 6. 28 ü Korea University of Technology & Education

Linux – 2 l Strong point – Free : Open source, low design cost Linux – 2 l Strong point – Free : Open source, low design cost – Open architecture : support various processor – Large development people Short development time ü Easy to obtain device drivers – Stable : UNIX clone ü l Weak point – Difficult to design – Weak to GUI, Web brwosing, multimedia function Korea University of Technology & Education

ARM Processor Korea University of Technology & Education ARM Processor Korea University of Technology & Education

ARM Processor 32 -bit RISC processor l Load-store architecture l Fixed instruction length l ARM Processor 32 -bit RISC processor l Load-store architecture l Fixed instruction length l – 16 -bit : Thumb instructon set – 32 -bit : ARM instruction set Korea University of Technology & Education

ARM Core l ARM Core – the micro-architecture which can execute ARM instruction set ARM Core l ARM Core – the micro-architecture which can execute ARM instruction set architecture (ISA). – Its performance depends on the pipeline architecture & data -path structure. – Semiconductor foundry make its own ARM processors by adding memory and peripheral devices on ARM core such as Xscale (Intel), S 3 C 2410, S 3 C 2440 (Samsung), etc. l System core – ARM core + memory unit (buffer, cache, MMU, MPU) – Determine the structure & performance of ARM processor Korea University of Technology & Education

Types of ARM Core l Hard macrocell – Core in layout level, so any Types of ARM Core l Hard macrocell – Core in layout level, so any design change is not allowed. – Core size & supply voltage is fixed by ARM. – ARM 710 T, ARM 920 l Synthesizable core – HDL description of core in register-transfer-level. – Any change on core size or memory structure is allowed, but not for functionality – ARMT 7 TMDI-S, ARM 926 EJ-S, ARM 1136 J-S Korea University of Technology & Education

Roadmap of ARM Core 출처 : 임베디드 월드 Korea University of Technology & Education Roadmap of ARM Core 출처 : 임베디드 월드 Korea University of Technology & Education

ARM Instruction Set Architecture - 1 l Features of ARM ISA – All instructions ARM Instruction Set Architecture - 1 l Features of ARM ISA – All instructions are conditional – Shift & ALU by one instruction – Auto-increment & decremnet – Multiple registers read/write – 16 -bit instruction mode Korea University of Technology & Education

ARM Instruction Set Architecture - 2 ISA Thumb DSP Jazelle Media Trust. Zone Thumb ARM Instruction Set Architecture - 2 ISA Thumb DSP Jazelle Media Trust. Zone Thumb 2 v 4 T ○ v 5 TE ○ ○ v 5 TEJ ○ ○ ○ v 6 Z ○ ○ v 6 T 2 ○ ○ ○ T : Thumb E : DSP extension J : Java extension (Jazelle) Z : Trust. Zone, T 2 : Thumb-2, Blend 16 -/32 bit instruction. 25% faster than 16 -bit, 26% smaller than 32 -bit Korea University of Technology & Education 39

ARM Core List – 1 Core Cache(I/D ) TCM MMU MPU Thumb 7 TMDI ARM Core List – 1 Core Cache(I/D ) TCM MMU MPU Thumb 7 TMDI ○ DSP Jazelle ○ ○ ABI CLK ISA ○ ○ 7 EJ-S T-2 133 v 4 T ○ 133 v 5 TJ 720 T 8 K Uni ○ ○ ○ 100 v 4 T 920 T 16 K/16 K ○ ○ ○ 250 v 4 T 922 T 8 K/8 K ○ ○ ○ 250 v 4 T 940 T 4 K/4 K ○ ○ 180 v 4 T Dual 250 v 5 TEJ ○ 210 v 5 TE 250 v 5 TE 220 v 5 TE 325 v 5 TE 266 v 5 TE ○ 926 EJ-S 4~128 K ○ 946 E-S 0~1 M ○ ○ ○ ○ 966 E 968 E DMA 1020 E 32 K/32 K 1022 E 16 K/16 K 1026 EJ-S Variable ○ ○ ○ Korea University of Technology & Education ○ ○ ○ Dual 40

ARM Core List – 2 Core Cache(I/D ) TCM MMU 11 MP 16~64 K ARM Core List – 2 Core Cache(I/D ) TCM MMU 11 MP 16~64 K ○ ○ 1136 JF 4~64 k ○ ○ 1156 T 2 Variable ○ 1176 JZ 4~64 K ○ MPU ○ DSP Jazelle ABI CLK ISA ○ ○ ○ 2 x. AXI 550 v 6 ○ ○ Thumb ○ ○ 5 x. AHB 550 v 6 3 x. AXI 550 v 6 T 2 4 x. AXI 550 v 6 T 2 100 v 6 T 2 206 v 4 400 v 5 TE ○ T-2 ○ ○ Cortex ○ ○ ○ Strong. ARM 16 K/8 K ○ XScale 32 K/32 K ○ Korea University of Technology & Education ○ ○ ○ 41

ARM Core List – 3 * TCM : Tightly Coupled Memory * ABI : ARM Core List – 3 * TCM : Tightly Coupled Memory * ABI : AHB (AMBA Advanced High-performance Bus) Bus Interface. On-chip bus spec. for interconnection and management of function blocks for So. C. * TDMI : T(Thumb), D(Debug), M(Multiplier, 64 -bit result), I (In-circuit emulation interface) * Cortex : Thumb-2 ISA. 65 % faster interrupt handling. A-series (application), Rseries (Real-time), M-series (Microcontroller). 3 -stage pipeline, Harvard architecture. Accelerate the move from legacy 8 -/16 -bit architecture to 32 -bit * F : Vector floating point coprocessor * MP : multi-processor * E : DSP extension * S : Synthesizable core Korea University of Technology & Education 42

Core Architecture Example l Core architecture ARM 7 Architecture Strong. ARM 9 Von Neumann Core Architecture Example l Core architecture ARM 7 Architecture Strong. ARM 9 Von Neumann Harvard 3 -stage 5 -stage v 4 T Pipelining ISA l Pipeline stage Korea University of Technology & Education

ARM Operating Mode – 1 6 privileged modes + 1 user mode l Privileged ARM Operating Mode – 1 6 privileged modes + 1 user mode l Privileged mode l – System mode : run privileged operating system tasks – Supervisor mode : protected mode for operating system, – – entered by reset, software interrupt FIQ mode : entered by fast interrupt (FIQ), high-speed data transfer or channel process IRQ mode : entered by normal interrupt, general purpose interrupt handling Abort mode : entered by pre-fetch abort, data abort exception, virtual memory / memory protection, used to handle memory access violations. Undefined mode : entered by undefined instruction exception, used to handle undefined instructions. software emulation of hardware coprocessors Korea University of Technology & Education

ARM Operating Mode – 2 l User mode – Normal program execution mode. – ARM Operating Mode – 2 l User mode – Normal program execution mode. – Unable to access protected system resource, or change mode l Exception mode – Entered by hardware or software exception – Has banked register set (stack pointer, link register, status register) to minimize exception handling latency – Access system resource – Able to change operating mode, Korea University of Technology & Education

Processor Operating State l 2 operating states – ARM state, Thumb state l ARM Processor Operating State l 2 operating states – ARM state, Thumb state l ARM state – execute 32 -bit instruction set l Thumb state – execute 16 -bit instruction set l State transition – By special instruction (BX) – T-bit in program status registers Korea University of Technology & Education

ARM Register Set - 1 l 37 registers – 31 general purpose registers – ARM Register Set - 1 l 37 registers – 31 general purpose registers – 6 status registers l Only 16 registers of 31 GPRs are visible : R 0 ~ R 15 – R 13 : stack pointer – R 14 : link register, branch & link (BL) instruction – R 15 : program counter l Register banking – R 0 ~ R 7 : unbanked – Depends on operating mode ü ü R 8 ~ R 12 : banked only in FIQ mode R 13 ~R 14 : banked in exception mode Korea University of Technology & Education

ARM Register Set - 2 l Status register – CPSR (current program status register) ARM Register Set - 2 l Status register – CPSR (current program status register) – 5 SPSR (saved program status register) Korea University of Technology & Education

Register Map Korea University of Technology & Education Register Map Korea University of Technology & Education

Program Status Register Condition code : Negative (N), Zero (Z), Carry (C), Overflow (V) Program Status Register Condition code : Negative (N), Zero (Z), Carry (C), Overflow (V) I : IRQ disable F : FIQ disable T : Thumb mode M[4: 0] : operating mode, User (10000), FIQ (10001), IRQ (10010), Supervisor (10011), Abort (10111), Undefined (11011), System (11111) Korea University of Technology & Education

Exception – 1 l Reset – When reset input is asserted – Enter into Exception – 1 l Reset – When reset input is asserted – Enter into Supervisor mode l Data Abort – Data access memory abort – By accessing invalid address – Can be used by MMU or MPU to set MMU control register. l FIQ – By asserting external FIQ input – Interrupt which minimizes the interrupt processing time – Because the exception vector entry for FIQ handler is located at the highest address, the handler can be loaded directly at the exception vetor table entry without branching. – Additional banking of R 8~R 14. Korea University of Technology & Education

Exception – 2 l IRQ exception l Prefetch abort exception l Undefined exception – Exception – 2 l IRQ exception l Prefetch abort exception l Undefined exception – By asserting external IRQ input – Instruction fetch memory abort – Used to handle BKPT (breakpoint) instruction in v 5 T ISA. – Any attempt to execute undefined instruction – Used for software emulation of coprocessor & extension of instruction set l Software interrupt exception – Execution of SWI instruction – Enter into supervisor mode – SWI type parameter : 24 -bit in ARM mode, 8 -bit in Thumb mode Korea University of Technology & Education

Exception – 3 l Recognition time of exception – The end of execution of Exception – 3 l Recognition time of exception – The end of execution of the current instruction l Exception vector table Korea University of Technology & Education

Exception Procedure main() woo() ex_handler 0() ex_handler 1() Function call Program memory Nested exception Exception Procedure main() woo() ex_handler 0() ex_handler 1() Function call Program memory Nested exception handler exception IRQ Trap PC 0 x 0000 0004 0 x 0000 Exception vector Korea University of Technology & Education JMP Exception vector table

Exception Handling - 1 l Register change Korea University of Technology & Education Exception Handling - 1 l Register change Korea University of Technology & Education

Exception Handling - 2 l Handler example Korea University of Technology & Education Exception Handling - 2 l Handler example Korea University of Technology & Education

Memory Format ARM processor supports Little-endian, Big-endian memory access. l Data tyep : byte Memory Format ARM processor supports Little-endian, Big-endian memory access. l Data tyep : byte (8 -bit), Half-word (16 -bit), word (32 -bit) l – Half-word : 2 -byte boundary – Word : 4 -byte boundary Korea University of Technology & Education

Memory Format l Access format To store “ 0 x 0102 0304, 0 x Memory Format l Access format To store “ 0 x 0102 0304, 0 x 0506 0708” Little-Endian Big-Endian LSB 08 04 MSB 07 03 06 02 05 01 0 x 10 0 x 0 C 0 x 08 0 x 04 0 x 00 MSB First LSB MSB 05 01 06 02 07 03 LSB First low Korea University of Technology & Education 08 04 0 x 10 0 x 0 C 0 x 08 0 x 04 0 x 00

ARM Procedure Call Standard Korea University of Technology & Education ARM Procedure Call Standard Korea University of Technology & Education

Linux Korea University of Technology & Education Linux Korea University of Technology & Education

Operating System l Role of OS – Control & manage computing resource (CPU, memory, Operating System l Role of OS – Control & manage computing resource (CPU, memory, i/o). – Provide execution environment for application program – Support user interface : CLI, GUI Appli-1 Appli-2 Appli-3 User space System Call Interface Kernel space Kernel Core Device Driver Hardware Korea University of Technology & Education

Kernel of Operating System l Kernel – Essential part of operating system – Control Kernel of Operating System l Kernel – Essential part of operating system – Control computing resource & execute the command that user issued l Kernel component – Interrupt handler : service interrupt request – Scheduler : share processor among multiple processes – Memory management system : manage process address space – System service : networking, interprocess communication l Kernel architecture – Monolithic kernel – Micro kernel Korea University of Technology & Education

Monolithic-kernel vs. Micro-kernel System Service API 1 2 System Service API n 1 2 Monolithic-kernel vs. Micro-kernel System Service API 1 2 System Service API n 1 2 n Service Server Integrated Kernel Architecture Hardware (a) Monolithic kernel Korea University of Technology & Education Micro Kernel Architecture Hardware (b) Micro kernel

Features of Linux Kernel - 1 l Multi-tasking, multi-user system – based on time-division Features of Linux Kernel - 1 l Multi-tasking, multi-user system – based on time-division multi-plexing, multiple process can be executed, and multiple users can be logged on the same machine. l Symmetric multi-processor system – support multiple same kinds of processors in one machine. l Multi-platform – support various types of HW platform such as Intel IA-32, Alpha, Sparc, Power. PC, ARM, MIPS etc. l POSIX (portable operating system interface) – compatible with UNIX standard interface. l Paging – assign & swap the memory in pages. Korea University of Technology & Education

Features of Linux Kernel - 2 l System-V IPC support – support System-V IPC Features of Linux Kernel - 2 l System-V IPC support – support System-V IPC such as semaphore, message queue, shared memory, etc. l Various types of file system support – support FAT, VFAT, NTFS, ISO 9660, Joilet as well as the default file system, ext 2 l Various execution file-format support – a. out, ELF (executable and linking format). l Networking – TCP/IP, IPX/SPX, Appletalk, SLIP (serial line IP), PPP. BSD socket. l Shared library – Provide the program codes common to application programs in the form of shared library. Korea University of Technology & Education

Features of Linux Kernel - 3 l Module – Add the device driver programs Features of Linux Kernel - 3 l Module – Add the device driver programs for new devices & new kernel functions dynamically to the existing kernel. l Support a lot of types of peripheral devices – Network card, video card, sound card, CD-ROM, SCSI, USB, PCMCIA, Ir. DA, etc. Korea University of Technology & Education

Kernel Components - 1 l Process management – Process generation & termination – Process Kernel Components - 1 l Process management – Process generation & termination – Process communication : signal, pipe – CPU scheduling, synchronization – Access management of multiple processes on the limited resources. l Memory management – Virtual memory management – Effective memory hardware management by paging – Stable system by memory protection between processes l Network management – Support communication protocol – Network routing & address resolution – Manage network controller Korea University of Technology & Education

Kernel Components - 2 l File system management – Support various file system by Kernel Components - 2 l File system management – Support various file system by virtual file system (VFS) – Represent physical structure of hard disk with logical structure – File, directory management : normak file, device file, pipe – Manage buffer cache for block I/O l Device management – Verify & schedule I/O request – Data transfer between peripherals and memory – Manage device controllers – Handle interrupt request Korea University of Technology & Education

Program Operating Mode l User mode – Normal program is executed in user address Program Operating Mode l User mode – Normal program is executed in user address space l Kernel mode – Protected mode, privileged mode, supervisor mode Control accesses on system resource – Exception handling ü l Mode change – Change user mode to kernel mode ü By system call, exception User Mode Korea University of Technology & Education System Call & Interrupt (trap, IRQ) Kernel Mode

Kernel Size l Minimum Linux kernel size (in case of x 86 processor) – Kernel Size l Minimum Linux kernel size (in case of x 86 processor) – RAM size : 2. 3 MB – Ramdisk size : 389 KB – Kernel code size : 678 KB – ROM size : 500 KB ü ü Compressed ramdisk size : 151 KB Compressed kernel image size : 257 KB Korea University of Technology & Education

Kernel Source - 1 l Linux source tree LINUX fs init arch mm net Kernel Source - 1 l Linux source tree LINUX fs init arch mm net kernel drivers ext mips inet ext 2 alpha unix char xiafs lsofs hpfs nfs proc minix msdos sysv block sparc scsi ppc sound i 386 lib Modules lpc include linux asm-alpha asm-i 386 asm-m 88 k asm-generic kernel boot mm math-emu unsdos Korea University of Technology & Education asm-mips asm-sparc

Kernel Source - 2 Documentation l Header files l – Include/linux : common header Kernel Source - 2 Documentation l Header files l – Include/linux : common header file for linux kernel – Include/asm : architecture-dependent header file, symbolic link l Architecture-independent source – init : kernel booting related – kernel – – – : essential part of kernel such as process management, timer, interrupt, signal, module, etc ipc : IPC source fs : filesystem management source net : network related source drivers : device driver source lib : library function. In kernel, standard C library is not used. Korea University of Technology & Education

Kernel Source - 3 l Architecture-dependent source – arch/i 386/boot – arch/i 386/kernel – Kernel Source - 3 l Architecture-dependent source – arch/i 386/boot – arch/i 386/kernel – arch/i 386/mm – arch/i 386/lib – arch/i 386/math-emu ü if the floating-point coprocessor is not used, emualtor related source Korea University of Technology & Education

Example of Kernel Compile - 1 l Download kernel source – www. kernel. org Example of Kernel Compile - 1 l Download kernel source – www. kernel. org : kernel source, patch file, ex) linux- 2. 4. 0. tar. gz > > > cd /usr/src rm –f linux tar zxvf linux-2. 4. 0. tart. gz mv linux-2. 4. 0 ln –s lnux-2. 4. 0 linux (patching) > gzip –cd patch-2. 4. 1. gz | patch –p 0 Korea University of Technology & Education

Example of Kernel Compile - 2 Kernel source directory : /usr/src/linux l Kernel configuration Example of Kernel Compile - 2 Kernel source directory : /usr/src/linux l Kernel configuration l > make config / menuconfig / xconfig l Dependency check and generate kernel image & module > > make dep z. Image modules_install Korea University of Technology & Education

Kernel Booting l Diskette booting > dd if=bzimage of=/dev/fd 0 > rdev –R /dev/fd Kernel Booting l Diskette booting > dd if=bzimage of=/dev/fd 0 > rdev –R /dev/fd 0 /dev/hda 1 l LILO (linux loader) booting > cp arch/i 386/boot/bzimage /boot/vmlinuz-2. 4. 0 > cp system. map /boot/System. map-2. 4. 0 > vi /etc/lilo. conf (editing) image = /boot/vmlinuz-2. 4. 0 label=linux-2. 4. 0 root=/dev/hda 1 read-only Korea University of Technology & Education

EXT 2 File System The first filesystem of linux : Minix filesystem l EXT EXT 2 File System The first filesystem of linux : Minix filesystem l EXT (extended file system) : 1992. 4, included in linux v 0. 96 c l EXT 2 : 1993, improved EXT filesystem l Minix Ext 2 Xia Max. FS Size 64 M 2 G 4 T 2 G Max. File Size 64 M 2 G 2 G 64 M Max. File Name 14 255 248 3 Timestamps X X O O Extensible X X O X Variable Block Size X X O x Maintained O x O ? Korea University of Technology & Education 77

System Development (ARM + Linux) Korea University of Technology & Education System Development (ARM + Linux) Korea University of Technology & Education

Development Procedure of ARM + Linux Platform ① ② ③ ④ ⑤ ⑥ ⑦ Development Procedure of ARM + Linux Platform ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ Setup development environment Flash programming : JTAG Boot loader Kernel configuration File system generation (ramdisk, flash filesystem) Module programming Device driver User interface : GUI, command-line Application program Korea University of Technology & Education 79

Setup Development Environment l Host computer – develop & debug the software of target Setup Development Environment l Host computer – develop & debug the software of target board l Target board – what we want to build l Connection between host computer & target board – Serial port : connect target board’s consol port to host computer – JTAG : program download & debug – Ethernet : networking, file transfer, file system sharing Serial JTAG Ethernet Korea University of Technology & Education

Setup Host Computer Host computer provides software development environment for target board l Development Setup Host Computer Host computer provides software development environment for target board l Development tools installed in host computer l – terminal emulator, cross-compiler, BOOTP server, TFTP server, NFS server HUB Ethernet Terminal Emulator Serial Cross Compiler JTAG BOOTP Server TFTP Server NFS Server Target Board Korea University of Technology & Education Host Computer (LINUX)

Terminal Emulator l Terminal emulator – The program installed in host computer, which implements Terminal Emulator l Terminal emulator – The program installed in host computer, which implements the functions of terminal using serial communication – Play role of the monitor & keyboard of target board console – File upload & download – Hyper-terminal (Windows), minicom (Linux) Serial interface program Terminal Emulator Console console Port Target Board Korea University of Technology & Education File Upload File Download Serial Port Host PC

BOOTP Server l bootp (Boot Protocol) – Autobooting protocol of diskless client over IP BOOTP Server l bootp (Boot Protocol) – Autobooting protocol of diskless client over IP network – Use UDP protocol – Assign IP address of target board through IP network Bootloader # bootp BOOTP Server Bootp Request packet TCP /IP IP address daemon xinetd TCP /IP bootpd Target Board Korea University of Technology & Education Host PC Configuration file /etc/services /etc/xinetd. conf /etc/xinetd. d/bootp /etc/bootptab /etc/hosts

TFTP Server l TFTP (Trivial File Transfer Protocol) – Simple file transfer protocol using TFTP Server l TFTP (Trivial File Transfer Protocol) – Simple file transfer protocol using UDP – Fast download of large data file (kernel image, ramdisk image, applicaions) Bootloader #tftp [file_name] TFTP Server RRQ TCP /IP Kernel, ramdisk, TCP /IP xinetd in. tftpd Target Board Korea University of Technology & Education Host PC /etc/services /etc/xinetd. conf /etc/xinetd. d/tftpboot

NFS Server l NFS (Network File System) – File-system sharing via network – Provide NFS Server l NFS (Network File System) – File-system sharing via network – Provide storage space to target board – Direct execution of cross-compiled result without trasnfering it to target board HUB /mnt Network File System Target Board NFS client Korea University of Technology & Education /nfs_resource Host Computer NFS server

Tool Chain l Tool chain – A group of tools for the developments of Tool Chain l Tool chain – A group of tools for the developments of system program & application program – Text editor (vi), compiler (gcc), assembler (gas), linker (ld), utility programs (binutils), libraries (glibc) l Types of compilation – Native compile : the processor executing compiler is same as the prcessor executing compiled result (executable file) – Cross compile) : the processor executing compiler is different from the prcessor executing compiled result (executable file) l Compilation in embedde system development – Cross compile Korea University of Technology & Education

Cross Tool Chain for ARM Tool arm-linux-gcc arm-linux-c++ arm-linux-as arm-linux-gasp arm-linux-ld arm-linux-ar arm-linux-objdump arm-linux-nm Cross Tool Chain for ARM Tool arm-linux-gcc arm-linux-c++ arm-linux-as arm-linux-gasp arm-linux-ld arm-linux-ar arm-linux-objdump arm-linux-nm arm-linux-strip arm-linux-objcopy arm-linux-ranlib arm-linux-size arm-linux-strings Description C compiler C++ compiler GNU assembly preprocessor GNU linker Archives generation & modification Get information about object file Display symbol information of objective file Delete symbol information from objective file Copy objective file Generate archive index Display the size of sections of objective file Display strings & printable characters arm-linux-addr 2 line Translate address into file name and line number Korea University of Technology & Education

Make Utility program which compile efficiently multiple files l Control the sequence of compilation Make Utility program which compile efficiently multiple files l Control the sequence of compilation l Manage the location of program installation l Makefile l – Script file defining the compile procedure of make utility – Consist of dependencies & rules Korea University of Technology & Education

Make Utility (Makefile) all: myapp CC = gcc INSTDIR = /usr/local/bin CFLAGS = -g Make Utility (Makefile) all: myapp CC = gcc INSTDIR = /usr/local/bin CFLAGS = -g –Wall myapp: main. o foo. o boo. o $(CC) –o myapp main. o foo. o boo. o main. o : main. c myhead. h $(CC) $(CFLAGS) –c main. c foo. o: foo. c foohead. h $(CC) $(CFLAGS) –c foo. c boo. o: boo. c boohead. h $(CC) $(CFLAGS) –c boo. c clean: rm main. o foo. o boo. o Korea University of Technology & Education

GDB : GNU Debugger l GDB – Text-based GNU debugger – Default Linux debugger GDB : GNU Debugger l GDB – Text-based GNU debugger – Default Linux debugger l How to use – Use “–g” option when comple – Execute GDB command “gdb [object_file_name]” l GDB commands - run, backtrace, help, print, list, quit, break, clear, display, commnads, info, cont Korea University of Technology & Education

JTAG l JTAG – Joint Test Access Group’s boundary scan for PCB and chip JTAG l JTAG – Joint Test Access Group’s boundary scan for PCB and chip test – 1990 : adopted as IEEE 1149. 1 standard l 5 -pin interface – TDI : test data in – TDO : test data out – TCK : test clock input – TMS : test mode select – TRST : test reset Korea University of Technology & Education

JTAG Registers Identification register : 32 -bit, JTAG ID code – 0 : Constant, JTAG Registers Identification register : 32 -bit, JTAG ID code – 0 : Constant, ‘ 1’ if ID register exists – 1. . 11 : Manufacturer ID, “ 0000 1001” – 12. . 27 : Part Number, “ 1001 0010 0110 0001” – 28. . 31 : Stepping, “xxxx” l Instruction register : 4 -bit, 5 -bit (for SA 1110), holding instruction – 1111 : BYPASS, TDI + Bypass + TDO – 00110 : IDCODE, TDI + ID reg + TDO – 00011 : SAMPLE, TDI + boundary cells + TDO, sampling internal signals – 01001 : INTEST, TDI + boundary cells + TDO, internal test – 00000 : EXTEST, TDI + boundary cells + TDO, external test – 00101 : HIGHZ, external output pins = high-Z l Bypass register : 1 -bit l Korea University of Technology & Education

Boundary Scan Register l Boundary scan register – PI : parallel input – PO Boundary Scan Register l Boundary scan register – PI : parallel input – PO : parallel output – SI : serial input – SO : serial output Korea University of Technology & Education

Boundary Scan Chain l Chain of boundary scan registers Korea University of Technology & Boundary Scan Chain l Chain of boundary scan registers Korea University of Technology & Education

External Connection of JTAG External connectivity test Korea University of Technology & Education External Connection of JTAG External connectivity test Korea University of Technology & Education

TAP Controller - 1 l TAP controller : FSM that controls JTAG interface – TAP Controller - 1 l TAP controller : FSM that controls JTAG interface – TMS is used to change state of TAPC Korea University of Technology & Education

TAP Controller - 2 l States of TAP controller – Test-Logic-Reset : initialize TAPC TAP Controller - 2 l States of TAP controller – Test-Logic-Reset : initialize TAPC – Run-Test/Idle : ready to test – Select DR-scan : connect scan cells – Capture DR : capture the data of PI – Shift DR : shift the data of scan cell, output to SO – Update DR : output to PO – Select IR-Scan : select IR – Capture IR : output PI of IR to shift cell – Shift IR : shift out the content of IR – Update IR : output to PO Korea University of Technology & Education

State Transition Diagram of TAPC Korea University of Technology & Education 98 State Transition Diagram of TAPC Korea University of Technology & Education 98

Flash Fusing - 1 l In-system flash memory fusing – Programmed using JTAG – Flash Fusing - 1 l In-system flash memory fusing – Programmed using JTAG – Flash program utility : l jflash Flash memory map User space (/usr) 0 x 90 0000 – 0 xa 160 0000 RAMdisk 0 x 0020 0000 ~ kernel (0 x 10 0000) 0 x 000 c 0000 ~ 0 x 001 c 0000 Env. Values (0 x 10 0000) 0 x 0008 0000 ~ 0 x 000 c 0000 Boot loader 0 x 0000 ~ Korea University of Technology & Education

Flash Fusing - 2 command Target Board Host Computer DRAM TCP/IP boot loader TFTP Flash Fusing - 2 command Target Board Host Computer DRAM TCP/IP boot loader TFTP kernel ramdisk JTAG Parallel port Jflash cmd User Space Korea University of Technology & Education 100

Bootloader Korea University of Technology & Education Bootloader Korea University of Technology & Education

Bootloader l Bootloader – the first program after system reset. – Load operating system Bootloader l Bootloader – the first program after system reset. – Load operating system into main memory – BLOB (boot loader object) Store flash memory bank-0 l Function of bootloader l – Initialize the hardware – Support Command line – Download the data from host computer to main memory (SDRAM) – Write the data stored at SDRAM to flash memory – Boot linux kernel Korea University of Technology & Education

Operation Flow of Bootloader – 1 Set Interrupt handler l Interrupt masking l – Operation Flow of Bootloader – 1 Set Interrupt handler l Interrupt masking l – ICMR (0 x 9005_0004) = 0 x 00 l Prevent entering sleep mode – PMCR (0 x 9002_0000) = 0 x 00 l CPU clock setting – PPCR (0 x 9002_0014) = 0 x 0 A l Setup GPIO – GPDR (0 x 9004_0004) = 0 x 0000_00 FF – GPSR (0 x 9004_0008) = 0 x 0000_00 FF – GRER (0 x 9004_0010) = 0 x 0000_0200 – GFER (0 x 9004_0014) = 0 x 0000_0000 l Setup SDRAM parameters Korea University of Technology & Education

Operational Flow of Bootloader – 2 l Call Before. Main – Copy bootloader itself Operational Flow of Bootloader – 2 l Call Before. Main – Copy bootloader itself to main memory. – Call CMain function l Call CMain – Set baud rate of serial port & download speed – Initialize the timer & Ethernet interface – Wait key-stroke ü ü Any key-stroke : enter bootloader command mode No key-stroke : autobooting Korea University of Technology & Education

Source of hbloader. text // // // vector table Reset = 0 x 0000 Source of hbloader. text // // // vector table Reset = 0 x 0000 Undefined instruction = 0 x 0000 0004 Software interrupt = 0 x 0000 0008 Abort prefetch = 0 x 0000 000 C Abort data = 0 x 0000 0010 Not used = 0 x 0000 0014 IRQ = 0 x 0000 0018 FIQ = 0 x 0000 001 C start. s . globl _start: b b b nop b b reset undefined_instruction software_interrupt abort_prefetch abort_data irq fiq Korea University of Technology & Education 105

Source of hbloader reset: // All interrupt disable. mask ALL interrupts. // ICMR (interrupt Source of hbloader reset: // All interrupt disable. mask ALL interrupts. // ICMR (interrupt control mask register) = 0 x 9005 0004 // IM[31: 0] = ICMR[31: 0], 0 (masked), 1 (enabled) mov add mov str // // // r 1, r 2, #0 x 90000000 r 1, #0 x 50000 #0 x 00 [r 1, #0 x 4] Protect enterting sleep mode PMCR(power management control register) = 0 x 9002 0000 SF-bit = PMCR[0] 0 (Don't force invocation of sleep mode) 1 (Force invocation of sleep mode) mov add mov str r 1, r 2, Korea University of Technology & Education #0 x 90000000 r 1, #0 x 20000 #0 x 00 [r 1, #0 x 00] 106

Source of hbloader // // PPCR(power manager PLL configuration register) = 0 x 9002 Source of hbloader // // PPCR(power manager PLL configuration register) = 0 x 9002 0014 CPU clock = 206 MHz CCF 4. . 0 = PPCR[4: 0] 00000 = 59. 0 MHz, 00001 = 73. 7 MHz, 00010 = 88. 5 MHz 00011 = 103. 2 MHz, 00100 = 118. 0 MHz, 00101 = 132. 7 MHz 00110 = 147. 5 MHz, 00111 = 162. 2 MHz, 01000 = 176. 9 MHz 01001 = 191. 7 MHz, 01010 = 206. 4 MHz, 01011 = 221. 2 MHz mov add mov str Korea University of Technology & Education r 1, r 2, #0 x 90000000 r 1, #0 x 20000 #0 x 0 a [r 1, #0 x 14] 107

Source of hbloader // GPDR(GPIO Pin Direction Register) = 0 x 9004 0004 // Source of hbloader // GPDR(GPIO Pin Direction Register) = 0 x 9004 0004 // PD[27: 0] = GPDR[27: 0] // 0 (input), 1 (output) #define GPIO_DIRECTION 0 x 0000 00 ff mov add ldr str r 2, r 1, #0 x 90000000 r 2, #0 x 40000 =GPIO_DIRECTION [r 2, #0 x 04] // GPSR (GPIO pin output set register) = 0 x 9004 0008 // PS[27: 0] = GPSR[27: 0] // 0 (low), 1 (high) ldr str Korea University of Technology & Education r 3, =GPIO_DIRECTION r 3, [r 2, #0 x 08] 108

Source of hbloader // GRER - (GPIO Rising-Edge Detect Register) = 0 x 9004 Source of hbloader // GRER - (GPIO Rising-Edge Detect Register) = 0 x 9004 0010 // RE[27: 0] = GRER[27: 0] // 0 (Disable), 1 (set GEDR bit high when rising edge is detected) ldr str r 3, =0 x 00000200 r 3, [r 2, #0 x 10] // GFER (GPIO Falling-Edge Detect Register) = 0 x 9004 0014 // FE[27: 0] = GFER[27: 0] // 0 (disable), 1 (set GEDR bit high when falling edge is detected) mov str r 3, #0 x 0000 r 3, [r 2, #0 x 14] // Set Dynamic Memory. // DRAM configuration register (MDCNFG) = 0 x. A 0000 // MDCAS 00 (DRAM CAS waveform rotate register 0 for DRAM bank pair 0/1) = 0 x. A 0004 // MDCAS 20 (DRAM CAS waveform rotate register 0 for DRAM bank pair 2/3) = 0 x. A 000 0020 // MDCAS 01 = 0 x. A 0008, MDCAS 02 = 0 x. A 000 C // MDCAS 21 = 0 x. A 000 0024, MDCAS 22 = 0 x. A 000 0028 // MDCASn 0[31: 0] = 0 x. AAAA AA 7 F // MDCASn 1[31: 0] = 0 x. AAAA // MDCASn 2[31: 0] = 0 x. AAAA Korea University of Technology & Education 109

Source of hbloader // MDREFR. Kn. DB 2 = 0 // (SDRAM) // RAS-to-CAS Source of hbloader // MDREFR. Kn. DB 2 = 0 // (SDRAM) // RAS-to-CAS delay = 8 * CPU-clock-period // CAS-to-CAS delay = 2 * CPU-clock-period // Delay from SDCLK rising edge to read data // latching edge = 3* CPU-clock-period mov ldr str r 1, #0 x. A 0000000 r 2, =0 x. AAAAAA 7 F r 2, [r 1, #0 x 04] r 2, [r 1, #0 x 20] ldr str r 2, =0 x. AAAA r 2, [r 1, #0 x 08] r 2, [r 1, #0 x 24] ldr str r 2, =0 x. AAAA r 2, [r 1, #0 x 0 C] r 2, [r 1, #0 x 28] // MDREFR (DRAM refresh control register) = 0 x. A 000 001 C // 0 (SLFRSH, KAPD, EAPD, K 2 DB 2, K 2 RUN, K 0 RUN, E 0 PIN) // 1 (K 1 DB 2, K 1 RUN, E 1 PIN, K 0 DB 2) // DRI[11: 6] = 0, DRI[5: 4] = 1, DRI[3: 2] = 0, DRI 1 = 1, DRI 0 = 0 // TRASR[3: 0] = 0111 ldr str Korea University of Technology & Education r 2, =0 x 00740327 r 2, [r 1, #0 x 1 C] 110

Source of hbloader // MDCNFG (DRAM configuration register) = 0 x. A 0000 ldr Source of hbloader // MDCNFG (DRAM configuration register) = 0 x. A 0000 ldr str r 2, =0 x 725 c 7245 r 2, [r 1, #0 x 00] // Issue read requests to disabled bank to start refresh. . rept ldr 8 ldr r 1, =0 x. C 0000000 r 0, [r 1] . endr // LED 0 on // GPIO clear register = GPCR : 0 x 9004 000 c mov add r 1, #0 x 90000000 r 1, #0 x 40000 ldr str r 2, =0 x 00000001 r 2, [r 1, #0 x 0 C] // Set Static Memory. // MSC 0(Static memory control register 0) = 0 x. A 000 0010 // MSC 1(Static memory control register 1) = 0 x. A 000 0014 // MSC 2(Static memory control register 2) = 0 x. A 000 002 C // SMCNFG(SMROM configuration register) = 0 x. A 000 0030 // MECR (Expansion bus configuration register) = 0 x. A 000 0018 Korea University of Technology & Education 111

Source of hbloader start. s mov ldr str r 1, #0 x. A 0000000 Source of hbloader start. s mov ldr str r 1, #0 x. A 0000000 r 2, =0 x 4 b 944 b 90 r 2, [r 1, #0 x 10] ldr str r 2, =0 x 4 b 954 b 94 r 2, [r 1, #0 x 14] ldr str r 2, =0 x 00004 b 95 r 2, [r 1, #0 x 2 C] ldr str r 2, =0 xafccefcc r 2, [r 1, #0 x 30] ldr str r 2, =0 x 994 a r 2, [r 1, #0 x 18] // Led 1 on mov add ldr str r 1, r 2, // SDRAM Clear #define DRAM_BASE_ADDR #define DRAM_SIZE (0 xc 0000000) (0 x 02000000) Korea University of Technology & Education #0 x 90000000 r 1, #0 x 40000 =0 x 00000002 [r 1, #0 x 0 C] // 32 MB 112

Source of hbloader ldr mov r 1, =DRAM_BASE_ADDR r 2, #0 x 0000 ldr Source of hbloader ldr mov r 1, =DRAM_BASE_ADDR r 2, #0 x 0000 ldr add r 3, =DRAM_BASE_ADDR r 3, #DRAM_SIZE str add r 2, [r 1] r 1, #4 cmp bne r 1, r 3 1 b mov add r 1, #0 x 90000000 r 1, #0 x 40000 ldr str r 2, =0 x 00000004 r 2, [r 1, #0 x 0 C] 1: // Led 2 on // Set stack pointer ldr Korea University of Technology & Education sp, =STACK_POINT 113

Source of hbloader // Jump to the C code. jump_to_c: b Before. Main // Source of hbloader // Jump to the C code. jump_to_c: b Before. Main // handler setting undefined_instruction: b software_interrupt: b abort_prefetch: b abort_data: b not_used: b irq: b fiq: b undefined_instruction software_interrupt abort_prefetch abort_data not_used irq fiq Korea University of Technology & Education 114

Source of hbloader typedef struct { long } LOADER_STATUS; terminal. Speed; download. Speed; LOADER_STATUS Source of hbloader typedef struct { long } LOADER_STATUS; terminal. Speed; download. Speed; LOADER_STATUS status; void bool main. c Before. Main(void); CMain(void); Do. Printf. Help(int argc, char **argv); #define LOADER_SRAM_BASE (0 x 0000) #define LOADER_DRAM_MAX_SIZE (0 x 00010000) #define DRAM_SIZE (0 x 02000000) #define LOADER_DRAM_BASE (DRAM_BASE_ADDR+DRAM_SIZE-LOADER_DRAM_MAX_SIZE) void Before. Main(){ register ulong *dest = (ulong *)LOADER_DRAM_BASE; register ulong *src = (ulong *)LOADER_SRAM_BASE; register ulong len = LOADER_DRAM_MAX_SIZE / 4; void (*Jump. To)(void); while (len--) *dest++ = *src++; Jump. To = CMain; Jump. To(); return; } Korea University of Technology & Education 115

Source of hbloader main. c void CMain( ){ int bool char long int char Source of hbloader main. c void CMain( ){ int bool char long int char CMD_TBL i; autoboot=true; cmd[128]; timeout; argc=0; *argv[MAX_ARGS]; *cptr; #define SERIAL_SPEED #define SERIAL_DOWNLOAD_SPEED 1 1 // 191 : 1200 // 23 : 9600 // 11 : 19200 // 5 : 38400 // 3 : 57600 // 1 : 115200 status. terminal. Speed = SERIAL_SPEED; status. download. Speed = SERIAL_DOWNLOAD_SPEED; Serial. Init(status. terminal. Speed); Timer. Init(); #ifdef USE_LCD_LOGO View. Logo(); #endif Korea University of Technology & Education 116

Source of hbloader main. c // ethernet initialization Eth. Init(); // scc. c // Source of hbloader main. c // ethernet initialization Eth. Init(); // scc. c // wait 10 seconds before starting autoboot. printf("Autoboot in progress, press any key to stop "); for (i=0; i

Source of hbloader main. c // No key was pressed, proceed booting the kernel. Source of hbloader main. c // No key was pressed, proceed booting the kernel. if (autoboot){ printf("Autoboot started. n"); printf("nkernel loading. . . "); Mem. Cpy( (char *)KERNEL_DRAM_BASE, (char *)KERNEL_SRAM_BASE, KERNEL_MAX_SIZE); printf("Done"); printf("nramdisk loading. . . "); Mem. Cpy( (char *)RAMDISK_DRAM_BASE, (char *)RAMDISK_SRAM_BASE, RAMDISK_MAX_SIZE); printf("Done"); for (cptr=cmd. Tbl; cptr->cmd; cptr++){ if (!Str. Cmp(cptr->cmd, "boot")) break; } Do. Boot. Kernel(cptr, 1, 0); } Korea University of Technology & Education 118

Source of hbloader main. c // Key was pressed, proceed command mode. printf( Source of hbloader main. c // Key was pressed, proceed command mode. printf("n. Autoboot abortedn"); printf("Type "help" to get a list of commandsn"); // the command loop. endless, of course. for(; ; ) { Display. Prompt(NULL); // wait an hour to get a command. Get. Command(cmd, 128, 3600); if (!cmd || !cmd[0]) continue; argc = Get. Args(cmd, argv); for (cptr=cmd. Tbl; cptr->cmd; cptr++){ if (!Str. Cmp(argv[0], cptr->cmd)){ (cptr->run)(cptr, argc, argv); break; } } if (!Str. Cmp(argv[0], "help") || !Str. Cmp(argv[0], "? ")){ Do. Printf. Help(argc, argv); } else if (!(cptr->cmd)){ printf("t. Unknown command : %sn", argv[0]); } } } // The end of CMain Korea University of Technology & Education 119

Source of hbloader command. c bool Do. Boot. Kernel(CMD_TBL *cptr, int argc, char **argv){ Source of hbloader command. c bool Do. Boot. Kernel(CMD_TBL *cptr, int argc, char **argv){ #ifndef TINY_LOADER long addr; #endif long opt[2]; void (*the. Kernel)(int zero, int arch); if (argc!=1 && argc!=3 && argc!=4){ printf(cptr->usage); return false; } switch (argc){ case 1 : // boot opt[0] = 0; opt[1] = 0 x 14; // KERNEL_DRAM_BASE = 0 x. C 000 8000 the. Kernel = (void (*)(int, int))KERNEL_DRAM_BASE; break; case 3 : (생략) printf("n. Starting kernel. . . nn"); the. Kernel(opt[0], opt[1]); return true; } Korea University of Technology & Education 120

Kernel Configuration Korea University of Technology & Education Kernel Configuration Korea University of Technology & Education

Configuration Options – 1 l Code maturity level options – Prompt for development and/or Configuration Options – 1 l Code maturity level options – Prompt for development and/or incompleter code/drivers l Loadable module support – enable loadable module support l System type – (SA 1100 -based) ARM system type - SA 11 x 0 implementations, include support for TBEL 1110 l General setup – support hot-pluggable devices – Networking support – System V IPC : +18 KB – Sysctl support Korea University of Technology & Education

Configuration Options – 2 l General setup – NWFPE math emulation – kernel core Configuration Options – 2 l General setup – NWFPE math emulation – kernel core (/proc/kcore) format (ELF/a. out) – kernel support for ELF binaries** : +13 KB. – Timer and CPU usage LEDs – Timer LED – CPU usage LED – Kernel-mode alignment trap handler Korea University of Technology & Education

Configuration Options - 3 l Block devices – Loopback device support** – RAM disk Configuration Options - 3 l Block devices – Loopback device support** – RAM disk support – Default RAM disk size (8192) – Initial RAMS disk (initrd) support – Flash memory block device support l Networking options – packet socket** – Unix domain sockets** – TCP/IP networking Korea University of Technology & Education

Configuration Options - 4 l Network device support – Ethernet (10 or 100 Mbit) Configuration Options - 4 l Network device support – Ethernet (10 or 100 Mbit) Ethernet (10 or 100 Mbit)** – PPP (point-to-point protocol) support** – PPP support for async serial ports** – PPP deflate compression** – PPP BSD-compression l Character devices – Virtual terminal – SA 1100 serial port support – Console on SA 1100 serial port – Serial console 115200 – Unix 98 PTY support Korea University of Technology & Education

Configuration Options – 5 l File systems – /proc file system support – /dev/pts Configuration Options – 5 l File systems – /proc file system support – /dev/pts file system for Unix 98 PTYs – Second extended fs support** – Network file systems NFS file system support : +27 KB. l Kernel hacking – Verbos kernel error message – Verbose user fault messages – Kernel low-level debugging functions Korea University of Technology & Education

File System Korea University of Technology & Education File System Korea University of Technology & Education

Linux File System Architecture User process User mode Kernel mode System Call Interface Virtual Linux File System Architecture User process User mode Kernel mode System Call Interface Virtual File System Switch (VFS) proc ext 2 msdos minix Buffer Cache Device Drivers Disk Controller Korea University of Technology & Education 128

File System Structure – 1 Each file is represented by a data structure, called File System Structure – 1 Each file is represented by a data structure, called an inode. l Inode : File type, access rights, owners, timestamps, size, pointers to data blocks, link counter l Korea University of Technology & Education

File System Structure – 2 l Directory : structured in a hierarchical tree, contains File System Structure – 2 l Directory : structured in a hierarchical tree, contains files and subdirectories – A file containing a list of entries which contains inode number & file name l Link – Hard link : used only within a single file system. Can only point on files. – Symbolic link : file containing a filename. Does not point to an inode. Cross-filesystem symoblic link is possible. Korea University of Technology & Education

File System Structure – 3 l Device special file – devices can be accessed File System Structure – 3 l Device special file – devices can be accessed via special file. Does not use disk space. Access point to the device driver. l Character special file – I/O operations in character mode l Block special file – I/O operations in block mode via a buffer cache function. l I/O request on special file – forwarded to device driver. Referenced by major number (device type) & minor number (device unit) Korea University of Technology & Education

Virtual File System Switch (VFS) l VFS – Abstraction layer between application program and Virtual File System Switch (VFS) l VFS – Abstraction layer between application program and filesystem Provides system calls for file management ü Maintains internal data structures and pass task on to actual file system – Common interface to various filesystem ü Korea University of Technology & Education

Virtual File System Switch (VFS) l Filesystem supported by VFS – Disk-based filesystem : Virtual File System Switch (VFS) l Filesystem supported by VFS – Disk-based filesystem : manage memory space of local disk parition ü EXT 2, MS-DOS, VFAT, NTFS, ISO 9660 CD-ROM – Network-based filesystem : access the filesystem belongs to other computer in network. ü NFS, Coda, AFS, SMB, NCP – Special filesystem (virtual filesystem) : no use of disk space ü /proc : provide the interface for user to access data structure of kernel ü /dev/pts : support pseudo-terminal of Open Group’s UNIX 98 standard Korea University of Technology & Education

/Proc File System – 1 l l l Provide the information on the status /Proc File System – 1 l l l Provide the information on the status of kernel and running processes Inodes for /proc • Root : 1 • Others : defined in Directory structure • /proc/pid : holding informtion on process-pid • /proc/loadavg : provide average system load for the last 1, 5, 15 minutes • /proc/uptime : indicates time in seconds since system start and the time used by idle process • /proc/meminfo : contains the number of total, used and free bytes of main memory and swap area • /proc/kmsg : supplies kernel messages which have not been read viad syslog system call • /proc/version : kernel version information • /proc/cpuinfo : parameters of the processor • /proc/pci : occupation of PCI slots • /proc/self/ : information about the process accessing /proc file system • /proc/scsi/ : information about SCSI devices • /proc/malloc : monitoring of kmalloc(), kfree() • /proc/kcore : core dump of kernel Korea University of Technology & Education 134

/Proc File System – 2 l Directory structure (continued) • /proc/net/ : files that /Proc File System – 2 l Directory structure (continued) • /proc/net/ : files that describe Linux network layer ü unix : information on opened Unix domain sockets ü arp : contents of ARP table ü route : routing table ü dev : available network devices ü raw : information about opened RAW sockets ü tcp : information about TCP sockets ü u. DP : information about UDP sockets ü snmp : MIB (Management Information Bases) for SNMP protocol ü sockstat : statistics about the sockets • /proc/modules : information about modules loaded, size and status • /proc/stat : Linux kernel statistics • /proc/devices : information about registered device drivers • /proc/interrupts : the number and names of hardware interrupt received. • /proc/filesystems : existing file system of kernel • /proc/ksyms : all symbols exported by kernel • /proc/dma : DMA channel information Korea University of Technology & Education 135

/Proc File System – 3 l Directory structure (continued) • /proc/sys/ : information controlling /Proc File System – 3 l Directory structure (continued) • /proc/sys/ : information controlling kernel algorithms ü kernel ú domainname : system domain name ú filemax : max # of simultaneously opened files ú filenr : # of currently opened files ú hostname : computer name ú inodemax : max # of simultaneously opened inodes ú inodenr : # of currently opened inodes ú osrelease : kernel version ú ostype : operting system name ú panic : timeout after a panic message ú securelevel : security level ú version : compiler information during kernel compilation ü net/ : depends on network configuration ü vm/ : control parameters of memory management processes ú bdflush : control parameters of bd_flush process ú freepages : value of free-page levels ú kswapd : control parameters of kswap daemon ú swapctl : control parameters of swap process Korea University of Technology & Education 136

/Proc File System – 4 l Directory structure (continued) • /proc/ioports : I/O ports /Proc File System – 4 l Directory structure (continued) • /proc/ioports : I/O ports occupied via request_region() • /proc/smp : information on CPUs in SMP systems • /proc/cmdline : command line passed to kernel at startup • /proc/mtab : list of currently mounted file systems • /proc/md : statistics on usage of multiple device driver (CONFIG_BLK_DEV_MD configured) • /proc/rc : RTC values (CONFIG_RTC configured) • /proc/locks : current file locks Korea University of Technology & Education 137

EXT 2 File System The first filesystem of linux : Minix filesystem l EXT EXT 2 File System The first filesystem of linux : Minix filesystem l EXT (extended file system) : 1992. 4, included in linux v 0. 96 c l EXT 2 : 1993, improved EXT filesystem l Minix Ext 2 Xia Max. FS Size 64 M 2 G 4 T 2 G Max. File Size 64 M 2 G 2 G 64 M Max. File Name 14 255 248 3 Timestamps X X O O Extensible X X O X Variable Block Size X X O x Maintained O x O ? Korea University of Technology & Education 138

Ext 2 File System Structure l Physical structure of filesystem Boot Sector l Block Ext 2 File System Structure l Physical structure of filesystem Boot Sector l Block Group 1 Block Group 2 . . . Block Group N Structure of block group Super Block Group Descriptors Korea University of Technology & Education Block Bitmap Inode Table Data Blocks 139

Ext 2 File System Structure l Block group descriptor (32 -bytes) 0 7 Block Ext 2 File System Structure l Block group descriptor (32 -bytes) 0 7 Block bitmap Inode table # of free blocks # of free inodes # of directories l Pad words Directory • Managed usingly linked list • Date structure of directory entry struct ext 2_dir_entry { unsigned long inode; // inode number unsigned short rec_len; // length of directory entry unsigned short name_len; // length of filename char name[EXT 2_NAME_LEN]; // filename }; Korea University of Technology & Education 140

Ext 2 File System Structure l Inode (128 bytes) 0 Type/Permission 7 UID File Ext 2 File System Structure l Inode (128 bytes) 0 Type/Permission 7 UID File size Access time Time of creation Time of modification Time of deletion GID # of blocks Link counter File attributes Reserved 1 st direct block …. 12 -th direct block 1 -stage indirect block 2 -stage indirect block 3 -stage indirect block File version File ACL (access control list) Directory ACL Fragment address Reserved Korea University of Technology & Education 141

EXT 2 Library and Tools Libext 2 fs : allow user to manipulate the EXT 2 Library and Tools Libext 2 fs : allow user to manipulate the control structure of Ext 2 filesystem – Filesystem-oriented operations – Directory-oriented operations – Inode-oriented operations l Tools – tune 2 fs : modify filesystem parameters – e 2 fsck : repair filesystem consistencies after unclean shutdown ü Phase-1 : inode check ü Phase-2 : directory check ü Phase-3 : directory connectivity check ü Phase-4 : reference count (link count) check for all inodes ü Phase-5 : check the validity of filesystem summary information – debugfs : examine and change the state of filesystem l Korea University of Technology & Education

Ramdisk l Ramdisk device – Use a part of main memory as hard disk Ramdisk l Ramdisk device – Use a part of main memory as hard disk – /dev/ram 0, /dev/ram 1 l Ramdisk image – File having ramdisk or file system image mounted with “–o” loop option l Ramdisk object – ELF object file having ramdisk image (generally compressed) Korea University of Technology & Education

Loop Device l Loop device – Virtual device which use a file as file Loop Device l Loop device – Virtual device which use a file as file system – /dev/loop 0, /dev/loop 1 l Initial ramdisk device – Use loop device as root file system – After executing /linuxrc program on ramdisk, the file system on the other device is mounted as root file system. – Even after changing root file system, initial ramdisk device can be accessed through /dev/initrd device. Korea University of Technology & Education

Ramdisk Generation ① ② ③ ④ ⑤ ⑥ ⑦ dd if=/dev/zero of=/tmp/fsfile bs=1 K Ramdisk Generation ① ② ③ ④ ⑤ ⑥ ⑦ dd if=/dev/zero of=/tmp/fsfile bs=1 K count=1000 /sbin/losetuo /dev/loop 0 /tmp/fsfile /sbin/mke 2 fs /dev/loop 0 mkdir /mnt/tmp mount –t ext 2 /dev/loop 0 /mnt/tm cd /mnt/tmp ls Korea University of Technology & Education