Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Repackage SM-G361F system image - Cannot be flashed with ODIN/Heimdall

1,421 views
Skip to first unread message

marek....@gmail.com

unread,
Mar 11, 2016, 3:12:50 PM3/11/16
to
Hi,

I'm trying to repackage (pre-root) system.img taken from "G361FXXU1APA2_G361FOXX1APA1_G361FXXU1APA2_HOME.tar.md5" (taken from ETL factory image named ETL-G361FXXU1APA2-20160202095551.zip )

Step-by-step:

1) tar xvf G361FXXU1APA2_G361FOXX1APA1_G361FXXU1APA2_HOME.tar.md5 system.img
2) simg2img system.img system.img.raw
3) mount system.img.raw /mnt
4) made changes
5a) make_ext4fs -s -g 32768 -b 4096 -T -1 -S file_contexts -f -l 1843M system.repack.img /mnt/
5b) mkuserimg.sh -s /mnt system.repack.img ext4 system 1843M file_contexts
6) tar --owner 0 --group 0 --numeric-owner -H ustar -c system.img > G361F_SYSTEM.tar
7a) Load either system.img through Heimdall (PIT file downloaded through Heimdall is here: http://forum.xda-developers.com/showpost.php?p=65779994&postcount=146 )
7b) Load G361F_SYSTEM.tar in Odin v3.10.7 in AP tab and flash it

On ODIN/Download screen I can see that
1) FRP LOCK: OFF
2) KNOX: 0x0
3) System status: official
4) RP SWREV: S1, L1, M1

Notes
1) I have checked the box "OEM Unlock" in Developers settings to enabled
2) "file_contexts" is taken from booted up device through ADB (adb pull /file_contexts)
3) I've tried repackage the image without making any changes
4) When I compare original and repackaged images ("ls -lsaR" outputs), it seems like owner:group permissions are not persisted
5) I've tried both simg2img/make_ext4fs/mkuserimg.sh from CM12.1 repository (up to date today) and from https://github.com/ASdev/android_img_repack_tools (branch android-5.1.1)
6) I'm not sure about size 1843M, however flashing fails in the same manner when I go with 1536M and 2048M and anything between those two
7) Heimdall fails at about 6% of flashing single (sparse system.img) file with error "Failed to unpack received packet"

Is there something I completely missed in the process or is making system.img for Samsung devices in any way different from standard devices?

Thank you for any help!

josep...@gmail.com

unread,
Aug 12, 2016, 1:50:09 AM8/12/16
to
Have the same exact problem except that I'm using the Samsung Galaxy tab A 7.0 (SM-T285)

Something similar also happened to me and I am still in the process of figuring it out. However mine fails also at 6% (Probably depending on the size of your image 2GB). I've tried various image sizes (600MB to 2048M) however it always fails when sending the second packet. Both Heimdall and Odin behave the same way though there is more detail on Heimdall.

Note that I have tried every possible way that make_ext4fs is to be used and the result is the same.

Here are notes that I have taken so far:

1.) Flashing an untouched system.img file works fine both on odin and heimdall
2.) Also used just a repackaged image without making any changes and it still fails
3.) Also OEM unlocked.
4.) when Heimdall fails, note that no error is displayed. It is as if it is still waiting for the succeeding packets.

Possible Hypothesis:

1.) Odin (as currently released) and Heimdall can't handle the new devices yet. The device probably checks if the data it is writing is the same as the one already stored which is why the untouched stock image works. There may be some flag or response during actual writing which isn't handled by Heimdall/Odin.

2.) the bootloader does some sort of undocumented check on the uploaded image and rejects it.

3.) I totally repacked the images wrong, though like you I am at a loss on what it is.

Possible course of action:

For my device there are unconfirmed reports of people not having this problem, I'll try to flash another ROM region and see it there is any difference.

josep...@gmail.com

unread,
Aug 12, 2016, 7:19:04 AM8/12/16
to
Finally fixed it after days and hours of struggle.

turns out that the sparse file format expected by the samsung device is not exactly the same as the one generated by the make_ext4fs utility bundled with cm and aosp. I had to apply patches to libsparse in order to fix. After apply the patch I am now able to flash up to 100%

adna...@gmail.com

unread,
Aug 20, 2016, 5:54:24 PM8/20/16
to
On Friday, August 12, 2016 at 1:19:04 PM UTC+2, josep...@gmail.com wrote:
> Finally fixed it after days and hours of struggle.
>
> turns out that the sparse file format expected by the samsung device is not exactly the same as the one generated by the make_ext4fs utility bundled with cm and aosp. I had to apply patches to libsparse in order to fix. After apply the patch I am now able to flash up to 100%

I'm having the same issue, could you share your solution? What modifications are required?

adna...@gmail.com

unread,
Aug 21, 2016, 8:34:16 PM8/21/16
to
For future readers (if any), I managed to solve this by myself and have written a short summary in this xda thread:
http://forum.xda-developers.com/android/general/edit-cache-img-file-using-simg2img-t3443915

Basically what I did is recompile the tools img2simg and simg2img from here:
https://github.com/ASdev/android_img_repack_tools/tree/android-6.0.1

But before building, I applied this patch, I'm unsure if it would've worked without it since I haven't tested the clean build.
https://gist.github.com/jedld/4f388496bda03b349f5744f367749a67

Then I managed to make a flashable img file with:

./simg2img cache.img cache.raw
...mount cache.raw and do my modifications to it...
./img2simg cache.raw cache_new.img

cache_new.img was now flashable on my galaxy s7 (but failed when I used the "normal" simg2img and img2simg binaries, can't remember in which ubuntu package they came in)

If someone isn't able to build it for some reason, here are my simg2img and img2simg binaries (built on ubuntu 16.04 LTS x64)
https://app.box.com/s/3gji2k6m1jsd3kf426ah5hpfc8vt26xe

andrew...@gmail.com

unread,
Dec 9, 2016, 3:46:20 AM12/9/16
to
> For future readers (if any), I managed to solve this by myself and have written a short summary in this xda thread:
> http://forum.xda-developers.com/android/general/edit-cache-img-file-using-simg2img-t3443915
>
> Basically what I did is recompile the tools img2simg and simg2img from here:
> https://github.com/ASdev/android_img_repack_tools/tree/android-6.0.1
>
> But before building, I applied this patch, I'm unsure if it would've worked without it since I haven't tested the clean build.
> https://gist.github.com/jedld/4f388496bda03b349f5744f367749a67
>
> Then I managed to make a flashable img file with:
>
> ./simg2img cache.img cache.raw
> ...mount cache.raw and do my modifications to it...
> ./img2simg cache.raw cache_new.img
>
> cache_new.img was now flashable on my galaxy s7 (but failed when I used the "normal" simg2img and img2simg binaries, can't remember in which ubuntu package they came in)
>
> If someone isn't able to build it for some reason, here are my simg2img and img2simg binaries (built on ubuntu 16.04 LTS x64)
> https://app.box.com/s/3gji2k6m1jsd3kf426ah5hpfc8vt26xe

Hi, I'm impressed that you managed to flash cache.img re-packaged with your modified img2simg onto your S7... A question:
Have you been able to falsh modified system.img as well??? ;););)

Thanks for your info!

erfa...@gmail.com

unread,
Mar 6, 2017, 1:01:14 PM3/6/17
to
On Friday, August 12, 2016 at 4:19:04 AM UTC-7, josep...@gmail.com wrote:
> Finally fixed it after days and hours of struggle.
>
> turns out that the sparse file format expected by the samsung device is not exactly the same as the one generated by the make_ext4fs utility bundled with cm and aosp. I had to apply patches to libsparse in order to fix. After apply the patch I am now able to flash up to 100%

Hello Mr..
Im ERFAN from iran..
i have the problem when repack system.img odin show error...
please help me...
thanks very much...
0 new messages