diff options
author | Benjamin Dobell <benjamin.dobell+git@glassechidna.com.au> | 2014-11-16 21:02:07 +0100 |
---|---|---|
committer | Benjamin Dobell <benjamin.dobell+git@glassechidna.com.au> | 2014-11-16 21:02:39 +0100 |
commit | 1ddfdc1a880279ce07b2c43f60b7aa138d4ad315 (patch) | |
tree | 4ea142d9013a6dfdf84cab401f561d45ff8ccad4 | |
parent | More empty transfer craziness, this time when receving packets (diff) | |
download | Heimdall-1ddfdc1a880279ce07b2c43f60b7aa138d4ad315.tar Heimdall-1ddfdc1a880279ce07b2c43f60b7aa138d4ad315.tar.gz Heimdall-1ddfdc1a880279ce07b2c43f60b7aa138d4ad315.tar.bz2 Heimdall-1ddfdc1a880279ce07b2c43f60b7aa138d4ad315.tar.lz Heimdall-1ddfdc1a880279ce07b2c43f60b7aa138d4ad315.tar.xz Heimdall-1ddfdc1a880279ce07b2c43f60b7aa138d4ad315.tar.zst Heimdall-1ddfdc1a880279ce07b2c43f60b7aa138d4ad315.zip |
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | CMakeLists.txt | 10 | ||||
-rw-r--r-- | cmake/Findlibusb-1.0.cmake | 98 | ||||
-rw-r--r-- | cmake/LargeFiles.c | 15 | ||||
-rw-r--r-- | cmake/LargeFiles.cmake | 87 | ||||
-rw-r--r-- | cmake/LargeFiles64.c | 16 | ||||
-rw-r--r-- | cmake/LargeFilesWindows.c | 8 | ||||
-rw-r--r-- | heimdall/CMakeLists.txt | 88 | ||||
-rw-r--r-- | heimdall/source/BridgeManager.cpp | 6 | ||||
-rw-r--r-- | heimdall/source/Heimdall.h | 16 | ||||
-rw-r--r-- | libpit/CMakeLists.txt | 10 | ||||
-rw-r--r-- | libusb-1.0/lib/mingw/libusb-1.0.a | bin | 0 -> 499112 bytes |
12 files changed, 342 insertions, 13 deletions
@@ -1,5 +1,6 @@ .DS_Store ._* +.idea/ Debug/ Release/ Release (Static)/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..ff25585 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 2.8.4) + +set(CMAKE_MODULE_PATH + ${CMAKE_SOURCE_DIR}/cmake + ${CMAKE_MODULE_PATH}) + +project(Heimdall) + +add_subdirectory(libpit) +add_subdirectory(heimdall) diff --git a/cmake/Findlibusb-1.0.cmake b/cmake/Findlibusb-1.0.cmake new file mode 100644 index 0000000..bc63763 --- /dev/null +++ b/cmake/Findlibusb-1.0.cmake @@ -0,0 +1,98 @@ +# - Try to find libusb-1.0 +# Once done this will define +# +# LIBUSB_1_FOUND - system has libusb +# LIBUSB_1_INCLUDE_DIRS - the libusb include directory +# LIBUSB_1_LIBRARIES - Link these to use libusb +# LIBUSB_1_DEFINITIONS - Compiler switches required for using libusb +# +# Adapted from cmake-modules Google Code project +# +# Copyright (c) 2006 Andreas Schneider <mail@cynapses.org> +# +# (Changes for libusb) Copyright (c) 2008 Kyle Machulis <kyle@nonpolynomial.com> +# +# Redistribution and use is allowed according to the terms of the New BSD license. +# +# CMake-Modules Project New BSD License +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the name of the CMake-Modules Project nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + + +if (LIBUSB_1_LIBRARIES AND LIBUSB_1_INCLUDE_DIRS) + # in cache already + set(LIBUSB_FOUND TRUE) +else (LIBUSB_1_LIBRARIES AND LIBUSB_1_INCLUDE_DIRS) + find_path(LIBUSB_1_INCLUDE_DIR + NAMES + libusb.h + PATHS + /usr/include + /usr/local/include + /opt/local/include + /sw/include + PATH_SUFFIXES + libusb-1.0 + ) + + find_library(LIBUSB_1_LIBRARY + NAMES + usb-1.0 usb + PATHS + /usr/lib + /usr/local/lib + /opt/local/lib + /sw/lib + ) + + set(LIBUSB_1_INCLUDE_DIRS + ${LIBUSB_1_INCLUDE_DIR} + ) + set(LIBUSB_1_LIBRARIES + ${LIBUSB_1_LIBRARY} +) + + if (LIBUSB_1_INCLUDE_DIRS AND LIBUSB_1_LIBRARIES) + set(LIBUSB_1_FOUND TRUE) + endif (LIBUSB_1_INCLUDE_DIRS AND LIBUSB_1_LIBRARIES) + + if (LIBUSB_1_FOUND) + if (NOT libusb_1_FIND_QUIETLY) + message(STATUS "Found libusb-1.0:") + message(STATUS " - Includes: ${LIBUSB_1_INCLUDE_DIRS}") + message(STATUS " - Libraries: ${LIBUSB_1_LIBRARIES}") + endif (NOT libusb_1_FIND_QUIETLY) + else (LIBUSB_1_FOUND) + if (libusb_1_FIND_REQUIRED) + message(FATAL_ERROR "Could not find libusb") + endif (libusb_1_FIND_REQUIRED) + endif (LIBUSB_1_FOUND) + + # show the LIBUSB_1_INCLUDE_DIRS and LIBUSB_1_LIBRARIES variables only in the advanced view + mark_as_advanced(LIBUSB_1_INCLUDE_DIRS LIBUSB_1_LIBRARIES) + +endif (LIBUSB_1_LIBRARIES AND LIBUSB_1_INCLUDE_DIRS)
\ No newline at end of file diff --git a/cmake/LargeFiles.c b/cmake/LargeFiles.c new file mode 100644 index 0000000..d11ea97 --- /dev/null +++ b/cmake/LargeFiles.c @@ -0,0 +1,15 @@ +#include <sys/types.h> +#include <stdio.h> +#include <stdlib.h> + +#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) +#define VALID_ARRAY_LENGTH 1 +#define INVALID_ARRAY_LENGTH -1 + +int main(int argc, const char **argv) +{ + int a[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? VALID_ARRAY_LENGTH : INVALID_ARRAY_LENGTH]; + off_t offset = ftello(NULL); + fseeko(NULL, offset, SEEK_SET); + return 0; +} diff --git a/cmake/LargeFiles.cmake b/cmake/LargeFiles.cmake new file mode 100644 index 0000000..b59295a --- /dev/null +++ b/cmake/LargeFiles.cmake @@ -0,0 +1,87 @@ +macro(test_large_files VARIABLE USE_64_SUFFIX) + if(NOT DEFINED ${VARIABLE}) + message(STATUS "Checking if large (64-bit) file support is available...") + + if(${USE_64_SUFFIX}) + set(SUFFIX_64 "64") + else(${USE_64_SUFFIX}) + set(SUFFIX_64 "") + endif(${USE_64_SUFFIX}) + + # First try without any macros defined + try_compile(LARGE_FILES_SUPPORTED "${CMAKE_BINARY_DIR}" + "${CMAKE_MODULE_PATH}/LargeFiles${SUFFIX_64}.c") + + if(NOT LARGE_FILES_SUPPORTED) + # Try with C macro _FILE_OFFSET_BITS=64 + try_compile(LARGE_FILES_SUPPORTED "${CMAKE_BINARY_DIR}" + "${CMAKE_MODULE_PATH}/LargeFiles${SUFFIX_64}.c" + COMPILE_DEFINITIONS "-D_FILE_OFFSET_BITS=64") + + if(LARGE_FILES_SUPPORTED) + set(_FILE_OFFSET_BITS=64 CACHE INTERNAL "C macro _FILE_OFFSET_BITS=64 is required for 64-bit file support") + endif(LARGE_FILES_SUPPORTED) + endif(NOT LARGE_FILES_SUPPORTED) + + if(NOT LARGE_FILES_SUPPORTED) + # Try with C macro _LARGEFILE_SOURCE + + try_compile(LARGE_FILES_SUPPORTED "${CMAKE_BINARY_DIR}" + "${CMAKE_MODULE_PATH}/LargeFiles${SUFFIX_64}.c" + COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE${SUFFIX_64}") + + if(LARGE_FILES_SUPPORTED) + set(_LARGEFILE_SOURCE${SUFFIX_64}=1 CACHE INTERNAL "C macro _LARGEFILE_SOURCE${SUFFIX_64} is required for 64-bit file support") + endif(LARGE_FILES_SUPPORTED) + endif(NOT LARGE_FILES_SUPPORTED) + + if(NOT LARGE_FILES_SUPPORTED) + # Try with both C macro _FILE_OFFSET_BITS=64 and _LARGEFILE_SOURCE + try_compile(LARGE_FILES_SUPPORTED "${CMAKE_BINARY_DIR}" + "${CMAKE_MODULE_PATH}/LargeFiles${SUFFIX_64}.c" + COMPILE_DEFINITIONS "-D_FILE_OFFSET_BITS=64" "-D_LARGEFILE_SOURCE${SUFFIX_64}") + + if(LARGE_FILES_SUPPORTED) + set(_FILE_OFFSET_BITS=64 CACHE INTERNAL "C macro _FILE_OFFSET_BITS=64 is required for 64-bit file support") + set(_LARGEFILE_SOURCE${SUFFIX_64}=1 CACHE INTERNAL "C macro _LARGEFILE_SOURCE${SUFFIX_64} is required for 64-bit file support") + endif(LARGE_FILES_SUPPORTED) + endif(NOT LARGE_FILES_SUPPORTED) + + if(NOT LARGE_FILES_SUPPORTED) + # Maybe we are using the Windows C standard library + try_compile(LARGE_FILES_SUPPORTED "${CMAKE_BINARY_DIR}" + "${CMAKE_MODULE_PATH}/LargeFilesWindows.c") + endif(NOT LARGE_FILES_SUPPORTED) + + if(LARGE_FILES_SUPPORTED) + message(STATUS "Checking if large (64-bit) file support is available - yes") + set(${VARIABLE} 1 CACHE INTERNAL "Is large file support available?") + else(LARGE_FILES_SUPPORTED) + message(STATUS "Checking if large (64-bit) file support is available - no") + set(${VARIABLE} 0 CACHE INTERNAL "Is large file support available?") + endif(LARGE_FILES_SUPPORTED) + endif(NOT DEFINED ${VARIABLE}) +endmacro(test_large_files VARIABLE USE_64_SUFFIX) + +macro(use_large_files TARGET USE_64_SUFFIX) + test_large_files(USING_LARGE_FILES ${USE_64_SUFFIX}) + + if(USING_LARGE_FILES) + if(DEFINED _FILE_OFFSET_BITS) + set_property(TARGET ${TARGET} + APPEND PROPERTY COMPILE_DEFINITIONS "-D_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS}") + endif(DEFINED _FILE_OFFSET_BITS) + + if(DEFINED _LARGEFILE_SOURCE) + set_property(TARGET ${TARGET} + APPEND PROPERTY COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE") + endif(DEFINED _LARGEFILE_SOURCE) + + if(DEFINED _LARGEFILE_SOURCE64) + set_property(TARGET ${TARGET} + APPEND PROPERTY COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE64") + endif(DEFINED _LARGEFILE_SOURCE64) + else(USING_LARGE_FILES) + message(FATAL_ERROR "Large file support not available") + endif(USING_LARGE_FILES) +endmacro(use_large_files TARGET USE_64_SUFFIX) diff --git a/cmake/LargeFiles64.c b/cmake/LargeFiles64.c new file mode 100644 index 0000000..57826b7 --- /dev/null +++ b/cmake/LargeFiles64.c @@ -0,0 +1,16 @@ +#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+
+#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define VALID_ARRAY_LENGTH 1
+#define INVALID_ARRAY_LENGTH -1
+
+int main(int argc, const char **argv)
+{
+ int a[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? VALID_ARRAY_LENGTH : INVALID_ARRAY_LENGTH];
+ off_t offset = ftello64(NULL);
+ fseeko64(NULL, offset, SEEK_SET);
+ return 0;
+}
diff --git a/cmake/LargeFilesWindows.c b/cmake/LargeFilesWindows.c new file mode 100644 index 0000000..85fadd8 --- /dev/null +++ b/cmake/LargeFilesWindows.c @@ -0,0 +1,8 @@ +#include <stdio.h> + +int main() +{ + __int64 off = 0; + _fseeki64(NULL, off, SEEK_SET); + return 0; +} diff --git a/heimdall/CMakeLists.txt b/heimdall/CMakeLists.txt new file mode 100644 index 0000000..8887211 --- /dev/null +++ b/heimdall/CMakeLists.txt @@ -0,0 +1,88 @@ +cmake_minimum_required(VERSION 2.8.4) + +project(heimdall) + +if(WIN32) + set(LIBUSB_1_INCLUDE_DIRS + ../libusb-1.0/include) +else(WIN32) + find_package(libusb-1.0 REQUIRED) +endif(WIN32) + +set(LIBPIT_INCLUDE_DIRS + ../libpit/Source) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") + +include_directories(SYSTEM ${LIBUSB_1_INCLUDE_DIRS}) + +include_directories(${LIBPIT_INCLUDE_DIRS}) + +set(HEIMDALL_SOURCE_FILES + source/Arguments.cpp + source/Arguments.h + source/BeginDumpPacket.h + source/BeginSessionPacket.h + source/BridgeManager.cpp + source/BridgeManager.h + source/ClosePcScreenAction.cpp + source/ClosePcScreenAction.h + source/ControlPacket.h + source/DetectAction.cpp + source/DetectAction.h + source/DeviceTypePacket.h + source/DownloadPitAction.cpp + source/DownloadPitAction.h + source/DumpPartFileTransferPacket.h + source/DumpPartPitFilePacket.h + source/DumpResponse.h + source/EndFileTransferPacket.h + source/EndModemFileTransferPacket.h + source/EndPhoneFileTransferPacket.h + source/EndPitFileTransferPacket.h + source/EndSessionPacket.h + source/FilePartSizePacket.h + source/FileTransferPacket.h + source/FlashAction.cpp + source/FlashAction.h + source/FlashPartFileTransferPacket.h + source/FlashPartPitFilePacket.h + source/Heimdall.h + source/HelpAction.cpp + source/HelpAction.h + source/InboundPacket.h + source/InfoAction.cpp + source/InfoAction.h + source/Interface.cpp + source/Interface.h + source/main.cpp + source/OutboundPacket.h + source/Packet.h + source/PitFilePacket.h + source/PitFileResponse.h + source/PrintPitAction.cpp + source/PrintPitAction.h + source/ReceiveFilePartPacket.h + source/ResponsePacket.h + source/SendFilePartPacket.h + source/SendFilePartResponse.h + source/SessionSetupPacket.h + source/SessionSetupResponse.h + source/SetupSessionPacket.h + source/SetupSessionResponse.h + source/TotalBytesPacket.h + source/Utility.cpp + source/Utility.h + source/VersionAction.cpp + source/VersionAction.h) + +include(LargeFiles) +use_large_files(heimdall YES) +add_executable(heimdall ${HEIMDALL_SOURCE_FILES}) + +target_link_libraries(heimdall PRIVATE pit) + +LINK_DIRECTORIES(../libusb-1.0/lib/mingw) +if(WIN32) + target_link_libraries(heimdall PRIVATE ${CMAKE_SOURCE_DIR}/libusb-1.0/lib/mingw/libusb-1.0.a) +endif(WIN32) diff --git a/heimdall/source/BridgeManager.cpp b/heimdall/source/BridgeManager.cpp index 9b8fdfa..8fb678c 100644 --- a/heimdall/source/BridgeManager.cpp +++ b/heimdall/source/BridgeManager.cpp @@ -19,7 +19,7 @@ THE SOFTWARE.*/ // C Standard Library -#include <stdio.h> +#include <cstdio> // libusb #include <libusb.h> @@ -53,7 +53,9 @@ #include "SessionSetupResponse.h" // Future versions of libusb will use usb_interface instead of interface. +#ifndef usb_interface #define usb_interface interface +#endif #define USB_CLASS_CDC_DATA 0x0A @@ -1035,7 +1037,7 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int { sequenceCount++; - int lastSequenceBytes = fileSize % (fileTransferSequenceMaxLength * fileTransferPacketSize); + unsigned int lastSequenceBytes = fileSize % (fileTransferSequenceMaxLength * fileTransferPacketSize); lastSequenceSize = lastSequenceBytes / fileTransferPacketSize; if (partialPacketByteCount != 0) diff --git a/heimdall/source/Heimdall.h b/heimdall/source/Heimdall.h index 3982dd4..c5c11ef 100644 --- a/heimdall/source/Heimdall.h +++ b/heimdall/source/Heimdall.h @@ -21,7 +21,7 @@ #ifndef HEIMDALL_H
#define HEIMDALL_H
-#ifdef OS_WINDOWS
+#ifdef _MSC_VER // Microsoft Visual C Standard Library
#include <Windows.h>
#undef GetBinaryType
@@ -36,24 +36,18 @@ #define FileTell(FILE) _ftelli64(FILE)
#define FileRewind(FILE) rewind(FILE)
-#else
+#else // POSIX Standard Library
-#include "../config.h"
-
-#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 FileSeek(FILE, OFFSET, ORIGIN) fseeko64(FILE, OFFSET, ORIGIN)
+#define FileTell(FILE) ftello64(FILE)
#define FileRewind(FILE) rewind(FILE)
-#else
-#error operating system not supported
-#endif
-
#endif
#if (!(defined _MSC_VER) || (_MSC_VER < 1700))
diff --git a/libpit/CMakeLists.txt b/libpit/CMakeLists.txt new file mode 100644 index 0000000..8d12868 --- /dev/null +++ b/libpit/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 2.8.4) +project(libpit) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") + +set(LIBPIT_SOURCE_FILES + Source/libpit.cpp + Source/libpit.h) + +add_library(pit STATIC ${LIBPIT_SOURCE_FILES}) diff --git a/libusb-1.0/lib/mingw/libusb-1.0.a b/libusb-1.0/lib/mingw/libusb-1.0.a Binary files differnew file mode 100644 index 0000000..7b0f6cf --- /dev/null +++ b/libusb-1.0/lib/mingw/libusb-1.0.a |