Skip to content

Commit d1819cc

Browse files
committed
Add verify, support Risc-V, and replace asserts on returned chars with reset_chips
1 parent a30a140 commit d1819cc

File tree

2 files changed

+75
-11
lines changed

2 files changed

+75
-11
lines changed

bootloaders/uart/uart-pt.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
{
1313
"start": "128K",
1414
"size": "32K",
15-
"families": ["rp2350-arm-s"],
15+
"families": ["rp2350-arm-s", "rp2350-riscv"],
1616
"permissions": {
1717
"secure": "rw",
1818
"nonsecure": "rw",
1919
"bootloader": "rw"
2020
}
2121
}
2222
]
23-
}
23+
}

bootloaders/uart/uart_boot.c

+73-9
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ void reset_chip() {
2727

2828
void uart_boot() {
2929
uint knocks = 0;
30+
char in = 0;
3031
while (true) {
3132
// Send the knock sequence
3233
uart_putc_raw(UART_ID, 0x56);
@@ -36,13 +37,17 @@ void uart_boot() {
3637
uart_putc_raw(UART_ID, 'n');
3738

3839
if (uart_is_readable_within_us(UART_ID, 1000)) {
39-
char in = uart_getc(UART_ID);
40-
assert(in == 'n');
40+
in = uart_getc(UART_ID);
41+
if (in != 'n') {
42+
printf("Incorrect response - resetting\n");
43+
reset_chip();
44+
return;
45+
}
4146
printf("%c\n", in);
4247
break;
4348
} else {
4449
if (knocks > 10) {
45-
printf("No response - resetting\n");
50+
printf("No response - resetting\n");
4651
reset_chip();
4752
return;
4853
}
@@ -83,25 +88,84 @@ void uart_boot() {
8388
reset_chip();
8489
return;
8590
}
86-
char in = uart_getc(UART_ID);
87-
printf("%c\n", in);
88-
assert(in == 'w');
91+
in = uart_getc(UART_ID);
92+
if (in != 'w') {
93+
printf("Incorrect response - resetting\n");
94+
reset_chip();
95+
return;
96+
}
8997
current_addr += 32;
9098
}
9199

92100
uint32_t time_end = time_us_32();
93101
printf("Write took %dus\n", time_end - time_start);
94-
printf("Write complete - executing\n");
102+
printf("Write complete - resetting pointer\n");
103+
104+
uart_putc_raw(UART_ID, 'c');
105+
if (!uart_is_readable_within_us(UART_ID, 500)) {
106+
// Detect hangs and reset the chip
107+
printf("Clear has hung - resetting\n");
108+
reset_chip();
109+
return;
110+
}
111+
in = uart_getc(UART_ID);
112+
printf("%c\n", in);
113+
if (in != 'c') {
114+
printf("Incorrect response - resetting\n");
115+
reset_chip();
116+
return;
117+
}
118+
119+
printf("Verifying binary\n");
120+
time_start = time_us_32();
121+
current_addr = start_addr;
122+
while (current_addr < end_addr) {
123+
uart_putc_raw(UART_ID, 'r');
124+
char *buf = (char*)current_addr;
125+
if (!uart_is_readable_within_us(UART_ID, 500)) {
126+
// Detect hangs and reset the chip
127+
printf("Verify has hung - resetting\n");
128+
reset_chip();
129+
return;
130+
}
131+
int i = 0;
132+
while (uart_is_readable_within_us(UART_ID, 10) && i < 32) {
133+
in = uart_getc(UART_ID);
134+
if (in != buf[i]) {
135+
printf("Verify has incorrect data at 0x%08x - resetting\n", current_addr - start_addr + SRAM_BASE);
136+
}
137+
i++;
138+
}
139+
if (i != 32) {
140+
printf("Verify has incorrect data size - resetting\n");
141+
}
142+
in = uart_getc(UART_ID);
143+
if (in != 'r') {
144+
printf("Incorrect response - resetting\n");
145+
reset_chip();
146+
return;
147+
}
148+
current_addr += 32;
149+
}
150+
151+
time_end = time_us_32();
152+
printf("Verify took %dus\n", time_end - time_start);
153+
printf("Verify complete - executing\n");
154+
95155
uart_putc_raw(UART_ID, 'x');
96156
if (!uart_is_readable_within_us(UART_ID, 500)) {
97157
// Detect hangs and reset the chip
98158
printf("Execute has hung - resetting\n");
99159
reset_chip();
100160
return;
101161
}
102-
char in = uart_getc(UART_ID);
162+
in = uart_getc(UART_ID);
103163
printf("%c\n", in);
104-
assert(in == 'x');
164+
if (in != 'x') {
165+
printf("Incorrect response - resetting\n");
166+
reset_chip();
167+
return;
168+
}
105169
}
106170

107171

0 commit comments

Comments
 (0)