Skip to content

Commit

Permalink
workaround older phone fw issues when retrieving via json rpc and gpt…
Browse files Browse the repository at this point in the history
… get function failures
  • Loading branch information
gus33000 committed Sep 1, 2024
1 parent 91961b0 commit c6dee3f
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 10 deletions.
3 changes: 2 additions & 1 deletion WPinternals/Models/UEFIApps/LumiaFlashAppModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ internal byte[] GetGptChunk(UInt32 Size) // TODO!
UInt16 Error = (UInt16)((Buffer[6] << 8) + Buffer[7]);
if (Error > 0)
{
throw new NotSupportedException("ReadGPT: Error 0x" + Error.ToString("X4"));
ThrowFlashError(Error);
//throw new NotSupportedException("ReadGPT: Error 0x" + Error.ToString("X4"));
}

System.Buffer.BlockCopy(Buffer, 8, GPTChunk, 0, 0x4400);
Expand Down
2 changes: 1 addition & 1 deletion WPinternals/Models/UEFIApps/NokiaFlashModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ internal void SwitchToBootManagerContext(bool DisableTimeOut = true)
bool ModernFlashApp = info.VersionMajor >= 2;

byte[] Request = new byte[7];
ByteOperations.WriteAsciiString(Request, 0, SwitchModeSignature + "B");
ByteOperations.WriteAsciiString(Request, 0, $"{SwitchModeSignature}B");
byte[] Response = ExecuteRawMethod(Request);
if (ByteOperations.ReadAsciiString(Response, 0, 4) == "NOKU")
{
Expand Down
31 changes: 29 additions & 2 deletions WPinternals/ViewModels/LumiaFlashRomViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ await SwitchModeViewModel.SwitchToWithProgress(PhoneNotifier, PhoneInterfaces.Lu

internal void FlashFFUTask(string FFUPath)
{
new Thread(() =>
new Thread(async () =>
{
bool Result = true;
Expand All @@ -519,8 +519,35 @@ internal void FlashFFUTask(string FFUPath)
if (Info.FlashAppProtocolVersionMajor >= 2)
{
byte[] GPTChunk = Phone.GetGptChunk(0x20000); // TODO: Get proper profile FFU and get ChunkSizeInBytes
Phone.SwitchToBootManagerContext();
if (PhoneNotifier.CurrentInterface != PhoneInterfaces.Lumia_Bootloader)
{
await PhoneNotifier.WaitForArrival();
}
if (PhoneNotifier.CurrentInterface != PhoneInterfaces.Lumia_Bootloader)
{
throw new WPinternalsException("Unexpected Mode");
}
byte[] GPTChunk = ((LumiaBootManagerAppModel)PhoneNotifier.CurrentModel).GetGptChunk(0x20000); // TODO: Get proper profile FFU and get ChunkSizeInBytes
GPT GPT = new(GPTChunk);
((LumiaBootManagerAppModel)PhoneNotifier.CurrentModel).SwitchToFlashAppContext();
if (PhoneNotifier.CurrentInterface != PhoneInterfaces.Lumia_Flash)
{
await PhoneNotifier.WaitForArrival();
}
if (PhoneNotifier.CurrentInterface != PhoneInterfaces.Lumia_Flash)
{
throw new WPinternalsException("Unexpected Mode");
}
Phone = (LumiaFlashAppModel)PhoneNotifier.CurrentModel;
FlashPart Part;
List<FlashPart> FlashParts = new();
Expand Down
30 changes: 24 additions & 6 deletions WPinternals/ViewModels/NokiaNormalViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,35 @@ private void StartLoadDeviceInfo()

LogFile.Log("IMEI: " + IMEI);
PublicID = CurrentModel.ExecuteJsonMethodAsBytes("ReadPublicId", "PublicId"); // 0x14 bytes: a5 e5 ...
LogFile.Log("Public ID: " + Converter.ConvertHexToString(PublicID, " "));
if (PublicID != null)
{
LogFile.Log("Public ID: " + Converter.ConvertHexToString(PublicID, " "));
}
BluetoothMac = CurrentModel.ExecuteJsonMethodAsBytes("ReadBtId", "BtId"); // 6 bytes: bc c6 ...
LogFile.Log("Bluetooth MAC: " + Converter.ConvertHexToString(BluetoothMac, " "));
if (BluetoothMac != null)
{
LogFile.Log("Bluetooth MAC: " + Converter.ConvertHexToString(BluetoothMac, " "));
}
WlanMac1 = CurrentModel.ExecuteJsonMethodAsBytes("ReadWlanMacAddress", "WlanMacAddress1"); // 6 bytes
LogFile.Log("WLAN MAC 1: " + Converter.ConvertHexToString(WlanMac1, " "));
if (WlanMac1 != null)
{
LogFile.Log("WLAN MAC 1: " + Converter.ConvertHexToString(WlanMac1, " "));
}
WlanMac2 = CurrentModel.ExecuteJsonMethodAsBytes("ReadWlanMacAddress", "WlanMacAddress2"); // 6 bytes
LogFile.Log("WLAN MAC 2: " + Converter.ConvertHexToString(WlanMac2, " "));
if (WlanMac2 != null)
{
LogFile.Log("WLAN MAC 2: " + Converter.ConvertHexToString(WlanMac2, " "));
}
WlanMac3 = CurrentModel.ExecuteJsonMethodAsBytes("ReadWlanMacAddress", "WlanMacAddress3"); // 6 bytes
LogFile.Log("WLAN MAC 3: " + Converter.ConvertHexToString(WlanMac3, " "));
if (WlanMac3 != null)
{
LogFile.Log("WLAN MAC 3: " + Converter.ConvertHexToString(WlanMac3, " "));
}
WlanMac4 = CurrentModel.ExecuteJsonMethodAsBytes("ReadWlanMacAddress", "WlanMacAddress4"); // 6 bytes
LogFile.Log("WLAN MAC 4: " + Converter.ConvertHexToString(WlanMac4, " "));
if (WlanMac4 != null)
{
LogFile.Log("WLAN MAC 4: " + Converter.ConvertHexToString(WlanMac4, " "));
}

bool? ProductionDone = CurrentModel.ExecuteJsonMethodAsBoolean("ReadProductionDoneState", "ProductionDone");
IsBootloaderSecurityEnabled = ProductionDone == null
Expand Down

0 comments on commit c6dee3f

Please sign in to comment.