[Tool] SparseConverter v1.0.1

G4 Man2

Senior Member
May 4, 2011
883
286
0
Coffeyville
I think you're confused, once the image is decompressed, it's no longer a sparse file, you shouldn't use simg2img (to convert it to raw image, because it's already been done).
instead, you can just mount the image, for ext4 it would be:
Code:
sudo mount -t ext4 -o loop,offset=131072 system.img mnt/
and when you're done customizing:
Code:
sudo ./make_ext4fs -l 840M -a system mysystem.img mnt/
sudo umount mnt
(note that I've used offset=131072 instead of removing the header)
After the second command I'm getting a memory allocation error though
"error: do_inode_allocate_extents: Failed to allocate 6524 blocks"
Also, just to be complete, the way I am going to modify/root the ext4 image is by using TWRP on a bootloader unlocked device according to these instructions:

http://forum.xda-developers.com/showpost.php?p=60389310&postcount=177


It worked for the XT1096 so it should work for the XT1097. Once we get the rooted ext4 image, we have a tool to flash it to the XT1097 that bypasses the signature check. Our bootloaders are locked so we have to do it this way.
After adjusting the length flag to 3 gigs I was able to get it to work (I'm clueless but I assume that's what I was supposed to do). I'm hesitant to start uploading until I can get verification though.
 

tal.aloni

Member
May 12, 2014
46
95
0
After adjusting the length flag to 3 gigs I was able to get it to work (I'm clueless but I assume that's what I was supposed to do)
It should be the same as the system.img that you're mounting (don't forget to subtract the header length).
p.s. 840MB is for the Moto G GPE, for the Moto X it should be 2768MB.
 

G4 Man2

Senior Member
May 4, 2011
883
286
0
Coffeyville
It should be the same as the system.img that you're mounting (don't forget to subtract the header length).
p.s. 840MB is for the Moto G GPE, for the Moto X it should be 2768MB.
Unfortunately I'm just the middle man who runs linux so I don't know exactly what I'm doing with the image.

So you're saying I should use the commands you gave earlier (replacing 840 with 2768) and I should be golden? Or do I need an extra step to "subtract the header length"?
 

tal.aloni

Member
May 12, 2014
46
95
0
So you're saying I should use the commands you gave earlier (replacing 840 with 2768) and I should be golden? Or do I need an extra step to "subtract the header length"?
Take the length of the system.img you've decompressed (with the Motorola header and footer), subtract (128KB + 4KB) from it, and that's the size of the raw image that you should end up with.

example: say your system.img is 2,902,593,536 bytes, you remove the header and footer from that and are left with 2,902,458,368 bytes,
that's exactly 2768MB.
 
Last edited:
  • Like
Reactions: JulesJam

G4 Man2

Senior Member
May 4, 2011
883
286
0
Coffeyville
Take the length of the system.img you've decompressed (with the Motorola header and footer), subtract (128KB + 4KB) from it, and that's the size of the raw image that you should end up with.

example: say your system.img is 2,902,593,536 bytes, you remove the header and footer from that and are left with 2,902,458,368 bytes,
that's exactly 2768MB.
The system image I have (with the header and footer) is in fact 2,902,593,536 bytes. So I do need to set the length to 2768M and I should be good?
 

tal.aloni

Member
May 12, 2014
46
95
0
The system image I have (with the header and footer) is in fact 2,902,593,536 bytes. So I do need to set the length to 2768M and I should be good?
Yes.
note that it would only make sense to use make_ext4fs (which would create a new ext4 image) if you have made changes to the raw image.
if you're just sending the decompressed image to someone else, then just remove the header and footer with HxD, and you'll have an unmodified ext4 raw image.
 
  • Like
Reactions: JulesJam

G4 Man2

Senior Member
May 4, 2011
883
286
0
Coffeyville
Yes.
note that it would only make sense to use make_ext4fs (which would create a new ext4 image) if you have made changes to the raw image.
if you're just sending the decompressed image to someone else, then just remove the header and footer with HxD, and you'll have an unmodified ext4 raw image.
To my knowledge, all I'm doing is using some tools I have available to follow directions from JulesJam.

Here's what he said.
"I was able to make a single file but as the OP of that thread indicates, there is a header in the files.

When I try to flash it to my XT1096, it says invalid sparse file format at header magi. So obviously the header is noticed. However, it then proceeds to try to flash it. But it gives me a signature error - invalid signed image - and the flash is aborted. I can boot normally from bootloader mode so no issues there. "

