Summary of the invention
Object of the present invention, mainly in order to solve the defect of above-mentioned prior art, provides a kind of implementation method of the UEFI firmware based on Godson desktop computer.According to this method, can realize out on Godson desktop computer meeting that international mainstream UEFI firmware specification, extensibility are strong, the fastener product of perfect in shape and function, to support the normal start-up and operation of Godson desktop computer.
Based on an implementation method for the UEFI firmware of Godson desktop computer, firmware is divided into hardware abstraction layer, firmware core layer, device protocol layer and firmware application layer.
Wherein, hardware abstraction layer realizes the initialization of the key hardware components such as processor, internal memory, chipset, carries out packaging and abstract and realize initialization, simultaneously for upper layer module provides the function interface of access bottom hardware equipment to other plate level hardware.It comprises processor driver module, chipset driver module and peripheral hardware driver module, and processor driver module completes the initial work of processor, internal memory, and provides the interface of access processor and internal memory; Chipset driver module mainly completes the initial work of the Central-South north bridge chips of Godson desktop computer hardware platform, comprises initialization and the Resourse Distribute work of bridge sheet itself and each peripheral control unit, and provides the interface of access north and south bridge; The mainly driving of various peripheral hardware on mainboard of peripheral hardware driver module, as video card, hard disk, keyboard, USB device, network interface card etc., each peripheral hardware can corresponding (or multiple) driver module.
Firmware core layer is similar to the kernel of operating system, sets up the system service table in UEFI, carries out the unified management of all modules in firmware and the management of various resource.It comprises firmware core loading module, firmware nucleus module and architecture functional module, firmware core loading module is responsible for loading firmware nucleus module, and prepare running environment for it, service (Runtime Service) table when firmware nucleus module is responsible for setting up the startup service (Boot Service) in UEFI specification and runs, load, run other functional modules, what manage between each module is mutual, realize the management of internal memory, realize and safeguard tick interrupt and case mechanism, realize and safeguard the level of privilege mechanism of firmware application, realize the administrative mechanism of the Protocol defined in UEFI specification, realize other Mechanism and FunctionsDNAs that UEFI code requirement realizes, as debugging interface, compression algorithm, variable storage/process etc.Architectural Protocol in architecture Implement of Function Module UEFI specification, comprises multiple functional module, and each module realizes an Architectural Protocol.Each Architectural Protocol comprises some infrastructure service interfaces, calls for other functional modules in firmware.
Device protocol layer realizes the industrial specification of various standard, comprises bus protocol, Peripheral Interface, network protocol stack etc.It comprises bus protocol module and network protocol stack module, and bus protocol module realizes various bus protocol, as PCI/PCIE, SATA, PATA, SCSI, USB, ISA, SMBUS, LPCBUS etc.Normally a module realizes a kind of bus protocol, and passes through the interface of Protocol mechanism " issue " these buses in UEFI specification, and other modules just can use these interfaces to visit bus like this; Network protocol stack module realizes network protocol stack, and as TCP/IP, SNP, DHCP, TFTP etc., other modules can realize the relevant function of network based on these protocol stacks like this.
Firmware application layer realizes the various functions of firmware, as configuration interface, system monitoring, file system, booting operating system etc.; It comprises device scan module, man-machine interface display module, system-monitoring module, system start module, file system module, kernel loads module, module and Shell module when running, device scan module enumerates all external units in system, as the equipment in PCI/PCIE bus, for these equipment Resources allocation, and equipment and corresponding peripheral hardware driver module are carried out Connect (also namely giving this device drives to manage); Man-machine interface display module is positioned on video driver module, realizes the interface that all displays are relevant, as arranged display mode, at ad-hoc location printable character string, Show Picture, cls etc.; The real-time check processing actuator temperature of system-monitoring module, system voltage and rotation speed of the fan, adjust the rotating speed of fan according to temperature value; Allow user's design temperature threshold value, when temperature is too high, carry out automatic shutdown; System starts module provides patterned user's configuration interface, and user, by the mode of menu operation, checks system information and is configured system.Finally according to the selection of user, start the operating system from memory device; File system module realizes FAT/FAT32, EXT2/3/4 and ISO9660 file system, supports the read operation to file; The final stage that kernel loads module starts in system, kernel file is loaded in internal memory by this module from the storage mediums such as hard disk, USB flash disk, CD, and preparing necessary parameter for kernel file, the entrance then jumping to kernel performs, and has so just given operating system by control; The confession operating system that during operation, module achieves the definition of UEFI specification call in its operation phase operation time (Runtime) interface, and some interfaces that the operating system of dragon chip processor platform and firmware define, as system reboot, shutdown etc.; Shell module Shell is the command line environment that UEFI firmware provides, and based on a large amount of interface service provided in UEFI firmware, can develop the multiple firmware application programs under Shell.
The carrying out practically step of the UEFI firmware based on Godson desktop computer of the present invention is as follows:
(1) initialization processor, internal memory, sets up the Essential Environment that firmware runs;
(2) UEFI firmware code is copied to internal memory, and decompress(ion) is carried out to firmware, loading firmware nucleus module;
(3) infrastructure service of UEFI firmware is set up;
(4) load UEFI firmware functional module, comprise architecture functional module, device protocol module;
(5) scanning device is also equipment distributing system resource, loading equipemtn driver module, finishing equipment initialization;
(6) load and execution firmware application module;
(7) configuration interface is run;
(8) from memory device load operation system.
In above-mentioned steps, in step (1), perform processor driver module.Processor driver module adopts MIPS assembly language to realize, and be the module first performed after system electrification, now internal memory does not also complete initialization, so this module is directly run in FLASH chip.Processor driver module realizes the initialization such as Godson 3A processor, Cache (high-speed cache), internal memory, TLB (bypass conversion buffered), realize the initialization of MCU (Memory Controller Hub), SMBUS and internal memory, allocate memory address window, and the interface that the parts such as access CPU, Cache, internal memory are provided.Processor driver module also wants the serial port module in initialization processor, provides debugging method for follow-up firmware code.
In above-mentioned steps, in step (2), perform firmware core loading module.After step (1) is complete, Installed System Memory initialization is good, and now firmware code can run to accelerate travelling speed in internal memory; And firmware code can be realized by C language, Speeding up development speed.The functional module comprised in firmware is more, and the finite capacity of FLASH chip, generally need the firmware volume depositing functional module to compress, firmware core loading module is responsible for the firmware volume of compression being copied in internal memory from FLASH, and carries out decompress(ion); After decompress(ion) success, in internal memory, create HOB (Hand-Off Block) tables of data, deposit the system informations such as processor, internal memory, FLASH, be supplied to follow-up firmware module and use; Finally, control is given firmware nucleus module by firmware core loading module.
In above-mentioned steps, in step (3), perform firmware nucleus module.The system service of firmware nucleus module first initialization UEFI, for follow-up functional module loading, run and prepare.Mainly complete the initialization of agent list when UEFI system table, UEFI startup agent list and UEFI run, specific service comprises code debugging, memory management, the management of UEFI mirror image, HOB, UEFI clock, FLASH access, decompression, firmware volume parsing, UEFI event, task priority, UEFI Protocol management, UEFI variable access etc.System service table leaves the specific region of internal memory in, and all functions module in UEFI firmware can call these system services.
In above-mentioned steps, the functional module of firmware nucleus module loading firmware in step (4).Firmware nucleus module, by retrieval firmware volume, is searched functional module wherein successively, and is loaded in internal memory.Each functional module is compiled into the performed mirror image of a PE/ELF form, and firmware nucleus module needs analytical capabilities module mirror image, is then loaded into the particular address place of internal memory, and jumps to entrance function.After the entrance function of functional module is complete, usually can turn back to firmware nucleus module, firmware nucleus module proceeds the loading of next functional module.
The module be loaded in step (4) comprises architecture functional module, device protocol module.Wherein, architecture functional module major function is the Architectural Protocol realized in UEFI specification, mainly comprise: Boot Device Selection (BDS), CPU, Metronome, Monotonic Counter, Real TimeClock, Runtime, Security, Status Code, Timer, Variable, Variable Write, WatchdogTimer, each Architectural Protocol is realized by a module; Device protocol layer module mainly realizes the function interface of accessing the buses such as PCI/PCIE, SATA, PATA, SCSI, USB, ISA, SMBUS, LPCBUS, and be encapsulated in Protocol and call for other functional modules, normally a module realizes a kind of bus protocol.In addition, the functional module realizing TCP/IP network protocol stack is also comprised;
In above-mentioned steps, the initialization of finishing equipment in step (5).Firmware nucleus module loading equipemtn driver module, realize the initialization of peripheral hardware on mainboard and realize the function interface of access peripheral hardware, comprising north and south bridge chip, video card, SATA/IDE controller, USB controller, SMBUS controller, LPC controller, keyboard, network interface card etc.Usually a kind of device drives is realized by a module.In addition, in this stage by all peripheral hardwares in device scan module scans system, and be peripheral assignment internal memory, IO and interrupt resources, such peripheral hardware could normally work under an operating system.
In above-mentioned steps, the firmware application module in step (6) in firmware nucleus module loading firmware volume, and realize corresponding firmware function.Comprise display module, system-monitoring module, file system module, kernel loads module, run time module, Shell module, system start module.Finally, control is given system and is started module by firmware nucleus module, prepares to start the operating system.
In above-mentioned steps, in step (7), system starts the service interface that module provides by calling firmware nucleus module and other functional modules, demonstrates figure configuration interface as human-computer interaction interface.In this stage, firmware carries out next step work according to the operation of user, comprises and provides the display of system information and the configuration of systematic parameter, and the equipment that selection will start, and comprises hard disk, CD, USB flash disk, network, order line etc.User exits configuration interface by specific keys and enters into next execution step.
In above-mentioned steps, in step (8), realize the startup of operating system.According to user configured boot sequence, system starts module and to attempt operating system nucleus files loading successively from media such as hard disk, CD, USB flash disk, networks to internal memory, and prepare necessary start-up parameter for kernel, then give kernel by control, thus the startup work of completion system.After os starting completes, still can call a small amount of function that when running in firmware, module provides, comprise system reboot, shutdown etc.
Beneficial effect:
1, method of the present invention meets UEFI and the PI firmware specification of international mainstream, and the Open Source Code resource that UEFI alliance can be utilized to provide realizes firmware fast; A lot of peripheral hardware board manufacturer all provides the driving based on UEFI specification, also greatly can accelerate the progress of firmware development.In addition, the computer industry standard that the support of UEFI firmware is main, as ACPI (advanced configuration and the power-management interface) specification that current Loongson processor is not also supported, the firmware adopting the present invention to design like this can increase the support to these specifications easily.
2, the important feature of the UEFI firmware of the present invention's design is high modularization, and the function that firmware will realize is broken down into a lot of subfunction, and each subfunction is realized by independent module, and loads and manage these functional modules by a nucleus module.Therefore the function of customized firmware easily can be carried out by additions and deletions module.
Embodiment
To develop simultaneously embodiment below in conjunction with accompanying drawing, describe the present invention.
As accompanying drawing 1 represents, below for the development board that a model of section's company designs in Godson is MBLS3A-RS780E, introduce the embodiment of the UEFI firmware that the present invention describes.Mainly comprise the following steps:
(1) realize the functional module in STU stage, comprise two modules, these two modules will be placed to the starting position of FLASH chip successively after compiling, and are performed successively upon power-up of the system.Comprise:
(1.1) a Start module, i.e. processor driver module is created.The initialization such as processor, Cache (high-speed cache), internal memory, address window, TLB (bypass conversion buffered) are realized according to Godson 3A processor handbook, realize the initialization of MCU (Memory Controller Hub), SMBUS and internal memory, and the interface of the parts such as access CPU, Cache, internal memory is provided;
(1.2) a Sec module is created.The function of the realization of this module is included in internal memory and creates the data structure that some deposit processor, memory information, unzips in internal memory by the functional module in FLASH chip, last load and execution firmware nucleus module DxeCore.
(2) firmware nucleus module DxeCore is realized.The function realized mainly comprises: agent list when realizing the startup service that defines in UEFI specification and run, load, run other functional modules, what manage between each module is mutual, realize the management of internal memory, realize and safeguard tick interrupt and case mechanism, realizing and safeguard the level of privilege mechanism of firmware application, realize the administrative mechanism of the Protocol defined in UEFI specification, optimized integration function library, and debugging interface, compression algorithm, variable storage/process etc.
(3) realize Architectural Protocol, comprise Variable, Variable Write, Timer, CPU, Metronome, Monotonic Counter, Status Code, Watchdog Timer, RTC, BDS.A module realizes a kind of Architectural Protocol.
(4) peripheral hardware driver module is realized.Comprise:
(4.1) driver module of chipset is realized.Initialization to AMD RS780 north bridge chips, AMD SB710 South Bridge chip is realized according to chipset handbook, and the initialization of pci bus, USB, SATA/IDE, LPC/SMBUS bus, HD Audio controller in South Bridge chip.
(4.2) realize peripheral hardware driver module, comprise video driver, USB storage device driving, the driving of PS2 keyboard drive, USB keyboard drive, SATA device drives, IDE device drives, trawl performance, tick interrupt.
(4.3) realize peripheral hardware enumeration module, enumerate the equipment in PCI/PCIE bus, and be equipment distribution IO, internal memory and interrupt resources.
(5) realize bus driver block, comprise PCI/PCIE, SATA, PATA, SCSI, USB, ISA, SMBUS, LPCBUS, a module realizes a kind of bus protocol.
(6) firmware application layer module is realized.Mainly comprise:
(6.1) graphical interfaces module is realized.A patterned configuration interface or command line environment can be realized, support that user checks processor model and frequency, memory size and frequency, system time, boot sequence, peripheral hardware list etc., and allow user to be configured system time, boot sequence;
(6.2) realize file system module, support the read operation to FAT/FAT32, EXT2/3/4 and ISO9660 file system;
(6.3) boot kernel module is realized, the operational factor that data structure needs with deposit operation system is created in internal memory, and according to the configuration of user, from hard disk, USB flash disk, CD or network load operation system kernel file to internal memory, finally give operating system nucleus by control;
(6.4) system that realizes starts module, and its function comprises: load configuration interface, realize the loading of operating system.
(6.5) Shell module is realized, user can start to Shell command line environment by arranging boot sequence in configuration interface, and Shell provides multiple order to realize file in the checking of system information, device parameter configuration, access storage media, equipment control and test, os starting etc.
In above-mentioned steps, for the module relevant to particular hardware platform, as Godson 3A processor, AMDRS780+SB710 chipset, the general user manual according to hardware or the Open Source Code with reference to producer of needing is developed; For the general module irrelevant with hardware platform, as DxeCore module, ArchitecturalProtocol module, bus protocol, network protocol stack, SATA/IDE device drives, USB storage device driving, keyboard drive, file system, BDS module etc., the module and code that provide in EDK II can be adopted; For the functional module of firmware, as configuration interface, operating system loading etc., need to develop according to real needs; For video driver, due to OPROM (the Option ROM on video card, the driving that video card producer provides) be x86 instruction set, the Loongson processor of MIPS instruction set cannot perform, so adopt an X86 emulation module of increasing income to explain the OPROM performing video card in firmware, realize the initialization to video card.
In sum, these are only preferred embodiment of the present invention, be not intended to limit protection scope of the present invention.Within the spirit and principles in the present invention all, any amendment done, equivalent replacement, improvement etc., all should be included within protection scope of the present invention.