the 4 th linux seminar firmware in linux mar 26, 2000 ssmlug byungsoo jung

46
The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung http://alpha.secsm.org

Upload: cody-chandler

Post on 17-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

The 4th Linux SeminarFirmware in Linux

Mar 26, 2000ssmLUG

Byungsoo Jung

http://alpha.secsm.org

Page 2: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

What’s the Firmware?

• BIOS– Low Level, Loading the OS kernel.

• Monitor Program– As a part of BIOS– mainboard debuging

• OS Kernel– Monolithic in Linux– Currently micro kernel

Page 3: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

Developing Tools• GAS 와 Binutils

– GNU Assembler and Binary utilities

• NASM– Free Assembler for i86

• GCC– GNU C compiler– I386,Alpha,PowerPC,MIPS,ARM,M68K

Page 4: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

Simple GAS source code

• Get the Assembly source code from C source code– % gcc –S hello.c

• Compile with GAS– % as –o hello.o hello.S

• Get the executabable file with GCC– % gcc –o hello hello.o

Page 5: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

.file "hello.c"

.version "01.01"

gcc2_compiled.:

.section .rodata

.LC0:

.string "Hello World!\n"

.text

.align 4

.globl main

.type main,@function

main:

pushl %ebp

movl %esp,%ebp

pushl $.LC0

call printf

addl $4,%esp

.L1:

leave

ret

.Lfe1:

.size main,.Lfe1-main

Page 6: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

Simple GAS example#

# File : hello.S

# Author : Byungsoo Jung

# Date : Aug 8, 1999

#

.data # section declaration

msg:

.string "Hello, world!" # our dear string

msgend:

.equ len, msgend - msg # length of our dear string

.text # section declaration

# we must export the entry point to the ELF linker or

.global _start # loader. They conventionally recognize _start as their

# entry point. Use ld -e hello to override the default.

Page 7: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

_start:

# write our string to stdout

movl $4, %eax # system call number (sys_write)

movl $1, %ebx # first argument: file handle (stdout)

movl $msg, %ecx # second argument: pointer to message to write

movl $len, %edx # third argument: message length

int $0x80 # INT 80h

# and exit

movl $1,%eax # system call number (sys_exit)

xorl %ebx,%ebx # first syscall argument: exit code

int $0x80 # INT 80h

Page 8: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

Making CrossGCC

• Patch packages for the CrossGCC • Configure for CrossGCC• Make CrossGCC with Makefile• Installing CrossGCC

Page 9: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

CrossGCC for ARM

• Binutils for ARM– # tar zxvf binutils-2.9.5.0.24.tar.gz– # cd bintutils-2.9. 5.0.24– # export CC=/usr/bin/gcc– # configure –target=arm-linux– # make– # make install

Page 10: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

CrossGCC for ARM

• GCC for ARM– # export CC=/usr/bin/gcc – # tar zxvf gcc-core-2.95.1.tar.gz– # cd gcc-core-2.95.1– # gzip –d gcc-2.95-diff-990730.gz– # patch –p0 < gcc-2.95-diff-990730– # configure –target=arm-linux– # make– # make install

Page 11: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

I. BIOS : Alpha MILO and OpenBIOS

• Alpha MILO– Introduction on the

Alpha MILO

• OpenBIOS Project– Overview on the

OpenBIOS Project

Page 12: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

II. Monitor Program : PROM for MIPS

• PROM Monitor Program : PROM– Serial Monitoring and Program

Downloading– Ethernet Monitoring and Program

Downloading

Page 13: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

III. Embedded Linux Kernel : ELKS

• Embedded Linux Kernel : ELKS– Introduction on ELKS – ELKS Kernel Structure– ELKS Device Driver

Page 14: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

I. BIOS

ssmLUGByungsoo Jung

Alpha MILO 와 OpenBIOS

http://alpha.secsm.org

Page 15: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

Alpha MILO

Page 16: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

Alpha MILO’s History

• At 1993, Jim Paradis in Alpha Migration Tools Group had a project Linux porting on Alpha AXP

• At 1994, John Hall, senior manager, gave the Jensen to Linus Torvals

• At 1994, Dave Rusling made MILO bootloader for Alpha

• Now, Jay Easterbrook porting XFree86 to the Alpha Linux

Page 17: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

What’s the MILO?

• MILO’s function– PALcode– Memory Setup code– Video Code– Linux kernel code– File System support (ext2, fat, iso9660)– User interface code– Kernel interface code– NVRAM code

Page 18: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

MILO’s structure

• Two part– System indepent part : MILO– Most System dependt part : PALcode

• Code– MILo core : about 24,000 lines– PALcode : about 1,1000 lines– X86 emulation : about 1,6000 lines– Etc : about 40,000 lines

Page 19: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

Alpha’s history

• At 1988, Dick Sites and Rich Witek had a project designing Alpha Architecture

• They predicted it would be a 64bit world in the future

• They created Alpha architecture in the long peorid more than 10 years

Page 20: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

PALcode’s history

