Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1M6tWY-0002NX-5j for mharc-grub-devel@gnu.org; Wed, 20 May 2009 17:40:30 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M6tWW-0002Lz-9K for grub-devel@gnu.org; Wed, 20 May 2009 17:40:28 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M6tWR-0002JK-KF for grub-devel@gnu.org; Wed, 20 May 2009 17:40:27 -0400 Received: from [199.232.76.173] (port=41546 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M6tWR-0002JC-GI for grub-devel@gnu.org; Wed, 20 May 2009 17:40:23 -0400 Received: from mailout06.t-online.de ([194.25.134.19]:57272) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1M6tWQ-0000XB-Cm for grub-devel@gnu.org; Wed, 20 May 2009 17:40:23 -0400 Received: from fwd03.aul.t-online.de by mailout06.sul.t-online.de with smtp id 1M6tWN-0000xQ-00; Wed, 20 May 2009 23:40:19 +0200 Received: from [10.3.2.2] (Gh+9lOZ1rhlyWHmB3kM0H+M+Z1O8srFG4i73bNBEIW4PuVLwzThn+5CblWqmbWwZb6@[217.235.244.225]) by fwd03.aul.t-online.de with esmtp id 1M6tWK-09wEbI0; Wed, 20 May 2009 23:40:16 +0200 Message-ID: <4A1478C1.5000906@t-online.de> Date: Wed, 20 May 2009 23:40:17 +0200 From: Christian Franke User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.21) Gecko/20090403 SeaMonkey/1.1.16 MIME-Version: 1.0 To: The development of GRUB 2 References: <1242689772.16522.1.camel@mj> <1242692278.26306.3.camel@mj> <1M6P7a-0SfD5U0@fwd04.aul.t-online.de> In-Reply-To: <1M6P7a-0SfD5U0@fwd04.aul.t-online.de> Content-Type: multipart/mixed; boundary="------------040302070200000602030008" X-ID: Gh+9lOZ1rhlyWHmB3kM0H+M+Z1O8srFG4i73bNBEIW4PuVLwzThn+5CblWqmbWwZb6 X-TOI-MSGID: 67ee1f50-eb75-455c-ace9-75611401c2b8 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: Re: [PATCH] ata.mod under qemu X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 May 2009 21:40:28 -0000 This is a multi-part message in MIME format. --------------040302070200000602030008 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit The attached patch should fix this. It should also prevents misleading error messages if a device does not exist. 2009-05-20 Christian Franke * disk/ata.c: (grub_ata_wait_not_busy): Add debug output of status register. (grub_ata_identify): Suppress error message if status register is 0x00 after command failure. (grub_device_initialize): Remove unsafe status register check. Thanks to 'phcoder' for problem report and patch. Prevent sign extension in debug message. -- Regards, Christian Franke --------------040302070200000602030008 Content-Type: text/x-diff; name="grub2-ata-status-fix.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="grub2-ata-status-fix.patch" diff --git a/disk/ata.c b/disk/ata.c index ea42d59..651937d 100644 --- a/disk/ata.c +++ b/disk/ata.c @@ -41,11 +41,14 @@ grub_ata_wait_not_busy (struct grub_ata_device *dev, int milliseconds) grub_millisleep (1); int i = 1; - while (grub_ata_regget (dev, GRUB_ATA_REG_STATUS) & GRUB_ATA_STATUS_BUSY) + grub_uint8_t sts; + while ((sts = grub_ata_regget (dev, GRUB_ATA_REG_STATUS)) + & GRUB_ATA_STATUS_BUSY) { if (i >= milliseconds) { - grub_dprintf ("ata", "timeout: %dms\n", milliseconds); + grub_dprintf ("ata", "timeout: %dms, status=0x%x\n", + milliseconds, sts); return grub_error (GRUB_ERR_TIMEOUT, "ATA timeout"); } @@ -259,20 +262,21 @@ grub_ata_identify (struct grub_ata_device *dev) if (grub_ata_wait_drq (dev, 0, GRUB_ATA_TOUT_STD)) { + grub_free(info); + grub_errno = GRUB_ERR_NONE; + if (grub_ata_regget (dev, GRUB_ATA_REG_ERROR) & 0x04) /* ABRT */ - { - /* Device without ATA IDENTIFY, try ATAPI. */ - grub_free(info); - grub_errno = GRUB_ERR_NONE; - return grub_atapi_identify (dev); - } + /* Device without ATA IDENTIFY, try ATAPI. */ + return grub_atapi_identify (dev); + + else if (grub_ata_regget (dev, GRUB_ATA_REG_STATUS) == 0x00) + /* No device, return error but don't print message. */ + return GRUB_ERR_UNKNOWN_DEVICE; + else - { - /* Error. */ - grub_free(info); - return grub_error (GRUB_ERR_UNKNOWN_DEVICE, - "device can not be identified"); - } + /* Other Error. */ + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, + "device can not be identified"); } grub_ata_pio_read (dev, info, GRUB_DISK_SECTOR_SIZE); @@ -334,26 +338,12 @@ grub_ata_device_initialize (int port, int device, int addr, int addr2) grub_ata_regset (dev, GRUB_ATA_REG_DISK, dev->device << 4); grub_ata_wait (); - /* If status is 0x00, it is safe to assume that there - is no device (or only a !READY) device connected. */ - grub_int8_t sts = grub_ata_regget (dev, GRUB_ATA_REG_STATUS); - grub_dprintf ("ata", "status=0x%x\n", sts); - if (sts == 0x00) - { - grub_free(dev); - return 0; - } - /* Try to detect if the port is in use by writing to it, waiting for a while and reading it again. If the value - was preserved, there is a device connected. - But this tests often detects a second (slave) device - connected to a SATA controller which supports only one - (master) device. In this case, the status register - check above usually works. */ + was preserved, there is a device connected. */ grub_ata_regset (dev, GRUB_ATA_REG_SECTORS, 0x5A); grub_ata_wait (); - grub_int8_t sec = grub_ata_regget (dev, GRUB_ATA_REG_SECTORS); + grub_uint8_t sec = grub_ata_regget (dev, GRUB_ATA_REG_SECTORS); grub_dprintf ("ata", "sectors=0x%x\n", sec); if (sec != 0x5A) { @@ -361,6 +351,12 @@ grub_ata_device_initialize (int port, int device, int addr, int addr2) return 0; } + /* The above test may detect a second (slave) device + connected to a SATA controller which supports only one + (master) device. It is not safe to use the status register + READY bit to check for controller channel existence. Some + ATAPI commands (RESET, DIAGNOSTIC) may clear this bit. */ + /* Use the IDENTIFY DEVICE command to query the device. */ if (grub_ata_identify (dev)) { --------------040302070200000602030008--