1 / 45

UEFI 与固件程序设计

UEFI 与固件程序设计. Tel : 69589584 Email:wang.box@163.com. 同济大学软件学院. Agenda. Overview DXE Core DXE Dispatcher DXE Architectural Protocol DXE Services DXE Drivers. Exposed Platform Interface. Pre Verifier. OS-Absent App. CPU Init. Transient OS Environment. verify. Chipset Init.

Download Presentation

UEFI 与固件程序设计

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. UEFI与固件程序设计 Tel:69589584 Email:wang.box@163.com 同济大学软件学院

  2. Agenda • Overview • DXE Core • DXE Dispatcher • DXE Architectural Protocol • DXE Services • DXE Drivers

  3. Exposed PlatformInterface Pre Verifier OS-AbsentApp CPUInit Transient OS Environment verify Chipset Init Device, Bus, or Service Driver Board Init Transient OS Boot Loader OS-PresentApp EFI Driver Dispatcher Boot Manager Intrinsic Services ? Final OS Environment Final OS Boot Loader security Pre EFI Initialization (PEI) Driver Execution Environment (DXE) Boot Dev Select(BDS) Transient System Load (TSL) Run Time (RT) After Life (AL) Security (SEC) Power on [ . . Platform initialization . . ] [ . . . . OS boot . . . . ] Shutdown Boot Flow DXE IPL DXE MAIN

  4. Why DXE • No DXE • BIOS features coded in proprietary fashion • ODM has to port features from IBV to IBV • Third parties can not provide value added pre OS features • Single source file controls boot flow • With DXE • Works like OS, large group of companies can write drivers • Modular systems enabled • FLASH on a plug in module to support module

  5. Properties of DXE Foundation • Depends only on HOB list • State initialization passed in from PEI • No hard coded addresses in DXE • Foundation code can be loaded anywhere • No hardware specifics in DXE Foundation • Access to hardware abstracted by a set of architectural protocols (APs) • APs implemented as drivers • Only DXE Foundation may call APs • APs encapsulate CPU, chipset, board specifics

  6. DXE Components • DXE Core – The main DXE executable binary responsible for dispatching drivers and provide basic services. • DXE Driver – code loaded by the core to do various initializations, produce protocols and other services. • DXE Dispatcher – The part of the DXE core that searches for and executes the drivers in the correct order. • DXE Architectural Protocols – Produced by DXE drivers to abstract DXE from hardware. • UEFI System Table – Contains pointers to all the EFI service tables, configuration tables, handle database, and console device.

  7. Agenda • Overview • DXE Core • DXE Dispatcher • DXE Architectural Protocol • DXE Services • DXE Drivers

  8. DXE Core • No hard coded addresses allowed • Single Binary for each CPU Architecture • Well specified and validated • Written in C. No assembly allowed • Consumes • HOB List • Architectural Protocols • Produces • Dispatcher • EFI Boot Services • EFI Runtime Services

  9. System System System System System System I/O MMIO Firmware Firmware System DXE Memory Memory Memory Memory Memory Memory Resources Resources Devices Volumes Memory Drivers HOB List System DXE PHIT . . . Memory HOB HOB HOB HOB HOB Drivers HOB EFI Boot Services Table DXE Services EFI System Table EFI Runtime Services Table DXE Core / DXE Dispatcher Monotonic Security Metronome BDS Runtime Status Code Counter Architectural Architectural Architectural Architectural Architectural Architectural Protocol Protocol Protocol Protocol Protocol Protocol Watchdog Real Time CPU Timer Variable Reset Timer Clock Architectural Architectural Architectural Architectural Architectural Architectural Protocol Protocol Protocol Protocol Protocol Protocol Hardware DXE Core Block Diagram

  10. DXE Core EFI Boot Services DXE Services Task Priority Event and Timer Image Global Coherency Domain Services Services Services Services Memory Protocol Handler Driver Support Dispatcher Services Services Services Services PE/COFF HOB Firmware Volume Driver Loader Parser DXE Dispatcher Section Firmware Flush Instruction Extraction Volume Protocol Cache Block Driver Driver (Read - Only) Switch SetJump Dependency Expression Decompress (Memory Evaluator Stacks LongJump Mapped) Driver DXE Core Functional Blocks

  11. Active Consoles UEFI Runtime Services Table UEFI System Input Console Variable Services Table Output Console Real Time Clock Services Standard Error Console Reset Services Status Code Services UEFI Boot Services Table Virtual Memory Services Task Priority Level Services Version Information Memory Services Event and Timer Services UEFI Specification Version Protocol Handler Services Firmware Vendor Image Services Firmware Revision Driver Support Services System Configuration Table DXE Services Table DXE Services Table Global Coherency Domain Services HOB List Dispatcher Services ACPI Table SMBIOS Table Protocol Interface … Handle Database Protocol Interface Protocol Interface Protocol Interface SAL System Table Protocol Interface Protocol Interface Boot Services and Structures Runtime Services and Structures Only available prior to OS runtime Available before and during OS runtime DXE Core Data Structures

  12. DXE Main • Responsible for Initializing DXE Core • Consumes HOB List • Builds EFI System Table • Builds EFI Boot Services Table • Builds EFI Runtime Services Table • Builds DXE Services Table • Makes Memory-Only Boot Services Available • Hands off control to the DXE Dispatcher • Requires access to Firmware Volumes • Requires LoadImage(), StartImage(), Exit() • May require decompression service

  13. DXE Core Initialization • Initialize EFI Boot Services Table • Global Variable in DXE Core • All services return EFI_NOT_AVAILABLE_YET • Initialize DXE Services Table • Global Variable in DXE Core • All services return EFI_NOT_AVAILABLE_YET • Initialize Memory-Only TPL Services • RaiseTPL(), RestoreTPL() • Initialize Memory Services (Parses HOB List) • AllocatePages(), AllocatePool(), FreePages(), FreePool() • Allocate EFI System Table • Allocated from EfiRuntimeServicesData • Allocate EFI Runtime Service Table • Allocated from EfiRuntimeServicesData • All services return EFI_NOT_AVAILABLE_YET

  14. DXE Core Initialization • Initialize GCD Services (Parses HOB List) • Initialize Driver Support Services • Initialize Event Services • Initialize Protocol Services • Initialize Miscellaneous Services • Add HOB List to System Configuration Table • Part of EFI System Table • Provides other component access to HOB List • Initialize Image Services • Creates Image Handle for DXE Core itself

  15. DXE Core Initialization • Create event for each Architectural Protocol • Informs DXE Core when AP is installed • Used to complete EFI Boot Services • Used to complete EFI Runtime Services • Initialize Firmware Volume Drivers • Provides file access to FVs discovered by PEI • Initialize File Decompression (Optional) • Hand control to DXE Dispatcher

  16. Agenda • Overview • DXE Core • DXE Dispatcher • DXE Architectural Protocol • DXE Services • DXE Drivers

  17. Dispatcher Goals • Resolve Execution Ordering Among DXE Drivers • Drivers may be written by different organizations • Different divisions • Different companies • Support Known Business Issues • Emergency patches • “Control of Destiny” for • System developer • Add-in card developer • Driver developer • Expansion Hooks for e.g. Security

  18. DXE Dispatcher Model • Some of each • A Priori list of drivers to be run first • Defined by system developers • May be null • Generally implemented as pre-load dispatch queue • Requirements based dispatching for the rest • General Concept: Driver provides a list of requirements that must be met before it can be dispatched. • A syntax that gets the ordering to about 90% is ok • EFI primitives exist to do finer granularity ordering

  19. Requirements • Protocols are the “Requirements” • Represented by their GUIDs • The fundamental primitive is • “Does this protocol exist?” • Hits the 90% target • Driver may have to do RequestProtocolNotify for finer granularity • “List of Requirements”: Boolean Expressions • Operators: And, Or, Not (&, |, !) • Special operators: Before, After • Run this driver just before or just after that one • Used for patching • Internally, stored in driver header as Postfix (RPN) for quicker processing • Tool support planned

  20. Driver Execution Environment DXE Foundation Dispatcher Main Firmware Volume Handle Database DXE Dispatcher Driver C Loaded Image Protocol 1 Dependent: A B C Scheduled: Driver B (CPU_AP) Initializing: Initialized: Driver A (Timer_AP) Dependency Expression: CPU_AP DXE Foundation FALSE Evaluates To:

  21. Driver Execution Environment DXE Foundation Dispatcher Main Firmware Volume Handle Database DXE Dispatcher Driver C Loaded Image Protocol 1 Dependent: A B C Scheduled: Driver B (CPU_AP) Initializing: Initialized: Driver A (Timer_AP) Dependency Expression: CPU_AP TRUE DXE Foundation FALSE TRUE Evaluates To:

  22. Driver Execution Environment DXE Foundation Dispatcher Main Firmware Volume Handle Database DXE Dispatcher ` Driver C Loaded Image Protocol 1 C Dependent: A B C Scheduled: B Driver B (CPU_AP) Initializing: Initialized: Driver A (Timer_AP) Dependency Expression: CPU_AP AND TIMER_AP CPU_AP TRUE DXE Foundation FALSE FALSE TRUE Evaluates To:

  23. Driver Execution Environment CPU Architectural Protocol Driver B Initializes 2 DXE Foundation Dispatcher Main Firmware Volume Handle Database DXE Dispatcher ` Driver C Loaded Image Protocol 1 C Dependent: A B C Scheduled: B Driver B (CPU_AP) Initializing: Initialized: Driver A (Timer_AP) B Dependency Expression: CPU_AP AND TIMER_AP CPU_AP TRUE DXE Foundation FALSE FALSE TRUE Evaluates To:

  24. Driver Execution Environment CPU Architectural Protocol Driver B Initializes 2 DXE Foundation Dispatcher Main Firmware Volume Handle Database DXE Dispatcher ` Driver C Loaded Image Protocol 1 C Dependent: A B C Scheduled: B Driver B (CPU_AP) Initializing: Initialized: Driver A (Timer_AP) B Dependency Expression: CPU_AP AND TIMER_AP CPU_AP TRUE CPU_AP DXE Foundation TRUE FALSE FALSE TRUE Evaluates To:

  25. Driver Execution Environment CPU Architectural Protocol 2 DXE Foundation Dispatcher Main Firmware Volume Handle Database DXE Dispatcher ` Driver C Loaded Image Protocol 1 C Dependent: A B C C Scheduled: B A Driver B (CPU_AP) Initializing: Initialized: Driver A (Timer_AP) B Dependency Expression: CPU_AP AND TIMER_AP CPU_AP TRUE CPU_AP CPU_AP AND TIMER_AP DXE Foundation TRUE FALSE FALSE TRUE Evaluates To: FALSE

  26. Driver Execution Environment Driver A Initializes CPU Architectural Protocol 2 Timer ArchitecturalProtocol 3 DXE Foundation Dispatcher Main Firmware Volume Handle Database DXE Dispatcher ` Driver C Loaded Image Protocol 1 Dependent: A C Scheduled: Driver B (CPU_AP) Initializing: Initialized: Driver A (Timer_AP) B A Dependency Expression: CPU_AP AND TIMER_AP CPU_AP TRUE CPU_AP CPU_AP AND TIMER_AP DXE Foundation TRUE FALSE FALSE TRUE Evaluates To: FALSE

  27. Driver Execution Environment Driver A Initializes CPU Architectural Protocol 2 Timer ArchitecturalProtocol 3 DXE Foundation Dispatcher Main Firmware Volume Handle Database DXE Dispatcher ` Driver C Loaded Image Protocol 1 Dependent: A C Scheduled: Driver B (CPU_AP) Initializing: Initialized: Driver A (Timer_AP) B A Dependency Expression: CPU_AP AND TIMER_AP DXE Foundation Evaluates To: TRUE

  28. Driver Execution Environment Driver C Initializes CPU Architectural Protocol 2 Timer ArchitecturalProtocol 3 DXE Foundation Dispatcher Main Firmware Volume Handle Database DXE Dispatcher ` Driver C Loaded Image Protocol 1 Dependent: A C Scheduled: B Driver B (CPU_AP) Initializing: Initialized: Driver A (Timer_AP) B A C Dependency Expression: CPU_AP AND TIMER_AP DXE Foundation Evaluates To: TRUE Execution Order Determined at Runtime Based on Dependencies

  29. Agenda • Overview • DXE Core • DXE Dispatcher • DXE Architectural Protocol • DXE Services • DXE Drivers

  30. DXE – Architectural Protocols What are Architectural Protocols? • Low level protocols that support DXE APIs • Provide support for boot services and runtime services • Typically touch hardware • Only called by DXE core (directly)

  31. System System System System System System I/O MMIO Firmware Firmware System DXE Memory Memory Memory Memory Memory Memory Resources Resources Devices Volumes Memory Drivers HOB List System DXE PHIT . . . Memory HOB HOB HOB HOB HOB Drivers HOB EFI Boot Services Table DXE Services EFI System Table EFI Runtime Services Table DXE Core / DXE Dispatcher Monotonic Security Metronome BDS Runtime Status Code Counter Architectural Architectural Architectural Architectural Architectural Architectural Protocol Protocol Protocol Protocol Protocol Protocol Watchdog Real Time CPU Timer Variable Reset Timer Clock Architectural Architectural Architectural Architectural Architectural Architectural Protocol Protocol Protocol Protocol Protocol Protocol Hardware DXE Core

  32. DXE – Architectural Protocols • Boot Service APs • CPU – cache, interrupts, reset, timers • Metronome – periodic signals • Timer – event services • Boot Device Selection (BDS) • Watchdog Timer • Security • Runtime Service APs • Runtime – virtual addressing • Real Time Clock • Reset • Variable Services – nonvolatile storage access • Monotonic Counter • Status Code

  33. DXE – Architectural Protocols • Some APs have dependencies on others. • Timer requires interrupts (CPU) and IO access • Watchdog timer requires timer and IO access • Reset requires CPU and IO access • Dependencies can be satisfied by using one or more of the following methods to control load order • Dependency grammar to have DXE load in the correct order • RegisterProtocolNotify() to be notified when required AP gets loaded • Apriori list – file in the file system containing list of filename GUIDs

  34. DXE – Architectural Protocols BDS Security Status Code Runtime Services Variable Services Watchdog Timer Load Order Reset Realtime Clock Timer Metronome CPU PCI I/O Abstraction DXE Core FDVP

  35. DXE – Architectural Protocols • CPU APs • FlushDataCache() • EnableInterrupt()/DisableInterrupt()/GetInterruptState() • RaiseTPL() and RestoreTPL() • Init() • reset control • RegisterInterruptHandler() • Used by timer initialization • GetTimerValue() • SetMemoryAttributes()

  36. DXE – Architectural Protocols • Watchdog Timer • RegisterHandler() • SetTimer() • GetTimer() • Boot Device Select (BDS) • Entry() • to hand off system to OS loader or system utility • Security • FileAuthenticationState()

  37. DXE – Architectural Protocols • Real Time Clock APs • RT->GetTime() • RT->SetTime() • RT->GetWakeupTime() • RT->SetWakeupTime() • Reset APs • RT->ResetSystem() – for cold or warm system reset • Status Code • RT->ReportStatusCode()

  38. Agenda • Overview • DXE Core • DXE Dispatcher • DXE Architectural Protocol • DXE Services • DXE Drivers

  39. DXE Services • Dispatcher Services • Dispatch() • Schedule() • Trust() • Global Coherency Domain Services • Used to manage CPU visible memory resources • Used to manage CPU visible I/O resources

  40. DXE GCD Services • GCD Memory Services • AddMemorySpace() • AllocateMemorySpace() • FreeMemorySpace() • RemoveMemorySpace() • GetMemorySpaceDescriptor() • SetMemorySpaceAttributes() • GetMemorySpaceMap() • GCD I/O Services • AddIoSpace() • AllocateIoSpace() • FreeIoSpace() • RemoveIoSpace() • GetIoSpaceDescriptor() • GetIoSpaceMap()

  41. Agenda • Overview • DXE Core • DXE Dispatcher • DXE Architectural Protocol • DXE Services • DXE Drivers

  42. DXE Drivers • DXE drivers are DXE Components that • Initialize the platform • Provide the services required to • boot an UEFI-compliant operating system • Or • a set of UEFI-compliant system utilities. • DXE drivers may consume • UEFI Boot Services • UEFI Runtime Services • DXE Services

  43. Classification of DXE Drivers • According to Functionality • Early DXE Drivers • DXE Drivers that follow the UEFI Driver Model • According to Life Cycle • Boot service drivers • Runtime drivers

  44. Early DXE Drivers • Early DXE Drivers • Basic services • Processor initialization code • Chipset initialization code • Platform initialization code • DXE Architectural Protocols • Not all services are available • Execution order depends on dependency expressions • As much initialization should be deferred to DXE drivers that follow UEFI Driver Model

  45. DXE Drivers that Follow theUEFI Driver Model • DXE Drivers that follow the UEFI Driver Model • Do not touch any hardware resources when they initialize • Register a Driver Binding Protocol interface • Ultimately provide software abstraction for console devices and boot devices • Do not need to be concerned with dependency expressions • Selected by BDS

More Related