[HOW TO] Convert back Qualcomm's DTB to DTS file, extract kernel config - Android Software/Hacking General [Developers Only]

I assume you are a ROM builder. When your device vendor continue violate the GPL, refuse to open the device kernel source, let's we reverse engineering our device stock kernel.
Dedicated to ex Google Hugo Barra. Ends up as a GPL violator a pretty miserable.
Tools:
Python tool csplitb https://github.com/mypalmike/csplitb
dtc binary from out/target/product/<device>/obj/KERNEL_OBJ/scripts/dtc
unpackbootimg from out/host/linux-x86/bin
extract-ikconfig from kernel/<vendor>/<device>/scripts
Copy all needed tools to your PATH, $HOME/bin/
Steps:
Unpack stock boot.img using unpackbootimg:
Code:
$ mkdir boot
$ cd boot
$ unpackbootimg -i ../boot.img -o .
Split DT image to DTB files, for MSM8916 in this example:
Code:
$ mkdir dtb
$ cd dtb
$ csplitb.py --prefix msm8916- --suffix .dtb --number 4 D00DFEED ../boot.img-dt
Find proper DTB file for your device, device model "Qualcomm Technologies, Inc. MSM 8916 QRD SKUM" string from my device dmesg output in this example:
Code:
$ grep -r "QRD SKUM"
Binary file msm8916-0011.dtb matches
Convert DTB to DTS files:
Code:
$ dtc -I dtb -O dts -o ../msm8916-0011.dts msm8916-0011.dtb
$ cd ../
Extract kernel config
Code:
extract-ikconfig boot.img-zImage > msm8916_defconfig
This how to success story: http://forum.xda-developers.com/android/development/rom-cyanogenmod-unofficial-builds-t3200883

RESERVED.

what is use of convert DTB TO DTS

ela1103 said:
what is use of convert DTB TO DTS
Click to expand...
Click to collapse
Reconstruct a closed source kernel or vendor kernel update not in sync to their open source version or vendor DTS completely not available, prepared outside the kernel source.

Amazing! Hope Hugo Barra stumbles upon this post!

Nice Ketut! I love the way you live OpenSource!

guys, someone can send me dtc binary for me please? I extrcting the boot img of mtk device and I dont have the dtc binary
Thanks and sorry fir my bad english

Thanks for sharing this. :highfive:
Do you know any way to circumvent lz4 zImage compression? Trying to do it for Xiaomi Mi 5.

@ketut.kumajaya What if my boot.img does not have any dt files. My boot.img-dt is 0 bytes and the error prints this:
Traceback (most recent call last):
File "/home/nick/bin/csplitb.py", line 64, in <module>
main()
File "/home/nick/bin/csplitb.py", line 61, in main
return csplitb.run()
File "/home/nick/bin/csplitb.py", line 26, in run
self.mm = mmap.mmap(f.fileno(), 0)
ValueError: cannot mmap an empty file
Halp

For anyone that may need, another way to split appended dtbs is by using this tool.

i have only stock boot and recovery how to unpack in decompile plz upload video your tutroial

@ketut.kumajaya on step 2 you using this value D00DFEED, and what is that value mean? Is that value for dtb header or what? Can u explain sir, thanks

Guizão BR said:
guys, someone can send me dtc binary for me please? I extrcting the boot img of mtk device and I dont have the dtc binary
Thanks and sorry fir my bad english
Click to expand...
Click to collapse
Sometimes device tree binaries live in a separate partition. That's sort of the idea behind a device tree - it's just that the bindings on ARM are so in flux that keeping a static device tree embedded in "firmware" becomes impractical, and so vendors will ship a kernel with a device tree (or a bundle of device trees) appended to it.
You can get the 'dtc' binary by installing the 'device-tree-compiler' package on Ubuntu, or just use 'kernel/scripts/dtc' if you've got a kernel built.

zainifame said:
@ketut.kumajaya on step 2 you using this value D00DFEED, and what is that value mean? Is that value for dtb header or what? Can u explain sir, thanks
Click to expand...
Click to collapse
Instead of using that tool, use this one, it requires no arguments - https://github.com/dianlujitao/split-appended-dtb.
Hope it helps

Can anyone explain to me, how to extract touchscreen firmware from kernel binary? Thanks

Related

[Tutorial] How to compile a kernel module outside the kernel

