1769 Commits

Author SHA1 Message Date
Mikhail Krichanov
709984a981 Fixed compilation of all packages tracked by CI after rebasing upon edk2-stable202502 tag. 2025-04-07 13:54:15 +03:00
vit9696
0146e644f0 BaseTools: Provide fat Mach-O binaries on Darwin
Merge pull request #63 from acidanthera/vit9696-fattools-20240327
2025-04-07 12:32:50 +03:00
Mikhail Krichanov
0d9d6f987b Fixed compilation of all packages tracked by CI after rebasing upon edk2-stable202311. 2025-04-07 12:32:50 +03:00
Mikhail Krichanov
992385e15e SecurePE: Defined new PcdImageProtectionPolicy. 2025-04-07 12:30:28 +03:00
Mikhail Krichanov
48b806f46f UE: Support UE generation and consumption. 2025-04-07 12:24:28 +03:00
Marvin Häuser
8171958c4e BaseTools/CommonLib: Replace aligned_alloc with posix_memalign 2025-04-07 12:24:27 +03:00
Mikhail Krichanov
ba9aad0b56 ImageTool: Rework PeEmit with dynamically-growing buffers 2025-04-07 12:24:27 +03:00
Mikhail Krichanov
e46d356fc9 MdePkg/UefiImageLib: Support multi-format and multi-source architecture
Signed-off-by: Marvin Häuser <mhaeuser@posteo.de>
2025-04-07 12:24:27 +03:00
Mikhail Krichanov
7193c4e313 BaseTools: Introduce new HII section design 2025-04-07 12:18:23 +03:00
Mikhail Krichanov
54c0f644f9 BaseTools/C: Consume UefiImageLib and ImageToolEmit 2025-04-07 12:18:23 +03:00
Marvin Häuser
4c392eb104 BaseTools/GenFv: Remove .text and .data from FV map 2025-04-07 12:18:23 +03:00
Marvin Häuser
544c7bdda8 BaseTools/build_rule: Drop deprecated ASM16 definition 2025-04-07 12:18:22 +03:00
Mikhail Krichanov
bc87d7b430 Drop support for the TE format 2025-04-07 12:18:22 +03:00
Mikhail Krichanov
f60f34fabf BaseTools/CommonLib: Consume MemoryAllocationLib 2025-04-07 12:18:22 +03:00
Marvin Häuser
473ab07302 BaseTools/GenFvInternalLib: Remove unused BaseOfCode parameter 2025-04-07 12:13:58 +03:00
Marvin Häuser
607095f8f4 BaseTools/GenFv: Remove duplicated alignment macros 2025-04-07 12:13:58 +03:00
Marvin Häuser
48e9d4282c BaseTools/DevicePath: Consume MdePkg/UefiDevicePathLib
BaseTools has been duplicating and adapting code that is defined in
MdePkg and MdeModulePkg. This leads to desync issues where the same
symbols may be backed by different functions with slightly different
semantics and also fixes that apply only to BaseTools or only to MdePkg
and MdeModulePkg.

To address these issues, update BaseTools/Source/C to utilize the code
from MdePkg and MdeModulePkg.

Signed-off-by: Marvin Häuser <mhaeuser@posteo.de>
2025-04-07 12:13:58 +03:00
Marvin Häuser
2f61ab9f51 BaseTools/CommonLib: Consume MdePkg and MdeModulePkg
BaseTools has been duplicating and adapting code that is defined in
MdePkg and MdeModulePkg. This leads to desync issues where the same
symbols may be backed by different functions with slightly different
semantics and also fixes that apply only to BaseTools or only to MdePkg
and MdeModulePkg.

To address these issues, update BaseTools/Source/C to utilize the code
from MdePkg and MdeModulePkg.

