In FfsProcessSection(), delete CompressionSectionHeaderSize and move
CompressedData to avoid the compiler warning without changing functional
behavior.
Signed-off-by: Tuan Phan <tuan.phan@oss.qualcomm.com>
EmbeddedPkg's PrePiLib and OvmfPkg's PeilessStartupLib (which
uses PrePiLib) only produce FV2 HOBs for extracted FVs. However,
FV3 HOBs have superceded FV2 HOBs for describing extracted FVs.
This commit updates both of these libs to also produce FV3 HOBs,
following PEI's pattern of producing an FV, FV2, and FV3 HOB for
each extracted FV.
Eventually, only FV3 HOBs will be produced, so this paves the way
for that.
Continuous-integration-options: PatchCheck.ignore-multi-package
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
PrePiLib is incorrectly producing FV2 HOBs. The FvName field of
the FV2 HOB is intended to be the parent FV's name. This way the
HOB consumer phase can identify when an FV has already been
extracted: if the file name of the extracted FV and the parent
FV name match in the FV2 HOB.
With the incorrect FvName, DXE will re-extract the already
extracted FV, which can be a large performance hit (some platforms
we have seen ~1 second).
This requires an update to FfsProcessFvFile to pass the parent
FV handle through so the FV2 HOB can be correctly produced.
OvmfPkg consumers are also updated.
Continuous-integration-options: PatchCheck.ignore-multi-package
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
FfsGetVolumeInfo() in PrePiLib does not zero the VolumeInfo
buffer before writing to it. However, it has some fields that
are expected to be zero if certain conditions are not met.
For example, the FvName is expected to be all 0's if the
extended header is not present in the FV. Currently,
the FvName field will point to garbage if the caller does
not zero the buffer first.
Flip the expectation and have FfsGetVolumeInfo() zero the
buffer before it writes to it.
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
PrePiLib only searches for the existence of an FV2 HOB to
determine if an FV has already been extracted. However,
FV2 HOBs have been superceded by FV3 HOBs for describing extracted
FVs.
This commit updates PrePiLib to check for the existence of either
an FV2 or FV3 HOB for this FV and skips extracting if either is
found.
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
PrePi.h has some duplicate HOB definitions from HobLib.h.
Instead of redefining them, use HobLib.h.
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
This reverts commit 57230fff6b.
RealTimeClockLib is not a generic library class that is intended to be
used widely to get access to the RTC when the associated runtime
services are not available in the calling context.
The purpose of RealTimeClockLib is to abstract the underlying hardware
access from the generic RealTimeClockRuntimeDxe driver, which backs the
runtime services.
This means it does not belong in a different package; it belongs in the
same package as the driver.
Continuous-integration-options: PatchCheck.ignore-multi-package
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
The PrePiMemoryAllocationLib supports AllocateAlignedPages(),
however is missing the corresponding FreeAlignedPages().
Although the FreeAlignedPages() in PrePiMemoryAllocationLib
does not support the ability to free pages in the PrePei Memory
Allocator and the allocated memory is lost, it would be good
to have an empty implementation of FreeAlignedPages() so that
implementations utilises the correct deallocation function.
Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
Symptom:Unsafe typecasting may lead to out‑of‑bound memory access
RootCause: FileSize and FileLength are declared as
UINT32 and masked with 0x00FFFFFF to store only the lower 24 bits.
Although this approach yields the correct result,
it introduces a potential risk due to unsafe typecasting and
dereferencing.
Solution: Using the predefined macro FFS_FILE_SIZE()
from MdePkg\Include\Pi\PiFirmwareFile.h,
which safely performs the same operation by reconstructing
the size using individual byte access.
This commit also addresses the fix for coverity isssue "OVERRUN"
Cc: Sachin Ganesh <sachinganesh@ami.com>
Signed-off-by: Gowtham M <gowthamm@ami.com>
The Inf file standard specifies that comments begin with the
characters "#". The following files contained incorrectly
formatted C-style comments and have been updated:
EmbeddedPkg/Library/DxeDtPlatformDtbLoaderLibDefault/DxeDtPlatformDtbLoaderLibDefault.inf
EmbeddedPkg/Library/NorFlashInfoLib/NorFlashInfoLib.inf
The problems were identified during testing of the parser
https://github.com/xpahos/edk2-idea.
Signed-off-by: Alexander Gryanko <xpahos@gmail.com>
Replace traditional `#ifndef`/`#define`/`#endif` include guards with
`#pragma` once.
`#pragma once` is a widely supported preprocessor directive that
prevents header files from being included multiple times. It is
supported by all toolchains used to build edk2: GCC, Clang/LLVM, and
MSVC.
Compared to macro-based include guards, `#pragma once`:
- Eliminates the risk of macro name collisions or copy/paste errors
where two headers inadvertently use the same guard macro.
- Eliminate inconsistency in the way include guard macros are named
(e.g., some files use `__FILE_H__`, others use `FILE_H_`, etc.).
- Reduces boilerplate (three lines replaced by one).
- Avoids polluting the macro namespace with guard symbols.
- Can improve build times as the preprocessor can skip re-opening the
file entirely, rather than re-reading it to find the matching
`#endif` ("multiple-include optimization").
- Note that some compilers may already optimize traditional include
guards, by recognzining the idiomatic pattern.
This change is made acknowledging that overall portability of the
code will technically be reduced, as `#pragma once` is not part of the
C/C++ standards.
However, this is considered acceptable given:
1. edk2 already defines a subset of supported compilers in
BaseTools/Conf/tools_def.template, all of which have supported
`#pragma once` for over two decades.
2. There have been concerns raised to the project about inconsistent
include guard naming and potential macro collisions.
Approximate compiler support dates:
- MSVC: Supported since Visual C++ 4.2 (1996)
- GCC: Supported since 3.4 (2004)
(http://gnu.ist.utl.pt/software/gcc/gcc-3.4/changes.html)
- Clang (LLVM based): Since initial release in 2007
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
When allocating Runtime memory the MemoryAllocation HOB's length needs
to meet the alignment requirements of Runtime memory. On AARCH64
architectures this alignment is not the default of 4KB.
Instead it is set by the RUNTIME_PAGE_ALLOCATION_GRANULARITY
definition, which is 64KB.
This change enforces the RUNTIME alignment as part of generating the
MemoryAllocationHob for runtime memory types.
Signed-off-by: Antaeus Kleinert-Strand <antklein@microsoft.com>
The comment for the Buffer parameter incorrectly said
"then no the size" instead of "then the size".
This patch fixes the typo only; no functional changes.
Signed-off-by: Dongyan Qian <qiandongyan@loongson.cn>
ArmVirtPkg uses PrePiMemoryAllocationLib and PeiServicesLib in
the same module. PeiServicesLib depends on MemoryAllocationLib,
fulfilled by PrePiMemoryAllocationLib in this instance. However,
PeiServicesLib uses AllocateCopyPool() which is not provided in
PrePiMemoryAllocationLib. CLANGPDB AARCH64 finds this as a link
error. Other toolchains are optimizing the call out since that
code path is not used in this module.
This adds AllocateCopyPool() to PrePiMemoryAllocationLib to
satisfy the dependency.
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
CLANGPDB AARCH64 catches that PrePiHobLib doesn't correctly
list the library classes and protocols it uses. This resolves
that.
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
Change VirtualRealTimeClockLib.inf to use SOURCE_DATE_EPOCH
instead of Linux only shell command. This allows this library
to be used in Windows build environments.
Signed-off-by: Leif Lindholm <leif.lindholm@oss.qualcomm.com>
edk2 is dropping support for the ARM32 architecture. This
commit removes ARM32 code from EmbeddedPkg. This also drops
irrelevant VALID_ARCHITECTURES comments from infs that are not
arch specific.
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
Drop an else wrapper in FfsProcessSection () on the other side of
an if-statemenmt that is an error return.
Signed-off-by: Leif Lindholm <leif.lindholm@oss.qualcomm.com>
The "Found" variable provided only a deferred form of success handling, so
eliminate it to improve readability.
Signed-off-by: Leif Lindholm <leif.lindholm@oss.qualcomm.com>
Create some helper functions to make FfsProcessSection at least halfway
readable by both humans and compilers.
Signed-off-by: Leif Lindholm <leif.lindholm@oss.qualcomm.com>
RealTimeClockLib is an architectural implementation that is not
restricted to the embedded segment or any platform in particular.
So the header has been moved to MdeModulePkg.
And the package has been added to the relevant INF files.
Continuous-integration-options: PatchCheck.ignore-multi-package
Signed-off-by: Sachin Ganesh <sachinganesh@ami.com>
PrePiMemoryAllocationLib does not implement functions to allocate
EfiMemoryReservedType. These are implemented in other instances of
MemoryAllocationLib (Dxe, Uefi, PiSmmCore, SmmMemory).
Add AllocateReservedPages() and AllocateAlignedReservedPages()
functions to make it consistent with other MemoryAllocationLib
intstances.
Signed-off-by: Vishal Oliyil Kunnil <vishalo@qti.qualcomm.com>
According to the UEFI Specification version 2.11, the valid range for the
Year field in the EFI_TIME structure is from 1900 to 9999.
Currently IsTimeValid() checks a restricted range 2000 - 2099.
Update range in TimeBaseLib.c to match UEFI specification.
Signed-off-by: Pankaj Singh <pansing@qti.qualcomm.com>
With all in-tree users migrated, finally delete this.
Any out-of-tree users need to migrate to MdePkg BaseFdtLib.
Signed-off-by: Leif Lindholm <leif.lindholm@oss.qualcomm.com>
Migrate these packages to use the up-to-date BaseFdtLib instead
of the EmbeddedPkg relic that is going away.
Continuous-integration-options: PatchCheck.ignore-multi-package
Signed-off-by: Leif Lindholm <leif.lindholm@oss.qualcomm.com>
This commit is to add two new APIs in EmbeddedPkg
PrePiHobLib:
1.The GetNextMemoryAllocationGuidHob () returns the next
instance of the Memory Allocation HOB with the matched
GUID from a starting HOB pointer.
2.The TagMemoryAllocationHobWithGuid () searchs the HOB
list for the Memory Allocation HOB with a matching base
address and set the Name GUID. Then the instance of the
tagged Memory Allocation HOB with matched base address is
returned.
Signed-off-by: Dun Tan <dun.tan@intel.com>
Makes changes to comply with alerts raised by CodeQL.
Most of the issues here fall into the following two categories:
1. Potential use of uninitialized pointer.
2. Inconsistent integer width in comparison.
Co-authored-by: Taylor Beebe <taylor.d.beebe@gmail.com>
Co-authored-by: Ken Lautner <kenlautner3@gmail.com>
Co-authored-by: Bret Barkelew <bret@corthon.com>
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
The "Found ACPI table" messages are informative and don't indicate an
error, so reduce the debug level from DEBUG_ERROR to DEBUG_INFO.
Signed-off-by: Rebecca Cran <rebecca@bsdio.com>
Removes the following types from the memory type information HOB
produced:
- `EfiBootServicesCode`
- `EfiBootServicesData`
- `EfiLoaderCode`
- `EfiLoaderData`
This follows the guidance in the whitepaper "A Tour Beyond BIOS
Memory Map and Practices in UEFI BIOS".
https://github.com/tianocore-docs/Docs/raw/master/White_Papers/A_Tour_Beyond_BIOS_Memory_Map_And_Practices_in_UEFI_BIOS_V2.pdf
"NOTE: We recommend a platform only define the ReservedMemory,
ACPINvs, ACPIReclaim, RuntimeCode, RuntimeData in Memory Type
Information table, because OSes only request these regions to be
consistent. There is no need to add BootServicesCode,
BootServicesData, LoaderCode, LoaderData in memory type information
table, because these regions will not be reserved during S4 resume."
Since these memory types are not tracked in memory type information
any longer it also reduces the number of resets that may need to
occur to update memory type buckets that are not needed.
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Add missing includes of BaseMemoryLib.h and declaration of
BaseLib/BaseMemoryLib dependencies hidden by use of EmbeddedPkg
FdtLib, which is being deleted.
Signed-off-by: Leif Lindholm <quic_llindhol@quicinc.com>
After updating Doxygen, we can see that SetBootMode returns the BootMode
instead of status code as it should, fix it to return status.
Signed-off-by: Vishal Oliyil Kunnil <quic_vishalo@quicinc.com>
The Doxygen comment for SetBootMode and GetBootMode in PrePiHobLib/Hob.c
does not match declaration in PrePiLib.h. The C file has it wrong. Align
the text to match the header.
Signed-off-by: Vishal Oliyil Kunnil <quic_vishalo@quicinc.com>
LocateAndInstallAcpiFromFvConditional was always returning EFI_SUCCESS
even when it failed to find `AcpiFile`. Fix that, and improve the layout
by checking if an error occurred and breaking earlier.
Signed-off-by: Rebecca Cran <rebecca@bsdio.com>
When cspell is installed (via `npm install cspell`), CI checks for
spelling mistakes. There are currently a very large number of them: some
are genuine mistakes while others are words or acryonyms that cspell
doesn't know.
Fix a few of the misspellings in EmbeddedPkg.
Signed-off-by: Rebecca Cran <rebecca@bsdio.com>
Retire the ancient reset runtime DXE in EmbeddedPkg, and the associated
EfiResetSystemLib library class and template implementation. These are
incomplete and have been superseded by a generic implementation in
MdeModulePkg.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Commit 8984fba2f2 added setting the
EFI_MEMORY_XP attribute on DMA buffers. However, it did not ensure
that the XP capability was set on that region.
This patch adds setting the XP capability before attempting to set
the attribute. If setting the capability fails, it defaults to the
old behavior of not setting the XP bit.
Signed-off-by: Oliver Smith-Denny <osde@linux.microsoft.com>
When allocating memory for a non-coherent DMA device, the current core
code removes the XP attribute, allowing code to execute from that
region. This is a security vulnerability and unneeded. This change
updates to mark the region as XP when allocating memory for the
non-coherent DMA device.
Signed-off-by: Oliver Smith-Denny <osde@linux.microsoft.com>
RISC-V ovmf used VirtualRealTimeClockLib but the default epoch is a
compilation time. It causes that the RISC-V ovmf binary image is NOT
reproducible.
This patch added the support of SOURCE_DATE_EPOCH by printenv command.
If SOURCE_DATE_EPOCH be found then we use it as BUILD_EPOCH. Otherwise
we run date command for setting BUILD_EPOCH.
For distributions want a reproducible RISC-V ovmf image, they should
export SOURCE_DATE_EPOCH environment variable before building ovmf.
References: https://reproducible-builds.org/docs/source-date-epoch/
Cc: Pete Batard <pete@akeo.ie>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: "Lee, Chun-Yi" <jlee@suse.com>
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4668
This commit fixes the issue reported in the BZ4668.
The EmbeddedPkg fails to compile with a compiler error
generated due to invalid/illegal arithmetic operation
on void pointers. It has been fixed by using explicit
type conversion of the void pointer to UINTN.
Cc: Rebecca Cran <rebecca@bsdio.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Abner Chang <abner.chang@amd.com>
Cc: Jayaprakash N <n.jayaprakash@intel.com>
Signed-off-by: Jayaprakash N <n.jayaprakash@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Ard Biesheuvel <ardb+tianocore@kernel.org>
Acked-by: Michael D Kinney <michael.d.kinney@intel.com>
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4166
Fix integer overflow in various CreateHob instances.
Fixes: CVE-2022-36765
The CreateHob() function aligns the requested size to 8
performing the following operation:
```
HobLength = (UINT16)((HobLength + 0x7) & (~0x7));
```
No checks are performed to ensure this value doesn't
overflow, and could lead to CreateHob() returning a smaller
HOB than requested, which could lead to OOB HOB accesses.
Reported-by: Marc Beatove <mbeatove@google.com>
Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Reviewed-by: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Abner Chang <abner.chang@amd.com>
Cc: John Mathew <john.mathews@intel.com>
Authored-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Gua Guo <gua.guo@intel.com>
Add implementation of ReallocatePool which is defined in the
MemoryAllocationLib header file to allow components to not
need special handling for PrePi module types.
Signed-off-by: Jeff Brasen <jbrasen@nvidia.com>
AndroidBootImgLib allows for platforms to append to kernel command
line but does not allow for the overall kernel command line to go
beyond the limit set by the image header. Address this limitation
by adding a pcd where platform can tell how many extra characters
they expect on their platform in addition to what the image header
specifies.
Signed-off-by: Ashish Singhal <ashishsingha@nvidia.com>
Reviewed-by: Abner Chang <abner.chang@amd.com>
Curently, AndroidBootImgLib expects input kernel command line
to never exceed 256 unicode characters where the image header
allows for 512 ascii characters. If image header allows 512
ascii characters, similar number of unicode characters should be
allowed at the minimum.
Signed-off-by: Ashish Singhal <ashishsingha@nvidia.com>
Reviewed-by: Abner Chang <abner.chang@amd.com>
The RealTimeClockLib class header in edk2 mistakenly declares a function
called LibRtcVirtualNotifyEvent(). No component ever calls this function
crossing module boundaries; all RealTimeClockLib instances in edk2 and
edk2-platforms are supposed to register (and do register) their
SetVirtualAddressMap() notification functions.
In particular, VirtualRealTimeClockLib *itself* doesn't even use
LibRtcVirtualNotifyEvent() -- the function is defined with an empty body,
clearly in an understandable, but misguided, attempt, to conform to the
(bogus) library interface. Remove the function.
Build-tested only (with "RiscVVirtQemu.dsc").
Cc: Abner Chang <abner.chang@amd.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Daniel Schaefer <git@danielschaefer.me>
Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=4564
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20231012091057.108728-5-lersek@redhat.com>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
The RealTimeClockLib class header in edk2 mistakenly declares a function
called LibRtcVirtualNotifyEvent(). No component ever calls this function
crossing module boundaries; all RealTimeClockLib instances in edk2 and
edk2-platforms are supposed to register (and do register) their
SetVirtualAddressMap() notification functions.
In particular, TemplateRealTimeClockLib *itself* doesn't even use
LibRtcVirtualNotifyEvent() -- the function is defined with an empty body,
clearly in an understandable, but misguided, attempt, to conform to the
(bogus) library interface. Remove the function.
Build-tested only (with "EmbeddedPkg.dsc").
Cc: Abner Chang <abner.chang@amd.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Daniel Schaefer <git@danielschaefer.me>
Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=4564
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20231012091057.108728-4-lersek@redhat.com>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
__FUNCTION__ is a pre-standard extension that gcc and Visual C++ among
others support, while __func__ was standardized in C99.
Since it's more standard, replace __FUNCTION__ with __func__ throughout
EmbeddedPkg.
Signed-off-by: Rebecca Cran <rebecca@bsdio.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Abner Chang <abner.chang@amd.com>
The code never references the PCD so the INF should not reference it
either. The last reference was moved to PrePiHobLib in commit
05e48e0083 (dated 2011!) and dropped from there as well in
commit 9710639195.
Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Cc: Abner Chang <abner.chang@amd.com>
Cc: Daniel Schaefer <git@danielschaefer.me>
Reported-by: Sunil V L <sunilvl@ventanamicro.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>