Explorar o código

initiator: fixed 2 images when device/host were 0/7.

This caused the drive to respond twice when in the SELECTION phase.

Partially used code from 1aeb33d.

Co-authored-by: Morio <morio.earth@gmail.com>
Eric Helgeson hai 1 ano
pai
achega
857bbf6a96

+ 1 - 4
lib/BlueSCSI_platform_RP2040/scsiHostPhy.cpp

@@ -31,7 +31,7 @@ void scsiHostPhyReset(void)
 
 // Select a device, id 0-7.
 // Returns true if the target answers to selection request.
-bool scsiHostPhySelect(int target_id)
+bool scsiHostPhySelect(int target_id, int initiator_id)
 {
     SCSI_ENABLE_INITIATOR();
     SCSI_RELEASE_OUTPUTS();
@@ -55,9 +55,6 @@ bool scsiHostPhySelect(int target_id)
         }
     }
 
-    // Choose initiator ID different than target ID
-    uint8_t initiator_id = (target_id == 7) ? 0 : 7;
-
     // Selection phase
     scsiLogInitiatorPhaseChange(SELECTION);
     debuglog("------ SELECTING ", target_id, " with initiator ID ", (int)initiator_id);

+ 1 - 1
lib/BlueSCSI_platform_RP2040/scsiHostPhy.h

@@ -14,7 +14,7 @@ void scsiHostPhyReset(void);
 
 // Select a device, id 0-7.
 // Returns true if the target answers to selection request.
-bool scsiHostPhySelect(int target_id);
+bool scsiHostPhySelect(int target_id, int initiator_id);
 
 // Read the current communication phase as signaled by the target
 // Matches SCSI_PHASE enumeration from scsi.h.

+ 15 - 2
src/BlueSCSI_initiator.cpp

@@ -10,6 +10,7 @@
 #include "BlueSCSI_log_trace.h"
 #include "BlueSCSI_initiator.h"
 #include <BlueSCSI_platform.h>
+#include <minIni.h>
 #include "SdFat.h"
 
 #include <scsi2sd.h>
@@ -49,6 +50,8 @@ static struct {
     // Bitmap of all drives that have been imaged
     uint32_t drives_imaged;
 
+    uint8_t initiator_id;
+
     // Is imaging a drive in progress, or are we scanning?
     bool imaging;
 
@@ -75,7 +78,17 @@ void scsiInitiatorInit()
 {
     scsiHostPhyReset();
 
-    g_initiator_state.drives_imaged = 0;
+    g_initiator_state.initiator_id = ini_getl("SCSI", "InitiatorID", 7, CONFIGFILE);
+    if (g_initiator_state.initiator_id > 7)
+    {
+        log("InitiatorID set to illegal value in, ", CONFIGFILE, ", defaulting to 7");
+        g_initiator_state.initiator_id = 7;
+    } else
+    {
+        log_f("InitiatorID set to ID %d", g_initiator_state.initiator_id);
+    }
+    // treat initiator id as already imaged drive so it gets skipped
+    g_initiator_state.drives_imaged = 1 << g_initiator_state.initiator_id;
     g_initiator_state.imaging = false;
     g_initiator_state.target_id = -1;
     g_initiator_state.sectorsize = 0;
@@ -347,7 +360,7 @@ int scsiInitiatorRunCommand(int target_id,
                             const uint8_t *bufOut, size_t bufOutLen,
                             bool returnDataPhase)
 {
-    if (!scsiHostPhySelect(target_id))
+    if (!scsiHostPhySelect(target_id, g_initiator_state.initiator_id))
     {
         debuglog("------ Target ", target_id, " did not respond");
         scsiHostPhyRelease();