[Android Q&A, Help & Troubleshooting] Jyibzz:
Failed mounting system.img with header

Hi all !

[history]

Three years ago I bought a phone (HTC Desire 320), the night I received it, I flash a ROM found on Internet and root it with the bad root application k*root.

(Bad because I install a firewall, and the app tried to connect to an IP from NSA, why ? Whatever...)

This weekend, I (by mistake) deleted a "framework" app, and the phone didn't start anymore. (In fact it start, but all applications restart, the pincode application, launchers, it was unusable anymore.)

Ok, so I reflash the ROM I had (I was more noob three years ago, I didn't make any dump of my "virgin" phone before flashing the other ROM found on the internet), by the way, "only" a weird version of SPflashtool (V5.1348_sec) can flash this phone, I don't know why, but it is another question, if someone have or could help me to get this version working on Linux, tell me please.

Right, my phone is repaired, as the virgin state. But I loose the root. I don't want to reuse any weird "one click root app". I've the system.img, I should be able to add it by myself ! But...

[/history]

I tried "unyaffs" but it didn't recognised the pattern. I tried "unsparse" (or sparse, or sparse.pl, I don't remember, all scripts I tried). But It didn't works.

After many trys, I'm still unable to mount it.

The last I tried is github.com/ehlers/unyaffs

$./unyaffs ../ROM/system.img
Can't determine flash layout, perhaps not a yaffs2 image

