Development Installing GSI by repacking super.img on SM-A127F and SM-A325F (Linux)

Search This thread

uluruman

Senior Member
Oct 23, 2021
162
26
repacksuper
===========

Copyleft uluruman 2021-2022

(for LINUX/WSL only)

This is the minimalistic set of tools + script for Linux for the automated
ground-up repacking and flashing of the Samsung Galaxy super.img, replacing
the stock Android system with something much less intrusive and obtrusive
(e.g. LineageOS). Or just some other GSI (Generic System Image).

Theoretically should work for any Samsung A-series phones, and may be even for
some others. Tested on SM-A127F/DSN made in India and Vietnam and SM-A325F/DS
made in India, on Debian Linux 11 x64. There are reports of successful flashing
of SM-127M and SM-A032M.


Requirements
------------

Install the following tools from the official repositories of your Linux distro:
simg2img xz-utils lz4 unzip gzip jq file


Basic instructions
------------------

repacksuper.sh: main script for changing your phone's operating system
heimdall_flash_stock.sh: script for flashing stock firmware under Linux

heimdall_flash.sh: script for flashing any custom image file under Linux
Just run a script without any arguments to see help.


Extra tools used (x64 binaries and sources included)
----------------------------------------------------


Additional notes
----------------

The included binaries for the lpunpack, lpmake and Heimdall were compiled for
the x86_64 architecture. If your PC architecture is different (e.g. x86 32-bit
or ARM) you have to compile these tools yourself. The full source code is
included (or otherwise available on GitHub).


0.9: Initial release
0.91: Non-sparse new system is now correctly moved into the super dir
0.91a: Bug in the new system file format checking fixed
0.91b: Better support for spaces in paths
0.92: Added checking for system requirements and an optional parameter for
setting of the final tar archive name.
0.92a: Fixed file ownership issues inside the tar distribution archive
0.93: Added support for SM-A325F. Several minor improvements.
0.94: Added support for gzip-packed GSI images. Packing into .tar is now done
without question if the command line parameter is given. Tar parameter
now can include the full path. Without the full path the default tar
location is now the same as the GSI. Several other minor changes.
1.0: Finally added working native Linux flashing using Heimdall (HUGE thanks
to amo13 and Benjamin Dobell). Two new options: using empty product.img
and silent (non-interactive) mode. Colored text. Bugfixes and minor
changes.
1.01: Option to specify the SUPER partition name manually (needed for flashing
SM-A127F with Heimdall). Now it is possible to place output .img and .tar
files in any directory and give them any name. Text terminology a bit
clarified, help text expanded. Done many internal optimizations,
additional sanity checks and minor changes.
1.02: Support for SM-A032F/M and similar firmwares with non-packed super.img.
Support for firmwares with/without additional partitions. Support for
arbitrary partition group names. Very experimental option to use empty
system_ext.img for additional privacy (applicable to some phone models/
regions). Lots of minor fixes.
1.03: Multiple .img files are now supported in GSI archive files (one of them
should be system.img in that case), e.g. Android AOSP zip files are now
supported directly. The logic of flashing with Heimdall now includes more
complex cases, such as flashing in two steps with a reboot. Unnecessary
code in GZ unpacking removed. Some other small fixes and optimizations.
1.1: New scripts heimdall_flash_stock.sh and heimdall_flash.sh added.
Lots of refactoring in repacksuper.sh (because of that there may be some
bugs left), improved and clarified UI logic, changes in where the files are
now placed (see help for details), direct work with stock Zip firmware
files, lots of minor changes.

During the script run you can see several "Invalid sparse file format at header
magic" warnings, just ignore them.

For some phones Heimdall may not work at all, in that case you have to resort to
Odin. In many cases Heimdall freezes when uploading firmware for quite some
time, but that does not mean it is completely frozen, just be patient.

In LineageOS, Dot OS and some other GSIs I tried on SM-127F the touch screen
remains not responsive for about 6 seconds after waking up. The problem is not
present at least with SM-127F/DSN phones made in India, but present at least in
those made in Vietnam, which means it is not caused by the OS installation
approach but rather by the quirks of the phone hardware itself. Solution should
require tweaking of the kernel behavior but it's beyond my capabilities.

