uartproxy: s/CRCERR/CSUMERR/ and actually use it

It's not a CRC.

Signed-off-by: Hector Martin <marcan@marcan.st>
This commit is contained in:
Hector Martin 2021-04-17 16:25:48 +09:00
parent 8104ec02c4
commit 88e1612c09
2 changed files with 16 additions and 9 deletions

View file

@ -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):

View file

@ -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;