--- /dev/null
+package com.codesrc.scsi2sd.io;
+
+public class StorageDevice {
+ private int _deviceId;
+ private StorageDeviceType _storageDeviceType;
+ private long _capacity;
+
+ private boolean _supportsImageCommands;
+
+ StorageDevice(
+ int deviceId,
+ StorageDeviceType storageDeviceType,
+ long capacity,
+ boolean supportsImageCommands) {
+
+ this._deviceId = deviceId;
+ this._storageDeviceType = storageDeviceType;
+ this._capacity = capacity;
+ this._supportsImageCommands = supportsImageCommands;
+ }
+
+ public int get_deviceId() { return this._deviceId; }
+ public long get_capacity() { return this._capacity; }
+ public StorageDeviceType get_storageDeviceType() { return this._storageDeviceType; }
+ public boolean is_supportsImageCommands() { return this._supportsImageCommands; }
+}
import org.slf4j.LoggerFactory;
import java.io.*;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
public class V3FirmwareUsbDevice implements UsbDevice {
private static org.slf4j.Logger LOGGER = LoggerFactory.getLogger(V3FirmwareUsbDevice.class.getPackageName());
private HidPacketProtocolDevice protocolDevice;
private int firmwareVersion;
- private int sDCapacity;
+
+ private List<StorageDevice> storageDeviceList;
+ private long legacySdCapacity;
private byte[] boardConfigSector;
private Map<Integer, byte[]> diskConfigSector = new HashMap<>();
throw new RuntimeException("Failed to open USB device.");
}
}
+
this.readDebugData();
+ this.storageDeviceList = new LinkedList<StorageDevice>();
if (firmwareVersion >= 0x0485) {
this.readDeviceList();
}
+ else
+ {
+ this.storageDeviceList.add(new StorageDevice(0, StorageDeviceType.SD, this.legacySdCapacity, false));
+ }
}
@Override
return "Unknown";
}
+ @Override
+ public List<StorageDevice> getStorageDevices() {
+ return Collections.unmodifiableList(this.storageDeviceList);
+ }
+
@Override
public int getFirmwareVersion() {
return this.firmwareVersion;
return out.toString();
}
- @Override
- public int getSdCapacity() {
- return this.sDCapacity;
- }
-
@Override
public boolean supportsTerminator() {
switch (this.configHidDevice.getReleaseNumber()) {
this.debugHidDevice.read(data, 5000);
this.firmwareVersion = (HidPacketProtocol.uint8ToInt(data[62]) << 8) | HidPacketProtocol.uint8ToInt(data[63]);
- this.sDCapacity =
+ this.legacySdCapacity =
(HidPacketProtocol.uint8ToInt(data[58]) << 24) |
(HidPacketProtocol.uint8ToInt(data[59]) << 16) |
(HidPacketProtocol.uint8ToInt(data[60]) << 8) |
for (int i = 1; i + 4 < response.length; i += 5) {
int devType = HidPacketProtocol.uint8ToInt(response[i]);
- String devTypeStr = "Unknown";
+ StorageDeviceType devTypeEnum = StorageDeviceType.SD;
switch (devType) {
- case 0: devTypeStr = "SD"; break;
- case 1: devTypeStr = "SPIFLASH"; break;
+ case 0: devTypeEnum = StorageDeviceType.SD; break;
+ case 1: devTypeEnum = StorageDeviceType.NOR_FLASH; break;
}
int capacity = (HidPacketProtocol.uint8ToInt(response[i + 1]) << 24) |
(HidPacketProtocol.uint8ToInt(response[i + 2]) << 16) |
(HidPacketProtocol.uint8ToInt(response[i + 3]) << 8) |
(HidPacketProtocol.uint8ToInt(response[i + 4]));
- System.out.print("Found storage device type " + devTypeStr + " with capacity: ");
- System.out.println(capacity * 512L);
- }
- /*
- System.out.println("Reading a sector");
- byte[] readCmd = {(byte)Commands.DEV_READ.ordinal(), (byte)1, (byte)0, (byte)0, (byte)0, (byte)1};
- byte[] readResponse = protocolDevice.sendHIDPacket(readCmd, 512);
- for (var i = 0; i < readResponse.length; ++i) {
- System.out.println(HidPacketProtocol.uint8ToInt(readResponse[i]));
- }
-
- System.out.println("FLASH test complete");
- */
+ this.storageDeviceList.add(
+ new StorageDevice(
+ this.storageDeviceList.size(),
+ devTypeEnum,
+ capacity * 512L,
+ devTypeEnum == StorageDeviceType.NOR_FLASH
+ )
+ );
+ }
}
}
@Override
- public void writeImage(File file, int sectorStart) throws IOException
+ public void writeImage(int deviceId, File file, int sectorStart) throws IOException
{
// Only supported on the flash device
// Erase the flash device
var sectors = ((int) file.length() + 511) / 512;
byte[] eraseCmd = {
(byte)Commands.DEV_ERASE.ordinal(),
- (byte)1, // Hardcoded flash device for now
+ HidPacketProtocol.intToUint8(deviceId),
(byte)0,
(byte)0,
(byte)0,
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
public class V6FirmwareUsbDevice implements UsbDevice {
private HidPacketProtocolDevice protocolDevice;
private int firmwareVersion;
+
+ private List<StorageDevice> storageDeviceList;
private int sDCapacity;
private byte[] configSector0;
}
}
this.readDebugData();
+
+ this.storageDeviceList.add(new StorageDevice(0, StorageDeviceType.SD, this.sDCapacity, false));
}
@Override
return "3.5\" SCSI2SD V6";
}
+ @Override
+ public List<StorageDevice> getStorageDevices() {
+ return Collections.unmodifiableList(this.storageDeviceList);
+ }
+
@Override
public int getFirmwareVersion() {
return this.firmwareVersion;
return out.toString();
}
- @Override
- public int getSdCapacity() {
- return this.sDCapacity;
- }
-
@Override
public boolean supportsTerminator() {
return true;
}
@Override
- public void writeImage(File file, int sectorStart) throws IOException
+ public void writeImage(int deviceId, File file, int sectorStart) throws IOException
{
throw new UnsupportedOperationException("Not implemented yet");
}