I've decided to make a short tutorial and present the way I compile kernel modules (outside the kernel sources).
I've built few kernel modules (governors - ineractive and smartass, cifs, nls, etc) and I started receiving private messages asking how I did it.
For kernel modules that come with the kernel itself - cifs / tun for example - they just work if you compile the kernel and activate correct config parameters.
Some other modules (such as the smartass governor that doesn't come with the kernel) you compile outside the kernel source. However they require changes since kernel does not export the symbols the module needs to use - so you have to know what k_all_syms are needed, grab them from the phone and update the kernel module.
So there will be changes there. However, the main steps are:
a) follow tutorials to get the kernel / android ndk to compile. People seem able to do this.
b) then take the module you want (For example cpufreq_smartass.c from here: http://pastebin.com/rR4QUCrk ) and copy it in a new folder on the disk.
c) create a Makefile like the one below, but with your paths of course:
Code:
KERNEL_DIR=/home/viulian/android_platform/kernel-2.1.A.0.435/kernel
obj-m := cpufreq_smartass.o
PWD := $(shell pwd)
default:
$(MAKE) ARCH=arm CROSS_COMPILE=/home/viulian/android_platform/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi- -C $(KERNEL_DIR) SUBDIRS=$(PWD) modules
clean:
$(MAKE) -C $(KERNEL_DIR) SUBDIRS=$(PWD) clean
d) execute make
Of course, the module source needs to be adjusted as you need to put in the frequencies, and also update the k_all_syms pointers .. But you can retrieve them from /proc/kallsyms on the device itself - just look for the method name, and use the address you see in the log.
If you still can't get it to compile, try to compile a very basic hello_world kernel module. I used the code below when testing:
Code:
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_ALERT */
MODULE_LICENSE("GPL");
MODULE_AUTHOR("viulian, 2011");
MODULE_DESCRIPTION("Demo module for X10i");
int init_module(void)
{
printk("<1>Hello world\n");
// A non 0 return means init_module failed; module can't be loaded.
return 0;
}
void cleanup_module(void)
{
printk(KERN_ALERT "Goodbye world 1.\n");
}
It is not perfect, but if you manage to insmod-it and check dmesg, you will see "Hello world" written there.
One more thing, linux kernel is fussy about the module versions. Even if nothing is changed between two kernel versions related to what a module needs, is enough a small difference in module's modinfo value to make the kernel to refuse the module.
For this, you need to trick your local kernel and adjust EXTRAVERSION value in kernel's main Makefile to have the exact version of the one on the device:
In X10 stock kernel (GB 2.3.3 release), the kernel version is 2.6.29-00054-g5f01537 visible in phone settings.
This means that the kernel on the phone will only accept modules that are compiled for that exact version. But the kernel version is just a string in the module .ko, so is a string comparison - the module might work perfectly, but is not loaded.
There is luck though, the string value comes from a define in kernel's Makefile, which you can change before you compile!
The Makefile in the kernel you are going to use to build the module will have to include these lines at the top:
Code:
VERSION = 2
PATCHLEVEL = 6
SUBLEVEL = 29
EXTRAVERSION = -00054-g5f01537
Other than that, it should work .. Expect phone reboots and difficulty to debug if stuff goes wrong. Android kernel doesn't come with syslog functionality, kernel prints are found in /proc/kmsg. Dmesg works, but you can't execute if if phone reboots.
I usually had to keep another adb shell opening with 'cat /proc/kmsg' which showed as much as possible from the module's outputs.
Happy compiling on your risk!
Good
Sent from my GT-S5570 using Tapatalk
Nice really nice.
Anyone help me.have someone who could compile the linux bluetooth modules please? Iam noob in linux
http://www.multiupload.com/58OPISAYNH
Anyone please can make a video tutorial?
That's really nice of you for sharing this.
Guide to Compiling Custom Kernel Modules in Android
I've spent the better part of today trying to figure out how to compile and load a custom kernel modules in android to aid me in my research. It has been in entirely frustrating experience, as there is almost no documentation on the topic that I can find. Below you will find my attempt at a guide. Hopefully this will help save someone else the hassle.
PREREQUISITES
Disclaimer: This list may be incomplete, since I've not tried it on a fresh install. Please let me know if I've missed anything.
Install the general android prereqs found here .
Download and un(zip|tar) the android NDK found here .
http://developer.android.com/sdk/ndk/index.html
Download and un(zip|tar) the android SDK found here .
http://developer.android.com/sdk/index.html
Download and untar the kernel source for your device. This can usually be found on the website of your device manufacturer or by a quick Google search.
Root your phone. In order to run custom kernel modules, you must have a rooted phone.
Plug your phone into your computer.
PREPARING YOUR KERNEL SOURCE
First we must retrieve and copy the kernel config from our device.
Code:
$ cd /path/to/android-sdk/tools
$ ./adk pull /proc/config.gz
$ gunzip ./config.gz
$ cp config /path/to/kernel/.config
Next we have to prepare our kernel source for our module.
Code:
$ cd /path/to/kernel
$ make ARCH=arm CROSS_COMPILE=/path/to/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi- modules_prepare
PREPARING YOUR MODULE FOR COMPILATION
We need to create a Makefile to cross-compile our kernel module. The contents of your Makefile should be similar to the following:
Code:
obj-m := modulename.o
KDIR := /path/to/kernel
PWD := $(shell pwd)
CCPATH := /path/to/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin
default:
$(MAKE) ARCH=arm CROSS_COMPILE=$(CCPATH)/arm-linux-androideabi- -C $(KDIR) M=$(PWD) modules
COMPILING AND INSTALLING YOUR MODULE
Code:
$ cd /path/to/module/src
$ make
$ cd /path/to/android-sdk/tools/
$ ./adb push /path/to/module/src/modulename.ko /sdcard/modulename.ko
RUNNING YOUR MODULE
Code:
$ cd /path/to/android-sdk/
$ ./adb shell
$ su
# insmod /sdcard/modulename.ko
---------- Post added at 07:40 PM ---------- Previous post was at 07:37 PM ----------
IMPORNTANT TOO
Preparing a build environment
To build an Android kernel, you need a cross-compiling toolchain. Theoretically, any will do, provided it targets ARM. I just used the one coming in the Android NDK:
$ wget http://dl.google.com/android/ndk/android-ndk-r6b-linux-x86.tar.bz2
$ tar -jxf android-ndk-r6b-linux-x86.tar.bz2
$ export ARCH=arm
$ export CROSS_COMPILE=$(pwd)/android-ndk-r6b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-
For the latter, you need to use a directory path containing prefixed versions (such as arm-eabi-gcc orarm-linux-androideabi-gcc), and include the prefix, but not “gcc”.
You will also need the adb tool coming from the Android SDK. You can install it this way:
$ wget http://dl.google.com/android/android-sdk_r12-linux_x86.tgz
$ tar -zxf android-sdk_r12-linux_x86.tgz
$ android-sdk-linux_x86/tools/android update sdk -u -t platform-tool
$ export PATH=$PATH:$(pwd)/android-sdk-linux_x86/platform-tools
not yet ((((
Come on, please make video tuto
that's interesting.
Thanks for sharing
Any takers to do a video status? Come on people it would be good for newbies like me and many that tme around. When teaching the community grows.
hi
i'm traing to compile module for acer a500.
but i have got an error: Nothing to be done for `default'.
my makefile:
Code:
obj-m += hello.o
KDIR := /home/hamster/android
PWD := $(shell pwd)
CCPATH := /home/hamster/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin
default:
$(MAKE) ARCH=arm CROSS_COMPILE=$(CCPATH)/arm-linux-androideabi- -C $(KDIR) M=$(PWD) modules
acer kernel code is located in /home/hamster/android
could you help me?
thanks
Thanks man. The step "modules_prepare" is what did the trick for me!
Makefile including tabs
hamsterksu said:
hi
i'm traing to compile module for acer a500.
but i have got an error: Nothing to be done for `default'.
my makefile:
Code:
obj-m += hello.o
KDIR := /home/hamster/android
PWD := $(shell pwd)
CCPATH := /home/hamster/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin
default:
$(MAKE) ARCH=arm CROSS_COMPILE=$(CCPATH)/arm-linux-androideabi- -C $(KDIR) M=$(PWD) modules
acer kernel code is located in /home/hamster/android
could you help me?
thanks
Click to expand...
Click to collapse
This is probably because you need to add a tab in front of your $(MAKE). Without the tab it will not recognize the command.
Help with compiling module
I am trying to compile a module for Galaxy S. I am getting this error.
# insmod hello_world.ko
insmod: init_module 'hello_world.ko' failed (Exec format error)
These are the module related options that I have enabled in the .config
CONFIG_MODULES=y
CONFIG_MODULE_FORCE_LOAD=y
CONFIG_MODULE_UNLOAD=y
CONFIG_MODULE_FORCE_UNLOAD=y
# CONFIG_MODVERSIONS is not set
# CONFIG_MODULE_SRCVERSION_ALL is not set
Further this is the cat /proc/kmsg out put
<3>[53597.457275] hello_world: version magic '2.6.35.7-I900XXJVP-CL264642 preempt mod_unload ARMv7 ' should be '2.6.35.7-I9000XXJVP-CL264642 preempt mod_unload ARMv7 '
Why am I getting this error??
These are the steps I followed,
1. Downloaded the GT-I9000_OpenSource_GB.zip from samsung open source.
2. Change the EXTRAVERSION to EXTRAVERSION = .7-I900XXJVP-CL264642 (kernel version shown on phone is [email protected] #2)
I tried with EXTRAVERSION = [email protected] as well.
3. Added this line to the main make file -
core-y := usr/ TestModule/
5. Place the TestModule/ with the module code on the root directory.
6. Created the TestModule/Makefile and added this entry
obj-m := hello_world.o
4. On the read me of the kernel source it says to install Sourcery G++ Lite 2009q3-68 toolchain for ARM EABI, which I did.
5. Execute 'make aries_eur_defconfig'.
6. Execute make (again this is how the readme in the source says)
I have compiled this module for the emulator and it works fine, What am I doing wrong here?
Thanks in advance.
hamsterksu said:
hi
but i have got an error: Nothing to be done for `default'.
Code:
default:
$(MAKE) ARCH=arm CROSS_COMPILE=$(CCPATH)/arm-linux-androideabi- -C $(KDIR) M=$(PWD) modules
Click to expand...
Click to collapse
be sure to have {tab} not space or other symbol before: $(MAKE) in:
Code:
default:
$(MAKE) ARCH=arm CROSS_COMPILE=$(CCPATH)/arm-linux-androideabi- -C $(KDIR) M=$(PWD) modules
Hello,
I'm trying to load a module in my GS3 but I encounter problems about version. Maybe it's just a mismatch between the kernel i use to compile and the one on my phone.
I have a 3.0.31-742798 kernel version on my GS3, so I put this info in the makefile like viulian said but it didn't work.
I manage to compile and put the module on the phone, but when I want to insmod it, I've got
Code:
insmod: init_module 'hello_world.ko' failed (Exec format error)
and the /proc/kmsg say
Code:
... disagrees about version of symbol module_layout
And there no config.gz on the /proc/ dir like fabricioemmerick suggest to use
EDIT: I try to modify the symbol by copying the one of module from the phone. Have another error.
btw , with modinfo I found that the compilation always add -gc33f1bc-dirty after the subversion. Maybe something in the compilation goes wrong. Still use the stock kernel and the toolchain from the ndk sourcecode
m00gle said:
Hello,
I'm trying to load a module in my GS3 but I encounter problems about version. Maybe it's just a mismatch between the kernel i use to compile and the one on my phone.
I have a 3.0.31-742798 kernel version on my GS3, so I put this info in the makefile like viulian said but it didn't work.
I manage to compile and put the module on the phone, but when I want to insmod it, I've got
Code:
insmod: init_module 'hello_world.ko' failed (Exec format error)
and the /proc/kmsg say
Code:
... disagrees about version of symbol module_layout
And there no config.gz on the /proc/ dir like fabricioemmerick suggest to use
EDIT: I try to modify the symbol by copying the one of module from the phone. Have another error.
btw , with modinfo I found that the compilation always add -gc33f1bc-dirty after the subversion. Maybe something in the compilation goes wrong. Still use the stock kernel and the toolchain from the ndk sourcecode
Click to expand...
Click to collapse
Maybe your kernel source code version and your phone kernel version is different. If both are 3.0.31 but just the subversion is different, you can
try "insmod -f" to load. The -f option will ignore the version.
How can I get a dmesg of a specific kernel module using adb shell or any other way?
ravike14 said:
How can I get a dmesg of a specific kernel module using adb shell or any other way?
Click to expand...
Click to collapse
I'm not sure I understand the question ... you can just dmesg and grep by the module name ? Or some string that the module outputs ? You have full control
viulian said:
I'm not sure I understand the question ... you can just dmesg and grep by the module name ? Or some string that the module outputs ? You have full control
Click to expand...
Click to collapse
That's the part I don't understand, the grep part.. When I enter grep with my commamd I get as it's not a recognized command.. I'm using Windows is that the reason?
I'm using 'adb shell dmesg > dmesg.txt' how do I add the grep part for it and and the module name.. I did alot research but all are Linux kernel specific debugging guides.. What would be the exact command to grep a specific module.ko logs?
Sent from my HTC_Amaze_4G using XDA Premium 4 mobile app
ravike14 said:
I'm using 'adb shell dmesg > dmesg.txt' how do I add the grep part for it and and the module name.. I did alot research but all are Linux kernel specific debugging guides.. What would be the exact command to grep a specific module.ko logs?
Click to expand...
Click to collapse
I think I understand now
The order is this:
a) DroidSSHd from here: http://code.google.com/p/droidsshd/downloads/list
b) Busybox installer from the market.
c) Putty on your windows to connect to the phone
Now you can dmesg + grep once you are connected to the phone (don't forget to su before and allow DroidSSHd root).
You need to be connected to the phone since it is much more easier. Use the phone as your remote Linux machine.

[SCRIPTS] Unpack / repack MT65xx/MT83xx boot.img, recovery.img or logo.bin

If you are looking for a way to easily unpack / repack boot.img, recovery.img or logo.bin from your MediaTek device (all except Android One devices), don't look any further. Here you can find my own Perl scripts.
Scripts were first based on the ones available on Android-DLS WiKi, but are now highly modified in order to work with specific MTK boot and recovery images. The scripts fully work with every image from all known MediaTek SoC:
MT6516
MT65x3 (MT6513 and MT6573)
MT65x5 (MT6515 and MT6575)
MT6577
MT65x2 (MT6572, MT6582 and MT6592)
MT6589
MT83xx (MT8377 and MT8389)
MT6595
The most up to date version of the scripts is always available at my public github repository: bgcngm/mtk-tools. Scripts require Perl v5.14+ to be installed and were fully tested under Ubuntu 12.04 as well as Windows 7 x64 (using Cygwin).
Please don't just leech the files and go away. You can easily say thanks just by pressing "Thanks" button.
Unpack script usage:
Code:
Usage: unpack-MTK.pl <infile> [COMMAND ...]
Unpacks MediaTek boot, recovery or logo images
Optional COMMANDs for boot or recovery images are:
-info_only
Display file information only
(useful to check image information without unpacking)
-kernel_only [--debug]
Extract kernel only
-ramdisk_only [--debug]
Extract ramdisk only
(optional argument '--debug' can additionally be used to provide useful
information for debugging purposes, even while unpacking both kernel
and ramdisk)
Optional COMMANDs for logo images are:
-force_logo_res <width> <height>
Forces file to be unpacked by specifying image resolution (in pixels)
(only useful when no zlib compressed images are found)
-invert_logo_res
Invert image resolution (width <-> height)
(may be useful when extracted images appear to be broken)
Repack script usage:
Code:
Usage: repack-MTK.pl <COMMAND ...> <outfile>
Repacks MediaTek boot, recovery or logo images
COMMANDs for boot or recovery images are:
-boot [--debug] <kernel> <ramdisk-directory>
Repacks boot image
-recovery [--debug] <kernel> <ramdisk-directory>
Repacks recovery image
(optional argument '--debug' can additionally be used to provide useful
information for debugging purposes, while repacking)
COMMANDs for logo images are:
-logo [--no_compression] <logo-directory>
Repacks logo image
(optional argument '--no_compression' can be used to repack logo images
without compression)
Version history:
modified to work with MT6516 boot and recovery images (17-03-2011)
included support for MT65x3 and eliminated the need of header files (16-10-2011)
added cygwin mkbootimg binary and propper fix (17-05-2012)
included support for MT65xx logo images (31-07-2012)
fixed problem unpacking logo images containing more than nine packed rgb565 raw files (29-11-2012)
re-written logo images file verification (29-12-2012)
image resolution is now calculated and shown when unpacking logo images (02-01-2013)
added colored screen output (04-01-2013)
included support for logo images containing uncompressed raw files (06-01-2013)
more verbose output when unpacking boot and recovery images (13-01-2013)
kernel or ramdisk extraction only is now supported (13-01-2013)
re-written check of needed binaries (13-01-2013)
ramdisk.cpio.gz deleted after successful extraction (15-01-2013)
added rgb565 <=> png images conversion (27-01-2013)
code cleanup and revised verbose output (16-10-2014)
boot or recovery is now extracted to the working directory (16-10-2014)
unpack result is stored on the working directory, despite of the input file path (17-10-2014)
added support for new platforms - MT6595 (thanks @carliv) (29-12-2014)
minor code cleanup and revised information output for boot and recovery images (29-12-2014)
make scripts more future-proof by supporting even more args (30-12-2014)
continue repacking even if there's no extra args file (01-01-2015)
more verbose output when repacking boot and recovery images (02-01-2015)
added new cmdline option for debugging purposes when unpacking / repacking boot and recovery images (06-01-2015)
Credits:
Android-DLS for the initial scripts
starix (from forum.china-iphone.ru) for the decryption of logo.bin files structure
carliv (from forum.xda-developers.com) for new platform support and new binaries
XDA:DevDB Information
MTK-Tools, Tool/Utility for the Android General
Contributors
bgcngm
Version Information
Status: Stable
Created 2014-10-15
Last Updated 2014-10-17
Editing .rgb565 raw files
There may be other ways for doing this, but here's a short info that will help you to edit .rgb656 raw files found inside MTK logo images.
Download and install Paint.NET
Download the attached plugin and copy the RGB565.dll file to the folder: "C:\Program Files\Paint.Net\FileTypes"
Open the .rgb565 file and enter image height and width
Information:
The plugin will allow read and write support to the RGB565 or RAW565 format. This format is used by the Android platform for the initial boot screen of the device. It will also allow you to open a BMP, PNG, JPG or other image and save it as a RGB565 file.
RGB565 is simply the raw pixel data of a bitmap file. It does not contain any header information and does not contain the dimensions of the image. The only thing that is known is the total number of pixels. When opening a .rgb565 file, the user must specify the height and width of the image, which is the resolution of your device's screen.
Just as an example, for a device with a 540 x 960 screen, the .rgb565 file for that device will have 518400 pixels. The size of the file in bytes will be twice the number of pixels, i.e. 1036800 bytes.
hello,
i tried ur script and works with MT6573 but i need some help.
How to repack?
The syntax u posted looks little jumbled and i need a example on unpack and repacking from u
Burned from my laser torch using pencil cells
Simple... let's say you unpack a boot.img:
Code:
unpack-MT65xx.pl boot.img
This extracts the kernel (it will be named boot.img-kernel.img) and the ramdisk folder (it will be named boot.img-ramdisk).
In order to repack, you should run:
Code:
repack-MT65xx.pl boot.img-kernel.img boot.img-ramdisk new-boot.img
If you are repacking a recovery.img, then it should be:
Code:
repack-MT65xx.pl -recovery recovery.img-kernel.img recovery.img-ramdisk new-recovery.img
I m getting "can't exec "mkbootimg" : No such file or directory at ./repack-Mt65xx.pl line 66" error
Now?
Edit: Solved the error
Burned from my laser torch using pencil cells
How did u solve?
Sent from my Android using Tapatalk 2
Probably it was just a matter of setting the proper permissions.
Hello, sorry for my bad english
help me please
i'm getting this error:
C:\Perl\MT65xx_scripts>unpack-MT65xx.pl recovery.img
Subroutine Cwd::fastcwd redefined at C:/Perl/lib/Cwd.pm line 819.
Subroutine Cwd::getcwd redefined at C:/Perl/lib/Cwd.pm line 819.
Subroutine Cwd::abs_path redefined at C:/Perl/lib/Cwd.pm line 819.
kernel written to boot/recovery.img-kernel.img
the boot image does not appear to contain a valid gzip file at C:\Perl\MT65xx_sc
ripts\unpack-MT65xx.pl line 48.
My telephone have a MT6573 processor
I have only used the scripts under Ubuntu, so never tested it on a Windows environment.
Are you sure that you have Perl correctly installed?
tried with ubuntu works.
Thanks!!!
Works in windows with cygwin too with some minor tweaking...
change the repack script line 66, mkbootimg to ./mkbootimg.exe & replace mkbootimg with this windows version... i think it should work with any mkbootimg.exe windows version too...
ignore the unpack scripts error though, it works fine actually in cygwin...
bgcngm said:
If you are looking for a way to easily unpack / repack boot.img (or recovery.img) from your MediaTek device, don't look any further. Here you can find my own Perl scripts.
These scripts are based on the ones available on Android-DLS WiKi, but highly modified in order to work with specific MTK boot and recovery images. Currently, these scripts fully work with any MT6516, MT6513 or MT6573 boot image. I believe it will still work for the new MT6575 images.
Unpack script usage:
Code:
unpack-MT65xx.pl <image>
Repack script usage:
Code:
repack-MT65xx.pl [-recovery] <kernel> <ramdisk-directory> <outfile>
Click to expand...
Click to collapse
when i type
unpack-MT65xx.pl boot.img
in terminal it says
unpack-MT65xx.pl cammand not found
im on ubuntu 11
Solution to the error!!
Edit: Solved the error - can't exec "mkbootimg"
If someone gets the error:
can't exec "mkbootimg" : No such file or directory at ./repack-Mt65xx.pl line 66
Follow this:
In Ubuntu:
copy the 'mkbootimg' file and paste it in your /bin folder.
A command like this in the terminal will do the work:
Code:
sudo cp /path/to/unpack-repack-scripts/mkbootimg /bin
(enter your password, when it asks)
In windows(using cygwin):
Edit:
Use the OP to download latest script.
bindassdost said:
when i type
unpack-MT65xx.pl boot.img
in terminal it says
unpack-MT65xx.pl cammand not found
im on ubuntu 11
Click to expand...
Click to collapse
type like this bro:
Code:
./unpack-MT65xx.pl boot.img
hope it helps !
marsavo said:
Hello, sorry for my bad english
help me please
i'm getting this error:
C:\Perl\MT65xx_scripts>unpack-MT65xx.pl recovery.img
Subroutine Cwd::fastcwd redefined at C:/Perl/lib/Cwd.pm line 819.
Subroutine Cwd::getcwd redefined at C:/Perl/lib/Cwd.pm line 819.
Subroutine Cwd::abs_path redefined at C:/Perl/lib/Cwd.pm line 819.
kernel written to boot/recovery.img-kernel.img
the boot image does not appear to contain a valid gzip file at C:\Perl\MT65xx_sc
ripts\unpack-MT65xx.pl line 48.
Click to expand...
Click to collapse
I am getting the same error. I am running this script on windows 7. My phone is based on MT6516.
ajparag said:
I am getting the same error. I am running this script on windows 7. My phone is based on MT6516.
Click to expand...
Click to collapse
Dude Check whether you have installed perl packages for cygwin properly
bgcngm said:
Simple... let's say you unpack a boot.img:
Code:
unpack-MT65xx.pl boot.img
This extracts the kernel (it will be named boot.img-kernel.img) and the ramdisk folder (it will be named boot.img-ramdisk).
In order to repack, you should run:
Code:
repack-MT65xx.pl boot.img-kernel.img boot.img-ramdisk new-boot.img
If you are repacking a recovery.img, then it should be:
Code:
repack-MT65xx.pl -recovery recovery.img-kernel.img recovery.img-ramdisk new-recovery.img
Click to expand...
Click to collapse
Thanks for sharing. Very useful.
varun.chitre15 said:
I m getting "can't exec "mkbootimg" : No such file or directory at ./repack-Mt65xx.pl line 66" error
Now?
Edit: Solved the error
Burned from my laser torch using pencil cells
Click to expand...
Click to collapse
give the binary execute permission, and move it to somewhere in the path:
sudo chmod a+x mkbootimg
sudo mv mkbootimg /bin
@OP
Real Gr8 job
For those people facing problems regarding the mkbootimg ,
Just that you need that binary compiled for your system
Here is for OS X (tested on 10.7.4) attached !
I just compiled form the Source
got from Internet ( lazy to boot that thing in Parallels )
for compiling !!
Source for Windows :
http://www.freeyourandroid.com/guide/extract-edit-repack-boot-img-windows
mkbootimg for OS X, Linux and Windows
Does any one need for Linux ?
ninadpchaudhari said:
Does any one need for Linux ?
Click to expand...
Click to collapse
The binary for Linux is already included in the 7zip file, along with the scripts.

Boot.img Tools Compiled for Arm^7 -- (un)Pack kernels on your phone !!!

About
These two applets ( mkbootimg + unpackbootimg ) are used to pack and unpack any standard android kernel with 4096 / 2048 page size . Most of tools that pack and unpack boot.img files such as Dsixda kitchen , Kernel kitchen or. ... use these applets .
These applets were compiled only for X86 so we could only (un)pack boot.img in Windows or Ubuntu but I compiled and fixed these applets for Arm7 platform on android devices from Android sources. So you may pack and unpack boot.img on any android device !!
How to use
1- First download applets package
2- Unzip it and push two files in it to /system/bin or /system/xbin
3- Set their pemissions to 777 ( rwxrwxrwx )
For unpacking a kernel
* Assuming that you have boot.img in /sdcard
* Open terminal and type : [ this is just an example , you can change it ]
Code:
su
unpackbootimg -i /sdcard/boot.img -o /sdcard/ -p 4096
*You will have extracted boot.img at /sdcard
* Save ouput information that applets gives you at the end . you need them in future
For packing a kernel
* Copy ramdisk.gz , zimage , cmdline , pagesize , base you got from unpacking boot.img into /sdcard
* Open terminal and type :
Code:
su
mkbootimg --cmdline cmdline --kernel zimage --ramdisk ramdisk.gz --base base --pagesize pagesize -o boot.img
* You will have output ( boot.img ) at /sdcard/boot.img
Download
Download build 1 @ Uploadboy
* Initial build
Credits
* Alireza7991 - for fixing , improving and cross-compiling for arm^7
* Andrew Huang ( [email protected]) - for sources
* Android Open Source Project - for sources
This applet is under GPL 2.0
Using this is free but you have to ask me if you want to use this in your tools or ...
Reserved for OP
First!!! Another great job alireza!!
Sent from my GT-I9001 using Tapatalk 4 Beta
very nice tnx 4 u
-------
dash daset tala
its awesome :good:
tnx alireza
any way to use on armv6 ?
s27moto said:
any way to use on armv6 ?
Click to expand...
Click to collapse
Hi
Test it on arm^6 , if you couldnt tell me to compile it for arm^6
Great job Alireza just saw this topic while doing a quick browse through the i9001 forums. this may really become handy sometime
In Android:
I unpacked the file boot.img from within the K^Kernel_ICS_3.0_v2.0_Linaro-4.7.4_OC_UV_360MB_Signed.zip
next
# unpackbootimg -i *.img -o . -p 4096
# gunzip -d boot.img-ramdisk.gz
# gunzip: invalid gzip magic
I have a question.
Do boot.img-ramdisk.gz file is corrupted or protected?
ze7zez said:
In Android:
I unpacked the file boot.img from within the K^Kernel_ICS_3.0_v2.0_Linaro-4.7.4_OC_UV_360MB_Signed.zip
next
# unpackbootimg -i *.img -o . -p 4096
# gunzip -d boot.img-ramdisk.gz
# gunzip: invalid gzip magic
I have a question.
Do boot.img-ramdisk.gz file is corrupted or protected?
Click to expand...
Click to collapse
Hi
Ramdisk is compressed by two gzip and cpio methods . you have to use this ( I suggest to run this on ubuntu or cygwin :
Code:
cd ramdisk_place
gunzip < ramdisk.gz > ramdisk.cpio
cpio -i < ramdisk.cpio
alireza7991 said:
Download build 1 @ Uploadboy
Click to expand...
Click to collapse
Hi,
does someone still have the build somewhere? The download link is not working anymore.
Thanks.
frantisek.nesveda said:
Hi,
does someone still have the build somewhere? The download link is not working anymore.
Thanks.
Click to expand...
Click to collapse
Look here:
http://forum.xda-developers.com/showthread.php?t=2364447
alireza7991 said:
Look here:
http://forum.xda-developers.com/showthread.php?t=2364447
Click to expand...
Click to collapse
Already found that in the meantime, it turns out I had that thread open too, but I didn't realize they were two different threads, as they look nearly the same. But thanks
frantisek.nesveda said:
Already found that in the meantime, it turns out I had that thread open too, but I didn't realize they were two different threads, as they look nearly the same. But thanks
Click to expand...
Click to collapse
I think I made first one in SGS+ section then I found it should be in Android section and I made one there too .

[Development] MKBOOTIMG TOOLS

MKBOOTIMG-TOOLS
MY GITHUB SOURCE:
https://github.com/ModdingMyMind/mkbootimg_tools​
Original Author: xiaolu (GITHUB SOURCE: https://github.com/xiaolu/mkbootimg_tools)
Heavily Modified By: Modding.MyMind
This project is originally based from xiaolu. To make this compatible for ARM I modified the script, compiled some binaries such as file, bash, grep, gzip, lzma, xz, mkbootimg, etc.
-- This project uses busybox but due to how stripped and limited busybox is it ultimately led to me having to compile a few binaries from source. These binaries must be part of the project in order for the project to be successful. For example, busybox grep will not always give accurate offsets for the android header. One of MANY bugs found with busybox.
This project supports device tree binaries found inside the Boot.img and Recovery.img.
This project supports multiple Ramdisk compressions.
-- This project will check the ramdisk compression and if it determines that the tool does not support that particular compression then it will display a hazard warning letting the user know that the compression is not supported and that the ramdisk currently cannot be decompressed or compressed until support has been officially added.
-- If the compression is supported it will display what type of compression the Ramdisk is and how many blocks it has when unpacked.
This project will determine your kernel size, ramdisk size, and TRUE OFFSETS (not just the standard mkbootimg.c offsets).
-- With respect to the offsets; You will learn that many available tools found available specifically handle images where the ANDROID! header is located at 0x0. Not all images are built like this from stock. This project will find the header, base, kernel offset, ramdisk offset, second offset, and tags offset. It will rebuild the image using DD to insure the android header is located at 0x0. The found offsets inside the image will be cross referenced to see if the OEM of that image built it using the standard mkbootimg.c. If it detects any offsets which are built using NON-standard offsets then it will display a warning as well as show you what the image TRUE offsets actually are. Those same offsets are then applied to properly rebuild your image to insure that it boots like it was intended to do.
-- The warning will let you know that you may modify mkbootimg.c with the NON-standard values if you wish to have a binary specific to your device. The offsets displayed are not the address. Because the offsets are determined and not the address this makes it possible for this project to not have to rebuild mkbootimg.c. When the project is used to rebuild your image using the mkbootimg args such as --ramdisk_offset, --kernel_offsets, etc, etc, this then tells mkbootimg.c to ignore the hardcoded offsets and only use the ones it has been instructed to use. This is even more successful by insuring the BASE is accurate and applying the base as one of the mkbootimg args (--base 0 <-- this is lazy and stupid).
The mkboot script requires two args whether unpacking the image or repacking the image.
-- mkboot boot.img bootfolder (This will unpack the image)
1. mkboot is the script.
2. boot.img is the actual image.
3. bootfolder will be created and become the project folder.
-- mkboot bootfolder newboot.img (This will repack the image)
1. mkboot is the script.
2. bootfolder is the project folder which has the needed files and information to repack.
3. This will be the name of the finished build.
UNPACK STANDARD IMAGE​
This image uses standard mkbootimg.c:
[email protected]:/data/local/tmp/mkbootimg_tools-master # ./mkboot boot.img work
Unpack & decompress boot.img to work
kernel : zImage
ramdisk : ramdisk
page size : 2048
kernel size : 2529072
ramdisk size : 230255
base : 0x12200000
kernel offset : 0x00008000
ramdisk offset : 0x01000000
second_offset : 0x00f00000
tags offset : 0x00000100
cmd line : mem=471M console=ttyMSM2,115200n8 androidboot.hardware=thunderc lge.rev=10
Ramdisk is lzma format.
1436 blocks
Unpack completed.
[email protected]:/data/local/tmp/mkbootimg_tools-master #
Click to expand...
Click to collapse
REPACK STANDARD IMAGE​
Image repacked with standard mkbootimg.c:
[email protected]:/data/local/tmp/mkbootimg_tools-master # ./mkboot work boot.img
mkbootimg from work/img_info.
kernel : zImage
ramdisk : new_ramdisk.lzma
page size : 2048
kernel size : 2529072
ramdisk size : 230029
base : 0x12200000
kernel offset : 0x00008000
ramdisk offset : 0x01000000
tags offset : 0x00000100
cmd line : mem=471M console=ttyMSM2,115200n8 androidboot.hardware=thunderc lge.rev=10
Kernel size: 2529072, new ramdisk size: 230029, boot.img: 2762752.
boot.img has been created.
[email protected]:/data/local/tmp/mkbootimg_tools-master #
Click to expand...
Click to collapse
UNPACK NON-STANDARD IMAGE​
This image uses non-standard mkbootimg.c:
[email protected]:/data/local/tmp/mkbootimg_tools-master # ./mkboot recovery.img work
Unpack & decompress recovery.img to work
****** WARNING ******* WARNING ******* WARNING ******
This image is built using NON-standard mkbootimg!
RAMDISK_OFFSET is 0x01608000
You can modify mkbootimg.c with the above value(s)
****** WARNING ******* WARNING ******* WARNING ******
kernel : zImage
ramdisk : ramdisk
page size : 2048
kernel size : 5834192
ramdisk size : 4351685
base : 0x80600000
kernel offset : 0x00008000
ramdisk offset : 0x01608000
second_offset : 0x00f00000
tags offset : 0x00000100
cmd line : console=ttyHSL0,115200,n8 user_debug=31
Ramdisk is gzip format.
14837 blocks
Unpack completed.
[email protected]:/data/local/tmp/mkbootimg_tools-master #
Click to expand...
Click to collapse
REPACK NON-STANDARD IMAGE​
Image repacked with non-standard mkbootimg.c:
[email protected]:/data/local/tmp/mkbootimg_tools-master # ./mkboot work recovery.img
mkbootimg from work/img_info.
kernel : zImage
ramdisk : new_ramdisk.gzip
page size : 2048
kernel size : 5834192
ramdisk size : 4358038
base : 0x80600000
kernel offset : 0x00008000
ramdisk offset : 0x01608000
tags offset : 0x00000100
cmd line : console=ttyHSL0,115200,n8 user_debug=31
Kernel size: 5834192, new ramdisk size: 4358038, recovery.img: 10194944.
recovery.img has been created.
[email protected]:/data/local/tmp/mkbootimg_tools-master #
Click to expand...
Click to collapse
UNPACK IMAGE WITH INCOMPATIBLE RAMDISK​
[email protected]:/data/local/tmp/mkbootimg_tools-master # ./mkboot boot-1.img work
Unpack & decompress boot-1.img to work
kernel : zImage
ramdisk : ramdisk
page size : 2048
kernel size : 3580032
ramdisk size : 594701
base : 0x10000000
kernel offset : 0x00008000
ramdisk offset : 0x01000000
second_offset : 0x00f00000
tags offset : 0x00000100
cmd line :
****** HAZARD ******* HAZARD ******* HAZARD ******
Ramdisk is data format. Can't unpack ramdisk.
This tool currently does not support data.
****** HAZARD ******* HAZARD ******* HAZARD ******
[email protected]:/data/local/tmp/mkbootimg_tools-master #
Click to expand...
Click to collapse
REPACK IMAGE WITH INCOMPATIBLE RAMDISK​
[email protected]d:/data/local/tmp/mkbootimg_tools-master # ./mkboot work boot-1.img
mkbootimg from work/img_info.
****** HAZARD ******* HAZARD ******* HAZARD ******
Ramdisk is data format. Can't repack ramdisk.
This tool currently does not support data.
****** HAZARD ******* HAZARD ******* HAZARD ******
[email protected]:/data/local/tmp/mkbootimg_tools-master #
Click to expand...
Click to collapse
*Reserved*
If your boot.img and/or recovery.img is found to not be supported using this tool then please send me your boot.img and recovery.img so I may review it and determine if official support can be added. Thanks.
Add support for MediaTek Images:
-- Unpack and repack boot/recovery images.
-- Append proper headers to ramdisk when repacking.
-- Compiled mkimage to assist with the headers.
-- This support currently does not include the logo images at this time.
-- MT6516
-- MT65x3 (MT6513 and MT6573)
-- MT65x5 (MT6515 and MT6575)
-- MT6577
-- MT65x2 (MT6572 and MT6582)
-- MT6589
-- MT83xx (MT8377 and MT8389)
Modding.MyMind said:
If your boot.img and/or recovery.img is found to not be supported using this tool then please send me your boot.img and recovery.img so I may review it and determine if official support can be added. Thanks.
Click to expand...
Click to collapse
getting error
Code:
[email protected]:/ $ su
/mkbootimg_tool/ARM <
/mkboot boot.img h3ll <
<Unpack and repack boot.img tool>
----------------------------------------------------------------------
Not enough parameters or parameter error!
unpack boot.img & decompress ramdisk
mkboot [img] [output dir]
mkboot boot.img boot20130905
^[[?1;2cUse the unpacked directory repack boot.img(img_info)
mkboot [unpacked dir] [newbootfile]
mkboot boot20130905 newboot.img
^[[?1;[email protected]:/data/local/tmp/mkbootimg_tool/A;2c1;2c <
sh: 1: not found
sh: 2c1: not found
sh: 2c: not found
127|[email protected]:/data/local/tmp/mkbootimg_tool/ARM #
H3LL said:
getting error
Code:
[email protected]:/ $ su
/mkbootimg_tool/ARM <
/mkboot boot.img h3ll <
----------------------------------------------------------------------
Not enough parameters or parameter error!
unpack boot.img & decompress ramdisk
mkboot [img] [output dir]
mkboot boot.img boot20130905
^[[?1;2cUse the unpacked directory repack boot.img(img_info)
mkboot [unpacked dir] [newbootfile]
mkboot boot20130905 newboot.img
^[[?1;[email protected]:/data/local/tmp/mkbootimg_tool/A;2c1;2c <
sh: 1: not found
sh: 2c1: not found
sh: 2c: not found
127|[email protected]:/data/local/tmp/mkbootimg_tool/ARM #
Click to expand...
Click to collapse
Check the permissions, check that bash is placed at /system/xbin, and insure the image you are trying to unpack is in the same directory where the mkboot script is located or else, insure you specify the image path properly.
If it still errors out insure your device is ARM and compatible for the project. If yes, then at the top of the script will be; #set -x. Uncomment it and run the script again, then copy and paste it's output here.
Also, send me your image to download and verify on my end. Thanks.
Modding.MyMind said:
Check the permissions, check that bash is placed at /system/xbin, and insure the image you are trying to unpack is in the same directory where the mkboot script is located or else, insure you specify the image path properly.
If it still errors out insure your device is ARM and compatible for the project. If yes, then at the top of the script will be; #set -x. Uncomment it and run the script again, then copy and paste it's output here.
Also, send me your image to download and verify on my end. Thanks.
Click to expand...
Click to collapse
tried same output as above here's boot.IMG
H3LL said:
tried same output as above here's boot.IMG
Click to expand...
Click to collapse
Your image doesn't have an android header. It's elf. This tool currently doesn't support it but now that I have your boot.img I can see about adding support. Can you send me your recovery image as well so I may verify that the process is the same for both when unpacking and repacking. Some images such as MediaTek have different headers for the ramdisk depending on whether it's the boot or recovery and so I would like to confirm the same with yours as well. Thanks.
Edit: Also, this tool won't work on your device unless the binaries are compiled from source for your machine. It's currently for ARM, but your device won't play nice with it.
Modding.MyMind said:
Your image doesn't have an android header. It's elf. This tool currently doesn't support it but now that I have your boot.img I can see about adding support. Can you send me your recovery image as well so I may verify that the process is the same for both when unpacking and repacking. Some images such as MediaTek have different headers for the ramdisk depending on whether it's the boot or recovery and so I would like to confirm the same with yours as well. Thanks.
Edit: Also, this tool won't work on your device unless the binaries are compiled from source for your machine. It's currently for ARM, but your device won't play nice with it.
Click to expand...
Click to collapse
there is no recovery. img for this device (its not mediatek) its in ramdisk of the boot.img....yeah my device is ARM
H3LL said:
there is no recovery. img for this device (its not mediatek) its in ramdisk of the boot.img....yeah my device is ARM
Click to expand...
Click to collapse
Reviewed the binaries and somehow overlooked a few after compiling them. Some aren't even true static when I originally thought I did compile them as such. There are also some which are true static but focus on either hard floats or soft floats. So, I need to go back and recompile the ones which stood out and push them to my repo. This may very well be why it isn't playing fair on your Sony device.
With that said, adding support for your image is gonna be a bit complicated to write out in bash since it is very involved lol. However, I am gonna make an attempt by taking on the challenge and seeing if I can get it done .
The github account doesn't exist anymore and there's no download link?
[null]
how to compile this for windows
I can't use one over the other because I need gamepass cuz Iwant to save money on hardware not buy games on steam but also i need linux because bash is miles better than some IDE which takes up 30 gb at minimum

How to specify a custom defconfig file in Android 10 Kernel compilation

I wanted to enable certain kernel features and in my Android 10 build for Pixel 3. I downloaded and built the correct msm kernel and successfully flashed it on the Pixel. To build the kernel I'm using the build/build.sh from the kernel source. I tried adding a custom defconfig file in private/msm-google/arch/arm64/configs/ and changing the DEFCONFIG variable in build.config to that file. When I compile I get following error:
Code:
++ echo ERROR: savedefconfig does not match private/msm-google/arch/arm64/configs/sdm845_defconfig
ERROR: savedefconfig does not match private/msm-google/arch/arm64/configs/sdm845_defconfig
How can I compile the kernel with a custom defconfig? It doesn't have to be through the build.sh method (although it would be preferable)
gardeimasei said:
I wanted to enable certain kernel features and in my Android 10 build for Pixel 3. I downloaded and built the correct msm kernel and successfully flashed it on the Pixel. To build the kernel I'm using the build/build.sh from the kernel source. I tried adding a custom defconfig file in private/msm-google/arch/arm64/configs/ and changing the DEFCONFIG variable in build.config to that file. When I compile I get following error:
Code:
++ echo ERROR: savedefconfig does not match private/msm-google/arch/arm64/configs/sdm845_defconfig
ERROR: savedefconfig does not match private/msm-google/arch/arm64/configs/sdm845_defconfig
How can I compile the kernel with a custom defconfig? It doesn't have to be through the build.sh method (although it would be preferable)
Click to expand...
Click to collapse
I don't know if it's solved, but I solved the problem removing the "check defconfig" in build.config (the symlink in the root which points to the kernel build.config).
Change
Code:
POST_DEFCONFIG_CMDS="check_defconfig"
to
Code:
POST_DEFCONFIG_CMDS=""
I've been working with a Google engineer who showed me the fix for my savedefconfig problem. Maybe it will fix yours, too.
The key is to set ARCH:
Code:
$ export ARCH=arm64
Here's the context and full procedure. My work is based on the b1c1_defconfig config. Your directory names may vary.
Code:
$ cd private/msm-google
$ export ARCH=arm64 # this is the magic line
$ make b1c1_defconfig # This sets up the config for my hardware. Yours is probably different.
$ make menuconfig
Now edit the kernel configuration and save it as ".config", the default.
When you're done:
Code:
$ make savedefconfig
$ cp defconfig arch/arm64/configs/b1c1_defconfig # or whatever your hardware configuration is
$ make mrproper
With luck, you won't see any savedefconfig problems.

Categories

Resources