1

I have a ROM that I can flash on Samsung S10 5G(Qualcomm) successfully. My goal is to check whether I can modify system.img file of the ROM or not but before modification, I just want to verify that the AP file can be flashed after unpacking and packing of the system.img. To check this I have tried following:

Unpack-Pack AP file:

A) tar flashing:

  1. Extracted AP file using tar -xf AP...tar.md5 command.
  2. Compress the extracted files using tar -cvf AP...tar *
  3. Flash it with Odin3 v3.13.

B) tar.md5 flashing: - Get tar by following steps in A) and then run md5sum -t AP...tar >> AP...tar and mv AP...tar AP...tar.md5

Both Ap...tar and AP...tar.md5 flashed successfully.

Unpack-Pack system.img.ext4.lz4

  1. Extracted AP file using tar -xf AP...tar.md5 command. Extracted files are "boot.img.lz4, meta-data, userdata.img.ext4.lz4, carrier.img.ext4.lz4, persist.img.ext4.lz4, vbmeta.img.lz4, dqmdbg.img.ext4.lz4, recovery.img.lz4, vendor.img.ext4.lz4, dtbo.img.lz4, system.img.ext4.lz4".
  2. Extract system file using unlz4 system.img.ext4.lz4 command. This is giving me a system.img.ext4 Android sparse image.
  3. Tried following commands to compress system.img.ext4 without doing any modification:
    lz4 system.img.ext4 system.img.ext4.lz4                     - Default Compression
    lz4 -9 system.img.ext4 system.img.ext4.lz4              - High Compression 
    lz4 -l system.img.ext4 system.img.ext4.lz4              - Default Compression in Legacy format
    lz4 -l -9 system.img.ext4 system.img.ext4.lz4           - High Compression in Legacy format
    lz4 -0 -l system.img.ext4 system.img.ext4.lz4           - No Compression in Legacy format
    lz4 -B4 system.img.ext4 system.img.ext4.lz4             - Default Compression with Block size 4
    lz4 -B5 system.img.ext4 system.img.ext4.lz4             - Default Compression with Block size 5
    lz4 -B6 system.img.ext4 system.img.ext4.lz4             - Default Compression with Block size 6
    lz4 --no-frame-crc system.img.ext4 system.img.ext4.lz4   - Default Compression with no crc frame

and make an AP file by replacing the original system.img.ext4.lz4 file with the compressed file from above command(one at one time) and tried to flash it but every time it fails with "Odin FAIL! LZ4 is invalid"

LZ4 command detail: 1. Working on Ubuntu 18 2. Using "LZ4 command line interface 64-bits r128, by Yann Collet (Apr 3 2018)"

Tried with "LZ4 command line interface 64-bits v1.9.2, by Yann Collet" but get the same result.

file system.img.ext4.lz4 output:

  • Original file: system.img.ext4.lz4: LZ4 compressed data (v1.4+).
  • My version with both LZ4 (r128 and v1.9.2):

    1. For file compressed with legacy flag(-l): system.img.ext4.lz4: LZ4 compressed data (v0.1-v0.9)
    2. For file compressed without legacy flag(-l): system.img.ext4.lz4: LZ4 compressed data (v1.4+)

So, I think it means the file should be compressed without legacy flag.

Size

  1. With -9 flag i.e. High Compression the output file is of 3.3 GB.
  2. Without -9 flag i.e. Default Compression the output file is of 3.6 GB.

The Original file is of size 3.6 GB so, I think high compression should not be used.

But still the same error throws by Odin.

Any suggestion why it is happening?

Vatish Sharma
  • 1,536
  • 3
  • 16
  • 35

2 Answers2

5

Use This:

lz4 -B6 --content-size in.img out.img.lz4

For More Info: https://www.mankier.com/1/lz4

Found this solution from: https://forum.xda-developers.com/galaxy-s9/help/how-to-compress-samsung-images-lz4-t3844760

Ajay
  • 66
  • 3
  • 3
    While this might be the solution, it would be helpful if you could expand a bit more on what this command is doing exactly and why it's the correct one to use. – germi Oct 26 '19 at 10:22
  • https://forum.xda-developers.com/galaxy-s9/help/how-to-compress-samsung-images-lz4-t3844760 – Ajay Oct 27 '19 at 12:09
  • Thanks, it worked. I think, Odin wants the original size in the header of `lz4` file(which is the job of `--content-size` flag) and the block size should be 1MB(`-B6`). – Vatish Sharma Oct 29 '19 at 05:51
1

Assuming that system.img.ext4 isn't modified,

lz4 -l -9 system.img.ext4 system.img.ext4.lz4

is supposed to work. It's strange that it doesn't, although I notice in your example that you are compressing system.img, not system.img.ext4, so it's unclear if it's the same file.

Suggestion 1 : there might be a checksum somewhere that disallow playing with the lz4 payload. That part is system specific, so it can be difficult to know. You'll have to look around.

Suggestion 2 : compare your original system.img.ext4.lz4 with the one produced by recompressing with lz4. Try to figure out the differences (especially, smaller, larger ?)

Suggestion 3 : use a more recent version of lz4. r128 is actually very old. You could locally compile a more recent version such as v1.9.2, which contains ultra modes, able to compress more that -9 (the compression level can be upgraded to -12).

Cyan
  • 13,248
  • 8
  • 43
  • 78
  • 1
    Corrected the commands in description, last time I have used `unlz4 system.img.ext4.lz4 system.img` so `system.img` was in description. Just now I have used `unlz4 system.img.ext4.lz4` and tried `lz4 -l -9 system.img.ext4 system.img.ext4.lz4` but I get the same result. New thing, I have noticed is the output of file command on the original `system.img.ext4.lz4` is `system.img.ext4.lz4: LZ4 compressed data (v1.4+)` and the another `system.img.ext4.lz4` is `system.img.ext4.lz4: LZ4 compressed data (v0.1-v0.9)`. – Vatish Sharma Oct 24 '19 at 05:56
  • Compile ` LZ4 command line interface 64-bits v1.9.2, by Yann Collet ` from the source code and run `./lz4 -l -9 system.img.ext4 ../system.img.ext4.lz4` command. The output is of **3.3 GB** `system.img.ext4.lz4` file and the `file ../system.img.ext4.lz4` output is `../system.img.ext4.lz4: LZ4 compressed data (v0.1-v0.9)`. The original `system.img.ext4.lz4` is of **3.6 GB**. Any idea how can we make `LZ4 compressed data (v1.4+)` file? – Vatish Sharma Oct 24 '19 at 06:14
  • Tried with `./lz4 -l system.img.ext4 ../system.img.ext4.lz4` command and the output file is of **3.6 GB** but it also has same `file` command output. – Vatish Sharma Oct 24 '19 at 06:19
  • It's unclear if this is a compression format issue. Maybe there is something going on on the Odin side, or even from the Galaxy S10 side, which may prevent editing the payload. Maybe there is a watermark, with a checksum, somewhere, as part of the payload. I would recommend looking into Odin documentation regarding loading a different (non-official) payload. – Cyan Oct 24 '19 at 22:00
  • I get success in flashing simple `system.img.ext4` file by making a `tar` of it but the same thing doesn't work with lz4. Here is the detail: https://stackoverflow.com/questions/58541074/how-to-unpack-modify-pack-and-flash-system-img-ext4-file-using-odin – Vatish Sharma Oct 25 '19 at 03:53