summaryrefslogtreecommitdiffstats
path: root/heimdall
diff options
context:
space:
mode:
Diffstat (limited to 'heimdall')
-rw-r--r--heimdall/Makefile.am2
-rw-r--r--heimdall/source/BridgeManager.cpp10
-rw-r--r--heimdall/source/DownloadPitAction.cpp6
-rw-r--r--heimdall/source/FlashAction.cpp36
-rw-r--r--heimdall/source/Heimdall.h13
-rw-r--r--heimdall/source/PrintPitAction.cpp10
-rw-r--r--heimdall/source/SendFilePartPacket.h8
7 files changed, 49 insertions, 36 deletions
diff --git a/heimdall/Makefile.am b/heimdall/Makefile.am
index c793757..cf171e0 100644
--- a/heimdall/Makefile.am
+++ b/heimdall/Makefile.am
@@ -1,8 +1,8 @@
AUTOMAKE_OPTIONS = subdir-objects
ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS}
AM_CPPFLAGS = $(DEPS_CFLAGS) -std=c++0x -I../libpit/Source
+AC_SYS_LARGEFILE
STATIC_LIBS = ../libpit/libpit-1.4.a
-
bin_PROGRAMS = heimdall
heimdall_SOURCES = source/Arguments.cpp \
source/BridgeManager.cpp \
diff --git a/heimdall/source/BridgeManager.cpp b/heimdall/source/BridgeManager.cpp
index 32807ca..dc2926a 100644
--- a/heimdall/source/BridgeManager.cpp
+++ b/heimdall/source/BridgeManager.cpp
@@ -1002,9 +1002,9 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int
return (false);
}
- fseek(file, 0, SEEK_END);
- long fileSize = ftell(file);
- rewind(file);
+ FileSeek(file, 0, SEEK_END);
+ unsigned int fileSize = (unsigned int)FileTell(file);
+ FileRewind(file);
ResponsePacket *fileTransferResponse = new ResponsePacket(ResponsePacket::kResponseTypeFileTransfer);
success = ReceivePacket(fileTransferResponse);
@@ -1031,7 +1031,7 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int
lastSequenceSize++;
}
- long bytesTransferred = 0;
+ unsigned int bytesTransferred = 0;
unsigned int currentPercent;
unsigned int previousPercent = 0;
Interface::Print("0%%");
@@ -1144,7 +1144,7 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int
if (bytesTransferred > fileSize)
bytesTransferred = fileSize;
- currentPercent = (int)(100.0f * ((float)bytesTransferred / (float)fileSize));
+ currentPercent = (unsigned int)(100.0 * ((double)bytesTransferred / (double)fileSize));
if (currentPercent != previousPercent)
{
diff --git a/heimdall/source/DownloadPitAction.cpp b/heimdall/source/DownloadPitAction.cpp
index 000844e..841afd2 100644
--- a/heimdall/source/DownloadPitAction.cpp
+++ b/heimdall/source/DownloadPitAction.cpp
@@ -120,7 +120,7 @@ int DownloadPitAction::Execute(int argc, char **argv)
// Open output file
const char *outputFilename = outputArgument->GetValue().c_str();
- FILE *outputPitFile = fopen(outputFilename, "wb");
+ FILE *outputPitFile = FileOpen(outputFilename, "wb");
if (!outputPitFile)
{
@@ -135,7 +135,7 @@ int DownloadPitAction::Execute(int argc, char **argv)
if (bridgeManager->Initialise(resume) != BridgeManager::kInitialiseSucceeded || !bridgeManager->BeginSession())
{
- fclose(outputPitFile);
+ FileClose(outputPitFile);
delete bridgeManager;
return (1);
@@ -164,7 +164,7 @@ int DownloadPitAction::Execute(int argc, char **argv)
delete bridgeManager;
- fclose(outputPitFile);
+ FileClose(outputPitFile);
delete [] pitBuffer;
return (success ? 0 : 1);
diff --git a/heimdall/source/FlashAction.cpp b/heimdall/source/FlashAction.cpp
index aa08ed8..590e0b5 100644
--- a/heimdall/source/FlashAction.cpp
+++ b/heimdall/source/FlashAction.cpp
@@ -87,7 +87,7 @@ static bool openFiles(Arguments& arguments, vector<PartitionFile>& partitionFile
if (pitArgument)
{
- pitFile = fopen(pitArgument->GetValue().c_str(), "rb");
+ pitFile = FileOpen(pitArgument->GetValue().c_str(), "rb");
if (!pitFile)
{
@@ -109,7 +109,7 @@ static bool openFiles(Arguments& arguments, vector<PartitionFile>& partitionFile
if (arguments.GetArgumentTypes().find(argumentName) == arguments.GetArgumentTypes().end())
{
const StringArgument *stringArgument = static_cast<const StringArgument *>(*it);
- FILE *file = fopen(stringArgument->GetValue().c_str(), "rb");
+ FILE *file = FileOpen(stringArgument->GetValue().c_str(), "rb");
if (!file)
{
@@ -130,34 +130,34 @@ static void closeFiles(vector<PartitionFile>& partitionFiles, FILE *& pitFile)
if (pitFile)
{
- fclose(pitFile);
+ FileClose(pitFile);
pitFile = nullptr;
}
// Close partition files
for (vector<PartitionFile>::const_iterator it = partitionFiles.begin(); it != partitionFiles.end(); it++)
- fclose(it->file);
+ FileClose(it->file);
partitionFiles.clear();
}
static bool sendTotalTransferSize(BridgeManager *bridgeManager, const vector<PartitionFile>& partitionFiles, FILE *pitFile, bool repartition)
{
- int totalBytes = 0;
+ unsigned int totalBytes = 0;
for (vector<PartitionFile>::const_iterator it = partitionFiles.begin(); it != partitionFiles.end(); it++)
{
- fseek(it->file, 0, SEEK_END);
- totalBytes += ftell(it->file);
- rewind(it->file);
+ FileSeek(it->file, 0, SEEK_END);
+ totalBytes += (unsigned int)FileTell(it->file);
+ FileRewind(it->file);
}
if (repartition)
{
- fseek(pitFile, 0, SEEK_END);
- totalBytes += ftell(pitFile);
- rewind(pitFile);
+ FileSeek(pitFile, 0, SEEK_END);
+ totalBytes += (unsigned int)FileTell(pitFile);
+ FileRewind(pitFile);
}
bool success;
@@ -168,7 +168,7 @@ static bool sendTotalTransferSize(BridgeManager *bridgeManager, const vector<Par
if (!success)
{
- Interface::PrintError("Failed to send total bytes device info packet!\n");
+ Interface::PrintError("Failed to send total bytes packet!\n");
return (false);
}
@@ -179,13 +179,13 @@ static bool sendTotalTransferSize(BridgeManager *bridgeManager, const vector<Par
if (!success)
{
- Interface::PrintError("Failed to receive device info response!\n");
+ Interface::PrintError("Failed to receive session total bytes response!\n");
return (false);
}
if (totalBytesResult != 0)
{
- Interface::PrintError("Unexpected device info response!\nExpected: 0\nReceived:%d\n", totalBytesResponse);
+ Interface::PrintError("Unexpected session total bytes response!\nExpected: 0\nReceived:%d\n", totalBytesResponse);
return (false);
}
@@ -316,9 +316,9 @@ static PitData *getPitData(BridgeManager *bridgeManager, FILE *pitFile, bool rep
{
// Load the local pit file into memory.
- fseek(pitFile, 0, SEEK_END);
- long localPitFileSize = ftell(pitFile);
- rewind(pitFile);
+ FileSeek(pitFile, 0, SEEK_END);
+ unsigned int localPitFileSize = (unsigned int)FileTell(pitFile);
+ FileRewind(pitFile);
unsigned char *pitFileBuffer = new unsigned char[localPitFileSize];
memset(pitFileBuffer, 0, localPitFileSize);
@@ -327,7 +327,7 @@ static PitData *getPitData(BridgeManager *bridgeManager, FILE *pitFile, bool rep
if (dataRead > 0)
{
- rewind(pitFile);
+ FileRewind(pitFile);
localPitData = new PitData();
localPitData->Unpack(pitFileBuffer);
diff --git a/heimdall/source/Heimdall.h b/heimdall/source/Heimdall.h
index 5e348c4..3982dd4 100644
--- a/heimdall/source/Heimdall.h
+++ b/heimdall/source/Heimdall.h
@@ -30,6 +30,12 @@
#define va_copy(d, s) ((d) = (s))
#endif
+#define FileOpen(FILE, MODE) fopen(FILE, MODE)
+#define FileClose(FILE) fclose(FILE)
+#define FileSeek(FILE, OFFSET, ORIGIN) _fseeki64(FILE, OFFSET, ORIGIN)
+#define FileTell(FILE) _ftelli64(FILE)
+#define FileRewind(FILE) rewind(FILE)
+
#else
#include "../config.h"
@@ -37,6 +43,13 @@
#if defined(OS_DARWIN) || defined(OS_LINUX)
#include <unistd.h>
#define Sleep(t) usleep(1000*t)
+
+#define FileOpen(FILE, MODE) fopen(FILE, MODE)
+#define FileClose(FILE) fclose(FILE)
+#define FileSeek(FILE, OFFSET, ORIGIN) fseeko(FILE, OFFSET, ORIGIN)
+#define FileTell(FILE) ftello(FILE)
+#define FileRewind(FILE) rewind(FILE)
+
#else
#error operating system not supported
#endif
diff --git a/heimdall/source/PrintPitAction.cpp b/heimdall/source/PrintPitAction.cpp
index 781973d..12c28d1 100644
--- a/heimdall/source/PrintPitAction.cpp
+++ b/heimdall/source/PrintPitAction.cpp
@@ -115,7 +115,7 @@ int PrintPitAction::Execute(int argc, char **argv)
{
const char *filename = fileArgument->GetValue().c_str();
- localPitFile = fopen(filename, "rb");
+ localPitFile = FileOpen(filename, "rb");
if (!localPitFile)
{
@@ -133,14 +133,14 @@ int PrintPitAction::Execute(int argc, char **argv)
{
// Print PIT from file; there's no need for a BridgeManager.
- fseek(localPitFile, 0, SEEK_END);
- long localPitFileSize = ftell(localPitFile);
- rewind(localPitFile);
+ FileSeek(localPitFile, 0, SEEK_END);
+ unsigned int localPitFileSize = (unsigned int)FileTell(localPitFile);
+ FileRewind(localPitFile);
// Load the local pit file into memory.
unsigned char *pitFileBuffer = new unsigned char[localPitFileSize];
size_t dataRead = fread(pitFileBuffer, 1, localPitFileSize, localPitFile); // dataRead is discarded, it's here to remove warnings.
- fclose(localPitFile);
+ FileClose(localPitFile);
PitData *pitData = new PitData();
pitData->Unpack(pitFileBuffer);
diff --git a/heimdall/source/SendFilePartPacket.h b/heimdall/source/SendFilePartPacket.h
index 3ecaa89..38e9dbe 100644
--- a/heimdall/source/SendFilePartPacket.h
+++ b/heimdall/source/SendFilePartPacket.h
@@ -38,11 +38,11 @@ namespace Heimdall
{
memset(data, 0, size);
- long position = ftell(file);
+ unsigned int position = (unsigned int)FileTell(file);
- fseek(file, 0, SEEK_END);
- long fileSize = ftell(file);
- fseek(file, position, SEEK_SET);
+ FileSeek(file, 0, SEEK_END);
+ unsigned int fileSize = (unsigned int)FileTell(file);
+ FileSeek(file, position, SEEK_SET);
// min(fileSize, size)
unsigned int bytesToRead = (fileSize < size) ? fileSize - position : size;