In the most, if not all, GSIs USB file transfer does not work (at least on
Linux) because of the "wrong" (Samsung's instead of Google's) default MPT driver
used by the kernel. Again fixing this requires patching and rebuilding the
kernel from sources and repacking of the boot image, which is still a bit beyond
my capabilities, although there were reports of success from other people.
Alternative solutions include using apps such as Warpinator, Syncthing or ftpd.

When choosing a GSI to install I really don't recommend using ones which include
GApps and therefore use any of the Google services. Don't let corporations
gather your data. You bought the phone and from now on it should be all yours,
with all of its data, like a PC in the good old days. You own your device, and
nobody has the right to stick their nose into how you use your phone, gather any
statistics and push you any ads. You always have a choice to turn down
privacy-unfriendly stuff, the price of that "inconvenience" is actually
ridiculous. From my point of view, there is simply no point in using non-stock
systems if they are still littered with the privacy-unfriendly bloatware.

For the step-by-step guide (slightly outdated) read this post. Also be sure to read this post concerning the importance of optics.img.

The included binaries for the lpunpack, lpmake and Heimdall were compiled for the x86_64 architecture. If your PC architecture is different (e.g. x86 32-bit or ARM) you have to compile these tools yourself. The full source code is included (or otherwise available on GitHub).

As v1.1 may contain new bugs introduced by the refactoring the previous v1.03 is also available for download.
 

Attachments

  • repacksuper_v1.1.tar.gz
    66.6 MB · Views: 10
  • repacksuper_v1.03.tar.gz
    50.4 MB · Views: 5
Last edited:

uluruman

Senior Member
Oct 23, 2021
162
26
Some recommendations for the users of SM-127F/DSN:
  1. It's possible that SM-127F/DSN internally is not A12 but actually M12, at least most of the tools and kernels made for M12 work on SM-127F/DSN while those made specifically for SM-125 and even other SM-127 versions do not. Therefore you can find more relevant info and tools in the corresponding XDA thread (my script is still remains relevant though).
  2. If you are a newbie and don't know how to do unlock the bootloader and other such stuff, here is a good guide by LAST_krypton (follow the "Unlocking the booloader" section) or a shorter guide by cldkrs.
  3. First flash the phone with the whole set of stock firmware using Odin. For Linux there is a working version of Heimdall available, which is good and open-source but much less user-friendly. Odin unfortunately is only for Windows, so you have to either use Windows in QEMU (tested) or probably Wine (untested). When using QEMU remember to add the SUBSYSTEM=="usb", ATTRS{idVendor}=="04e8", ATTRS{idProduct}=="685d", MODE:="0666" line to the udev rules (e.g. /etc/udev/rules.d/30-qemu.rules) to enable the write access to the phone.
  4. The stock firmware comes in different revision numbers (also known as the U number of the baseband version). Generally it should be beneficial to use the latest revision, but note that once you have upgraded it to a later revision there is no way back (at least known to me). In case you want to experiment with flashing of special kernels and other flavors provided by the XDA developers, if possible, you should probably stick to the very first revision (U1).
  5. If you already have the bootloader unlocked (OEM unlock) then after flashing the stock firmware there is no need to set up the Android, just go straight into the download mode again.
  6. When downloading LineageOS or any other GSI select the normal arm64 bvS version, not vndklite version, as it doesn't seem to boot properly.
  7. After flashing the OS go into the Recovery mode (hold volume up and power when rebooting) straight away and do the Factory reset.
  8. If you cannot get into the Recovery mode be sure to connect the USB cable before trying to.
  9. You can forcefully reboot your phone at any time, even if it seems bricked, by holding the volume down and power buttons for several seconds.
  10. Do not flash TWRP or any other 3rd party recovery tool (more on that below) and try to avoid using Magisk (the latter is not needed at all for LineageOS) if you just want to install another OS and nothing else. Those tools (may) have their own bunch of problems with SM-127F/DSN. The stock recovery tool work fine for just the factory reset after flashing the super file.
  11. If you really need a 3rd party recovery tool, there is a version of Orange Fox tested to be working fine on SM-127F/DSN with the U3 and U4 baseband versions. If you have the baseband version U2 or earlier I cannot give any recommendations besides flashing a newer version. There are also custom kernels available for U3 and U4.
  12. To upgrade your system to the recent version of the same OS just repackage it into a new super.img using the same script and flash it normally, but be sure to get into the Recovery mode right on the first boot and wipe the Cache partition. All your apps and settings should remain intact.
  13. If flashing with Heimdall completely freezes at some point make sure you've downloaded and repacked the correct arm64 b or a/b GSI and not arm and not a or a-only variant. If "sw rev check fail" message appears on the screen at some point just ignore it.
 
