Skip to content

Commit d1de3ee

Browse files
committed
Visual Studio Improvements, Introduce wolfBootTestLib
1 parent a8afa74 commit d1de3ee

File tree

12 files changed

+828
-16
lines changed

12 files changed

+828
-16
lines changed
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
name: wolfBoot Visual Studio
2+
3+
on:
4+
push:
5+
# TODO: branches: [ 'master', 'main', 'release/**' ]
6+
branches: [ '*' ]
7+
pull_request:
8+
branches: [ '*' ]
9+
10+
jobs:
11+
build:
12+
name: Visual Studio Keytools Tests
13+
runs-on: windows-latest
14+
15+
env:
16+
CONFIG: Debug
17+
PLATFORM: x64
18+
ASYM: ecc256
19+
HASH: sha256
20+
21+
steps:
22+
# Adds MSBuild to PATH
23+
- uses: microsoft/setup-msbuild@v2
24+
with:
25+
msbuild-architecture: x64
26+
27+
- name: Checkout (with submodules)
28+
uses: actions/checkout@v4
29+
with:
30+
submodules: true
31+
32+
- name: Fetch test target.h
33+
shell: cmd
34+
working-directory: .\
35+
run: |
36+
:: Ensure there's a target.h
37+
38+
echo Current directory:
39+
echo %cd%
40+
41+
:: echo Copying tools\unit-tests\target.h to src\target.h
42+
43+
:: copy /Y tools\unit-tests\target.h src\target.h
44+
45+
echo Copying tools\unit-tests\target.h to include\target.h
46+
47+
copy /Y tools\unit-tests\target.h include\target.h
48+
49+
# Step 1 Build keygen, then run it
50+
- name: Build KeygenTool keygen.exe
51+
shell: cmd
52+
working-directory: .\
53+
run: |
54+
echo Current directory:
55+
echo %cd%
56+
57+
pushd tools\keytools\
58+
59+
msbuild wolfBootKeygenTool.vcxproj ^
60+
/t:Rebuild ^
61+
/m ^
62+
/p:Configuration=%CONFIG% ^
63+
/p:Platform=%PLATFORM% ^
64+
/p:PreferredToolArchitecture=x64 ^
65+
/v:m
66+
67+
popd
68+
69+
- name: Run KeygenTool keygen.exe
70+
shell: cmd
71+
working-directory: .\
72+
run: |
73+
:: Run keygen.exe
74+
75+
echo Current directory:
76+
echo %cd%
77+
78+
.\tools\keytools\%PLATFORM%\%CONFIG%\keygen.exe --ecc256 -g wolfboot_signing_private_key.der
79+
if errorlevel 1 (
80+
echo keygen.exe failed with ERRORLEVEL %ERRORLEVEL%
81+
exit /b %ERRORLEVEL%
82+
)
83+
84+
echo "wolfboot_signing_private_key.der file:"
85+
dir wolfboot_signing_private_key.der /s
86+
87+
echo "keystore.c file:"
88+
dir keystore.c /s
89+
90+
# Step 2 Build signing tool, then run it
91+
- name: Build SignTool sign.exe
92+
shell: cmd
93+
working-directory: .\
94+
run: |
95+
pushd tools\keytools\
96+
97+
msbuild wolfBootSignTool.vcxproj ^
98+
/t:Rebuild ^
99+
/m ^
100+
/p:Configuration=%CONFIG% ^
101+
/p:Platform=%PLATFORM% ^
102+
/p:PreferredToolArchitecture=x64 ^
103+
/v:m
104+
105+
popd
106+
107+
- name: Create a file to sign
108+
shell: cmd
109+
working-directory: .\
110+
run: |
111+
:: Create a test.bin file
112+
113+
echo Creating a new test.bin
114+
echo "Test" > test.bin
115+
116+
- name: Run SignTool sign.exe
117+
shell: cmd
118+
working-directory: .\
119+
run: |
120+
:: Run sign.exe
121+
122+
echo Current directory:
123+
echo %cd%
124+
125+
echo Running .\tools\keytools\%PLATFORM%\%CONFIG%\sign.exe --%ASYM% --%HASH% test.bin wolfboot_signing_private_key.der 1
126+
127+
.\tools\keytools\%PLATFORM%\%CONFIG%\sign.exe --%ASYM% --%HASH% test.bin wolfboot_signing_private_key.der 1
128+
129+
if errorlevel 1 (
130+
echo sign.exe failed with ERRORLEVEL %ERRORLEVEL%
131+
exit /b %ERRORLEVEL%
132+
)
133+
134+
echo wolfboot_signing_private_key.der file:
135+
dir wolfboot_signing_private_key.der /s
136+
137+
echo "keystore.c file:"
138+
dir keystore.c /s
139+
140+
echo test.bin file:
141+
dir test.bin /s
142+
143+
echo test_v1_signed.bin file:
144+
dir test_v1_signed.bin /s
145+
146+
# Step 3 Build Test tool, then run it
147+
- name: Build Library Test test-lib.exe
148+
shell: cmd
149+
working-directory: .\
150+
run: |
151+
pushd tools\keytools\
152+
153+
msbuild wolfBootTestLib.vcxproj ^
154+
/t:Rebuild ^
155+
/m ^
156+
/p:Configuration=%CONFIG% ^
157+
/p:Platform=%PLATFORM% ^
158+
/p:PreferredToolArchitecture=x64 ^
159+
/v:m
160+
161+
popd
162+
163+
- name: Run Library Test test-lib.exe
164+
shell: cmd
165+
working-directory: .\
166+
run: |
167+
:: Run sign.exe
168+
169+
echo Current directory:
170+
echo %cd%
171+
172+
:: A missing target.h is a common build failure on GitHub.
173+
:: See above where we copy one from [WOLFBOOT_ROOT]\tools\unit-tests\
174+
:: echo Where is the target.h?
175+
:: dir target.h /s
176+
177+
dir test_v1_signed.bin /s
178+
179+
echo Running .\tools\keytools\%PLATFORM%\%CONFIG%\test-lib.exe .\test_v1_signed.bin
180+
181+
if errorlevel 1 (
182+
echo test-lib.exe failed with ERRORLEVEL %ERRORLEVEL%
183+
exit /b %ERRORLEVEL%
184+
)
185+
186+
.\tools\keytools\%PLATFORM%\%CONFIG%\test-lib.exe .\test_v1_signed.bin
187+
188+
echo Done!

