Skip to content

Commit

Permalink
Add chip ID & num LBA retrieval commands
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonlw committed Oct 1, 2014
1 parent 6232c23 commit fadcac1
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DriveCom/DriveCom/DriveCom.csproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<StartArguments>/drive=E /burner=C:\Users\Brandon\Documents\GitHub\PS2251-03\BINs\BN03V104M.BIN /firmware=C:\Users\Brandon\Documents\GitHub\PS2251-03\BINs\FW03FF01V10353M.BIN</StartArguments>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<StartArguments>/drive=E /burner="C:\Users\Brandon\Documents\GitHub\PS2251-03\BINs\BN03V104M.BIN"</StartArguments>
<StartArguments>/drive=E</StartArguments>
</PropertyGroup>
</Project>
26 changes: 26 additions & 0 deletions DriveCom/DriveCom/PhisonDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,21 @@ public byte[] RequestVendorInfo()
return ret;
}

public string GetChipID()
{
var response = SendCommand(new byte[] { 0x06, 0x56, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 512);

return BitConverter.ToString(response, 0, 6);
}

public string GetFirmwareVersion()
{
var info = RequestVendorInfo();

return info[0x94] + "." + info[0x95].ToString("X02") + "." + info[0x96].ToString("X02");
}

public ushort? GetChipType()
{
ushort? ret = null;
Expand Down Expand Up @@ -197,6 +212,17 @@ public RunMode GetRunMode()
return ret;
}

public ulong GetNumLBAs()
{
var response = SendCommand(new byte[] { 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 8);
ulong ret = response[3];
ret |= (ulong)((ulong)(response[2] << 8) & 0x0000FF00);
ret |= (ulong)((ulong)(response[1] << 16) & 0x00FF0000);
ret |= (ulong)((ulong)(response[0] << 24) & 0xFF000000);

return ret + 1;
}

public void JumpToPRAM()
{
SendCommand(new byte[] { 0x06, 0xB3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
Expand Down
22 changes: 20 additions & 2 deletions DriveCom/DriveCom/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public enum Action
DumpFirmware,
SetBootMode,
SendExecutable,
SendFirmware
SendFirmware,
GetNumLBAs
}

public enum ExitCode
Expand Down Expand Up @@ -113,6 +114,11 @@ static void Main(string[] args)
_SendFirmware();
break;
}
case Action.GetNumLBAs:
{
_DisplayLBAs();
break;
}
case Action.SetBootMode:
{
_device.JumpToBootMode();
Expand Down Expand Up @@ -157,7 +163,7 @@ static void Main(string[] args)
}
case "mode":
{
Console.WriteLine("Mode: " + _GetInfo().ToString());
_GetInfo();
break;
}
case "info":
Expand All @@ -166,6 +172,11 @@ static void Main(string[] args)
Console.WriteLine(string.Format("Info: {0}...", BitConverter.ToString(data, 0, 16)));
break;
}
case "get_num_lbas":
{
_DisplayLBAs();
break;
}
case "password":
{
_SendPassword(@params[1]);
Expand Down Expand Up @@ -311,6 +322,11 @@ private static void _CloseDrive()
}
}

private static void _DisplayLBAs()
{
Console.WriteLine("Number of LBAs: 0x" + _device.GetNumLBAs().ToString("X08"));
}

private static void _DumpFirmware(string fileName)
{
var address = 0;
Expand Down Expand Up @@ -366,6 +382,8 @@ private static PhisonDevice.RunMode _GetInfo()
{
Console.WriteLine("Gathering information...");
Console.WriteLine("Reported chip type: " + _device.GetChipType().GetValueOrDefault().ToString("X04"));
Console.WriteLine("Reported chip ID: " + _device.GetChipID());
Console.WriteLine("Reported firmware version: " + _device.GetFirmwareVersion());

var ret = _device.GetRunMode();
Console.WriteLine("Mode: " + ret.ToString());
Expand Down
41 changes: 36 additions & 5 deletions firmware/scsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#define VENDOR_BOOT 0xBF
#define VENDOR_INFO 0x05
#define VENDOR_CHIPID 0x56
#define CUSTOM_XPEEK 0x06
#define CUSTOM_XPOKE 0x07
#define CUSTOM_IPEEK 0x08
Expand Down Expand Up @@ -113,16 +114,46 @@ BYTE HandleCDB()
SendData1(1, 0);
break;
}
case VENDOR_INFO: //get info
case VENDOR_CHIPID:
{
int i;

memset(usb_buffer, 0x00, 0x210);
for (i = 0; i < 0x200; i++)
memset(usb_buffer, 0x00, 0x200);

//Set raw command mode
XVAL(0xF480) = 0x00;
XVAL(0xF618) = 0xFF;

//Select chip 0
XVAL(0xF608) = 0xFE;

//Reset it
XVAL(0xF400) = 0xFF;
while (!(XVAL(0xF41E) & 0x01));

//Send read chip ID command
XVAL(0xF400) = 0x90;
XVAL(0xF404) = 0x00;
for (i = 0; i < 6; i++)
{
usb_buffer[i] = *((BYTE __xdata *)(0x5000 + i));
usb_buffer[i] = XVAL(0xF408);
}

SendData1(0x200, 0);
scsi_status = 0;
return 1;
}
case VENDOR_INFO: //get info
{
int i;

memset(usb_buffer, 0x00, 0x210);
usb_buffer[0x094] = 0x00;
usb_buffer[0x095] = 0x99;
usb_buffer[0x096] = 0x53;
usb_buffer[0x17A] = 'V';
usb_buffer[0x17B] = 'R';
usb_buffer[0x17E] = 0x23;
usb_buffer[0x17F] = 0x03;
usb_buffer[0x200] = 'I';
usb_buffer[0x201] = 'F';
SendData1(0x210, 0);
Expand Down

0 comments on commit fadcac1

Please sign in to comment.