From 27a82ba331241e7c7df46b9bcb4543876e5dda9c Mon Sep 17 00:00:00 2001 From: gojimmypi Date: Sat, 22 Nov 2025 12:04:45 -0800 Subject: [PATCH 1/2] Visual Studio Improvements, Move to IDE, Introduce wolfBootTestLib --- .github/workflows/build-keytools-windows.yml | 39 -- .github/workflows/test-visual-studio.yml | 424 ++++++++++++++++++ IDE/VisualStudio/README.md | 266 +++++++++++ IDE/VisualStudio/wolfBootDebug.props | 16 + IDE/VisualStudio/wolfBootImage.props | 67 +++ .../VisualStudio}/wolfBootKeyTools.sln | 35 +- IDE/VisualStudio/wolfBootKeygen.props | 79 ++++ IDE/VisualStudio/wolfBootKeygenTool.vcxproj | 360 +++++++++++++++ IDE/VisualStudio/wolfBootSign.props | 64 +++ IDE/VisualStudio/wolfBootSignTool.vcxproj | 369 +++++++++++++++ IDE/VisualStudio/wolfBootTarget.props | 53 +++ IDE/VisualStudio/wolfBootTestLib.vcxproj | 383 ++++++++++++++++ hal/library.c | 28 +- include/user_settings.h | 19 +- src/image.c | 4 + tools/keytools/README.md | 183 +++++++- tools/keytools/keygen.c | 23 +- tools/keytools/wolfBootKeygenTool.vcxproj | 191 -------- tools/keytools/wolfBootSignTool.vcxproj | 198 -------- 19 files changed, 2357 insertions(+), 444 deletions(-) delete mode 100644 .github/workflows/build-keytools-windows.yml create mode 100644 .github/workflows/test-visual-studio.yml create mode 100644 IDE/VisualStudio/README.md create mode 100644 IDE/VisualStudio/wolfBootDebug.props create mode 100644 IDE/VisualStudio/wolfBootImage.props rename {tools/keytools => IDE/VisualStudio}/wolfBootKeyTools.sln (52%) create mode 100644 IDE/VisualStudio/wolfBootKeygen.props create mode 100644 IDE/VisualStudio/wolfBootKeygenTool.vcxproj create mode 100644 IDE/VisualStudio/wolfBootSign.props create mode 100644 IDE/VisualStudio/wolfBootSignTool.vcxproj create mode 100644 IDE/VisualStudio/wolfBootTarget.props create mode 100644 IDE/VisualStudio/wolfBootTestLib.vcxproj delete mode 100644 tools/keytools/wolfBootKeygenTool.vcxproj delete mode 100755 tools/keytools/wolfBootSignTool.vcxproj diff --git a/.github/workflows/build-keytools-windows.yml b/.github/workflows/build-keytools-windows.yml deleted file mode 100644 index 43d3868b91..0000000000 --- a/.github/workflows/build-keytools-windows.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: Build Windows Keytools executables - -on: - push: - branches: - - master - pull_request: - branches: [ '*' ] - -jobs: - build-windows: - runs-on: windows-latest - timeout-minutes: 15 - - steps: - # Step 1: Checkout the repository - - name: Checkout Code - uses: actions/checkout@v4 - with: - submodules: true - - # Step 2: Setup MSBuild - - name: Setup MSBuild - uses: microsoft/setup-msbuild@v1 - - # Step 3: Build the solution - - name: Build Solution - shell: cmd - run: | - echo #define WOLFBOOT_SECTOR_SIZE 1024 > include\target.h - MSBuild.exe tools\keytools\wolfBootKeyTools.sln /m /p:Configuration=Release /p:Platform="x64" - - # Step 4: Upload executables as artifacts - - name: Upload EXE Artifacts - uses: actions/upload-artifact@v4 - with: - name: windows-keytools - path: | - tools\keytools\x64\Release\*.exe diff --git a/.github/workflows/test-visual-studio.yml b/.github/workflows/test-visual-studio.yml new file mode 100644 index 0000000000..1e72f99ad7 --- /dev/null +++ b/.github/workflows/test-visual-studio.yml @@ -0,0 +1,424 @@ +name: wolfBoot Visual Studio + +on: + push: + branches: [ 'master', 'main', 'release/**' ] + pull_request: + branches: [ '*' ] + +jobs: + build: + name: Visual Studio Keytools Tests + runs-on: windows-latest + + env: + CONFIG: Debug + PLATFORM: x64 + + # Note: project-level preprocessors made need to be adjusted when changing. + # These are the "--" params, case sensitive: + ASYM: ed25519 + HASH: sha256 + + # Generated exe files, used for artifacts + APP_KEYGEN: keygen + APP_SIGN: sign + APP_TESTLIB: test-lib + # OTP Visual Studio not supported at this time + OTP_SUPPORTED: 'false' + # APP_OTP: otp-keystore-gen + # APP_PRIMER: otp-keystore-primer + + steps: + # Adds MSBuild to PATH + - uses: microsoft/setup-msbuild@v2 + with: + msbuild-architecture: x64 + + - name: Checkout (with submodules) + uses: actions/checkout@v4 + with: + submodules: true + + - name: Fetch test target.h + shell: cmd + working-directory: .\ + run: | + :: Ensure there's a target.h + + echo Current directory: + echo %cd% + + :: # echo Copying tools\unit-tests\target.h to src\target.h + :: # copy /Y tools\unit-tests\target.h src\target.h + + :: # Note the target.h is typically assembled during the CMake process. + :: # configure_file(include/target.h.in ${CMAKE_CURRENT_BINARY_DIR}/target.h @ONLY) + :: + :: # But we copy the unit-test sample for this workflow + echo Copying tools\unit-tests\target.h to include\target.h + + copy /Y tools\unit-tests\target.h include\target.h + + # Step 1 Build keygen, then run it + - name: Build KeygenTool keygen.exe + shell: cmd + working-directory: .\ + run: | + echo Current directory: + echo %cd% + + pushd IDE\VisualStudio + + msbuild wolfBootKeygenTool.vcxproj ^ + /t:Rebuild ^ + /m ^ + /p:Configuration=%CONFIG% ^ + /p:Platform=%PLATFORM% ^ + /p:PreferredToolArchitecture=x64 ^ + /v:m + + popd + + - name: Export EFFECTIVE_DEBUG_ARGS to env + id: export-keygen-debug-args + shell: bash + run: | + # MSBuid should have written the generated default debug args to a file in wolfBootKeygen.props + args_file="IDE/VisualStudio/${CONFIG}/${PLATFORM}/wolfBootKeygenTool/effective-debug-args.txt" + + echo "Checking args file: ${args_file}" + + # 1) File must exist and be non-empty + if [ ! -s "$args_file" ]; then + echo "WARNING: args file missing or empty: $args_file" >&2 + exit 0 + fi + + # 2) Read value and check it is non-empty + value="$(cat "$args_file")" + if [ -z "$value" ]; then + echo "WARNING: args file has no value: $args_file" >&2 + exit 0 + fi + + echo "Found debug args: $value" + + # 3) Export to GITHUB_ENV, preserving spaces and quotes + { + echo "DEBUG_ARGS_MSBUILD<> "$GITHUB_ENV" + + # Reminder that the args found are the default, and not matrix values to be tested here + echo "Found msbuild debug args DEBUG_ARGS_MSBUILD: $DEBUG_ARGS_MSBUILD" + + env: + CONFIG: ${{ env.CONFIG }} + PLATFORM: ${{ env.PLATFORM }} + + - name: Run KeygenTool keygen.exe + shell: cmd + working-directory: .\ + run: | + :: # Run keygen.exe + + echo Current directory: + echo %cd% + + echo "Config params used:" + echo "HASH=%HASH%" > .\config_params.txt + echo "ASYM=%ASYM%" >> .\config_params.txt + + echo "Calling keygen using --%ASYM%" + echo "Running .\IDE\VisualStudio\%PLATFORM%\%CONFIG%\keygen.exe --%ASYM% -g wolfboot_signing_private_key.der" + .\IDE\VisualStudio\%PLATFORM%\%CONFIG%\keygen.exe --%ASYM% -g wolfboot_signing_private_key.der + + if errorlevel 1 ( + echo keygen.exe failed with ERRORLEVEL %ERRORLEVEL% + exit /b %ERRORLEVEL% + ) + + echo "wolfboot_signing_private_key.der file:" + dir wolfboot_signing_private_key.der /s + + echo "keystore.c file:" + dir keystore.c /s + + # Step 2 Build signing tool, then run it + - name: Build SignTool sign.exe + shell: cmd + working-directory: .\ + run: | + pushd IDE\VisualStudio + + msbuild wolfBootSignTool.vcxproj ^ + /t:Rebuild ^ + /m ^ + /p:Configuration=%CONFIG% ^ + /p:Platform=%PLATFORM% ^ + /p:PreferredToolArchitecture=x64 ^ + /v:m + + popd + + - name: Create a file to sign + shell: cmd + working-directory: .\ + run: | + :: Create a test.bin file + + echo Creating a new test.bin + echo "Test" > test.bin + + - name: Run SignTool sign.exe + shell: cmd + working-directory: .\ + run: | + :: Run sign.exe + + echo Current directory: + echo %cd% + + echo "Calling sign using --%ASYM% --%HASH%" + echo Running .\IDE\VisualStudio\%PLATFORM%\%CONFIG%\sign.exe --%ASYM% --%HASH% test.bin wolfboot_signing_private_key.der 1 + + .\IDE\VisualStudio\%PLATFORM%\%CONFIG%\sign.exe --%ASYM% --%HASH% test.bin wolfboot_signing_private_key.der 1 + + if errorlevel 1 ( + echo sign.exe failed with ERRORLEVEL %ERRORLEVEL% + exit /b %ERRORLEVEL% + ) + + echo wolfboot_signing_private_key.der file: + dir wolfboot_signing_private_key.der /s + + echo "keystore.c file:" + dir keystore.c /s + + echo test.bin file: + dir test.bin /s + + echo test_v1_signed.bin file: + dir test_v1_signed.bin /s + + - name: DOS Keystore File Check + shell: cmd + working-directory: .\ + run: | + :: # Run a script to check for keystore files + echo Running .\tools\scripts\keystore_file_check.bat + + .\tools\scripts\keystore_file_check.bat + + - name: Bash Keystore File Check + shell: bash + working-directory: .\ + run: | + # Run a script to re-check for keystore files using bash (just to test scripts) + echo "Running ./tools/scripts/keystore_file_check.sh" + + ./tools/scripts/keystore_file_check.sh + + # Step 3 Build Test tool, then run it + - name: Build Library Test test-lib.exe + shell: cmd + working-directory: .\ + run: | + pushd IDE\VisualStudio + + msbuild wolfBootTestLib.vcxproj ^ + /t:Rebuild ^ + /m ^ + /p:Configuration=%CONFIG% ^ + /p:Platform=%PLATFORM% ^ + /p:PreferredToolArchitecture=x64 ^ + /v:m + + popd + + - name: Run Library Test test-lib.exe + shell: cmd + working-directory: .\ + run: | + :: # Run sign.exe + + @echo on + setlocal enableextensions + + echo Current directory: + echo %cd% + + :: # Paths + set "EXE=IDE\VisualStudio\%PLATFORM%\%CONFIG%\test-lib.exe" + set "BIN=test_v1_signed.bin" + + :: # Validate required env vars + if "%PLATFORM%"=="" ( + echo ERROR: PLATFORM is not set. + exit /b 1 + ) + if "%CONFIG%"=="" ( + echo ERROR: CONFIG is not set. + exit /b 1 + ) + + :: # Show where files are + echo Looking for "%BIN%" under "%cd%": + dir "%BIN%" /s 2>nul + + rem Existence checks + if not exist "%EXE%" ( + echo ERROR: Missing "%EXE%". + echo Tree of tools\keytools: + dir tools\keytools /s /b 2>nul + exit /b 2 + ) + if not exist "%BIN%" ( + echo ERROR: Missing "%BIN%" in current dir. + exit /b 3 + ) + + :: # A missing target.h is a common build failure on GitHub. + :: # See above where we copy one from [WOLFBOOT_ROOT]\tools\unit-tests\ + :: # echo Where is the target.h? + :: # dir target.h /s + + echo Running %EXE%" "%BIN%" + + "%EXE%" "%BIN%" + set ERR=%ERRORLEVEL% + + if not "%ERR%"=="0" ( + echo test-lib.exe failed with ERRORLEVEL %ERR% + exit /b %ERR% + ) + + dir test_v1_signed.bin /s + + echo test-lib.exe completed successfully. + endlocal + + # Build the OTP Flash otp-keystore-gen.exe that creates otp.bin + - name: Build Flash OTP + if: ${{ env.OTP_SUPPORTED == 'true' }} + shell: cmd + working-directory: .\ + run: | + :: # Begin otp-keystore-gen.exe build from DOS command prompt + + echo Current directory: + echo %cd% + + pushd IDE\VisualStudio + + msbuild wolfBootFlashOTP.vcxproj ^ + /t:Rebuild ^ + /m ^ + /p:Configuration=%CONFIG% ^ + /p:Platform=%PLATFORM% ^ + /p:PreferredToolArchitecture=x64 ^ + /v:m + + popd + + - name: Run Flash OTP otp-keystore-gen.exe + if: ${{ env.OTP_SUPPORTED == 'true' }} + shell: cmd + working-directory: .\ + run: | + :: # Run otp-keystore-gen.exe + + echo Current directory: + echo %cd% + + .\IDE\VisualStudio%PLATFORM%\%CONFIG%\otp-keystore-gen.exe + + if errorlevel 1 ( + echo otp-keystore-gen.exe failed with ERRORLEVEL %ERRORLEVEL% + exit /b %ERRORLEVEL% + ) + + echo "otp-keystore-gen otp.bin file:" + dir otp.bin /s + + # Build the OTP Keystore Primer otp-keystore-primer.exe + - name: Build OTP Keystore Primer + if: ${{ env.OTP_SUPPORTED == 'true' }} + shell: cmd + working-directory: .\ + run: | + :: # Begin otp-keystore-primer.exe build from DOS command prompt + + echo Current directory: + echo %cd% + + pushd IDE\VisualStudio + + msbuild wolfBootFlashPrimerOTP.vcxproj ^ + /t:Rebuild ^ + /m ^ + /p:Configuration=%CONFIG% ^ + /p:Platform=%PLATFORM% ^ + /p:PreferredToolArchitecture=x64 ^ + /v:m + + popd + + - name: Run Flash OTP otp-keystore-primer.exe + if: ${{ env.OTP_SUPPORTED == 'true' }} + shell: cmd + working-directory: .\ + run: | + :: # Run otp-keystore-primer.exe + + echo Current directory: + echo %cd% + + .\IDE\VisualStudio%PLATFORM%\%CONFIG%\otp-keystore-primer.exe + + if errorlevel 1 ( + echo otp-keystore-primer.exe failed with ERRORLEVEL %ERRORLEVEL% + exit /b %ERRORLEVEL% + ) + + echo Done! + + # Upload binaries if present (non-fatal if none) + - name: Upload firmware/artifacts + if: always() + uses: actions/upload-artifact@v4 + with: + name: wolfboot-visual-studio-${{ env.CONFIG }}-${{ env.PLATFORM }} + path: | + # config params used + ./config_params.txt + + # copied from tools/unit-tests/target.h + ./include/target.h + + # test private key generated + ./keystore.der + ./wolfboot_signing_private_key.der + ./src/keystore.c + + # created executables + ./tools/keytools/${{ env.PLATFORM }}/${{ env.CONFIG }}/${{ env.APP_KEYGEN }}.exe + ./tools/keytools/${{ env.PLATFORM }}/${{ env.CONFIG }}/${{ env.APP_SIGN }}.exe + ./tools/keytools/${{ env.PLATFORM }}/${{ env.CONFIG }}/${{ env.APP_TESTLIB }}.exe + #./tools/keytools/${{ env.PLATFORM }}/${{ env.CONFIG }}/${{ env.APP_OTP }}.exe + #./tools/keytools/${{ env.PLATFORM }}/${{ env.CONFIG }}/${{ env.APP_PRIMER }}.exe + + ./tools/keytools/${{ env.PLATFORM }}/${{ env.CONFIG }}/${{ env.APP_KEYGEN }}-preprocessor-defs.${{ env.CONFIG }}.${{ env.PLATFORM }}.txt + ./tools/keytools/${{ env.PLATFORM }}/${{ env.CONFIG }}/${{ env.APP_SIGN }}-preprocessor-defs.${{ env.CONFIG }}.${{ env.PLATFORM }}.txt + ./tools/keytools/${{ env.PLATFORM }}/${{ env.CONFIG }}/${{ env.APP_TESTLIB }}-preprocessor-defs.${{ env.CONFIG }}.${{ env.PLATFORM }}.txt + #./tools/keytools/${{ env.PLATFORM }}/${{ env.CONFIG }}/${{ env.APP_OTP }}-preprocessor-defs.${{ env.CONFIG }}.${{ env.PLATFORM }}.txt + #./tools/keytools/${{ env.PLATFORM }}/${{ env.CONFIG }}/${{ env.APP_PRIMER }}-preprocessor-defs.${{ env.CONFIG }}.${{ env.PLATFORM }}.txt + + # sample files + ./test.bin + ./test_v1_signed.bin + ./otp.bin + + if-no-files-found: warn diff --git a/IDE/VisualStudio/README.md b/IDE/VisualStudio/README.md new file mode 100644 index 0000000000..80bc9fa713 --- /dev/null +++ b/IDE/VisualStudio/README.md @@ -0,0 +1,266 @@ +# wolfboot Visual Studio + +## IDE + +Project files can be found in [`[WOLFBOOT_ROOT]/IDE/VisualStudio`](../IDE/VisualStudio/README.md). + + +## CMake + +Users of Visual Studio can open the `WOLFBOOT_ROOT` directory without the need for a project file. + +Visual Studio is "cmake-aware" and recognizes the [CMakePresets.json](../../CMakePresets.json) + +For the `Select Startup Item`, leave at default. Do not select `image`, wolfboot_name[], etc. + +Select a device from the ribbon bar, shown here for the `stm32l4` + +image

