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
Click to expand...
Click to collapse
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?
having the same problem here.anyone have a solution?
Why Ya dont use "lz4 -m *.lz4" command after Extract with tar, its Decompress all Files in one Process!!
But iam have the same Problem i would a Existing Package tar.md5 Extract and Replace the system.img.lz4 with a newer Version, so i have Compress the IMG to LZ4 with these Command
"lz4 -B6 --content-size system.img system.img.lz4" and then Pack all to tar and add md5sum!! and Flash the Package it would like ya Failed at System Flash Process!!!
Related
Is there a way to run mkbootimg in cygwin.. I can extract the ramdisk from boot & recovery images but cannot rebuild.. each time it fails to /usr/bin/mkbootimg: /usr/bin/mkbootimg: cannot execute binary file
Thanks.
If you interested in extracting the kernel image from the Samsung Galaxy S5 ROM, you should follow the following steps.
This is was tested with the G900VVRU1ANCG_G900VVZW1ANCG_VZW stock ROM firmware.
The first is extracting the files from the ROM firmware file, this is explained in many places and won't be covered here.
Extract the boot.img to some directory, using the Android unpackbootimg utility:
Code:
unpackbootimg -i boot.img -o boot/
After extracting the boot.img file you will usually end up with the following file list:
Code:
boot.img-base
boot.img-cmdline
boot.img-pagesize
boot.img-ramdisk.gz <- this includes the root (/) files, like init*.rc and SELinux policy files
boot.img-zImage <- compressed image of the Android Linux kernel
Next step will be extracting the compressed kernel image from the zImage file. The Android kernel is a self-extracting compressed file, while different devices use different compression methods. While looking at the file contents using hex editor, you can see the decompression code at the beginning, and then at some point the compressed data begins. The compressed image begins where you find the LZO magic header.
Code:
static const unsigned char lzop_magic[9] = {
0x89, 0x4c, 0x5a, 0x4f, 0x00, 0x0d, 0x0a, 0x1a, 0x0a
};
Save the data from the LZO magic header to the end of the file with the zImage.kernel file name.
This firmware and kernel are using LZO compression, and there is an easy to use utility called lzop that is used for the decompression of the file. Just run the following command to decompress the kernel from the zImage.kernel file:
Code:
lzop -d -c zImage.kernel > zImage.kernel.decompressed
And now you have the decompressed kernel for the device ready for exploration, which is also attached to this post.
Note:
I've tried using different scripts that do the job, including galaxys2_kernel_repack and http://forum.xda-developers.com/showthread.php?t=901152 but both failed while extracting the kernel image, although were able to extract the begin position for the LZO compression header.
But it does trip KNOX after flashing, doesn't it?
roman.blachman said:
If you interested in extracting the kernel image from the Samsung Galaxy S5 ROM, you should follow the following steps.
This is was tested with the G900VVRU1ANCG_G900VVZW1ANCG_VZW stock ROM firmware.
The first is extracting the files from the ROM firmware file, this is explained in many places and won't be covered here.
Extract the boot.img to some directory, using the Android unpackbootimg utility:
Code:
unpackbootimg -i boot.img -o boot/
After extracting the boot.img file you will usually end up with the following file list:
Code:
boot.img-base
boot.img-cmdline
boot.img-pagesize
boot.img-ramdisk.gz <- this includes the root (/) files, like init*.rc and SELinux policy files
boot.img-zImage <- compressed image of the Android Linux kernel
Next step will be extracting the compressed kernel image from the zImage file. The Android kernel is a self-extracting compressed file, while different devices use different compression methods. While looking at the file contents using hex editor, you can see the decompression code at the beginning, and then at some point the compressed data begins. The compressed image begins where you find the LZO magic header.
Code:
static const unsigned char lzop_magic[9] = {
0x89, 0x4c, 0x5a, 0x4f, 0x00, 0x0d, 0x0a, 0x1a, 0x0a
};
Save the data from the LZO magic header to the end of the file with the zImage.kernel file name.
This firmware and kernel are using LZO compression, and there is an easy to use utility called lzop that is used for the decompression of the file. Just run the following command to decompress the kernel from the zImage.kernel file:
Code:
lzop -d -c zImage.kernel > zImage.kernel.decompressed
And now you have the decompressed kernel for the device ready for exploration, which is also attached to this post.
Note:
I've tried using different scripts that do the job, including galaxys2_kernel_repack and http://forum.xda-developers.com/showthread.php?t=901152 but both failed while extracting the kernel image, although were able to extract the begin position for the LZO compression header.
Click to expand...
Click to collapse
I tried that and was given a warning of trailing bytes by `lzop`. Later when i do a `file` command on the resulting uncompressed file, it is not a vmlinux ELF image, rather it is a data file. How are we able to repack this image back into zImage? Any advise is appreciated thanks.
What i do if i have boot.img-kernel and boot.img-kernel_offset?
DGKG said:
What i do if i have boot.img-kernel and boot.img-kernel_offset?
Click to expand...
Click to collapse
The boot.img-kernel is your zimage file
What Source you used for Unpack?
Can you share link for you Scripts? or can you provide link to scripts for unpacking and repacking Note 9 Exynos Kernel?
Thanks
Greetings
I followed these procedures, and pushed the boot.img with Odin, but the phone goes into download mode stating: "Could not do normal boot." Can anyone see what I am doing wrong? How can I troubleshoot the issue? Is there some way I can look at some logs somewhere? I did save my recovery.log file from twrp to the sdcard before I loaded the backedup files and rebooted the phone. I put them here is there anything else I can do?
I tried the same thing with boot.img and I got the following:
Code:
[email protected]:~/xiaolu/mkbootimg_tools$ ./mkboot boot.img ksumag
Unpack & decompress boot.img to ksumag
kernel : zImage
ramdisk : ramdisk
page size : 2048
kernel size : 8262680
ramdisk size : 1064985
dtb size : 1300480
base : 0x00000000
kernel offset : 0x00008000
ramdisk offset : 0x02000000
second_offset : 0x00f00000
tags offset : 0x01e00000
dtb img : dt.img
cmd line : console=null androidboot.hardware=qcom user_debug=31 msm_rtb.filter=0x37 ehci-hcd.park=3
ramdisk is gzip format.
Unpack completed.
[email protected]:~/xiaolu/mkbootimg_tools$ cd ksumag/
[email protected]:~/xiaolu/mkbootimg_tools/ksumag$ ls
dt.img img_info ramdisk ramdisk.gz zImage
[email protected]:~/xiaolu/mkbootimg_tools/ksumag$
I put the scsi_wait.ko ( name? ) file in ramdisk /dev folder, and replaced the zImage and dt.img file with the ones I made, and packed them into my own boot.img file.
Here is the output:
Code:
[email protected]:~/xiaolu/mkbootimg_tools$ ./mkboot ksumag/ boot.img
mkbootimg from ksumag//img_info.
kernel : zImage
ramdisk : new_ramdisk.gz
page size : 2048
kernel size : 8262680
ramdisk size : 1082259
dtb size : 1300480
base : 0x00000000
kernel offset : 0x00008000
ramdisk offset : 0x02000000
tags offset : 0x01e00000
dtb img : dt.img
cmd line : console=null androidboot.hardware=qcom user_debug=31 msm_rtb.filter=0x37 ehci-hcd.park=3
Kernel size: 8262680, new ramdisk size: 1082259, boot.img: 10893312.
boot.img has been created.
...
Then I put all files in a tar file. I did make a couple of mistakes with files names, which I hope did not damage the boot.img file.
Code:
[email protected]:~/xiaolu/mkbootimg_tools$ tar -H ustar -c boot.img >> boot.img
tar: boot.img: file is the archive; not dumped
[email protected]:~/xiaolu/mkbootimg_tools$ ls
ARM dtbToolCM ksumag mkbootimg recovery.img
boot.img dtbtool.txt lz4 MyKernel.tar.md5 recovery.tar.md5
commands dtc mkboot oldfiles shahin
dtbTool ksuamg mkbootfs README.md sm-n900p-test1
[email protected]:~/xiaolu/mkbootimg_tools$ tar -H ustar -c boot.img > boot.img
tar: boot.img: file is the archive; not dumped
[email protected]:~/xiaolu/mkbootimg_tools$ tar -H ustar -c boot.img > boot.tar
[email protected]:~/xiaolu/mkbootimg_tools$
Then I took the hash of the entire thing:
Code:
[email protected]:~/xiaolu/mkbootimg_tools$ md5sum -t boot.tar >> boot.tar
[email protected]:~/xiaolu/mkbootimg_tools$ mv boot.tar boot.tar.md5
[email protected]:~/xiaolu/mkbootimg_tools$
What are you trying to get
kenny1991 said:
What are you trying to get
Click to expand...
Click to collapse
I am trying to get a flashable image. The file I get from the above procedure goes on my phone, but the kernel does not seem to be loaded. I am still learning about the boot process, and I do not know if my phone just has a bootloader or a bootstrap also; regardless it seems to not load the kernel since it goes into download mode. The recovery.log does not show anything either. I posted in pastebin. I can put link to it here if you think it would help. My goal is to flash my phone with a copy of the kernel which I built myself.
Oh you need a developer to respond for that.
kenny1991 said:
Oh you need a developer to respond for that.
Click to expand...
Click to collapse
Do you know if I can move this thread myself or perhaps request it from one of the admins? I do not know how effective it would be if I put a link to this discussion in the developer forum.
You may ask as you can't move it. You should move it to developers discussion forum
i want to remove some apk from system. so i plan make odin flashable tarball.
i just test the extract and repack, didn't do any modify, but it was fail.
1.
system.img.ext4.lz4 -> lz4 -> system.img.ext4 -> simg2img -> system.img -> img2simg -> system.img.ext4 -> N960U.tar(only system.img.ext4)
with system.img , i didn't modify anything,
after img2simg :
file system.img.ext4
system.img.ext4: Android sparse image, version: 1.0, Total of 1291776 4096-byte output blocks in 6335 input chunks.
Odin flash fail (auth), mobile show : security check fail system.
2.
system.img.ext4.lz4 -> lz4 -> system.img.ext4 -> N960U.tar(only system.img.ext4)
do not use simg2img or img2simg
after lz4:
file system.img.ext4
system.img.ext4: Android sparse image, version: 1.0, Total of 1291776 4096-byte output blocks in 6277 input chunks.
Odin flash success.
i also try to use mkuserimg.sh to repack android sparse image, but it also make fail.
mkuserimg.sh -s /Volumes/sysmain system.img.ext4 ext4 /system 529114496
The tow system.img.ext4 has some different, i want to compare the tow img file , but it to huge.
Any good idea? how the samsung mobile to check if it own img?
Sorry for my poor english.
[Q] Help on unpack repack ext4 system image
Does any one know how can I unpack and repack ext4 system images using cygwin? can you give me the complete and understandable tutorials on it? I have tried all of the tutorials here in XDA, but it seems that I can't follow the right way. Please...
forum.xda-developers.com
auth fail = OEM lock = BL Lock
must unlock bl or sampwnd
zalmen hatotach said:
[Q] Help on unpack repack ext4 system image
Does any one know how can I unpack and repack ext4 system images using cygwin? can you give me the complete and understandable tutorials on it? I have tried all of the tutorials here in XDA, but it seems that I can't follow the right way. Please...
forum.xda-developers.com
Click to expand...
Click to collapse
What errors do you get?
I have a `system.img.ext4.lz4` file that is compatible with my Samsung S10 5G(Qualcomm) device. I have extracted `system.img.ext4` file from the `system.img.ext4.lz4` using `unlz4 system.img.ext4.lz4` command.
I want to play with its content. So I have decided it in two steps:
1. Flash `system.img.ext4` without modification:
- Using `tar -cvf AP.tar system.img.ext4` command, I have created a AP.tar file.
- Flashed `AP.tar` file using Odin3 v3.13.
- It flashed successfully.
2. Flash `system.img.ext4` with modification:
a) Modifying
- With `simg2img system.img.ext4 system.img`, you will get a raw image file named `system.img`
- With `mkdir system`, create directory to mount system.img
- With `sudo mount -t ext4 -o loop system.img system/` you will get all files of `system.img` in `system` folder
- With `ls -l system/init.rc` note permissions: 750
- With `sudo chmod 777 system/init.rc` give write permissions
- With `sudo echo "#MODIFICATION " >> system/init.rc` done some modification in `init.rc`
- With `sudo chmod 750 init.rc` reset `init.rc` to the noted permissions
b) Calculate system sector size
- With `tune2fs -l system.img | grep "Block size\|Block count"` you will get block size and count
- With `echo $((1553064 * 4096))` multiply both results. I got 6361350144
c) Packing
- With `sudo make_ext4fs -s -l 6361350144 -a system system_new.img sys/` you will get `system_new.img` “Android Sparse Image” that has all changes
- With `sudo umount system` unmount the system directory
- With `rm -fr system` delete the system directory
d) Tar Compression
- With `rm system.img.ext4` remove original system.img.ext4, Don’t worry you should have a backup of it in lz4 file
- With `mv system_new.img system.img.ext4` rename system_new.img to system.img.ext4 for flashing with Odin3 v3.13
- With `tar -cvf AP.tar system.img.ext4` you will get AP.tar that you can flash with Odin3 v3.13.
- It failed to flash with FAIL! (Auth) error.
Please suggest how can I resolve this issue?
I will be very thankful to you for any little to big suggestion.:angel:
Vats12 said:
I have a `system.img.ext4.lz4` file that is compatible with my Samsung S10 5G(Qualcomm) device. I have extracted `system.img.ext4` file from the `system.img.ext4.lz4` using `unlz4 system.img.ext4.lz4` command.
I want to play with its content. So I have decided it in two steps:
1. Flash `system.img.ext4` without modification:
- Using `tar -cvf AP.tar system.img.ext4` command, I have created a AP.tar file.
- Flashed `AP.tar` file using Odin3 v3.13.
- It flashed successfully.
2. Flash `system.img.ext4` with modification:
a) Modifying
- With `simg2img system.img.ext4 system.img`, you will get a raw image file named `system.img`
- With `mkdir system`, create directory to mount system.img
- With `sudo mount -t ext4 -o loop system.img system/` you will get all files of `system.img` in `system` folder
- With `ls -l system/init.rc` note permissions: 750
- With `sudo chmod 777 system/init.rc` give write permissions
- With `sudo echo "#MODIFICATION " >> system/init.rc` done some modification in `init.rc`
- With `sudo chmod 750 init.rc` reset `init.rc` to the noted permissions
b) Calculate system sector size
- With `tune2fs -l system.img | grep "Block size\|Block count"` you will get block size and count
- With `echo $((1553064 * 4096))` multiply both results. I got 6361350144
c) Packing
- With `sudo make_ext4fs -s -l 6361350144 -a system system_new.img sys/` you will get `system_new.img` “Android Sparse Image” that has all changes
- With `sudo umount system` unmount the system directory
- With `rm -fr system` delete the system directory
d) Tar Compression
- With `rm system.img.ext4` remove original system.img.ext4, Don’t worry you should have a backup of it in lz4 file
- With `mv system_new.img system.img.ext4` rename system_new.img to system.img.ext4 for flashing with Odin3 v3.13
- With `tar -cvf AP.tar system.img.ext4` you will get AP.tar that you can flash with Odin3 v3.13.
- It failed to flash with FAIL! (Auth) error.
Please suggest how can I resolve this issue?
I will be very thankful to you for any little to big suggestion.:angel:
Click to expand...
Click to collapse
you need to unlock your bl and/or flash in twrp.
if you are trying this on a locked bl it will not work since when u modify the system partition you break the sig and hashes etc etc
elliwigy said:
you need to unlock your bl and/or flash in twrp.
if you are trying this on a locked bl it will not work since when u modify the system partition you break the sig and hashes etc etc
Click to expand...
Click to collapse
The bootloader is already unlocked and after that I am getting this issue. Twrp is not available for this model of Samsung S10.
hi, what next about this problem?
i have same issue
Vats12 said:
The bootloader is already unlocked and after that I am getting this issue. Twrp is not available for this model of Samsung S10.
Click to expand...
Click to collapse