Grow largest frame length to 512 bytes

This commit is contained in:
Daniel Lublin 2023-02-18 16:16:46 +01:00
parent 2e2ca04ab7
commit 8fd0fca967
No known key found for this signature in database
GPG Key ID: 75BD0FEB8D3E7830
5 changed files with 33 additions and 31 deletions

View File

@ -125,12 +125,12 @@ The bits in the command header byte should be interpreted as:
0. 1 byte 0. 1 byte
1. 4 bytes 1. 4 bytes
2. 32 bytes 2. 32 bytes
3. 128 bytes 3. 512 bytes
Note that the number of bytes indicated by the command data length field Note that the number of bytes indicated by the command data length field
does **not** include the command header byte. This means that a complete does **not** include the command header byte. This means that a complete
command frame, with a header indicating a data length of 128 bytes, is command frame, with a header indicating a data length of 512 bytes, is
129 bytes in length. 512+1 bytes in length.
Note that the host sets the frame ID tag. The ID tag in a given command Note that the host sets the frame ID tag. The ID tag in a given command
MUST be preserved in the corresponding response to the command. MUST be preserved in the corresponding response to the command.
@ -148,7 +148,7 @@ Some examples to clarify endpoints and commands:
data. The single byte could indicate action such as reading from the data. The single byte could indicate action such as reading from the
TRNG or resetting the application_fpga. TRNG or resetting the application_fpga.
* 0x13: A command to the FW in the application_fpga with 128 bytes of * 0x13: A command to the FW in the application_fpga with 512 bytes of
data. The data could for example be parts of an application binary to data. The data could for example be parts of an application binary to
be loaded into the program memory. be loaded into the program memory.
@ -179,13 +179,13 @@ The bits in the response header byte should be interpreted as:
0. 1 byte 0. 1 byte
1. 4 bytes 1. 4 bytes
2. 32 bytes 2. 32 bytes
3. 128 bytes 3. 512 bytes
Note that the number of bytes indicated by the response data length field Note that the number of bytes indicated by the response data length field
does **not** include the response header byte. This means that a complete does **not** include the response header byte. This means that a complete
response frame, with a header indicating a data length of 128 bytes, is response frame, with a header indicating a data length of 512 bytes, is
129 bytes in length. 512+1 bytes in length.
Note that the ID in a response MUST be the same ID as was present in the Note that the ID in a response MUST be the same ID as was present in the
header of the command being responded to. header of the command being responded to.
@ -205,7 +205,7 @@ less available for the "payload" of the response.
responds with a single byte of data. responds with a single byte of data.
* 0x1b: A successful command to the application running in the * 0x1b: A successful command to the application running in the
application_fpga. The response contains 128 bytes of data, for example application_fpga. The response contains 512 bytes of data, for example
an EdDSA Ed25519 signature. an EdDSA Ed25519 signature.

View File

@ -248,6 +248,7 @@ The commands look like this:
| *name* | *size (bytes)* | *comment* | | *name* | *size (bytes)* | *comment* |
|------------------|----------------|------------------------------------------| |------------------|----------------|------------------------------------------|
| Header | 1 | Framing protocol header including length | | Header | 1 | Framing protocol header including length |
| | | of the rest of the frame |
| Command/Response | 1 | Any of the below commands or responses | | Command/Response | 1 | Any of the below commands or responses |
| Data | n | Any additional data | | Data | n | Any additional data |
@ -294,10 +295,11 @@ Response to `FW_CMD_LOAD_APP`
| *name* | *size (bytes)* | *comment* | | *name* | *size (bytes)* | *comment* |
|--------|----------------|---------------------| |--------|----------------|---------------------|
| data | 127 | Raw binary app data | | data | 511 | Raw binary app data |
Load 127 bytes of raw app binary into device RAM. Should be sent Load 511 bytes of raw app binary into device RAM. Should be sent
consecutively over the complete raw binary. consecutively over the complete raw binary. (512 == largest frame
length minus the command byte).
#### `FW_RSP_LOAD_APP_DATA` (0x06) #### `FW_RSP_LOAD_APP_DATA` (0x06)
@ -362,9 +364,9 @@ host <-
``` ```
host -> host ->
u8 CMD[1 + 128]; u8 CMD[1 + 512];
CMD[0].len = 128 // command frame format CMD[0].len = 512 // command frame format
CMD[1] = 0x03 // FW_CMD_LOAD_APP CMD[1] = 0x03 // FW_CMD_LOAD_APP
CMD[2..6] = APP_SIZE CMD[2..6] = APP_SIZE
@ -383,14 +385,14 @@ host <-
RSP[3..] = 0 RSP[3..] = 0
repeat ceil(APP_SIZE / 127) times: repeat ceil(APP_SIZE / 511) times:
host -> host ->
u8 CMD[1 + 128]; u8 CMD[1 + 512];
CMD[0].len = 128 // command frame format CMD[0].len = 512 // command frame format
CMD[1] = 0x05 // FW_CMD_LOAD_APP_DATA CMD[1] = 0x05 // FW_CMD_LOAD_APP_DATA
CMD[2..] = APP_DATA (127 bytes of app data, pad with zeros) CMD[2..] = APP_DATA (511 bytes of app data, pad with zeros)
host <- host <-
u8 RSP[1 + 4] u8 RSP[1 + 4]
@ -407,9 +409,9 @@ Except response from last chunk of app data which is:
``` ```
host <- host <-
u8 RSP[1 + 4] u8 RSP[1 + 512]
RSP[0].len = 128 // command frame format RSP[0].len = 512 // command frame format
RSP[1] = 0x07 // FW_RSP_LOAD_APP_DATA_READY RSP[1] = 0x07 // FW_RSP_LOAD_APP_DATA_READY
RSP[2] = STATUS RSP[2] = STATUS