He then asked for someone with the tools available to " convert the file into ext4 format"

I'm not knowledgeable in all this, I'm just trying to help a guy out.
 

JulesJam

Senior Member
Aug 9, 2014
2,468
773
0
Yes.
note that it would only make sense to use make_ext4fs (which would create a new ext4 image) if you have made changes to the raw image.
if you're just sending the decompressed image to someone else, then just remove the header and footer with HxD, and you'll have an unmodified ext4 raw image.
With your help @G4 Man2 was able to make an ext4 image that flashed successfully. Thanks for all of your help!!!

I was able to root the unmodified ext4 image and then I could use the tool we have - MoFo - to flash it to my phone with a locked bootloader. Next someone has to bake some useful features into the ext4 image to make it, well useful!

Our (Verizon and ATT Moto X 2014) bootloaders are locked so we have to use MoFo to flash unsigned, modified ext4 images to have root, Xposed, busy box, etc.

Thanks again for all of your help!!!
 

G4 Man2

Senior Member
May 4, 2011
883
286
0
Coffeyville
How do I do this? Is this what I use?

http://mh-nexus.de/en/hxd/

@G4 Man2 - does this require linux?
Any hex editor, even ones on Windows that can edit system images will work. Open your image with the editor and to get rid of the Motorola header and footer, delete the first 131072 bytes and the last 4096 bytes. Then save the image and that's that.
 
Last edited:
  • Like
Reactions: JulesJam

JulesJam

Senior Member
Aug 9, 2014
2,468
773
0
Any hex editor, even ones on Windows that can edit system images will work. Open your image with the editor and to get rid of the Motorola header and footer, delete the first 131072 bits and the last 4096 bits. Then save the image and that's that.
This is what I see:

Image is 2,834,564 and I need it to be 2,834,432.
 

Attachments

G4 Man2

Senior Member
May 4, 2011
883
286
0
Coffeyville
This is what I see:

Image is 2,834,564 and I need it to be 2,834,432.
Say that I wanted to delete a 3 byte header and a 4 byte footer.

I would delete the first 3 FF FF FF
And the last 4 FF FF FF FF
So you need to delete the first 131072 pairs of digits and the last 4096 pairs of digits.
 
Last edited:
  • Like
Reactions: JulesJam

JulesJam

Senior Member
Aug 9, 2014
2,468
773
0
Say that I wanted to delete a 3 bit header and a 4 bit footer.

I would delete the first 3 FF FF FF
And the last 4 FF FF FF FF
So you need to delete the first 131072 pairs of digits and the last 4096 pairs of digits.
Each row has 16 pairs and 131072 pairs divided by 16 = 8192. So I have to delete the first 8,192 rows?

If I convert 8192 into hex, that is 2000 so I delete all of the pairs through row 2000 including row 2000? Or not including row 2000?
 

G4 Man2

Senior Member
May 4, 2011
883
286
0
Coffeyville
Each row has 16 pairs and 131072 pairs divided by 16 = 8192. So I have to delete the first 8,192 rows?

If I convert 8192 into hex, that is 2000 so I delete all of the pairs through row 2000 including row 2000? Or not including row 2000?
I'm just gonna be honest with ya. On the software I use, I just entered 131072 and it took me to that byte. I'm no hex expert. I can tell you though you should see a difference in what the bytes contain where you need to separate the header and footer from the contents.
 

JulesJam

Senior Member
Aug 9, 2014
2,468
773
0
I'm just gonna be honest with ya. On the software I use, I just entered 131072 and it took me to that byte. I'm no hex expert. I can tell you though you should see a difference in what the bytes contain where you need to separate the header and footer from the contents.
How did you do the footer?
 

JulesJam

Senior Member
Aug 9, 2014
2,468
773
0
SparseConverter.exe /compress D:\system.img E:\ 256MB
( will compress D:\system.img to 256MB sparse files starting from E:\system.img_sparsechunk1 )
I have a system.img that is flashable as is by fastboot. I want it to be an ext4 image. Can this tool do that for me? When I run that command above, it tells me Image size is a not a multiple of 4096 bytes.

---------- Post added at 06:01 AM ---------- Previous post was at 05:59 AM ----------

Searched for the 4096th byte from the end
I think I figured it out. thanks!