Fix input of size fieds and CDROM sector length in scsi2sd-util
authorMichael McMaster <michael@codesrc.com>
Mon, 24 Apr 2017 11:21:43 +0000 (21:21 +1000)
committerMichael McMaster <michael@codesrc.com>
Mon, 24 Apr 2017 11:21:43 +0000 (21:21 +1000)
software/SCSI2SD/src/scsi.c
software/scsi2sd-util/Makefile
software/scsi2sd-util/SCSI2SD_HID.cc
software/scsi2sd-util/TargetPanel.cc
software/scsi2sd-util/scsi2sd-bulk.cc [new file with mode: 0644]

index 9ac58d6..b3f301b 100755 (executable)
@@ -167,8 +167,11 @@ void process_Status()
                message = MSG_COMMAND_COMPLETE;\r
        }\r
 \r
-// TODO OMTI ENABLE VIA CONFIG\r
-// scsiDev.status |=  (scsiDev.target->targetId & 0x03) << 5 ;\r
+\r
+       if (scsiDev.target->cfg->quirks == CONFIG_QUIRKS_OMTI)\r
+       {\r
+               scsiDev.status |= (scsiDev.target->targetId & 0x03) << 5;\r
+       }\r
 \r
        scsiWriteByte(scsiDev.status);\r
 \r
index 842441e..5bce4e0 100755 (executable)
@@ -84,6 +84,7 @@ ifeq ($(TARGET),Darwin)
 all: $(BUILD)/scsi2sd-util.dmg
 
 $(BUILD)/scsi2sd-util.dmg: $(BUILD)/scsi2sd-util $(BUILD)/scsi2sd-monitor
