Commit Graph

1368 Commits

Author SHA1 Message Date
Michał Kopeć 0285e00e8b BaseTools/Source/Python: Add -noattr to capsule signing openssl commands
This makes capsule PKCS#7 signatures reproducible.

openssl smime -sign embeds a signingTime signed attribute (current
UTCTime) by default. Because the attribute is inside the signed
digest, the resulting RSA signature differs on every invocation even
when the key and payload are identical, breaking reproducible builds
of signed FMP capsules.

Pass -noattr to drop all signed attributes from the SignerInfo. The
signature is then computed directly over the content, producing
byte-identical output across runs.

The FMP update path is unaffected: FmpAuthenticationLibPkcs7 calls
Pkcs7Verify() without extracting signed attributes, and rollback
protection uses FwVersion / LowestSupportedVersion in
FMP_PAYLOAD_HEADER plus the auth header MonotonicCount, not
signingTime. signingTime is only consumed by DxeImageVerificationLib
for Secure Boot dbt checks on PE/COFF images, which is a separate
code path.

Signed-off-by: Michał Kopeć <michal.kopec@3mdeb.com>
2026-05-19 16:43:55 +03:00
Sergii Dmytruk 6641250988 BaseTools/GenerateCapsule.py: fix --decode omitting EmbeddedDrivers in JSON
Collect paths to drivers as they being saved and pass to
GenerateOutputJson() for inclusion into the output JSON file.

Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
2026-05-03 01:03:12 +03:00
Sergii Dmytruk 7b88f63516 BaseTools/GenerateCapsule.py: skip pointless verification on --decode
When a capsule is signed, --decode printed a warning if neither openssl
nor signtool was configured via command-line options.  And yet, it then
proceeded to attempt the verification anyway.

Current implementation only ever uses --trusted-public-cert during
verification, so there could be some logic to this behaviour.  However,
it's still confusing, so don't attempt to verify anything if it's not
expected to work.

Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
2026-05-03 01:03:12 +03:00
Sergii Dmytruk b3ce4fc718 BaseTools/GenerateCapsule.py: fix --decode producing bad "Dependencies"
The "Dependencies" key of Payloads was set to "None" string for capsules
with no DepEx.  The produced JSON file wasn't suitable for passing back
to --encode without modifications.

Fix the issue by removing such invalid "Dependencies" keys similarly how
it's done for keys related to signing.

Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
2026-05-03 01:03:12 +03:00
Michael D Kinney 12f785f106 Revert "BaseTools: Add support for out-of-tree builds"
This reverts commit 3fe1d56cc9.

PR https://github.com/tianocore/edk2/pull/11757 introduced a
"Breaking Change" feature for out of tree builds of tools.

This breaking change is blocking testing of edk2-stable202602
due to side effects on building FitGen tool in edk2-platforms.

Revert this feature for the edk2-stable202602 release and
work on this feature after the release.

Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2026-02-11 22:53:29 +00:00
Oleksandr Tymoshenko 3fe1d56cc9 BaseTools: Add support for out-of-tree builds
Main EDK2 build supports out-of-tree builds but BaseTools make process
still creates tools and object files in-tree. In order to make
out-of-tree build support complete move the generated tools and
interim obj files to $WORKSPACE location as well.

This patch also changes the location of BaseTools for in-tree builds
(default behavior when WORKSPACE is not provided before calling
edksetup) to $WORKSPACE/BaseTools/Build/... It may potentially break
external workflows that invoke tools from the default location outside
of the build tool.

Signed-off-by: Oleksandr Tymoshenko <ovt@google.com>
2026-02-02 08:56:31 +00:00
PaddyDeng c2915d24a1 BaseTools: Prevent Subsection PCDs from polluting global expressions
The PCD value defined in module subsections can be added to global PCD
database. Therefore the unsolved expressions, even belongs to the global
scope, can incorrectly refer to the value from module subsection.

This only happens when the referred PCD has no value assignment in the
platform dsc file. Which also should raise an error.

Signed-off-by: Paddy Deng <paddydeng@ami.com>
2026-01-30 09:55:39 +00:00
Michael D Kinney a0002ddc53 BaseTools/build: Add defines for Windows build environments
The stuart tools automatically add -D WIN_HOST_BUILD to
edk2 build command line if a Windows build environment
is detected. This behavior is added to build.py so that
builds of the EmulatorPkg using build.py are not required
to add the option -D WIN_HOST_BUILD when building in a
Windows environment. This aligns Linux and Windows builds
of the EmulatorPkg removing the need to specify extra
defines.