+ +From `Solution Explorer`, right-click `CmakeLists.txt` and then select `Configure wolfBoot`. + +image

+ +To build, follow the same steps to right click, and select `Build`. + +View the CMake and Build messages in the `Output` Window. Note the drop-down to select view: + +image

+ + +### Studio Command Prompt + +Select `View` - `Terminal` from the menu bar. + +* Configure: `cmake --preset ` +* Build: `cmake --build --preset ` + +```bash +# delete build directory +rmdir /s /q build-stm32l4 + +# configure +cmake --preset stm32l4 + +# build +cmake --build --preset stm32l4 +``` + +If there are no devices listed in the `Manage Configurations` drop-down, ensure the `CMakePresets.json` is valid. +A single json syntax error will spoil the entire project. + +## Local Visual Studio Projects + +Project files can be found in [`[WOLFBOOT_ROOT]/IDE/VisualStudio`](../../IDE/VisualStudio/README.md). + +There are three projects to: + +1. Generate a new signing key +2. Sign an image +3. Verify the signed image + +Visual Studio `$(ProjectDir)` is typically `[WOLFBOOT_ROOT]\tools\keytools`. + +----- + +## Keytools Usage + +See [keytools/README.md](../../keytools/README.md) + +### Step 1: wolfBootKeyGenTool Visual Studio Project + +Build the project. Generate a new signing key with `keygen.exe`. + +```DOS +keygen.exe [ --ed25519 | --ed448 | --ecc256 | --ecc384 | --ecc521 | --rsa2048 | --rsa3072 | --rsa4096 ] ^ + [ -g privkey] [ -i pubkey] [ -keystoreDir dir] ^ + [ --id {list}] [ --der] ^ + [ --exportpubkey] [ --nolocalkeys] +``` + +WARNING: Key Generation will *overwrite* any prior keystore files. + +Right-click on `wolfBootKeygenTool` project, typically in: + +```text +C:\workspace\wolfBoot-%USERNAME%\tools\keytools +``` + +Select: Properties - Configuration Properties - Debugging: + +```text +Command: $(TargetPath) +Command Arguments: --ed25519 -g $(ProjectDir)wolfboot_signing_private_key.der -keystoreDir $(ProjectDir) +Working Directory: $(ProjectDir)..\..\ +``` + +Replace `$(ProjectDir)` with your desired `keystoreDir` path for keys and firmware locations. +Otherwise the private key will be created in the project directory `[WOLFBOOT_ROOT]\tools\keytools`. + +Example: + +```DOS +cd %WOLFBOOT_ROOT%\tools\keytools + +:: cmd sign private key +:: ------- --------- ----------------------------------- +keygen.exe --ed25519 -g wolfboot_signing_private_key.der +``` + +Expected output: + +```text +wolfBoot KeyGen +Keystore size: 2608 +Saving keystore file: C:\workspace\wolfBoot-gojimmypi\tools\keytools\/keystore.c +Selected Keytype: ECC256 +Generating key (type: ECC256) +Associated key file: C:\workspace\wolfBoot-gojimmypi\tools\keytools\wolfboot_signing_private_key.der +Partition ids mask: ffffffff +Key type: ECC256 +Public key slot: 0 +Done. +``` + +----- + +### Step 2: wolfBootSignTool Visual Studio Project + +Build the project. Sign an image with `sign.exe [OPTIONS] IMAGE.BIN KEY.DER VERSION`. + +Right-click on `wolfBootSignTool` project, typically in: + +```text +C:\workspace\wolfBoot-%USERNAME%\tools\keytools +``` + +Select: Properties - Configuration Properties - Debugging: + +```text +Command: $(TargetPath) +Command Arguments: --ed25519 --sha256 "$(ProjectDir)test.bin" "$(ProjectDir)wolfboot_signing_private_key.der" 1 +Working Directory: $(ProjectDir) +``` + +The `$(ProjectDir)` will typically be something like this, where the `keystore.c` was generated in Step 1 (above): + +Example: + +```DOS +cd %WOLFBOOT_ROOT%\tools\keytools + +:: cmd sign hash input private key [version] [output] +:: ----- --------- -------- -------- -------------------------------- --------- ------------------ +sign.exe --ed25519 --sha256 test.bin wolfboot_signing_private_key.der 1 test_v1_signed.bin +``` + +The last two parameters are optional: + +- Version, default is `1` +- Output, default is `[input]_v1_signed.bin`, where the number after the `v` is the version. + +Be sure the signing algorithm used here matches the one on the key generation! + +Expected output: + +```text +wolfBoot KeyTools (Compiled C version) +wolfBoot version 2060000 +Update type: Firmware +Input image: C:\workspace\wolfBoot-\tools\keytools\test.bin +Selected cipher: ED25519 +Selected hash: SHA256 +Private key: C:\workspace\wolfBoot-\tools\keytools\wolfboot_signing_private_key.der +Output image: C:\workspace\wolfBoot-\tools\keytools\test_v1_signed.bin +Target partition id: 1 +Manifest header size: 256 +Found ED25519 key +Hashing primary pubkey, size: 32 +Calculating SHA256 digest... +Signing the digest... +Sign: 0x01 +Output image(s) successfully created. +``` + +----- + +### Step 3. wolfBootTestlib Visual Studio Project + +The `IS_TEST_LIB_APP` Macro is needed for the Visual Studio `wolfBootTestLib.vcproj` project file. +See also the related `wolfBootImage.props` file. + +Other additional preprocessor macros defined in project file: + +```text +__WOLFBOOT; +WOLFBOOT_NO_PARTITIONS; +WOLFBOOT_HASH_SHA256; +WOLFBOOT_SIGN_ECC256; +WOLFSSL_USER_SETTINGS; +WOLFSSL_HAVE_MIN; +WOLFSSL_HAVE_MAX; +``` + +Build the project. Verify an image with `sign.exe [OPTIONS] IMAGE.BIN KEY.DER VERSION`. + +Right-click on `wolfBootSignTool` project, typically in: + +```text +C:\workspace\wolfBoot-%USERNAME%\tools\keytools +``` + +Select: Properties - Configuration Properties - Debugging: + +```text +Command: $(TargetPath) +Command Arguments: test_v1_signed.bin +Working Directory: $(ProjectDir) +``` + +## Additional Configuration Defaults + +See the [cmake/config_defaults.cmake](../../cmake/config_defaults.cmake) file. Of particular interest +are some environment configuration settings, in particular the `DETECT_VISUALGDB`: + +```cmake +# Environments are detected in this order: +set(DETECT_VISUALGDB true) +set(DETECT_CUBEIDE true) +set(DETECT_VS2022 true) + +# Enable HAL download only implemented for TMS devices at this time. +# See [WOLFBOOT_ROOT]/cmake/stm32_hal_download.cmake +# and [WOLFBOOT_ROOT]/cmake/downloads/stm32_hal_download.cmake +set(ENABLE_HAL_DOWNLOAD true) +set(FOUND_HAL_BASE false) + +# optionally use .config files; See CMakePresets.json instead +set(USE_DOT_CONFIG false) +``` + +## Your own toolchain + +Create a `CMakeUserPresets.json` (ignored by git, see and rename `cmake/preset-examples/CMakeUserPresets.json.sample` ): + +```json +{ + "version": 3, + "configurePresets": [ + { + "name": "my-arm-bin", + "inherits": "stm32l4", + "cacheVariables": { + "ARM_GCC_BIN": "C:/Tools/arm-none-eabi-14.2/bin" + } + } + ], + "buildPresets": [ + { + "name": "my-arm-bin", + "configurePreset": "my-arm-bin" + } + ] +} +``` + +For more details, see the [cmake/README](../../cmake/README.md) file. diff --git a/IDE/VisualStudio/wolfBootDebug.props b/IDE/VisualStudio/wolfBootDebug.props new file mode 100644 index 0000000000..cf9506399d --- /dev/null +++ b/IDE/VisualStudio/wolfBootDebug.props @@ -0,0 +1,16 @@ + + + + + 4096 + + + + + + %(PreprocessorDefinitions);LMS_IMAGE_SIGNATURE_SIZE=$(IMAGE_SIGNATURE_SIZE);XMSS_IMAGE_SIGNATURE_SIZE=$(IMAGE_SIGNATURE_SIZE) + + + + + diff --git a/IDE/VisualStudio/wolfBootImage.props b/IDE/VisualStudio/wolfBootImage.props new file mode 100644 index 0000000000..2dc261b42b --- /dev/null +++ b/IDE/VisualStudio/wolfBootImage.props @@ -0,0 +1,67 @@ + + + + + + + <_DbgArgsTrim>$([System.String]::Copy('$(LocalDebuggerCommandArguments)').Trim()) + + + <_UserSetArgs>false + <_UserSetArgs Condition="'$(_DbgArgsTrim)' != ''">true + + + <_DefaultArgs> + + <_DefaultSignedImage>$(ProjectDir)\test_v1_signed.bin + $(_DefaultSignedImage) + + + <_DefaultArgs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SIGNED_IMAGE) + + $(LocalDebuggerCommandArguments) + $(SIGNED_IMAGE) + + + false + true + + + + + + + + + + + + + + + + %(PreprocessorDefinitions); + SIGNED_IMAGE_MSBUILD="$(SIGNED_IMAGE)"; + DEBUG_ARGS_MSBUILD="$(EFFECTIVE_DEBUG_ARGS)"; + MSBUILD_CFG_DEBUG=$(IS_DEBUG_CONFIG) + + + + + + + WindowsLocalDebugger + $(ProjectDir) + + $(EFFECTIVE_DEBUG_ARGS) + + + + + + + + + + + diff --git a/tools/keytools/wolfBootKeyTools.sln b/IDE/VisualStudio/wolfBootKeyTools.sln similarity index 52% rename from tools/keytools/wolfBootKeyTools.sln rename to IDE/VisualStudio/wolfBootKeyTools.sln index 3aad386492..e7cee0048b 100644 --- a/tools/keytools/wolfBootKeyTools.sln +++ b/IDE/VisualStudio/wolfBootKeyTools.sln @@ -1,12 +1,32 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.28307.779 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36518.9 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wolfBootSignTool", "wolfBootSignTool.vcxproj", "{0E5B9C81-CA2B-47CA-BA83-074078CF3393}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wolfBootKeygenTool", "wolfBootKeygenTool.vcxproj", "{599F7765-B224-41D4-AA56-597FFA9763BC}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8EC462FD-D22E-90A8-E5CE-7E832BA40C5D}" + ProjectSection(SolutionItems) = preProject + README.md = README.md + ..\..\.github\workflows\test-visual-studio.yml = ..\..\.github\workflows\test-visual-studio.yml + wolfBootDebug.props = wolfBootDebug.props + wolfBootImage.props = wolfBootImage.props + wolfBootKeygen.props = wolfBootKeygen.props + wolfBootSign.props = wolfBootSign.props + wolfBootTarget.props = wolfBootTarget.props + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}" + ProjectSection(SolutionItems) = preProject + ..\..\docs\keystore.md = ..\..\docs\keystore.md + ..\..\docs\README.md = ..\..\docs\README.md + ..\..\docs\Signing.md = ..\..\docs\Signing.md + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wolfBootTestLib", "wolfBootTestLib.vcxproj", "{3A6C8B82-0B5E-4B5E-9C9D-5C9F1F9B1D77}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -31,10 +51,21 @@ Global {599F7765-B224-41D4-AA56-597FFA9763BC}.Release|x64.Build.0 = Release|x64 {599F7765-B224-41D4-AA56-597FFA9763BC}.Release|x86.ActiveCfg = Release|Win32 {599F7765-B224-41D4-AA56-597FFA9763BC}.Release|x86.Build.0 = Release|Win32 + {3A6C8B82-0B5E-4B5E-9C9D-5C9F1F9B1D77}.Debug|x64.ActiveCfg = Debug|x64 + {3A6C8B82-0B5E-4B5E-9C9D-5C9F1F9B1D77}.Debug|x64.Build.0 = Debug|x64 + {3A6C8B82-0B5E-4B5E-9C9D-5C9F1F9B1D77}.Debug|x86.ActiveCfg = Debug|x64 + {3A6C8B82-0B5E-4B5E-9C9D-5C9F1F9B1D77}.Debug|x86.Build.0 = Debug|x64 + {3A6C8B82-0B5E-4B5E-9C9D-5C9F1F9B1D77}.Release|x64.ActiveCfg = Release|x64 + {3A6C8B82-0B5E-4B5E-9C9D-5C9F1F9B1D77}.Release|x64.Build.0 = Release|x64 + {3A6C8B82-0B5E-4B5E-9C9D-5C9F1F9B1D77}.Release|x86.ActiveCfg = Release|x64 + {3A6C8B82-0B5E-4B5E-9C9D-5C9F1F9B1D77}.Release|x86.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} = {8EC462FD-D22E-90A8-E5CE-7E832BA40C5D} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {002B85D3-20F7-44FB-BFA5-6B5AC72F499B} EndGlobalSection diff --git a/IDE/VisualStudio/wolfBootKeygen.props b/IDE/VisualStudio/wolfBootKeygen.props new file mode 100644 index 0000000000..6139e5c09f --- /dev/null +++ b/IDE/VisualStudio/wolfBootKeygen.props @@ -0,0 +1,79 @@ + + + + + + + <_DbgArgsTrim>$([System.String]::Copy('$(LocalDebuggerCommandArguments)').Trim()) + + + <_UserSetArgs>false + <_UserSetArgs Condition="'$(_DbgArgsTrim)' != ''">true + + + <_DefaultArgs> + + + <_DefaultArgs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">--no-overwrite --ed25519 -g "$(THIS_KEYSTORE_ROOT)\$(THIS_PRIVATE_KEY_DER)" -keystoreDir "$(THIS_KEYSTORE_ROOT)" + + + $(LocalDebuggerCommandArguments) + $(_DefaultArgs) + + + false + true + + + + + + + + + + + + + + + + %(PreprocessorDefinitions); + SIGNED_IMAGE_MSBUILD="$(SIGNED_IMAGE)"; + DEBUG_ARGS_MSBUILD="$(EFFECTIVE_DEBUG_ARGS)"; + MSBUILD_CFG_DEBUG=$(IS_DEBUG_CONFIG) + + + + + + + WindowsLocalDebugger + $(ProjectDir) + $(EFFECTIVE_DEBUG_ARGS) + + + + + + + + + + + + + + + $(IntDir)effective-debug-args.txt + + + + + + + diff --git a/IDE/VisualStudio/wolfBootKeygenTool.vcxproj b/IDE/VisualStudio/wolfBootKeygenTool.vcxproj new file mode 100644 index 0000000000..7b4082ba67 --- /dev/null +++ b/IDE/VisualStudio/wolfBootKeygenTool.vcxproj @@ -0,0 +1,360 @@ + + + + wolfboot_signing_private_key.der + wolfBootKeygen.props + + + $(WOLFBOOT_ROOT) + $(MSBuildThisFileDirectory)..\.. + + + + + $(KEYSTORE_ROOT) + $([System.IO.Path]::Combine('$(THIS_WOLFBOOT_ROOT)', 'src')) + $([MSBuild]::NormalizePath('$(THIS_KEYSTORE_ROOT_RAW)')) + + + + + $(KEYGEN_ROOT) + $(THIS_WOLFBOOT_ROOT)\tools\keytools + + + + $(WOLFSSL_ROOT) + $(THIS_WOLFBOOT_ROOT)\lib\wolfssl + + + + $(WOLFTPM_ROOT) + $(THIS_WOLFBOOT_ROOT)\lib\wolfTPM + + + + $(WOLFPKCS11_ROOT) + $(THIS_WOLFBOOT_ROOT)\lib\wolfPKCS11 + + + + $(WOLFHSM_ROOT) + $(THIS_WOLFBOOT_ROOT)\lib\wolfHSM + + + + + + + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + EnsureTargetHeader;$(BuildDependsOn) + + + + + + $(THIS_WOLFBOOT_ROOT)\tools\unit-tests\target.h + $(IntDir)target.h + + + + + + + + + + + + + + + + + + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {599F7765-B224-41D4-AA56-597FFA9763BC} + Win32Proj + wolfBootKeygenTool + 10.0 + wolfBootKeygenTool + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + true + keygen + $(Platform)\$(Configuration)\$(ProjectName)\ + + + true + keygen + $(Platform)\$(Configuration)\$(ProjectName)\ + + + false + keygen + $(Platform)\$(Configuration)\$(ProjectName)\ + + + false + keygen + $(Platform)\$(Configuration)\$(ProjectName)\ + + + + + + Level3 + Disabled + WOLFSSL_USER_SETTINGS;WOLFSSL_HAVE_MIN;WOLFSSL_HAVE_MAX;%(PreprocessorDefinitions) + + $(IntDir); + $(THIS_KEYGEN_ROOT); + $(THIS_WOLFSSL_ROOT); + $(THIS_WOLFBOOT_ROOT)/include; + %(AdditionalIncludeDirectories) + + false + + + Console + true + + + + + + + Level3 + Disabled + + $(THIS_KEYGEN_ROOT); + $(THIS_WOLFSSL_ROOT); + $(THIS_WOLFBOOT_ROOT)/include; + $(IntDir); + %(AdditionalIncludeDirectories) + + WOLFSSL_USER_SETTINGS;WOLFSSL_HAVE_MIN;WOLFSSL_HAVE_MAX;%(PreprocessorDefinitions) + false + + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + WOLFSSL_USER_SETTINGS;WOLFSSL_HAVE_MIN;WOLFSSL_HAVE_MAX;%(PreprocessorDefinitions) + + $(THIS_KEYGEN_ROOT); + $(THIS_WOLFSSL_ROOT); + $(THIS_WOLFBOOT_ROOT)/include; + $(IntDir); + %(AdditionalIncludeDirectories) + + false + + + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + WOLFSSL_USER_SETTINGS;WOLFSSL_HAVE_MIN;WOLFSSL_HAVE_MAX;%(PreprocessorDefinitions) + + $(THIS_KEYGEN_ROOT); + $(THIS_WOLFSSL_ROOT); + $(THIS_WOLFBOOT_ROOT)/include; + $(IntDir); + %(AdditionalIncludeDirectories) + + false + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + $(TargetDir)$(TargetName)-preprocessor-defs.$(Configuration).$(Platform).txt + + + + + <_AllDefs Include="%(ClCompile.PreprocessorDefinitions)" /> + + <_DefRaw Include="$([System.String]::Copy('%(_AllDefs.Identity)').Split(';'))" /> + + + + <_Def Include="@(_DefRaw)" Condition="'%(_DefRaw.Identity)' != ''" /> + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/IDE/VisualStudio/wolfBootSign.props b/IDE/VisualStudio/wolfBootSign.props new file mode 100644 index 0000000000..4c7ea65330 --- /dev/null +++ b/IDE/VisualStudio/wolfBootSign.props @@ -0,0 +1,64 @@ + + + + + + + <_DbgArgsTrim>$([System.String]::Copy('$(LocalDebuggerCommandArguments)').Trim()) + + + <_UserSetArgs>false + <_UserSetArgs Condition="'$(_DbgArgsTrim)' != ''">true + + + <_DefaultArgs> + + + <_DefaultArgs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">--ed25519 --sha256 "$(ProjectDir)test.bin" "$(THIS_KEYSTORE_ROOT)\$(THIS_PRIVATE_KEY_DER)" 1 + + + $(LocalDebuggerCommandArguments) + $(_DefaultArgs) + + + false + true + + + + + + + + + + + + + + + + %(PreprocessorDefinitions); + SIGNED_IMAGE_MSBUILD="$(SIGNED_IMAGE)"; + DEBUG_ARGS_MSBUILD="$(EFFECTIVE_DEBUG_ARGS)"; + MSBUILD_CFG_DEBUG=$(IS_DEBUG_CONFIG) + + + + + + + WindowsLocalDebugger + $(ProjectDir) + $(EFFECTIVE_DEBUG_ARGS) + + + + + + + + + + + diff --git a/IDE/VisualStudio/wolfBootSignTool.vcxproj b/IDE/VisualStudio/wolfBootSignTool.vcxproj new file mode 100644 index 0000000000..cc92d4f129 --- /dev/null +++ b/IDE/VisualStudio/wolfBootSignTool.vcxproj @@ -0,0 +1,369 @@ + + + + wolfboot_signing_private_key.der + wolfBootSign.props + + $(WOLFBOOT_ROOT) + $(MSBuildThisFileDirectory)..\.. + + + + + $(KEYSTORE_ROOT) + $([System.IO.Path]::Combine('$(THIS_WOLFBOOT_ROOT)', 'src')) + $([MSBuild]::NormalizePath('$(THIS_KEYSTORE_ROOT_RAW)')) + + + + + $(KEYGEN_ROOT) + $(THIS_WOLFBOOT_ROOT)\tools\keytools + + + + $(WOLFSSL_ROOT) + $(THIS_WOLFBOOT_ROOT)\lib\wolfssl + + + + $(WOLFTPM_ROOT) + $(THIS_WOLFBOOT_ROOT)\lib\wolfTPM + + + + $(WOLFPKCS11_ROOT) + $(THIS_WOLFBOOT_ROOT)\lib\wolfPKCS11 + + + + $(WOLFHSM_ROOT) + $(THIS_WOLFBOOT_ROOT)\lib\wolfHSM + + + + + + + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + EnsureTargetHeader;$(BuildDependsOn) + + + + + + $(THIS_WOLFBOOT_ROOT)\tools\unit-tests\target.h + $(IntDir)target.h + + + + + + + + + + + + + + + + + + + + + + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {0E5B9C81-CA2B-47CA-BA83-074078CF3393} + Win32Proj + wolfBootSignTool + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + sign + $(Platform)\$(Configuration)\$(ProjectName)\ + + + true + sign + $(Platform)\$(Configuration)\$(ProjectName)\ + + + false + sign + $(Platform)\$(Configuration)\$(ProjectName)\ + + + false + sign + $(Platform)\$(Configuration)\$(ProjectName)\ + + + + + + Level3 + Disabled + WOLFSSL_USER_SETTINGS;DELTA_UPDATES;WOLFSSL_HAVE_MIN;WOLFSSL_HAVE_MAX;WOLFBOOT_SIGN_ED25519;%(PreprocessorDefinitions) + + $(IntDir); + $(THIS_KEYGEN_ROOT); + $(THIS_WOLFSSL_ROOT); + $(THIS_WOLFBOOT_ROOT)/include; + %(AdditionalIncludeDirectories) + + false + + Console + true + + + + + + + Level3 + Disabled + WOLFSSL_USER_SETTINGS;DELTA_UPDATES;WOLFSSL_HAVE_MIN;WOLFSSL_HAVE_MAX;WOLFBOOT_SIGN_ED25519;%(PreprocessorDefinitions) + + $(IntDir); + $(THIS_KEYGEN_ROOT); + $(THIS_WOLFSSL_ROOT); + $(THIS_WOLFBOOT_ROOT)/include; + %(AdditionalIncludeDirectories) + + false + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + WOLFSSL_USER_SETTINGS;DELTA_UPDATES;WOLFSSL_HAVE_MIN;WOLFSSL_HAVE_MAX;WOLFBOOT_SIGN_ED25519;%(PreprocessorDefinitions) + + $(IntDir); + $(THIS_KEYGEN_ROOT); + $(THIS_WOLFSSL_ROOT); + $(THIS_WOLFBOOT_ROOT)/include; + %(AdditionalIncludeDirectories) + + false + + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + WOLFSSL_USER_SETTINGS;DELTA_UPDATES;WOLFSSL_HAVE_MIN;WOLFSSL_HAVE_MAX;WOLFBOOT_SIGN_ED25519;%(PreprocessorDefinitions) + + $(IntDir); + $(THIS_KEYGEN_ROOT); + $(THIS_WOLFSSL_ROOT); + $(THIS_WOLFBOOT_ROOT)/include; + %(AdditionalIncludeDirectories) + + false + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + $(THIS_WOLFSSL_ROOT)\wolfssl;..\..\include;..\..\include;.;%(AdditionalIncludeDirectories) + $(THIS_WOLFSSL_ROOT)\wolfssl;..\..\include;.;%(AdditionalIncludeDirectories) + .;$(THIS_WOLFSSL_ROOT)\wolfssl;..\..\include;%(AdditionalIncludeDirectories) + .;$(THIS_WOLFSSL_ROOT)\wolfssl;..\..\include;%(AdditionalIncludeDirectories) + + + + + + + + + + + + + + + + + + + $(TargetDir)$(TargetName)-preprocessor-defs.$(Configuration).$(Platform).txt + + + + + + <_AllDefs Include="%(ClCompile.PreprocessorDefinitions)" /> + + <_DefRaw Include="$([System.String]::Copy('%(_AllDefs.Identity)').Split(';'))" /> + + + + + <_Def Include="@(_DefRaw)" Condition="'%(_DefRaw.Identity)' != ''" /> + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/IDE/VisualStudio/wolfBootTarget.props b/IDE/VisualStudio/wolfBootTarget.props new file mode 100644 index 0000000000..9c0ebbd860 --- /dev/null +++ b/IDE/VisualStudio/wolfBootTarget.props @@ -0,0 +1,53 @@ + + + + 0x0040000 + 0x0001000 + 0x08020000 + 0x08060000 + 0x080A0000 + 0x08020000 + 0x08060000 + 0x24000000 + 0x24000000 + + + + + + + include\target.h + + + + + + + + + diff --git a/IDE/VisualStudio/wolfBootTestLib.vcxproj b/IDE/VisualStudio/wolfBootTestLib.vcxproj new file mode 100644 index 0000000000..e4436a64ab --- /dev/null +++ b/IDE/VisualStudio/wolfBootTestLib.vcxproj @@ -0,0 +1,383 @@ + + + + wolfboot_signing_private_key.der + wolfBootImage.props + + $(WOLFBOOT_ROOT) + $(MSBuildThisFileDirectory)..\.. + + + + + $(KEYSTORE_ROOT) + $([System.IO.Path]::Combine('$(THIS_WOLFBOOT_ROOT)', 'src')) + $([MSBuild]::NormalizePath('$(THIS_KEYSTORE_ROOT_RAW)')) + + + + + $(KEYGEN_ROOT) + $(THIS_WOLFBOOT_ROOT)\tools\keytools + + + + $(WOLFSSL_ROOT) + $(THIS_WOLFBOOT_ROOT)\lib\wolfssl + + + + $(WOLFTPM_ROOT) + $(THIS_WOLFBOOT_ROOT)\lib\wolfTPM + + + + $(WOLFPKCS11_ROOT) + $(THIS_WOLFBOOT_ROOT)\lib\wolfPKCS11 + + + + $(WOLFHSM_ROOT) + $(THIS_WOLFBOOT_ROOT)\lib\wolfHSM + + + + + EnsureTargetHeader;$(BuildDependsOn) + + + + + + $(THIS_WOLFBOOT_ROOT)\tools\unit-tests\target.h + $(IntDir)target.h + + + + + + + + + + + + + + + + + + + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {3A6C8B82-0B5E-4B5E-9C9D-5C9F1F9B1D77} + Win32Proj + wolfBootTestLib + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + test-lib + $(Platform)\$(Configuration)\$(ProjectName)\ + + + true + test-lib + $(Platform)\$(Configuration)\$(ProjectName)\ + + + false + test-lib + $(Platform)\$(Configuration)\$(ProjectName)\ + + + false + test-lib + $(Platform)\$(Configuration)\$(ProjectName)\ + + + + + + Level3 + Disabled + __WOLFBOOT;WOLFBOOT_NO_PARTITIONS;WOLFBOOT_HASH_SHA256;WOLFBOOT_SIGN_ED25519;WOLFSSL_USER_SETTINGS;WOLFSSL_HAVE_MIN;WOLFSSL_HAVE_MAX;NO_ED25519_MAKE_KEY;%(PreprocessorDefinitions) + + $(THIS_WOLFBOOT_ROOT)/include; + $(IntDir); + $(THIS_KEYGEN_ROOT); + $(THIS_WOLFSSL_ROOT); + %(AdditionalIncludeDirectories) + + false + + + Console + true + + + + + + + Level3 + Disabled + __WOLFBOOT;WOLFBOOT_NO_PARTITIONS;WOLFBOOT_HASH_SHA256;WOLFBOOT_SIGN_ED25519;WOLFSSL_USER_SETTINGS;WOLFSSL_HAVE_MIN;WOLFSSL_HAVE_MAX;NO_ED25519_MAKE_KEY;%(PreprocessorDefinitions) + + + $(THIS_WOLFBOOT_ROOT)/include; + $(IntDir); + $(THIS_KEYGEN_ROOT); + $(THIS_WOLFSSL_ROOT); + %(AdditionalIncludeDirectories) + + false + + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + __WOLFBOOT;WOLFBOOT_NO_PARTITIONS;WOLFBOOT_HASH_SHA256;WOLFBOOT_SIGN_ED25519;WOLFSSL_USER_SETTINGS;WOLFSSL_HAVE_MIN;WOLFSSL_HAVE_MAX;NO_ED25519_MAKE_KEY;%(PreprocessorDefinitions) + + $(THIS_WOLFBOOT_ROOT)/include; + $(IntDir); + $(THIS_KEYGEN_ROOT); + $(THIS_WOLFSSL_ROOT); + %(AdditionalIncludeDirectories) + + false + + + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + __WOLFBOOT;WOLFBOOT_NO_PARTITIONS;WOLFBOOT_HASH_SHA256;WOLFBOOT_SIGN_ED25519;WOLFSSL_USER_SETTINGS;WOLFSSL_HAVE_MIN;WOLFSSL_HAVE_MAX;NO_ED25519_MAKE_KEY;%(PreprocessorDefinitions) + + $(THIS_WOLFBOOT_ROOT)/include; + $(IntDir); + $(THIS_KEYGEN_ROOT); + $(THIS_WOLFSSL_ROOT); + %(AdditionalIncludeDirectories) + + false + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + $(THIS_WOLFBOOT_ROOT)\include\user_settings.h;%(ForcedIncludeFiles) + + + + + + + + + + + + + + + + $(IntDir)generated + $(GeneratedIncludeDir)\target.h + + + + + + + + + + + + + + + + + + + + + true + + + + + + + $(TargetDir)$(TargetName)-preprocessor-defs.$(Configuration).$(Platform).txt + + + + + <_AllDefs Include="%(ClCompile.PreprocessorDefinitions)" /> + + <_DefRaw Include="$([System.String]::Copy('%(_AllDefs.Identity)').Split(';'))" /> + + + + <_Def Include="@(_DefRaw)" Condition="'%(_DefRaw.Identity)' != ''" /> + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/hal/library.c b/hal/library.c index 00e0b5230b..c5efd7867e 100644 --- a/hal/library.c +++ b/hal/library.c @@ -24,6 +24,20 @@ #include #include +#ifdef _WIN32 +#include +#define HAVE_MMAP 0 +#define ftruncate(fd, len) _chsize(fd, len) +static inline int fp_truncate(FILE* f, long len) +{ + int fd; + if (f == NULL) + return -1; + fd = _fileno(f); + return _chsize(fd, len); +} +#define PRINTF_ENABLED +#else #if 1 /* for desktop testing */ #define HAVE_UNISTD_H #define PRINTF_ENABLED @@ -37,6 +51,7 @@ #else #define exit(x) while(1); #endif +#endif #include "image.h" #include "printf.h" @@ -83,15 +98,16 @@ void hal_prepare_boot(void) return; } -int do_boot(uint32_t* v) -{ - wolfBoot_printf("booting %p" + #ifdef HAVE_UNISTD_H - "(actually exiting)" + #define BOOT_SUFFIX " (actually exiting)" #else - "(actually spin loop)" + #define BOOT_SUFFIX " (actually spin loop)" #endif - "\n", v); + +int do_boot(uint32_t* v) +{ + wolfBoot_printf("booting %p" BOOT_SUFFIX "\n", v); exit(0); } diff --git a/include/user_settings.h b/include/user_settings.h index b21ff4c5c4..c3e85ff4a8 100644 --- a/include/user_settings.h +++ b/include/user_settings.h @@ -25,6 +25,21 @@ #ifndef _WOLFBOOT_USER_SETTINGS_H_ #define _WOLFBOOT_USER_SETTINGS_H_ +#if defined(_MSC_VER) + /* MSVC and clang-cl both define _MSC_VER */ + #ifndef WOLFSSL_HAVE_MIN + #define WOLFSSL_HAVE_MIN + #endif + #ifndef WOLFSSL_HAVE_MAX + #define WOLFSSL_HAVE_MAX + #endif + + /* Really keep Windows headers from redefining min/max */ + #ifndef NOMINMAX + #define NOMINMAX 1 + #endif +#endif + #ifdef WOLFBOOT_PKCS11_APP # include "test-app/wcs/user_settings.h" #else @@ -330,7 +345,9 @@ extern int tolower(int c); /* SP Math needs to understand long long */ # ifndef ULLONG_MAX -# define ULLONG_MAX 18446744073709551615ULL +# ifndef _MSC_VER +# define ULLONG_MAX 18446744073709551615ULL +# endif # endif #endif diff --git a/src/image.c b/src/image.c index 5c776ae6d8..9b0e56ff08 100644 --- a/src/image.c +++ b/src/image.c @@ -59,7 +59,11 @@ #endif /* Globals */ +#ifdef _MSC_VER +static XALIGNED(4) uint8_t digest[WOLFBOOT_SHA_DIGEST_SIZE]; +#else static uint8_t digest[WOLFBOOT_SHA_DIGEST_SIZE] XALIGNED(4); +#endif #if defined(WOLFBOOT_CERT_CHAIN_VERIFY) && \ (defined(WOLFBOOT_ENABLE_WOLFHSM_CLIENT) || \ diff --git a/tools/keytools/README.md b/tools/keytools/README.md index cee4e06a0d..9dd83b25d1 100644 --- a/tools/keytools/README.md +++ b/tools/keytools/README.md @@ -1,3 +1,184 @@ # Key Tools for signing and key generation -See documentation [here](../../docs/Signing.md). + +## Sign + +See documentation in [docs/Signing.md](../../docs/Signing.md). + +## KeyGen and KeyStore + +See documentation [docs/keystore.md](../../docs/keystore.md). + +## Quick Start (Linux) + +``` +make wolfboot_signing_private_key.der SIGN=ECC256 + +# or +./tools/keytools/keygen --ecc256 -g wolfboot_signing_private_key.der +``` + +## Generated Files + +Unless otherwise specified the keygen will create: + +1. `./wolfboot_signing_private_key.der` - the private key used for signing. +2. `./keystore.der` - the public key. +3. `src/keystore.c` - the public key, converted to c array. + +## Local Visual Studio Projects + +There are three projects to: + +1. Generate a new signing key +2. Sign an image +3. Verify the signed image + +Visual Studio `$(ProjectDir)` is typically `[WOLFBOOT_ROOT]\tools\keytools`. + +----- + +### Step 1: wolfBootKeyGenTool Visual Studio Project + +Build the project. Generate a new signing key with `keygen.exe`. + +```DOS +keygen.exe [ --ed25519 | --ed448 | --ecc256 | --ecc384 | --ecc521 | --rsa2048 | --rsa3072 | --rsa4096 ] ^ + [ -g privkey] [ -i pubkey] [ -keystoreDir dir] ^ + [ --id {list}] [ --der] ^ + [ --exportpubkey] [ --nolocalkeys] +``` + +WARNING: Key Generation will *overwrite* any prior keystore files. + +Right-click on `wolfBootKeygenTool` project, typically in: + +```text +C:\workspace\wolfBoot-%USERNAME%\tools\keytools +``` + +Select: Properties - Configuration Properties - Debugging: + +```text +Command: $(TargetPath) +Command Arguments: --ed25519 -g $(ProjectDir)wolfboot_signing_private_key.der -keystoreDir $(ProjectDir) +Working Directory: $(ProjectDir) +``` + +Replace `$(ProjectDir)` with your desired path for keys and firmware locations. +Otherwise the private key will be created in `tools\keytools`. + +Example: + +```DOS +cd $WOLFBOOT_ROOT\tools\keytools + +:: cmd sign private key +:: ------- --------- ----------------------------------- +keygen.exe --ed25519 -g wolfboot_signing_private_key.der +``` + +Expected output: + +```text +wolfBoot KeyGen +Keystore size: 2608 +Saving keystore file: C:\workspace\wolfBoot-gojimmypi\tools\keytools\/keystore.c +Selected Keytype: ECC256 +Generating key (type: ECC256) +Associated key file: C:\workspace\wolfBoot-gojimmypi\tools\keytools\wolfboot_signing_private_key.der +Partition ids mask: ffffffff +Key type: ECC256 +Public key slot: 0 +Done. +``` + +----- + +### Step 2: wolfBootSignTool Visual Studio Project + +Build the project. Sign an image with `sign.exe [OPTIONS] IMAGE.BIN KEY.DER VERSION`. + +Right-click on `wolfBootSignTool` project, typically in: + +```text +C:\workspace\wolfBoot-%USERNAME%\tools\keytools +``` + +Select: Properties - Configuration Properties - Debugging: + +```text +Command: $(TargetPath) +Command Arguments: --ed25519 --sha256 "$(ProjectDir)test.bin" "$(ProjectDir)wolfboot_signing_private_key.der" 1 +Working Directory: $(ProjectDir) +``` + +The `$(ProjectDir)` will typically be something like this, where the `keystore.c` was generated in Step 1 (above): + +Example: + +```DOS +cd $WOLFBOOT_ROOT\tools\keytools + +:: cmd sign hash input private key version +:: ----- --------- -------- -------- -------------------------------- ------- +sign.exe --ed25519 --sha256 test.bin wolfboot_signing_private_key.der 1 +``` + +Be sure the signing algorithm used here matches the one on the key generation! + +Expected output: + +```text +wolfBoot KeyTools (Compiled C version) +wolfBoot version 2060000 +Update type: Firmware +Input image: C:\workspace\wolfBoot-\tools\keytools\test.bin +Selected cipher: ED25519 +Selected hash: SHA256 +Private key: C:\workspace\wolfBoot-\tools\keytools\wolfboot_signing_private_key.der +Output image: C:\workspace\wolfBoot-\tools\keytools\test_v1_signed.bin +Target partition id: 1 +Manifest header size: 256 +Found ED25519 key +Hashing primary pubkey, size: 32 +Calculating SHA256 digest... +Signing the digest... +Sign: 0x01 +Output image(s) successfully created. +``` + +----- + +### Step 3. wolfBootTestlib Visual Studio Project + +The `IS_TEST_LIB_APP` Macro is needed for the Visual Studio `wolfBootTestLib.vcproj` project file. +See also the related `wolfBootImage.props` file. + +Other additional preprocessor macros defined in project file: + +```text +__WOLFBOOT; +WOLFBOOT_NO_PARTITIONS; +WOLFBOOT_HASH_SHA256; +WOLFBOOT_SIGN_ECC256; +WOLFSSL_USER_SETTINGS; +WOLFSSL_HAVE_MIN; +WOLFSSL_HAVE_MAX; +``` + +Build the project. Verify an image with `sign.exe [OPTIONS] IMAGE.BIN KEY.DER VERSION`. + +Right-click on `wolfBootSignTool` project, typically in: + +```text +C:\workspace\wolfBoot-%USERNAME%\tools\keytools +``` + +Select: Properties - Configuration Properties - Debugging: + +```text +Command: $(TargetPath) +Command Arguments: test_v1_signed.bin +Working Directory: $(ProjectDir) +``` diff --git a/tools/keytools/keygen.c b/tools/keytools/keygen.c index 97f38340d6..c2de30a879 100644 --- a/tools/keytools/keygen.c +++ b/tools/keytools/keygen.c @@ -40,10 +40,16 @@ #include #include #include -#ifndef _WIN32 +#ifdef _WIN32 + #define _CRT_SECURE_NO_WARNINGS + #define _CRT_NONSTDC_NO_DEPRECATE /* unlink */ +#else #include #endif +/* wolfSSL */ +/* Always include wolfcrypt/settings.h before any other wolfSSL file. */ +/* Reminder: settings.h pulls in user_settings.h; don't include it here. */ #include #ifndef NO_RSA #include @@ -173,6 +179,10 @@ const char Store_hdr[] = "\n" "#define KEYSTORE_SECTION /* Renesas RX */\n" "#elif defined(TARGET_x86_64_efi)\n" "#define KEYSTORE_SECTION\n" + "#elif defined(_MSC_VER)\n" + "/* Create a RW data section named .keystore ! */\n" + "#pragma section(\".keystore\", read, write)\n" + "#define KEYSTORE_SECTION __declspec(allocate(\".keystore\"))\n" "#else\n" "#define KEYSTORE_SECTION __attribute__((section (\".keystore\")))\n" "#endif\n\n" @@ -504,10 +514,10 @@ void keystore_add(uint32_t ktype, uint8_t *key, uint32_t sz, const char *keyfile } fprintf(fpub, Pubkey_footer); fprintf(fpub, Slot_footer); - printf("Associated key file: %s\n", keyfile); + printf("Associated key file: %s\n", keyfile); printf("Partition ids mask: %08x\n", id_mask); - printf("Key type : %s\n", KName[ktype]); - printf("Public key slot: %u\n", id_slot); + printf("Key type: %s\n", KName[ktype]); + printf("Public key slot: %u\n", id_slot); if (noLocalKeys) { printf("WARNING: --nolocalkeys flag used, keystore.c public key is zeroed\n"); } @@ -1157,7 +1167,8 @@ static void key_gen_check(const char *kfilename) f = fopen(kfilename, "rb"); if (!force && (f != NULL)) { if (no_overwrite) { - printf("** Warning: key file already exists and will not be overwritten!"); + printf("** Warning: private key file already exists and will not be overwritten!\n"); + printf("File: %s\n", kfilename); } else { char reply[40]; @@ -1446,7 +1457,7 @@ int main(int argc, char** argv) i++; sprintf(pubkeyfile,"%s%s", argv[i], "/keystore.c"); sprintf(pubkeyimg, "%s%s", argv[i], "/keystore.der"); - printf("keystore file: %s\n", pubkeyfile); + printf("Keystore file: %s\n", pubkeyfile); i++; continue; } diff --git a/tools/keytools/wolfBootKeygenTool.vcxproj b/tools/keytools/wolfBootKeygenTool.vcxproj deleted file mode 100644 index b9fd05a5f4..0000000000 --- a/tools/keytools/wolfBootKeygenTool.vcxproj +++ /dev/null @@ -1,191 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - {599F7765-B224-41D4-AA56-597FFA9763BC} - Win32Proj - wolfBootKeygenTool - 10.0 - - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - keygen - $(Platform)\$(Configuration)\$(ProjectName)\ - - - true - keygen - $(Platform)\$(Configuration)\$(ProjectName)\ - - - false - keygen - $(Platform)\$(Configuration)\$(ProjectName)\ - - - false - keygen - $(Platform)\$(Configuration)\$(ProjectName)\ - - - - - - Level3 - Disabled - .;../../lib/wolfssl;../../include;%(AdditionalIncludeDirectories) - WOLFSSL_USER_SETTINGS;WOLFSSL_HAVE_MIN;WOLFSSL_HAVE_MAX;%(PreprocessorDefinitions) - - - Console - true - - - - - - - Level3 - Disabled - .;../../lib/wolfssl;../../include;%(AdditionalIncludeDirectories) - WOLFSSL_USER_SETTINGS;WOLFSSL_HAVE_MIN;WOLFSSL_HAVE_MAX;%(PreprocessorDefinitions) - - - Console - true - - - - - Level3 - - - MaxSpeed - true - true - .;../../lib/wolfssl;../../include;%(AdditionalIncludeDirectories) - WOLFSSL_USER_SETTINGS;WOLFSSL_HAVE_MIN;WOLFSSL_HAVE_MAX;%(PreprocessorDefinitions) - - - Console - true - true - true - - - - - Level3 - - - MaxSpeed - true - true - .;../../lib/wolfssl;../../include;%(AdditionalIncludeDirectories) - WOLFSSL_USER_SETTINGS;WOLFSSL_HAVE_MIN;WOLFSSL_HAVE_MAX;%(PreprocessorDefinitions) - - - Console - true - true - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tools/keytools/wolfBootSignTool.vcxproj b/tools/keytools/wolfBootSignTool.vcxproj deleted file mode 100755 index 084882f016..0000000000 --- a/tools/keytools/wolfBootSignTool.vcxproj +++ /dev/null @@ -1,198 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - {0E5B9C81-CA2B-47CA-BA83-074078CF3393} - Win32Proj - wolfBootSignTool - 10.0 - - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - sign - $(Platform)\$(Configuration)\$(ProjectName)\ - - - true - sign - $(Platform)\$(Configuration)\$(ProjectName)\ - - - false - sign - $(Platform)\$(Configuration)\$(ProjectName)\ - - - false - sign - $(Platform)\$(Configuration)\$(ProjectName)\ - - - - - - Level3 - Disabled - WOLFSSL_USER_SETTINGS;DELTA_UPDATES;WOLFSSL_HAVE_MIN;WOLFSSL_HAVE_MAX;%(PreprocessorDefinitions) - .;../../lib/wolfssl;../../include;%(AdditionalIncludeDirectories) - - - Console - true - - - - - - - Level3 - Disabled - WOLFSSL_USER_SETTINGS;DELTA_UPDATES;WOLFSSL_HAVE_MIN;WOLFSSL_HAVE_MAX;%(PreprocessorDefinitions) - .;../../lib/wolfssl;../../include;%(AdditionalIncludeDirectories) - - - Console - true - - - - - Level3 - - - MaxSpeed - true - true - WOLFSSL_USER_SETTINGS;DELTA_UPDATES;WOLFSSL_HAVE_MIN;WOLFSSL_HAVE_MAX;%(PreprocessorDefinitions) - .;../../lib/wolfssl;../../include;%(AdditionalIncludeDirectories) - - - Console - true - true - true - - - - - Level3 - - - MaxSpeed - true - true - WOLFSSL_USER_SETTINGS;DELTA_UPDATES;WOLFSSL_HAVE_MIN;WOLFSSL_HAVE_MAX;%(PreprocessorDefinitions) - .;../../lib/wolfssl;../../include;%(AdditionalIncludeDirectories) - - - Console - true - true - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ..\..\lib\wolfssl;..\..\include;..\..\include;.;%(AdditionalIncludeDirectories) - ..\..\lib\wolfssl;..\..\include;.;%(AdditionalIncludeDirectories) - .;..\..\lib\wolfssl;..\..\include;%(AdditionalIncludeDirectories) - .;..\..\lib\wolfssl;..\..\include;%(AdditionalIncludeDirectories) - - - - - - From 25ad87e0ebf72a72fc49ea34ce3ca278ac94172b Mon Sep 17 00:00:00 2001 From: gojimmypi Date: Sat, 22 Nov 2025 12:16:18 -0800 Subject: [PATCH 2/2] Remove Keystore File Check per https://github.com/wolfSSL/wolfBoot/pull/628/ --- .github/workflows/test-visual-studio.yml | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/.github/workflows/test-visual-studio.yml b/.github/workflows/test-visual-studio.yml index 1e72f99ad7..56db569fbf 100644 --- a/.github/workflows/test-visual-studio.yml +++ b/.github/workflows/test-visual-studio.yml @@ -203,24 +203,6 @@ jobs: echo test_v1_signed.bin file: dir test_v1_signed.bin /s - - name: DOS Keystore File Check - shell: cmd - working-directory: .\ - run: | - :: # Run a script to check for keystore files - echo Running .\tools\scripts\keystore_file_check.bat - - .\tools\scripts\keystore_file_check.bat - - - name: Bash Keystore File Check - shell: bash - working-directory: .\ - run: | - # Run a script to re-check for keystore files using bash (just to test scripts) - echo "Running ./tools/scripts/keystore_file_check.sh" - - ./tools/scripts/keystore_file_check.sh - # Step 3 Build Test tool, then run it - name: Build Library Test test-lib.exe shell: cmd