From f390e9a7d1c958b63861c2100783249912e9f067 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 23 Jul 2014 19:12:22 -0600 Subject: [PATCH] corecom_serial: add CRC for kernel --- artiq/devices/corecom_serial.py | 6 +++--- soc/runtime/main.c | 11 ++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/artiq/devices/corecom_serial.py b/artiq/devices/corecom_serial.py index 84ee55c79..1b45b3fe6 100644 --- a/artiq/devices/corecom_serial.py +++ b/artiq/devices/corecom_serial.py @@ -1,4 +1,4 @@ -import os, termios, struct +import os, termios, struct, zlib from enum import Enum from artiq.language import units @@ -78,8 +78,8 @@ class CoreCom: return Environment(ref_period*units.ps) def run(self, kcode): - _write_exactly(self.port, struct.pack(">lbl", - 0x5a5a5a5a, _MsgType.LOAD_KERNEL.value, len(kcode))) + _write_exactly(self.port, struct.pack(">lblL", + 0x5a5a5a5a, _MsgType.LOAD_KERNEL.value, len(kcode), zlib.crc32(kcode))) _write_exactly(self.port, kcode) (reply, ) = struct.unpack("b", _read_exactly(self.port, 1)) if reply != 0x4f: diff --git a/soc/runtime/main.c b/soc/runtime/main.c index a31472f38..2714c1255 100644 --- a/soc/runtime/main.c +++ b/soc/runtime/main.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -81,6 +82,7 @@ static void send_sync(void) static int ident_and_download_kernel(void *buffer, int maxlength) { int length; + unsigned int crc; int i; char msgtype; unsigned char *_buffer = buffer; @@ -93,10 +95,17 @@ static int ident_and_download_kernel(void *buffer, int maxlength) send_int(1000000000000LL/identifier_frequency_read()); /* RTIO clock period in picoseconds */ } else if(msgtype == MSGTYPE_LOAD_KERNEL) { length = receive_int(); - if(length > maxlength) + if(length > maxlength) { + send_char(0x4c); /* Incorrect length */ return -1; + } + crc = receive_int(); for(i=0;i