[Android Q&A, Help & Troubleshooting] mirfatif:
I'm a mechanical engineer, not an IT guy. I can fix machines, perhaps, but not bricked phones. So try anything at your own extreme risk. This is NOT a step by step guide.

DEVICE:

QMobile Z8, same as Wikio Ridge 4G, (MSM8916).

Running Android 5.0.2, SuperSU rooted.

Kernel v 3.10.49

Thanks to [MENTION=6793286]ASAZING[/MENTION] for TWRP 3.0.2-0

PROBLEM:

So the screen started blinking and locking / unlocking automatically like UI resetting. And there was no SIM. At first I thought it's launcher or SuperSU causing problem. But it got worse over days. So I decided a factory flash since I didn't have untouched flashable zip.

Flashed firmware using QFIL but no success. Rebooted to recovery and TWRP was still there.

/data partition was locked and TWRP doesn't support decryption. So I did a factory reset and the message came: /data not mounted. Invalid Argument

Formatted /data from "Repair or Change Filesystem" option in TWRP and as a result /data and /cache both couldn't be mounted.

Formatted /cache, and /system too not mounted.

Manually formatted using '

make_ext4

' and tried '

fastboot format:ext4 userdata

' as well. Both succeeded apparently but mount still failed.

Run '

e2fsck

' and that showed: "Bad magic number in super block" and "The superblock could not be read."

Run '

mke2fs -n

' for alternate super blocks, run again '

e2fsck

' but no success. Images are attached.

'

sgdisk --verify

' gives this error log:

sgdisk --verify mmcblk0p1

[COLOR="Red"]***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format in memory.
***************************************************************

Exact type match not found for type code 7200; assigning type code for 'Linux filesystem'
Exact type match not found for type code 6500; assigning type code for 'Linux filesystem'
Exact type match not found for type code 7900; assigning type code for 'Linux filesystem'
Exact type match not found for type code 0D00; assigning type code for 'Linux filesystem'
Warning! Main partition table overlaps the first partition by 34 blocks!
You will need to delete this partition or resize it in another utility.

Warning! Secondary partition table overlaps the last partition by 3805778618 blocks!
You will need to delete this partition or resize it in another utility.

Problem: partitions 2 and 1 overlap:
Partition 2: 168689522 to 2104717761
Partition 1: 778135908 to 1919645538

Problem: partitions 3 and 1 overlap:
Partition 3: 1869881465 to 3805909656
Partition 1: 778135908 to 1919645538

Problem: partitions 3 and 2 overlap:
Partition 3: 1869881465 to 3805909656
Partition 2: 168689522 to 2104717761

Problem: partition 1 is too big for the disk.
Problem: partition 2 is too big for the disk.
Problem: partition 3 is too big for the disk.
Problem: partition 4 is too big for the disk.

Warning! Main partition table overlaps the first partition by 34 blocks!
You will need to delete this partition or resize it in another utility.

Warning! Secondary partition table overlaps the last partition by 3805778618 blocks!
You will need to delete this partition or resize it in another utility.

Identified 9 problems![/COLOR]

==========================
sgdisk --verify mmcblk0p16

[COLOR="red"]Creating new GPT entries.

