mirror of
https://github.com/tillitis/tillitis-key1.git
synced 2024-12-23 14:39:29 -05:00
Grow largest frame length to 512 bytes
This commit is contained in:
parent
2e2ca04ab7
commit
8fd0fca967
@ -125,12 +125,12 @@ The bits in the command header byte should be interpreted as:
|
||||
0. 1 byte
|
||||
1. 4 bytes
|
||||
2. 32 bytes
|
||||
3. 128 bytes
|
||||
3. 512 bytes
|
||||
|
||||
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
|
||||
command frame, with a header indicating a data length of 128 bytes, is
|
||||
129 bytes in length.
|
||||
command frame, with a header indicating a data length of 512 bytes, is
|
||||
512+1 bytes in length.
|
||||
|
||||
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.
|
||||
@ -148,7 +148,7 @@ Some examples to clarify endpoints and commands:
|
||||
data. The single byte could indicate action such as reading from the
|
||||
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
|
||||
be loaded into the program memory.
|
||||
|
||||
@ -179,13 +179,13 @@ The bits in the response header byte should be interpreted as:
|
||||
0. 1 byte
|
||||
1. 4 bytes
|
||||
2. 32 bytes
|
||||
3. 128 bytes
|
||||
3. 512 bytes
|
||||
|
||||
|
||||
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
|
||||
response frame, with a header indicating a data length of 128 bytes, is
|
||||
129 bytes in length.
|
||||
response frame, with a header indicating a data length of 512 bytes, is
|
||||
512+1 bytes in length.
|
||||
|
||||
Note that the ID in a response MUST be the same ID as was present in the
|
||||
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.
|
||||
|
||||
* 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.
|
||||
|
||||
|
||||
|
@ -248,6 +248,7 @@ The commands look like this:
|
||||
| *name* | *size (bytes)* | *comment* |
|
||||
|------------------|----------------|------------------------------------------|
|
||||
| Header | 1 | Framing protocol header including length |
|
||||
| | | of the rest of the frame |
|
||||
| Command/Response | 1 | Any of the below commands or responses |
|
||||
| Data | n | Any additional data |
|
||||
|
||||
@ -294,10 +295,11 @@ Response to `FW_CMD_LOAD_APP`
|
||||
|
||||
| *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
|
||||
consecutively over the complete raw binary.
|
||||
Load 511 bytes of raw app binary into device RAM. Should be sent
|
||||
consecutively over the complete raw binary. (512 == largest frame
|
||||
length minus the command byte).
|
||||
|
||||
#### `FW_RSP_LOAD_APP_DATA` (0x06)
|
||||
|
||||
@ -362,9 +364,9 @@ 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[2..6] = APP_SIZE
|
||||
@ -383,14 +385,14 @@ host <-
|
||||
|
||||
RSP[3..] = 0
|
||||
|
||||
repeat ceil(APP_SIZE / 127) times:
|
||||
repeat ceil(APP_SIZE / 511) times:
|
||||
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[2..] = APP_DATA (127 bytes of app data, pad with zeros)
|
||||
CMD[2..] = APP_DATA (511 bytes of app data, pad with zeros)
|
||||
|
||||
host <-
|
||||
u8 RSP[1 + 4]
|
||||
@ -407,9 +409,9 @@ Except response from last chunk of app data which is:
|
||||
|
||||
```
|
||||
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[2] = STATUS
|
||||
|
@ -291,7 +291,7 @@ int main()
|
||||
|
||||
case FW_CMD_LOAD_APP:
|
||||
htif_puts("cmd: load-app(size, uss)\n");
|
||||
if (hdr.len != 128) {
|
||||
if (hdr.len != 512) {
|
||||
// Bad length
|
||||
rsp[0] = STATUS_BAD;
|
||||
fwreply(hdr, FW_RSP_LOAD_APP, rsp);
|
||||
@ -333,7 +333,7 @@ int main()
|
||||
|
||||
case FW_CMD_LOAD_APP_DATA:
|
||||
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)) {
|
||||
// Bad cmd length or state
|
||||
rsp[0] = STATUS_BAD;
|
||||
@ -342,8 +342,8 @@ int main()
|
||||
}
|
||||
|
||||
int nbytes;
|
||||
if (left > 127) {
|
||||
nbytes = 127;
|
||||
if (left > (512 - 1)) {
|
||||
nbytes = 512 - 1;
|
||||
} else {
|
||||
nbytes = left;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2022 - Tillitis AB
|
||||
* Copyright (C) 2022, 2023 - Tillitis AB
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*/
|
||||
|
||||
@ -47,8 +47,8 @@ int parseframe(uint8_t b, struct frame_header *hdr)
|
||||
case LEN_32:
|
||||
hdr->len = 32;
|
||||
break;
|
||||
case LEN_128:
|
||||
hdr->len = 128;
|
||||
case LEN_512:
|
||||
hdr->len = 512;
|
||||
break;
|
||||
default:
|
||||
// Unknown length
|
||||
@ -82,8 +82,8 @@ void fwreply(struct frame_header hdr, enum fwcmd rspcode, uint8_t *buf)
|
||||
break;
|
||||
|
||||
case FW_RSP_LOAD_APP_DATA_READY:
|
||||
len = LEN_128;
|
||||
nbytes = 128;
|
||||
len = LEN_512;
|
||||
nbytes = 512;
|
||||
break;
|
||||
|
||||
case FW_RSP_GET_UDI:
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2022 - Tillitis AB
|
||||
* Copyright (C) 2022, 2023 - Tillitis AB
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*/
|
||||
|
||||
@ -19,10 +19,10 @@ enum cmdlen {
|
||||
LEN_1,
|
||||
LEN_4,
|
||||
LEN_32,
|
||||
LEN_128
|
||||
LEN_512
|
||||
};
|
||||
|
||||
#define CMDLEN_MAXBYTES 128
|
||||
#define CMDLEN_MAXBYTES 512
|
||||
|
||||
// clang-format off
|
||||
enum fwcmd {
|
||||
|
Loading…
Reference in New Issue
Block a user