* Fix segfault when file to flash does not exist
* Rename some fields in the flashing protocol, MMC4096 seem to be UFS,
and what I thought was the protocol number seem to be the number of
logical units in the storage
Check needs to be right after it is opened, before we try to seek in
it. Before this fix, heimdall segfaults if file does not exist.
Fixes commit 60ab9bbaff ("FlashAction: Make sure file fit partition
before flashing")
This assumption was wrong. The number is really the number of logical
units in the storage, which tends to increase over time as the storage
space is increased I suppose.
This reverts commit e916c679ed.
Except for general cleanup we have these functional changes:
* Change printed pit header: last unknown number seem to be the Odin
protocol version.
* Only run libusb_reset_device on ubuntu: on some distros/devices
resetting the device causes the handshake to fail (observered for
degaswifi/SM-T230).
It seems that only ubuntu needs libusb_reset_device for successful
handshake. On most distros and device it works with or without, but
for some devices (like degaswifi/SM-T230 with a Marvell PXA 1088 SOC)
it causes handshake to fail.
Probably libusb_reset_device causes issues only for some devices, but
there seem to be no way to distinguish which ones from Heimdall (not
based on Odin protocol version or SOC at least).
Fixes commit 07a14d4aa8 ("InitialiseProtocol: reset device before
handshake").
And in that case there now exists a fifth version of the Odin
protocol, seen on Galaxy S9 and newer.
In total we have seen these versions (as of January 2022):
* 0, on devices from around 2014 or older
* 3, on devices from around 2015
* 4, on devices from around 2016 - 2017
* 5, on devices from around 2018 or newer
Go from 1.4.2 to 2.0.0 to indicate that maintainer, and upstream repo,
has changed.
Main changes:
* A check so that partition is not smaller than file size has been
added, to make it a bit harder to overwrite things on the emmc by
accident:
60ab9bbaff
* libusb_reset_device is needed before handshake on ubuntu:
https://github.com/Benjamin-Dobell/Heimdall/pull/478
* Support for flashing images larger than 3.5 GB:
https://github.com/Benjamin-Dobell/Heimdall/pull/459
* Avoid libusb_set_interface_alt_setting when it anyways doesn't do
anything: https://github.com/Benjamin-Dobell/Heimdall/issues/497, fixed
in: 2ecc98020c
* Some compilation issues on
[freeBSD](64bd479db6),
[Android](719edaff9e)
and
[macOS](6ede1f1f33)
have been fixed.
All changes are verified to be compatible for devices as old as Galaxy
S3, and as new as Galaxy S8 (I don't have access to anything older, or
newer, than that).
Can be used to skip the check that verifies that all files fit in the
partitions. The option need to be set if we are to be able to flash
stock android to some devices, for example klimtlte (sboot.bin is
larger than the BOOTLOADER partition on this device).
Partition size is calculated as block count times a block size of 512
for DeviceType 2 and 4096 for DeviceType 8.
Flashing stock android on some devices fail due to some partitions
being too small for the corresponding file. This is the case on
klimtlte (and other exynos5420 devices), where sboot.bin does not fit
into the BOOTLOADER partition.
Tests done:
* Flash stock android (A500FXXS1CSB2) to a5lte, works fine
* Flash stock android (I9300XXUGPE1) to i9300, works fine
* Flash stock android (I9505XXUPQG1) to i9505, works fine
* Flash stock android (G930FXXU8ETI2) to herolte (with block
size 4096), works fine
* Flash stock android (T705XXU1CPL1) to klimtlte, fails due to
BOOTLOADER partition being smaller than sboot.bin, the file has a
size of 1148160, and the partition 2046*512=1047552
The unknown string is "COM_TAR2" in all devices I have access to. The
last unknown 4 bytes might be some sort of version, in old devices it
is 0000, in Galaxy S6 0003, in Galaxy S7 and S8 0004 and in Galaxy S9
and tab S6 lite 0005.
The CPU/bootloader string looks something like:
* LSI5410 - Seen in Exynos 5420, 5433 devices (and perhaps others)
* LSI7420 - Seen in Exynos 7420, 8890, 8895 devices (and perhaps others)
* LSI7880 - Seen in a5y17lte (exynos 7880)
* LSI9610 - Seen in gta4xl (exynos 9611)
* LSI9810 - Seen in star2lte (exynos 9810)
* Mx - Seen in Galaxy S3 (device codename is m0/m3)
* MSM8916 - Seen in MSM8916 devices
* MSM8960 - Seen in jflte (and probably in others, jflte has a APQ8064AB CPU)
Carrying around this (now outdated) driver in the repo seems
unnecessary. Windows users can download latest from
https://zadig.akeo.ie/downloads/ instead.
Testing on 32bit arm have weird issues where the build failed if
run/continued without configuring again.
With these scripts we also require less files, no .c files in cmake/.
One downside is that we now require at least Visual Studio
2005 (MSVCR80) for compiling on windows (and there's no check for this
currently).
We should only need to define it for old versions of MSVC. On linux
it seems that defining nullptr does not really have any downsides, but
on android we get some obscure compiler errors due to how nullptr is
defined. Fix nullptr check and thereby make heimdall compile on
android.
Error message looked something like:
[ 6%] Building CXX object libpit/CMakeFiles/pit.dir/source/libpit.cpp.o
In file included from /data/data/com.termux/files/home/Heimdall/libpit/source/libpit.cpp:22:
In file included from /data/data/com.termux/files/home/Heimdall/libpit/source/libpit.h:38:
In file included from /data/data/com.termux/files/usr/include/c++/v1/string:504:
In file included from /data/data/com.termux/files/usr/include/c++/v1/string_view:175:
In file included from /data/data/com.termux/files/usr/include/c++/v1/__string:57:
In file included from /data/data/com.termux/files/usr/include/c++/v1/algorithm:643:
/data/data/com.termux/files/usr/include/c++/v1/memory:2268:9: error: cannot initialize a member subobject of type 'libpit::PitEntry **' with an rvalue of type 'int'
: __value_(_VSTD::forward<_Up>(__u))
^ ~~~~~~~~~~~~~~~~~~~~~~~~
/data/data/com.termux/files/usr/include/c++/v1/memory:2353:9: note: in instantiation of function template specialization 'std::__compressed_pair_elem<libpit::PitEntry **, 0, false>::__compressed_pair_elem<int, void>' requested here
: _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {}
^
/data/data/com.termux/files/usr/include/c++/v1/vector:436:7: note: in instantiation of function template specialization 'std::__compressed_pair<libpit::PitEntry **, std::allocator<libpit::PitEntry *>>::__compressed_pair<int, std::__default_init_tag>' requested here
__end_cap_(nullptr, __default_init_tag())
^
/data/data/com.termux/files/usr/include/c++/v1/vector:495:5: note: in instantiation of member function 'std::__vector_base<libpit::PitEntry *, std::allocator<libpit::PitEntry *>>::__vector_base' requested here
vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
^
/data/data/com.termux/files/home/projects/Heimdall/libpit/source/libpit.cpp:65:10: note: in instantiation of member function 'std::vector<libpit::PitEntry *>::vector' requested here
PitData::PitData()
^
Some (older) devices seem to have a problem with this:
https://github.com/Benjamin-Dobell/Heimdall/issues/497
As far as I can see from logs, alt_setting is always 0, so with this
change libusb_set_interface_alt_setting will probably never be run.
tests: flash and boot recovery onto SM-G955
Heimdall fails to handshake with device on my Linux installation:
Initialising protocol...
ERROR: libusb error -7 whilst sending bulk transfer. Retrying...
ERROR: libusb error -7 whilst sending bulk transfer. Retrying...
ERROR: libusb error -7 whilst sending bulk transfer. Retrying...
ERROR: libusb error -7 whilst sending bulk transfer. Retrying...
ERROR: libusb error -7 whilst sending bulk transfer. Retrying...
ERROR: libusb error -7 whilst sending bulk transfer.
ERROR: Failed to send handshake!
ERROR: Failed to receive handshake response. Result: -7
ERROR: Protocol initialisation failed!
However, with the same USB cable, port and device, Heimdall
successfully handshake with the device on Windows via WinUSB.
This indicates handling of USB devices of host (AMD X570) on
Linux might lead to undesired results. Though, without further
testing, the interference from userspace (Ubuntu 20.04, KDE) can
not be ruled out.
Thus, this patch calls libusb_reset_device to ensure
the USB port is in a clean state before we send the data.
Fixes issues with newer devices and hosts.
Signed-off-by: Jesse Chan <jc@linux.com>
Use QRandomGenerator instead. Fixes compilation warning:
/home/grimler/Heimdall/heimdall-frontend/source/Packaging.cpp: In static member function ‘static QString HeimdallFrontend::Packaging::ClashlessFilename(const QList<HeimdallFrontend::FileInfo>&, const QString&)’:
/home/grimler/Heimdall/heimdall-frontend/source/Packaging.cpp:910:34: warning: ‘int qrand()’ is deprecated: use QRandomGenerator instead [-Wdeprecated-declarations]
910 | filename.append(QChar(qrand() % ('Z' - 'A' + 1) + 'A'));
| ^
In file included from /usr/include/qt/QtCore/qchar.h:43,
from /usr/include/qt/QtCore/qstring.h:49,
from /usr/include/qt/QtCore/qdatetime.h:44,
from /usr/include/qt/QtCore/QDateTime:1,
from /home/grimler/Heimdall/heimdall-frontend/source/Packaging.cpp:32:
/usr/include/qt/QtCore/qglobal.h:1274:80: note: declared here
1274 | Q_CORE_EXPORT QT_DEPRECATED_VERSION_X_5_15("use QRandomGenerator instead") int qrand();
| ^~~~~
Use QString::asprintf instead. Fixes compilation warning:
/home/grimler/Heimdall/heimdall-frontend/source/mainwindow.cpp: In member function ‘void HeimdallFrontend::MainWindow::StartFlash()’:
/home/grimler/Heimdall/heimdall-frontend/source/mainwindow.cpp:925:53: warning: ‘QString& QString::sprintf(const char*, ...)’ is deprecated: Use asprintf(), arg() or QTextStream instead [-Wdeprecated-declarations]
925 | flag.sprintf("--%u", fileInfos[i].GetPartitionId());
| ^
In file included from /usr/include/qt/QtCore/qcoreapplication.h:44,
from /usr/include/qt/QtCore/QCoreApplication:1,
from /home/grimler/Heimdall/heimdall-frontend/source/mainwindow.cpp:22:
/usr/include/qt/QtCore/qstring.h:393:14: note: declared here
393 | QString &sprintf(const char *format, ...) Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
|
The former is deprecated. Fixes compilation warning:
/home/grimler/Heimdall/heimdall/source/BridgeManager.cpp: In member function ‘bool Heimdall::BridgeManager::DetectDevice()’:
/home/grimler/Heimdall/heimdall/source/BridgeManager.cpp:402:57: warning: ‘void libusb_set_debug(libusb_context*, int)’ is deprecated: Use libusb_set_option instead [-Wdeprecated-declarations]
402 | libusb_set_debug(libusbContext, LIBUSB_LOG_LEVEL_NONE);
| ^
In file included from /home/grimler/Heimdall/heimdall/source/BridgeManager.cpp:25:
/usr/include/libusb-1.0/libusb.h:1352:18: note: declared here
1352 | void LIBUSB_CALL libusb_set_debug(libusb_context *ctx, int level);
| ^~~~~~~~~~~~~~~~