Signed-off-by: Marvin Häuser <mhaeuser@posteo.de>
2025-04-07 12:13:58 +03:00
Mike Beaton
850cf3b628 GenSec: Support TianoCompress
Allows .fdf files to define a compressed .ffs section which can be read
by legacy EFI firmware (such as found on Apple Mac).
Use `COMPRESS TIANO`.
2025-04-07 12:13:58 +03:00
Mikhail Krichanov
011411a38e BaseTools, MdeModulePkg: Update brotli submodule
Update the brotli submodule to the latest commit (ed1995b6bda1)
so that the build isn't broken in GCC 12 compilers.

Signed-off-by: Savva Mitrofanov <savvamtr@gmail.com>
2025-04-07 12:13:57 +03:00
Mikhail Krichanov
5d894921a3 BaseTools: Replaced GenFw with ImageTool and MicroTool. 2025-04-07 12:13:57 +03:00
Mikhail Krichanov
09a0c067d0 SecurePE: Replaced old PE loader with Secure one. 2025-04-07 12:12:35 +03:00
Rebecca Cran
259e1f04c6 BaseTools: Add @verbatim as allowed Doxygen tag
Per the discussion in https://github.com/tianocore/edk2/pull/6476,
update Ecc code to allow the @verbatim Doxygen tag.

Signed-off-by: Rebecca Cran <rebecca@bsdio.com>
2025-02-04 00:12:00 +00:00
Michael D Kinney
62b0698309 BaseTools/AutoGen: GenMake response file quotes strings
If command line options are moved into a response file
of a GCC family build, then the file path separators are
converted from '\' to '/'. However, this can corrupt
command line options that are quoted strings.

Update GenMake to no convert '\' to '/' in quoted strings.

Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-02-02 19:22:42 +00:00
Gerd Hoffmann
e063f8b8a5 BaseTools/Pccts: set C standard
The prehistoric code base doesn't build with ISO C23.  Set the C
standard to C11 (for both clang and gcc) so it continues to build with
gcc 15 (which uses C23 by default).

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2025-01-31 05:23:39 +00:00
Ashraf Ali S
6d2143f685 BaseTools: Fix NoneType parent reference in FMMT operations
This patch addresses an issue in the FMMT operations where the parent
reference is not checked for NoneType. This oversight can lead to an
AttributeError: 'NoneType' object has no attribute 'Name' when
attempting to access the parent reference. The fix involves adding a
check for NoneType before accessing the parent reference to ensure that
the operations handle such cases gracefully.

The affected functions include:
- AddNewFfs
- ReplaceFfs
- ExtractFfs

These functions now include proper checks to prevent the AttributeError.

Signed-off-by: Ashraf Ali S <ashraf.ali.s@intel.com>
2025-01-27 16:26:18 +00:00
Yang Gang
3ac092cf72 BaseTools: Clean up os.path.normcase and os.path.normpath usage
Refer to the docs of python, `os.path.normcase(path)` function:
"Normalize the case of a pathname. On Windows, convert all characters in
the pathname to lowercase, and also convert forward slashes to backward
slashes. On other operating systems, return the path unchanged."

`os.path.normpath(path)` also convert forward slashes to backward slashes.

So call `os.path.normcase` after `os.path.normpath` just convert path to
lowercase on Windows(only).

And Windows is case-insensitive but case-preserving.

So the usage of `os.path.normcase(os.path.normpath(path))` can be
simplified to `os.path.normpath(path)`. Then we can use case-preserving
paths rather than lowercase paths in compile_commands.json file
or build log.

But this patch continue to use `os.path.normcase`
when comparing/searching paths.

Signed-off-by: Yang Gang <yanggang@byosoft.com.cn>
2025-01-09 07:25:45 +00:00
Ashraf Ali
1cc78814cd Remove dependancy on re.T
Signed-off-by: Ashraf Ali <ashraf.ali.s@intel.com>
2024-12-24 07:32:42 +00:00
kuqin12
3c8016b302 BaseTools: Support custom library build for base tools on Linux ARM
This change added the build script to cross compile the base tool
binaries for Linux ARM/AARCH64 systems.

The needed libuuid system library is pulled from source file and rebuilt
to support the corresponding library dependencies. Individual tools'
makefiles are also updated to link the cross compiled library as well.

