Skip to content

Commit 4235e8f

Browse files
committed
Improve TBYB sequence
Add self check (1 == 1), which is only performed on first boot
1 parent d0379cb commit 4235e8f

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

Diff for: encrypted/hello_encrypted/hello_encrypted.c

+23-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,29 @@ int main() {
1515
stdio_init_all();
1616

1717
#if PICO_CRT0_IMAGE_TYPE_TBYB
18-
// If TBYB image, then buy it
19-
uint8_t* buffer = malloc(4096);
20-
rom_explicit_buy(buffer, 4096);
21-
free(buffer);
18+
boot_info_t boot_info = {};
19+
int ret = rom_get_boot_info(&boot_info);
20+
if (ret) {
21+
// BOOT_TBYB_AND_UPDATE_FLAG_BUY_PENDING will always be set, but check anyway
22+
if (boot_info.tbyb_and_update_info & BOOT_TBYB_AND_UPDATE_FLAG_BUY_PENDING) {
23+
// Need to check flash_update_base is set to see if this is a TBYB update
24+
uint32_t flash_update_base = boot_info.reboot_params[0];
25+
if (flash_update_base) {
26+
printf("Perform self-check... ");
27+
if (1 == 1) {
28+
printf("passed\n");
29+
} else {
30+
printf("failed - looping forever\n");
31+
while (true) sleep_ms(1000);
32+
}
33+
}
34+
uint32_t buf_size = flash_update_base ? 4096 : 0;
35+
uint8_t* buffer = flash_update_base ? malloc(buf_size) : NULL;
36+
int ret = rom_explicit_buy(buffer, buf_size);
37+
assert(ret == 0);
38+
if (buffer) free(buffer);
39+
}
40+
}
2241
#endif
2342
extern char secret_data[];
2443

0 commit comments

Comments
 (0)