Commit Graph

64 Commits

Author SHA1 Message Date
Aiden Park 12b4201543 Fix a compile error with gcc-4.8
gcc-4.8 reports an error - 'Count' may be used uninitialized

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-09-29 22:26:22 -07:00
Aiden Park b17c6c29b1 Fix compile errors when disabling compile optimization
- 'OpenFile may be used uninitialized' in ExtLib
- 'undefined reference to memcpy' in FatLib
- 'Lasa/Laml may be used uninitialized' in TpmLib
- 'Adjust may be used uninitialized' in Stage2Support

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-09-29 22:26:22 -07:00
Sai Talamudupula 1a7287881b Update ContainerLib
Add GetNextAvailableComponent() and authenticate the
components after registering them in CONTAINER_LIST.

Signed-off-by: Sai Talamudupula <sai.kiran.talamudupula@intel.com>
2019-09-27 14:13:01 -07:00
Maurice Ma d2bd63df12 Allocate page aligned memory for component loading in container (#326)
To assist source level debug, it is better to always load PE/TE images
at page aligned memory address so that the script can locate the image
much easier. This patch changed the AllocatePool to AllocatePages for
component loading inside a container.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-09-23 09:19:27 -07:00
Maurice Ma 866493b926 Fix klocwork scanning issues in BootloaderCommonPkg
Fixed several issues reported by klockwork scanning.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-08-28 09:33:45 -07:00
Sai Talamudupula 9af34bca9a Remove Core pkg references from Common pkg
By design, BootloaderCommonPkg should not refer to
BootloaderCorePkg. Hence removed those references in
the .inf files in Common pkg.

Moving SmbiosInitLib to Core pkg as it is a core feature.

Signed-off-by: Sai Talamudupula <sai.kiran.talamudupula@intel.com>
2019-08-22 06:26:18 -07:00
Sai Talamudupula f0b5eaf43a Add UEFI Get Variable support
Users might want to have some parameters that can be set
from UEFI environment. UEFI NVRAM variables provide a way
to achieve this functionality. And they require these vars
to be read from bootloader.

This patch provides a library to get read access to the
UEFI variables stored in NV region. The driver was ported
from MdeModulePkg\Universal\Variable\Pei @ EDKII Open Source.

Signed-off-by: Sai Talamudupula <sai.kiran.talamudupula@intel.com>
2019-08-16 07:25:20 -07:00
James Gutbub b0e390f1d3 Fix ContainerLib flash bug
There is a small bug in the ContainerLib
where the check for whether the data is
stored in the flash needs to be adjusted.

Signed-off-by: James Gutbub <james.gutbub@intel.com>
2019-08-15 14:03:46 -07:00
Maurice Ma 19a0890a54 Break Load Linux BzImage into more functions
This patch splitted LoadBzImage() into two functions.  One is just
for kernel loading.  The other one UpdateLinuxBootParams() is for
Linux boot parameter updates. It is required to do so because when
kernel loading in Stage2 is enabled the loading occurs before all
HOBs are finalized. The Linux boot parameters depend on HOBs to fill
correct information, such as frame buffer. With this patch, the boot
parameters can be updated at the very end.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-08-12 10:40:11 -07:00
Maurice Ma de675ac5af Fix Linux framebuffer boot parameters
Current SBL code depends on PixelInformation to fill kernel
framebuffer parameters. However, this info is only valid if
PixelFormat is PixelBitMask type. Since FSP will only produce
8bit per pixel format, it is better to use PixelFormat to
determine the pixel bit size and position information. This
patch added this logic. It also fixed #260 .

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-08-12 08:33:42 -07:00
Maurice Ma 4a5af4f8b0 Add Linux Kernel Boot Support in Stage2
OsLoader has the capability to boot a Linux kernel. However, to support
LinuxBoot type of payload, it is required to load kernel in Stage2. This
patch abstracts the standard Linux loading logic into common LinuxLib
class so that it can be linked in Stage2 or Payload such as OsLoader.
A new PcdLinuxPayloadEnabled is introduced to control if this feature
should be enabled or not.

To boot a Linux kernel from Stage2, it is required to put the command
line file and kernel image into the EPAYLOAD container during the build.
And the PayloadId CFGDATA needs to be set to 'LINX'.
For example:
  python BuildLoader.py build qemu
         -p OsLoader.efi::Lz4;vmlinuz:LINX:Dummy;cmdline.txt:CMDL:Dummy
vmlinuz and cmdkube.txt need to be copied to PayloadPkg/PayloadBins
folder. If kernel size cannot fit into EPAYLOAD, EPAYLOAD_SIZE in
BoardConfig.py needs to be adjusted accordingly.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-08-09 16:48:12 -07:00
Maurice Ma bc8a817e59 Reinitialize Shell command list
Since OsLoader will restart from beginning and all memory will be
reclaimed, it is required for Shell library to re-initialize the
global varaibles, for example, command list. Otherwise, the old
memory pointer will be used and cause issues. This patch added the
link list re-initialization in Shell lib.  It fixed #253.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-08-07 13:37:05 -07:00
Aiden Park 5103615bfb [ShellLib] Add ShellCommandRegister API
Currently, all shell commands are statically defined in header file.
Add shell command registration API to allow include/exclude shell
commands dynamically.
Later, some debug shell commands will be added according to build
mode or debug mask.
- TBD: Sorting shell commands by name

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-08-05 21:04:27 -07:00
Aiden Park 13bd3d2d26 [Ext23Lib] Fix EXT filesystem booting failure
Currently, Ext23Lib accesses device index 0 only.
It must access proper hardware partition when reading blocks.
- Reproducible with QEMU which has SATA port 5

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-08-02 08:45:07 -07:00
Maurice Ma ef682b19c3 Switch to use container for EPAYLOAD
This patch enabled container use case for EPAYLOAD loading.
It also switched to use LoadComponent() API for Stage2 and
payload loading. It simplified the code flow. An example in
QEMU was added to demonstrate on how to add a container in
build and load it in Stage2 code.

To define a container layout, it is required to provide
GetContainerList() in BoardConfig.py. Then in stage or payload
code, LoadComponent() can be used to load a component from the
container.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-08-01 15:58:25 -07:00
Maurice Ma 93b2e96d8e Add ContainerLib to support sub-region
This patch added a ContainerLib to support load and location a
component from a specified container. It copies the component
from flash to memory, authenticate it, and then decompress it if
required. It can also be used to support load component from flash
map in SBL stage2 or payload, such as payload or e-payload.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-07-31 09:32:00 -07:00
Markus Schuetterle c1117a2be5 Add support for ELF type: Shared object file
SBL only support ELF type: EXEC (Executable file)
This changes also allow loading ELF type: DYN (Shared object file)

This is required to boot recent ACRN Hypervisor.

Signed-off-by: Markus Schuetterle <markus.schuetterle@intel.com>
2019-07-31 07:56:15 -07:00
Maurice Ma 626a8db20e Add temporary memory management for MemoryAllocationLib
There are cases where temporary memory is required in stages. Since
MemoryAllocationLib instance for stages has no de-allocation function,
it needs special handling. This patch added temporary memory management
into standard MemoryAllocatoinLib interface.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-07-29 14:44:02 -07:00
James Gutbub bc8f743c53 Add EXT2F_INCOMPAT_RECOVER to EXT2F_INCOMPAT_SUPP
Currently there is some limitation with mounting an
EXT4 partition to retrieve a file for booting when
the partition was not properly umounted during the
previous usage (ex. powering off an OS without
using 'poweroff' command, unplugging power, etc.).

There is no recovery support in the Ext23Lib but
as a temporary solution we can ignore the recovery
bit to avoid boot issues when the recovery bit is
flipped due to unexpected power loss.

Signed-off-by: James Gutbub <james.gutbub@intel.com>
2019-07-22 18:34:05 -07:00
Guo Dong a30d2ea913 Enhance SPI Flash Library
1. Add region type FlashRegionAll support
2. Add Hardware sequence check

Signed-off-by: Guo Dong <guo.dong@intel.com>
2019-07-18 13:25:01 -07:00
Sai Talamudupula 10fa1fe72a Handle empty and NULL strings in Smbios types
If the platform provides an empty or a NULL string,
Smbios type might end abruptly and the Types are
reported incorrectly.

Signed-off-by: Sai Talamudupula <sai.kiran.talamudupula@intel.com>
2019-06-26 17:13:48 -07:00
James Gutbub c9f5d2e35f Fix EXT4 extent calculations
When determining which extent node to fetch
the filesystem block address from for a file's
data we should count from block 0 of the file
and when we enter into a non-zero extent node
we need to subtract the starting block number
from the file block number we are looking for
so that we don't skip over any blocks.

Signed-off-by: James Gutbub <james.gutbub@intel.com>
2019-06-17 17:04:52 -07:00
Aiden Park 0066eccdb3
Re-implement ElfLib for ELF32 format image (#193)
The previous implementation has a little confusion in license header.
To avoid further annoying, simply re-implement ElfLib.
- 32bits, little-endian, executable elf only supported
- elf32.h/elf_common.h from BaseTools/Source/C/GenFw
- LoadElfImage() interface changed

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-06-17 16:58:08 -07:00
James Gutbub e702622fee Add support for EXT4 partition reading
The current EXT2/3 library does not support EXT4 partition
reading namely due to a limitation with handling extents
instead of block maps within an I_node's I_block data.

There is a todo currently to support 48-bit logical block
addressing, the code currently does not support reading
larger than 32-bit addresses; throw an ASSERT if upper
16-bits are non-zero.

Signed-off-by: James Gutbub <james.gutbub@intel.com>
2019-06-17 12:08:07 -07:00
Maurice Ma 4061d47f30 Add call to board notifications by default
Current SBL does not call board ReadyToBoot & EndOfFirmware phases
in Stage on normal boot flow. Current open source UEFI payload does not
do it either. It caused some security concerns. The patch enforced
these notification calls on normal boot flow in SBL for all payloads
except for those that can handle board and FSP notification on its own.

It fixed #191.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-06-14 16:18:41 -07:00
Maurice Ma 896937483c [WHL] Fix boot performance issue for BP1
On WHL, if using Boot Guard profile 0, booting from BP1 will be
significantly slower than BP0. It is because some code region in BP1
is not covered by MTRR cache settings. This patch adjusted MTRR
settings during PostTempRamInit notification to cover full flash
code region if Boot Guard profile 0 is used.

It fixed #188.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-06-13 15:02:36 -07:00
Guo Dong 5e10bd1e07 Update BSD license to BSD+Patent license
To align with EDK2, update file license
to use BSD+Patent license

Signed-off-by: Guo Dong <guo.dong@intel.com>
2019-06-13 10:46:49 -07:00
Maurice Ma 179130751f Fix FAT file path matching issue
In current FAT lib, the file path matching code will just compare
the 1st N chars and ignored the remaining. The end of the string
should be checked to ensure exact matching. As part of this fix,
the GRUB config parsing library needs to be updated since the file
name length field is one less than expected.

It fixed #183.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-06-12 10:59:31 -07:00
Maurice Ma 6f8c44b375 Sync up with EDK2 stable tag edk2-stable201905
Synced up MdePkg, IntelFsp2Pkg and BaseTools to EDK2 stable tag
edk2-stable201905.

There are several changes for MdePkg and BaseTools.
MdePkg:
 - Support light print to reduce SBL size
   MdePkg\Library\BasePrintLib\PrintLibInternal.c
   MdePkg\Include\Library\DebugLib.h
 - TCG TPM2 spec changes and remove dependencies
   MdePkg\Include\IndustryStandard\UefiTcgPlatform.h
   MdePkg\Include\IndustryStandard\Tpm2Acpi.h
 - Use old NVM protocol file
   MdePkg\Include\Protocol\NvmExpressPassthru.h
 - Removed unused files

BaseTools:
 - Added LZ4 support
 - Removed unused files

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-06-12 08:29:06 -07:00
Guo Dong b9ad47848a Move SpiFlashLib into bootloader common package
Cleaned up SpiFlashLib in APL platform, and move it into
BootloaderCommonPkg, so that other platform could reuse
this SpiFlashLib

Signed-off-by: Guo Dong <guo.dong@intel.com>
2019-06-06 14:28:31 -07:00
James Gutbub 90b155b3e3 Enable EXT2/3 sub-directory filepath image loading
Currently when providing a filepath with sub-directories
the EXT2/3 library is not able to locate the file. The
code for traversing sub-directories is already present
but was not enabled. This change enables this support.
Ex: 'boot/iasimage.bin'

Signed-off-by: James Gutbub <james.gutbub@intel.com>
2019-06-04 11:41:41 -07:00
Aiden Park 497e66eadb [FileSystemLib] Added generic filesystem/file access APIs
FileSystemLib provides generic interfaces to access file system and
its files as a abstraction of FatLib/ExtLib.

- Added CloseFileSystem
  If there are opened files in a specific filesystem, those files
  will be de-allocated in CloseFileSystem.
- Added OpenFile/GetFileSize/ReadFile/CloseFile
  The ReadFile() does not allocate any memory for the file content.
  The caller of OpenFile() MUST allocate necessary memory before
  calling ReadFile().

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-05-23 15:53:03 -07:00
Aiden Park 51b69d447b
[PartitionLib] Added ClosePartitions to clean-up partition data (#167)
The FindPartitions() allocates memory for PART_BLOCK_DEVICE instance.
This allocated memory needs to be de-allocated if no more necessary
to avoid memory leak.

TBD: Current partition info needs to be cleared before going to next
boot option.

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-05-22 09:03:41 -07:00
Aiden Park 592915c7e7
[MmcAccessLib] Fix SD card single block read failure (#165)
- CMD23(SET_BLOCK_COUNT) is for only MMC.
- CMD17(READ_SINGLE_BLOCK) must be used when reading a single block
  with SD card

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-05-20 09:48:32 -07:00
James Gutbub e75dd48e83 Enhance BMP image splashing
Current implementation of splashing a BMP image to the
display requires the allocation of a temporary buffer
to store the BMP image into a GOP Blt friendly format
that can then be used to splash the image to the display.
Instead of using a buffer for the whole image we can
allocate a smaller buffer to splash one line at a time
since splashing is already performed one line at a time.

Also fix a small print message regarding frame buffer
format.

Signed-off-by: James Gutbub <james.gutbub@intel.com>
2019-05-13 15:55:55 -07:00
Sai Talamudupula 0522b833df Add Smbios support
Initial Smbios support infrastructure

Signed-off-by: Sai Talamudupula <sai.kiran.talamudupula@intel.com>
2019-04-30 15:22:05 -07:00
Maurice Ma 0d8fad8bbc Allow SATA boot option to boot from any AHCI port
For SATA boot option, the hardware partition is mapped into AHCI
port. Current implementation requires a specific AHCI port in order
to boot from that hard drive. This patch added support to boot
from the first detected AHCI port when the hardware partition is
set to 0xFF.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-04-19 10:43:10 -07:00
Maurice Ma 3dfcd913eb Fix incorrect image base for TE image
TE image has stripped header to reduce the image size. When calculating
the preferred base for TE image, the gap should be added back in order
to match the actual TE image base. This patch fixed #133.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-04-12 10:44:02 -07:00
Maurice Ma 0980e74c12 Remove IPP 7z file from BootloaderCommonPkg
This patch removed the IPP 7z file from the BootloaderCommonPkg.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-04-10 10:26:59 -07:00
Guo Dong 5c041c0fe1 Clean up graphics HOBs
Removing the HOB defined by SBL to use generic HOBs from EDK2.
Update GraphicsLib for above HOB change.
Update osloader and multibootLib for hob change.
update APL and Qemu platform for hob change.

Signed-off-by: Guo Dong <guo.dong@intel.com>
2019-04-10 10:23:58 -07:00
Maurice Ma f6c1b690c2 Disable deprecated EDKII API interfaces
This patch enabled DISABLE_NEW_DEPRECATED_INTERFACES build option by
default so that the deprecated APIs cannot be used in SBL source tree.
It is to enhance the coding for security.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-03-14 11:26:03 -07:00
Subash Lakkimsetti db58e2358b Log startup locality only when Boot Guard is not enabled
When Boot guard is enabled, Locality event would be
logged from Boot guard library.

Signed-off-by: Subash Lakkimsetti <subashx.lakkimsetti@intel.com>
2019-03-13 08:34:15 -07:00
Maurice Ma a62bd10f63 Add framebuffer info into Multiboot table
Multiboot defined framebuffer structure.  However, it was not
implemented in SBL.  This patch added this support by filling in
the framebuffer information into the multiboot table.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-03-06 13:28:10 -08:00
Maurice Ma 93d1915742 Add FAT long file name support
This patch enhanced the FAT library to support long file name. The
old driver only supports 8.3 short name. Combined with FAT full path
support, the FAT library now can load any file from the partition.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-03-04 17:42:11 -08:00
Maurice Ma 072d5f5427 Add full path support for FAT file loading
Current FAT library can only support loading file from the root
directory of FAT file system. This patch enhanced it to support
load file from FAT file system with any give full path. Both unix
and Windows style path are supported. For example, "efi\boot.cfg",
"\efi\boot.cfg", "/efi/boot.cfg", etc, all are valid path string.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-02-26 08:53:08 -08:00
Maurice Ma 7b37f56ff2 Refactor LiteFvLib/LitePeCoffLib implementation
This patch did some clean up for LiteFvLib and LitePeCoffLib.  It
also moved LoadFvImage() API from Stage2 core code into the LiteFvLib.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-01-31 14:06:36 -08:00
Guo Dong 095f281023 Enhance UEFI payload support
Previously SBL expects UEFI payload entrypoint and base at
hardcoded address of FV header. With this patch, SBL could
parse FV to get these info.

TEST=Tested on Leafhill and boot UEFI payload success.

Signed-off-by: Guo Dong <guo.dong@intel.com>
2019-01-28 13:54:11 -08:00
Maurice Ma 1f972af0cd Fix large file read issue on USB device
The current USB block read library trancated the number of blocks
to read from UINT32 to UINT16. It caused read issue for large file
on USB disk. This patch fixed #63. It has been verified on LeahHill
CRB platform.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2019-01-07 13:30:57 -08:00
Huang Jin 3009428255
Fix bug in file system library
When InitFileSystem() API is given EnumFileSystemTypeFat in argument,
the FAT file system is not initialized. This bug is discovered when
firmware update payload fails to load capsule from FAT partition via
shell interface.

Fixed #62 

TEST=Created FwuImage.bin and perform firmware update from SBL shell on
     UP2 board. Verified successful update and booting to Ubuntu 16.04
     from eMMC

Signed-off-by: Huang Jin <huang.jin@intel.com>
2019-01-03 13:18:25 -08:00
Guo Dong 501be46716 Update file system support
The patch gives the platform the configuration capability to only build
required file system into final image.
This helps to have a smaller image for fast boot.

Signed-off-by: Guo Dong <guo.dong@intel.com>
2018-11-27 15:09:14 -07:00