In order to build the EmulatorPkg for Windows Mingw
environments, EmulatorPkg DSC/FDF files require a way
to detect if Windows Mingw environment is present.
The Windows Mingw environment can be detected if
CLANG_BIN is set and mingw32-make.exe is detected
in the CLANG_BIN directory.

If a Windows Mingw environment is detected, add
-D WIN_MINGW32_BUILD to the edk2 build command line.

Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2026-01-06 04:44:08 +00:00
Michael D Kinney 79fdd2b82a BaseTools: GNUMakefiles must use CMD.EXE in Windows
Use $(OS) in all GNUMakefiles to detect if the GNUMakefile
is being used in a Windows OS. If a Windows OS is detected,
then override SHELL to use cmd.exe. This prevents make
utility from using sh.exe if sh.exe happens to be in PATH.

If sh.exe is used, then backslash (\) characters in file
paths are removed and builds break for files not found.

Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-12-24 02:03:38 +00:00
Ayden Meng a058a2856d BaseTools: Cap AutoGen thread count to avoid file descriptor exhaustion
When the number of build threads multiplied by per-thread file
descriptor usage exceeds the system's open file descriptor limit,
some threads may fail to acquire necessary resources (e.g., pipes
or semaphores), leading to deadlocks or hangs during parallel builds.

To prevent this situation, calculate the safety upper limit of
concurrency by dividing the system's maximum file descriptor limit by
3 (An empirical value derived from balancing performance overhead
against the theoretical number of file descriptors consumed per thread).
The actual thread count is then clamped to this safe value.

Other usages of ThreadNum()—such as during actual compilation or log
queue creation—do not significantly contribute to file descriptor
consumption. Therefore, adjusting ThreadNum() globally would be
unwarranted, as it could unnecessarily restrict parallelism in stages
that are not FD-bound.

This ensures stable parallel builds even under constrained resource
limits.

Signed-off-by: Ayden Meng <mengxiangdong@loongson.cn>
2025-12-03 14:11:32 +00:00
Ayden Meng 7aaf742d2d BaseTools: Handle file descriptor exhaustion during parallel build
Previously, when file descriptors were exhausted in high-concurrency
builds (e.g., 512 threads with 1024 FD limit), the build would hang or
fail silently without clear indication of the root cause.

This change catches relevant OSError instances and terminates the build,
ensuring failures due to resource limits are explicit.

Signed-off-by: Ayden Meng <mengxiangdong@loongson.cn>
2025-12-03 14:11:32 +00:00
Jeremy Compostella 3af7eccf47 BaseTools: AutoGen: Optimize tuple creation using tuple() for PcdDbBuffer
Replace manual loop-based tuple construction with the built-in tuple()
function when converting PcdDbBuffer to a tuple. This change
significantly improves performance—approximately three times
faster—resulting in substantial build time savings in large
environments.

Previously, the code iterated over each byte in PcdDbBuffer, unpacking
and appending it to a tuple. The new approach leverages
tuple(PcdDbBuffer) to achieve the same result more efficiently. The
generated tuple remains identical to the original implementation.

TEST=The generated tuple is the same than with to original code

Signed-off-by: Jeremy Compostella <jeremy.compostella@intel.com>
2025-12-02 02:21:22 +00:00
Yuwei Chen d8a171b895 BaseTools: Enhance FMMT rebase feature with FFS type check
1.Add FFS file type check: Only allow rebase operation for
EFI_FV_FILETYPE_SECURITY_CORE, EFI_FV_FILETYPE_PEI_CORE,
EFI_FV_FILETYPE_DXE_CORE, EFI_FV_FILETYPE_PEIM, EFI_FV_FILETYPE_DRIVER,
EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER,EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
types, improving safety and compliance.
2.Automatically detect and complete the PE/COFF or TE image
relocation table (reloc section) to ensure integrity and compatibility
of the rebase operation.
3.After rebase, automatically update FFS checksum and FV header
information to ensure correct data structure.
4.Support recursive processing for nested FVs, ensuring all related FFS
files' PE/TE images are properly rebased and reloc tables are completed.
5.Use table-driven architecture for relocation types, making it easier to
extend to more platforms.
6.Improve error handling and logging for better robustness and
maintainability.

Please attention, only IA32 and X64 PE/COFF image are supported now.
For other Arch, will support it after testing.

Signed-off-by: Yuwei Chen <yuwei.chen@intel.com>
2025-11-23 23:30:49 +00:00
Yuwei Chen 7977926811 BaseTools: Enable FMMT Rebase function
This patch adds and improves the rebase functionality
for firmware images (PE/COFF/TE) in the FMMT tool.
Key features include:

1.Automatically rebases PE/COFF/TE images within FFS files
when the firmware volume (FV) layout is adjusted or FFS files
are moved, ensuring correct loading and execution at new addresses.
2.Implements recursive rebase logic for nested sections,
guaranteeing all relevant images are properly relocated.
3.Adds support for rebasing subsequent FFS files within the same FV,
enhancing compatibility and stability during firmware layout changes.
4.Core code changes are mainly in FvHandler.py, BiosTreeNode.py,
and BinaryFactoryProduct.py, covering rebase flag detection, address calculation,
and actual relocation operations.
5.This feature improves the flexibility of firmware space management
and enhances the automation and reliability of the FMMT tool.

Co-Auther: Ashraf Ali S <ashraf.ali.s@intel.com>
Signed-off-by: Yuwei Chen <yuwei.chen@intel.com>
2025-11-23 23:30:49 +00:00
Evgenii Shatokhin e93ee87643 BaseTools: FMMT: Fix incorrect size calculation in ModifyTest()
There is another issue in FvHander.py similar to the one fixed by
a60334ad59 ("BaseTools: Fix FMMT FvHandler Padding operation issue").

For a guided section (ParTree.Data.Type == 0x02), the length of
ParTree.Data.OriData is used to obtain the original size of the data even
after ParTree.Data.OriData has changed, which is incorrect.

This caused the following issue I observed. I built OVMF image for Aarch64
and then tried to add a couple FFS modules to it with 'FMMT -a [...]'. The
resulting image turned out to be invalid: the total size of the image was
less than the size of the firmware volume within it.

UEFITool failed to load such firmware image and complained:
"parseRawArea: one of objects inside overlaps the end of data".

This patch fixes the issue.

Signed-off-by: Evgenii Shatokhin <euspectre@gmail.com>
2025-11-22 11:53:36 +00:00
Philipp Schuster e0184abff1 BaseTools: fix various typos
This commit is the first in a series of multiple commits to fix various
typos in the code, originating mostly from copy&paste over the years.

Most of them only affect documentation and not code.

Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2025-11-21 21:49:59 +00:00
Sathya Ravichandran 98d1f8a6fd BaseTools: Remove DXE_SAL_DRIVER
The DXE_SAL_DRIVER module type was introduced to support
Itanium (IPF) platforms. Since support for Itanium processors has been
dropped, the instances of DXE_SAL_DRIVER have been removed.

Ref: [3cb0a311cb]

Cc: Sachin Ganesh <sachinganesh@ami.com>
Signed-off-by: Sathya Ravichandran <sathyar@ami.com>
2025-10-30 10:00:32 +00:00
Ashraf Ali S e494b25fe3 BaseTools:Remove deprecated ast.Str import for Python 3.14 compatibility
- Str is not being used in FvHeader.py
- Removed import of ast.Str as it was removed in Python 3.14.
- Ensures compatibility with Python 3.14 and later.
- https://docs.python.org/3/whatsnew/3.14.html#id9

This addresses ImportError caused by removal of deprecated AST classes
including ast.Str.

Signed-off-by: Ashraf Ali S <ashraf.ali.s@intel.com>
2025-10-21 02:45:38 +00:00
Phil Noh 1e7a83cbb6 BaseTools/FMMT: Fix errors when operating the FV with CRC32 section
Currently the FMMT tool supports CRC32 GUID section (Ref. GuidTools.py).
But it is found that there are errors for the FV with CRC32 section.
For example, the errors are checked on the following commands.

--v : Show FV information except for the FV
--a : Show "Target Fv not found!!!" when adding an FFS file to the FV
--d : Show "Target Ffs not found!!!" when deleting an FFS file in the FV

They are caused by the mismatch for CRC32 section data between the FMMT
and GenCrc32 tools. The FMMT tool returns CRC32 section data without CRC
checksum field (4 bytes). The GenCrc32 tool (with -d option, verify CRC32
value for the input file) requires CRC32 section data including CRC
checksum field (4 bytes).

Fix the issue through adjusting the section data to include CRC checksum
field. Currently DataOffset field for CRC32 GUID section is reported as
0x1C differently (GUID Section header length: 0x18 + Checksum field: 0x4).
Instead of DataOffset field that includes CRC checksum field, configure
the section data based on the offset from section header length (0x18)
that was previously calculated. This update enables GUID sections to use
the same offset consistently.

