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
This commit is contained in:
Aidan MacDonald 2022-12-22 20:31:06 +00:00
parent 6ffd42548b
commit dc9d354ed2
6 changed files with 99 additions and 12 deletions

View file

@ -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)