The EDK2 base tool build script was also updated to support such change.

This was tested functional on Linux ARM host system.

Cc: Rebecca Cran <rebecca@bsdio.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Yuwei Chen <yuwei.chen@intel.com>
Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2024-12-20 22:57:04 +00:00
Kun Qin
74bf7f55c1 BaseTools: Adding cross compilation of BaseTool for Windows ARM/ARM64
This change adds the support of crossbuilding basetool for Windows ARM/
ARM64 systems, which will enable the generally available pipeline agents
to build binary tools and make releases as they see fit.

The EDK2 base tools build script is also updated to support cross
compilation using this script.

The crossbuilt binary output is tested on Windows ARM based hardware
systems.

Cc: Rebecca Cran <rebecca@bsdio.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Yuwei Chen <yuwei.chen@intel.com>
Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2024-12-20 22:57:04 +00:00
kuqin12
4b2f964749 BaseTools: Adding support of building BaseTool on Windows ARM/ARM64
This change focuses on the support of building basetool natively for
Windows ARM/ARM64 host system, which will enable the ARM based platforms
to build UEFI and unit tests.

Note that the warnings due to integer conversions are suppressed for
this specific target to avoid too much local changes carried in MU. The
formal change should drop all these binaries and move to pythonic
scripts.

The binary output is tested on Windows ARM based hardware systems.

Cc: Rebecca Cran <rebecca@bsdio.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Yuwei Chen <yuwei.chen@intel.com>
Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2024-12-20 22:57:04 +00:00
Dionna Glaze
74ac8cc0e8 BaseTools: Typo fixes
Some in error messages, some in local variable names.

Signed-off-by: Dionna Glaze <dionnaglaze@google.com>
2024-12-11 09:00:21 +08:00
Rebecca Cran
5b2d55533b BaseTools: Improve error messages from UefiCapsuleHeader.py
Instead of throwing ValueErrors with no explanation, add a message
explaining what went wrong.

Signed-off-by: Rebecca Cran <rebecca@bsdio.com>
2024-12-06 13:02:18 +00:00
Ard Biesheuvel
051ef932bd BaseTools/GenFw X64: Detect GOTCPRELX relaxations applied by LLD
GenFw relies on static ELF relocation tables emitted by the linker (via
the --emit-relocs command line switch). These are different from the
dynamic relocations that a dynamic loader uses: static relocations are
emitted by the compiler/assembler, and consumed by the linker to
construct the executable. Only when the load address is a priori unknown
are dynamic relocations emitted, by the linker, in a format that the
dynamic loader can consume.

This distinction is relevant because only dynamic relocations cover the
GOT, and so GOT based indirections are better avoided. Unfortunately,
there are cases where the toolchain insists on emitting GOT based symbol
references, and so we have to deal with them in one of 2 ways:

- replace GOT based symbol references with direct references, so that
  the GOT entries themselves are no longer used, and can be ignored when
  generating the PE/COFF relocation tables (AARCH64 and RISCV64 take
  this approach);

- infer the locations of the GOT slots from the references appearing in
  the code, and emit PE/COFF relocations for them so that their contents
  will be fixed up appropriately.

The latter is the approach taken by GenFw for x86_64, which is the only
feasible approach for its ISA, given that GOT slots can be used as
memory operands in many different types of instructions, not all of
which can be converted straight-forwardly.

E.g.,

   movq   foo@GOTPCREL(%rip), %rax

can always be converted into

   leaq   foo(%rip), %rax

whereas

   cmpq   foo@GOTPCREL(%rip), %rax

can only be converted under the 32-bit position dependent code model,
into

   cmpq   $foo, %rax

and so the GOT references cannot be elided when generating position
independent code, which is what GenFw requires.

To remove the need for the linker to guess where the instructions start,
the ELF psABI for x86_64 specifies a couple of relaxable alternatives
for GOTPCREL, which are used to annotate particular classes of GOT
referencing instructions that may be relaxed to their non-GOT
counterparts.

