Commit Graph

229 Commits (master)

Author SHA1 Message Date
Henrik Grimler 02b577ec77
* 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
2022-07-12 17:42:55 +02:00
Henrik Grimler 14f3521a6b
FlashAction: fix FileOpen check
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")
2022-07-12 17:23:21 +02:00
Henrik Grimler 0cf817a591
libpit: MMC4096 is really UFS
Change name to better describe the hardware.
2022-05-04 13:12:31 +02:00
Henrik Grimler c3516307d2
libpit: last number in PIT header is the "LUN count"
Where LUN probably stands for Logical Unit Number.  Previous
assumption that it was the odin protocol version was wrong, so let's
fix this.
2022-05-04 13:12:28 +02:00
Henrik Grimler f6c4698c8b
Revert "PIT: unknown version in PIT header has to be protocol version"
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.
2022-05-04 13:11:18 +02:00
Henrik Grimler d81e0f5bc2
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
2022-02-13 11:38:55 +01:00
Henrik Grimler 62368adc7d
BridgeManager: only libusb_reset_device on ubuntu
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
2022-02-13 11:17:22 +01:00
Henrik Grimler 0f1843c93c
BridgeManager: break another long line 2022-02-13 08:53:03 +01:00
Henrik Grimler 172ab65cbe
BridgeManager: use SetUsbLogLevel for setting usb log level 2022-02-13 08:53:00 +01:00
Henrik Grimler 1e7ff3b659
README: point to samsung-loki/samsung-docs for more docs 2022-01-01 20:38:27 +01:00
Henrik Grimler e916c679ed
PIT: unknown version in PIT header has to be protocol version
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
2022-01-01 20:38:19 +01:00
Henrik Grimler e9a68f6862
BridgeManager: fix return value by libusb_get_device_list
And remove unnecessary spaces and break a long line.
2022-01-01 20:38:12 +01:00
Henrik Grimler 990ce68f5c
BridgeManager: fix missing newline in error messages 2021-12-31 00:16:46 +01:00
Antony Cherepanov c939ab18d1
Fix comparison between signed and unsigned integers
Warning was seen when compiling with -Wall.
2021-12-18 18:22:42 +01:00
Antony Cherepanov 1385b183d2
Packet destructor should be virtual
Fixes warning seen when compiling with -Wall.
2021-12-18 18:21:40 +01:00
Henrik Grimler 95e5c1cdcb
heimdall-frontend: set version to 2.0.0 here as well
Will not make a new release for just this though.
2021-12-16 17:40:42 +01:00
Henrik Grimler 622067f284
Release v2.0.0
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
* libusb_reset_device is needed before handshake on ubuntu:
* Support for flashing images larger than 3.5 GB:
* Avoid libusb_set_interface_alt_setting when it anyways doesn't do
  anything:, fixed
  in: 2ecc98020c
* Some compilation issues on
  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).