Problem: GPT claims the disk is larger than it is! (Claimed last usable sector is 18446744073709551584, but backup header is at 1 and disk size is 2 sectors.
The 'e' option on the experts' menu will probably fix this problem

Identified 1 problems!
[/COLOR]
==========================
sgdisk --verify mmcblk0p17

[COLOR="red"]Creating new GPT entries.

Problem: GPT claims the disk is larger than it is! (Claimed last usable sector is 18446744073709551598, but backup header is at 15 and disk size is 16 sectors.
The 'e' option on the experts' menu will probably fix this problem

Identified 1 problems![/COLOR]

==========================
sgdisk --verify mmcblk0p22

[COLOR="red"]Creating new GPT entries.

Problem: GPT claims the disk is larger than it is! (Claimed last usable sector is 18446744073709551614, but backup header is at 31 and disk size is 32 sectors.
The 'e' option on the experts' menu will probably fix this problem

Identified 1 problems![/COLOR]

'

parted rm

' and '

fastboot erase

' didn't work either. Partition was still there.

Then I tried to flash stock recovery through TWRP. And recovery too gone.

Now, device boots directly to bootloader (fastboot mode) and is halted there. Have to '

fastboot boot recovery.img

' or '

fastboot boot boot.img

' each time.

Download Mode (QDLoader 9008) is also accessible.

FLASHING FACTORY FIRMWARE:

Now left only with fastboot and EDL, tried once again QFIL flasher, Wiko official flasher, QDownloader. Log says: "Read back verify failed at sector ...." for partitions misc, system, cache, persist, recovery, userdata (6 partitions) and 2 partition table *.bins

Hence proved, eMMC is malfunctioning and device now can't boot on its own due to no partition table.

Tried '

sgdisk --backup

' and 'sgdisk --load-backup' options for partition table. It gives error: "Warning! Current disk size doesn't match that of backup." and "Problem: Partition 28 ends before it begins." etc.

'

fastboot flash partition *.bin

' also failed with error: "remote: failed to write partition".

'

dd if=gpt_main0.bin of=/dev/block/mmcblk0

' apparently succeeded but comparing octal dump ('

od

') files of 34 sectors at start shows no difference, means file is not written to eMMC.

SOLUTION SUMMARY:

Partition SD card according to already existing partition table on internal eMMC.

Flash partition images from factory firmware to newly created partitions.

Modify kernel (boot.img) and recovery to boot from sd card instead of internal memory.

Boot kernel or recovery through fastboot.

SECTION 1

PARTITION SD CARD:

Here comes Google. Following the footsteps of [MENTION=4423479]lexelby[/MENTION] at this, I created gpt (parted command) on 16GB C-10 sd card using Ubuntu virtual machine.

Created first partition for external_sd card and 6 more of same size as original ones (size checked by parted and from rawprogram_unsparse.xml). Filesystems: system, userdata, cache & persist of ext4 while misc, recovery of linux-swap (though 'dd' will overwrite them).

Then I unsparsed userdata, system and cache images from factory firmware (on Windows used packsparseimg.exe binary). Sparsed images can only be flashed through fastboot?

Copied 5 prtitions images: userdata, system, cache, persist and misc using dd command to /dev/block/mmcblk1p*.

MODIFYING BOOT & RECOVERY:

Now coming to the changes in mount paths of boot and recovery (fstab and init.*.rc).

Extracted boot.img and then ramdisk using "Image Studio for Android". '

unpackbootimg

' and '

abootimg

' don't extract all files on Ubuntu. '

mkbootimg

' makes smaller boot.img file without boot.img-dtb. Perhaps I'm doing it wrong.

Anyway, then did '

grep dev/block

' on all extracted files. Results are attached for reference.

Made changes in "fstab.qcom" and "init.target.rc". For details on changes made, please read on RE-MODIFYING BOOT & RECOVERY.

Repacked boot.img

Similarly extracted recovery.img, did '

grep dev/block

' on all extracted files. And made changes in "recovery.fstab".

Repacked recovery.img

COPYING IMAGES TO PARTITIONS AND BOOTING:

'

fastboot flash boot boot.img

' and '

dd if=recovery.img of=dev/block/mmcblk1p*

' (though useless, have to boot from fastboot)

Rebooted to recovery by '

fastboot boot recovery.img

'

userdata, persist and cache couldn't be mounted in TWRP. Tried '

mount -t ext4 -o loop *.img

' on Ubuntu but there too not mounted. Googled and using commands '

file

', '

fdisk

', '

sfdisk

', '

e2fsck

' and finally '

resize2fs -f /*.img

' resolved the problem "bad geometry: block count xxx exceeds size of device...".

Also unsparsed userdata too large to handle and only a few MBs data inside, that too useless. Therefore, did '

make_ext4fs

' on cache & userdata.

Now booted kernel by '

fastboot boot boot.img

'

And.......... it boots. But very very slow (due to slow write speed of sd card obviously). Took almost half an hour at first boot.

UNRESOLVED PROBLEMS:

There is no sound. Because of /persist not mounted? And still no SIM, means radio firmware isn't readable from eMMC or this too due to /persist absent? After all that contains drivers. And also Wi-Fi and bluetooth not working.

SECTION 2

RE-PARTITION SD CARD:

So re-created gpt on sd card (using parted and fdisk) and in a hope to utilize all necessary partitions, 100% replicated all partitions (except larger userdata) including space required at start and end of eMMC for partition table. Partition tables of both mmcblk0 and mmvblk1 are attached.

RE-MODIFYING BOOT & RECOVERY:

Made following changes in boot.img:

DEVICE BOOTS ALSO WITHOUT MAKING ANY CHANGES TO BOOT.IMG.

I don't know why but 'bootdevice' is automagiacally changed from 7824900.sdhci (eMMC) to 7864900.sdhci (external SD card). It seems there is some auto-detection mechanism.

########## ./ramdisk/fstab.qcom ##########

#/dev/block/bootdevice/by-name/system /system ext4 ro,barrier=1,discard wait
#/dev/block/bootdevice/by-name/userdata /data ext4 nosuid,nodev,barrier=1,noauto_da_alloc,discard wait,check,encryptable=footer
#CHANGED TO
/dev/block/[B]mmcblk1p24[/B] /system ext4 ro,barrier=1,discard wait
/dev/block/[B]mmcblk1p32[/B] /data ext4 nosuid,nodev,barrier=1,noauto_da_alloc,discard wait,check,encryptable=footer

#/devices/soc.0/7864900.sdhci/mmc_host /storage/sdcard1 vfat nosuid,nodev wait,voldmanaged=sdcard1:auto,noemulatedsd
#[B]disabled[/B]

########## ./ramdisk/init.target.rc ##########

on fs
mount_all fstab.qcom

#wait /dev/block/bootdevice/by-name/cache
#mount ext4 /dev/block/bootdevice/by-name/cache /cache nosuid nodev barrier=1
#CHANGED TO
wait /dev/block/[B]mmcblk1p26[/B]
mount ext4 /dev/block/[B]mmcblk1p26[/B] /cache nosuid nodev barrier=1

#wait /dev/block/bootdevice/by-name/persist
#mount ext4 /dev/block/bootdevice/by-name/persist /persist nosuid nodev barrier=1
#CHANGED TO
wait /dev/block/[B]mmcblk1p25[/B]
mount ext4 /dev/block/[B]mmcblk1p25[/B] /persist nosuid nodev barrier=1

#wait /dev/block/bootdevice/by-name/modem
#mount vfat /dev/block/bootdevice/by-name/modem /firmware ro context=u:object_r:firmware_file:s0,shortname=lower,uid=1000,gid=1000,dmask=227,fmask=337
#CHANGED TO
wait /dev/block/[B]mmcblk1p1[/B]
mount vfat /dev/block/[B]mmcblk1p1[/B] /firmware ro context=u:object_r:firmware_file:s0,shortname=lower,uid=1000,gid=1000,dmask=227,fmask=337

on charger
#wait /dev/block/bootdevice/by-name/system
#mount ext4 /dev/block/bootdevice/by-name/system /system ro barrier=1
#CHANGED TO
wait /dev/block/[B]mmcblk1p24[/B]
mount ext4 /dev/block/[B]mmcblk1p24[/B] /system ro barrier=1

########## ./split_img/boot.img-cmdline ##########

#console=ttyHSL0,115200,n8 androidboot.console=ttyHSL0 androidboot.hardware=qcom user_debug=30 msm_rtb.filter=0x3F ehci-hcd.park=3 androidboot.bootdevice=7824900.sdhci lpm_levels.sleep_disabled=1
#CHANGED TO
console=ttyHSL0,115200,n8 androidboot.console=ttyHSL0 androidboot.hardware=qcom user_debug=30 msm_rtb.filter=0x3F ehci-hcd.park=3 [B]androidboot.bootdevice=7864900.sdhci[/B] lpm_levels.sleep_disabled=1

And following changes in recovery.img:

########## ./ramdisk/etc/recovery.fstab ##########

#/cache ext4 /dev/block/bootdevice/by-name/cache flags=display=Cache
#/system ext4 /dev/block/bootdevice/by-name/system flags=display=System
#/data ext4 /dev/block/bootdevice/by-name/userdata flags=encryptable=footer;length=-16384
#/persist ext4 /dev/block/mmcblk0p25 flags=backup=1;display=Persist
#/boot emmc /dev/block/bootdevice/by-name/boot flags=display=Boot
#/recovery emmc /dev/block/bootdevice/by-name/recovery flags=backup=1;display=Recovery
#/misc emmc /dev/block/bootdevice/by-name/misc /misc	flags=backup=1;display=Misc
#/firmware vfat /dev/block/mmcblk0p1 flags=backup=1;display=Modem
#/splash emmc /dev/block/mmcblk0p18 flags=backup=1;display=Splash
#/fsg	emmc /dev/block/mmcblk0p20	flags=backup=1;subpartitionof=/oem
#/aboot emmc /dev/block/mmcblk0p4 flags=backup=1;display=Aboot
#/abootbak emmc /dev/block/mmcblk0p5	flags=subpartitionof=/aboot;backup=1
#/hyp emmc /dev/block/mmcblk0p10 flags=backup=1;display=Firmware-update
#/sbl1 emmc /dev/block/mmcblk0p2 flags=backup=1;subpartitionof=/hyp
#/rpm emmc /dev/block/mmcblk0p6 flags=backup=1;subpartitionof=/hyp
#/tz emmc /dev/block/mmcblk0p8 flags=backup=1;subpartitionof=/hyp
#/hypbak emmc /dev/block/mmcblk0p11 flags=backup=1;subpartitionof=/hyp
#/sbl1bak emmc /dev/block/mmcblk0p3 flags=backup=1;subpartitionof=/hyp
#/rpmbak emmc /dev/block/mmcblk0p7 flags=backup=1;subpartitionof=/hyp
#/tzbak emmc /dev/block/mmcblk0p9 flags=backup=1;subpartitionof=/hyp
#/modemst1 emmc /dev/block/mmcblk0p13 flags=backup=1;display=EFS
#/modemst2 emmc /dev/block/mmcblk0p14 flags=backup=1;subpartitionof=/modemst1
#/oem emmc /dev/block/mmcblk0p30 flags=backup=1;display=OEM
#/DDR emmc /dev/block/mmcblk0p20 flags=backup=1;subpartitionof=/oem
#/fsc emmc /dev/block/mmcblk0p16 flags=backup=1;subpartitionof=/oem
#/ssd emmc /dev/block/mmcblk0p17 flags=backup=1;subpartitionof=/oem
#/pad emmc /dev/block/mmcblk0p12 flags=backup=1;subpartitionof=/oem

#CHANGED TO

/cache ext4 /dev/block/[B]mmcblk1p26[/B] flags=display=Cache
/system ext4 /dev/block/[B]mmcblk1p24[/B] flags=display=System
/data ext4 /dev/block/[B]mmcblk1p32[/B] flags=encryptable=footer;length=-16384
/persist ext4 /dev/block/[B]mmcblk1p25[/B] flags=backup=1;display=Persist
/boot emmc /dev/block/[B]mmcblk1p23[/B] flags=display=Boot
/recovery emmc /dev/block/[B]mmcblk1p27[/B] flags=backup=1;display=Recovery
/misc emmc /dev/block/[B]mmcblk1p15[/B]	flags=backup=1;display=Misc
/firmware vfat /dev/block/[B]mmcblk1p1[/B] flags=backup=1;display=Modem
/splash emmc /dev/block/[B]mmcblk1p18[/B] flags=backup=1;display=Splash
/fsg emmc /dev/block/[B]mmcblk1p21[/B]	flags=backup=1;subpartitionof=/oem
/aboot emmc /dev/block/[B]mmcblk1p4[/B] flags=backup=1;display=Aboot
/abootbak emmc /dev/block/[B]mmcblk1p5[/B]	flags=subpartitionof=/aboot;backup=1
/hyp emmc /dev/block/[B]mmcblk1p10[/B] flags=backup=1;display=Firmware-update
/sbl1 emmc /dev/block/[B]mmcblk1p2[/B] flags=backup=1;subpartitionof=/hyp
/rpm emmc /dev/block/[B]mmcblk1p6[/B] flags=backup=1;subpartitionof=/hyp
/tz emmc /dev/block/[B]mmcblk1p8[/B] flags=backup=1;subpartitionof=/hyp
/hypbak emmc /dev/block/[B]mmcblk1p11[/B] flags=backup=1;subpartitionof=/hyp
/sbl1bak emmc /dev/block/[B]mmcblk1p3[/B] flags=backup=1;subpartitionof=/hyp
/rpmbak emmc /dev/block/[B]mmcblk1p7[/B] flags=backup=1;subpartitionof=/hyp
/tzbak emmc /dev/block/[B]mmcblk1p9[/B] flags=backup=1;subpartitionof=/hyp
/modemst1 emmc /dev/block/[B]mmcblk1p13[/B] flags=backup=1;display=EFS
/modemst2 emmc /dev/block/[B]mmcblk1p14[/B] flags=backup=1;subpartitionof=/modemst1
/oem emmc /dev/block/[B]mmcblk1p30[/B] flags=backup=1;display=OEM
/DDR emmc /dev/block/[B]mmcblk1p20[/B] flags=backup=1;subpartitionof=/oem
/fsc emmc /dev/block/[B]mmcblk1p16[/B] flags=backup=1;subpartitionof=/oem
/ssd emmc /dev/block/[B]mmcblk1p17[/B] flags=backup=1;subpartitionof=/oem
/pad emmc /dev/block/[B]mmcblk1p12[/B] flags=backup=1;subpartitionof=/oem

#/external_sd auto /dev/block/mmcblk1p1 /dev/block/mmcblk1 flags=display="MicroSD Card";storage;wipeingui;removable
#CHANGED TO
# None. [B]External sd disabled[/B].

########## ./ramdisk/uneventd.rc ##########

#/dev/block/bootdevice/by-name/config 0660 system system
#CHANGED TO
/dev/block/[B]mmcblk1p29[/B] 0660 system system

########## ./split_img/recovery.img-cmdline ##########

#console=ttyHSL0,115200,n8 androidboot.console=ttyHSL0 androidboot.hardware=qcom user_debug=30 msm_rtb.filter=0x3F ehci-hcd.park=3 androidboot.bootdevice=7824900.sdhci lpm_levels.sleep_disabled=1 androidboot.selinux=permissive
#CHANGED TO
console=ttyHSL0,115200,n8 androidboot.console=ttyHSL0 androidboot.hardware=qcom user_debug=30 msm_rtb.filter=0x3F ehci-hcd.park=3 [B]androidboot.bootdevice=7864900.sdhci[/B] lpm_levels.sleep_disabled=1 androidboot.selinux=permissive

Repacked boot.img and recovery.img.

RE-COPYING IMAGES TO PARTITIONS AND BOOTING:

Copied (dd) all available (15) images to (20) partitions on sd card.

Copied (dd) the 10 images not found in factory firmware from mmcblk0 to mmcblk1. (Not sure if successful).

2 partitions (/data and /cache) already formatted in ext4.

'

fastboot boot recovery.img

'. All partitions are mounted now. No horrible error lines. :D

'

fastboot boot boot.img

'

ROM booted successfully WITH sounds, SIM, Wi-Fi and Bluetooth. All seems working well so far.

SECTION 3

Continued on post 3...