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

Search This thread

uluruman

Senior Member
Oct 23, 2021
137
22
Just in case, the basic "clean install" procedure looks like this (as an example):
  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
137
22
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
86
11
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
137
22
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
284
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
137
22
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
137
22
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.
  • 3
    repacksuper
    ===========

    Copyleft uluruman 2021-2022

    (for LINUX 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 something else.

    Theoretically should work for any Samsung A-series phones.
    Tested on SM-A127F/DSN made in India and Vietnam and SM-A325F/DS made in India,
    on Debian Linux 11 x64.


    Changelog
    ---------

    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.


    P.S.: The first upload of v1.0 included the not-yet-working extractoptics.sh.
    Now it is removed.


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

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


    Instructions
    ------------

    Just run the script without args to see help.
    Better read
    this post for the step-by-step guide.
    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).

    Known issues (not solvable by the script):
    1. During the script run you can see several "Invalid sparse file format at header magic" warnings, just ignore them.
    2. In LineageOS, Dot OS and some other GSIs I tried 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 yet to be found.
    3. In LineageOS MTP file transfer does not work (at least on Linux). Unfortunately currently there is no solution (known to me) for this, so you have to resort to the ftpd, Bluetoothor some other method.
    P.S.: I really don't recommend using any of the Google services (GApps, Google Play, etc.). 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.
    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
    The dot goes after -p. All the options should go first.
    ./repacksuper.sh -p . *pixelexpierence12plusblabla* pixelexpierence.tar
    Ok thx, i just switched to native linux on my pc, but i have one more question.
    Do you know the name of the package "simg2img" on arch linux because it shows that the package is not found even tho it is on the arch AUR
    1657317251227.png

    Fehler: Ziel nicht gefunden means Error: target not found. it appears when package was not found.

    Arch AUR for simg2img https://aur.archlinux.org/packages/android-simg2img