Skip to content

Commit 6c8aafe

Browse files
committed
Remove keytools dependency on IMAGE_HEADER_SIZE.
- Added getenv() to override the value at runtime - Removed doc on old python tools
1 parent bf4c801 commit 6c8aafe

File tree

3 files changed

+34
-41
lines changed

3 files changed

+34
-41
lines changed

docs/Signing.md

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,18 @@
44
server) environment to manage wolfBoot private keys and sign the initial
55
firmware and all the updates for the target.
66

7-
## C or Python
8-
9-
The tools are distributed in two versions, using the same command line syntax,
10-
for portability reasons.
11-
12-
By default, C keytools are compiled. The makefiles and scripts in this
13-
repository will use the C tools.
14-
15-
### C Key Tools
7+
## C Key Tools
168

179
A standalone C version of the key tools is available in: `./tools/keytools`.
1810

1911
These can be built in `tools/keytools` using `make` or from the wolfBoot root using `make keytools`.
2012

21-
If the C version of the key tools exists they will be used by wolfBoot's makefile and scripts.
22-
2313
#### Windows Visual Studio
2414

2515
Use the `wolfBootSignTool.vcxproj` Visual Studio project to build the `sign.exe` and `keygen.exe` tools for use on Windows.
2616

2717
If you see any error about missing `target.h` this is a generated file based on your .config using the make process. It is needed for `WOLFBOOT_SECTOR_SIZE` used in delta updates.
2818

29-
### Python key tools
30-
31-
**Please note that the Python tools are deprecated and will be removed in future versions.**
32-
33-
In order to use the python key tools, ensure that the `wolfcrypt` package is
34-
installed in your python environment. In most systems it's sufficient to run a
35-
command similar to:
36-
37-
`pip install wolfcrypt`
38-
39-
to ensure that the dependencies are met.
4019

4120
## Command Line Usage
4221

@@ -78,6 +57,19 @@ Usage: `sign [OPTIONS] IMAGE.BIN KEY.DER VERSION`
7857
`VERSION`: The version associated with this signed software
7958
`OPTIONS`: Zero or more options, described below
8059

60+
#### Image header size
61+
62+
By default, the manifest header size used by SIGN tool depends on the ideal
63+
value for the configuration chosen. In some cases however, it is necessary to use
64+
a different value than the default. To override the `IMAGE_HEADER_SIZE` value,
65+
set an environment variable with the same name and the desired value, via `setenv`,
66+
`export`, or simply inlining it with the sign command:
67+
68+
```
69+
IMAGE_HEADER_SIZE=2048 sign [OPTIONS] IMAGE.BIN KEY.DER VERSION
70+
```
71+
72+
8173
#### Public key signature options
8274

8375
If none of the following arguments is given, the tool will try to guess the key

tools/keytools/Makefile

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,6 @@ else
7979
CFLAGS+=$(OPTIMIZE)
8080
endif
8181

82-
ifeq ($(IMAGE_HEADER_SIZE),)
83-
IMAGE_HEADER_SIZE=256
84-
endif
85-
86-
CFLAGS+=-DIMAGE_HEADER_SIZE=$(IMAGE_HEADER_SIZE)
8782
CFLAGS+=-DDELTA_UPDATES
8883

8984
ifneq ($(RENESAS_KEY),)

tools/keytools/sign.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,6 @@ static inline int fp_truncate(FILE *f, size_t len)
147147
#define PATH_MAX 256
148148
#endif
149149

150-
#ifndef IMAGE_HEADER_SIZE
151-
#define IMAGE_HEADER_SIZE 256
152-
#endif
153150

154151
#define WOLFBOOT_MAGIC 0x464C4F57 /* WOLF */
155152

