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
Just in case, the basic "clean install" procedure looks like this (just as an example, using Odin for Windows):
  1. unlock the OEM in the Developer Settings and the Download mode
  2. download and unpack the full stock firmware (I use the Nepal version, because it does not include any prism-ware in prism.img)
  3. download a GSI of your choice, for example LiR v3.16
  4. unpack the script and execute it like so: repacksuper.sh Samfw.com_SM-A325F_NPB_A325FXXU2AUJ4_fac lir-v316-220325-arm64-bvZ.img.xz lir_v316_super (the first parameter is the location of the unpacked stock firmware, the second is the GSI file, the third is the name of the resulting .tar file). The script requires some additional tools to be present in the system (simg2img, xz-utils, lz4, unzip, jq and file)
  5. the script takes a long time to do its main job, when it's done it asks to pack everything into a tar file, answer "y" (yes)
  6. now you have lir_v316_super.tar file in the repacksuper subdir
  7. boot into Download mode (Volume Up + Volume Down with the USB cable plugged in) and flash the full original firmware as is using Odin, but be sure to first uncheck the "Auto Reboot" in the options. Reboot manually (Power + Volume Down) when it's finished to be able to go into the download mode again straight away without booting the system
  8. (optionally) boot into the recovery mode (Power + Volume Down with the USB cable plugged in) and do factory reset and cache format. I'm not sure if it's needed at all at this stage. You can try skipping this step.
  9. boot into the download mode flash lir_v316_super.tar into the AP slot
  10. now boot into recovery (Power + Volume Down with the USB cable plugged in) and do factory reset and cache format
  11. disconnect the USB cable (otherwise it can cause a freeze on the first boot)
  12. now reboot and boot the system normally
 
Last edited:
  • Like
Reactions: LuCeiFeR

uluruman

Senior Member
Oct 23, 2021
162
26
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).
 
Last edited:

LuCeiFeR

Senior Member
Jun 8, 2012
87
12
HTC EVO 3D
Samsung Galaxy Note 9
Tried the script in kali, it almost took about 4 minutes to generate the tar file. Obviously, it was corrupted however it was about 4.6 GB. Moved to Odin and flashed original fw, but it stuck in flashing the generated tar file with a message analyzing the file!

It is now about half an hour on wsl with Ubuntu and is still going on generating the tar. Will keep you posted :D

N.B. you should include the above amazing guide in OP

Edit: Just flashed phh Treble android 12 and it is very smooth. Has some bugs, but worth it. Will try lineage in few days. Thank you very much for your efforts my friend. Keep it up.
 
Last edited:
  • Like
Reactions: uluruman

bs7799de

New member
May 19, 2019
2
0
Must the GSI have the same Android version as the stock firmware (11) or can you also take an Android 12?
 

uluruman

Senior Member
Oct 23, 2021
162
26
Must the GSI have the same Android version as the stock firmware (11) or can you also take an Android 12?
There is no dependency. You can switch between versions 12 and 11 freely.

The only thing you can't do is to downgrade the baseband version of the stock firmware, e.g. U4 to U3. Although this is technically possible this action is blocked by the Download mode. It's interesting if anyone can tell what's so important about that?
 

Akhil99

Senior Member
Oct 6, 2015
192
287
Mysore
Hi, Great work.

As far as MTP is concerned it is an Kernel issue.
I do know the fix. We can chat on telegram. my username there is @cha0scl0wn
 

uluruman

Senior Member
Oct 23, 2021
162
26
twrp is not working everytime so just an alternative way to install it.
The only alternative way I've found for myself is the one described in this thread: repackaging the whole super.img with the system.img (it's located inside super.img) replaced with the GSI you want. It seems to be more or less universal approach for the Samsung phones with dynamic partitions. There is only one thing that may not work: when the script does the final compilation of the super.img using the lpmake tool on an unknown phone it may fail throwing the error message "Cannot extract a value using lpdump", because on different phones the names of the metadata fields slightly differ. In that case contact me using the conversation mode and we'll figure it out (it will require running the lpdump tool on the stock super.img file).
 

uluruman

Senior Member
Oct 23, 2021
162
26
try these commits.
Thanks! I see the solution seems to be in compiling the kernel with the f_mtp_samsung driver disabled so that only the default f_mpt would be used instead. Or may be I'm wrong but I'll figure it out. Anyway, there's a problem: I have already upgraded my phone to the U2 baseband version, but the source code for U2 is still not released.

EDIT: by the way, it's the A12 forum, not A32. I have both phones, but the forum is wrong... Anyway the phones are very similar, so the method should work for both, once it is possible.

EDIT 2: Ah, I see that it's quite possible that the kernel was not upgraded with the U2 baseband release. That was the problem with A12 U3/4 but not necessary with A32 U2. I think I'll try compiling the old kernel, may be even Mohammad's version, it may work okay. By the way, I think a cleaner solution would be just blacklisting the wrong MTP driver using modprobe.
 
Last edited:
  • Like
Reactions: Akhil99

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)