UEFI与固件程序设计 Tel:69589584 Email:wang.box@163.com 同济大学软件学院 Legacy BIOS Interface Legacy BIOS provides OS with I/O routines via x86 software interrupts – Normally for OS booting – Can also be used at runtime by legacy OSes (DOS, Windows 3.x, Windows 9X) Typical software interrupts used by legacy OS loaders – INT 10h – Video display – INT 13h – Floppy/Hard disk I/O – INT 15h – Extended memory support, Report memory map, … – INT 16h – Keyboard input – INT 19h – Bootstrap loader – INT 1Ah – System date and time, PCI BIOS real mode interface 继续 返回 Boot OS under Legacy BIOS BIOS identifies all IPL(Initial Program Load) devices in the system and determines the boot order during POST – BAIDs (BIOS Aware IPL Device) – PnP ISA/PCI Cards Legacy ISA/PCI cards may hook INT 19h to control the boot process BIOS invokes INT 19h after POST to start booting OS The INT 19h handler attempts to boot from IPL devices sequentially in the boot order, if failed then next Boot flow when normally booting from hard disk – Hard disk is partitioned to up to 4 primary partitions so that multiple OSes can co-exist – The first sector (cylinder 0, head 0, sector 1) referred to as MBR (Main Boot Record) contains OS independent bootstrap code – INT 19h handler relies on INT 13h to read MBR into 0:7C00h – INT 19h handler verifies the validity of MBR – INT 19h handler transfers the control to the MBR bootstrap code by jumping to 0:7C00h 继续 返回 Hard Disk Partition and MBR Layout Legacy Master Boot Record 继续 返回 Hard Disk Partition and MBR Layout Offset Length (byte) Field Description 0 1 Boot Indicator 1 1 Starting Head 2 1 Starting Sector 3 1 Starting Cylinder 4 1 System ID 5 1 Ending Head 6 1 Ending Sector 7 1 Ending Cylinder 10-bit number, with a maximum value of 1023 8 4 Relative Sectors The offset from the beginning of the disk to the beginning of the volume, counting by sectors. 12 4 Total Sectors The total number of sectors in the volume 00 – inactive 80 - active Bit 0~5 sector number Bit 6~7 upper two bits of Starting Cylinder 10-bit number, with a maximum value of 1023 Defines the volume type Bit 0~5 sector number Bit 6~7 upper two bits of Ending Cylinder Partition Table Entry 继续 返回 What Does MBR Do? Replicate itself to a memory range at lower address to make room for the coming OS bootstrap code Parse the partition table to find the active partition Load the first sector of the active partition to memory at 0:7C00h Verify the validity of the sector as a bootstrap sector Transfer the control to the OS bootstrap sector by jumping to 0:7C00h OS specific bootstrap process starts Refer to UEFI Specification Revision 2.2 section 5.2 继续 返回 UEFI Boot Mechanisms File level boot – EFI_SIMPLE_FILE_SYSTEM_PROTOCOL – EFI_LOAD_FILE_PROTOCOL Boot options are defined via Boot#### variables – Two types of boot options UEFI OS boot loaders Other UEFI applications – System firmware and OS installer can set to a known set of boot options UEFI boot manager attempts to load and execute boot options in the order defined by the BootOrder variable – If a boot option failed and the device path points directly to an EFI_SIMPLE_FILE_SYSTEM_PROTOCOL device and specify no exact file, then search for a default application to boot per removable media boot behavior If no valid boot options are present, a default behavior is defined – Enumerate all removable media devices followed by all fixed media devices – Removable media boot behavior applies to the devices support EFI_SIMPLE_FILE_SYSTEM_PROTOCOL – Otherwise, attempt to boot the device via the EFI_LOAD_FILE_PROTOCOL Removable media boot behavior – \EFI\BOOT\BOOT{machine type short-name}.EFI 继续 返回 EFI GUIDed Partition Table (GPT) Partitioning Scheme 继续 返回 GPT Advantages over MBR Partition Table 64-bit Logical Block Addressing. Supports many partitions. Uses a primary and backup table for redundancy. Uses version number and size fields for future expansion. Uses CRC32 fields for improved data integrity. Defines a GUID for uniquely identifying each partition. Uses a GUID and attributes to define partition content type. Each partition contains a 36 Unicode character human readable name. 继续 返回 UEFI System Partition Persistent store on large mass storage media types for storing UEFI OS boot loader images, drivers/applications to extend platform firmware capabilities and other data files Infrastructure to increase platform value-add without significantly growing the need for nonvolatile platform memory Place can be shared by firmware developers, OEMs, OSVs and third parties Based on FA32 file system Identification – Legacy MBR partitioning scheme: new partition type 0xef – GPT: C12A7328-F81F-11d2-BA4B-00A0C93EC93B 继续 返回