45
Porting Operating Systems Phan Duy Hùng (PhD) ES Lecturer – Hanoi FPT University

Porting Operating Systems

  • Upload
    latham

  • View
    77

  • Download
    1

Embed Size (px)

DESCRIPTION

Porting Operating Systems. Phan Duy Hùng (PhD) ES Lecturer – Hanoi FPT University. Content. Bootloader Kernel Filesystem Bootloader (again). Embedded Linux Introduction. Linux Support CPU: x86, ARM, MIPS, SH, i960, PowerPC, …etc Open Source Powerful Network Functions - PowerPoint PPT Presentation

Citation preview

Page 1: Porting Operating Systems

Porting Operating Systems

Phan Duy Hùng (PhD)ES Lecturer – Hanoi FPT University

Page 2: Porting Operating Systems

Bootloader Kernel Filesystem

Bootloader (again)

2

Content

Page 3: Porting Operating Systems

Embedded Linux Introduction

Linux Support CPU: x86, ARM, MIPS, SH, i960,

PowerPC, …etc Open Source Powerful Network Functions Easy Software Porting GNU Complier and Debugger

Page 4: Porting Operating Systems

4

Cross-Development Environment

Target has limited resource (memory, storage, low speed processor) .

Host and Target are different architecture

Cross-platformDevelopmentEnvironment

Host•Bootloader•Kernel•Root Filesystem

Target

Page 5: Porting Operating Systems

Ways of Hardware Connection

Page 6: Porting Operating Systems

Linux Architecture

Applications

Bash Shell

LinuxKernel

hardware

Page 7: Porting Operating Systems

Linux Architecture

Hardware

Bootloader Drivers Kernel

File System Protocol StacksKernel System Call Interface

GLIBC Other Libraries

JavaGUI

Applications

Page 8: Porting Operating Systems

8

All the things we need

Cross-Platform development toolchain Bootloader

Usually provided by the vendor

Linux kernel Linux kernel + some patches if needed

Filesystem Busybox Device node Configuration

Page 9: Porting Operating Systems

9

Bootloader Concepts (cont`)

Typical space allocation

Boot parameters

Bootloader

Kernel Root filesystem

Page 10: Porting Operating Systems

10

Bootloader Concepts

What is bootloader ? Load kernel and filesystem Initialize hardware elements

Many bootloaders for each architecture LILO and GRUB for x86

LILO: http://lilo.go.dyndns.org/ GRUB: http://www.gnu.org/software/grub/

U-Boot for x86, ARM, PowerPC U-Boot: http://u-boot.sourceforge.net/

Page 11: Porting Operating Systems

11

Bootloader Concepts (cont`)

Bootloader also depends on various hardware

All type CPU will execute the instructions from the defined address when power on Normally, there exists some solid storage

devices mapped to defined address ROM, EEPROM, FLASH, etc

Page 12: Porting Operating Systems

12

The Bootloader's Job

One main mission: load the operating system(s).Tasks: Initialize the machine properly (the kernel can do this

later too). Access the kernel and initrd files in their storage

medium (need to support the corresponding filesystem too)

Because of the above 2 tasks, bootloaders may platform specific!

Load the kernel and initrd files Execute the kernel file with the right command line

Page 13: Porting Operating Systems

bootloader

Page 14: Porting Operating Systems

14

Some Bootloaders

LILO: LInux LOad. Original Linux bootloader. Still in use! http://freshmeat.net/projects/lilo/ Supports: x86

GRUB: GRand Unified Bootloader from GNU. More powerful. http://www.gnu.org/software/grub/ Supports: x86

LinuxBIOS: Linux based BIOS replacement http://www.linuxbios.org/ Supports: x86

Page 15: Porting Operating Systems

15

Some Bootloaders (cont.)

UBoot: Universal Bootloader. The most used on arm. http://uboot.sourceforge.net/ Supports: arm, ppc, mips, x86

RedBoot: eCos based bootloader from RedHat http://sources.redhat.com/redboot/ Supports: x86, arm, ppc, mips, sh, m68k...

Page 16: Porting Operating Systems

16

Why Use Linux

