corecom_serial: add CRC for kernel

This commit is contained in:
Sebastien Bourdeauducq 2014-07-23 19:12:22 -06:00
parent 06cc9302f8
commit f390e9a7d1
2 changed files with 13 additions and 4 deletions

View File

@ -1,4 +1,4 @@
import os, termios, struct import os, termios, struct, zlib
from enum import Enum from enum import Enum
from artiq.language import units from artiq.language import units
@ -78,8 +78,8 @@ class CoreCom:
return Environment(ref_period*units.ps) return Environment(ref_period*units.ps)
def run(self, kcode): def run(self, kcode):
_write_exactly(self.port, struct.pack(">lbl", _write_exactly(self.port, struct.pack(">lblL",
0x5a5a5a5a, _MsgType.LOAD_KERNEL.value, len(kcode))) 0x5a5a5a5a, _MsgType.LOAD_KERNEL.value, len(kcode), zlib.crc32(kcode)))
_write_exactly(self.port, kcode) _write_exactly(self.port, kcode)
(reply, ) = struct.unpack("b", _read_exactly(self.port, 1)) (reply, ) = struct.unpack("b", _read_exactly(self.port, 1))
if reply != 0x4f: if reply != 0x4f:

View File

@ -2,6 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <crc.h>
#include <irq.h> #include <irq.h>
#include <uart.h> #include <uart.h>
@ -81,6 +82,7 @@ static void send_sync(void)
static int ident_and_download_kernel(void *buffer, int maxlength) static int ident_and_download_kernel(void *buffer, int maxlength)
{ {
int length; int length;
unsigned int crc;
int i; int i;
char msgtype; char msgtype;
unsigned char *_buffer = buffer; 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 */ send_int(1000000000000LL/identifier_frequency_read()); /* RTIO clock period in picoseconds */
} else if(msgtype == MSGTYPE_LOAD_KERNEL) { } else if(msgtype == MSGTYPE_LOAD_KERNEL) {
length = receive_int(); length = receive_int();
if(length > maxlength) if(length > maxlength) {
send_char(0x4c); /* Incorrect length */
return -1; return -1;
}
crc = receive_int();
for(i=0;i<length;i++) for(i=0;i<length;i++)
_buffer[i] = receive_char(); _buffer[i] = receive_char();
if(crc32(buffer, length) != crc) {
send_char(0x43); /* CRC failed */
return -1;
}
send_char(0x4f); /* kernel reception OK */ send_char(0x4f); /* kernel reception OK */
return length; return length;
} else } else