Skip to content

Commit

Permalink
Add verify, support Risc-V, and replace asserts on returned chars wit…
Browse files Browse the repository at this point in the history
…h reset_chips
  • Loading branch information
will-v-pi committed Nov 15, 2024
1 parent 1ad1139 commit 82c3e7c
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 11 deletions.
4 changes: 2 additions & 2 deletions bootloaders/uart/uart-pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
{
"start": "128K",
"size": "32K",
"families": ["rp2350-arm-s"],
"families": ["rp2350-arm-s", "rp2350-riscv"],
"permissions": {
"secure": "rw",
"nonsecure": "rw",
"bootloader": "rw"
}
}
]
}
}
82 changes: 73 additions & 9 deletions bootloaders/uart/uart_boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ void reset_chip() {

void uart_boot() {
uint knocks = 0;
char in = 0;
while (true) {
// Send the knock sequence
uart_putc_raw(UART_ID, 0x56);
Expand All @@ -36,13 +37,17 @@ void uart_boot() {
uart_putc_raw(UART_ID, 'n');

if (uart_is_readable_within_us(UART_ID, 1000)) {
char in = uart_getc(UART_ID);
assert(in == 'n');
in = uart_getc(UART_ID);
if (in != 'n') {
printf("Incorrect response - resetting\n");
reset_chip();
return;
}
printf("%c\n", in);
break;
} else {
if (knocks > 10) {
printf("No response - resetting\n");
printf("No response - resetting\n");
reset_chip();
return;
}
Expand Down Expand Up @@ -83,25 +88,84 @@ void uart_boot() {
reset_chip();
return;
}
char in = uart_getc(UART_ID);
printf("%c\n", in);
assert(in == 'w');
in = uart_getc(UART_ID);
if (in != 'w') {
printf("Incorrect response - resetting\n");
reset_chip();
return;
}
current_addr += 32;
}

uint32_t time_end = time_us_32();
printf("Write took %dus\n", time_end - time_start);
printf("Write complete - executing\n");
printf("Write complete - resetting pointer\n");

uart_putc_raw(UART_ID, 'c');
if (!uart_is_readable_within_us(UART_ID, 500)) {
// Detect hangs and reset the chip
printf("Clear has hung - resetting\n");
reset_chip();
return;
}
in = uart_getc(UART_ID);
printf("%c\n", in);
if (in != 'c') {
printf("Incorrect response - resetting\n");
reset_chip();
return;
}

printf("Verifying binary\n");
time_start = time_us_32();
current_addr = start_addr;
while (current_addr < end_addr) {
uart_putc_raw(UART_ID, 'r');
char *buf = (char*)current_addr;
if (!uart_is_readable_within_us(UART_ID, 500)) {
// Detect hangs and reset the chip
printf("Verify has hung - resetting\n");
reset_chip();
return;
}
int i = 0;
while (uart_is_readable_within_us(UART_ID, 10) && i < 32) {
in = uart_getc(UART_ID);
if (in != buf[i]) {
printf("Verify has incorrect data at 0x%08x - resetting\n", current_addr - start_addr + SRAM_BASE);
}
i++;
}
if (i != 32) {
printf("Verify has incorrect data size - resetting\n");
}
in = uart_getc(UART_ID);
if (in != 'r') {
printf("Incorrect response - resetting\n");
reset_chip();
return;
}
current_addr += 32;
}

time_end = time_us_32();
printf("Verify took %dus\n", time_end - time_start);
printf("Verify complete - executing\n");

uart_putc_raw(UART_ID, 'x');
if (!uart_is_readable_within_us(UART_ID, 500)) {
// Detect hangs and reset the chip
printf("Execute has hung - resetting\n");
reset_chip();
return;
}
char in = uart_getc(UART_ID);
in = uart_getc(UART_ID);
printf("%c\n", in);
assert(in == 'x');
if (in != 'x') {
printf("Incorrect response - resetting\n");
reset_chip();
return;
}
}


Expand Down

0 comments on commit 82c3e7c

Please sign in to comment.