From 88e1612c09f79c4b66b447cf0afa37d528bfbd39 Mon Sep 17 00:00:00 2001 From: Hector Martin Date: Sat, 17 Apr 2021 16:25:48 +0900 Subject: [PATCH] uartproxy: s/CRCERR/CSUMERR/ and actually use it It's not a CRC. Signed-off-by: Hector Martin --- proxyclient/proxy.py | 6 +++--- src/uartproxy.c | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/proxyclient/proxy.py b/proxyclient/proxy.py index 3d99fc06..004480b9 100755 --- a/proxyclient/proxy.py +++ b/proxyclient/proxy.py @@ -75,7 +75,7 @@ class UartInterface: ST_BADCMD = -1 ST_INVAL = -2 ST_XFERERR = -3 - ST_CRCERR = -4 + ST_CSUMERR = -4 CMD_LEN = 56 REPLY_LEN = 36 @@ -200,7 +200,7 @@ class UartInterface: raise UartRemoteError("Reply error: Invalid argument") elif status == self.ST_XFERERR: raise UartRemoteError("Reply error: Data transfer failed") - elif status == self.ST_CRCERR: + elif status == self.ST_CSUMERR: raise UartRemoteError("Reply error: Data checksum failed") else: raise UartRemoteError("Reply error: Unknown error (%d)"%status) @@ -250,7 +250,7 @@ class UartInterface: chexdump(data) ccsum = self.checksum(data) if checksum != ccsum: - raise UartCRCError("Reply data checksum error: Expected 0x%08x, got 0x%08x"%(checksum, ccsum)) + raise UartChecksumError("Reply data checksum error: Expected 0x%08x, got 0x%08x"%(checksum, ccsum)) return data def readstruct(self, addr, stype): diff --git a/src/uartproxy.c b/src/uartproxy.c index cc98fe23..4632d9ee 100644 --- a/src/uartproxy.c +++ b/src/uartproxy.c @@ -44,11 +44,11 @@ typedef struct { #define REQ_MEMWRITE 0x03AA55FF #define REQ_BOOT 0x04AA55FF -#define ST_OK 0 -#define ST_BADCMD -1 -#define ST_INVAL -2 -#define ST_XFRERR -3 -#define ST_CRCERR -4 +#define ST_OK 0 +#define ST_BADCMD -1 +#define ST_INVAL -2 +#define ST_XFRERR -3 +#define ST_CSUMERR -4 // I just totally pulled this out of my arse // Noinline so that this can be bailed out by exc_guard = EXC_RETURN @@ -95,8 +95,15 @@ void uartproxy_run(void) bytes = uart_read((&request.type) + 1, REQ_SIZE - 4); if (bytes != REQ_SIZE - 4) continue; - if (checksum(&(request.type), REQ_SIZE - 4) != request.checksum) + + if (checksum(&(request.type), REQ_SIZE - 4) != request.checksum) { + memset(&reply, 0, sizeof(reply)); + reply.type = request.type; + reply.status = ST_CSUMERR; + reply.checksum = checksum(&reply, REPLY_SIZE - 4); + uart_write(&reply, REPLY_SIZE); continue; + } memset(&reply, 0, sizeof(reply)); reply.type = request.type;