int actualcrc;
int goodcrc;
- /* Grab one frame */
+ /* Get one Frame */
frame.length = uart_read();
frame.crc[0] = uart_read();
frame.crc[1] = uart_read();
for(i=0;i<frame.length;i++)
frame.payload[i] = uart_read();
- /* Check CRC */
- actualcrc = ((int)frame.crc[0] << 8)|(int)frame.crc[1];
- goodcrc = crc16(&frame.cmd, frame.length+1);
- if(actualcrc != goodcrc) {
- failed++;
- if(failed == MAX_FAILED) {
- printf("Too many consecutive errors, aborting");
- return 1;
+ /* Check Frame CRC (if CMD has a CRC) */
+ if (frame.cmd != SFL_CMD_LOAD_NO_CRC) {
+ actualcrc = ((int)frame.crc[0] << 8)|(int)frame.crc[1];
+ goodcrc = crc16(&frame.cmd, frame.length+1);
+ if(actualcrc != goodcrc) {
+ failed++;
+ if(failed == MAX_FAILED) {
+ printf("Too many consecutive errors, aborting");
+ return 1;
+ }
+ uart_write(SFL_ACK_CRCERROR);
+ continue;
}
- uart_write(SFL_ACK_CRCERROR);
- continue;
}
- /* CRC OK */
+ /* Execute Frame CMD */
switch(frame.cmd) {
case SFL_CMD_ABORT:
failed = 0;
uart_write(SFL_ACK_SUCCESS);
return 1;
- case SFL_CMD_LOAD: {
+ case SFL_CMD_LOAD:
+ case SFL_CMD_LOAD_NO_CRC: {
char *writepointer;
failed = 0;
|((unsigned long)frame.payload[3] << 0));
for(i=4;i<frame.length;i++)
*(writepointer++) = frame.payload[i];
- uart_write(SFL_ACK_SUCCESS);
+ if (frame.cmd == SFL_CMD_LOAD)
+ uart_write(SFL_ACK_SUCCESS);
break;
}
case SFL_CMD_JUMP: {
sfl_payload_length = 251
# General commands
-sfl_cmd_abort = b"\x00"
-sfl_cmd_load = b"\x01"
-sfl_cmd_jump = b"\x02"
+sfl_cmd_abort = b"\x00"
+sfl_cmd_load = b"\x01"
+sfl_cmd_load_no_crc = b"\x03"
+sfl_cmd_jump = b"\x02"
# Replies
sfl_ack_success = b"K"
class LiteXTerm:
- def __init__(self, serial_boot, kernel_image, kernel_address, json_images):
+ def __init__(self, serial_boot, kernel_image, kernel_address, json_images, no_crc):
self.serial_boot = serial_boot
assert not (kernel_image is not None and json_images is not None)
self.mem_regions = {}
self.mem_regions.update(json.load(f))
self.boot_address = self.mem_regions[list(self.mem_regions.keys())[-1]]
f.close()
+ self.no_crc = no_crc
self.reader_alive = False
self.writer_alive = False
retry = 1
while retry:
self.port.write(frame.encode())
- # Get the reply from the device
- reply = self.port.read()
- if reply == sfl_ack_success:
- retry = 0
- elif reply == sfl_ack_crcerror:
- retry = 1
+ if not self.no_crc:
+ # Get the reply from the device
+ reply = self.port.read()
+ if reply == sfl_ack_success:
+ retry = 0
+ elif reply == sfl_ack_crcerror:
+ retry = 1
+ else:
+ print("[LXTERM] Got unknown reply '{}' from the device, aborting.".format(reply))
+ return 0
else:
- print("[LXTERM] Got unknown reply '{}' from the device, aborting.".format(reply))
- return 0
+ retry = 0
return 1
def upload(self, filename, address):
sys.stdout.flush()
frame = SFLFrame()
frame_data = data[:sfl_payload_length]
- frame.cmd = sfl_cmd_load
+ frame.cmd = sfl_cmd_load if not self.no_crc else sfl_cmd_load_no_crc
frame.payload = current_address.to_bytes(4, "big")
frame.payload += frame_data
if self.send_frame(frame) == 0:
parser.add_argument("--kernel", default=None, help="kernel image")
parser.add_argument("--kernel-adr", default="0x40000000", help="kernel address")
parser.add_argument("--images", default=None, help="json description of the images to load to memory")
+ parser.add_argument("--no-crc", default=False, action='store_true', help="disable CRC check (speedup serialboot)")
return parser.parse_args()
def main():
args = _get_args()
- term = LiteXTerm(args.serial_boot, args.kernel, args.kernel_adr, args.images)
+ term = LiteXTerm(args.serial_boot, args.kernel, args.kernel_adr, args.images, args.no_crc)
term.open(args.port, int(float(args.speed)))
term.console.configure()
term.start()