Skip to content

Commit c0606dc

Browse files
jgriffithsDaniel Newton
andcommitted
usb: refactor usb handling
- Simplify the USB caller interface down to start() and stop(). - Simplify the internal state machine to a single loop - Remove multiple synchronization primatives in favour of a single mutex - Prevent freezing when JTAG and logging are both enabled - Remove UI-based logging support - Load the next data block while the current one is processing - Time-out if ota_data messages are not forthcoming - Reduce stack usage Co-authored-by: Daniel Newton <[email protected]>
1 parent 61690c6 commit c0606dc

File tree

4 files changed

+317
-411
lines changed

4 files changed

+317
-411
lines changed

main/process/ota_util.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
#include "../jade_assert.h"
55
#include "../jade_wally_verify.h"
66
#include "../qrmode.h"
7+
#include "../utils/malloc_ext.h"
78
#include "ota_defines.h"
9+
#include "process_utils.h"
810

911
#include <ctype.h>
1012
#include <esp_efuse.h>
@@ -110,6 +112,7 @@ void handle_in_bin_data(void* ctx, uint8_t* data, const size_t rawsize)
110112
}
111113

112114
if (!rpc_is_method(&value, "ota_data")) {
115+
JADE_LOGE("handle_in_bin_data: message is not ota_data");
113116
joctx->ota_return_status = OTA_ERR_BADDATA;
114117
return;
115118
}
@@ -120,6 +123,7 @@ void handle_in_bin_data(void* ctx, uint8_t* data, const size_t rawsize)
120123
rpc_get_bytes_ptr("params", &value, &inbound_buf, &written);
121124

122125
if (written == 0 || data[0] != joctx->expected_source || written > JADE_OTA_BUF_SIZE || !inbound_buf) {
126+
JADE_LOGE("handle_in_bin_data: invalid written or source");
123127
joctx->ota_return_status = OTA_ERR_BADDATA;
124128
return;
125129
}
@@ -148,17 +152,16 @@ void handle_in_bin_data(void* ctx, uint8_t* data, const size_t rawsize)
148152

149153
joctx->remaining_compressed -= written;
150154

151-
JADE_LOGI("Received ota_data msg %s, payload size %u", joctx->id, written);
152-
153-
JADE_LOGI("compressed: total = %u, current = %u", joctx->compressedsize,
154-
joctx->compressedsize - joctx->remaining_compressed);
155-
JADE_LOGI("uncompressed: total = %u, current = %u", joctx->uncompressedsize,
156-
joctx->uncompressedsize - joctx->remaining_uncompressed);
157-
158155
// Send ack after all processing - see comment above.
159-
uint8_t reply_msg[64];
160-
jade_process_reply_to_message_result_with_id(
161-
joctx->id, reply_msg, sizeof(reply_msg), joctx->expected_source, joctx, reply_ok);
156+
{
157+
uint8_t reply_msg[64];
158+
jade_process_reply_to_message_result_with_id(
159+
joctx->id, reply_msg, sizeof(reply_msg), joctx->expected_source, joctx, reply_ok);
160+
}
161+
162+
JADE_LOGI("sent ok for ota_data %s(%u), %u/%u->%u/%u", joctx->id, written,
163+
joctx->compressedsize - joctx->remaining_compressed, joctx->compressedsize,
164+
joctx->uncompressedsize - joctx->remaining_uncompressed, joctx->uncompressedsize);
162165

163166
// Blank out the current msg id once 'ok' is sent for it
164167
joctx->id[0] = '\0';
@@ -280,6 +283,7 @@ jade_ota_ctx_t* ota_init(jade_process_t* process, const bool is_delta)
280283
if (errmsg) {
281284
JADE_LOGE("%s", errmsg);
282285
jade_process_reject_message(process, errcode, errmsg);
286+
joctx = NULL;
283287
}
284288
return joctx;
285289
}

0 commit comments

Comments
 (0)