diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2022-12-22 19:23:29 +0000 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2024-03-31 16:57:19 +0100 |
commit | 6ffd42548bf10cda13a01555ff4fa56d4213cdf2 (patch) | |
tree | 975d6a4f88a0a3469c1450476e841ef0bf8fbb85 /apps | |
parent | af644e02a151bb6d4c229cc1d4846c7ffe952135 (diff) | |
download | rockbox-6ffd42548bf10cda13a01555ff4fa56d4213cdf2.tar.gz rockbox-6ffd42548bf10cda13a01555ff4fa56d4213cdf2.zip |
multiboot: Refactor boot data validation, add version numbers
Instead of verifying the CRC before every access of the boot data,
verify the CRC once at startup and set a flag to indicate the boot
data is valid.
Also add a framework to support multiple boot protocol versions.
Firmware declares the maximum supported protocol version using a
version byte in the boot data header. The bootloader chooses the
highest version supported by it and the firmware when deciding
what boot protocol to use.
Change-Id: I810194625dc0833f026d2a23b8d64ed467fa6aca
Diffstat (limited to 'apps')
-rw-r--r-- | apps/debug_menu.c | 39 | ||||
-rw-r--r-- | apps/main.c | 5 |
2 files changed, 21 insertions, 23 deletions
diff --git a/apps/debug_menu.c b/apps/debug_menu.c index 5b73f8badd..5e2451e41b 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c | |||
@@ -2530,38 +2530,31 @@ static bool dbg_pic(void) | |||
2530 | #if defined(HAVE_BOOTDATA) && !defined(SIMULATOR) | 2530 | #if defined(HAVE_BOOTDATA) && !defined(SIMULATOR) |
2531 | static bool dbg_boot_data(void) | 2531 | static bool dbg_boot_data(void) |
2532 | { | 2532 | { |
2533 | unsigned int crc = crc_32(boot_data.payload, boot_data.length, 0xffffffff); | ||
2534 | struct simplelist_info info; | 2533 | struct simplelist_info info; |
2535 | info.scroll_all = true; | 2534 | info.scroll_all = true; |
2536 | simplelist_info_init(&info, "Boot data", 1, NULL); | 2535 | simplelist_info_init(&info, "Boot data", 1, NULL); |
2537 | simplelist_set_line_count(0); | 2536 | simplelist_set_line_count(0); |
2538 | 2537 | ||
2539 | #if defined(HAVE_MULTIBOOT) | 2538 | if (!boot_data_valid) |
2540 | char rootpath[MAX_PATH / 2] = RB_ROOT_CONTENTS_DIR; | ||
2541 | int boot_volume = 0; | ||
2542 | if(crc == boot_data.crc) | ||
2543 | { | 2539 | { |
2544 | boot_volume = boot_data.boot_volume; /* boot volume contained in uint8_t payload */ | 2540 | simplelist_addline("Boot data invalid"); |
2545 | int rtlen = get_redirect_dir(rootpath, sizeof(rootpath), boot_volume, "", ""); | 2541 | simplelist_addline("Magic[0]: %08lx", boot_data.magic[0]); |
2546 | while (rtlen > 0 && rootpath[--rtlen] == PATH_SEPCH) /* remove extra separators */ | 2542 | simplelist_addline("Magic[1]: %08lx", boot_data.magic[1]); |
2547 | rootpath[rtlen] = '\0'; | 2543 | simplelist_addline("Length: %lu", boot_data.length); |
2548 | } | 2544 | } |
2549 | simplelist_addline("Boot Volume: <%lu>", boot_volume); | 2545 | else |
2550 | simplelist_addline("Root:"); | 2546 | { |
2551 | simplelist_addline("%s", rootpath); | 2547 | simplelist_addline("Boot data valid"); |
2552 | simplelist_addline(""); | 2548 | simplelist_addline("Version: %d", (int)boot_data.version); |
2553 | #endif | 2549 | simplelist_addline("Boot volume: %d", (int)boot_data.boot_volume); |
2550 | } | ||
2551 | |||
2554 | simplelist_addline("Bootdata RAW:"); | 2552 | simplelist_addline("Bootdata RAW:"); |
2555 | if (crc != boot_data.crc) | 2553 | for (size_t i = 0; i < boot_data.length; i += 4) |
2556 | simplelist_addline("Magic: %.8s", boot_data.magic); | ||
2557 | simplelist_addline("Length: %lu", boot_data.length); | ||
2558 | simplelist_addline("CRC: %lx", boot_data.crc); | ||
2559 | (crc == boot_data.crc) ? simplelist_addline("CRC: OK!") : | ||
2560 | simplelist_addline("CRC: BAD"); | ||
2561 | for (unsigned i = 0; i < boot_data.length; i += 4) | ||
2562 | { | 2554 | { |
2563 | simplelist_addline("%02x: %02x %02x %02x %02x", i, boot_data.payload[i], | 2555 | simplelist_addline("%02x: %02x %02x %02x %02x", i, |
2564 | boot_data.payload[i+1], boot_data.payload[i+2], boot_data.payload[i+3]); | 2556 | boot_data.payload[i + 0], boot_data.payload[i + 1], |
2557 | boot_data.payload[i + 2], boot_data.payload[i + 3]); | ||
2565 | } | 2558 | } |
2566 | 2559 | ||
2567 | return simplelist_show_list(&info); | 2560 | return simplelist_show_list(&info); |
diff --git a/apps/main.c b/apps/main.c index 1e012efb3c..cf7d302fc9 100644 --- a/apps/main.c +++ b/apps/main.c | |||
@@ -77,6 +77,7 @@ | |||
77 | #include "statusbar-skinned.h" | 77 | #include "statusbar-skinned.h" |
78 | #include "bootchart.h" | 78 | #include "bootchart.h" |
79 | #include "logdiskf.h" | 79 | #include "logdiskf.h" |
80 | #include "bootdata.h" | ||
80 | #if (CONFIG_PLATFORM & PLATFORM_ANDROID) | 81 | #if (CONFIG_PLATFORM & PLATFORM_ANDROID) |
81 | #include "notification.h" | 82 | #include "notification.h" |
82 | #endif | 83 | #endif |
@@ -445,6 +446,10 @@ static void init(void) | |||
445 | core_allocator_init(); | 446 | core_allocator_init(); |
446 | kernel_init(); | 447 | kernel_init(); |
447 | 448 | ||
449 | #if defined(HAVE_BOOTDATA) && !defined(BOOTLOADER) | ||
450 | verify_boot_data(); | ||
451 | #endif | ||
452 | |||
448 | /* early early early! */ | 453 | /* early early early! */ |
449 | filesystem_init(); | 454 | filesystem_init(); |
450 | 455 | ||