1
votes

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?

2

2 Answers

3
votes

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

1
votes

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).