The story: I was running the phone with a custom built cm-10.1 and playing Candy Crush when the battery died. After that the phone wouldn't boot. After booting into recovery it appeared /efs wouldn't mount. That puts the phone in a boot loop. Desperation...
The key to the provided solution is that eventhough your parition is damaged, the relevant data (nv_data.bin) may still exist.
Here's what I did. Not all steps may be necessary, but this is what happened to work for me. The steps I think are crucial are highlighted.
!!!AS USUAL, TRY ANY OF THIS AT YOUR OWN RISK!!! In any case, only do this when your efs partition is damaged and won't mount, not when only files in it are missing or something else.
1. Create an image of /dev/block/mmcblk0p3. mmcblk0p3 is the device file for the partition that is mounted as /efs
I did this by logging into the phone while it is in recovery with adb:
linux# adb root linux# adb shell phone# dd if=/dev/block/mmcblk0p3 of=/data/efs.img phone# exit linux# adb pull /data/efs.img .
linux# losetup /dev/loop0 efs.img linux# fsck /dev/loop0
2. I still didn't know what to do so I flashed a stock ROM (G4) using Odin. Still boot looping. Since I wasn't sure the partition table wasn't damaged and the efs partition was lost anyway, I decided to check "Repartition", which is generally discouraged, using a pit file downloaded from the forum.
3. I re-rooted using CF-Root. This time using Heimdal from linux. Stock didn't fix things and you need root to access the partitions.
4. Format the efs! It's unusable and I made a backup, so in recovery:
linux# adb root linux# adb shell phone# mke2fs /dev/block/mmcblk0p3
5. I edited some files in /efs/FactoryApp
linux# adb root linux# adb shell phone# cd /efs/FactoryApp phone# echo -n ON > factorymode phone# echo -n ON > keystr phone# echo -n <xxxxxxx> > serial_no
6. I flashed cm-10.1 again from recovery, because I was experimenting with EFSPro, which requires busybox on the phone. EFSPro doesn't do much for you in this case. So I don't think this is important.
7. Try to recreate an nv_data.bin from the damaged partition! In order to do this I pulled the rebuilt default nv_data.bin from the phone and compared it to efs.img created in step 1.
linux# adb root linux# adb pull /efs/nv_data.bin . linux# xxd nv_data.bin > nv_data.hex linux# xxd efs.img > efs.hex
0000000: cccc cccc cccc cccc cccc cccc cccc cccc ................ 0000010: cccc cccc cccc cccc cccc cccc cccc cccc ................ 0000020: 4d21 5317 00a0 a2f7 1435 5799 529d 129b M!S......5W.R... 0000030: 48bd ca0e 6249 1367 37a5 96c3 39da 19ea H...bI.g7...9... 0000040: 0000 0000 e000 0000 0200 7400 6c00 0000 ..........t.l... 0000050: 0000 0000 0000 8130 0100 0000 0000 0000 .......0........ 0000060: ffff ffff ffff ffff ffff ffff ffff ffff ................ 0000070: ffff ffff 0200 0000 333a 3476 2020 2020 ........3:4v 0000080: 5350 3632 3630 5f4d 305f 4d4f 4445 4d5f SP6260_M0_MODEM_ 0000090: 3033 2e31 3332 375f 4442 3133 3037 3032 03.1327_DB130702 00000a0: 2032 3031 332d 4a75 6c2d 3136 2032 303a 2013-Jul-16 20: 00000b0: 3035 3a33 3020 0a20 2020 2050 4442 5f4e 05:30 . PDB_N 00000c0: 4f54 5f41 5641 494c 4142 4c45 200a 0000 OT_AVAILABLE ...
0600080: 5350 3632 3630 5f4d 305f 4d4f 4445 4d5f SP6260_M0_MODEM_ 0600090: 3033 2e31 3234 315f 4442 3132 3130 3038 03.1241_DB121008 06000a0: 2032 3031 322d 4e6f 762d 3136 2031 343a 2012-Nov-16 14: 06000b0: 3030 3a34 3920 0a20 2020 2050 4442 5f4e 00:49 . PDB_N 06000c0: 4f54 5f41 5641 494c 4142 4c45 200a 0000 OT_AVAILABLE ...
linux# dd if=efs.img of=new_nv_data.bin skip=12288 count=4096
8. Put the recreated nv_data.bin on the phone and delete backups.
linux# adb root linux# adb shell phone# cd /efs phone# rm nv_data.bin phone# rm .nv_data.bak phone# rm .nv_core.bak phone# adb push new_nv_data.bin /efs/nv_data.bin
Hope any of this may be of any help to anyone. It took me quite a while to figure things out !!