pata-gpio icon indicating copy to clipboard operation
pata-gpio copied to clipboard

CHS (pre-LBA drives)

Open edescourtis opened this issue 2 years ago • 6 comments

I realise that this project doesn't currently have many practical uses since a simple USB to IDE adapter will do a much better job. But we could make this project useful by adding support for hard drives without LBA support. Early IDE drives are not readable by most modern IDE interfaces and this can be a pain for vintage computer owners, by adding support for those drives this immediately becomes a useful project to a lot of people.

As a first step we could allow manual configuration of drives similar to an old BIOS type 1-46 + a custom parameter mode. And later also detect pre-LBA drives with autodetect parameters.

I am more than happy to help with this.

edescourtis avatar Aug 28 '21 01:08 edescourtis

Hm, I do have quite a collection of old hardware, but I don't seem to have any HDDs old enough to only support CHS, not LBA. Not sure, how CHS is handled in the Linux kernel (if at all?), but the 3 registers LBAH, LBAM, LBAL are used for Cylinder, Heads and Sectors instead. The kernel can specify these registers directly, so if it wanted, my driver should (?!) be able to handle CHS.

Please feel free to test this yourself, you don't need the fancy PCB, just plug some wires (and ideally the resistors, not 100% strictly required though) into the GPIOs and you should be good to go.

I'd be happy to accept PRs fixing issues regarding CHS.

Manawyrm avatar Aug 29 '21 11:08 Manawyrm

I have a Conner CP30254 (252 MB, ca. 1992) that I'd really like to access. This project would be perfect for this.

AFAICT, the Linux kernel is (still) fully aware of CHS, see these source files of the 5.10 LTS branch (search for CHS):

libata: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/driver-api/libata.rst?h=v5.10 https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/include/linux/libata.h?h=v5.10 https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/drivers/ata/libata-core.c?h=v5.10

ide (legacy, deprecated, removed in 5.13+): https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/ide/ide.rst?h=v5.10 https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/drivers/ide/ide-disk.c?h=v5.10 https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/drivers/ide/ide.c?h=v5.10

Your pata-gpio hooks into libata, right? So CHS drives would probably just work out of the box? What do you think?

fonic avatar Jan 02 '22 14:01 fonic

The only thing I'm unsure of is how one would specify the drive geometry for libata. The legacy driver offers ide_core.chs=[interface_number.device_number]:cyls,heads,sects, but I was unable to find similar parameters for libata.

Old drives like mine do not support any auto-detection - I clearly remember having to enter (or select) the correct CHS values for the drive within the BIOS.

fonic avatar Jan 02 '22 15:01 fonic

Not sure if something still might be parsing the ide_core parameters… I‘d give it a try.

My driver is very low level and only handles the raw communication and setting of registers, everything else is done by libata.

Not sure if anyone has ever used libata with a CHS drive…

I have been looking for some very old pre-LBA drives in my collection over Christmas, but I wasn‘t able to find one that doesn‘t support autodetection.

Manawyrm avatar Jan 02 '22 15:01 Manawyrm

Not sure if something still might be parsing the ide_core parameters… I‘d give it a try.

I've studied the kernel sources for quite a bit - the ide_core parameters are only parsed by the legacy driver (i.e. the one activated by configuration item Device Drivers -> ATA/ATAPI/MFM/RLL support (DEPRECATED)).

libata has its own set of parameters, defined here. Manually setting CHS drive geometry is not supported, libata relies solely on information sent by the drive itself (i.e. in reply to a ATA_CMD_ID_ATA request), which early drives likely won't provide (see FIXME in this comment block).

Thus, I'd presume that drives made before ATA-1 (first standard, started 1986, finalized 1994) won't work with libata and thus won't work with pata-gpio.


The way I see it, the best bet to access a CHS-only drive in 2022 is a mainboard with an IDE interface that's supported by the legacy 'ide' driver + Linux distribution with 5.10 LTS kernel (as 'ide' was removed from the Linux kernel starting with 5.13).

fonic avatar Jan 02 '22 18:01 fonic

Well, libata supports CHS, see here: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/drivers/ata/libata-core.c?h=v5.10#n747

If device don't report LBA support libata will convert LBA to CHS. So it's pretty possible and will be quite useful feature to implement, given that motherboards capable of accessing CHS drives are more rare to come by, and speed for drives that old is usually not the concern...

VasylSamoilov avatar Oct 01 '23 21:10 VasylSamoilov