Commit Graph

485 Commits

Author SHA1 Message Date
Maurice Ma f63f7f808c Add support for both private and public PEM key format
Current gen_pub_key only supports private key in PEM support.  In
many cases, private key might not be available and only public key
is available. This patch enhanced this function to handle both
private and public key in PEM format.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-12-10 11:34:52 -08:00
Maurice Ma 0a6c955dbe Add bytes print function in CommonUtility
There are many cases that it is required to print the values of
byte-array for debug. It is not convenient in current SBL python
scripts. This patch added a print_bytes() function in CommonUtility
to provide generic function to print out a byte array object.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-12-10 11:32:54 -08:00
Maurice Ma 70cb62f68f Add HeaderLength field in Hash Store header
This patch add HeaderLength to indicate the length of Hahs Store
header so that common code can be used to skip the header without
using the sizeof() operator.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-12-08 21:04:59 -08:00
Maurice Ma 4ed0742524 Fix hash store buffer size issue in SBL global data
Current code only counted used hash store size as the whole
buffer size. This is not correct and will cause buffer overflow.
It is required to use the whole hash store buffer size including
the unused space at the end. This patch fixed this.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-12-08 21:04:59 -08:00
Subash Lakkimsetti 1d50d7c888 Fix review comments for Hash Store updates
Signed-off-by: Subash Lakkimsetti <subashx.lakkimsetti@intel.com>
2019-12-06 15:48:53 -07:00
Subash Lakkimsetti 53f088f9d5 Hash Store: Restructuring Hash Store definition
HASH_STORE_TABLE is updated and HASH_STORE_DATA is added
to provide info with variable length sizes. Usage bits would
notify for multiple component/key using the same hash.
These data structure would optimize the hash store size
in storage.

PcdHashStoreSize would define the size of Hash store
to allocate in bios bootup.

Signed-off-by: Subash Lakkimsetti <subashx.lakkimsetti@intel.com>
2019-12-06 15:48:53 -07:00
Subash Lakkimsetti 323120273c Build Tools: Hash Store is defined for variable sizes
HashStoreTable is defined for variable size to support
different hash alg and sizes. This would optimize the
hash store size in storage. Signing hash alg defined in BoardConfig file.
Hash store data is aligned as per the Digest length used.

Signed-off-by: Subash Lakkimsetti <subashx.lakkimsetti@intel.com>
2019-12-06 15:48:53 -07:00
Subash Lakkimsetti 27257925d6 TpmLib: added TpmExtendHash to extend hash provided
Component Hash is passed with TpmExtendHash if available.
Hash Store is getting optimized on storage and this would avoid
setting component hash in hash table. SetComponent Hash API is
removed in bootloaderlib.

Added HashAlg param to TpmExtendHash for future purposes
where TPM PCR bank would be selected based on HashAlg.

