From 3dbe349dd95d60d5a45e872b44823fb1209d4263 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Fri, 15 Apr 2022 18:01:26 +0200 Subject: [PATCH] liblitesata/sata_init: Add SATA Read check (Seems to be required with some disks). --- litex/soc/software/liblitesata/sata.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/litex/soc/software/liblitesata/sata.c b/litex/soc/software/liblitesata/sata.c index 6f96a1ad6..1c5ecc739 100644 --- a/litex/soc/software/liblitesata/sata.c +++ b/litex/soc/software/liblitesata/sata.c @@ -21,8 +21,9 @@ int sata_init(void) { uint16_t timeout; + uint8_t buf[512]; - for (timeout=10; timeout>0; timeout--) { + for (timeout=16; timeout>0; timeout--) { /* Reset SATA PHY */ sata_phy_enable_write(0); busy_wait(1); @@ -32,10 +33,27 @@ int sata_init(void) { busy_wait(100); /* Check SATA PHY status */ - if (sata_phy_status_read() & 0x1) - return 1; + if ((sata_phy_status_read() & 0x1) == 0) + /* Re-initialize if failing */ + continue; + + /* Initiate a SATA Read */ + sata_sector2mem_base_write((uint64_t)(uintptr_t) buf); + sata_sector2mem_sector_write(0); + sata_sector2mem_start_write(1); + + /* Wait for 10ms */ + busy_wait(10); + + /* Check SATA Read status */ + if ((sata_sector2mem_done_read() & 0x1) == 0) + continue; + + /* Init succeeded */ + return 1; } + /* Init failed */ return 0; }