Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## [6.2.6]

### Fixed
- Windows: fix print specifiers
- Support Stdlib logging in UEFI builds

### Changed
- Windows: migrate to VS2022
- Refactor package structure and file paths for UEFI build consistency

## [6.2.5]

### Fixed
Expand Down
22 changes: 11 additions & 11 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
{
"name": "base64",
"displayName": "Windows x86-64 base",
"description": "Build x86-64 Release, VS2019",
"description": "Build x86-64 Release, VS2022",
"hidden": true,
"generator": "Visual Studio 16 2019",
"generator": "Visual Studio 17 2022",
"architecture": {
"value": "x64",
"strategy": "set"
Expand All @@ -19,9 +19,9 @@
{
"name": "base32",
"displayName": "Windows x86 base",
"description": "Build x86 Release, VS2019",
"description": "Build x86 Release, VS2022",
"hidden": true,
"generator": "Visual Studio 16 2019",
"generator": "Visual Studio 17 2022",
"architecture": {
"value": "Win32",
"strategy": "set"
Expand All @@ -34,7 +34,7 @@
{
"name": "Release32Static",
"displayName": "Windows x86 Release Static",
"description": "Build x86 Release, VS2019",
"description": "Build x86 Release, VS2022",
"inherits": "base32",
"binaryDir": "${sourceDir}/Release",
"cacheVariables": {
Expand All @@ -45,7 +45,7 @@
{
"name": "Release32",
"displayName": "Windows x86 Release",
"description": "Build x86 Release, VS2019",
"description": "Build x86 Release, VS2022",
"inherits": "base32",
"binaryDir": "${sourceDir}/Release",
"cacheVariables": {
Expand All @@ -55,7 +55,7 @@
{
"name": "Release64",
"displayName": "Windows x86-64 Release",
"description": "Build x86-64 Release, VS2019",
"description": "Build x86-64 Release, VS2022",
"inherits": "base64",
"binaryDir": "${sourceDir}/Release",
"cacheVariables": {
Expand All @@ -65,7 +65,7 @@
{
"name": "Release64Static",
"displayName": "Windows x86-64 Release Static",
"description": "Build x86-64 Release, VS2019",
"description": "Build x86-64 Release, VS2022",
"inherits": "base64",
"binaryDir": "${sourceDir}/Release",
"cacheVariables": {
Expand All @@ -76,7 +76,7 @@
{
"name": "Release64AllStatic",
"displayName": "Windows x86-64 Release Static",
"description": "Build x86-64 Release, VS2019",
"description": "Build x86-64 Release, VS2022",
"inherits": "base64",
"binaryDir": "${sourceDir}/Release",
"cacheVariables": {
Expand All @@ -89,7 +89,7 @@
{
"name": "Debug64All",
"displayName": "Windows x86-64 Debug All",
"description": "Build x86-64 Debug, VS2019, including test and samples",
"description": "Build x86-64 Debug, VS2022, including test and samples",
"inherits": "base64",
"binaryDir": "${sourceDir}/Debug",
"cacheVariables": {
Expand All @@ -101,7 +101,7 @@
{
"name": "Debug64AllStatic",
"displayName": "Windows x86-64 Debug Static All",
"description": "Build x86-64 Debug, VS2019, including test and samples",
"description": "Build x86-64 Debug, VS2022, including test and samples",
"inherits": "base64",
"binaryDir": "${sourceDir}/Debug",
"cacheVariables": {
Expand Down
4 changes: 2 additions & 2 deletions MeTeePkg/MeTeePkg.dec.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
PACKAGE_VERSION = 0.1

[Includes]
@METEE_INCLUDE_RELPATH@
Include

[LibraryClasses]
## @libraryclass Provides MeTee interface functions
MeTeeLib|include/metee.h
MeTeeLib|Include/metee.h

[Guids]
gMeTeePkgTokenSpaceGuid = { 0x8e6a6715, 0x9abc, 0x4043, { 0x88, 0xef, 0x9e, 0x39, 0xc6, 0xf6, 0x3e, 0x0f }}
5 changes: 3 additions & 2 deletions MeTeePkg/MeTeePkg.dsc.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
LibC|StdLib/LibC/LibC.inf

DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
PciLib|MdePkg/Library/BasePciLibCf8/BasePciLibCf8.inf
Expand All @@ -36,10 +37,10 @@ PciCf8Lib|MdePkg/Library/BasePciCf8Lib/BasePciCf8Lib.inf
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
PciSegmentLib|MdePkg/Library/BasePciSegmentLibPci/BasePciSegmentLibPci.inf

MeTeeLib|MeTeePkg/MeTeeLibrary/MeTeeLibrary.inf
MeTeeLib|MeTeePkg/Library/MeTeeLibrary/MeTeeLibrary.inf

[Components]
MeTeePkg/MeTeeLibrary/MeTeeLibrary.inf
MeTeePkg/Library/MeTeeLibrary/MeTeeLibrary.inf

@METEE_SAMPLES@

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ ME TEE library uses CMake for both Linux and Windows builds.

### Windows

From the "Developer Command Prompt for VS 2019" with C compiler and CMake component installed:
From the "Developer Command Prompt for VS 2022" with C compiler and CMake component installed:

1. Go to sources directory: `cd <srcdir>`
2. Create `build` directory: `mkdir build`
3. Run `cmake -G "Visual Studio 16 2019" -A <build_arch> <srcdir>` from the `build` directory (best to set *build_arch* to Win32)
3. Run `cmake -G "Visual Studio 17 2022" -A <build_arch> <srcdir>` from the `build` directory (best to set *build_arch* to Win32)
4. Run `cmake --build . --config Release --target package -j <nproc>` from the `build` directory to build an archive with all executables and libraries, *nproc* is the number of parallel threads in compilation, best to set to number of processor threads available

By default, CMake links with dynamic runtime (/MD), set BUILD_MSVC_RUNTIME_STATIC to ON to link with static runtime (/MT):
`cmake -G "Visual Studio 16 2019" -A <build_arch> -DBUILD_MSVC_RUNTIME_STATIC=ON <srcdir>`
`cmake -G "Visual Studio 17 2022" -A <build_arch> -DBUILD_MSVC_RUNTIME_STATIC=ON <srcdir>`

### Linux

Expand Down Expand Up @@ -47,13 +47,13 @@ ninja -v -C build/
### Windows Visual Studio

In order to use Visual Studio project meson requires to run under Visual Studio Command Prompt.
In case of Visual Studio 2019, you can use either *"x64 Native Tools Command Prompt for VS 2019"*
In case of Visual Studio 2022, you can use either *"x64 Native Tools Command Prompt for VS 2022"*
or under powershell enter VisualStudio DevShell and then just continue with the [general setup](#general-setup)

#### Powershell example setting:

```powershell
$installPath = &"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -version 16.0 -property installationpath
$installPath = &"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -version 17.0 -property installationpath
Import-Module (Join-Path $installPath "Common7\Tools\Microsoft.VisualStudio.DevShell.dll")
Enter-VsDevShell -VsInstallPath $installPath -SkipAutomaticLocation
```
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.2.5
6.2.6
26 changes: 22 additions & 4 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@ target_link_libraries(metee-gsc metee)
install(TARGETS metee-gsc RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

if(EFI)
configure_file (
set(_metee_gsc_stage "${CMAKE_BINARY_DIR}/MeTeePkg/Samples/MeTeeGsc")
configure_file(
"${PROJECT_SOURCE_DIR}/metee_gsc.c"
"${_metee_gsc_stage}/metee_gsc.c" COPYONLY
)
configure_file(
"${PROJECT_SOURCE_DIR}/MeTeeGscMain.c"
"${_metee_gsc_stage}/MeTeeGscMain.c" COPYONLY
)
configure_file(
"${PROJECT_SOURCE_DIR}/MeTeeGsc.inf.in"
"${CMAKE_BINARY_DIR}/MeTeePkg/Samples/MeTeeGsc/MeTeeGsc.inf"
"${_metee_gsc_stage}/MeTeeGsc.inf"
)
endif(EFI)

Expand All @@ -38,9 +47,18 @@ target_link_libraries(metee-basic metee)
install(TARGETS metee-basic RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

if(EFI)
configure_file (
set(_metee_basic_stage "${CMAKE_BINARY_DIR}/MeTeePkg/Samples/MeTeeBasic")
configure_file(
"${PROJECT_SOURCE_DIR}/metee_basic.c"
"${_metee_basic_stage}/metee_basic.c" COPYONLY
)
configure_file(
"${PROJECT_SOURCE_DIR}/MeTeeBasicMain.c"
"${_metee_basic_stage}/MeTeeBasicMain.c" COPYONLY
)
configure_file(
"${PROJECT_SOURCE_DIR}/MeTeeBasic.inf.in"
"${CMAKE_BINARY_DIR}/MeTeePkg/Samples/MeTeeBasic/MeTeeBasic.inf"
"${_metee_basic_stage}/MeTeeBasic.inf"
)
endif(EFI)

Expand Down
4 changes: 2 additions & 2 deletions samples/MeTeeBasic.inf.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
ENTRY_POINT = UefiMain

[Sources]
../samples/metee_basic.c
../samples/MeTeeBasicMain.c
metee_basic.c
MeTeeBasicMain.c

[Packages]
MdePkg/MdePkg.dec
Expand Down
4 changes: 2 additions & 2 deletions samples/MeTeeGsc.inf.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
ENTRY_POINT = UefiMain

[Sources]
../samples/metee_gsc.c
../samples/MeTeeGscMain.c
metee_gsc.c
MeTeeGscMain.c

[Packages]
MdePkg/MdePkg.dec
Expand Down
24 changes: 12 additions & 12 deletions src/Windows/metee_winhelpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ TEESTATUS BeginOverlappedInternal(IN TEE_OPERATION operation, IN PTEEHANDLE hand

if (ERROR_IO_PENDING != err) {
status = Win32ErrorToTee(err);
ERRPRINT(handle, "Error in ReadFile/Write, error: %d\n", err);
ERRPRINT(handle, "Error in ReadFile/Write, error: %lu\n", err);
}
else {
DBGPRINT(handle, "Pending in ReadFile/Write\n");
Expand Down Expand Up @@ -132,15 +132,15 @@ TEESTATUS EndOverlapped(IN PTEEHANDLE handle, IN EVENTHANDLE evt, IN DWORD milli
err = GetLastError();
status = Win32ErrorToTee(err);

ERRPRINT(handle, "WaitForSingleObject reported error: %d\n", err);
ERRPRINT(handle, "WaitForSingleObject reported error: %lu\n", err);
goto Cleanup;
}

// last parameter is true b/c if we're here the operation has been completed)
if (!GetOverlappedResult(impl_handle->handle, evt, pBytesTransferred, TRUE)) {
err = GetLastError();
status = Win32ErrorToTee(err);
ERRPRINT(handle, "Error in GetOverlappedResult, error: %d\n", err);
ERRPRINT(handle, "Error in GetOverlappedResult, error: %lu\n", err);
goto Cleanup;
}

Expand Down Expand Up @@ -198,7 +198,7 @@ TEESTATUS GetDevicePath(IN PTEEHANDLE handle, IN LPCGUID InterfaceGuid,

if (deviceInterfaceListLength <= 1) {
status = TEE_DEVICE_NOT_FOUND;
ERRPRINT(handle, "SetupDiGetClassDevs returned status %d\n", GetLastError());
ERRPRINT(handle, "No device interfaces found (list length: %lu)\n", deviceInterfaceListLength);
goto Cleanup;
}

Expand Down Expand Up @@ -304,20 +304,20 @@ TEESTATUS GetDeviceKind(IN PTEEHANDLE handle, IN OUT OPTIONAL char *kind, IN OUT
prop_size = MAX_PATH;
cr = CM_Get_Device_Interface_PropertyW(device_path_w, &DEVPKEY_Device_InstanceId, &prop_type, (PBYTE)instance_id, &prop_size, 0);
if (cr != CR_SUCCESS) {
ERRPRINT(handle, "CM_Get_Device_Interface_Property: %d\n", cr);
ERRPRINT(handle, "CM_Get_Device_Interface_Property: %lu\n", cr);
status = TEE_INTERNAL_ERROR;
goto Cleanup;
}
if (DEVPROP_TYPE_STRING != prop_type)
{
ERRPRINT(handle, "Invalid property type %d\n", prop_type);
ERRPRINT(handle, "Invalid property type %lu\n", prop_type);
status = TEE_INTERNAL_ERROR;
goto Cleanup;
}

cr = CM_Locate_DevNodeW(&devInstHandle, &instance_id[0], CM_LOCATE_DEVNODE_NORMAL);
if (cr != CR_SUCCESS) {
ERRPRINT(handle, "CM_Locate_DevNode: %d\n", cr);
ERRPRINT(handle, "CM_Locate_DevNode: %lu\n", cr);
status = TEE_INTERNAL_ERROR;
goto Cleanup;
}
Expand All @@ -330,7 +330,7 @@ TEESTATUS GetDeviceKind(IN PTEEHANDLE handle, IN OUT OPTIONAL char *kind, IN OUT
goto Cleanup;
}
if (cr != CR_BUFFER_SMALL) {
ERRPRINT(handle, "CM_Get_DevNode_Property: %d %d\n", cr, prop_size);
ERRPRINT(handle, "CM_Get_DevNode_Property: %lu %lu\n", cr, prop_size);
status = TEE_INTERNAL_ERROR;
goto Cleanup;
}
Expand All @@ -342,12 +342,12 @@ TEESTATUS GetDeviceKind(IN PTEEHANDLE handle, IN OUT OPTIONAL char *kind, IN OUT
}
cr = CM_Get_DevNode_PropertyW(devInstHandle, &DEVPKEY_TeedriverKindString, &prop_type, (PBYTE)kind_w, &prop_size, 0);
if (cr != CR_SUCCESS) {
ERRPRINT(handle, "CM_Get_DevNode_Property: %d %d\n", cr, prop_size);
ERRPRINT(handle, "CM_Get_DevNode_Property: %lu %lu\n", cr, prop_size);
status = TEE_INTERNAL_ERROR;
goto Cleanup;
}
if (*kindSize < prop_size) {
ERRPRINT(handle, "Insufficient buffer %d %d\n", *kindSize, prop_size);
ERRPRINT(handle, "Insufficient buffer %zu %lu\n", *kindSize, prop_size);
*kindSize = prop_size;
status = TEE_INSUFFICIENT_BUFFER;
goto Cleanup;
Expand Down Expand Up @@ -401,7 +401,7 @@ TEESTATUS SendIOCTL(IN PTEEHANDLE handle, IN EVENTHANDLE evt, IN DWORD ioControl
err = GetLastError();
// it's ok to get an error here, because it's overlapped
if (ERROR_IO_PENDING != err) {
ERRPRINT(handle, "Error in DeviceIoControl, error: %d\n", err);
ERRPRINT(handle, "Error in DeviceIoControl, error: %lu\n", err);
status = Win32ErrorToTee(err);
goto Cleanup;
}
Expand All @@ -410,7 +410,7 @@ TEESTATUS SendIOCTL(IN PTEEHANDLE handle, IN EVENTHANDLE evt, IN DWORD ioControl

if (!GetOverlappedResult(impl_handle->handle, evt, pBytesRetuned, TRUE)) {
err = GetLastError();
ERRPRINT(handle, "Error in GetOverlappedResult, error: %d\n", err);
ERRPRINT(handle, "Error in GetOverlappedResult, error: %lu\n", err);
status = Win32ErrorToTee(err);
goto Cleanup;
}
Expand Down
6 changes: 4 additions & 2 deletions src/uefi/MeTeeLibrary.inf.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
@TEE_SOURCES_MULTILINE@

[BuildOptions]
MSFT:*_*_*_CC_FLAGS = /GS- /D EFI /U _WIN32 /W4 /WX
GCC:*_*_*_CC_FLAGS = -D EFI
MSFT:*_*_*_CC_FLAGS = /GS- /D EFI /U _WIN32 /W4 /WX@METEE_EFI_STDLIB_MSFT_CC_FLAG@
GCC:*_*_*_CC_FLAGS = -D EFI@METEE_EFI_STDLIB_CC_FLAG@

[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
StdLib/StdLib.dec
MeTeePkg/MeTeePkg.dec

[LibraryClasses]
UefiLib
Expand All @@ -31,6 +32,7 @@
BaseMemoryLib
IoLib
PciSegmentLib
@METEE_EFI_STDLIB_LIBRARY_CLASS@

[Protocols]
gEfiPciRootBridgeIoProtocolGuid
12 changes: 8 additions & 4 deletions src/uefi/metee_efi.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,18 @@ HwInfoGfxCsc(
void CallbackPrintHelper(IN PTEEHANDLE handle, bool is_error, const char* args, ...)
{
char msg[DEBUG_MSG_LEN + 1];
VA_LIST varl;
VA_START(varl, args);
#ifdef METEE_EFI_STDLIB_SUPPORT
vsnprintf(msg, DEBUG_MSG_LEN, args, varl);
/* stdio.h vsnprintf requires a native C va_list, not EDK2 VA_LIST */
va_list varl;
va_start(varl, args);
vsnprintf(msg, DEBUG_MSG_LEN, args, varl);
va_end(varl);
#else
VA_LIST varl;
VA_START(varl, args);
AsciiVSPrint(msg, DEBUG_MSG_LEN, args, varl);
#endif
VA_END(varl);
#endif
handle->log_callback2(is_error, msg);
}

Expand Down
Loading
Loading