From dc9d354ed22b4c6230c6bfe885e8a3d2519b1285 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Thu, 22 Dec 2022 20:31:06 +0000 Subject: multiboot: Add v1 boot protocol v1 passes the drive and partition number of the boot volume instead of using the volume number. The volume number isn't reliable because the same filesystem might get a different volume number once the firmware is loaded, which will cause the firmware to use the wrong root volume and fail to locate the correct .rockbox directory. Using drive and partition numbers avoids this issue because drive numbering is fixed and determined by the target. Change-Id: I7e68b892d9424a1f686197a6122e139b438e5f7e --- firmware/include/dircache_redirect.h | 43 ++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 7 deletions(-) (limited to 'firmware/include') diff --git a/firmware/include/dircache_redirect.h b/firmware/include/dircache_redirect.h index d4d72978c0..32e441c5b3 100644 --- a/firmware/include/dircache_redirect.h +++ b/firmware/include/dircache_redirect.h @@ -136,6 +136,41 @@ static inline void fileop_onsync_internal(struct filestr_base *stream) #endif } +#if defined(HAVE_MULTIBOOT) && !defined(SIMULATOR) && !defined(BOOTLOADER) +static inline bool multiboot_is_boot_volume(int volume) +{ + if (boot_data.version == 0) + { + /* + * Version 0 bootloaders just pass the volume number, but that's + * dynamically assigned and sometimes differs by the time we get + * into the firmware. So we can't rely on the volume passed by + * the bootloader. + */ +#if CONFIG_CPU == X1000 + /* The affected X1000 players only have one drive to begin with */ + return volume_drive(volume) == 0; +#else + /* FIXME: Anything else that can get here is a Sansa. */ + return volume_drive(volume) == boot_data.boot_volume || + volume == boot_data.boot_volume; +#endif + } + + if (boot_data.version == 1) + { + /* + * Since version 1 the bootloader passes drive and partition + * number which unambiguously identifies the boot volume. + */ + return volume_drive(volume) == boot_data.boot_drive && + volume_partition(volume) == boot_data.boot_partition; + } + + return false; +} +#endif + static inline void volume_onmount_internal(IF_MV_NONVOID(int volume)) { #if defined(HAVE_MULTIBOOT) && !defined(SIMULATOR) && !defined(BOOTLOADER) @@ -148,13 +183,7 @@ static inline void volume_onmount_internal(IF_MV_NONVOID(int volume)) /* we need to mount the drive before we can access it */ root_mount_path(path, 0); /* root could be different folder don't hide */ -/*BUGFIX bootloader is less selective about which drives it will mount -- revisit */ -#if defined(HAVE_MULTIDRIVE) && (NUM_VOLUMES_PER_DRIVE == 1) - if (volume_drive(volume) == boot_data.boot_volume - || volume == boot_data.boot_volume) -#else - if (volume == boot_data.boot_volume) /* boot volume contained in uint8_t payload */ -#endif + if (multiboot_is_boot_volume(IF_MV_VOL(volume))) { int rtlen = get_redirect_dir(rtpath, sizeof(rtpath), volume, "", ""); while (rtlen > 0 && rtpath[--rtlen] == PATH_SEPCH) -- cgit v1.2.3