View File

@ -291,7 +291,7 @@ int main()
case FW_CMD_LOAD_APP: case FW_CMD_LOAD_APP:
htif_puts("cmd: load-app(size, uss)\n"); htif_puts("cmd: load-app(size, uss)\n");
if (hdr.len != 128) { if (hdr.len != 512) {
// Bad length // Bad length
rsp[0] = STATUS_BAD; rsp[0] = STATUS_BAD;
fwreply(hdr, FW_RSP_LOAD_APP, rsp); fwreply(hdr, FW_RSP_LOAD_APP, rsp);
@ -333,7 +333,7 @@ int main()
case FW_CMD_LOAD_APP_DATA: case FW_CMD_LOAD_APP_DATA:
htif_puts("cmd: load-app-data\n"); htif_puts("cmd: load-app-data\n");
if (hdr.len != 128 || (state != FW_STATE_INIT_LOADING && if (hdr.len != 512 || (state != FW_STATE_INIT_LOADING &&
state != FW_STATE_LOADING)) { state != FW_STATE_LOADING)) {
// Bad cmd length or state // Bad cmd length or state
rsp[0] = STATUS_BAD; rsp[0] = STATUS_BAD;
@ -342,8 +342,8 @@ int main()
} }
int nbytes; int nbytes;
if (left > 127) { if (left > (512 - 1)) {
nbytes = 127; nbytes = 512 - 1;
} else { } else {
nbytes = left; nbytes = left;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2022 - Tillitis AB * Copyright (C) 2022, 2023 - Tillitis AB
* SPDX-License-Identifier: GPL-2.0-only * SPDX-License-Identifier: GPL-2.0-only
*/ */
@ -47,8 +47,8 @@ int parseframe(uint8_t b, struct frame_header *hdr)
case LEN_32: case LEN_32:
hdr->len = 32; hdr->len = 32;
break; break;
case LEN_128: case LEN_512:
hdr->len = 128; hdr->len = 512;
break; break;
default: default:
// Unknown length // Unknown length
@ -82,8 +82,8 @@ void fwreply(struct frame_header hdr, enum fwcmd rspcode, uint8_t *buf)
break; break;
case FW_RSP_LOAD_APP_DATA_READY: case FW_RSP_LOAD_APP_DATA_READY:
len = LEN_128; len = LEN_512;
nbytes = 128; nbytes = 512;
break; break;
case FW_RSP_GET_UDI: case FW_RSP_GET_UDI:

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2022 - Tillitis AB * Copyright (C) 2022, 2023 - Tillitis AB
* SPDX-License-Identifier: GPL-2.0-only * SPDX-License-Identifier: GPL-2.0-only
*/ */
@ -19,10 +19,10 @@ enum cmdlen {
LEN_1, LEN_1,
LEN_4, LEN_4,
LEN_32, LEN_32,
LEN_128 LEN_512
}; };
#define CMDLEN_MAXBYTES 128 #define CMDLEN_MAXBYTES 512
// clang-format off // clang-format off
enum fwcmd { enum fwcmd {