Signed-off-by: Phil Noh <Phil.Noh@amd.com>
2025-10-16 14:14:06 +00:00
Leif Lindholm fcc568ca6e BaseTools/build.py: set BUILD_TIME_EPOCH if not already in environment
Set BUILD_TIME_EPOCH to the current UTC timestamp if not already present
in the environment.

Use the resulting value to print the "Build start time:" message.

Signed-off-by: Leif Lindholm <leif.lindholm@oss.qualcomm.com>
2025-10-16 10:41:09 +00:00
Leif Lindholm 5ca97bf64f BaseTools/build.py: language cleanup around CheckEnvVariable
The function CheckEnvVariable in fact checks several environment
variables. And the comment at its invocation enumerates a specific set of
variables, which defeats half the point of abstracting it out into a
helper function.

Rename the function to the plural form and turn the comment into a list
of examples.

Signed-off-by: Leif Lindholm <leif.lindholm@oss.qualcomm.com>
2025-10-16 10:41:09 +00:00
Oliver Smith-Denny 2ff173af12 BaseTools: Remove ARM32 Support
edk2 is dropping support for the ARM32 architecture. This
commit removes ARM32 code from BaseTools.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
2025-09-25 22:04:10 +00:00
Sergii Dmytruk 433bbe6e49 BaseTools: DSC: fix processing !include in multiarch subsections
Commit f0a2015373 ("UefiPayloadPkg: Add AARCH64 support") changed
`[Components.X64]` to `[Components.X64, Components.AARCH64]` which
resulted in the following code within that section to not work as
expected (the code wasn't there, just providing a real world example
that uncovered the issue):

[Components.X64, Components.AARCH64]
    FmpDevicePkg/FmpDxe/FmpDxe.inf {
      ...
      <PcdsFixedAtBuild>
        !include .../...PcdFmpDevicePkcs7CertBufferXdr.inc
      ...
    }

At the same time `[Components.X64]` or even `[Components.AARCH64,
Components.X64]` (notice the swapped order) worked fine for X64 target.

The cause of the issue turned out to be skipping includes inside
`_PostProcess()` method of `DscParser` class.  This method processes
list of items stored in a database filled on the first pass through a
DSC file in `Start()` method.  One of the fields stored in each row
of a table is link to a parent object (owner).  A section like
`[Components.X64, Components.AARCH64]` creates two objects and all of
its subelements are duplicated for both X64 and AARCH64.  This was not
happening for !include statement in the example above.

Because `_PostProcess()` contracted a sequence of !include objects
disregarding their owner, it did not create instance for each of the
requested targets.  Codewise, `self._ContentIndex` was incremented more
than once, while `__ProcessDirective()` method (invoked indirectly as
`Processer[self._ItemType]()`) queried owner of the current directive
as:

    if self._InSubsection:
        Owner = self._Content[self._ContentIndex - 1][8]
    else: # not taken in this case

This is why order of targets made a difference, only the last was fully
initialized in this case.

An alternative fix is completely dropping merging of !include
directives, but hard to say whether it still has some utility (the code
is complex, hard to follow and barely documented).  Safer to keep it, in
the worst case it doesn't do anything now.

Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
2025-08-25 11:54:17 +00:00
Yuwei Chen a60334ad59 BaseTools: Fix FMMT FvHandler Padding operation issue
When using the FMMT FvHandler function, new padding size
should be calculated correctly comparing with origin ffs
and new ffs, else it will cause the binary size changes.
This patch is used to fix the bug.

Signed-off-by: Yuwei Chen <yuwei.chen@intel.com>
2025-07-30 02:44:25 +00:00
Aaron Pop 0277d5d8f1 BaseTools: Improve report generation for Nested Fvs.
Build report would not detect a nested FV if the nested
FV was not in a subsection of an FFS statement.

Modify the build report to better handle some of the
variations of nested FVs.

Failing Example:

[Fv.FvName1]
  INF <path to some driver>.inf

[Fv.FvName0]
  FILE FV_IMAGE = B25ACDEF-39CE-4FA5-B50A-33E24DB1BDDF {
    SECTION FV_IMAGE = FvName1
  }

Working Example:

[Fv.FvName1]
  INF <path to some driver>.inf

[Fv.FvName0]
FILE FV_IMAGE = DA04F6BF-A0FD-47EC-928B-5101A6C95026 {
  SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF
    PROCESSING_REQUIRED = TRUE {
      SECTION FV_IMAGE = FvName1
  }
}

Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
2025-07-08 10:06:36 +08:00