2021-12-16 16:59:29 +01:00
Henrik Grimler 9b0e9ff174
README: add build status images 2021-12-16 16:15:51 +01:00
Henrik Grimler 225164f87e
README: point to OS specific READMEs inside the repository 2021-12-16 16:14:05 +01:00
Henrik Grimler 91802883a0
README: use https for libusb link 2021-12-16 16:13:47 +01:00
Henrik Grimler 40be58b43e
FlashAction: add option --skip-size-check
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).
2021-12-16 16:07:41 +01:00
Henrik Grimler 60ab9bbaff
FlashAction: Make sure file fit partition before flashing
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
2021-12-16 16:05:42 +01:00
Henrik Grimler e51c9119f1
libpit: describe more parts of pit header
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)
2021-12-16 16:01:18 +01:00
Henrik Grimler 31745c287a
libpit: add DeviceType = 8 entry for MMC with blksize 4096
Newer devices have an emmc with 4096 block size instead of 512.  These
seem to have DeviceType=8 instead of DeviceType=2.
2021-12-16 16:01:15 +01:00
Henrik Grimler cedfcd8c80
win32: remove zadig.exe from repo
Carrying around this (now outdated) driver in the repo seems
unnecessary. Windows users can download latest from instead.
2021-12-14 11:22:04 +01:00
Henrik Grimler 6441c6a6c5
Remove some extra whitespace and convert some spaces to tabs 2021-12-10 09:46:30 +01:00
Henrik Grimler af87b7b7e4
cmake: replace LFS check with scripts from wireshark
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
2021-12-10 09:46:24 +01:00
Henrik Grimler 761c2db4d2
cmake: set -std=c+++11 with target_compile_features instead 2021-12-10 09:46:17 +01:00
Henrik Grimler 719edaff9e
heimdall, libpit: fix (MSVC) nullptr check
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

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
2021-11-25 21:26:37 +01:00
Henrik Grimler f0594beaf6
builds: test build for ubuntu 20.04 as well 2021-11-22 17:26:43 +01:00
Henrik Grimler 2ecc98020c
BridgeManager: skip libusb_set_interface_alt_setting if altsetting=0
Some (older) devices seem to have a problem with this:

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
2021-11-22 16:25:45 +01:00
Henrik Grimler 6317e88503 */README: replace http with https in urls 2021-06-15 11:29:49 +02:00
Henrik Grimler 74c498d61e builds: add more (build) dependencies on alpine and arch 2021-06-15 11:29:25 +02:00
Henrik Grimler f3bdacf03d CI: test build heimdall on alpine and archlinux
Using sourcehuts build service
2021-06-15 10:46:43 +02:00
Henrik Grimler 53466cbd51 gitignore: ignore *~ as well 2021-06-15 10:46:25 +02:00
Henrik Grimler df83a4b010 CMakeLists: update usb library variable
It was renamed in the update of the Findlibusb cmake module.
2021-06-06 20:37:55 +02:00
Henrik Grimler 64bd479db6 cmake: update Findlibusb.cmake
This one adds support for more platforms (like freebsd) out of the
box, so that those distros do not need to patch the module.
2021-05-29 20:26:37 +02:00
Henrik Grimler 4fadfe9c5d heimdall: cmake: do not set libusb_USE_STATIC_LIBS
It does not have an effect, heimdall is dynamically linked in any
2021-05-29 19:32:05 +02:00
Henrik Grimler 82f7241133 Use https in urls and link to libusb instead of libusbx 2021-05-29 16:54:04 +02:00
Jesse Chan 07a14d4aa8 InitialiseProtocol: reset device before handshake
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 <>
2021-05-03 22:38:41 +02:00
Henrik Grimler 6d17eb5178 heimdall-frontend: Remove one indentation level from Packaging
In the two variants of Packaging::ClashlessFilename.
2021-05-03 14:53:19 +02:00
Henrik Grimler 54d58b8244 README: re-format, re-phrase supported platform section
And use https for external links.
2021-05-03 14:53:19 +02:00
Romain Hunault 6ede1f1f33 Fix macOS issues
[ Taken from ]
2021-05-03 14:53:19 +02:00
Henrik Grimler af3f0d6ac9 Convert all files to unix line endings
All except Win32/README.txt.
2021-05-03 14:24:06 +02:00
Henrik Grimler ccafa21e64 heimdall-frontend: fix deprecated use of qrand()
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();
      |                                                                                ^~~~~
2021-05-03 14:24:06 +02:00
Henrik Grimler 220f90a4fe heimdall-frontend: fix deprecated use of sprintf
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);
2021-05-03 14:24:06 +02:00
Henrik Grimler 094f715c4d heimdall: BridgeManager: libusb_set_debug->libusb_set_option
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);
      |                  ^~~~~~~~~~~~~~~~
2021-05-03 14:23:40 +02:00
Henrik Grimler 9bff064d40 CMake: bump minimum version
Mostly because 2.8.4 will be deprecated in the not too far future
2021-05-03 14:07:33 +02:00
fft 92ea948323 fixup! heimdall: Fix flashing firmwares bigger than 3.5GB
Fix show progress percentage for big files.
2021-05-03 14:04:53 +02:00
Mallon Lobjakas c87f5bf210 heimdall: Fix flashing firmwares bigger than 3.5GB 2021-05-03 14:04:53 +02:00