From 70c1e8e5bae373c4660e460703b577336caac8b0 Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Fri, 8 Jul 2011 23:40:28 +1000 Subject: 1.3 beta --- heimdall/source/BeginDumpPacket.h | 2 +- heimdall/source/BridgeManager.cpp | 148 +++++++++++++++----------- heimdall/source/BridgeManager.h | 2 +- heimdall/source/ControlPacket.h | 2 +- heimdall/source/DeviceInfoPacket.h | 2 +- heimdall/source/DeviceInfoResponse.h | 2 +- heimdall/source/DumpPartFileTransferPacket.h | 2 +- heimdall/source/DumpPartPitFilePacket.h | 2 +- heimdall/source/DumpResponse.h | 2 +- heimdall/source/EndFileTransferPacket.h | 2 +- heimdall/source/EndModemFileTransferPacket.h | 2 +- heimdall/source/EndPhoneFileTransferPacket.h | 2 +- heimdall/source/EndSessionPacket.h | 2 +- heimdall/source/FileTransferPacket.h | 2 +- heimdall/source/FlashPartFileTransferPacket.h | 2 +- heimdall/source/FlashPartPitFilePacket.h | 2 +- heimdall/source/Heimdall.h | 2 +- heimdall/source/InboundPacket.h | 2 +- heimdall/source/Interface.cpp | 80 +++++++++----- heimdall/source/Interface.h | 13 ++- heimdall/source/OutboundPacket.h | 2 +- heimdall/source/Packet.h | 2 +- heimdall/source/PitFilePacket.h | 2 +- heimdall/source/PitFileResponse.h | 2 +- heimdall/source/ReceiveFilePartPacket.h | 2 +- heimdall/source/ResponsePacket.h | 2 +- heimdall/source/SendFilePartPacket.h | 2 +- heimdall/source/SendFilePartResponse.h | 2 +- heimdall/source/main.cpp | 14 ++- 29 files changed, 185 insertions(+), 120 deletions(-) (limited to 'heimdall') diff --git a/heimdall/source/BeginDumpPacket.h b/heimdall/source/BeginDumpPacket.h index 4bd6d88..8de4002 100644 --- a/heimdall/source/BeginDumpPacket.h +++ b/heimdall/source/BeginDumpPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 diff --git a/heimdall/source/BridgeManager.cpp b/heimdall/source/BridgeManager.cpp index ef5faa6..af968a9 100644 --- a/heimdall/source/BridgeManager.cpp +++ b/heimdall/source/BridgeManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 @@ -116,7 +116,7 @@ bool BridgeManager::DetectDevice(void) int result = libusb_init(&libusbContext); if (result != LIBUSB_SUCCESS) { - Interface::PrintError("Failed to initialise libusb. Error: %d\n", result); + Interface::PrintError("Failed to initialise libusb. libusb error: %d\n", result); return (false); } @@ -135,7 +135,7 @@ bool BridgeManager::DetectDevice(void) { libusb_free_device_list(devices, deviceCount); - Interface::Print("Device detected"); + Interface::Print("Device detected\n"); return (true); } } @@ -149,14 +149,19 @@ bool BridgeManager::DetectDevice(void) bool BridgeManager::Initialise(void) { + Interface::Print("Initialising connection...\n"); + // Initialise libusb-1.0 int result = libusb_init(&libusbContext); if (result != LIBUSB_SUCCESS) { - Interface::PrintError("Failed to initialise libusb. Error: %d\n", result); + Interface::PrintError("Failed to initialise libusb. libusb error: %d\n", result); + Interface::Print("Failed to connect to device!"); return (false); } + Interface::Print("Detecting device...\n"); + // Get handle to Galaxy S device struct libusb_device **devices; int deviceCount = libusb_get_device_list(libusbContext, &devices); @@ -184,14 +189,14 @@ bool BridgeManager::Initialise(void) if (!heimdallDevice) { - Interface::PrintError("Failed to detect compatible device\n"); + Interface::PrintError("Failed to detect device!\n"); return (false); } result = libusb_open(heimdallDevice, &deviceHandle); if (result != LIBUSB_SUCCESS) { - Interface::PrintError("Failed to access device. Error: %d\n", result); + Interface::PrintError("Failed to access device. libusb error: %d\n", result); return (false); } @@ -264,8 +269,7 @@ bool BridgeManager::Initialise(void) for (int k = 0; k < configDescriptor->usb_interface[i].altsetting[j].bNumEndpoints; k++) { - const libusb_endpoint_descriptor *endpoint = - &configDescriptor->usb_interface[i].altsetting[j].endpoint[k]; + const libusb_endpoint_descriptor *endpoint = &configDescriptor->usb_interface[i].altsetting[j].endpoint[k]; if (verbose) { @@ -280,8 +284,7 @@ bool BridgeManager::Initialise(void) outEndpointAddress = endpoint->bEndpointAddress; } - if (interfaceIndex < 0 - && configDescriptor->usb_interface[i].altsetting[j].bNumEndpoints == 2 + if (interfaceIndex < 0 && configDescriptor->usb_interface[i].altsetting[j].bNumEndpoints == 2 && configDescriptor->usb_interface[i].altsetting[j].bInterfaceClass == CLASS_CDC && inEndpointAddress != -1 && outEndpointAddress != -1) { @@ -301,7 +304,7 @@ bool BridgeManager::Initialise(void) return (false); } - Interface::Print("\nClaiming interface..."); + Interface::Print("Claiming interface...\n"); result = libusb_claim_interface(deviceHandle, interfaceIndex); #ifdef OS_LINUX @@ -309,9 +312,9 @@ bool BridgeManager::Initialise(void) if (result != LIBUSB_SUCCESS) { detachedDriver = true; - Interface::Print(" Failed. Attempting to detach driver...\n"); + Interface::Print("Attempt failed. Detaching driver...\n"); libusb_detach_kernel_driver(deviceHandle, interfaceIndex); - Interface::Print("Claiming interface again..."); + Interface::Print("Claiming interface again...\n"); result = libusb_claim_interface(deviceHandle, interfaceIndex); } @@ -319,21 +322,20 @@ bool BridgeManager::Initialise(void) if (result != LIBUSB_SUCCESS) { - Interface::PrintError(" Failed!\n"); + Interface::PrintError("Claiming interface failed!\n"); return (false); } - Interface::Print(" Success\n"); - - Interface::Print("Setting up interface..."); + Interface::Print("Setting up interface...\n"); result = libusb_set_interface_alt_setting(deviceHandle, interfaceIndex, altSettingIndex); + if (result != LIBUSB_SUCCESS) { - Interface::PrintError(" Failed!\n"); + Interface::PrintError("Setting up interface failed!\n"); return (false); } - Interface::Print(" Success\n"); + Interface::Print("\n"); return (true); } @@ -348,7 +350,8 @@ bool BridgeManager::BeginSession(void) const if (result < 0) { - Interface::PrintError("Failed to initialise usb communication!\n"); + Interface::PrintError("Failed to begin session!\n"); + delete [] dataBuffer; return (false); } @@ -361,7 +364,8 @@ bool BridgeManager::BeginSession(void) const result = libusb_control_transfer(deviceHandle, LIBUSB_REQUEST_TYPE_CLASS, 0x20, 0x0, 0, dataBuffer, 7, 1000); if (result < 0) { - Interface::PrintError("Failed to initialise usb communication!\n"); + Interface::PrintError("Failed to begin session!\n"); + delete [] dataBuffer; return (false); } @@ -369,7 +373,8 @@ bool BridgeManager::BeginSession(void) const result = libusb_control_transfer(deviceHandle, LIBUSB_REQUEST_TYPE_CLASS, 0x22, 0x3, 0, nullptr, 0, 1000); if (result < 0) { - Interface::PrintError("Failed to initialise usb communication!\n"); + Interface::PrintError("Failed to begin session!\n"); + delete [] dataBuffer; return (false); } @@ -377,7 +382,8 @@ bool BridgeManager::BeginSession(void) const result = libusb_control_transfer(deviceHandle, LIBUSB_REQUEST_TYPE_CLASS, 0x22, 0x2, 0, nullptr, 0, 1000); if (result < 0) { - Interface::PrintError("Failed to initialise usb communication!\n"); + Interface::PrintError("Failed to begin session!\n"); + delete [] dataBuffer; return (false); } @@ -390,7 +396,8 @@ bool BridgeManager::BeginSession(void) const result = libusb_control_transfer(deviceHandle, LIBUSB_REQUEST_TYPE_CLASS, 0x20, 0x0, 0, dataBuffer, 7, 1000); if (result < 0) { - Interface::PrintError("Failed to initialise usb communication!\n"); + Interface::PrintError("Failed to begin session!\n"); + delete [] dataBuffer; return (false); } @@ -398,12 +405,13 @@ bool BridgeManager::BeginSession(void) const result = libusb_control_transfer(deviceHandle, LIBUSB_REQUEST_TYPE_CLASS, 0x22, 0x2, 0, nullptr, 0, 1000); if (result < 0) { - Interface::PrintError("Failed to initialise usb communication!\n"); + Interface::PrintError("Failed to begin session!\n"); + delete [] dataBuffer; return (false); } - Interface::Print("Handshaking with Loke..."); + Interface::Print("Handshaking with Loke...\n"); int dataTransferred; @@ -413,10 +421,10 @@ bool BridgeManager::BeginSession(void) const result = libusb_bulk_transfer(deviceHandle, outEndpoint, dataBuffer, 4, &dataTransferred, 1000); if (result < 0) { - Interface::PrintError(" Failed!\n"); - if (verbose) - Interface::PrintError("ERROR: Failed to send data: \"%s\"\n", dataBuffer); + Interface::PrintError("Failed to send data: \"%s\"\n", dataBuffer); + else + Interface::PrintError("Failed to send data!"); delete [] dataBuffer; return (false); @@ -424,10 +432,10 @@ bool BridgeManager::BeginSession(void) const if (dataTransferred != 4) { - Interface::PrintError(" Failed!\n"); - if (verbose) - Interface::PrintError("ERROR: Failed to complete sending data: \"%s\"\n", dataBuffer); + Interface::PrintError("Failed to complete sending of data: \"%s\"\n", dataBuffer); + else + Interface::PrintError("Failed to complete sending of data!"); delete [] dataBuffer; return (false); @@ -439,26 +447,27 @@ bool BridgeManager::BeginSession(void) const result = libusb_bulk_transfer(deviceHandle, inEndpoint, dataBuffer, 7, &dataTransferred, 1000); if (result < 0) { - Interface::PrintError(" Failed!\n"); + Interface::PrintError("Failed to receive response!\n"); - if (verbose) - Interface::PrintError("ERROR: Failed to receive response\n"); delete [] dataBuffer; return (false);; } if (dataTransferred != 4 || memcmp(dataBuffer, "LOKE", 4) != 0) { - Interface::PrintError(" Failed!\n"); + Interface::PrintError("Unexpected communication!\n"); if (verbose) - Interface::PrintError("ERROR: Unexpected communication.\nExpected: \"%s\"\nReceived: \"%s\"\n", "LOKE", dataBuffer); + Interface::PrintError("Expected: \"%s\"\nReceived: \"%s\"\n", "LOKE", dataBuffer); + + Interface::PrintError("Handshake failed!\n"); delete [] dataBuffer; return (false); } - Interface::Print(" Success\n\n"); + Interface::Print("\n"); + return (true); } @@ -473,6 +482,7 @@ bool BridgeManager::EndSession(bool reboot) const if (!success) { Interface::PrintError("Failed to send end session packet!\n"); + return (false); } @@ -483,6 +493,7 @@ bool BridgeManager::EndSession(bool reboot) const if (!success) { Interface::PrintError("Failed to receive session end confirmation!\n"); + return (false); } @@ -497,6 +508,7 @@ bool BridgeManager::EndSession(bool reboot) const if (!success) { Interface::PrintError("Failed to send reboot device packet!\n"); + return (false); } @@ -507,6 +519,7 @@ bool BridgeManager::EndSession(bool reboot) const if (!success) { Interface::PrintError("Failed to receive reboot confirmation!\n"); + return (false); } } @@ -528,13 +541,13 @@ bool BridgeManager::SendPacket(OutboundPacket *packet, int timeout) const int retryDelay = (communicationDelay > 250) ? communicationDelay : 250; if (verbose) - Interface::PrintError("Error %d whilst sending packet. ", result); + Interface::PrintError("libusb error %d whilst sending packet.", result); // Retry for (int i = 0; i < 5; i++) { if (verbose) - Interface::PrintError(" Retrying...\n"); + Interface::PrintErrorSameLine(" Retrying...\n"); // Wait longer each retry Sleep(retryDelay * (i + 1)); @@ -546,11 +559,11 @@ bool BridgeManager::SendPacket(OutboundPacket *packet, int timeout) const break; if (verbose) - Interface::PrintError("Error %d whilst sending packet. ", result); + Interface::PrintError("libusb error %d whilst sending packet.", result); } if (verbose) - Interface::PrintError("\n"); + Interface::PrintErrorSameLine("\n"); } if (communicationDelay != 0) @@ -574,13 +587,13 @@ bool BridgeManager::ReceivePacket(InboundPacket *packet, int timeout) const int retryDelay = (communicationDelay > 250) ? communicationDelay : 250; if (verbose) - Interface::PrintError("Error %d whilst receiving packet. ", result); + Interface::PrintError("libusb error %d whilst receiving packet.", result); // Retry for (int i = 0; i < 5; i++) { if (verbose) - Interface::PrintError(" Retrying\n"); + Interface::PrintErrorSameLine(" Retrying...\n"); // Wait longer each retry Sleep(retryDelay * (i + 1)); @@ -592,7 +605,7 @@ bool BridgeManager::ReceivePacket(InboundPacket *packet, int timeout) const break; if (verbose) - Interface::PrintError("Error %d whilst receiving packet. ", result); + Interface::PrintError("libusb error %d whilst receiving packet.", result); if (i >= 3) { @@ -602,7 +615,7 @@ bool BridgeManager::ReceivePacket(InboundPacket *packet, int timeout) const } if (verbose) - Interface::PrintError("\n"); + Interface::PrintErrorSameLine("\n"); } if (communicationDelay != 0) @@ -623,7 +636,11 @@ bool BridgeManager::RequestDeviceInfo(unsigned int request, int *result) const if (!success) { - Interface::PrintError("Failed to request device info packet!\nFailed Request: %d\n"); + Interface::PrintError("Failed to request device info packet!\n"); + + if (verbose) + Interface::PrintError("Failed request: %u\n", request); + return (false); } @@ -647,7 +664,7 @@ bool BridgeManager::SendPitFile(FILE *file) const if (!success) { - Interface::PrintError("Failed to request sending of PIT file!\n"); + Interface::PrintError("Failed to initialise PIT file transfer!\n"); return (false); } @@ -657,7 +674,7 @@ bool BridgeManager::SendPitFile(FILE *file) const if (!success) { - Interface::PrintError("Failed to confirm sending of PIT file!\n"); + Interface::PrintError("Failed to confirm transfer initialisation!\n"); return (false); } @@ -804,13 +821,13 @@ bool BridgeManager::SendFile(FILE *file, int destination, int fileIdentifier) co { if (destination != EndFileTransferPacket::kDestinationModem && destination != EndFileTransferPacket::kDestinationPhone) { - Interface::PrintError("ERROR: Attempted to send file to unknown destination!\n"); + Interface::PrintError("Attempted to send file to unknown destination!\n"); return (false); } if (destination == EndFileTransferPacket::kDestinationModem && fileIdentifier != -1) { - Interface::PrintError("ERROR: The modem file does not have an identifier!\n"); + Interface::PrintError("The modem file does not have an identifier!\n"); return (false); } @@ -820,7 +837,7 @@ bool BridgeManager::SendFile(FILE *file, int destination, int fileIdentifier) co if (!success) { - Interface::PrintError("Failed to initialise transfer!\n"); + Interface::PrintError("Failed to initialise file transfer!\n"); return (false); } @@ -868,7 +885,7 @@ bool BridgeManager::SendFile(FILE *file, int destination, int fileIdentifier) co if (!success) { - Interface::PrintError("\nFailed to begin file transfer sequence!\n"); + Interface::PrintError("\nERROR: Failed to begin file transfer sequence!\n"); return (false); } @@ -878,7 +895,7 @@ bool BridgeManager::SendFile(FILE *file, int destination, int fileIdentifier) co if (!success) { - Interface::PrintError("\nFailed to confirm beginning of file transfer sequence!\n"); + Interface::PrintError("\nERROR: Failed to confirm beginning of file transfer sequence!\n"); return (false); } @@ -894,7 +911,7 @@ bool BridgeManager::SendFile(FILE *file, int destination, int fileIdentifier) co if (!success) { - Interface::PrintError("\nFailed to send file part packet!\n"); + Interface::PrintError("\nERROR: Failed to send file part packet!\n"); return (false); } @@ -914,11 +931,11 @@ bool BridgeManager::SendFile(FILE *file, int destination, int fileIdentifier) co if (!success) { - Interface::PrintError("\nFailed to receive file part response!\n"); + Interface::PrintError("\nERROR: Failed to receive file part response!\n"); for (int retry = 0; retry < 4; retry++) { - Interface::PrintError("\nRetrying..."); + Interface::PrintError("\nERROR: Retrying..."); // Send sendFilePartPacket = new SendFilePartPacket(file); @@ -927,7 +944,7 @@ bool BridgeManager::SendFile(FILE *file, int destination, int fileIdentifier) co if (!success) { - Interface::PrintError("\nFailed to send file part packet!\n"); + Interface::PrintError("\nERROR: Failed to send file part packet!\n"); return (false); } @@ -973,15 +990,20 @@ bool BridgeManager::SendFile(FILE *file, int destination, int fileIdentifier) co currentPercent = (int)(100.0f * ((float)bytesTransferred / (float)fileSize)); - if (!verbose) + + if (currentPercent != previousPercent) { - if (currentPercent != previousPercent) + if (!verbose) { if (previousPercent < 10) Interface::Print("\b\b%d%%", currentPercent); else Interface::Print("\b\b\b%d%%", currentPercent); } + else + { + Interface::Print("\n%d%%\n", currentPercent); + } } previousPercent = currentPercent; @@ -999,7 +1021,7 @@ bool BridgeManager::SendFile(FILE *file, int destination, int fileIdentifier) co if (!success) { - Interface::PrintError("\nFailed to end phone file transfer sequence!\n"); + Interface::PrintError("\nERROR: Failed to end phone file transfer sequence!\n"); return (false); } } @@ -1013,7 +1035,7 @@ bool BridgeManager::SendFile(FILE *file, int destination, int fileIdentifier) co if (!success) { - Interface::PrintError("\nFailed to end modem file transfer sequence!\n"); + Interface::PrintError("\nERROR: Failed to end modem file transfer sequence!\n"); return (false); } } @@ -1024,7 +1046,7 @@ bool BridgeManager::SendFile(FILE *file, int destination, int fileIdentifier) co if (!success) { - Interface::PrintError("\nFailed to confirm end of file transfer sequence!\n"); + Interface::PrintError("\nERROR: Failed to confirm end of file transfer sequence!\n"); return (false); } } diff --git a/heimdall/source/BridgeManager.h b/heimdall/source/BridgeManager.h index c28cd9c..b488ea6 100644 --- a/heimdall/source/BridgeManager.h +++ b/heimdall/source/BridgeManager.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 diff --git a/heimdall/source/ControlPacket.h b/heimdall/source/ControlPacket.h index 019513e..f003654 100644 --- a/heimdall/source/ControlPacket.h +++ b/heimdall/source/ControlPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 diff --git a/heimdall/source/DeviceInfoPacket.h b/heimdall/source/DeviceInfoPacket.h index 153cdc5..9ec1be3 100644 --- a/heimdall/source/DeviceInfoPacket.h +++ b/heimdall/source/DeviceInfoPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 diff --git a/heimdall/source/DeviceInfoResponse.h b/heimdall/source/DeviceInfoResponse.h index 3bf2d8f..11a0404 100644 --- a/heimdall/source/DeviceInfoResponse.h +++ b/heimdall/source/DeviceInfoResponse.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 diff --git a/heimdall/source/DumpPartFileTransferPacket.h b/heimdall/source/DumpPartFileTransferPacket.h index 60fb8c5..0e8bc7c 100644 --- a/heimdall/source/DumpPartFileTransferPacket.h +++ b/heimdall/source/DumpPartFileTransferPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 diff --git a/heimdall/source/DumpPartPitFilePacket.h b/heimdall/source/DumpPartPitFilePacket.h index 29025c2..39e41db 100644 --- a/heimdall/source/DumpPartPitFilePacket.h +++ b/heimdall/source/DumpPartPitFilePacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 diff --git a/heimdall/source/DumpResponse.h b/heimdall/source/DumpResponse.h index 126982a..639c67f 100644 --- a/heimdall/source/DumpResponse.h +++ b/heimdall/source/DumpResponse.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 diff --git a/heimdall/source/EndFileTransferPacket.h b/heimdall/source/EndFileTransferPacket.h index 3f3d689..a67eeaa 100644 --- a/heimdall/source/EndFileTransferPacket.h +++ b/heimdall/source/EndFileTransferPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 diff --git a/heimdall/source/EndModemFileTransferPacket.h b/heimdall/source/EndModemFileTransferPacket.h index 9dc4c78..f4f4d56 100644 --- a/heimdall/source/EndModemFileTransferPacket.h +++ b/heimdall/source/EndModemFileTransferPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 diff --git a/heimdall/source/EndPhoneFileTransferPacket.h b/heimdall/source/EndPhoneFileTransferPacket.h index f875002..e3af6ed 100644 --- a/heimdall/source/EndPhoneFileTransferPacket.h +++ b/heimdall/source/EndPhoneFileTransferPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 diff --git a/heimdall/source/EndSessionPacket.h b/heimdall/source/EndSessionPacket.h index 15c7162..6547efb 100644 --- a/heimdall/source/EndSessionPacket.h +++ b/heimdall/source/EndSessionPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 diff --git a/heimdall/source/FileTransferPacket.h b/heimdall/source/FileTransferPacket.h index daa6a75..9a2a15e 100644 --- a/heimdall/source/FileTransferPacket.h +++ b/heimdall/source/FileTransferPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 diff --git a/heimdall/source/FlashPartFileTransferPacket.h b/heimdall/source/FlashPartFileTransferPacket.h index 6aa57da..3bb9def 100644 --- a/heimdall/source/FlashPartFileTransferPacket.h +++ b/heimdall/source/FlashPartFileTransferPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 diff --git a/heimdall/source/FlashPartPitFilePacket.h b/heimdall/source/FlashPartPitFilePacket.h index 3974c3c..2eaeef9 100644 --- a/heimdall/source/FlashPartPitFilePacket.h +++ b/heimdall/source/FlashPartPitFilePacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 diff --git a/heimdall/source/Heimdall.h b/heimdall/source/Heimdall.h index 174e7d7..918986b 100644 --- a/heimdall/source/Heimdall.h +++ b/heimdall/source/Heimdall.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 diff --git a/heimdall/source/InboundPacket.h b/heimdall/source/InboundPacket.h index 3285c48..772f3c2 100644 --- a/heimdall/source/InboundPacket.h +++ b/heimdall/source/InboundPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 diff --git a/heimdall/source/Interface.cpp b/heimdall/source/Interface.cpp index 35105bb..6c3c58e 100644 --- a/heimdall/source/Interface.cpp +++ b/heimdall/source/Interface.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 @@ -31,12 +31,16 @@ using namespace std; using namespace libpit; using namespace Heimdall; +bool Interface::stdoutErrors = false; + const char *Interface::version = "v1.3 (beta)"; -const char *Interface::usage = "Usage: heimdall [--verbose] [--no-reboot] [--delay ]\n\ +const char *Interface::usage = "Usage: heimdall \n\ +Common Arguments:\n\ + [--verbose] [--no-reboot] [--stdout-errors] [--delay ]\n\ \n\ -action: flash\n\ -arguments:\n\ +Action: flash\n\ +Arguments:\n\ --repartition --pit [--factoryfs ]\n\ [--cache ] [--dbdata ] [--primary-boot ]\n\ [--secondary-boot ] [--param ] [--kernel ]\n\ @@ -53,31 +57,31 @@ arguments:\n\ [--user-data ] [--fota ] [--hidden ]\n\ [--movinand ] [--data ] [--ums ]\n\ [--emmc ] [-- ]\n\ -description: Flashes firmware files to your phone.\n\ +Description: Flashes firmware files to your phone.\n\ WARNING: If you're repartitioning it's strongly recommended you specify\n\ all files at your disposal, including bootloaders.\n\ \n\ -action: close-pc-screen\n\ -description: Attempts to get rid off the \"connect phone to PC\" screen.\n\ +Action: close-pc-screen\n\ +Description: Attempts to get rid off the \"connect phone to PC\" screen.\n\ \n\ -action: detect\n\ -description: Indicates whether or not a download mode device can be detected.\n\ +Action: detect\n\ +Description: Indicates whether or not a download mode device can be detected.\n\ \n\ -action: dump\n\ -arguments: --chip-type --chip-id --output \n\ -description: Attempts to dump data from the phone corresponding to the\n\ +Action: dump\n\ +Arguments: --chip-type --chip-id --output \n\ +Description: Attempts to dump data from the phone corresponding to the\n\ specified chip type and chip ID.\n\ NOTE: Galaxy S phones don't appear to properly support this functionality.\n\ \n\ -action: print-pit\n\ -description: Dumps the PIT file from the connected device and prints it in\n\ +Action: print-pit\n\ +Description: Dumps the PIT file from the connected device and prints it in\n\ a human readable format.\n\ \n\ -action version\n\ -description: Displays the version number of this binary.\n\ +Action version\n\ +Description: Displays the version number of this binary.\n\ \n\ -action: help\n\ -description: Displays this dialogue.\n"; +Action: help\n\ +Description: Displays this dialogue.\n"; const char *Interface::releaseInfo = "Heimdall %s, Copyright (c) 2010-2011, Benjamin Dobell, Glass Echidna\n\ http://www.glassechidna.com.au\n\n\ @@ -123,11 +127,11 @@ string Interface::commonValueShortArguments[kCommonValueArgCount] = { }; string Interface::commonValuelessArguments[kCommonValuelessArgCount] = { - "-verbose", "-no-reboot" + "-verbose", "-no-reboot", "-stdout-errors" }; string Interface::commonValuelessShortArguments[kCommonValuelessArgCount] = { - "v", "nobt" + "v", "nobt", "err" }; Action Interface::actions[Interface::kActionCount] = { @@ -319,23 +323,49 @@ bool Interface::GetArguments(int argc, char **argv, map& argumen void Interface::Print(const char *format, ...) { va_list args; - va_start(args, format); + vfprintf(stdout, format, args); - va_end(args); + fflush(stdout); - fflush(stdout); // Make sure output isn't buffered. + va_end(args); + } void Interface::PrintError(const char *format, ...) { va_list args; - va_start(args, format); + + fprintf(stderr, "ERROR: "); vfprintf(stderr, format, args); + fflush(stderr); + + if (stdoutErrors) + { + fprintf(stdout, "ERROR: "); + vfprintf(stdout, format, args); + fflush(stdout); + } + va_end(args); +} + +void Interface::PrintErrorSameLine(const char *format, ...) +{ + va_list args; + va_start(args, format); - fflush(stderr); // Make sure output isn't buffered. + vfprintf(stderr, format, args); + fflush(stderr); + + if (stdoutErrors) + { + vfprintf(stdout, format, args); + fflush(stdout); + } + + va_end(args); } void Interface::PrintVersion(void) diff --git a/heimdall/source/Interface.h b/heimdall/source/Interface.h index 7b1741d..81f17e5 100644 --- a/heimdall/source/Interface.h +++ b/heimdall/source/Interface.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 @@ -207,15 +207,18 @@ namespace Heimdall { kCommonValuelessArgVerbose = 0, kCommonValuelessArgNoReboot, + kCommonValuelessArgStdoutErrors, kCommonValuelessArgCount }; private: + + static bool stdoutErrors; static const char *version; static const char *usage; - static const char *releaseInfo; + static const char *releaseInfo; // Flash arguments static string flashValueArguments[kFlashValueArgCount]; @@ -243,6 +246,7 @@ namespace Heimdall static void Print(const char *format, ...); static void PrintError(const char *format, ...); + static void PrintErrorSameLine(const char *format, ...); static void PrintVersion(void); static void PrintUsage(void); @@ -254,6 +258,11 @@ namespace Heimdall { return (flashValueArguments[kFlashValueArgPit]); } + + static void SetStdoutErrors(bool enabled) + { + stdoutErrors = enabled; + } }; } diff --git a/heimdall/source/OutboundPacket.h b/heimdall/source/OutboundPacket.h index 8f8e6c6..83ef844 100644 --- a/heimdall/source/OutboundPacket.h +++ b/heimdall/source/OutboundPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 diff --git a/heimdall/source/Packet.h b/heimdall/source/Packet.h index 33469f1..fb81bd4 100644 --- a/heimdall/source/Packet.h +++ b/heimdall/source/Packet.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 diff --git a/heimdall/source/PitFilePacket.h b/heimdall/source/PitFilePacket.h index d23314e..773de41 100644 --- a/heimdall/source/PitFilePacket.h +++ b/heimdall/source/PitFilePacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 diff --git a/heimdall/source/PitFileResponse.h b/heimdall/source/PitFileResponse.h index bf8f6f6..89035bd 100644 --- a/heimdall/source/PitFileResponse.h +++ b/heimdall/source/PitFileResponse.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 diff --git a/heimdall/source/ReceiveFilePartPacket.h b/heimdall/source/ReceiveFilePartPacket.h index 5671ed4..0e60344 100644 --- a/heimdall/source/ReceiveFilePartPacket.h +++ b/heimdall/source/ReceiveFilePartPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 diff --git a/heimdall/source/ResponsePacket.h b/heimdall/source/ResponsePacket.h index 8cafc95..6094c83 100644 --- a/heimdall/source/ResponsePacket.h +++ b/heimdall/source/ResponsePacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 diff --git a/heimdall/source/SendFilePartPacket.h b/heimdall/source/SendFilePartPacket.h index 7734e2a..94446a8 100644 --- a/heimdall/source/SendFilePartPacket.h +++ b/heimdall/source/SendFilePartPacket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 diff --git a/heimdall/source/SendFilePartResponse.h b/heimdall/source/SendFilePartResponse.h index ba6eb6b..d3a054d 100644 --- a/heimdall/source/SendFilePartResponse.h +++ b/heimdall/source/SendFilePartResponse.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 diff --git a/heimdall/source/main.cpp b/heimdall/source/main.cpp index f24b64a..8ab0b19 100644 --- a/heimdall/source/main.cpp +++ b/heimdall/source/main.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Benjamin Dobell, Glass Echidna +/* Copyright (c) 2010-2011 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 @@ -278,7 +278,7 @@ bool flashFile(BridgeManager *bridgeManager, unsigned int partitionIndex, const } else { - Interface::PrintError("%s upload failed!\n", partitionName); + Interface::Print("%s upload failed!\n", partitionName); return (false); } } @@ -309,7 +309,7 @@ bool flashFile(BridgeManager *bridgeManager, unsigned int partitionIndex, const } else { - Interface::PrintError("%s upload failed!\n", partitionName); + Interface::Print("%s upload failed!\n", partitionName); return (false); } } @@ -325,7 +325,7 @@ bool flashFile(BridgeManager *bridgeManager, unsigned int partitionIndex, const } else { - Interface::PrintError("%s upload failed!\n", partitionName); + Interface::Print("%s upload failed!\n", partitionName); return (false); } } @@ -460,7 +460,9 @@ bool attemptFlash(BridgeManager *bridgeManager, map argumentFile if (!pitsMatch) { - Interface::PrintError("Local and device PIT files don't match and repartition wasn't specified!\n"); + Interface::Print("Local and device PIT files don't match and repartition wasn't specified!\n"); + Interface::Print("Flash aborted!\n"); + Interface::PrintError("Flash aborted!\n"); delete pitData; return (false); @@ -595,6 +597,8 @@ int main(int argc, char **argv) bool verbose = argumentMap.find(Interface::commonValuelessArguments[Interface::kCommonValuelessArgVerbose]) != argumentMap.end(); bool reboot = argumentMap.find(Interface::commonValuelessArguments[Interface::kCommonValuelessArgNoReboot]) == argumentMap.end(); + Interface::SetStdoutErrors(argumentMap.find(Interface::commonValuelessArguments[Interface::kCommonValuelessArgStdoutErrors]) != argumentMap.end()); + int communicationDelay = BridgeManager::kCommunicationDelayDefault; if (argumentMap.find(Interface::commonValueArguments[Interface::kCommonValueArgDelay]) != argumentMap.end()) communicationDelay = atoi(argumentMap.find(Interface::commonValueArguments[Interface::kCommonValueArgDelay])->second.c_str()); -- cgit v1.1