diff options
Diffstat (limited to 'heimdall/source')
-rw-r--r-- | heimdall/source/FlashAction.cpp | 48 | ||||
-rw-r--r-- | heimdall/source/TFlashModePacket.h | 65 | ||||
-rw-r--r-- | heimdall/source/TFlashModeResponse.h | 58 |
3 files changed, 171 insertions, 0 deletions
diff --git a/heimdall/source/FlashAction.cpp b/heimdall/source/FlashAction.cpp index d9203b0..3a9b180 100644 --- a/heimdall/source/FlashAction.cpp +++ b/heimdall/source/FlashAction.cpp @@ -30,6 +30,8 @@ #include "Heimdall.h" #include "Interface.h" #include "SessionSetupResponse.h" +#include "TFlashModePacket.h" +#include "TFlashModeResponse.h" #include "TotalBytesPacket.h" #include "Utility.h" @@ -47,8 +49,10 @@ Arguments:\n\ --repartition --pit <filename> [--<partition name> <filename> ...]\n\ [--<partition identifier> <filename> ...] [--verbose] [--no-reboot]\n\ [--resume] [--stdout-errors] [--usb-log-level <none/error/warning/debug>]\n\ + [--tflash]\n\ Description: Flashes one or more firmware files to your phone. Partition names\n\ (or identifiers) can be obtained by executing the print-pit action.\n\ + T-Flash mode allows to flash the inserted SD-card instead of the internal MMC.\n\ Note: --no-reboot causes the device to remain in download mode after the action\n\ is completed. If you wish to perform another action whilst remaining in\n\ download mode, then the following action must specify the --resume flag.\n\ @@ -379,6 +383,40 @@ static PitData *getPitData(BridgeManager *bridgeManager, FILE *pitFile, bool rep return (pitData); } +static bool setTFlashMode(BridgeManager *bridgeManager) +{ + bool success; + + TFlashModePacket *tFlashModePacket = new TFlashModePacket(); + success = bridgeManager->SendPacket(tFlashModePacket); + delete tFlashModePacket; + + if (!success) + { + Interface::PrintError("Failed to request T-Flash mode!\n"); + return false; + } + + TFlashModeResponse *tFlashModeResponse = new TFlashModeResponse(); + success = bridgeManager->ReceivePacket(tFlashModeResponse); + unsigned int result = tFlashModeResponse->GetResult(); + delete tFlashModeResponse; + + if (!success) + { + Interface::PrintError("Failed to receive T-Flash mode result!\n"); + return false; + } + + if(result) + { + Interface::PrintError("Failed to set T-Flash mode (received: %d)!\n", result); + return false; + } + + return true; +} + int FlashAction::Execute(int argc, char **argv) { // Setup argument types @@ -393,6 +431,7 @@ int FlashAction::Execute(int argc, char **argv) argumentTypes["verbose"] = kArgumentTypeFlag; argumentTypes["stdout-errors"] = kArgumentTypeFlag; argumentTypes["usb-log-level"] = kArgumentTypeString; + argumentTypes["tflash"] = kArgumentTypeFlag; argumentTypes["pit"] = kArgumentTypeString; shortArgumentAliases["pit"] = "pit"; @@ -420,6 +459,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; if (arguments.GetArgument("stdout-errors") != nullptr) Interface::SetStdoutErrors(true); @@ -506,6 +546,14 @@ int FlashAction::Execute(int argc, char **argv) return (1); } + if (tflash_mode && !setTFlashMode(bridgeManager)) + { + closeFiles(partitionFiles, pitFile); + delete bridgeManager; + + return (1); + } + bool success = sendTotalTransferSize(bridgeManager, partitionFiles, pitFile, repartition); if (success) diff --git a/heimdall/source/TFlashModePacket.h b/heimdall/source/TFlashModePacket.h new file mode 100644 index 0000000..4d5bc07 --- /dev/null +++ b/heimdall/source/TFlashModePacket.h @@ -0,0 +1,65 @@ +/* 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 diff --git a/heimdall/source/TFlashModeResponse.h b/heimdall/source/TFlashModeResponse.h new file mode 100644 index 0000000..a9a3558 --- /dev/null +++ b/heimdall/source/TFlashModeResponse.h @@ -0,0 +1,58 @@ +/* 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 TFLASHMODERESPONSE_H +#define TFLASHMODERESPONSE_H + +// Heimdall +#include "ResponsePacket.h" + +namespace Heimdall +{ + class TFlashModeResponse : public ResponsePacket + { + private: + + unsigned int result; + + public: + + TFlashModeResponse() : ResponsePacket(ResponsePacket::kResponseTypeSessionSetup) + { + } + + unsigned int GetResult(void) const + { + return (result); + } + + bool Unpack(void) + { + if (!ResponsePacket::Unpack()) + return (false); + + result = UnpackInteger(ResponsePacket::kDataSize); + + return (true); + } + }; +} + +#endif |