]> xenbits.xensource.com Git - osstest/seabios.git/commitdiff
Support booting USB drives with a write protect switch enabled
authorMike Banon <mikebdp2@gmail.com>
Thu, 3 Dec 2020 04:06:59 +0000 (07:06 +0300)
committerKevin O'Connor <kevin@koconnor.net>
Mon, 21 Dec 2020 15:59:39 +0000 (10:59 -0500)
At least some USB drives with a write protect switch (e.g. Netac U335)
could report "MEDIUM NOT PRESENT" for a while if a write protection is
enabled. Instead of stopping the initialization attempts immediately,
stop only after getting this report for 3 times, to ensure the
successful initialization of such a "broken hardware".

Signed-off-by: Mike Banon <mikebdp2@gmail.com>
src/hw/blockcmd.c

index 1f15081bd8b2efc0e215cb0f8ca38bf13c86e5ce..6b6fea9707484d211b9a5d8b0bf9040392873899 100644 (file)
@@ -144,8 +144,9 @@ scsi_is_ready(struct disk_op_s *op)
     dprintf(6, "scsi_is_ready (drive=%p)\n", op->drive_fl);
 
     /* Retry TEST UNIT READY for 5 seconds unless MEDIUM NOT PRESENT is
-     * reported by the device.  If the device reports "IN PROGRESS",
+     * reported by the device 3 times.  If the device reports "IN PROGRESS",
      * 30 seconds is added. */
+    int tries = 3;
     int in_progress = 0;
     u32 end = timer_calc(5000);
     for (;;) {
@@ -167,8 +168,11 @@ scsi_is_ready(struct disk_op_s *op)
 
         // Sense succeeded.
         if (sense.asc == 0x3a) { /* MEDIUM NOT PRESENT */
-            dprintf(1, "Device reports MEDIUM NOT PRESENT\n");
-            return -1;
+            tries--;
+            dprintf(1, "Device reports MEDIUM NOT PRESENT - %d tries left\n",
+                tries);
+            if (!tries)
+                return -1;
         }
 
         if (sense.asc == 0x04 && sense.ascq == 0x01 && !in_progress) {