diff options
author | Benjamin Dobell <benjamin.dobell+github@glassechidna.com.au> | 2012-03-28 14:59:27 +0200 |
---|---|---|
committer | Benjamin Dobell <benjamin.dobell+github@glassechidna.com.au> | 2012-03-28 14:59:27 +0200 |
commit | ee02a9c7c51d069de26f04d8d9464d573ed82d22 (patch) | |
tree | b82798f845129c76fec7e2a982bf4b5b2849c2a8 | |
parent | Updated libusb-1.0 binaries/headers for windows. (diff) | |
download | Heimdall-ee02a9c7c51d069de26f04d8d9464d573ed82d22.tar Heimdall-ee02a9c7c51d069de26f04d8d9464d573ed82d22.tar.gz Heimdall-ee02a9c7c51d069de26f04d8d9464d573ed82d22.tar.bz2 Heimdall-ee02a9c7c51d069de26f04d8d9464d573ed82d22.tar.lz Heimdall-ee02a9c7c51d069de26f04d8d9464d573ed82d22.tar.xz Heimdall-ee02a9c7c51d069de26f04d8d9464d573ed82d22.tar.zst Heimdall-ee02a9c7c51d069de26f04d8d9464d573ed82d22.zip |
Diffstat (limited to '')
-rw-r--r-- | heimdall/source/BridgeManager.cpp | 46 | ||||
-rw-r--r-- | heimdall/source/BridgeManager.h | 4 | ||||
-rw-r--r-- | heimdall/source/EndFileTransferPacket.h | 12 | ||||
-rw-r--r-- | heimdall/source/EndModemFileTransferPacket.h | 4 | ||||
-rw-r--r-- | heimdall/source/EndPhoneFileTransferPacket.h | 4 | ||||
-rw-r--r-- | heimdall/source/SetupSessionResponse.h | 2 | ||||
-rw-r--r-- | heimdall/source/main.cpp | 45 |
7 files changed, 63 insertions, 54 deletions
diff --git a/heimdall/source/BridgeManager.cpp b/heimdall/source/BridgeManager.cpp index db522ec..787aa88 100644 --- a/heimdall/source/BridgeManager.cpp +++ b/heimdall/source/BridgeManager.cpp @@ -520,7 +520,7 @@ bool BridgeManager::BeginSession(void) const if (!ReceivePacket(&setupSessionResponse)) return (false); - int result = setupSessionResponse.GetUnknown(); + unsigned int result = setupSessionResponse.GetUnknown(); // 131072 for Galaxy S II, 0 for other devices. if (result != 0 && result != 131072) @@ -542,7 +542,7 @@ bool BridgeManager::BeginSession(void) const if (!ReceivePacket(&setupSessionResponse)) return (false); - int deviceType = setupSessionResponse.GetUnknown(); + unsigned int deviceType = setupSessionResponse.GetUnknown(); // TODO: Work out what this value is... it has been either 180 or 0 for Galaxy S phones, 3 on the Galaxy Tab, 190 for SHW-M110S. if (deviceType != 180 && deviceType != 0 && deviceType != 3 && deviceType != 190) @@ -846,7 +846,7 @@ int BridgeManager::ReceivePitFile(unsigned char **pitBuffer) const PitFileResponse *pitFileResponse = new PitFileResponse(); success = ReceivePacket(pitFileResponse); - int fileSize = pitFileResponse->GetFileSize(); + unsigned int fileSize = pitFileResponse->GetFileSize(); delete pitFileResponse; if (!success) @@ -855,7 +855,7 @@ int BridgeManager::ReceivePitFile(unsigned char **pitBuffer) const return (0); } - int transferCount = fileSize / ReceiveFilePartPacket::kDataSize; + unsigned int transferCount = fileSize / ReceiveFilePartPacket::kDataSize; if (fileSize % ReceiveFilePartPacket::kDataSize != 0) transferCount++; @@ -863,7 +863,7 @@ int BridgeManager::ReceivePitFile(unsigned char **pitBuffer) const int offset = 0; // NOTE: The PIT file appears to always be padded out to exactly 4 kilobytes. - for (int i = 0; i < transferCount; i++) + for (unsigned int i = 0; i < transferCount; i++) { DumpPartPitFilePacket *requestPacket = new DumpPartPitFilePacket(i); success = SendPacket(requestPacket); @@ -921,7 +921,7 @@ int BridgeManager::ReceivePitFile(unsigned char **pitBuffer) const return (fileSize); } -bool BridgeManager::SendFile(FILE *file, int destination, int fileIdentifier) const +bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int partitionType, unsigned int fileIdentifier) const { if (destination != EndFileTransferPacket::kDestinationModem && destination != EndFileTransferPacket::kDestinationPhone) { @@ -929,7 +929,7 @@ bool BridgeManager::SendFile(FILE *file, int destination, int fileIdentifier) co return (false); } - if (destination == EndFileTransferPacket::kDestinationModem && fileIdentifier != -1) + if (destination == EndFileTransferPacket::kDestinationModem && fileIdentifier != 0xFFFFFFFF) { Interface::PrintError("The modem file does not have an identifier!\n"); return (false); @@ -959,10 +959,10 @@ bool BridgeManager::SendFile(FILE *file, int destination, int fileIdentifier) co return (false); } - int sequenceCount = fileSize / (kMaxSequenceLength * SendFilePartPacket::kDefaultPacketSize); - int lastSequenceSize = kMaxSequenceLength; - int partialPacketLength = fileSize % SendFilePartPacket::kDefaultPacketSize; - if (fileSize % (kMaxSequenceLength * SendFilePartPacket::kDefaultPacketSize) != 0) + unsigned int sequenceCount = fileSize / (kMaxSequenceLength * SendFilePartPacket::kDefaultPacketSize); + unsigned int lastSequenceSize = kMaxSequenceLength; + unsigned int partialPacketLength = fileSize % SendFilePartPacket::kDefaultPacketSize; + if (fileSize % (kMaxSequenceLength * SendFilePartPacket::kDefaultPacketSize) != 0) { sequenceCount++; @@ -973,15 +973,15 @@ bool BridgeManager::SendFile(FILE *file, int destination, int fileIdentifier) co } long bytesTransferred = 0; - int currentPercent; - int previousPercent = 0; + unsigned int currentPercent; + unsigned int previousPercent = 0; Interface::Print("0%%"); - for (int sequenceIndex = 0; sequenceIndex < sequenceCount; sequenceIndex++) + for (unsigned int sequenceIndex = 0; sequenceIndex < sequenceCount; sequenceIndex++) { // Min(lastSequenceSize, 131072) bool isLastSequence = sequenceIndex == sequenceCount - 1; - int sequenceSize = (isLastSequence) ? lastSequenceSize : kMaxSequenceLength; + unsigned int sequenceSize = (isLastSequence) ? lastSequenceSize : kMaxSequenceLength; FlashPartFileTransferPacket *beginFileTransferPacket = new FlashPartFileTransferPacket(0, 2 * sequenceSize); success = SendPacket(beginFileTransferPacket); @@ -1008,7 +1008,7 @@ bool BridgeManager::SendFile(FILE *file, int destination, int fileIdentifier) co SendFilePartPacket *sendFilePartPacket; SendFilePartResponse *sendFilePartResponse; - for (int filePartIndex = 0; filePartIndex < sequenceSize; filePartIndex++) + for (unsigned int filePartIndex = 0; filePartIndex < sequenceSize; filePartIndex++) { // Send sendFilePartPacket = new SendFilePartPacket(file); @@ -1061,7 +1061,7 @@ bool BridgeManager::SendFile(FILE *file, int destination, int fileIdentifier) co // Response sendFilePartResponse = new SendFilePartResponse(); success = ReceivePacket(sendFilePartResponse); - int receivedPartIndex = sendFilePartResponse->GetPartIndex(); + unsigned int receivedPartIndex = sendFilePartResponse->GetPartIndex(); if (verbose) { @@ -1100,7 +1100,6 @@ bool BridgeManager::SendFile(FILE *file, int destination, int fileIdentifier) co currentPercent = (int)(100.0f * ((float)bytesTransferred / (float)fileSize)); - if (currentPercent != previousPercent) { if (!verbose) @@ -1119,12 +1118,13 @@ bool BridgeManager::SendFile(FILE *file, int destination, int fileIdentifier) co previousPercent = currentPercent; } - int lastFullPacketIndex = 2 * ((isLastSequence && partialPacketLength != 0) ? sequenceSize - 1 : sequenceSize); + unsigned int lastFullPacketIndex = 2 * ((isLastSequence && partialPacketLength != 0) ? sequenceSize - 1 : sequenceSize); if (destination == EndFileTransferPacket::kDestinationPhone) { EndPhoneFileTransferPacket *endPhoneFileTransferPacket = new EndPhoneFileTransferPacket( - (isLastSequence) ? partialPacketLength : 0, lastFullPacketIndex, 0, 0, fileIdentifier, isLastSequence); + (isLastSequence) ? partialPacketLength : 0, lastFullPacketIndex, 0, partitionType, fileIdentifier, + isLastSequence); success = SendPacket(endPhoneFileTransferPacket, 3000); delete endPhoneFileTransferPacket; @@ -1139,7 +1139,7 @@ bool BridgeManager::SendFile(FILE *file, int destination, int fileIdentifier) co else // destination == EndFileTransferPacket::kDestinationModem { EndModemFileTransferPacket *endModemFileTransferPacket = new EndModemFileTransferPacket( - (isLastSequence) ? partialPacketLength : 0, lastFullPacketIndex, 0, 0, isLastSequence); + (isLastSequence) ? partialPacketLength : 0, lastFullPacketIndex, 0, partitionType, isLastSequence); success = SendPacket(endModemFileTransferPacket, 3000); delete endModemFileTransferPacket; @@ -1170,7 +1170,7 @@ bool BridgeManager::SendFile(FILE *file, int destination, int fileIdentifier) co return (true); } -bool BridgeManager::ReceiveDump(int chipType, int chipId, FILE *file) const +bool BridgeManager::ReceiveDump(unsigned int chipType, unsigned int chipId, FILE *file) const { bool success; @@ -1201,7 +1201,7 @@ bool BridgeManager::ReceiveDump(int chipType, int chipId, FILE *file) const transferCount++; char *buffer = new char[kDumpBufferSize * ReceiveFilePartPacket::kDataSize]; - int bufferOffset = 0; + unsigned int bufferOffset = 0; for (unsigned int i = 0; i < transferCount; i++) { diff --git a/heimdall/source/BridgeManager.h b/heimdall/source/BridgeManager.h index f929ac9..a1586c8 100644 --- a/heimdall/source/BridgeManager.h +++ b/heimdall/source/BridgeManager.h @@ -121,8 +121,8 @@ namespace Heimdall bool SendPitFile(FILE *file) const;
int ReceivePitFile(unsigned char **pitBuffer) const;
- bool SendFile(FILE *file, int destination, int fileIdentifier = -1) const;
- bool ReceiveDump(int chipType, int chipId, FILE *file) const;
+ bool SendFile(FILE *file, unsigned int destination, unsigned int partitionType, unsigned int fileIdentifier = 0xFFFFFFFF) const;
+ bool ReceiveDump(unsigned int chipType, unsigned int chipId, FILE *file) const;
bool IsVerbose(void) const
{
diff --git a/heimdall/source/EndFileTransferPacket.h b/heimdall/source/EndFileTransferPacket.h index a67eeaa..73353d5 100644 --- a/heimdall/source/EndFileTransferPacket.h +++ b/heimdall/source/EndFileTransferPacket.h @@ -49,12 +49,12 @@ namespace Heimdall unsigned short partialPacketLength; // Length or (length - 65536) if lastFullPacket is odd.
unsigned int lastFullPacketIndex;
unsigned short unknown1;
- unsigned int unknown2;
+ unsigned int partitionType;
protected:
EndFileTransferPacket(unsigned int destination, unsigned int partialPacketLength, unsigned int lastFullPacketIndex,
- unsigned short unknown1, unsigned int unknown2)
+ unsigned short unknown1, unsigned int partitionType)
: FileTransferPacket(FileTransferPacket::kRequestEnd)
{
this->destination = destination;
@@ -71,7 +71,7 @@ namespace Heimdall }
this->unknown1 = unknown1;
- this->unknown2 = unknown2;
+ this->partitionType = partitionType;
}
public:
@@ -99,9 +99,9 @@ namespace Heimdall return (unknown1);
}
- unsigned int GetUnknown2(void) const
+ unsigned int GetPartitionType(void) const
{
- return (unknown2);
+ return (partitionType);
}
virtual void Pack(void)
@@ -112,7 +112,7 @@ namespace Heimdall PackShort(FileTransferPacket::kDataSize + 4, partialPacketLength);
PackInteger(FileTransferPacket::kDataSize + 6, lastFullPacketIndex);
PackShort(FileTransferPacket::kDataSize + 10, unknown1);
- PackInteger(FileTransferPacket::kDataSize + 12, unknown2);
+ PackInteger(FileTransferPacket::kDataSize + 12, partitionType);
}
};
}
diff --git a/heimdall/source/EndModemFileTransferPacket.h b/heimdall/source/EndModemFileTransferPacket.h index f4f4d56..a2d88ca 100644 --- a/heimdall/source/EndModemFileTransferPacket.h +++ b/heimdall/source/EndModemFileTransferPacket.h @@ -35,9 +35,9 @@ namespace Heimdall public:
EndModemFileTransferPacket(unsigned int partialPacketLength, unsigned int lastFullPacketIndex, unsigned short unknown1,
- unsigned int unknown2, bool endOfFile)
+ unsigned int partitionType, bool endOfFile)
: EndFileTransferPacket(EndFileTransferPacket::kDestinationModem, partialPacketLength,
- lastFullPacketIndex, unknown1, unknown2)
+ lastFullPacketIndex, unknown1, partitionType)
{
this->endOfFile = (endOfFile) ? 1 : 0;
}
diff --git a/heimdall/source/EndPhoneFileTransferPacket.h b/heimdall/source/EndPhoneFileTransferPacket.h index e3af6ed..f035511 100644 --- a/heimdall/source/EndPhoneFileTransferPacket.h +++ b/heimdall/source/EndPhoneFileTransferPacket.h @@ -58,9 +58,9 @@ namespace Heimdall public:
EndPhoneFileTransferPacket(unsigned int partialPacketLength, unsigned int lastFullPacketIndex, unsigned short unknown1,
- unsigned int unknown2, unsigned int fileIdentifier, bool endOfFile)
+ unsigned int partitionType, unsigned int fileIdentifier, bool endOfFile)
: EndFileTransferPacket(EndFileTransferPacket::kDestinationPhone, partialPacketLength,
- lastFullPacketIndex, unknown1, unknown2)
+ lastFullPacketIndex, unknown1, partitionType)
{
this->fileIdentifier = fileIdentifier;
this->endOfFile = (endOfFile) ? 1 : 0;
diff --git a/heimdall/source/SetupSessionResponse.h b/heimdall/source/SetupSessionResponse.h index a107f29..2f854b1 100644 --- a/heimdall/source/SetupSessionResponse.h +++ b/heimdall/source/SetupSessionResponse.h @@ -38,7 +38,7 @@ namespace Heimdall { } - int GetUnknown(void) const + unsigned int GetUnknown(void) const { return (unknown); } diff --git a/heimdall/source/main.cpp b/heimdall/source/main.cpp index 2d05e33..bd4403b 100644 --- a/heimdall/source/main.cpp +++ b/heimdall/source/main.cpp @@ -69,13 +69,15 @@ enum vector<const char *> knownPartitionNames[kKnownPartitionCount]; -struct PartitionNameFilePair +struct PartitionInfo { + unsigned int partitionType; string partitionName; FILE *file; - PartitionNameFilePair(const char *partitionName, FILE *file) + PartitionInfo(unsigned int partitionType, const char *partitionName, FILE *file) { + this->partitionType = partitionType; this->partitionName = partitionName; this->file = file; } @@ -179,7 +181,7 @@ bool openFiles(const map<string, string>& argumentMap, map<string, FILE *>& argu return (true); } -bool mapFilesToPartitions(const map<string, FILE *>& argumentFileMap, const PitData *pitData, map<unsigned int, PartitionNameFilePair>& partitionFileMap) +bool mapFilesToPartitions(const map<string, FILE *>& argumentFileMap, const PitData *pitData, map<unsigned int, PartitionInfo>& partitionInfoMap) { map<string, FILE *>::const_iterator it = argumentFileMap.begin(); @@ -216,8 +218,9 @@ bool mapFilesToPartitions(const map<string, FILE *>& argumentFileMap, const PitD if (!pitEntry && knownPartition == kKnownPartitionPit) { - PartitionNameFilePair partitionNameFilePair(knownPartitionNames[kKnownPartitionPit][0], it->second); - partitionFileMap.insert(pair<unsigned int, PartitionNameFilePair>(static_cast<unsigned int>(-1), partitionNameFilePair)); + // NOTE: We're assuming a PIT file always has partitionType zero. + PartitionInfo partitionInfo(0, knownPartitionNames[kKnownPartitionPit][0], it->second); + partitionInfoMap.insert(pair<unsigned int, PartitionInfo>(0xFFFFFFFF, partitionInfo)); return (true); } @@ -229,8 +232,8 @@ bool mapFilesToPartitions(const map<string, FILE *>& argumentFileMap, const PitD return (false); } - PartitionNameFilePair partitionNameFilePair(pitEntry->GetPartitionName(), it->second); - partitionFileMap.insert(pair<unsigned int, PartitionNameFilePair>(pitEntry->GetPartitionIdentifier(), partitionNameFilePair)); + PartitionInfo partitionInfo(pitEntry->GetPartitionType(), pitEntry->GetPartitionName(), it->second); + partitionInfoMap.insert(pair<unsigned int, PartitionInfo>(pitEntry->GetPartitionIdentifier(), partitionInfo)); } return (true); @@ -261,7 +264,7 @@ int downloadPitFile(BridgeManager *bridgeManager, unsigned char **pitBuffer) return (devicePitFileSize); } -bool flashFile(BridgeManager *bridgeManager, unsigned int partitionIndex, const char *partitionName, FILE *file) +bool flashFile(BridgeManager *bridgeManager, unsigned int partitionType, unsigned int partitionIndex, const char *partitionName, FILE *file) { // PIT files need to be handled differently, try determine if the partition we're flashing to is a PIT partition. bool isPit = false; @@ -310,7 +313,7 @@ bool flashFile(BridgeManager *bridgeManager, unsigned int partitionIndex, const //if (bridgeManager->SendFile(file, EndPhoneFileTransferPacket::kDestinationPhone, // <-- Kies method. WARNING: Doesn't work on Galaxy Tab! // EndPhoneFileTransferPacket::kFileModem)) - if (bridgeManager->SendFile(file, EndModemFileTransferPacket::kDestinationModem)) // <-- Odin method + if (bridgeManager->SendFile(file, EndModemFileTransferPacket::kDestinationModem, partitionType)) // <-- Odin method { Interface::Print("%s upload successful\n", partitionName); return (true); @@ -326,7 +329,7 @@ bool flashFile(BridgeManager *bridgeManager, unsigned int partitionIndex, const // We're uploading to a phone partition Interface::Print("Uploading %s\n", partitionName); - if (bridgeManager->SendFile(file, EndPhoneFileTransferPacket::kDestinationPhone, partitionIndex)) + if (bridgeManager->SendFile(file, EndPhoneFileTransferPacket::kDestinationPhone, partitionType, partitionIndex)) { Interface::Print("%s upload successful\n", partitionName); return (true); @@ -451,10 +454,10 @@ bool attemptFlash(BridgeManager *bridgeManager, map<string, FILE *> argumentFile } } - map<unsigned int, PartitionNameFilePair> partitionFileMap; + map<unsigned int, PartitionInfo> partitionInfoMap; // Map the files being flashed to partitions stored in the PIT file. - if (!mapFilesToPartitions(argumentFileMap, pitData, partitionFileMap)) + if (!mapFilesToPartitions(argumentFileMap, pitData, partitionInfoMap)) { delete pitData; return (false); @@ -465,11 +468,13 @@ bool attemptFlash(BridgeManager *bridgeManager, map<string, FILE *> argumentFile // If we're repartitioning then we need to flash the PIT file first. if (repartition) { - for (map<unsigned int, PartitionNameFilePair>::iterator it = partitionFileMap.begin(); it != partitionFileMap.end(); it++) + for (map<unsigned int, PartitionInfo>::iterator it = partitionInfoMap.begin(); it != partitionInfoMap.end(); it++) { if (it->second.file == localPitFile) { - if (!flashFile(bridgeManager, it->first, it->second.partitionName.c_str(), it->second.file)) + PartitionInfo *partitionInfo = &(it->second); + + if (!flashFile(bridgeManager, partitionInfo->partitionType, it->first, partitionInfo->partitionName.c_str(), partitionInfo->file)) return (false); break; @@ -478,21 +483,25 @@ bool attemptFlash(BridgeManager *bridgeManager, map<string, FILE *> argumentFile } // Flash partitions not involved in the boot process second. - for (map<unsigned int, PartitionNameFilePair>::iterator it = partitionFileMap.begin(); it != partitionFileMap.end(); it++) + for (map<unsigned int, PartitionInfo>::iterator it = partitionInfoMap.begin(); it != partitionInfoMap.end(); it++) { if (!isKnownPartition(it->second.partitionName.c_str(), kKnownPartitionPit) && !isKnownBootPartition(it->second.partitionName.c_str())) { - if (!flashFile(bridgeManager, it->first, it->second.partitionName.c_str(), it->second.file)) + PartitionInfo *partitionInfo = &(it->second); + + if (!flashFile(bridgeManager, partitionInfo->partitionType, it->first, partitionInfo->partitionName.c_str(), partitionInfo->file)) return (false); } } // Flash boot partitions last. - for (map<unsigned int, PartitionNameFilePair>::iterator it = partitionFileMap.begin(); it != partitionFileMap.end(); it++) + for (map<unsigned int, PartitionInfo>::iterator it = partitionInfoMap.begin(); it != partitionInfoMap.end(); it++) { if (isKnownBootPartition(it->second.partitionName.c_str())) { - if (!flashFile(bridgeManager, it->first, it->second.partitionName.c_str(), it->second.file)) + PartitionInfo *partitionInfo = &(it->second); + + if (!flashFile(bridgeManager, partitionInfo->partitionType, it->first, partitionInfo->partitionName.c_str(), partitionInfo->file)) return (false); } } |