Skip to content

Commit

Permalink
bios/tools: allow disabling CRC check on serialboot (to speedup debug…
Browse files Browse the repository at this point in the history
…/loading large images when only serial is available)
  • Loading branch information
enjoy-digital committed Aug 26, 2019
1 parent 4842bdc commit ffebd20
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 28 deletions.
32 changes: 18 additions & 14 deletions litex/soc/software/bios/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,34 +122,37 @@ int serialboot(void)
int actualcrc;
int goodcrc;

/* Grab one frame */
/* Get one Frame */
frame.length = uart_read();
frame.crc[0] = uart_read();
frame.crc[1] = uart_read();
frame.cmd = 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;
Expand All @@ -160,7 +163,8 @@ int serialboot(void)
|((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: {
Expand Down
1 change: 1 addition & 0 deletions litex/soc/software/bios/sfl.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct sfl_frame {
#define SFL_CMD_ABORT 0x00
#define SFL_CMD_LOAD 0x01
#define SFL_CMD_JUMP 0x02
#define SFL_CMD_LOAD_NO_CRC 0x03

/* Replies */
#define SFL_ACK_SUCCESS 'K'
Expand Down
34 changes: 20 additions & 14 deletions litex/tools/litex_term.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ def getkey(self):
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"
Expand Down Expand Up @@ -126,7 +127,7 @@ def encode(self):


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 = {}
Expand All @@ -138,6 +139,7 @@ def __init__(self, serial_boot, kernel_image, kernel_address, json_images):
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
Expand Down Expand Up @@ -176,15 +178,18 @@ def send_frame(self, frame):
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):
Expand All @@ -202,7 +207,7 @@ 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:
Expand Down Expand Up @@ -332,12 +337,13 @@ def _get_args():
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()
Expand Down

0 comments on commit ffebd20

Please sign in to comment.