+       rm -rf $(dir $@)/dmg $@
        mkdir -p $(dir $@)/dmg
        cp $(BUILD)/scsi2sd-util $(BUILD)/scsi2sd-monitor $(dir $@)/dmg
        chmod a+rx $(dir $@)/dmg/*
@@ -92,7 +93,7 @@ endif
 
 export CC CXX
 
-all:  $(BUILD)/scsi2sd-util$(EXE) $(BUILD)/scsi2sd-monitor$(EXE)
+all:  $(BUILD)/scsi2sd-util$(EXE) $(BUILD)/scsi2sd-monitor$(EXE) $(BUILD)/scsi2sd-bulk$(EXE)
 
 CYAPI = \
        $(BUILD)/cybtldr_api2.o \
@@ -107,16 +108,20 @@ HIDAPI = \
 endif
 
 
-OBJ = \
+CONSOLEOBJ = \
        $(CYAPI) $(HIDAPI) \
-       $(BUILD)/ConfigUtil.o \
        $(BUILD)/Firmware.o \
-       $(BUILD)/BoardPanel.o \
-       $(BUILD)/TargetPanel.o \
        $(BUILD)/SCSI2SD_Bootloader.o \
        $(BUILD)/SCSI2SD_HID.o \
        $(BUILD)/hidpacket.o \
 
+OBJ = \
+       ${CONSOLEOBJ} \
+       $(BUILD)/ConfigUtil.o \
+       $(BUILD)/BoardPanel.o \
+       $(BUILD)/TargetPanel.o \
+       $(BUILD)/hidpacket.o \
+
 EXEOBJ = \
        $(BUILD)/scsi2sd-util.o \
        $(BUILD)/scsi2sd-monitor.o \
@@ -193,6 +198,10 @@ $(BUILD)/scsi2sd-monitor$(EXE): $(OBJ) $(BUILD)/scsi2sd-monitor.o
        mkdir -p $(dir $@)
        $(CXX) $(CXXFLAGS) $^ $(LDFLAGS_WX) $(LDFLAGS) -o $@
 
+$(BUILD)/scsi2sd-bulk$(EXE): $(CONSOLEOBJ) $(BUILD)/scsi2sd-bulk.o
+       mkdir -p $(dir $@)
+       $(CXX) $(CXXFLAGS) $^ $(LDFLAGS) -o $@
+
 clean:
        rm $(BUILD)/scsi2sd-util$(EXE) $(OBJ) $(BUILD)/libzipper/buildstamp
 
index df83b67..309f6c7 100644 (file)
 #include "scsi2sd.h"
 #include "hidpacket.h"
 
-// For compilers that support precompilation, includes "wx/wx.h".
-#include <wx/wxprec.h>
-#ifndef WX_PRECOMP
-#include <wx/wx.h>
-#endif
-
-#include <wx/utils.h>
-
 #include <cassert>
 #include <stdexcept>
 #include <sstream>
index d466643..3582b57 100755 (executable)
@@ -310,10 +310,6 @@ TargetPanel::evaluate()
 
        switch (myDeviceTypeCtrl->GetSelection())
        {
-       case CONFIG_OPTICAL:
-               mySectorSizeCtrl->ChangeValue("2048");
-               mySectorSizeCtrl->Enable(true); // Enable override
-               break;
        case CONFIG_FLOPPY_14MB:
                mySectorSizeCtrl->ChangeValue("512");
                mySectorSizeCtrl->Enable(false);
@@ -321,9 +317,9 @@ TargetPanel::evaluate()
                myNumSectorCtrl->Enable(false);
                mySizeUnitCtrl->Enable(false);
                mySizeCtrl->Enable(false);
+               evaluateSize();
                break;
        };
-       evaluateSize();
 
        if (myAutoStartSectorCtrl->IsChecked())
        {
@@ -420,6 +416,16 @@ TargetPanel::evaluate()
 template<typename EvtType> void
 TargetPanel::onInput(EvtType& event)
 {
+       if (event.GetId() == ID_deviceTypeCtrl)
+       {
+               switch (myDeviceTypeCtrl->GetSelection())
+               {
+               case CONFIG_OPTICAL:
+                       mySectorSizeCtrl->ChangeValue("2048");
+                       evaluateSize();
+                       break;
+               }
+       }
        wxCommandEvent changeEvent(ConfigChangedEvent);
        wxPostEvent(myParent, changeEvent);
 }
@@ -429,11 +435,18 @@ TargetPanel::onSizeInput(wxCommandEvent& event)
 {
        if (event.GetId() != ID_numSectorCtrl)
        {
-               std::stringstream ss;
-               ss << convertUnitsToSectors().first;
-               myNumSectorCtrl->ChangeValue(ss.str());
+               std::pair<uint32_t, bool> sec = convertUnitsToSectors();
+               if (sec.second)
+               {
+                       std::stringstream ss;
+                       ss << sec.first;
+                       myNumSectorCtrl->ChangeValue(ss.str());
+               }
+       }
+       if (event.GetId() != ID_sizeCtrl)
+       {
+               evaluateSize();
        }
-       evaluateSize();
        onInput(event); // propagate
 }
 
diff --git a/software/scsi2sd-util/scsi2sd-bulk.cc b/software/scsi2sd-util/scsi2sd-bulk.cc
new file mode 100644 (file)
index 0000000..cccda7f
--- /dev/null
@@ -0,0 +1,101 @@
+#include "SCSI2SD_Bootloader.hh"
+#include "SCSI2SD_HID.hh"
+#include "Firmware.hh"
+
+#include <iostream>
+#include <algorithm>
+#include <iomanip>
+#include <vector>
+#include <set>
+#include <sstream>
+
+#if __cplusplus >= 201103L
+#include <cstdint>
+#include <memory>
+using std::shared_ptr;
+#else
+#include <stdint.h>
+#include <tr1/memory>
+using std::tr1::shared_ptr;
+#endif
+
+#include <unistd.h>
+
+
+#define MIN_FIRMWARE_VERSION 0x0400
+
+using namespace SCSI2SD;
+
+extern "C"
+void ProgressUpdate(unsigned char arrayId, unsigned short rowNum)
+{
+       std::cout << "." << std::flush;
+}
+
+int main(int argc, char** argv)
+{
+       if (argc < 2)
+       {
+               std::cerr << "Usage: " << argv[0] << " {firmware.cyacd}" << std::endl;
+               exit(1);
+       }
+       std::string filename(argv[1]);
+
+       std::cout << "Searching for SCSI2SD device ..." << std::endl;
+
+       while (true)
+       {
+               shared_ptr<Bootloader> bootloader;
+               try
+               {
+                       shared_ptr<HID> hid(HID::Open());
+                       if (hid)
+                       {
+                               std::cout << "Resetting SCSI2SD into bootloader" << std::endl;
+                               usleep(100000);
+                               hid->enterBootloader();
+                               usleep(100000);
+                       }
+
+                       bootloader.reset(Bootloader::Open());
+               } catch (...) {}
+
+               if (bootloader)
+               {
+                       std::cout << "Upgrading firmware from file: " << filename << std::endl;
+
+                       try
+                       {
+                               bootloader->load(filename, &ProgressUpdate);
+                               usleep(2000000);
+                               std::cerr << "\nFirmware update successful" << std::endl;
+
+
+                               // Wait for disconnect
+                               shared_ptr<HID> hid(HID::Open());
+
+                               while (bootloader || hid)
+                               {
+                                       usleep(100000);
+                                       try {
+                                               hid.reset(HID::Open());
+                                               usleep(100000);
+                                               bootloader.reset(Bootloader::Open());
+                                               usleep(100000);
+                                       } catch (...) {}
+                               }
+                               std::cout << "Searching for SCSI2SD device ..." << std::endl;
+                       }
+                       catch (std::exception& e)
+                       {
+                               std::cerr << "Firmware update failed: " << e.what() << std::endl;
+                               abort();
+                       }
+
+               }
+               else
+               {
+                       usleep(100000);
+               }
+       }
+}