• New Architecture -> New Instruction?– They solved this problem with PALcode.

• PALcode is like software emulation– FX32 : x86 emulator– Freeport Express : sparc emulator

Page 21: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

PALcode’s structure

– Power-Up Initialization– Memory management control– Interuppt and exception

control– Privileged instructions– VAX and x86 instruction

emulation

Page 22: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

Making PALcode

Page 23: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

PALcode’s Image

Page 24: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

MILO’s image

Page 25: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

MILO Loading

• Loading MILO from System firmware– Windows NT ARC Firmware– SRM Console

• Loading MILO from Debug monitor

• Loading MILo from Flash

Page 26: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

OpenBIOS

Page 28: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

OpenBIOS’s structure : similar to the OpenFimware

OpenFirmware’s Structure

Page 29: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

Initial state of i386 in boot

Page 30: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

How to boot in i386?

• At Reset– CS : 0xFFFF F000h– EIP : 0x0000 FFF0h

• Absolut physical address– CS:EIP : 0xFFFF FFF0h– ROM BIOS intial routine

Page 31: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

Startup code in OpenBIOSSEGMENT .text

BITS 16

; entry point into startup code - the bootstrap will vector

; here with a near JMP generated by the builder. This

; label must be in the top 64K of linear memory.

global _main

_main:

jmp startup

sig: db 0xde, 0xad, 0xbe, 0xef

startup:

mov bx, cs

mov ds, bx

xor bx, bx ; es:bx == 0000:0000

mov es, bx

mov fs, ax ; Might contain BIST result

mov gs, dx ; CPU model/rev info

CPU_TEST

PORT_80 0x01

Page 32: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

Application of OpenBIOS

• Free i386 PC BIOS– Finally no commertial software in PC!– No trivial job for DOS 1.0 and fast

booting

• Linux Cluster– Linux BIOS project in Bewolf project in

NANL(Los Alamos National Laboratory)

Page 33: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

II. Monitor Program

ssmLUGByungsoo Jung

PMON for MIPS

http://alpha.secsm.org

Page 34: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

PMON for MIPS

Page 35: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

Introduction to the PMON

• Made by Phil Bunce for MIPS PROM monitor program

• Support the LSI logic MIPS CPU• Support the serial and ethernet• Source code available• http://www.carmel.com/pmon

Page 36: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

PMON’s environment• PMON : the general debug monitor

– Require about 300KB memory– Support serial and ethernet

• SerialICE-1A : with control board– Same as PMON’s function– Require about 1KB memory

• SerialICE-1B : no control board– Same as PMON’s function– Support only Windows 9x/NT

Page 37: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

PMON’s directory• imon : source code for SerialICE• pmon : source code for PMON• mon : main source code for PMON and SerialICE• lib : C runtime library for PMON and SerialICE• bsps : the drivers and kernels that are need for

SerialICE-1. • include : the include files used by this package• examples : example programs for execution

under PMON and the SerialICE • tools : tools that are executed on the host

Page 38: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

PMON’s usage

• RS232 serial port– % tip –19200 hadwire– % set hostport tty0– PMON> set dlecho off– PMON> set dlproto none– PMON> load –c “cat

bubble.bin”– PMON> g

• Ethernet port– Set the host ip in /etc/hosts

as 210.118.74.129 beta– PMON> set etheraddr

08:00:69:03:00:00– # arp –s beta

08:00:69:03:00:00– PMON> set hostport

ethernet– PMON> load– % tftp beta

tftp> put bubble.bintftp> quit

– PMON> g

Page 39: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

III. Embedded Linux Kernel

ssmLUGByungsoo Jung

ELKS

http://alpha.secsm.org

Page 40: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

ELKS

Page 41: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

Commertial Embedded Linux

• Lineo– Embedix– PowerPC, x86– Close relation with

Motorolla

• FSMLabs + Synergy– Real Time Linux– VME, CompactPCI– PowerPC, M68K

• Transmeta– Crusoe (x86 emulation)– Linux Tobals

Page 42: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

ELKS Kernel

• Embedded Linux Kernel• 512KB ROM and 1MB RAM• Now, only 16bit x86

Page 43: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

ELKS’s Structure

• Kernel– i86 8086 boot code in i86 directory

• File system– minix : MINIX file system– elksfs : ELKS file system– romfs : ROM file system

• Device Driver– serial : serial device driver– parallel : parallel device driver– network : ethernet device driver

Page 44: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

ELKS’s directory

• 1. arch/ • 2. kernel/ • 3. fs/ • 4. lib/• 5. scripts/• 6. include/• 7. modules/• 8. Documentation/• 9. init/• 10. net/

Page 45: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

booting of ELKS

• ROM BIOS– Move the first sector to the 0x7c00 in

memory

• arch/i86/bootsect.S– Move itself to the 0x90000 and jump

it.

• arch/i86/boot/setup.S– System initialize

Page 46: The 4 th Linux Seminar Firmware in Linux Mar 26, 2000 ssmLUG Byungsoo Jung

Thanks a lot!