hal/library.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@
2424
#include <stdint.h>
2525
#include <string.h>
2626

27+
#ifdef _WIN32
28+
#include <io.h>
29+
#define HAVE_MMAP 0
30+
#define ftruncate(fd, len) _chsize(fd, len)
31+
static inline int fp_truncate(FILE* f, long len)
32+
{
33+
int fd;
34+
if (f == NULL)
35+
return -1;
36+
fd = _fileno(f);
37+
return _chsize(fd, len);
38+
}
39+
#define PRINTF_ENABLED
40+
#else
2741
#if 1 /* for desktop testing */
2842
#define HAVE_UNISTD_H
2943
#define PRINTF_ENABLED
@@ -37,6 +51,7 @@
3751
#else
3852
#define exit(x) while(1);
3953
#endif
54+
#endif
4055

4156
#include "image.h"
4257
#include "printf.h"
@@ -77,15 +92,16 @@ void hal_prepare_boot(void)
7792
return;
7893
}
7994

80-
int do_boot(uint32_t* v)
81-
{
82-
wolfBoot_printf("booting %p"
95+
8396
#ifdef HAVE_UNISTD_H
84-
"(actually exiting)"
97+
#define BOOT_SUFFIX " (actually exiting)"
8598
#else
86-
"(actually spin loop)"
99+
#define BOOT_SUFFIX " (actually spin loop)"
87100
#endif
88-
"\n", v);
101+
102+
int do_boot(uint32_t* v)
103+
{
104+
wolfBoot_printf("booting %p" BOOT_SUFFIX "\n", v);
89105
exit(0);
90106
}
91107

include/user_settings.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@
2525
#ifndef _WOLFBOOT_USER_SETTINGS_H_
2626
#define _WOLFBOOT_USER_SETTINGS_H_
2727

28+
#if defined(_MSC_VER)
29+
/* MSVC and clang-cl both define _MSC_VER */
30+
#ifndef WOLFSSL_HAVE_MIN
31+
#define WOLFSSL_HAVE_MIN
32+
#endif
33+
#ifndef WOLFSSL_HAVE_MAX
34+
#define WOLFSSL_HAVE_MAX
35+
#endif
36+
37+
/* Really keep Windows headers from redefining min/max */
38+
#ifndef NOMINMAX
39+
#define NOMINMAX 1
40+
#endif
41+
#endif
42+
2843
#ifdef WOLFBOOT_PKCS11_APP
2944
# include "test-app/wcs/user_settings.h"
3045
#else
@@ -330,7 +345,9 @@ extern int tolower(int c);
330345

331346
/* SP Math needs to understand long long */
332347
# ifndef ULLONG_MAX
333-
# define ULLONG_MAX 18446744073709551615ULL
348+
# ifndef _MSC_VER
349+
# define ULLONG_MAX 18446744073709551615ULL
350+
# endif
334351
# endif
335352
#endif
336353

src/image.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@
5353
#endif
5454

5555
/* Globals */
56+
#ifdef _MSC_VER
57+
static XALIGNED(4) uint8_t digest[WOLFBOOT_SHA_DIGEST_SIZE];
58+
#else
5659
static uint8_t digest[WOLFBOOT_SHA_DIGEST_SIZE] XALIGNED(4);
60+
#endif
5761

5862
#if defined(WOLFBOOT_CERT_CHAIN_VERIFY) && \
5963
(defined(WOLFBOOT_ENABLE_WOLFHSM_CLIENT) || \

0 commit comments

Comments
 (0)