Last edited:

IchZerowan

Member
Oct 31, 2021
11
1
Thanks A LOT, this works! I am finally able to run LineageOS on my phone!

For Windows 10+ users: WSL runs this script just fine with a few additional steps.
1. Install WSL 2 and any Linux distribution from Microsoft Store
2. Run the distribution to finish setup
3. Install the required packages from the post (sudo apt install for Ubuntu/Debian)
4. Shift + Right Click in the folder where you have the script, the AP and the GSI packages
5. Open Linux shell there
6. Unpack & run script as stated in its help

Voila!
 
  • Like
Reactions: uluruman

jadfa

Member
Dec 12, 2016
10
1
Wow ! Great job! I want to try it, but i'm getting many "Invalid sparse file format at header magic" while running the script, is it OK to flah the super.tar anyway?
 
  • Like
Reactions: IchZerowan

uluruman

Senior Member
Oct 23, 2021
162
26
Wow ! Great job! I want to try it, but i'm getting many "Invalid sparse file format at header magic" while running the script, is it OK to flah the super.tar anyway?
Yes, it is fine. These are just warnings produced by lpmake, they can not be suppressed. I could only suppress all the stdout/stderr from lpmake but it's no good in case of more serious warnings.
 

ANDARXapi

Member
Nov 30, 2021
23
3
1640350845682.png
What should I do next with the raw file?
"Unknown super file format" is this how it should be?
 

uluruman

Senior Member
Oct 23, 2021
162
26
View attachment 5490897What should I do next with the raw file?
"Unknown super file format" is this how it should be?
Of course not. The format of each file is checked using the "file" utility, it should return the string "Android super image". Try to run file /home/toor/APfilles/super.stock.raw . What is the response? And try doing it all without sudo. There is no need in root privileges.
 

ANDARXapi

Member
Nov 30, 2021
23
3
Of course not. The format of each file is checked using the "file" utility, it should return the string "Android super image". Try to run file /home/toor/APfilles/super.stock.raw . What is the response? And try doing it all without sudo. There is no need in root privileges.
1640358693515.png
The raw file opens as a picture
 

ANDARXapi

Member
Nov 30, 2021
23
3
Of course not. The format of each file is checked using the "file" utility, it should return the string "Android super image". Try to run file /home/toor/APfilles/super.stock.raw . What is the response? And try doing it all without sudo. There is no need in root privileges.
1640359013603.png

run without sudo: 168: ./lpunpack_and_lpmake/lpunpack: Permission denied Cannot correctly unpack the super file. Exiting ...
 

ANDARXapi

Member
Nov 30, 2021
23
3
I managed to fix the script, you just need to give chmod +x rights to the files in the folder "lpunpack_and_lpmake": lpunpack, lpmake, lpflash, lpdump, lpadd
 

uluruman