Signed-off-by: Subash Lakkimsetti <subashx.lakkimsetti@intel.com>
2019-12-06 15:48:53 -07:00
Aiden Park 66b9a5191d Preserve ebx register in AsmEnableAvx()
System reset occurs after returning from AsmEnableAvx() in Stage1A.c
because ebx register is used for cpuid, but not restored.
- Save/Restore ebx register
- Move AsmEnableAvx () after init idt and serialport

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-12-05 11:41:00 -08:00
Aiden Park 72262b4722
Misc Klocwork scanning fixes (#484)
This patch fixes klocwork scanning reports in qemu, apl and cfl builds.

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-12-04 15:17:04 -08:00
Maurice Ma ef9040f00e Adjust GPIO based PayloadId selection policy
This patch updated the PayloadId detection logic on APL platform
to make it easy to understand.

The current policy is as below:
- If PayloadId CFGDATA is not AUTO, use whatever provided in CFGDATA.
- If PayloadId CFGDATA is AUTO, and GPIO based PayloadId detection
  is enabled, uses GPIO level to determine the actual PayloadId to
  use. (HIGH:OsLoader LOW:UEFI)
- If PayloadId CFGDATA is AUTO, and GPIO based PayloadId detection
  is disabled, uses default PlatfomrId 0 (OsLoader).

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-12-04 13:26:33 -08:00
Maurice Ma b693d9776e [QEMU] Fix QEMU boot issue with new IPP library change
The previoius IPP library updates used UpdateSHA256V8 as default for
SHA256. It works on real platform. However, QEMU's default CPU config
does not support SSE3 instructions and will generate exception. This
patch added the UpdateSHA256Compact as default SHA256 function if no
advanced optimization flags are set. The same is applied for SHA512
functions too.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-12-04 11:20:11 -08:00
Subash Lakkimsetti a3fa16511c Add support for AVX and SSE4 optimizations in IPP SHA384
AVX(G9) and SSE4(W7) is added to IPP crypto lib.
PcdCryptoShaOptEnabled is added to enable optimzations
in IPP SHA256 and SHA384.

Default is set to V8 (SSE3) for SHA256. ENABLE_CRYPTO_SHA_OPT has to
be configured in Platform board config files for optimizations
to be enabled.

Signed-off-by: Subash Lakkimsetti <subashx.lakkimsetti@intel.com>
2019-12-03 21:36:29 -08:00
Maurice Ma 8a0a8984f9 Enable CPU AVX support if available
EnableAvx ASM is included as part ExtraLibs.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
Signed-off-by: Subash Lakkimsetti <subashx.lakkimsetti@intel.com>
2019-12-03 21:36:29 -08:00
Aiden Park b24fd2759c Cosmetic: Convert LF to CRLF
This will fully support PatchCheck.py.
- Remove all trailing whitespace
- Convert LF to CRLF by default
- Update EFI_D_* to DEBUG_*
- Re-enable CRLF check in PatchCheck.py

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-12-02 16:21:19 -08:00
James Gutbub d6909c97fe Add features flag for pre-OS checker boot
By adding an additional flag for the pre-OS
checker execution flow it is possible to determine
at run time whether to attempt loading/execution
of the pre-OS checker during OS Loader time. From
platform code the decision to attempt to run the
pre-OS checker can be controlled.

Signed-off-by: James Gutbub <james.gutbub@intel.com>
2019-12-02 14:37:06 -07:00
Maurice Ma 533dbed5a0 Enhance CFGDATA tools to support generating DLT from IFWI
This patch enhanced the CFGDATA script to extract CFGDATA BIN
files from IFWI and further generate DLT using default DSC.
In this way, the default CFGDATA binaries and DLT files are no
longer requried to be provided in the release package in order
to customize the CFGDATA in an existing IFWI image.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-12-02 10:02:43 -08:00
Guo Dong 2b3b41ecf5 Add debug port support
PcdDebugInterfaceFlags and PcdDebugOutputDeviceMask are defined
for debug devices, so removed PcdDebugInterfaceFlags.

Add a new PCD PcdDebugPortNumber to indicate the serial debug
number.

Signed-off-by: Guo Dong <guo.dong@intel.com>
2019-12-02 09:17:05 -07:00
Maurice Ma 40ad2f9fb6 [APL] Provide WMI service for FWU trigger
This patch added WMI service in ACPI to provide a unified mechnism
for user to trigger a firmware update flow. New ASL methods are
defined. \DWMI.WQ00 is for read and \DWMI.WS00 is for write.

To use it from Linux (Ubuntu):
  - Install acpi-call module
    sudo apt install acpi-call-dkms
  - Load module
    sudo modprobe acpi_call
  - Read trigger register value
    echo '\DWMI.WQ00 0' | sudo tee /proc/acpi/call
    sudo cat /proc/acpi/call
  - Write trigger register value
    echo '\DWMI.WS00 0 0x12' | sudo tee /proc/acpi/call

To use it in Windows:
  - Open a command line window with admin right.
  - Run VB script to read / write the trigger register
    set Service = GetObject("winmgmts:root/wmi")
    set EnumSet = Service.InstancesOf ("AcpiFirmwareCommunication")
    for each Instance in EnumSet
      Wscript.Echo "Current  Val: " & Hex(instance.Command)
      instance.Command = 1
      instance.Put_()
      Wscript.Echo "Set New Val: " & Hex(instance.Command)
    next 'instance

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-11-26 12:58:29 -08:00
Maurice Ma 9c50d23a12 Add FSP API reset request handling
Current SBL does not check the FSP Notify API return status. As a
result, if reset is requested, it is ignored by SBL. This patch
added FSP reset request check for FspMemoryInit, FspSiliconInit and
FspNotifyPhase.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-11-25 09:22:52 -08:00
Maurice Ma abee91f2f8 Delay IA untrust bit set for BSP
SBL currently set IA Untrust bit in MpInit(). It is too early for
BSP. By doing so, it blocked some register access in FSP notification
APIs. This patch moved the IA Untrust bit set for BSP to the end of
boot flow while keeping it at same location for APs.

It also fixed #466.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-11-25 09:15:51 -08:00
Maurice Ma ec8dca50bb Move clear HOB to the very end of the boot flow
Current SBL calls ClearFspHob() too early. Since HOB is required
during the whole FSP life cycle. It is better to clear it at the
end after the last call. Otherwise, some previous API call will
potentically encounter issues.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-11-25 09:15:51 -08:00
Maurice Ma d7bdca432e PCIE device wake up enhancement
This is a follow-up to the previous WOL commit. The previous
implementation is more LeafHill specific. This patch further
added configuration data to control how wake up signal is mapped
into each PCIE root port. And the ASL code has been adjusted to
utilize that info so that the code can be more generic for all
other platforms.

The current default configuration for PCIE wake signal is aligned
with LeafHill CRB board. For other borads, to enable it properly,
it is required to override the wake signal configuration using DLT.

Test has been done on LeafHill to do WOL with yocto image. It worked
as expected.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-11-25 09:15:15 -08:00
Maurice Ma 6be72e56dd Add CFGDATA export command support in CfgDataTool
This patch added export sub-command support in CfgDataTool.py. It
is useful for users to export external CFGDATA from an exising
BIOS or IFWI binary file.
EX:
  python BootloaderCorePkg\Tools\CfgDataTool.py export
         -i Outputs\cfl\SlimBootloader.bin -o Temp

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-11-25 09:14:35 -08:00
Aiden Park 161af534d4 Fix invalid cmdline reading from config file
Kernel cmdline data from config.cfg or grub config files were copied
to invalid address.
This is only for traditional linux boot in debug build.

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-11-22 16:10:08 -08:00
Ursula Maplehurst c38f103cc3 [APL] Enable Wake-on-LAN for Leaf Hill CRB (#394)
Test: WoL works on Leaf Hill CRB

Signed-off-by: Ursula Maplehurst <ursula@kangatronix.co.uk>
2019-11-22 11:43:54 -08:00
Aiden Park 143b7facaa PatchCheck: Re-enable TAB check
This will not allow TAB characters in commit(s).

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-11-21 12:11:37 -08:00
Aiden Park d362ef39ec Cosmetic: Remove TAB characters (Tab to Space)
No code change. To check TABs in PatchCheck.py.

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-11-21 12:11:37 -08:00
Maurice Ma ace9d98eb8 Adjust GPIO CFGDATA structure header
This patch added additional information in the GPIO CFGDATA header
structure so that the full GPIO info can be extracted out later on
by tool. This additional information including GPIO SKIP bit position,
GPIO ID position and length.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-11-21 11:46:59 -08:00
Subash Lakkimsetti 3a932bdf0a GenCapsuleFirmware: Hash type is made optional param
Signing hash type is defaulted to SHA2_256.

Signed-off-by: Subash Lakkimsetti <subashx.lakkimsetti@intel.com>
2019-11-20 14:44:23 -08:00
Maurice Ma 3b457679ec Remove platform specific GetBuiltInConfigData()
Current SBL has platform specific GetBuiltInConfigData() implementation
because the internal CFGDATA blob is embedded into Stage1B data section.
Instead, it can be put into Stage1B FV FFS file, and then use a PCD to
get the base. In this way, it can be handled directly in core code and
remove platform specific implementation.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-11-20 14:43:50 -08:00
Aiden Park ae9068e80c
Fix no SBL serial output after restart Windows (#459)
SerialPortLib sets UART Scratch Register to a known value at the first
initialization to avoid unnecessary re-initialization afterward. But,
one of Windows driver(SIO) re-configures UART Registers while the Scratch
Register is preserved. As a result, SBL skips serial port initialization
after restarting from Windows.
Therefore, force to initialize Serial Port at Stage1A all the time simply.

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-11-18 19:14:44 -08:00
Maurice Ma 94a980625a Add extraction support for IfwiUtility script
This patch added extraction support in IfwiUtility tool so that
component in IFWI can be easily extracted into binary file.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-11-19 09:53:44 +08:00
Aiden Park cd46ffb6a4
Fix MRC re-training at warm reset (#457)
MRC re-init happens in next boot when an warm reset is issued in MRC
fast boot path. DRAM Initialization Scratchpad Bit is one of warm reset
detection logics, but the bit is not updated at fast boot path.

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-11-18 16:57:52 -08:00
Subash Lakkimsetti 90ee2ec323 Set auth type to default in CfgDataTool
Auth_type param is set to RSA2048SHA256 for default cases.

Signed-off-by: Subash Lakkimsetti <subashx.lakkimsetti@intel.com>
2019-11-17 08:41:37 -07:00
Subash Lakkimsetti d81d21cf81 Add hash type param to GenContainer tool
sigining hash type parameter added with command line
args for create, replace and sign component image.

Signed-off-by: Subash Lakkimsetti <subashx.lakkimsetti@intel.com>
2019-11-15 13:25:40 +08:00
Aiden Park d2ea80b5c9
Add InsertionSort for Linked List (#454)
This provides basic insertion sort API for Linked List. As part of change,
this insertion sort is used for PCI BAR calculation by its alignment
and for shell commands list by its name.

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-11-14 11:26:31 -08:00
Subash Lakkimsetti 36ec407123 Signing hash type in GenCapsuleFirmware tool
Added hash type to be used in signing process for
GenCapsuleFirmware.

Parameter added: -a alg_hash

Signed-off-by: Subash Lakkimsetti <subashx.lakkimsetti@intel.com>
2019-11-14 05:36:22 +08:00
Aiden Park 141d051b8f
OsLoader: Free all allocated memory at failing on a boot option (#453)
While trying to boot all boot options, some allocated memory are not
de-allocated properly. To avoid memory leak while booting next boot
options, OsLoader will track all image data and free the unnecessary
memory at failing to boot current boot option.

Tested and verified with
- Traditional linux image on debug build
- IAS type image
- Container type image
- MultiBoot image
- BootSlot (A/B Boot)
- Trusty image

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-11-13 09:50:01 -08:00
Aiden Park a340937fbb
Fix invalid addendum update in OsBootOption (#452)
OsBootOption config data provides addendum field to support multiple boot
option config data into a single boot option.
This patch updates a single boot option properly with multiple addendums.

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-11-13 09:49:37 -08:00
Subash Lakkimsetti ae3c5ae9b5 Add SHA384 and SM3 wrapper library support from IPP crypto
Functionality to Crypto Hash function is guarded with an
PcdIppHashLibSupportedMask.

PcdIppHashLibSupportedMask indicates IPP crypto algo supported

Signed-off-by: Subash Lakkimsetti <subashx.lakkimsetti@intel.com>
2019-11-12 09:58:54 +08:00
Subash Lakkimsetti 5608222f17 Add hash type param to bootloader build and signing tools
hash_type parameter added to build tool API's as required and
current supported hash in tools is for SHA2_256.

Added functionality for retriving RSA private key type.

Signed-off-by: Subash Lakkimsetti <subashx.lakkimsetti@intel.com>
2019-11-12 09:56:11 +08:00
Maurice Ma 659ede1ff0 Add SortLib support in BootloaderCommonPkg
There are multiple instances of sorting use case in SBL. For example,
memory map sorting and CPU APIC ID sorting. This patch added a generic
quick sort library to provide common sort API. As part of the change,
the quick sort API will be used for memory map and CPU APIC ID sorting.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-11-12 09:55:00 +08:00
Maurice Ma 62aa4407d5 Re-arrange CPU info entry order so MpInitLib
This patch sorts the CPU info entry according to their thread distances.
It is required to list CPU thread with furthest distance first in MADT
so as to better utilize CPU resources.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-11-12 03:31:44 +08:00
Maurice Ma 1870fb4fdf Remove HAVE_FLASH_MAP config option and PCD
SBL depends on flash map to locate all component info. It is
mandatory to keep flash map. HAVE_FLASH_MAP config option should
be removed. This patch removed this config option and the related
PcdFlashMapEnabled PCD.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-11-12 02:37:57 +08:00
Subash Lakkimsetti eba6c56241 Update TPM Physical Presence asl for SMM Dispatch usage in payload
UEFIPayload uses SMM dispatch for Physical Presence (Tcg2SMM) SMI.
Updated SMI port usage in asl to trigger SMI registered for
Physical Presence operation

Signed-off-by: Subash Lakkimsetti <subashx.lakkimsetti@intel.com>
2019-11-09 12:37:12 +08:00
stalamudupula a2c75b2faa Add GenGpioData.py tool (#432)
GenGpioData.py is a utility that converts
GPIO pin data from one format to other.

The formats currently supported are [h, csv, txt, dsc, dlt].
[h, csv, txt] formats are external to SBL and [dsc, dlt] formats
are known to SBL. So, this tool provides a way to convert one
of the [h, csv, txt] to [dsc, dlt] and vice-versa.

Example usage:

    python GenGpioData.py -if GpioInput.csv -of dsc

    python GenGpioData.py -if GpioInput.dsc -of txt

Signed-off-by: Sai Talamudupula <sai.kiran.talamudupula@intel.com>
2019-11-07 12:21:51 -08:00
Aiden Park 210bd02c47 Fix invalid PatchCheck commit ranges in travis
PatchCheck was using 'TRAVIS_COMMIT_RANGE' travis variable to get commit
range, but it lost tracks when doing force push or rebase. There are many
issue reports about this variable.
To avoid potential issue, let's get the range from git command directly
instead of TRAVIS_COMMIT_RANGE variable.

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-11-08 03:31:35 +08:00
Ravi Rangarajan 13974ee2d4 Fixed condition check based on klocwork scan (#442)
Fixed condition check based on KW report

Signed-off-by: Ravi Rangarajan <ravi.p.rangarajan@intel.com>
2019-11-06 16:51:02 -08:00
Ravi Rangarajan a218222928 Klocwork cleanup for PayloadPkg
Signed-off-by: Ravi Rangarajan <ravi.p.rangarajan@intel.com>
2019-11-07 06:47:56 +08:00