@@ -314,7 +311,6 @@ static struct cmd_options CMD = {
314311
.sign = SIGN_AUTO,
315312
.encrypt = ENC_OFF,
316313
.hash_algo = HASH_SHA256,
317-
.header_sz = IMAGE_HEADER_SIZE,
318314
.partition_id = HDR_IMG_TYPE_APP,
319315
.hybrid = 0
320316
};
@@ -324,7 +320,7 @@ static uint16_t sign_tool_find_header(uint8_t *haystack, uint16_t type, uint8_t
324320
uint8_t *p = haystack;
325321
uint16_t len, htype;
326322
const volatile uint8_t *max_p = (haystack - IMAGE_HEADER_OFFSET) +
327-
IMAGE_HEADER_SIZE;
323+
CMD.header_sz;
328324
*ptr = NULL;
329325
if (p > max_p) {
330326
fprintf(stderr, "Illegal address (too high)\n");
@@ -344,10 +340,10 @@ static uint16_t sign_tool_find_header(uint8_t *haystack, uint16_t type, uint8_t
344340

345341
len = p[2] | (p[3] << 8);
346342
/* check len */
347-
if ((4 + len) > (uint16_t)(IMAGE_HEADER_SIZE - IMAGE_HEADER_OFFSET)) {
343+
if ((4 + len) > (uint16_t)(CMD.header_sz - IMAGE_HEADER_OFFSET)) {
348344
fprintf(stderr, "This field is too large (bigger than the space available "
349345
"in the current header)\n");
350-
//fprintf(stderr, "%d %d %d\n", len, IMAGE_HEADER_SIZE, IMAGE_HEADER_OFFSET);
346+
//fprintf(stderr, "%d %d %d\n", len, CMD.header_sz, IMAGE_HEADER_OFFSET);
351347
break;
352348
}
353349
/* check max pointer */
@@ -923,13 +919,6 @@ static uint8_t *load_key(uint8_t **key_buffer, uint32_t *key_buffer_sz,
923919
goto failure;
924920
}
925921

926-
if (CMD.header_sz < IMAGE_HEADER_SIZE) {
927-
printf("image header size overridden by config value (%u bytes)\n", IMAGE_HEADER_SIZE);
928-
CMD.header_sz = IMAGE_HEADER_SIZE;
929-
} else {
930-
printf("image header size calculated at runtime (%u bytes)\n", CMD.header_sz);
931-
}
932-
933922
DEBUG_PRINT("Pubkey %d\n", *pubkey_sz);
934923
DEBUG_BUFFER(*pubkey, *pubkey_sz);
935924
return *key_buffer;
@@ -2112,6 +2101,8 @@ static void set_signature_sizes(int secondary)
21122101
{
21132102
uint32_t *sz = &CMD.signature_sz;
21142103
int *sign = &CMD.sign;
2104+
uint32_t suggested_sz = 0;
2105+
char *env_image_header_size;
21152106
if (secondary) {
21162107
sz = &CMD.secondary_signature_sz;
21172108
sign = &CMD.secondary_sign;
@@ -2261,6 +2252,18 @@ static void set_signature_sizes(int secondary)
22612252
*sz = sig_sz;
22622253
}
22632254
#endif /* WOLFSSL_WC_DILITHIUM */
2255+
2256+
env_image_header_size = getenv("IMAGE_HEADER_SIZE");
2257+
if (env_image_header_size) {
2258+
suggested_sz = atoi(env_image_header_size);
2259+
}
2260+
if (suggested_sz != 0) {
2261+
if (CMD.header_sz <= suggested_sz)
2262+
CMD.header_sz = suggested_sz;
2263+
else
2264+
printf("Environment variable IMAGE_HEADER_SIZE=%u overridden.\n", suggested_sz);
2265+
}
2266+
printf("Manifest header size: %u\n", CMD.header_sz);
22642267
}
22652268

22662269
int main(int argc, char** argv)
@@ -2291,6 +2294,9 @@ int main(int argc, char** argv)
22912294
exit(1);
22922295
}
22932296

2297+
/* Set initial manifest header size to a minimum default value */
2298+
CMD.header_sz = 256;
2299+
22942300
/* Parse Arguments */
22952301
for (i=1; i<argc; i++) {
22962302
if (strcmp(argv[i], "--no-sign") == 0) {

0 commit comments

Comments
 (0)