Commit bf891c93 authored by Benjamin Dobell's avatar Benjamin Dobell

Refactor T-Flash implementation before merging.

parent aa40b074
/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna
/* Copyright (c) 2010-2017 Benjamin Dobell, Glass Echidna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......@@ -18,39 +18,20 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.*/
#ifndef TFLASHMODERESPONSE_H
#define TFLASHMODERESPONSE_H
#ifndef ENABLETFLASHPACKET_H
#define ENABLETFLASHPACKET_H
// Heimdall
#include "ResponsePacket.h"
#include "SessionSetupPacket.h"
namespace Heimdall
{
class TFlashModeResponse : public ResponsePacket
class EnableTFlashPacket : public SessionSetupPacket
{
private:
unsigned int result;
public:
TFlashModeResponse() : ResponsePacket(ResponsePacket::kResponseTypeSessionSetup)
{
}
unsigned int GetResult(void) const
EnableTFlashPacket() : SessionSetupPacket(SessionSetupPacket::kEnableTFlash)
{
return (result);
}
bool Unpack(void)
{
if (!ResponsePacket::Unpack())
return (false);
result = UnpackInteger(ResponsePacket::kDataSize);
return (true);
}
};
}
......
......@@ -24,14 +24,13 @@
// Heimdall
#include "Arguments.h"
#include "BridgeManager.h"
#include "EnableTFlashPacket.h"
#include "EndModemFileTransferPacket.h"
#include "EndPhoneFileTransferPacket.h"
#include "FlashAction.h"
#include "Heimdall.h"
#include "Interface.h"
#include "SessionSetupResponse.h"
#include "TFlashModePacket.h"
#include "TFlashModeResponse.h"
#include "TotalBytesPacket.h"
#include "Utility.h"
......@@ -383,34 +382,34 @@ static PitData *getPitData(BridgeManager *bridgeManager, FILE *pitFile, bool rep
return (pitData);
}
static bool setTFlashMode(BridgeManager *bridgeManager)
static bool enableTFlash(BridgeManager *bridgeManager)
{
bool success;
TFlashModePacket *tFlashModePacket = new TFlashModePacket();
success = bridgeManager->SendPacket(tFlashModePacket);
delete tFlashModePacket;
EnableTFlashPacket *enableTFlashPacket = new EnableTFlashPacket();
success = bridgeManager->SendPacket(enableTFlashPacket);
delete enableTFlashPacket;
if (!success)
{
Interface::PrintError("Failed to request T-Flash mode!\n");
Interface::PrintError("Failed to send T-Flash packet!\n");
return false;
}
TFlashModeResponse *tFlashModeResponse = new TFlashModeResponse();
success = bridgeManager->ReceivePacket(tFlashModeResponse, 5000);
unsigned int result = tFlashModeResponse->GetResult();
delete tFlashModeResponse;
SessionSetupResponse *enableTFlashResponse = new SessionSetupResponse();
success = bridgeManager->ReceivePacket(enableTFlashResponse, 5000);
unsigned int result = enableTFlashResponse->GetResult();
delete enableTFlashResponse;
if (!success)
{
Interface::PrintError("Failed to receive T-Flash mode result!\n");
Interface::PrintError("Failed to receive T-Flash response!\n");
return false;
}
if(result)
if (result)
{
Interface::PrintError("Failed to set T-Flash mode (received: %d)!\n", result);
Interface::PrintError("Unexpected T-Flash response!\nExpected: 0\nReceived: %d\n", result);
return false;
}
......@@ -459,7 +458,7 @@ int FlashAction::Execute(int argc, char **argv)
bool reboot = arguments.GetArgument("no-reboot") == nullptr;
bool resume = arguments.GetArgument("resume") != nullptr;
bool verbose = arguments.GetArgument("verbose") != nullptr;
bool tflash_mode = arguments.GetArgument("tflash") != nullptr;
bool tflash = arguments.GetArgument("tflash") != nullptr;
if (arguments.GetArgument("stdout-errors") != nullptr)
Interface::SetStdoutErrors(true);
......@@ -546,7 +545,7 @@ int FlashAction::Execute(int argc, char **argv)
return (1);
}
if (tflash_mode && !setTFlashMode(bridgeManager))
if (tflash && !enableTFlash(bridgeManager))
{
closeFiles(partitionFiles, pitFile);
delete bridgeManager;
......
......@@ -36,7 +36,8 @@ namespace Heimdall
kDeviceType = 1, // ?
kTotalBytes = 2,
//kEnableSomeSortOfFlag = 3,
kFilePartSize = 5
kFilePartSize = 5,
kEnableTFlash = 8
};
private:
......
/* Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.*/
#ifndef TFLASHMODEPACKET_H
#define TFLASHMODEPACKET_H
// Heimdall
#include "ControlPacket.h"
namespace Heimdall
{
class TFlashModePacket : public ControlPacket
{
public:
enum
{
kRequestTFlashMode = 0x08
};
protected:
enum
{
kDataSize = ControlPacket::kDataSize + 4
};
private:
unsigned int subcmd = TFlashModePacket::kRequestTFlashMode;
public:
TFlashModePacket(void) : ControlPacket(ControlPacket::kControlTypeSession)
{
}
virtual void Pack(void)
{
ControlPacket::Pack();
PackInteger(ControlPacket::kDataSize, subcmd);
}
};
}
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment