Lanchon / REPIT

A Device-Only Data-Sparing Repartitioning Tool For Android
159 stars 25 forks source link

Samsung Galaxy S4 Mini GT-I9190 (serrano3gxx) #63

Closed vaedasti closed 7 years ago

vaedasti commented 7 years ago

Rom:CyanogenMod 13.0 2016/12/04 Kernel:Remix Kernel Recovery:Unofficial TWRP 3.0.2-1 Dump file: repit-dump.log.txt

Lanchon commented 7 years ago

hi, thanks!

any difference between serrano3g and serrano3gxx?

do you have a STOCK samsung image zipfile? could you please provide the file called "aboot" or "emmc_appsboot.mbn" within it? i highly suspect this device has a signed GPT.

vaedasti commented 7 years ago

Sorry, there is no difference between serrano3g and serrano3gxx. They are same thing.

Yes, there is have a file called "aboot.mbn" in the zipfile.

Lanchon commented 7 years ago

could you please zip aboot and post it here?

vaedasti commented 7 years ago

Here it is. aboot.zip

Lanchon commented 7 years ago

thanks!

$ strings aboot.mbn | grep -i gpt | grep -i sign

GPT: (WARNING) Primary signature invalid
GPT: Primary and backup signatures invalid
GPT: Primary signature invalid cannot write GPT
GPT: Backup signature invalid cannot write GPT

i'm sad to inform that there are strings in the bootloader that hint to a signed GPT. your bootloader might or might not enforce GPT signatures.

in case it does, altering the GPT might brick the device. the expectation is that not even fastboot would work, and the device would drop to one of the qualcomm bulk interfaces.

to recover from that situation requires qualcomm's tools and leaked factory firmware files for your device. do you know if such files exist?

there's a real hard-bricking possibility here. i can't really recommend going forward unless you are certain that you can unbrick your device. and... i wont be able to help you with that. so what do you think? call it off?

vaedasti commented 7 years ago

I'm gonna look at the firmware files. If i find something i will write it. Also, what is it "Qualcomm Bulk Interface"?

Lanchon commented 7 years ago

search for info on qualcomm's QPST info QXDM tools.

vaedasti commented 7 years ago

Ok. I think i know how to recover bricked device if its happens. Let's do it.

Lanchon commented 7 years ago

oh crap!! if you insist...

ok, im going out tonight, i'll try to port it tomorrow. later!

PS... you need the leaked files for your exact device!! those tools do not work without them. also, leaked files can require a particular bootloader version, and your BL could be newer. please double check and confirm here. thanks!

vaedasti commented 7 years ago

I confirm. I have these files and i want to do it.

Lanchon commented 7 years ago

i'm sorry for the delay, i have other stuff going on, but i will do this ASAP. thanks for understanding.

vaedasti commented 7 years ago

I apologize for keeping you from your job. Do it when you want. We don't have a hurry. PS: I'm sorry.

Lanchon commented 7 years ago

hi,

i really very sorry for the enormous delay in handling this.

so here is the port: serrano3gxx_UNTESTED.zip

download the file and rename it to: lanchon-repit-20170105-system=1G-cache=32M+wipe-preload=min+wipe-data=max-serrano3gxx_UNTESTED.zip and you are ready to brick your phone.

may the force be with you...

vaedasti commented 7 years ago

Sorry, i can't do it for now. I have exams. So, i should study. But i will do it on 15 January. Again i'm sorry and thank you.

Lanchon commented 7 years ago

it's me who is sorry for taking so long.

anyway, best of luck with the exams!!!

vaedasti commented 7 years ago

Well, i flashed the file today and it didn't work. This is what the TWRP's last words.

[ERROR 1]

Updater process ended with ERROR: 1
Error installing zip file '/tmp/lanchon-repit-20170105-system=1G+wipe-cache=32M+wipe-preload=min+wipe-data=max+wipe-serrano3gxx_UNTESTED.zip'
Updating partition details...
Failed to mount '/system' (No such file or directory)
...done

Log file: lanchon-repit.log.txt

Lanchon commented 7 years ago

from your log:

=====  PREPARATION  =====
info: determining usable sector range of block device
Warning! Main and backup partition tables differ! Use the 'c' and 'e' options
on the recovery & transformation menu to examine the two tables.

Warning! One or more CRCs don't match. You should repair the disk!

info: checking existing partitions
#####  processing heap 'main'
info: checking existing partition layout
info: current size: partition #21 'system' (system): 1500 MiB
info: current size: partition #22 'cache' (cache): 200 MiB
info: current size: partition #23 'preload' (hidden): 100 MiB
info: current size: partition #24 'data' (userdata): 5487 MiB
info: checking new partition layout
info: new size: partition #21 'system' (system): 1024 MiB
info: new size: partition #22 'cache' (cache): 32 MiB
info: new size: partition #23 'preload' (hidden): 8 MiB
info: new size: partition #24 'data' (userdata): 6223 MiB

=====  DRY-RUN  =====
#####  processing heap 'main'
-----  analyzing partition #21 'system' (system)
*****  processing partition #21 'system' (system)
info: will format the partition in ext4 and trim it
-----  analyzing partition #22 'cache' (cache)
*****  processing partition #22 'cache' (cache)
info: will format the partition in ext4 and trim it
-----  analyzing partition #23 'preload' (hidden)
*****  processing partition #23 'preload' (hidden)
info: will format the partition in ext4 and trim it
-----  analyzing partition #24 'data' (userdata)
*****  processing partition #24 'data' (userdata)
info: will format the partition in ext4 and trim it

=====  EXECUTION  =====
#####  processing heap 'main'
-----  analyzing partition #21 'system' (system)
*****  processing partition #21 'system' (system)
info: deleting current partition
info: creating new partition
Error: Unable to satisfy all constraints on the partition.
info: attempting to restore previous partition
Error: Unable to satisfy all constraints on the partition.

several very strange things. first:

info: determining usable sector range of block device
Warning! Main and backup partition tables differ! Use the 'c' and 'e' options
on the recovery & transformation menu to examine the two tables.

Warning! One or more CRCs don't match. You should repair the disk!

it seems the GPT in your device had some error. it usually means that the manufacturer pushes out phones with that same error on every phone. ive seen this kind of thing many times before. usually it produces warnings on the first execution, but then the partitioning tools used by REPIT fix the error and everything goes well.

but this time, what is really strange is that neither sgdisk nor parted saw anything strange!! this is the first time i see such a thing. take a look in the dump you published before:

==========================================================================================================
parted -s /dev/block/mmcblk0 unit MiB print free unit s print free
----------------------------------------------------------------------------------------------------------
Model: MMC SEM08G (sd/mmc)
Disk /dev/block/mmcblk0: 7456MiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start    End      Size     File system  Name      Flags
        0.02MiB  4.00MiB  3.98MiB  Free Space
 1      4.00MiB  64.0MiB  60.0MiB               modem
 2      64.0MiB  64.1MiB  0.13MiB               sbl1
 3      64.1MiB  64.4MiB  0.25MiB               sbl2
 4      64.4MiB  64.9MiB  0.50MiB               sbl3
 5      64.9MiB  66.9MiB  2.00MiB               aboot
 6      66.9MiB  67.4MiB  0.50MiB               rpm
 7      67.4MiB  67.9MiB  0.50MiB               tz
 8      67.9MiB  80.4MiB  12.5MiB               pad
 9      80.4MiB  88.4MiB  8.00MiB               param
10      88.4MiB  102MiB   13.6MiB  ext4         efs
11      102MiB   105MiB   3.00MiB               modemst1
12      105MiB   108MiB   3.00MiB               modemst2
13      108MiB   118MiB   10.0MiB               boot
14      118MiB   128MiB   10.0MiB               recovery
15      128MiB   138MiB   10.0MiB               fota
16      138MiB   145MiB   6.99MiB               backup
17      145MiB   148MiB   3.00MiB               fsg
18      148MiB   148MiB   0.01MiB               ssd
19      148MiB   156MiB   8.00MiB  ext4         persist
20      156MiB   168MiB   12.0MiB  ext4         persdata
21      168MiB   1668MiB  1500MiB  ext2         system
22      1668MiB  1868MiB  200MiB   ext4         cache
23      1868MiB  1968MiB  100MiB   ext4         hidden
24      1968MiB  7456MiB  5488MiB  ext4         userdata

Model: MMC SEM08G (sd/mmc)
Disk /dev/block/mmcblk0: 15269888s
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start     End        Size       File system  Name      Flags
        34s       8191s      8158s      Free Space
 1      8192s     131071s    122880s                 modem
 2      131072s   131327s    256s                    sbl1
 3      131328s   131839s    512s                    sbl2
 4      131840s   132863s    1024s                   sbl3
 5      132864s   136959s    4096s                   aboot
 6      136960s   137983s    1024s                   rpm
 7      137984s   139007s    1024s                   tz
 8      139008s   164607s    25600s                  pad
 9      164608s   180991s    16384s                  param
10      180992s   208895s    27904s     ext4         efs
11      208896s   215039s    6144s                   modemst1
12      215040s   221183s    6144s                   modemst2
13      221184s   241663s    20480s                  boot
14      241664s   262143s    20480s                  recovery
15      262144s   282623s    20480s                  fota
16      282624s   296943s    14320s                  backup
17      296944s   303087s    6144s                   fsg
18      303088s   303103s    16s                     ssd
19      303104s   319487s    16384s     ext4         persist
20      319488s   344063s    24576s     ext4         persdata
21      344064s   3416063s   3072000s   ext2         system
22      3416064s  3825663s   409600s    ext4         cache
23      3825664s  4030463s   204800s    ext4         hidden
24      4030464s  15269854s  11239391s  ext4         userdata

==========================================================================================================
sgdisk /dev/block/mmcblk0 --set-alignment 1 --print
----------------------------------------------------------------------------------------------------------
Disk /dev/block/mmcblk0: 15269888 sectors, 7.3 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 98101B32-BBE2-4BF2-A06E-2BB33D000C20
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 15269854
Partitions will be aligned on 1-sector boundaries
Total free space is 8158 sectors (4.0 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            8192          131071   60.0 MiB    0700  modem
   2          131072          131327   128.0 KiB   FFFF  sbl1
   3          131328          131839   256.0 KiB   FFFF  sbl2
   4          131840          132863   512.0 KiB   FFFF  sbl3
   5          132864          136959   2.0 MiB     FFFF  aboot
   6          136960          137983   512.0 KiB   FFFF  rpm
   7          137984          139007   512.0 KiB   FFFF  tz
   8          139008          164607   12.5 MiB    FFFF  pad
   9          164608          180991   8.0 MiB     8300  param
  10          180992          208895   13.6 MiB    8300  efs
  11          208896          215039   3.0 MiB     FFFF  modemst1
  12          215040          221183   3.0 MiB     FFFF  modemst2
  13          221184          241663   10.0 MiB    FFFF  boot
  14          241664          262143   10.0 MiB    FFFF  recovery
  15          262144          282623   10.0 MiB    FFFF  fota
  16          282624          296943   7.0 MiB     8300  backup
  17          296944          303087   3.0 MiB     FFFF  fsg
  18          303088          303103   8.0 KiB     FFFF  ssd
  19          303104          319487   8.0 MiB     8300  persist
  20          319488          344063   12.0 MiB    8300  persdata
  21          344064         3416063   1.5 GiB     8300  system
  22         3416064         3825663   200.0 MiB   8300  cache
  23         3825664         4030463   100.0 MiB   8300  hidden
  24         4030464        15269854   5.4 GiB     8300  userdata

no warnings at the beginning of the runs! which is the usual outcome if anything is not exactly perfect.

second, the REPIT plan fails! the plan is valid: it starts with resizing /system first from 1500MB to 1GiB keeping the start address. this should be possible but fails for unknown reasons:

info: checking existing partitions
#####  processing heap 'main'
info: checking existing partition layout
info: current size: partition #21 'system' (system): 1500 MiB
...
info: checking new partition layout
info: new size: partition #21 'system' (system): 1024 MiB
...

=====  DRY-RUN  =====
#####  processing heap 'main'
-----  analyzing partition #21 'system' (system)
*****  processing partition #21 'system' (system)
info: will format the partition in ext4 and trim it
...

=====  EXECUTION  =====
#####  processing heap 'main'
-----  analyzing partition #21 'system' (system)
*****  processing partition #21 'system' (system)
info: deleting current partition
info: creating new partition
Error: Unable to satisfy all constraints on the partition.
info: attempting to restore previous partition
Error: Unable to satisfy all constraints on the partition.

so the partition deletion goes ok, but recreating the partition fails. parted doesn't say why, but for sure REPIT is trying to de the right thing. it seems something is wrong with your GPT that parted didnt detect, but was enough to make the tool misbehave.

so after a REPIT plan fails, REPIT tries to at least undo enough work to keep the phone in working condition. a plan should NEVER EVER fail, but programs have bugs and so could REPIT; so it is prepared to handle this situation as a safety net anyway.

i've never seen a plan fail before. when i implemented this rollback mechanism i had to purposely introduce bugs in REPIT to trigger plan failure. and i can say that the rollback works just fine. but you can see that it fails anyway, even when trying to re create the exact original partition:\

info: attempting to restore previous partition
Error: Unable to satisfy all constraints on the partition.

clearly, it is parted that is failing here.

my assessment

it looks like your phone comes with an invalid GPT. not invalid enough to make linux not parse it. not invalid enough to make parted or sgdisk notice a problem. but invalid enough to make parted bork up the partition table after operating on it. this is very strange: parted is mature software and shouldn't do this. so strange in fact, that i suspect that my current assessment could be mistaken.

what can you do?

well, get to recovery your phone from the recovery files, im very sorry.

but... you could first get a new repit dump and post it here. this would help me analyze what the hell did parted do to your phone, and confirm suspicions. we could even escalate this to parted if it is a reasonable thing to do.

actually you can take TWO repit dumps. one now, before rebooting, if you haven't reboot yet. because i think there is a fair chance that the phone wont boot again because of GPT signature issues we talked about before. then reboot afterwards. then take a second repit dump.

i'd be interested in:

thanks so much, and i'm really very sorry. your device has been the most problematic of the lot. also, i think, the newest to try repit.

vaedasti commented 7 years ago

This is the first repit-dump (before reboot);

and this is the second (after reboot);

After all of that, it's booting. Nothing changed.

Lanchon commented 7 years ago

lol ok, good to hear that!

well now i know what happened, thank you!

so as you can see, both of the new dumps are the same as the original dump, with system included. the creation of system failed because... it's already there! so parted actually behaved well.

but how is it there if the deletion was successful? my guess is that parted created the new partition table as it should and then wrote it to disk. but the emmc has some mechanism configured that blocks writes to certain parts of the disk. this way, although the GPT is probably protected by signatures, people will still not brick their devices because the hardware won't let you change the GPT area.

so something along the disk stack failed the write but didnt report it to the kernel. so the partition was never actually git deleted. REPIT forces the kernel to reread the partition table after each change. so after this deletion attempt that failed silently, the GPT was reread (and the kernel saw the /system partition was there again), and as a result of this, so did parted. so when parted was later instructed to create the new partition, it complained that the space you want to use is already in use, which was exactly on target.

so the up side is that this mechanism protected you from having to recover your phone from an invalid GPT signature. the down side is that i think you will never be able to repartition your phone :(

thanks for all the hard work you put into this. i'm sorry it didnt work out.

i hope the exams went well though! thanks again

Lanchon commented 7 years ago

btw, you could technically repartition using LVM to pool partitions together and then create virtual volumes. but it would require big modifications to the way recovery and roms work, so it is out of scope here. for practical purposes i recommend you get a new phone instead if you absolutely need a different partition layout.

vaedasti commented 7 years ago

I'm sorry to for not working but i can live with that. Anyway. Thank You for all of your great work. I apologize for tired you. And thank you for asking my exams. They are.... not bad. Well, whatever. Have a nice day and have a nice life.

I apologize for my bad English.

Thank You. You are great.

Lanchon commented 7 years ago

lol, well no prob, u'll do better on the next exams anyway! ;) later!