幻灯片 1 - Google Code

Download Report

Transcript 幻灯片 1 - Google Code

再谈EDK
赵峰
上海交通大学微电子学院
Knowledge Check
What is the MHS file?
What does the PlatGen tool do?
What tool is used to place executable code in
an FPGA block RAM?
Answers
What is the MHS file?
• The MHS file is the Microprocessor Hardware Specification; it
specifies processors, hardware peripherals, bus connections,
and address spaces for the hardware
What does the PlatGen tool do?
• PlatGen takes the MHS file and creates the system and
peripheral netlists, HDL wrapper files, BMM file, etc.
What tool is used to place executable code in an FPGA
block RAM?
• The Data2Mem tool will take the BMM file and create the
proper initialization for the block RAM that is assigned to the
executable memory space
Knowledge Check
How can you add or change configuration
settings once the hardware system is build?
What does the LibGen tool do?
What is the difference between system.bit and
download.bit files?
Answers
How can you add or change configuration settings once the
hardware system is build?
• Select IP Catalog tab, expand related IP peripheral folder, select a
desired IP, and double-click on it to add it to the design
• Select an IP instance in the System Assembly View panel, right
click on it, and select desired configuration
What does the LibGen tool do?
• Read MSS file and generate libraries
What is the difference between system.bit and download.bit files?
• The system.bit file contains only hardware description whereas
download.bit file contains both hardware description as well as
executable software
Embedded Development
Tool Flow Overview
VHDL or Verilog
C Code
Standard Embedded
SW Development Flow
Code Entry
Include
the
BSP
C/C++
Cross
Compiler
and Compile the
Software
LinkerImage
?
2
Load Software
Into FLASH
Embedded
Development Kit
HDL Entry
Board Support
Package
System Netlist
Data2MEM
Compiled ELF
Standard FPGA
HW Development Flow
3
Compiled BIT
Download Combined
Image to FPGA
Debugger
Instantiate the
Simulation/Synthesis
‘System Netlist’
and Implement
Implementation
the FPGA
1
?
Download Bitstream
Into FPGA
Chipscope
RTOS, Board Support Package
Embedded System Tools
GNU software development tools
• C/C++ compiler for the MicroBlaze™ and PowerPC™ processors
(gcc)
• Debugger for the MicroBlaze and PowerPC processors (gdb)
Hardware and software development tools
•
•
•
•
•
•
•
•
•
•
•
Base System Builder Wizard
Hardware netlist generation tool: PlatGen
Software Library generation tool: LibGen
Simulation model generation tool: SimGen
Create/Import Peripherals Wizard
Xilinx Microprocessor Debug (XMD)
Hardware debugging using ChipScope™ Pro Analyzer cores
Eclipse IDE-based Software Development Kit (SDK)
Application code profiling tools
Virtual Platform generator: VPGen
Flash Writer utility
EDK Tool Flow
Library Generation
MSS
MHS
Hardware
Platform Generation
CompEDKLib
CompXLib
IP Models
ISE Models
Testbench
Stimulus
IP Library or User Repository
EDK SW
Libraries
LibGen
.a
Drivers,
MDD
SimGen
MPD, PAO
PCore
HDL
System and
Wrapper VHD
Synthesis (XST)
Embedded Software
Development
Application
Source
.c, .h, .s
PlatGen
system.BMM
Behavioral
VHD Model
ISE
Tools
NGC
UCF
NGDBuild
SimGen
NGD
Compiler (GCC)
MAP
Structural
VHD Model
.o
NCD, PCF
Linker (GCC)
PAR
NCD
ELF
system.BIT
BitGen
BitInit
system_BD.BMM
SimGen
Timing
VHD Model
download.BIT
download.CMD
iMPACT
Simulation
Simulation
Generator
Hardware Creation Flow
Platform Generator – PlatGen
• Input file → MHS and MPD
• MHS file defines the configuration of the embedded processor
system including bus architecture, peripherals and processor(s),
interrupt request priorities, and address space
• MPD file defines the configurable parameters with their default
values and available ports for a peripheral
•
•
•
•
•
•
•
Output files → system netlist, peripheral netlists, and BMM file
Creates the synthesis, HDL, and implementation directories
Generates the HDL wrapper files for the peripherals
Generates the top-level system HDL file
Extracts the peripheral netlists from the EDK install directory
Generates the BMM file
Calls XST to synthesize the top-level wrapper file
Software Flow Library Generation
Library Generator – LibGen
• Input files → MSS
• Output files → libc.a, libXil.a, libm.a
• LibGen is generally the first tool run to configure libraries
and device drivers
• The MSS file defines the drivers associated with
peripherals, standard input/output devices, interrupt
handler routines, and other related software features
• LibGen configures libraries and drivers with this information
and produces an archive of object files:
• libc.a - Standard C library
• libXil.a - Xilinx library
• libm.a - Math functions library
GNU Tools: GCC
GCC translates C source code into
assembly language
GCC also functions as the user interface
to the GNU assembler and to the GNU linker,
calling the assembler and the linker with
the appropriate parameters
Supported cross-compilers:
• PowerPC processor compiler
• GNU GCC (powerpc-eabi-gcc)
• Wind River Diab compiler (dcc)
• MicroBlaze processor compiler
• GNU GCC (mb-gcc)
C files
Cross-compiler
Assembly
Command line only; uses the settings set through the GUI
files
GNU Tools
Calls four different executables
•
•
•
•
Preprocessor (cpp0)
Language specific c-compiler
• cc1 C-programming
language
• cc1plus C++ language
Assembler
• mb-as (MicroBlaze
processor)
• powerpc-eabi-as
(PowerPC processor)
Linker and loader
• mb-ld (MicroBlaze
processor)
• powerpc-eabi-ld (PowerPC
processor)
GNU Tools: AS
Input: Assembly language files
• File extension: .s
Output: Object code
• File extension: .o
• Contains
• Assembled piece of code
• Constant data
• External references
• Debugging information
Typically, the compiler automatically
calls the assembler
Use –Wa switch if the source files are
assembly only and use gcc
Assembly files
Cross-assembler
Object files
GNU Tools: LD
Linker
Inputs:
• Several object files
• Archived object files (library)
• Linker script (mapfile)
Object
files
Linker
script
Linker/Locator
Outputs:
• Executable image (.ELF)
• Mapfile (different from linker script)
Executable
Map
Binutils: Binary Utilities
AR Archiver
• Create, modify, and extract from libraries
• Used in EDK to combine the object files of the Board Support
Package (BSP) in a library
• Used in EDK to extract object files from different libraries
OBJDUMP
• Display information from object files and executables
• Header information, memory map
• Data
• Disassemble code
• GNU executables
• powerpc-eabi-objdump
• mb-objdump
Powerpc-eabi-objdump
Text section
Memory
location
Machine
code
Assembly
instructions
Address Management
Embedded processor design requires you to manage the following:
• Address map for the peripherals
• Location of the application code in the memory space
• Block RAM
• External memory
Memory requirements for your programs are based on the following:
• The amount of memory required for storing the instructions
• The amount of memory required for storing the data associated with
the program
PowerPC Processor
Memory and peripherals
• PPC405 uses 32-bit addresses
Special addresses
• Every PowerPC™ system should have
the boot section starting at
0xFFFFFFFC
0xFFFF_FFFC
Reset Address
PLB/OPB Memory
0xFFFF_0000
Default linker options
PLB/OPB Memory
• Program space occupies a contiguous
address space from 0xFFFF0000 to
0xFFFFFFFF
• Stack size: 4 KB
• Heap size: 4 KB
Peripherals
0x0000_0000
Advanced User
Address Space
Different base address, contiguous
user address space
• The user program can run from any
memory PLB, OCM, OPB, or LMB
• To execute a program from any
address location other than default,
you must provide the compiler gcc
with a Program Start Address
Advanced User
Address Space
Different base address, noncontiguous user
address space
• You can place different components of your program
in different memories
• For example, on PowerPC systems, you can
keep your code on instruction cache memory and
the data on ZBT memory
• Noncontiguous executables that represent the
application must be created
• To do this, a linker script must be used
Object File Sections
What is an object file?
• An object file is an assembled piece of code
• Machine language:
li r31,0
=
0x3BE0 0000
• Constant data
• There may be references to external objects that are
defined elsewhere
• This file may contain debugging information
Object File Sections
.text
Text section
.rodata
Read-only data section
.sdata2
Small read-only data section (less than eight bytes)
.data
Read-write data section
.sdata
Small read-write data section
.sbss
Small uninitialized data section
.bss
Uninitialized data section
Object File Sections
.init
Language initialization code
.fini
Language cleanup code
.ctors
List of functions to be invoked at program startup
.dtors
List of functions to be invoked at program end
.got2
Pointers to program data
.got
Pointers to program data
.eh_frame
Frame unwind information for exception handling
Sections Example
int ram_data[10] = {0,1,2,3,4,5,6,7,8,9};
/* DATA */
const int rom_data[10] = {9,8,7,6,5,4,3,2,1};
/* RODATA */
int I;
/* BSS */
main(){
...
I = I + 10;
...
}
/* TEXT */
Linker Scripts
Linker scripts
•
•
•
•
Control the linking process
Map the code and data to a specified memory space
Set the entry point to the executable
Reserve space for the stack
Required if the design contains a discontinuous
memory space
Linker and Locator Flows
foo1.o
Merged
Output
Sections
.text1
foo2.o
.text2
0xFFFF
Code
.text
.data1
.bss1
Executable
Image
Locate
Link
0xF000
0xEFFF
uninitialized data
.data
0xEF00
0xEEFF
.bss
Unused
0x2000
.data2
.bss2
0x1FFF
Initialized data
0x0000
PowerPC Processor
Boot Files
Files: boot.S, boot0.S, crt0.S,
eabi.S
• Application entry point at label
_boot in boot.S
• _boot is single jump instruction
to _boot0
• _boot0 is a few instructions that
do a jump to _start in crt0.S
• _start
• Clears .bss and .sbss
sections
• Sets up stack on an eight
byte alignment
• Initializes time-base
registers to zero
• Optionally, enable FPU bit in
MSR
• Calls main()
– Calls _eabi to set R13 and R2
registers to point to .sdata and
.sdata2 sections respectively
– Performs user tasks
PowerPC Processor Script
Example
STACKSIZE = 4k;
MEMORY
{
ddr
: ORIGIN = 0x00000000, LENGTH = 32m
sram : ORIGIN = 0x10000000, LENGTH = 2m
flash : ORIGIN = 0x18000000, LENGTH = 32m
bram : ORIGIN = 0xffff8000, LENGTH = 32k - 4
boot : ORIGIN = 0xfffffffc, LENGTH = 4
}
SECTIONS
{
.text
: { *(.text) } > bram
.boot
: { *(.boot) } > boot
.data
: { *(.data) *(.got2) *(.rodata) *(.fixup)} > bram
.bss
: { *(.bss) } > bram
__bss_start = ADDR(.bss);
__bss_end
= ADDR(.bss) + SIZEOF(.bss);
}
Sections Command
This is where most of the work takes place
Output sections are named, and the input sections are grouped
and linked together into the output sections
Example:
.text
: { *(.text) *(.init) } > bram
Explanation:
• .text is the name of the output section
• { *(.text) *.(init) } includes all input sections named text and init from
the object files being linked
• > bram locates the .text output section in the next available memory
in the block RAM area
Linker Script Generator GUI
XPS contains a graphical
Linker Script Generator
Table-based GUI allows
you to define the memory
space for any section
Launch from Software
→ Generate Linker
Script, or from the
Applications Tab, rightclick on <project> →
Generate Linker Script
The tool will create a new
linker script (the old
script is backed up)
Drivers: Level 0 / Level 1
The layered architecture provides seamless integration with…
• (Layer 2) RTOS application layer
• (Layer 1) High-level device drivers that are full-featured and portable
across operating systems and processors
• (Layer 0) Low-level drivers for simple use cases
Layer 2, RTOS Adaptation
Layer 1, High-level Drivers
Layer 0, Low-level Drivers
Drivers: Level 0
Consists of low-level device drivers
Implemented as macros and functions that are designed to allow a
developer to create a small system
Characteristics:
•
•
•
•
•
Small memory footprint
Little to no error checking is performed
Supports primary device features only
No support of device configuration parameters
Supports multiple instances of a device with base address input to the
API
• Polled I/O only
• Blocking function calls
• Header files have “_l” in their names (e.g. xuartlite_l.h)
Drivers: Level 1
Consists of high-level device drivers
Implemented as macros and functions and designed to allow a
developer to utilize all of the features of a device
Characteristics:
•
•
•
•
•
•
•
Abstract API that isolates the API from hardware device changes
Supports device configuration parameters
Supports multiple instances of a device
Polled and interrupt driven I/O
Non-blocking function calls to aid complex applications
May have a large memory footprint
Typically, provides buffer interfaces for data transfers as opposed to
byte interfaces
• Header files do not have “_l” in their names (e.g. xuartlite.h)
Comparison Example
Uartlite Level 1
•
•
•
•
•
•
•
•
•
•
•
•
•
XStatus XUartLite_Initialize (XUartLite *InstancePtr, Xuint16 DeviceId)
void XUartLite_ResetFifos (XUartLite *InstancePtr)
unsigned int XUartLite_Send (XUartLite *InstancePtr, Xuint8 *DataBufferPtr, unsigned int NumBytes)
unsigned int XUartLite_Recv (XUartLite *InstancePtr, Xuint8 *DataBufferPtr, unsigned int NumBytes)
Xboolean XUartLite_IsSending (XUartLite *InstancePtr)
void XUartLite_GetStats (XUartLite *InstancePtr, XUartLite_Stats *StatsPtr)
void XUartLite_ClearStats (XUartLite *InstancePtr)
XStatus XUartLite_SelfTest (XUartLite *InstancePtr)
void XUartLite_EnableInterrupt (XUartLite *InstancePtr)
void XUartLite_DisableInterrupt (XUartLite *InstancePtr)
void XUartLite_SetRecvHandler (XUartLite *InstancePtr, XUartLite_Handler FuncPtr, void
*CallBackRef)
void XUartLite_SetSendHandler (XUartLite *InstancePtr, XUartLite_Handler FuncPtr, void
*CallBackRef)
void XUartLite_InterruptHandler (XUartLite *InstancePtr)
Uartlite Level 0
•
•
void XUartLite_SendByte (Xuint32 BaseAddress, Xuint8 Data)
Xuint8 XUartLite_RecvByte (Xuint32 BaseAddress)
Exceptions and Interrupts
Exceptions are events detected by the processor that require action
by the system software
• Typically, the result of unexpected error conditions (e.g., bus error)
• Some exceptions can be programmed to occur (e.g., FIT, PIT)
• Some exceptions are generated by external devices (e.g., CritInt)
Interrupts are automatic control transfers as a result of an exception
• Execution of the current program is suspended after the current
instruction
• Some context info is saved so execution can return to the current
program
• Execution is transferred to the interrupt handler to service the interrupt
• The interrupt handler must be registered
• The interrupt must be enabled
Hardware Interrupt Inputs
Two external inputs to the IBM PowerPC 405 processor core:
• Critical interrupt
• External interrupt
Enabled and disabled through the Machine State Register (MSR)
• MSR(CE) and MSR(EE)
• Default @RESET is disabled
FPGA design adds an interrupt controller for application-specific
requirements
• Supports 32 interrupts
Exceptions and Interrupts
Exception Code
Entry Point
Save State
Call Handler
Restore State
HANDLER
Registered Handler
Return to Program
Exceptions and Interrupts
Exception library function calls support:
• void XExc_Init(void);
• Initializes vector table, default handlers
• void XExc_RegisterHandler (Xuint8 ExceptionId, XExceptionHandler
Handler, void *DataPtr);
• Allows the registration of a handler
• void XExc_RemoveHandler (Xuint8 ExceptionId)
• Replaces the current handler with a default handler
• void XExc_mEnableExceptions (EnableMask);
• Enables Crit, NonCrit interrupts
• void XExc_mDisableExceptions (DisableMask);
• Disables Crit, NonCrit interrupts
thttpd
Thttpd
非常小巧的轻量级web server
仅仅提供了HTTP/1.1和简单的CGI支持
thttpd支持多种平台,如FreeBSD, SunOS,
Solaris, BSD, Linux, OSF等
其资源占用小
Web服务器通过调用CGI程序实现和Web
浏览器的交互
• CGI程序接受Web浏览器发送给Web服务
器的信息,进行处理,将响应结果再回送给
Web服务器及Web浏览器。
CGI程序一般完成Web网页中
• 表单(Form)数据的处理、
• 数据库查询
• 实现与传统应用系统的集成等工作。
CGI
The Common Gateway Interface
The method by which a web server can get data,
and display that data to users via the web
A CGI can be written in any programming
language (ex. C/C++, C Shell, Perl, VB)
CGI接口标准包括:标准输入、环境变量、标准输出三部
分。
标准输入
• CGI程序可通过标准输入(stdin)从Web服务器得到输入信息,如Form中的
数据,这就是所谓的向CGI程序传递数据的POST方法。
环境变量
• 操作系统提供了许多环境变量, 应用程序可以存取它们。Web服务器和
CGI接口又另外设置了自己的一些环境变量,用来向CGI程序传递一些重
要的参数。CGI的GET方法还通过环境变量QUERY-STRING向CGI程序传递
Form中的数据。
标准输出
• CGI程序通过标准输出(stdout)将输出信息传送给Web服务器。传送给
Web服务器的信息可以用各种格式,通常是以纯文本或者HTML文本的形式
How does CGI work?
Web Browser
(on client)
Application
Server
(on server)
CGI
User
1. HTTP
request
2. Call CGI
4. HTTP
response
3. CGI
program’s
response
HTML
<html>
<head><title>X LED Controler</title></head>
<body>
<H2>X-LED Controler</H2>
<H2>
<a href='xledctl.cgi?xflag=0'>Xled0</a><br>
<a href='xledctl.cgi?xflag=1'>Xled1</a><br>
<a href='xledctl.cgi?xflag=2'>Xled2</a><br>
<a href='xledctl.cgi?xflag=3'>Xled3</a><br>
<a href='xledctl.cgi?xflag=4'>Xled4</a><br>
<a href='xledctl.cgi?xflag=5'>Xled5</a><br>
<a href='xledctl.cgi?xflag=6'>Xled6</a><br>
<a href='xledctl.cgi?xflag=7'>Xled7</a><br>
<br>
<a href='xledctl.cgi?xflag=8'>Xled_on</a><br>
<a href='xledctl.cgi?xflag=9'>Xled_off</a><br>
</H2>
input LED light number (0 ~ 7)<br>
<FORM ACTION="xledctl.cgi" METHOD=GET>
<INPUT NAME="input1" TYPE=TEXT SIZE=12><BR>
<INPUT TYPE=SUBMIT VALUE="Commit">
</FORM><br>
CGI
WEB Page
unsigned char *paramStr;
printf("Content-type: text/html\r\n");
paramStr=getenv("QUERY_STRING");
if (paramStr[0]=='x')
{
int seq;
seq = paramStr[6]-'0';
if (seq<=7)
c = 1 << seq;
else if (seq ==8)
c = 0xff;
else
c = 0x00;
} else
{
int i = 0;
c = 0x00;
for(i = 7; paramStr[i] != '\0';i++)
if (((paramStr[i]-'0')>=0) && ((paramStr[i]-'0')<=7))
c |= 1 << (paramStr[i]-'0');
</body>
</html>
}
Project: remote control
Technology
• Hardware + OS
• Device driver: Led, Switch
• Application: CGI, HTML
• thttpd&cgi&html.doc
Design Flow
• Specification:
• Embedded application