mirror of
https://github.com/tillitis/tillitis-key1.git
synced 2024-12-25 07:29:25 -05:00
Consistently set any new state and do break out of case/default
Signed-off-by: Daniel Lublin <daniel@lublin.se>
This commit is contained in:
parent
f9960de506
commit
2b9bfc0eff
@ -127,8 +127,9 @@ static void copy_name(uint8_t *buf, const size_t bufsiz, const uint32_t word)
|
|||||||
buf[3] = word;
|
buf[3] = word;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int initial_commands(const struct frame_header *hdr, const uint8_t *cmd,
|
static enum state initial_commands(const struct frame_header *hdr,
|
||||||
enum state state, struct context *ctx)
|
const uint8_t *cmd, enum state state,
|
||||||
|
struct context *ctx)
|
||||||
{
|
{
|
||||||
uint8_t rsp[CMDLEN_MAXBYTES] = {0};
|
uint8_t rsp[CMDLEN_MAXBYTES] = {0};
|
||||||
|
|
||||||
@ -137,7 +138,8 @@ static int initial_commands(const struct frame_header *hdr, const uint8_t *cmd,
|
|||||||
htif_puts("cmd: name-version\n");
|
htif_puts("cmd: name-version\n");
|
||||||
if (hdr->len != 1) {
|
if (hdr->len != 1) {
|
||||||
// Bad length
|
// Bad length
|
||||||
return FW_STATE_FAIL;
|
state = FW_STATE_FAIL;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
copy_name(rsp, CMDLEN_MAXBYTES, *name0);
|
copy_name(rsp, CMDLEN_MAXBYTES, *name0);
|
||||||
@ -147,8 +149,7 @@ static int initial_commands(const struct frame_header *hdr, const uint8_t *cmd,
|
|||||||
htif_hexdump(rsp, 12);
|
htif_hexdump(rsp, 12);
|
||||||
|
|
||||||
fwreply(*hdr, FW_RSP_NAME_VERSION, rsp);
|
fwreply(*hdr, FW_RSP_NAME_VERSION, rsp);
|
||||||
// state unchanged
|
// still initial state
|
||||||
return state;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FW_CMD_GET_UDI: {
|
case FW_CMD_GET_UDI: {
|
||||||
@ -157,16 +158,17 @@ static int initial_commands(const struct frame_header *hdr, const uint8_t *cmd,
|
|||||||
htif_puts("cmd: get-udi\n");
|
htif_puts("cmd: get-udi\n");
|
||||||
if (hdr->len != 1) {
|
if (hdr->len != 1) {
|
||||||
// Bad length
|
// Bad length
|
||||||
return FW_STATE_FAIL;
|
state = FW_STATE_FAIL;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
rsp[0] = STATUS_OK;
|
rsp[0] = STATUS_OK;
|
||||||
wordcpy_s(udi_words, 2, (void *)udi, 2);
|
wordcpy_s(udi_words, 2, (void *)udi, 2);
|
||||||
memcpy_s(&rsp[1], CMDLEN_MAXBYTES - 1, udi_words, 2 * 4);
|
memcpy_s(&rsp[1], CMDLEN_MAXBYTES - 1, udi_words, 2 * 4);
|
||||||
fwreply(*hdr, FW_RSP_GET_UDI, rsp);
|
fwreply(*hdr, FW_RSP_GET_UDI, rsp);
|
||||||
// state unchanged
|
// still initial state
|
||||||
return state;
|
break;
|
||||||
} break;
|
}
|
||||||
|
|
||||||
case FW_CMD_LOAD_APP: {
|
case FW_CMD_LOAD_APP: {
|
||||||
uint32_t local_app_size;
|
uint32_t local_app_size;
|
||||||
@ -174,7 +176,8 @@ static int initial_commands(const struct frame_header *hdr, const uint8_t *cmd,
|
|||||||
htif_puts("cmd: load-app(size, uss)\n");
|
htif_puts("cmd: load-app(size, uss)\n");
|
||||||
if (hdr->len != 512) {
|
if (hdr->len != 512) {
|
||||||
// Bad length
|
// Bad length
|
||||||
return FW_STATE_FAIL;
|
state = FW_STATE_FAIL;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// cmd[1..4] contains the size.
|
// cmd[1..4] contains the size.
|
||||||
@ -188,8 +191,8 @@ static int initial_commands(const struct frame_header *hdr, const uint8_t *cmd,
|
|||||||
if (local_app_size == 0 || local_app_size > TK1_APP_MAX_SIZE) {
|
if (local_app_size == 0 || local_app_size > TK1_APP_MAX_SIZE) {
|
||||||
rsp[0] = STATUS_BAD;
|
rsp[0] = STATUS_BAD;
|
||||||
fwreply(*hdr, FW_RSP_LOAD_APP, rsp);
|
fwreply(*hdr, FW_RSP_LOAD_APP, rsp);
|
||||||
|
// still initial state
|
||||||
return state;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
*app_size = local_app_size;
|
*app_size = local_app_size;
|
||||||
@ -211,20 +214,24 @@ static int initial_commands(const struct frame_header *hdr, const uint8_t *cmd,
|
|||||||
|
|
||||||
ctx->left = *app_size;
|
ctx->left = *app_size;
|
||||||
|
|
||||||
return FW_STATE_LOADING;
|
state = FW_STATE_LOADING;
|
||||||
} break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
htif_puts("Got unknown firmware cmd: 0x");
|
htif_puts("Got unknown firmware cmd: 0x");
|
||||||
htif_puthex(cmd[0]);
|
htif_puthex(cmd[0]);
|
||||||
htif_lf();
|
htif_lf();
|
||||||
|
state = FW_STATE_FAIL;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return FW_STATE_FAIL;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int loading_commands(const struct frame_header *hdr, const uint8_t *cmd,
|
static enum state loading_commands(const struct frame_header *hdr,
|
||||||
enum state state, struct context *ctx)
|
const uint8_t *cmd, enum state state,
|
||||||
|
struct context *ctx)
|
||||||
{
|
{
|
||||||
uint8_t rsp[CMDLEN_MAXBYTES] = {0};
|
uint8_t rsp[CMDLEN_MAXBYTES] = {0};
|
||||||
int nbytes;
|
int nbytes;
|
||||||
@ -234,7 +241,8 @@ static int loading_commands(const struct frame_header *hdr, const uint8_t *cmd,
|
|||||||
htif_puts("cmd: load-app-data\n");
|
htif_puts("cmd: load-app-data\n");
|
||||||
if (hdr->len != 512) {
|
if (hdr->len != 512) {
|
||||||
// Bad length
|
// Bad length
|
||||||
return FW_STATE_FAIL;
|
state = FW_STATE_FAIL;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->left > (512 - 1)) {
|
if (ctx->left > (512 - 1)) {
|
||||||
@ -267,18 +275,21 @@ static int loading_commands(const struct frame_header *hdr, const uint8_t *cmd,
|
|||||||
32);
|
32);
|
||||||
fwreply(*hdr, FW_RSP_LOAD_APP_DATA_READY, rsp);
|
fwreply(*hdr, FW_RSP_LOAD_APP_DATA_READY, rsp);
|
||||||
|
|
||||||
return FW_STATE_RUN;
|
state = FW_STATE_RUN;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
rsp[0] = STATUS_OK;
|
rsp[0] = STATUS_OK;
|
||||||
fwreply(*hdr, FW_RSP_LOAD_APP_DATA, rsp);
|
fwreply(*hdr, FW_RSP_LOAD_APP_DATA, rsp);
|
||||||
|
// still loading state
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
htif_puts("Got unknown firmware cmd: 0x");
|
htif_puts("Got unknown firmware cmd: 0x");
|
||||||
htif_puthex(cmd[0]);
|
htif_puthex(cmd[0]);
|
||||||
htif_lf();
|
htif_lf();
|
||||||
return FW_STATE_FAIL;
|
state = FW_STATE_FAIL;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
|
Loading…
Reference in New Issue
Block a user