title: Odin FAIL! LZ4 is invalid
body: <p>I have a ROM that I can flash on Samsung S10 5G(Qualcomm) successfully. My goal is to check whether I can modify <code>system.img</code> 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 <code>system.img</code>. To check this I have tried following:</p>
  
  <p><strong>Unpack-Pack AP file:</strong></p>
  
  <p>A) <code>tar</code> flashing:</p>
  
  <ol>
  <li>Extracted AP file using <code>tar -xf AP...tar.md5</code> command.</li>
  <li>Compress the extracted files using <code>tar -cvf AP...tar *</code></li>
  <li>Flash it with Odin3 v3.13.</li>
  </ol>
  
  <p>B) <code>tar.md5</code> flashing:
  - Get tar by following steps in A) and then run <code>md5sum -t AP...tar &gt;&gt; AP...tar</code> and <code>mv AP...tar AP...tar.md5</code></p>
  
  <p>Both <code>Ap...tar</code> and <code>AP...tar.md5</code> flashed successfully.</p>
  
  <p><strong>Unpack-Pack <code>system.img.ext4.lz4</code></strong></p>
  
  <ol>
  <li>Extracted AP file using <code>tar -xf AP...tar.md5</code> command. Extracted files are "<em>boot.img.lz4</em>, <em>meta-data</em>, <em>userdata.img.ext4.lz4</em>, <em>carrier.img.ext4.lz4</em>, <em>persist.img.ext4.lz4</em>, <em>vbmeta.img.lz4</em>, <em>dqmdbg.img.ext4.lz4</em>, <em>recovery.img.lz4</em>, <em>vendor.img.ext4.lz4</em>, <em>dtbo.img.lz4</em>, <em>system.img.ext4.lz4</em>".</li>
  <li>Extract system file using <code>unlz4 system.img.ext4.lz4</code> command. This is giving me a <code>system.img.ext4</code> Android sparse image.</li>
  <li>Tried following commands to compress <code>system.img.ext4</code> without doing any modification:</li>
  </ol>
  
  <pre><code>    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
  </code></pre>
  
  <p>and make an AP file by replacing the original <code>system.img.ext4.lz4</code> file with the compressed file from above command(one at one time) and tried to flash it but every time it fails with <strong>"Odin FAIL! LZ4 is invalid"</strong></p>
  
  <p><strong>LZ4 command detail:</strong>
  1. Working on Ubuntu 18
  2. Using "LZ4 command line interface 64-bits r128, by Yann Collet (Apr 3 2018)"</p>
  
  <p>Tried with "<strong>LZ4 command line interface 64-bits v1.9.2, by Yann Collet</strong>" but get the same result.</p>
  
  <p><strong><code>file system.img.ext4.lz4</code> output:</strong></p>
  
  <ul>
  <li>Original file: <code>system.img.ext4.lz4: LZ4 compressed data (v1.4+)</code>.</li>
  <li><p>My version with both LZ4 (r128 and v1.9.2):</p>
  
  <ol>
  <li>For file compressed with <strong>legacy flag</strong>(-l): <code>system.img.ext4.lz4: LZ4 compressed data (v0.1-v0.9)</code></li>
  <li>For file compressed <strong>without legacy flag</strong>(-l): <code>system.img.ext4.lz4: LZ4 compressed data (v1.4+)</code></li>
  </ol></li>
  </ul>
  
  <p>So, I think it means the file should be compressed without legacy flag.</p>
  
  <p><strong>Size</strong></p>
  
  <ol>
  <li>With <code>-9</code> flag i.e. <strong>High Compression</strong> the output file is of <strong>3.3 GB</strong>.</li>
  <li>Without <code>-9</code> flag i.e. <strong>Default Compression</strong> the output file is of <strong>3.6 GB</strong>.</li>
  </ol>
  
  <p>The <strong>Original file</strong> is of size <strong>3.6 GB</strong> so, I think high compression should not be used.</p>
  
  <p>But still the same error throws by Odin.</p>
  
  <p>Any suggestion why it is happening?</p>