For example, a "normal" recovery.img (I don't know, but I guess in a yaffs format) should start with "ANDROID!", but before that, I've 0x4000 byte of header. I've maybe also a footer !

$ xxd -s 0x0000 -l 400 ./recovery.img

00000000: 4246 4246 0200 0000 0100 0000 0000 0001 BFBF............
00000010: 7265 636f 7665 7279 0000 0000 0000 0000 recovery........
00000020: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000030: 0078 4700 0000 0000 0000 0000 0000 0000 .xG.............
00000040: 3faa 9d18 1db9 8fbc b5e9 703f a5f9 9aa6 ?.........p?....
00000050: f8d3 ac26 8dc9 0a9d c912 ac32 6001 27d1 ...&.......2`.'.
00000060: 1e3f 7b14 79c3 3c0a 81f5 7f8d 50b3 aa17 .?{.y.<.....P...
00000070: a915 747b 548b 22d1 3b45 8522 5758 3d08 ..t{T.".;E."WX=.
00000080: 5bd9 679f 7866 7a47 e4ab 4b3b 3648 ded5 [.g.xfzG..K;6H..
00000090: caab 7f79 47f9 80b7 afce 02db c605 d367 ...yG..........g
000000a0: 5b49 9d72 bbce 2653 c2cd ef70 2f57 01e5 [I.r..&S...p/W..
000000b0: 458f 893d f33f a0fa 5398 f0d9 8e1c 2df0 E..=.?..S.....-.
000000c0: 302c d8f6 b5fe 6c0e b2b3 954f d6ee ec8d 0,....l....O....
000000d0: 65df 25ee 0000 0000 0000 0000 0000 0000 e.%.............
000000e0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000f0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000100: 4246 4246 0200 0000 0100 0000 0000 0001 BFBF............
00000110: 7265 636f 7665 7279 0000 0000 0000 0000 recovery........
00000120: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000130: 0078 4700 0000 0000 0000 0000 0000 0000 .xG.............
00000140: 7f11 0413 6baa 5df2 fc06 dd6f e25f 4b62 ....k.]....o._Kb
00000150: 86a2 b6f5 0000 0000 0000 0000 0000 0000 ................
00000160: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000170: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000180: 0000 0000 0000 0000 0000 0000 0000 0000 ................

$ xxd -s 0x38F0 -l 400 ./recovery.img

00003f80: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00003f90: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00003fa0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00003fb0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00003fc0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00003fd0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00003fe0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00003ff0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00004000: 5353 5353 5439 3800 0023 2323 2323 2323 SSSST98..#######
00004010: 2323 2323 2323 2323 0a00 6420 6173 2030 ########..d as 0
00004020: 2c20 7468 0100 0000 9400 0000 4000 0000 , th........@...
00004030: 797b 797b 0000 0000 0000 0000 0078 4700 y{y{.........xG.
00004040: 414e 4452 4f49 4421 08d3 3300 0080 0010 ANDROID!..3.....
00004050: 4e94 1300 0000 0011 0000 0000 0000 f010 N...............
00004060: 0001 0010 0008 0000 0000 0000 0000 0000 ................
00004070: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00004080: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00004090: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000040a0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000040b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000040c0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000040d0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000040e0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000040f0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00004100: 0000 0000 0000 0000 0000 0000 0000 0000 ................

As see, there is an header. I don't know what to do. Is the header important ? For example, does it contains a checksum or a signature ? Or could I split the .img into three part, header, image, footer, modifying the image, and simple concatenate the three files ?

For the ./system.img :

$ xxd -s 0x0000 -l 400 ./system.img

00000000: 4246 4246 0200 0000 4500 0000 0000 0001 BFBF....E.......
00000010: 7379 7374 656d 0000 0000 0000 0000 0000 system..........
00000020: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000030: 40fc 2444 0000 0000 0000 0000 0000 0000 @.$D............
00000040: 3534 a9d8 4d3e 2088 687c 4a50 af50 34f4 54..M> .h|JP.P4.
00000050: fce6 1622 dc25 8b53 fdb4 cbac 35f5 fdda ...".%.S....5...
00000060: 9d5f f0e1 ad7c bf21 01e8 caff 8ddc cd33 ._...|.!.......3
00000070: 87d7 8964 d151 9b78 99a5 64c1 88a8 970b ...d.Q.x..d.....
00000080: f647 1650 0672 28f3 c260 a4b5 5931 0039 .G.P.r(..`..Y1.9
00000090: d375 9896 4cd1 f201 fcf1 c4ec 4fef aae6 .u..L.......O...
000000a0: 33cd 7866 96f1 71cb bbbc 63cb be74 2433 3.xf..q...c..t$3
000000b0: c55c e485 cd06 de44 498f 6ee4 670c ee30 .\.....DI.n.g..0
000000c0: 322d 7ab1 f289 e1bb 412f d8bd 2aac 152a 2-z.....A/..*..*
000000d0: 7fa4 8e3f 0000 0000 0000 0000 0000 0000 ...?............
000000e0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000f0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000100: 4246 4246 0200 0000 4500 0000 0000 0001 BFBF....E.......
00000110: 7379 7374 656d 0000 0000 0000 0000 0000 system..........
00000120: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000130: 40fc 2444 0000 0000 0000 0000 0000 0000 @.$D............
00000140: 56ad 592a ee85 9a0c caa6 1acd d400 13f6 V.Y*............
00000150: 115a fd02 2d29 baa3 56bd 3368 fccd 3df8 .Z..-)..V.3h..=.
00000160: be30 7254 acad 1da1 5163 7c49 b184 ce55 .0rT....Qc|I...U
00000170: f210 cebd d948 4e0d a909 7bca 207a dbf9 .....HN...{. z..
00000180: 83bb 9673 7bf0 4b49 faea 39b8 9dd9 0403 ...s{.KI..9.....

$ xxd -s 0x38F0 -l 400 ./system.img

00003f80: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00003f90: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00003fa0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00003fb0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00003fc0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00003fd0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00003fe0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00003ff0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00004000: 5353 5353 5439 3800 0023 2323 2323 2323 SSSST98..#######
00004010: 2323 2323 2323 2323 0a00 6420 6173 2030 ########..d as 0
00004020: 2c20 7468 0100 0000 9400 0000 4000 0000 , th........@...
00004030: 797b 797b 0000 0000 0000 0000 40fc 2444 y{y{........@.$D
00004040: 3aff 26ed 0100 0000 1c00 0c00 0010 0000 :.&.............
00004050: 00ce 0400 0309 0000 0000 0000 c1ca 0000 ................
00004060: 0100 0000 0c10 0000 0000 0000 0000 0000 ................
00004070: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00004080: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00004090: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000040a0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000040b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000040c0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000040d0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000040e0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000040f0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00004100: 0000 0000 0000 0000 0000 0000 0000 0000 ................

For more information, I copy/paste some info from the scatter file here (cleared, without all lines).

- config_version: V1.1.1
platform: MT6582
project: uc81
boot_channel: MSDC_0
block_size: 0x20000

partition_name: PRELOADER
file_name: preloader_uc81.bin
type: SV5_BL_BIN
linear_start_addr: 0x0
physical_start_addr: 0x0
partition_size: 0xc00000

partition_name: MBR
file_name: MBR
type: NORMAL_ROM
linear_start_addr: 0xc00000
physical_start_addr: 0x0
partition_size: 0x80000

partition_name: EBR1
file_name: EBR1
type: NORMAL_ROM
linear_start_addr: 0xc80000
physical_start_addr: 0x80000
partition_size: 0x80000

partition_name: PRO_INFO
linear_start_addr: 0xd00000
physical_start_addr: 0x100000
partition_size: 0x300000

partition_name: NVRAM
linear_start_addr: 0x1000000
physical_start_addr: 0x400000
partition_size: 0x500000

partition_name: PROTECT_F
linear_start_addr: 0x1500000
physical_start_addr: 0x900000
partition_size: 0xa00000

partition_name: PROTECT_S
linear_start_addr: 0x1f00000
physical_start_addr: 0x1300000
partition_size: 0xa00000

partition_name: SECCFG
linear_start_addr: 0x2900000
physical_start_addr: 0x1d00000
partition_size: 0x20000

partition_name: UBOOT
file_name: lk.bin
type: NORMAL_ROM
linear_start_addr: 0x2920000
physical_start_addr: 0x1d20000
partition_size: 0x60000

partition_name: BOOTIMG
file_name: boot.img
type: NORMAL_ROM
linear_start_addr: 0x2980000
physical_start_addr: 0x1d80000
partition_size: 0x600000

partition_name: RECOVERY
file_name: recovery.img
type: NORMAL_ROM
linear_start_addr: 0x2f80000
physical_start_addr: 0x2380000
partition_size: 0x600000

partition_name: SEC_RO
file_name: secro.img
type: YAFFS_IMG
linear_start_addr: 0x3580000
physical_start_addr: 0x2980000
partition_size: 0x600000

partition_name: MISC
linear_start_addr: 0x3b80000
physical_start_addr: 0x2f80000
partition_size: 0x80000

partition_name: LOGO
file_name: logo.bin
type: NORMAL_ROM
linear_start_addr: 0x3c00000
physical_start_addr: 0x3000000
partition_size: 0x300000

partition_name: EBR2
file_name: EBR2
type: NORMAL_ROM
linear_start_addr: 0x3f00000
physical_start_addr: 0x3300000
partition_size: 0x80000

partition_name: RESV
linear_start_addr: 0x3f80000
physical_start_addr: 0x3380000
partition_size: 0x80000

partition_name: BLINKFEED
file_name: blinkfeed.img
type: YAFFS_IMG
linear_start_addr: 0x4000000
physical_start_addr: 0x3400000
partition_size: 0x2000000

partition_name: COTA
file_name: cota.img
type: YAFFS_IMG
linear_start_addr: 0x6000000
physical_start_addr: 0x5400000
partition_size: 0x3200000

partition_name: CUSTOM
file_name: custom.img
type: YAFFS_IMG
linear_start_addr: 0x9200000
physical_start_addr: 0x8600000
partition_size: 0x3700000

partition_name: EXPDB
linear_start_addr: 0xc900000
physical_start_addr: 0xbd00000
partition_size: 0xa00000

partition_name: ANDROID
file_name: system.img
type: YAFFS_IMG
linear_start_addr: 0xd300000
physical_start_addr: 0xc700000
partition_size: 0x4ce00000

partition_name: CACHE
file_name: cache.img
type: YAFFS_IMG
linear_start_addr: 0x5a100000
physical_start_addr: 0x59500000
partition_size: 0xc800000

partition_name: USRDATA
file_name: userdata.img
type: YAFFS_IMG
linear_start_addr: 0x66900000
physical_start_addr: 0x65d00000
partition_size: 0x78000000

partition_name: BMTPOOL
linear_start_addr: 0xFFFF00a8
physical_start_addr: 0xffff00a8
partition_size: 0x1500000

So, if I missed something, tell me and of course, any idea is welcome !

Jybz