Open Source Reliability Salability Secure Supports Virtually All Network Communication

Protocols

Page 17: Porting Operating Systems

17

GCC

Cross Compiler creates executables for another platform (such as ARM), the output form can be ELF (Executable and Linking Format)

If you build a Linux Kernel, you have to use Cross Compiler, i.e. GCC for most cases

Page 18: Porting Operating Systems

18

GCC = GNU Compiler Collection

Features Portable Cross-compiling Support different language

C, C++, Objective-C, Fortran, Java, and Ada Free Software

Compiler: arm-linux-gcccompiling source codes to run on arm platforms

$ arm-linux-gcc hello.c –o hello/usr/local/arm/include/asm,linux

Page 19: Porting Operating Systems

System Boot Flow

Page 20: Porting Operating Systems

20

System Storage

The storage devices used in embedded systems are often quite different from those used in workstations and servers.

Embedded systems tend to use solid-state storage devices such as flash chips and flash disks.

Need the MTD subsystem to support

bootloader

boot parameters

kernel root filesystem

Page 21: Porting Operating Systems

Kernel Considerations

Kernel ConfigurationKernel Compiling

Page 22: Porting Operating Systems

22

Root File System Content

Page 23: Porting Operating Systems

Root File System/

/bin/boot

/grub/dev/etc/home/lib/mnt/proc/sbin/tmp/usr

/src/bin/sbin

/var/log/spool

Page 24: Porting Operating Systems

24

Building Root Filesystem

Download the BusyBox source code from http://www.busybox.net/

Building BusyBox make clean make all make install

After make complete, the busybox will be at ./path/to/busybox_src/_install/

Page 25: Porting Operating Systems

25

Graphic User Interface

Window System X Window (TinyX)

http://www.xfree86.org/ QPE (Qt Plamtop Environment) / Qtopia

http://www.trolltech.com/products/qtopia/index.html GPE (GPE Palmtop Environment)

http://gpe.handhelds.org/ Microwindows

http://microwindows.org/ MiniGUI

http://www.minigui.org/

Page 26: Porting Operating Systems

Development Tools

Editor (VIM) Toolchains

Page 27: Porting Operating Systems

27

Bootloader Concepts

What is bootloader ? Load kernel and filesystem Initialize hardware elements

Many bootloaders for each architecture LILO and GRUB for x86

LILO: http://lilo.go.dyndns.org/ GRUB: http://www.gnu.org/software/grub/

U-Boot for x86, ARM, PowerPC U-Boot: http://u-boot.sourceforge.net/

Page 28: Porting Operating Systems

28

Linux-capable open source bootloaders

Bootloader monitor description Architectures

LILO NoThe main disk bootloader for Linux

x86

GNU successor to LILO

Loads Linux from ROM without a BIOS

Loads Linux from DOS

ROMable loader for booting systems through Ethernet cards

Linux-based BIOS replacement

Versatile loader mainly intended for Compaq iPAQ

Loader from the LART hardware project

Loader used in Agenda VR3

Main loader of the LinuxSH project

Universal loader based on PPCBoot and ARMBoot

eCos-based loader

x86

x86

x86

x86

ARM

ARM

x86

MIPS

SuperH

x86, ARM, PowerPC

x86, ARM, PowerPC, MIPS, SuperH, m68k

GRUB

ROLO

Loadlin

Etherboot

LinuxBIOS

Compaq’ s bootldr

blob

PMON

sh-boot

U-Boot

RedBoot

No

No

No

No

No

No

No

Yes

Yes

Yes

Yes

Page 29: Porting Operating Systems

29

Bootloader Concepts (cont`)

Bootloader also depends on various hardware

All type CPU will execute the instructions from the defined address when power on Normally, there exists some solid storage

devices mapped to defined address ROM, EEPROM, FLASH, etc

Page 30: Porting Operating Systems

30

Bootloader Concepts (cont`)

Typical space allocation

Boot parameters

Bootloader

Kernel Root filesystem

Page 31: Porting Operating Systems

31