Senior Member
Oct 23, 2021
162
26
I managed to fix the script, you just need to give chmod +x rights to the files in the folder "lpunpack_and_lpmake": lpunpack, lpmake, lpflash, lpdump, lpadd
Hmmm. I have updated it, may be it'll help. Could you please test the latest version (v0.92a)? I want to work it out of the box for everyone, without sudo or any tweaks.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 1
    ITS WORKING ANDROID 13 IN A03 CORE
    1
    i use crDroid-9.0-a64_bvN-Unofficial.img.xz and succesfully boot
    1
    Now flashee lineage OS and also boots, with partition A / b works not only type A
    1
    gsi update in a03 core or sm-a032m/f It is fast stable, but it presents the following, *not all roms work *the 3.5mm jack does not work even with the phh fixes so far only arrow os android 12 bvn works and crdroid android 13 bvn
    1
    @uluruman
    Wow! 😲
    Nice script ! Keep up the good work! :D(y)
  • 5
    repacksuper
    ===========

    Copyleft uluruman 2021-2022

    (for LINUX/WSL only)

    This is the minimalistic set of tools + script for Linux for the automated
    ground-up repacking and flashing of the Samsung Galaxy super.img, replacing
    the stock Android system with something much less intrusive and obtrusive
    (e.g. LineageOS). Or just some other GSI (Generic System Image).

    Theoretically should work for any Samsung A-series phones, and may be even for
    some others. Tested on SM-A127F/DSN made in India and Vietnam and SM-A325F/DS
    made in India, on Debian Linux 11 x64. There are reports of successful flashing
    of SM-127M and SM-A032M.


    Requirements
    ------------

    Install the following tools from the official repositories of your Linux distro:
    simg2img xz-utils lz4 unzip gzip jq file


    Basic instructions
    ------------------

    repacksuper.sh: main script for changing your phone's operating system
    heimdall_flash_stock.sh: script for flashing stock firmware under Linux

    heimdall_flash.sh: script for flashing any custom image file under Linux
    Just run a script without any arguments to see help.


    Extra tools used (x64 binaries and sources included)
    ----------------------------------------------------


    Additional notes
    ----------------

    The included binaries for the lpunpack, lpmake and Heimdall were compiled for
    the x86_64 architecture. If your PC architecture is different (e.g. x86 32-bit
    or ARM) you have to compile these tools yourself. The full source code is
    included (or otherwise available on GitHub).


    0.9: Initial release
    0.91: Non-sparse new system is now correctly moved into the super dir
    0.91a: Bug in the new system file format checking fixed
    0.91b: Better support for spaces in paths
    0.92: Added checking for system requirements and an optional parameter for
    setting of the final tar archive name.
    0.92a: Fixed file ownership issues inside the tar distribution archive
    0.93: Added support for SM-A325F. Several minor improvements.
    0.94: Added support for gzip-packed GSI images. Packing into .tar is now done
    without question if the command line parameter is given. Tar parameter
    now can include the full path. Without the full path the default tar
    location is now the same as the GSI. Several other minor changes.
    1.0: Finally added working native Linux flashing using Heimdall (HUGE thanks
    to amo13 and Benjamin Dobell). Two new options: using empty product.img
    and silent (non-interactive) mode. Colored text. Bugfixes and minor
    changes.
    1.01: Option to specify the SUPER partition name manually (needed for flashing
    SM-A127F with Heimdall). Now it is possible to place output .img and .tar
    files in any directory and give them any name. Text terminology a bit
    clarified, help text expanded. Done many internal optimizations,
    additional sanity checks and minor changes.
    1.02: Support for SM-A032F/M and similar firmwares with non-packed super.img.
    Support for firmwares with/without additional partitions. Support for
    arbitrary partition group names. Very experimental option to use empty
    system_ext.img for additional privacy (applicable to some phone models/
    regions). Lots of minor fixes.
    1.03: Multiple .img files are now supported in GSI archive files (one of them
    should be system.img in that case), e.g. Android AOSP zip files are now
    supported directly. The logic of flashing with Heimdall now includes more
    complex cases, such as flashing in two steps with a reboot. Unnecessary
    code in GZ unpacking removed. Some other small fixes and optimizations.
    1.1: New scripts heimdall_flash_stock.sh and heimdall_flash.sh added.
    Lots of refactoring in repacksuper.sh (because of that there may be some
    bugs left), improved and clarified UI logic, changes in where the files are
    now placed (see help for details), direct work with stock Zip firmware
    files, lots of minor changes.

    During the script run you can see several "Invalid sparse file format at header
    magic" warnings, just ignore them.

    For some phones Heimdall may not work at all, in that case you have to resort to
    Odin. In many cases Heimdall freezes when uploading firmware for quite some
    time, but that does not mean it is completely frozen, just be patient.

    In LineageOS, Dot OS and some other GSIs I tried on SM-127F the touch screen
    remains not responsive for about 6 seconds after waking up. The problem is not
    present at least with SM-127F/DSN phones made in India, but present at least in
    those made in Vietnam, which means it is not caused by the OS installation
    approach but rather by the quirks of the phone hardware itself. Solution should
    require tweaking of the kernel behavior but it's beyond my capabilities.

    In the most, if not all, GSIs USB file transfer does not work (at least on
    Linux) because of the "wrong" (Samsung's instead of Google's) default MPT driver
    used by the kernel. Again fixing this requires patching and rebuilding the
    kernel from sources and repacking of the boot image, which is still a bit beyond
    my capabilities, although there were reports of success from other people.
    Alternative solutions include using apps such as Warpinator, Syncthing or ftpd.

    When choosing a GSI to install I really don't recommend using ones which include
    GApps and therefore use any of the Google services. Don't let corporations
    gather your data. You bought the phone and from now on it should be all yours,
    with all of its data, like a PC in the good old days. You own your device, and
    nobody has the right to stick their nose into how you use your phone, gather any
    statistics and push you any ads. You always have a choice to turn down
    privacy-unfriendly stuff, the price of that "inconvenience" is actually
    ridiculous. From my point of view, there is simply no point in using non-stock
    systems if they are still littered with the privacy-unfriendly bloatware.

    For the step-by-step guide (slightly outdated) read this post. Also be sure to read this post concerning the importance of optics.img.

    The included binaries for the lpunpack, lpmake and Heimdall were compiled for the x86_64 architecture. If your PC architecture is different (e.g. x86 32-bit or ARM) you have to compile these tools yourself. The full source code is included (or otherwise available on GitHub).

    As v1.1 may contain new bugs introduced by the refactoring the previous v1.03 is also available for download.
    2
    One more important thing: if, for example, you're using the Nepalese firmware as the basis for your GSI, while you reside in the UK, you may still need to download your actual regional firmware as well. Inside the CSC part of the firmware there is a file called optics.img which contains the lists of the cellular provider carrier data specific to your region, otherwise you (probably) will be limited in number of service providers available.

    You can extract and flash optics.img separately this way:
    1. download and unzip the full stock firmware for your region of residence
    2. unpack optics.img.lz4 from the CSC_OMC_ODM tar.md5 file using the standard tar utility (e.g. tar -f CSC_OMC_ODM_A325FODM2AUJ3_CL22736284_QB44664166_REV00_user_low_ship_MULTI_CERT.tar.md5 -x optics.img.lz4)
    3. now unpack it using lz4: unlz4 optics.img.lz4
    4. pack .img into tar: tar cf optics_native.tar optics.img
    5. flash it using Odin into the CSC slot
    You can do it at any time after installing the GSI, and you have to do it only once (unless you flash the full stock firmware or the CSC slot separately, of course).
    1
    I should test this for a127f
    1
    Thanks A LOT, this works! I am finally able to run LineageOS on my phone!

    For Windows 10+ users: WSL runs this script just fine with a few additional steps.
    1. Install WSL 2 and any Linux distribution from Microsoft Store
    2. Run the distribution to finish setup
    3. Install the required packages from the post (sudo apt install for Ubuntu/Debian)
    4. Shift + Right Click in the folder where you have the script, the AP and the GSI packages
    5. Open Linux shell there
    6. Unpack & run script as stated in its help

    Voila!
    1
    @uluruman
    Wow! 😲
    Nice script ! Keep up the good work! :D(y)