summaryrefslogtreecommitdiff
path: root/BaseTools/Source/Python
AgeCommit message (Collapse)AuthorFilesLines
3 daysBaseTools/FirmwareStorageFormat: Fix FV ext entry struct factory functionsMichael D Kinney1-2/+2
The Refine_FV_EXT_ENTRY_OEM_TYPE_Header() and Refine_FV_EXT_ENTRY_GUID_TYPE_Header() functions incorrectly return an instantiation attempt of the local class with `Structure` as an argument (e.g., `return ClassName(Structure)`) instead of returning the class itself (e.g., `return ClassName`). This causes FMMT to fail with: "expected EFI_FIRMWARE_VOLUME_EXT_ENTRY instance, got _ctypes.PyCStructType" When processing FVs that contain ext header entries of type 0x01 (OEM Type) or type 0x02 (GUID Type, used for FV UI Name when FvNameString = TRUE). Fix by returning the class directly, matching the pattern used by Refine_FV_Header() which correctly returns the class for subsequent .from_buffer_copy() calls. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
9 daysBaseTools: Optimize parsing of byte-array PCD valueskuqin121-0/+31
This change adds a fast path for simple VOID* hexadecimal byte arrays, avoiding the generic expression tokenizer's repeated processing of large PCD values. Regression tests for both paths. It does not change the existing parser for structured and symbolic expressions. This reduces parsing time for a 28 KiB generated PCD from roughly 2 seconds to 50 milliseconds. Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2026-09-01BaseTools: Make DSC arch macro expansion owner-awareBob Chen (UST Global Singapore Pte Limited)1-11/+13
PR #12628 expanded architecture macros for every DSC record so component-private records match their component. A positive raw owner can also represent include provenance, so broad expansion changes records outside component scope. Expand architecture macros only for Component records and records whose owner maps to a final Component. Reset the owner mapping whenever the post-processed table is rebuilt to prevent stale ownership across DoPostProcess calls. Add regression coverage for component-private LibraryClasses and PCDs, nested and private includes, multiple architectures, unresolved macros, repeated sections, and repeated post-processing. Signed-off-by: Bob Chen (UST Global Singapore Pte Limited) <v-kuanlchen@microsoft.com>
2026-08-28BaseTools/Python: Remove error message with email addressVishal Oliyil Kunnil11-14/+0
Remove the "Please send email to devel@edk2.groups.io" message from the unhandled exception handlers in build.py, GenFds.py, Trim.py, and the UPT tools. Also remove the now-unused MSG_EDKII_MAIL_ADDR and MSG_SEARCH_FOR_HELP constants from Common/DataType.py and UPT/Logger/StringTable.py. Signed-off-by: Vishal Oliyil Kunnil <vishalo@qti.qualcomm.com>
2026-08-06BaseTools/Build: Output warning message for library class mismatchJoey Vagedes5-4/+117
Performs a check that will verify that the library instance implements the library specified in the dsc by ensuring a LIBRARY_CLASS definition exists in the INF [Defines] section and the value matches the library it says it is implementing. As an example, from a platform dsc file: BaseBmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.inf BaseBmpSupportLib is supposed to be of library class BmpSupportLib, but the dsc defines it incorrectly, the warning message will be displayed during build. Signed-off-by: Aaron Pop <aaronpop@microsoft.com> Co-authored-by: Poncho Figueroa <poncho.figueroa.esqueda@intel.com>
2026-08-01BaseTools: Fix Clang -Wtautological-overlap-compare in PcdValueInit.cPhil Noh1-6/+6
For each structured-PCD field copied via memcpy, DscBuildData.py emits the clamp expression, '(FieldSize > 0 && FieldSize < ValueSize) ? FieldSize : ValueSize'. When ValueSize == 1 and FieldSize is unsigned, it reduces to (FieldSize > 0 && FieldSize < 1) - always-false comparison. Clang flags it under -Wtautological-overlap-compare, and because PcdValueInit builds with -Werror, autogen fails and the build aborts with 'PcdValueInit.c: error: overlapping comparisons always evaluate to false [-Werror,-Wtautological-overlap-compare]'. This is specific to Clang host. To fix it, this update changes '<' to '<=' at all five generator sites in DscBuildData.py (GenerateDefaultValueAssignFunction, GenerateInitValueFunction, GenerateCommandLineValue, GenerateModuleScopeValue, GenerateFdfValue). Behavior is unchanged: both branches copy the same byte count when FieldSize == ValueSize. GCC and MSVC builds are unaffected. Signed-off-by: Phil Noh <Phil.Noh@amd.com>
2026-07-18BaseTools/Trim.py: Strip "#pragma once" from inlined ASL contentMichael Kubacki1-0/+4
When Trim processes an ASL file (`--asl-file`), it textually inlines the body of every `Include()`'d file directly into the constructed preprocessor input, once per include site. Its has duplicate protection in the form of a circular-include stack (`gIncludedAslFile`), that prevents A->B->A cycles. But, as far as the script is concerned, each `Include()` is a unique include site. Various combinations of includes and file types are possible and handled slightly differently. Starting with file types as defined in BaseTools\Conf\build_rule.template: - `.aslc`, `.act` files fall under `Acpi-Table-Code-File` and are compiled, linked, and processed by genfw. - `.asl`, `.Asl`, and `.ASL` files fall in `Acpi-Source-Language-File` and are processed by Trim: 1. `Trim --asl-file` to produce a single combined .i file with includes inlined. 2. `ASLPP` (ASL preprocessor, a C preprocessor) on the output of Trim to produce a .iii file with all macros expanded and conditional branches resolved. AutoGen.h is also included and processed here to resolve fixed PCD values if needed. 3. `Trim --source-code` which takes the pre-processed .iii file and produces a .iiii file with content like linemarkers cleaned up. 4. The ACPI compiler compiles the .iiii file to produce AML bytecode in a .aml file. Because the `.aslc`/`.act` files are directly passed to normal C processing tools, they are not part of the Trim change made in this commit and the remainder of this message focuses on the ACPI Source Language File case. ASL files can use either an ASL `Include()` directive or a C-style `#include` directive. In addition, different file types may be included such as a `.asl` file or a `.h` file. `Trim` handles these cases differently: - For ASL `Include()` directives, `Trim` inlines the content of the included file directly into the output at the include site. This is done for all included ASL files regardless of their extension. The inlining is purely textual and does not attempt to resolve or preserve any preprocessor directives such as `#pragma once` or include guards. - For C-style `#include` directives, `Trim` checks the file extension of the included file. If the file is an ASL file (`.asl` or `.asi`), `Trim` treats the file the same as the `Include()` case. Otherwise, `Trim` passes the directive through verbatim to the output, allowing the downstream C preprocessor (`ASLPP`) to handle it according to normal C preprocessor rules. This creates a situtation in which the resulting `.i` might include: - Inlined file content (from a `.asl` or `.h` file) depending on the include type and file extension. - Verbatim `#include` directives for non-ASL files which will be processed by the C preprocessor. Focusing on the "inlined" case, historically `.h` files would have traditional C include guards (`#ifndef`/`#define`, `#endif`). However, files might also include `#pragma once` as a guard. In that case, the inlined content of the `.i` file could contain multiple `#pragma once` directives, one per include site. When the C preprocessor (`ASLPP`) processes the `.i` file, it sees multiple `#pragma once` directives in what it considers the main file, and could emit a warning like the following from gcc: warning: '#pragma once' in main file [-Wpragma-once-outside-header] The remainder of this commit message describes the change made to address this warning. This change strips "#pragma once" lines on the ASL content path in `DoInclude()` in `Trim.py` so the directive is removed before it reaches the C preprocessor. - "#include" directives for non-ASL files are still passed through verbatim for the C preprocessor to resolve where the contents of those .h files might contain "#pragma once" or traditional guards. - Traditional include guards are untouched and continue to behave as before where multiple include sites might inline the same content in the .i file before reaching the C preprocessor. The change: In the case that a file is inlined with a `#pragma once` directive, the directive is stripped from the inlined content which prevents the warning. This is considered acceptable because it only removes the `#pragma once` directive from the inlined content for these specific cases. So, the `.i` file might contain multiple inlined copies of the same header content (like always in this inline case) but without the `#pragma once` directives. Because actual C content was already not processed or trimmed out (e.g. `typedef struct`) duplicate content is not considered to be a problem (`#define` multiple times is not a problem for the C preprocessor). Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
2026-07-17BaseTools/build.py: Use full source file path for dependency generationkowsiks1-3/+26
During Silent build,NMAKE suppresses the command echo entirely. As a result, the only output in ProcOut is the MSVC compiler’s output lines. Without the command echo, there is no full path in the output to identify which source file is currently being compiled. For unique basenames this is not an issue, but for namesake files (for example, AmdSev.c located in different directories), it is impossible to determine which file’s includes are being listed. This change improves dependency generation for MSVC builds by introducing explicit handling for source files with duplicate basenames (namesake sources). A new variable current_source_abs is added to consistently track the resolved absolute path of the active source file instead of repeatedly recomputing it from SourceFileAbsPathMap. To correctly resolve namesake files in silent builds (where compiler commands are not echoed), a namesake_queue is introduced, which preserves source ordering and sequentially maps basename occurrences to their corresponding full paths. Additionally, a cc_cmd_in_output flag is implemented to detect the presence of compiler command lines in the output stream; when present, source paths are derived directly from command-line arguments, otherwise the queue-based resolution is used. This ensures correct mapping of basenames to absolute paths across the silent builds, fixing incorrect dependency generation when multiple source files share the same name. Signed-off-by: Kowsik S <kowsiks@ami.com>
2026-07-09BaseTools/GenFds: Print INF name on Depex eval failureChristopher Zurcher1-1/+5
Signed-off-by: Christopher Zurcher <christopher.zurcher@microsoft.com>
2026-06-26BaseTools/Ecc: Add check for traditional include guardsMichael Kubacki4-0/+76
Adds a new ECC check, `IncludeFileCheckPragmaOnce` (error code 6006), that flags header files using a traditional `#ifndef`/`#define` include guard and recommends `#pragma once` instead. A guard is detected when a '#ifndef NAME' is immediately followed by a valueless '#define NAME' using the same macro name. Feature macros such as '#define FOO 1' and files already using '#pragma once' are not flagged. The check reports against the parsed preprocessor directive rows in the identifier tables rather than the File table. Those rows carry the actual source line number, whereas File-level findings resolve to "line 1" in the report. This gives an accurate line number, to the EccCheck CI plugin, so it can reconcile findings with the changed line ranges of a commit. It uses the binary extension list and the exception list, consistent with the other include file checks. Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
2026-06-26BaseTools: Fix MODEL_IDENTIFIER_MACRO_PROGMA typoMichael Kubacki4-5/+5
Fixes typo in the constant name. Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
2026-06-23BaseTools/Build: Fix arch macro expansion scope in DSC parserKirk Chou1-1/+11
Signed-off-by: Kirk Chou <kirk.chou@hpe.com>
2026-06-22BaseTools/GenFds: Fix FV attribute parser to allow any keyword orderMichael D Kinney1-2/+2
Fix _GetFvAttributes() to return True when it has successfully parsed at least one attribute before encountering a non-attribute keyword. Previously it always returned False on encountering an unrecognized word, even after consuming prior attributes. This caused the outer parsing loop to break prematurely when FvForceRebase, FvBaseAddress, or FvAlignment appeared between FV attribute flags (e.g. between ERASE_POLARITY and MEMORY_MAPPED), resulting in a Python stack trace. Move IsWordToken assignment to after successful attribute parsing and change the early return from 'return False' to 'return IsWordToken'. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2026-06-22BaseTools/GenFds: Allow PE32 section keywords in any orderMichael D Kinney1-25/+26
Replace sequential if-statements for Align, Xip, and RELOCS_STRIPPED/RELOCS_RETAINED parsing in _GetEfiSection() with a while-loop that accepts these keywords in any permutation. Previously, specifying Xip before Align in a [Rule] PE32 section caused a Python stack trace. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2026-06-22BaseTools/GenFds: Propagate Xip flag to FV INF via ,XIP suffixMichael D Kinney4-0/+44
Add Xip attribute to FDF Rule class and parse the Xip keyword in EFI section rules of FDF files. Add XipEnabled attribute to FfsInfStatement that is determined from the applicable FDF Rule's section Xip setting. When generating the FV INF file, append ",XIP" to EFI_FILE_NAME entries for modules whose Rule specifies Xip=TRUE. This enables per-file XIP rebase control in GenFv by communicating which files require XIP rebase directly in the FV INF file format. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2026-05-26BaseTools/Capsule: Prevent to Read the STDOUT Content as SignatureJason1 Lin1-6/+30
- Within the capsule generate script, it is using the STDOUT result as signature while signing the hash digest via OpenSSL tool. - There would have incorrect result when the user terminal have the output when executing the startup script. - Incorrect the content of signature would make the verification failed. - Use the "-output" flag to export the signature then read it back as the resolution. Signed-off-by: Jason1 Lin <jason1.lin@intel.com>
2026-04-21BaseTools: Reject Inline Comments in tools_defOliver Smith-Denny1-0/+4
There is a bug in BaseTools currently when an inline comment is used in tools_def. The comment is not stripped out and wreaks havoc down the line, causing BaseTools to get confused elsewhere and drop build options it should be applying. This fixes that behavior by following the build spec which states: Comments are only allows on separate lines and may not be appended appear on actual entry lines. Inline comments are now not allowed and the build will fail and specify why and where. Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
2026-04-09BaseTools: Ecc: Update to ANTLR 4.13.2Oliver Smith-Denny5-1407/+857
ANTLR 4.9 is broken in python 3.13 because it uses a library in the autogenerated files that is removed. This updates to 4.13.2 and also updates the autogen files, which contain support for python 3.13 as well as backwards compat. Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
2026-04-09BaseTools: Ecc: Use SPDX in AutoGen TemplateOliver Smith-Denny1-10/+2
The ANTLR autogen files are currently created without an SPDX identifer. Add the BSD-2-Clause-Patent ID. While here, correct the command to do the autogeneration by using the right filename. Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
2026-04-09BaseTools: Ecc: Drop ANTLR 3 SupportOliver Smith-Denny4-24447/+0
BaseTools hasn't been using ANTLR3 since at least 2019. Drop the files. Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
2026-03-06BaseTools/Source/Python/Trim: Add -f/--source-code-format optionMichael D Kinney1-2/+10
Add --source-code-format option that can be NASM or not specified. This can be used for file format specific actions when --source-code is used. A NASM specific action is added to convert #line to %line to preserve reference the originating NASM source file for source level debug in NASM format. Without this change, the source level debug of NASM files loads the generated intermediate file in the build output directory. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2026-03-05BaseTools: fix mdlint issuesSherry Fan2-139/+215
Fix markdownlint formatting issues in READMEs. Signed-off-by: Sherry Fan <sherryfan@microsoft.com>
2026-02-28BaseTools/Eot: Apply CParser4 ANTLR 4.9 regeneration whitespace changesMichael Kubacki3-16/+21
Whitespace-only changes produced by the ANTLR 4.9 code generator. Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
2026-02-28BaseTools/Eot: Regenerate CParser4 files with ANTLR 4.9Michael Kubacki3-900/+929
The CParser4 Python parser files (CLexer.py, CParser.py, CListener.py) were generated 7 years ago with ANTLR 4.7.1. Meanwhile, pip-requirements.txt pins antlr4-python3-runtime to version 4.9 in commit 4a7dd50, but the files were patched, not fully regenerated. This version mismatch could result in failures when running against non-trivial C code. This change regenerates the CParser4 files with ANTLR 4.9 to resolve the version mismatch. It also updates import statements to correctly reference Eot instead of Ecc. Steps used to regenerate the files: 1. Download the ANTLR 4.9 complete tool JAR: - `https://www.antlr.org/download/antlr-4.9-complete.jar` 2. Generate Python3 parser files Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
2026-02-28BaseTools/Ecc: Apply CParser4 ANTLR 4.9 regeneration whitespace changesMichael Kubacki3-16/+21
Whitespace-only changes produced by the ANTLR 4.9 code generator. Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
2026-02-28BaseTools/Ecc: Regenerate CParser4 files with ANTLR 4.9Michael Kubacki3-895/+924
The CParser4 Python parser files (CLexer.py, CParser.py, CListener.py) were generated 7 years ago with ANTLR 4.7.1. Meanwhile, pip-requirements.txt pins antlr4-python3-runtime to version 4.9 in commit 4a7dd50, but the files were patched, not fully regenerated. This version mismatch produced two failures when running EccMain.py against non-trivial C code: 1. A runtime warning on every file parsed: "ANTLR runtime and generated code versions disagree: 4.9!=4.7.1" 2. A crash when parsing complex C constructs that exercise the struct/union definition rule in CParser.py: TypeError: '<' not supported between instances of 'tuple' and 'int' This occurs in antlr4/BufferedTokenStream.py getText() because the 4.9 runtime changed the expected argument types for that method, and the 4.7.1-generated parser was passing a tuple where an int is now required. This change regenerates the CParser4 files with ANTLR 4.9 to resolve the version mismatch. Steps used to regenerate the files: 1. Download the ANTLR 4.9 complete tool JAR: - `https://www.antlr.org/download/antlr-4.9-complete.jar` 2. Generate Python3 parser files from the grammar: ``` java -jar antlr-4.9-complete.jar ` -Dlanguage=Python3 -visitor ` -o BaseTools/Source/Python/Ecc/CParser4_new ` BaseTools/Source/Python/Ecc/CParser4/C.g4 ``` Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
2026-02-24BaseTools/Ecc: Remove #ifndef include guard checksMichael Kubacki5-92/+0
The codebase has moved from traditional `#ifndef` include guards to `#pragma once`. Remove the ECC checks that validated include guard presence and naming conventions since they are no longer applicable. The following checks are removed: - IncludeFileCheckIfndefStatement: Verified all header file contents were guarded by a `#ifndef` statement, that the `#ifndef` was the first line of code after the file header comment, and that the `#endif` appeared on the last line. - NamingConventionCheckIfndefStatement: Verified that the `#ifndef` guard name at the start of an include file used a postfix underscore and no prefix underscore character. Also removed related error codes and configuration settings that were specific to these checks. Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
2026-02-12Revert "BaseTools: Add support for out-of-tree builds"Michael D Kinney1-2/+1
This reverts commit 3fe1d56cc98e011bbde8348f13dfa5e38c95f49e. 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-02BaseTools: Add support for out-of-tree buildsOleksandr Tymoshenko1-1/+2
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-01-30BaseTools: Prevent Subsection PCDs from polluting global expressionsPaddyDeng1-2/+3
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-06BaseTools/build: Add defines for Windows build environmentsMichael D Kinney1-0/+5
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>
2025-12-24BaseTools: GNUMakefiles must use CMD.EXE in WindowsMichael D Kinney1-1/+9
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-03BaseTools: Cap AutoGen thread count to avoid file descriptor exhaustionAyden Meng1-1/+10
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-03BaseTools: Handle file descriptor exhaustion during parallel buildAyden Meng1-0/+7
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-02BaseTools: AutoGen: Optimize tuple creation using tuple() for PcdDbBufferJeremy Compostella1-6/+2
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-11-24BaseTools: Enhance FMMT rebase feature with FFS type checkYuwei Chen2-12/+193
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-24BaseTools: Enable FMMT Rebase functionYuwei Chen10-26/+1400
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-22BaseTools: FMMT: Fix incorrect size calculation in ModifyTest()Evgenii Shatokhin1-3/+4
There is another issue in FvHander.py similar to the one fixed by a60334ad59eb ("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-22BaseTools: fix various typosPhilipp Schuster2-3/+3
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-10-30BaseTools: Remove DXE_SAL_DRIVERSathya Ravichandran12-27/+15
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: [3cb0a311cb7e747d7be5c5076d0fff76ad256d2b] Cc: Sachin Ganesh <sachinganesh@ami.com> Signed-off-by: Sathya Ravichandran <sathyar@ami.com>
2025-10-21BaseTools:Remove deprecated ast.Str import for Python 3.14 compatibilityAshraf Ali S1-1/+0
- 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-16BaseTools/FMMT: Fix errors when operating the FV with CRC32 sectionPhil Noh1-6/+1
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-16BaseTools/build.py: set BUILD_TIME_EPOCH if not already in environmentLeif Lindholm1-1/+22
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-16BaseTools/build.py: language cleanup around CheckEnvVariableLeif Lindholm1-3/+3
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-09-26BaseTools: Remove ARM32 SupportOliver Smith-Denny9-53/+15
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-08-25BaseTools: DSC: fix processing !include in multiarch subsectionsSergii Dmytruk1-1/+5
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-07-30BaseTools: Fix FMMT FvHandler Padding operation issuesecurity-advisory/cve-2025-xxxxx/advisoryYuwei Chen1-4/+22
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-08BaseTools: Improve report generation for Nested Fvs.Aaron Pop1-7/+15
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-04BaseTools: Fix the spelling or typoAbdul Lateef Attar1-1/+2
Signed-off-by: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>
2025-07-01BaseTools: WorkSpace: Remove unnecessary codePierre Gondois7-144/+0
Running the vulture tool on the WorkSpace folder gave the following report. Remove the unnecessary code. - Workspace/BuildClassObject.py:148: unused method 'IsSimpleTypeArray' (60% confidence) - Workspace/BuildClassObject.py:337: unused method 'SetPcdMode' (60% confidence) - Workspace/BuildClassObject.py:612: unused attribute 'DscSpecification' (60% confidence) - Workspace/DscBuildData.py:451: unused property 'DscSpecification' (60% confidence) - Workspace/DscBuildData.py:1253: unused method 'GetBuildOptionsByPkg' (60% confidence) - Workspace/DscBuildData.py:2064: unused method 'GetStarNum' (60% confidence) - Workspace/DscBuildData.py:3613: unused method 'AddModule' (60% confidence) - Workspace/DscBuildData.py:3650: unused method 'AddPcd' (60% confidence) - Workspace/InfBuildData.py:117: unused attribute '_TailComments' (60% confidence) - Workspace/InfBuildData.py:126: unused attribute '_BinaryModule' (60% confidence) - Workspace/MetaDataTable.py:114: unused method 'IsIntegral' (60% confidence) - Workspace/MetaDataTable.py:218: unused method 'GetFileTimeStamp' (60% confidence) - Workspace/MetaDataTable.py:230: unused method 'SetFileTimeStamp' (60% confidence) - Workspace/MetaDataTable.py:298: unused method 'GetCrossIndex' (60% confidence) - Workspace/MetaFileParser.py:161: unused attribute '_FileDir' (60% confidence) - Workspace/MetaFileParser.py:1187: unused method '_DecodeCODEData' (60% confidence) - Workspace/MetaFileParser.py:1796: unused attribute '_RestofValue' (60% confidence) - Workspace/MetaFileTable.py:31: unused attribute '_NumpyTab' (60% confidence) - Workspace/WorkspaceDatabase.py:136: unused class 'TransformObjectFactory' (60% confidence) - Workspace/WorkspaceDatabase.py:159: unused attribute 'TransformObject' (60% confidence) Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>