You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/6-Utilities.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,9 +16,9 @@ This chapter describes the auxiliary tools that ship alongside the wolfHSM clien
16
16
17
17
## NVM Provisioning Tool
18
18
19
-
The NVM provisioning tool (`tools/whnvmtool/`) is a host-side utility that builds a pre-populated wolfHSM NVM image from a configuration file. It is intended for device provisioning: rather than having the server populate its NVM at runtime, the integrator describes the desired initial contents — a set of NVM objects and keys, each with its metadata ID, access permissions, flags, label, and a path to the binary payload — and the tool produces a single image file that can be programmed into the device's flash at manufacture or used in place to back a `whNvmFlash` provider in simulation. Currently the tool targets the `whNvmFlash` provider; the generated image is binary, and can be converted to Intel HEX with the standard `objcopy` workflow for use with automated programmers.
19
+
The NVM provisioning tool (`tools/whnvmtool/`) is a host-side utility that builds a pre-populated wolfHSM NVM image from a configuration file. It is intended for device provisioning: rather than having the server populate its NVM at runtime, the integrator describes the desired initial contents — a set of NVM objects and keys, each with its metadata ID, access permissions, flags, label, and a path to the binary payload — and the tool produces a single image file that can be programmed into the device's flash. Currently the tool targets the `whNvmFlash` provider. By default, the tool creates a contiguous binary image, but can also emit an Intel HEX file (`--hex`, with `--hex-base` and `--hex-align`) for use with automated programmers. In hex mode, the HEX file contains only the bytes actually programmed while building the image, leaving erased regions absent so flash programmers do not program the erased value.
20
20
21
-
Because the on-flash layout depends on build-time configuration, the tool must be compiled against the same wolfHSM version as the target server and with a matching `WOLFHSM_CFG_NVM_OBJECT_COUNT` and `WOLFHSM_CFG_NVM_FLASH_CRC16` setting, and the `--size` argument must match the server's `whNvmFlash` partition size. For the full configuration file schema, command-line options, hex conversion recipe, and test workflow, see [`tools/whnvmtool/README.md`](https://github.com/wolfSSL/wolfHSM/blob/main/tools/whnvmtool/README.md).
21
+
Because the on-flash layout depends on build-time configuration, the tool must be compiled against the same wolfHSM version as the target server and with a matching `WOLFHSM_CFG_NVM_OBJECT_COUNT` and `WOLFHSM_CFG_NVM_FLASH_CRC16` setting, and the `--size` argument must match the server's `whNvmFlash` partition size. For the full configuration file schema, command-line options, Intel HEX output details, and test workflow, see [`tools/whnvmtool/README.md`](https://github.com/wolfSSL/wolfHSM/blob/main/tools/whnvmtool/README.md).
-`--image[=<file>]`: Specifies the output NVM image file. If not provided, defaults to `whNvmImage.bin`.
20
20
-`--size <size>`: Sets the partition size for the NVM image. Can be specified in decimal or hexadecimal (with '0x' prefix).
21
21
-`--invert-erased-byte`: Inverts the erased byte value (default is 0xFF, this option changes it to 0x00).
22
+
-`--hex[=<file>]`: Additionally generates an Intel HEX file containing only the programmed bytes of the image (see [Generating an Intel HEX File](#generating-an-intel-hex-file)). If no file is given, defaults to `whNvmImage.hex`.
23
+
-`--hex-base <addr>`: Base address added to every record address in the Intel HEX file, corresponding to the address of the NVM partition in the device's memory map. Defaults to 0x0. Requires `--hex`.
24
+
-`--hex-align <n>`: Expands each Intel HEX record range to `n`-byte boundaries, for devices that program flash in multi-byte units. Defaults to 1. Requires `--hex`, and `--hex-base` must be a multiple of `n`.
22
25
-`--test`: Enables test mode. In this mode, the tool generates an intermediate file (`nvm_metadata.txt`) containing comma separated metadata ID/file path pairs, associating each object ID with the file path containing the object's original data. This option is used by the `whnvmtool` tests to verify the contents of the generated NVM image, and is not required for normal operation.
23
26
24
27
## Configuration File Schema
@@ -137,24 +140,25 @@ The generated NVM image is a binary file that can be used to initialize an insta
137
140
2. The partition size specified for the NVM image must match that of the server's `whNvmFlash` provider
138
141
3. If using a real flash implementation, the binary NVM image must be programmed to the correct address
139
142
140
-
### Generating a Hex File
143
+
### Generating an Intel HEX File
141
144
142
-
Users may find it useful to generate a hexfile to program the NVM image into device memory. This can be accomplished by using the `objcopy` utility to convert the generated NVM image to a hex file, making sure to specify the correct offset into the image for the start of the NVM partition. For example:
145
+
Passing `--hex[=<file>]` generates an Intel HEX version of the NVM image alongside the binary, ready to be loaded by a flash programmer:
The HEX file contains only the bytes actually programmed while building the image: the partition state, the used directory entries, and the object data.
152
+
153
+
-`--hex-base <addr>` sets the base address of the NVM partition in the device's memory map. Record addresses in the HEX file are the image offsets plus this value. Without it, records start at address 0x0.
154
+
-`--hex-align <n>` expands each record range outward to `n`-byte boundaries, padding with the surrounding image bytes. Use this when the target flash programs in multi-byte units (for example ECC words), so every emitted range covers whole program units. The base address must be a multiple of `n` for this to hold in the device address space, so the tool rejects a `--hex-base` that is not. The default of 1 emits exactly the programmed ranges, which are already multiples of the 8-byte wolfHSM flash unit.
149
155
150
-
-`<offset>` is the offset to the base address that will be applied to the generated hex file. Without this option, the offset is 0x0, so automated programming tools will attempt to load the hex file starting at address 0x0, which is likely not the desired behavior. The `<offset>` parameter should correspond to the base address of the NVM partition used by wolfHSM in the device's address space.
151
-
-`<input-file>` is the NVM image file generated by `whnvmtool`
152
-
-`<output-file>` is the name of the output hex file
156
+
Because only the bytes programmed during the current run are tracked, `--hex` requires building a fresh image: the tool exits with an error if the `--image` file already exists.
153
157
154
158
## Testing
155
159
156
160
Tests for `whnvmtool` can be run by invoking `make check` or `make test`. This will perform the following steps:
157
161
158
-
1. Invoke `whnvmtool` to generate an NVM image using an example configuration file, using the `--test` option to export the ID/data file pairs to a file
159
-
2. Run the negative test script `test/test_invalid_input.sh`, which verifies that invalid configuration files (out-of-range clientId, keyId, SHE slot, counter, or flags, or the volatile `RAM_KEY` slot) and bad key files (wrong size or missing) cause the tool to exit with an error instead of producing an incomplete image
160
-
3. Build and run a test program `test/test_whnvmtool.c`, which loads the generated NVM image and verifies the contents of the objects and keys using the exported ID/data file pairs. The compatibility of the generated image is verified by loading the image into two `whNvmFlash` providers: the POSIX port file-based NVM flash file simulator (`port/posix/posix_flash_file.c`) and the RAM-based NVM flash simulator (`src/wh_flash_ramsim.c`).
162
+
1. Invoke `whnvmtool` to generate NVM images using an example configuration file, using the `--test` option to export the ID/data file pairs to a file and the `--hex` options to generate Intel HEX output for both erased byte values, plus a third image whose alignment is large enough that its expanded record ranges overlap and must be merged
163
+
2. Run the negative test script `test/test_invalid_input.sh`, which verifies that invalid configuration files (out-of-range clientId, keyId, SHE slot, counter, or flags, or the volatile `RAM_KEY` slot), bad key files (wrong size or missing), and invalid hex option combinations cause the tool to exit with an error instead of producing an incomplete image
164
+
3. Build and run a test program `test/test_whnvmtool.c`, which loads the generated NVM image and verifies the contents of the objects and keys using the exported ID/data file pairs. The compatibility of the generated image is verified by loading the image into two `whNvmFlash` providers: the POSIX port file-based NVM flash file simulator (`port/posix/posix_flash_file.c`) and the RAM-based NVM flash simulator (`src/wh_flash_ramsim.c`). The test program also parses the generated Intel HEX files and verifies that overlaying their records on an erased image reproduces the binary image exactly, that no record touches a region left erased (such as the inactive partition), that bytes programmed with the erased value are still present, that record ranges honor the requested base address and alignment, and that no two records cover the same byte.
0 commit comments