There is no specification for what --emit-relocs is supposed to produce,
or whether or not its output is supposed to reflect such relaxations.
ld.bfd and LLD behave differently in this regard, and the latter may
emit R_X86_64_REX_GOTPCRELX relocations for MOV instructions that it
already has relaxed into LEA instructions. This means the displacement
in the instruction no longer refers to the GOT slot, but directly to the
object itself, and emitting a relocation is not only unnecessary, but
also harmful as the PE/COFF loader will corrupt the object when it
applies the relocations at startup.

Under the position independent code model, the only relaxation that the
linker could have applied for a R_X86_64_REX_GOTPCRELX relocation is MOV
to LEA, so detect whether the instruction is already LEA, and ignore the
relocation if that is the case.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2024-10-23 09:52:54 +00:00
Mike Beaton
cc47e82703 BaseTools: Fix redefinition of UINT8_MAX in Decompress.c on XCODE5
This is part of a sequence of commits to restore build on the XCODE5
toolchain.

The definition is required on other toolchains, but on XCODE5 results
in a macro redefined error (from the existing value 255) from
/usr/include/stdint.h.

Signed-off-by: Mike Beaton <mjsbeaton@gmail.com>
2024-09-27 16:57:36 +00:00
Mike Beaton
6820004b3e BaseTools: Fix multiple 'invalid escape sequence' warnings in tests
In Python 3.12 invalid escape sequences in strings moved from
DeprecationWarning to SyntaxWarning
(ref https://docs.python.org/3/whatsnew/changelog.html#python-3-12-0-final
and search for gh-98401). In a future Python version this will become
SyntaxError.

Multiple instances of these SyntaxWarnings are currently printed when
running the BaseTools tests using Python 3.12 (though without actually
failing the affected tests).

This commit updates all lines which were causing this type of warning.

Typical examples which needed fixing are:

- "BaseTools\Source\Python" representing a path: "\S" and "\P" are invalid
escape sequences, therefore left unchanged, therefore the test works
(with a warning in Python 3.12). r"BaseTools\Source\Python" represents
the same string, but with escapes turned off completely thus no warning.

- Where '\t\s' is used as a regex pattern, then chr(9) + '\\s' is sent
to the regex parser (with a warning in Python 3.12) since '\s' is not a
valid Python escape sequence. This works correctly, though arguably for
the wrong reasons. r'\t\s' sends the same as '\\t\\s', as originally
intended and with no warning.

