From fadcac1c9e8097489c3cb6491c2efc9b665cb028 Mon Sep 17 00:00:00 2001 From: Brandon Wilson Date: Wed, 1 Oct 2014 19:34:59 -0400 Subject: [PATCH] Add chip ID & num LBA retrieval commands --- DriveCom/DriveCom/DriveCom.csproj.user | 2 +- DriveCom/DriveCom/PhisonDevice.cs | 26 ++++++++++++++++ DriveCom/DriveCom/Startup.cs | 22 ++++++++++++-- firmware/scsi.c | 41 ++++++++++++++++++++++---- 4 files changed, 83 insertions(+), 8 deletions(-) diff --git a/DriveCom/DriveCom/DriveCom.csproj.user b/DriveCom/DriveCom/DriveCom.csproj.user index 9934927..672238f 100644 --- a/DriveCom/DriveCom/DriveCom.csproj.user +++ b/DriveCom/DriveCom/DriveCom.csproj.user @@ -4,6 +4,6 @@ /drive=E /burner=C:\Users\Brandon\Documents\GitHub\PS2251-03\BINs\BN03V104M.BIN /firmware=C:\Users\Brandon\Documents\GitHub\PS2251-03\BINs\FW03FF01V10353M.BIN - /drive=E /burner="C:\Users\Brandon\Documents\GitHub\PS2251-03\BINs\BN03V104M.BIN" + /drive=E \ No newline at end of file diff --git a/DriveCom/DriveCom/PhisonDevice.cs b/DriveCom/DriveCom/PhisonDevice.cs index 1398604..a157f12 100644 --- a/DriveCom/DriveCom/PhisonDevice.cs +++ b/DriveCom/DriveCom/PhisonDevice.cs @@ -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; @@ -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 }); diff --git a/DriveCom/DriveCom/Startup.cs b/DriveCom/DriveCom/Startup.cs index a54a342..395e86b 100644 --- a/DriveCom/DriveCom/Startup.cs +++ b/DriveCom/DriveCom/Startup.cs @@ -26,7 +26,8 @@ public enum Action DumpFirmware, SetBootMode, SendExecutable, - SendFirmware + SendFirmware, + GetNumLBAs } public enum ExitCode @@ -113,6 +114,11 @@ static void Main(string[] args) _SendFirmware(); break; } + case Action.GetNumLBAs: + { + _DisplayLBAs(); + break; + } case Action.SetBootMode: { _device.JumpToBootMode(); @@ -157,7 +163,7 @@ static void Main(string[] args) } case "mode": { - Console.WriteLine("Mode: " + _GetInfo().ToString()); + _GetInfo(); break; } case "info": @@ -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]); @@ -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; @@ -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()); diff --git a/firmware/scsi.c b/firmware/scsi.c index 7673c46..ed6d52a 100644 --- a/firmware/scsi.c +++ b/firmware/scsi.c @@ -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 @@ -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);