Bootloader Concepts (cont`)

Single stage or Multi-stage ? Multi-stage bootloader can provide more complex capability

and better ability to cross platform Bootloader booted from solid storage device can be divided

into two stages Stage1

– Written by assembly language

– Fast and simple Stage 2

– Written by C

– more complex capability

– Easy to read and modify

Page 32: Porting Operating Systems

32

Bootloader Concepts (cont`)

Two operation modes Boot loading mode (autonomous mode)

Normal working mode

Downloading mode Bootloader can download images from host end

through UART or network

Page 33: Porting Operating Systems

33

Bootloader Concepts (cont`)

Communication equipment and protocol UART (Universal Asynchronous

Receiver/Transmitter) and network UART protocol:

xmodem, ymodem, zmodem slower

Network protocol: TFTP protocol

TFTP service required

Page 34: Porting Operating Systems

34

Bootloader’s task and structure

Stage1 and stage2 Stage1

Execute from flash Copy stage2 to RAM

Stage2 Execute from RAM Copy kernel & Root file

system to RAM Load kernel & Root file

system

Memory space of stage2

stage2_startMemory space

Flash space

Root filesystem

Kernel

Bootloader stage2

Bootloader stage1

sp = stage2_end -4

0x00000000

0x00080000

0x00480000

Page 35: Porting Operating Systems

35

Bootloader’s task and structure (cont`)

Steps of stage1 (according to implement order) Hardware initialization Prepare memory space for loading stage2 Copy stage2 to memory Set stack Go to starting address of stage2

Page 36: Porting Operating Systems

36

Bootloader’s task and structure (cont`)

Fundamental hardware initialization Mask all interrupts

through CPU’s interrupt mask register or state register

Set CPU speed and clock Initialize memory Initialize LED

Ensure hardware are initialized correctly

Initialize CPU internal instruction/data cache

Page 37: Porting Operating Systems

37

Bootloader’s task and structure (cont`)

Prepare memory space for loading stage2 Determine start and end address for stage2 in RAM

Stage2_start, stage2_end Take stack space into consideration

– Stage2 is written in C

Stage2 is placed in upper part of bootloader memory space

Page 38: Porting Operating Systems

38

Bootloader’s task and structure (cont`)

Copy stage2 to memorySet stack pointer (sp)

In order to execute C code of stage2 sp points to the location before stage2 end

(sp=stage2_end – 4)

Jump to the start address of stage2

Page 39: Porting Operating Systems

39

Bootloader’s task and structure (cont`)

Memory space of stage2

stage2_startMemory space

Flash space

Root filesystem

Kernel

Bootloader stage2

Bootloader stage1

sp = stage2_end -4

0x00000000

0x00080000

0x00480000

mem_start

Page 40: Porting Operating Systems

40

Bootloader’s task and structure (cont`)

Steps of stage2 (according to implement order) Initialize the hardware devices used in stage2 Check system memory mapping Copy kernel image and root filesystem to

memory Set boot parameters Load kernel and root filesystem

Page 41: Porting Operating Systems

41

Bootloader’s task and structure (cont`)

Initialize the hardware devices used in stage2 Initialize one UART at least Initialize timer

Check system memory mapping We should know which virtual memory space

is really mapped to physical memory

Page 42: Porting Operating Systems

42

Bootloader’s task and structure (cont`)

Copy kernel image and root filesystem Memory allocation mapping

Memory range of kernel image– Normally, locate in memory_start + 0x8000

0x8000 (32k) is used to store boot parameter and kernel page table

Memory range of root filesystem– Normally, locate in memory start + 0x100000

Copy from flash

Page 43: Porting Operating Systems

43

Bootloader’s task and structure (cont`)

Set boot parameters In U-boot, boot parameters are defined in the

header file of target board Boot parameters:

boot command root device root filesystem type console memory size network configuration etc.

Page 44: Porting Operating Systems

44

Bootloader’s task and structure (cont`)

Load kernel and root filesystem Jump to memory_start + 0x8000 CPU mode

Disable interrupts (IRQs and FIQs) In SVC mode (supervisor)

Page 45: Porting Operating Systems

45

Bootloader’s task and structure (cont`)

After loading kernel Bootloader is replaced with operating system