(Note that ' and " are not fundamentally different in Python.)

Signed-off-by: Mike Beaton <mjsbeaton@gmail.com>
2024-09-23 04:55:53 +00:00
Abdul Lateef Attar
222e2854fe BaseTools: Update RETURN_ERROR Macro in BaseTypes.h
This patch is to sync RETURN_ERROR macro with the
MdePkg/Include/Base.h

Ref: 1a89d9887f MdePkg:Update Return Error Macro in Base.h

Fixing RETURN_ERROR macro.
It is causing problem in Coverity Static analysis tool
as we are directly converting the UINT value to INTN.

Changing value from UINT to INTN might cause problema
Here we know that the values would not be in loss of data.
To increase the code quality and increase the static tool
analysis score we have to change it

Cc: Rebecca Cran <rebecca@bsdio.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Yuwei Chen <yuwei.chen@intel.com>
Signed-off-by: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>
2024-09-20 09:02:41 +00:00
Taylor Beebe
cac0955658 BaseTools: Update Stack Cookie Logic
This patch updates the GenC logic to generate a random stack cookie value
for the stack check libraries. These random values improve security
for modules which cannot update the global intrinsics.

If the stack cookie value is randomized in the AutoGen.h file each
build, the build system will determine the module/library must be
rebuilt causing effectively a clean build every time. This also makes
binary reproducibility impossible.

This patch updates the early build scripts to create 32 and 64-bit JSON
files in the build output directory which each contain 100 randomized
stack cookie values for each bitwidth. If the JSON files are already
present, then they are not recreated which allows them to be stored and
moved to other builds for binary reproducibility. Because they are in
the build directory, a clean build will cause the values to be
regenerated.

The logic which creates AutoGen.h will read these JSON files and use a
hash of the module GUID (the hash seed is fixed in Basetools) to index
into the array of stack cookie values for the module bitwidth. This
model is necessary because there isn't thread-consistent data so we
cannot use a locking mechanism to ensure only one thread is writing to
the stack cookie files at a time. With this model, the build threads
only need to read from the files.

Signed-off-by: Oliver Smith-Denny <osde@linux.microsoft.com>
2024-09-13 03:58:46 +00:00
Oliver Smith-Denny
61f9695f20 BaseTools: Remove Pip BaseTools
BaseTools was moved out to a separate repo and consumed as a pip
module by edk2 CI. This process has not led to the desired goals
of doing so, so this patch removes the pip based BaseTools from
edk2 CI.

The original goal of moving BaseTools to a pip module was
primarily to speed up the development process, as the old edk2
mailing list was slow. However, with edk2 moving to PRs, it now
actually slows the BaseTools development process to have to do
a PR in another repo, publish the module, and then make a PR
in edk2 to consume the new BaseTools. It also holds up using
the features in a new BaseTools in other PRs.

There were other goals of moving, such as allowing projects to
use the BaseTools outside of edk2. This can still be accomplished
outside of this PR, this PR simply stops edk2 CI from using the
pip module.

Continuous-integration-options: PatchCheck.ignore-multi-package

Signed-off-by: Oliver Smith-Denny <osde@linux.microsoft.com>
2024-09-10 00:41:53 +00:00
Ken Lautner
50871ee0ec BaseTools: GenMake: FIx missing logs from GenMake.py
EdkLogger logs were not showing up as part of the build log output.
Adding the EdkLogger import to GenMake.py fixes the missing log prints.

Signed-off-by: Kenneth Lautner <kenlautner3@gmail.com>
2024-09-02 06:32:06 +00:00
Joey Vagedes
95ee7f3ef7 BaseTools: Trim: Add header/footer for ASL include
When including one ASL file in another, add a header / footer to the
included file to easily tell where the included file starts and ends.

Signed-off-by: Joey Vagedes <joey.vagedes@gmail.com>
2024-08-31 04:58:54 +00:00
Jason1 Lin
68b4c4b481 BaseTools/Capsule: Support Different Hash Algorithm for Payload Digest
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4821

- The capsule payload digest got hardcoded inside the GenerateCapsule
  script as "sha256".

- It would be hard for the caller to change the supported hash algorithm
  which supported on OpenSSL or Windows signtool program and platform.

- Capsule payload digest signed data is followed by the PKCS#7 standard,
  in EDK-II CryptoPkg "Pkcs7Verify ()" is supported to validate with
  several hash algorithms naturally.
  (md5, sha1, sha256, sha384, and sha512)

- Deliver below changes within this patch,
  (1) Introduce an optional argument "--hash-algorithm" to assign
      the caller expected one and leave the default value "sha256"
      to support the backward compatibility.

  (2) Add the double quotes to put the string of certificate's
      subject name inside it.

  (3) Set "Open" argument of "SignToolSubjectName" into "False".

  (4) Set "Convert" argument of "SignToolSubjectName: into "str".

  (5) Correct the actual name of the "--subject-name" flag.

  (6) Add back correct number of arguments for PayloadDescriptor
      class object initializing.

Note:
- Platform needs to support the correspond hash algorithm to validate
  the digital signature or the failure would be observed.

- Set the md5 and sha1 algorithm as EOL based on the CryptoPkg supported
  table and reject the capsule creation.

Signed-off-by: Jason1 Lin <jason1.lin@intel.com>
2024-08-05 05:49:16 +00:00
Dmitry Antipov
41426040da BaseTools: Move MEMORY_TYPE_* Defines to EFI_MEMORY_TYPE Enum
Per TCBZ2372, clang on Linux emits a warning if an enum-typed variable
is compared with a constant outside of the range of the enum. Such
comparisons are performed in multiple locations in DXE core on
variables of type EFI_MEMORY_TYPE. This patch moves the OEM and OS
reserved types into the EFI_MEMORY_TYPE enum itself to resolve this
issue and improve readability. This commit does this for the BaseTools
copy of this enum.

Signed-off-by: Oliver Smith-Denny <osde@linux.microsoft.com>
2024-07-26 03:08:20 +00:00
Leif Lindholm
5366def8d0 BaseTools: drop GeneralCheckNonAscii() from ECC
The GeneralCheckNonAscii() function is a sledgehammer rejecting any file
containing any character outside of the 7-bit ASCII encoding space, as
well as the DEL character (which seems unrelated).

This conflicts with basic stuff like correctly spelling certain proper
nouns in comments (like copyright statements), or string literals (for
example in multi-language driver binding ComponentNames).

So rip it out, to be replaced by more fine-grained checks to be added as
identified and needed.

Signed-off-by: Leif Lindholm <quic_llindhol@quicinc.com>
2024-07-15 13:27:00 +00:00
Leif Lindholm
8ade6d7bd1 BaseTools: fix consistent Ecc misspelling of ASCII
Ecc concistently referred to ASCII/Ascii as ACSII/Acsii, which
bugged me to no end when trying to figure out how those tests
worked. Fix all instances.

Signed-off-by: Leif Lindholm <quic_llindhol@quicinc.com>
2024-07-15 13:27:00 +00:00
Michael Kubacki
6c061c4715 BaseTools/Ecc: Allow static as a modifier
Currently, `STATIC` is allowed as a function modifier but `static`
results in the below ECC errors:

```
*Error code: 5001
*Return type of a function should exist and in the first line
*file: D:\src\edk2\Build\.pytool\Plugin\EccCheck\MdePkg\Library\UefiDebugLibDebugPortProtocol\DebugLibConstructor.c
*Line number: 37
*[UefiDebugLibDebugPortProtocolExitBootServicesCallback] Return
 Type should appear at the start of line

EFI coding style error
*Error code: 5002
*Any optional functional modifiers should exist and next to the
 return type
*file: D:\src\edk2\Build\.pytool\Plugin\EccCheck\MdePkg\Library\UefiDebugLibDebugPortProtocol\DebugLibConstructor.c
*Line number: 37
```

This is because `GetDataTypeFromModifier()` will return both `static`
and the return type (e.g. `VOID`) whereas for a modifier in the list
(e.g. `STATIC`) it will return only the return type allowing logic in
Ecc/c.py to process the modifier and return type with current logic.

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
2024-07-10 14:32:08 +00:00
Sergii Dmytruk
26bc42f1e3 BaseTools/GenerateCapsule.py: Fix checking for DepExp presence
struct.unpack() returns a tuple even for a single-element pack,
resulting in signature verification being evaluated to false even when
the signature is there.

This fixes --decode and --dump-info actions incorrectly reporting issues
with parsing capsule dependencies when there are none.

Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
2024-07-05 19:33:50 +00:00
Sergii Dmytruk
eeddb86aaa BaseTools/GenerateCapsule.py: Fix inconsistent error formatting
Just add a space between colon and a more detailed error message in two
places.

Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
2024-07-05 19:33:50 +00:00
Sergii Dmytruk
47c1078175 BaseTools/GenerateCapsule.py: Require --output for --decode
--decode unconditionally uses args.OutputFile.name as a prefix for
output files that it creates and fails in a non-pretty way without
--output option.

This doesn't address creation/truncation of the file specified via
--output, but at least you're able to decode a capsule.

Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
2024-07-05 19:33:50 +00:00
Sergii Dmytruk
822ff966c6 BaseTools/GenerateCapsule.py: Better error message on --decode failure
Print error text from the exception.

Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
2024-07-05 19:33:50 +00:00