From 2e8cd4cfbf812bddad31de70efabf4c131914a04 Mon Sep 17 00:00:00 2001 From: torne Date: Wed, 14 Apr 2010 14:40:03 +0000 Subject: [PATCH] Make builds with MAX_PHYS_SECTOR_SIZE defined (ipod video) work with larger sizes if the drive is sane. The ipod video build has a MAX_PHYS_SECTOR_SIZE of 1024. This meant it would refuse to boot on drives with sectors larger than 1024 bytes, even if those drives don't actually require the workaround originally intended for the 80GB 5.5G's drive. ata_init() will now, if the drive claims to have >512 byte sectors, try and read sector 1 to determine if the drive is capable of emulating 512-byte sector accesses. If this succeeds, we assume the drive is better at it than us (this is very likely to be true) and set phys_sector_mult to 1, disabling the workaround and ensuring the drive will work regardless of sector size. Making use of this change requires that you build and install an updated bootloader as well as the main build; a new iPod bootloader will be released soon, so if you can't do this yourself, be patient. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25646 a1c6a512-1295-4272-9138-f99709370657 --- firmware/drivers/ata.c | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c index 2140456e6..4780cf5c0 100644 --- a/firmware/drivers/ata.c +++ b/firmware/drivers/ata.c @@ -1351,20 +1351,6 @@ int ata_init(void) DEBUGF("ata: %d sectors per ata request\n",multisectors); -#ifdef MAX_PHYS_SECTOR_SIZE - /* Find out the physical sector size */ - if((identify_info[106] & 0xe000) == 0x6000) - phys_sector_mult = BIT_N(identify_info[106] & 0x000f); - else - phys_sector_mult = 1; - - DEBUGF("ata: %d logical sectors per phys sector", phys_sector_mult); - - if (phys_sector_mult > (MAX_PHYS_SECTOR_SIZE/SECTOR_SIZE)) - panicf("Unsupported physical sector size: %d", - phys_sector_mult * SECTOR_SIZE); -#endif - total_sectors = identify_info[60] | (identify_info[61] << 16); #ifdef HAVE_LBA48 @@ -1387,6 +1373,32 @@ int ata_init(void) if (rc) return -60 + rc; +#ifdef MAX_PHYS_SECTOR_SIZE + /* Find out the physical sector size */ + if((identify_info[106] & 0xe000) == 0x6000) + phys_sector_mult = BIT_N(identify_info[106] & 0x000f); + else + phys_sector_mult = 1; + + DEBUGF("ata: %d logical sectors per phys sector", phys_sector_mult); + + if (phys_sector_mult > 1) + { + /* Check if drive really needs emulation - if we can access + * sector 1 then assume the drive will handle it better than + * us, and ignore the large physical sectors. + */ + char throwaway[SECTOR_SIZE]; + rc = ata_transfer_sectors(1, 1, &throwaway, false); + if (rc == 0) + phys_sector_mult = 1; + } + + if (phys_sector_mult > (MAX_PHYS_SECTOR_SIZE/SECTOR_SIZE)) + panicf("Unsupported physical sector size: %d", + phys_sector_mult * SECTOR_SIZE); +#endif + mutex_lock(&ata_mtx); /* Balance unlock below */ last_disk_activity = current_tick; -- 2.11.4.GIT