Android Zimage Kernel Can Be Unpacked? - android

Hy Guys ..
I'm making a custom kernel project for my device, the project is almost done, but I'm having constraints about the camera, and in the kernel source there are no suitable drivers for my phone,
my last choice is just to unpack zimage stock .. can it be unpacked or not?
My Devices:
Smartfren Andromax Ec C46B2H
Qualcomm Snapdragon 410 Msm8916

Yes, but not much.
Similar to what Chris pointed out, the zImage is a binary blob which is self extracting when run by the cpu on system bootup.
So you can manually look into the initial uncompression code and do it yourself to get an uncompressed kernel binary also known as: uImage
Thats it. You cannot unpack it any further without counting disassembly.

Related

Android: Insmod disagrees about version of symbol module_layout

I am attempting to use NFS on my Xiaomi Redmi Note 9S, it uses a custom ROM called Resurrection Remix OS. I am replacing my old kernel with a newly compiled one, with NFS built-in.
I am using the kernel source found here, the official kernel for the phone made by Xiaomi. I couldn't find the exact kernel source for my custom ROM, but the phone boots regardless.
At first, I only compiled the modules for NFS, however using insmod on sunrpc.ko requires __audit_inode_child, so a new kernel with CONFIG_AUDIT_SYSCALL=y is necessary. I also decided to make all the NFS modules built-in.
I made the changes to my .config, and compiled the entire kernel
(besides the device tree: CONFIG_BUILD_ARM64_DT_OVERLAY=n because of compilation errors).
With the new kernel from arch/arm64/boot/Image, I unpacked the boot.img from my device and swapped out the kernels and it boots, with NFS support listed in /proc/filesystems.
However, now none of the modules from /vendor/lib/modules work. Which is to be expected, they weren't built against this new kernel's source.
Trying to remedy this issue by inserting the newly compiled modules with insmod say disagrees about version of symbol module_layout.
How is this possible? These modules were compiled alongside the running kernel (same source code)
Something must have went wrong when creating the boot image, most likely the wrong kernel was copied (I have multiple kernel sources downloaded and compiled).
I repacked boot.img with a newly compiled kernel image and no module loading needed, every module in /vendor/lib/modules was loaded on boot.

custom kernel for msm8909

Need help. I have a ZTE blade a460 phone with broken screen and i want to make it something usefull like a nfs server. I want a custom compiled kernel so, i extract the config from the original kernel using the extract-ikconfig script. I compile kernel using this config and the original dtbs from ramdisk but the kernel dont bootup. After much trials i think something special is needed. Knows someone what specific is needed for this machine? compiling Modules for the original kernel needs the extra flag -fno-pic. Is needed for the new kernel too? The phone has 3.10.49 kernel and android 5.1.1 Lollipop. I use arm-linux-androideabi-4.8 (the same as they use to compile the original kernel). Adb boot to boot the new image.

Unpacking 'Non-Standard' Boot.img Problems for 64 Bit Device

This is in relation to this XDA thread and my thread on xda. This is a cross post from XDA, trying my luck on here.
Device specs, just in case someone asks
Device Specifications:
Current Android Version: Android Lollipop 5.1.1
Chipset: Marvell Armada PXA1908 (Note: Due to this being a rarely used chip, the CF-Auto root won't work)
Custom Recovery Status: TWRP 3.0.2-0 (Not working with lollipop)
Root Status (This is technically why I am here): Android KitKat 4.4.4 (Root), Android Lollipop 5.1.1 (NO ROOT Yet)
ARMv8 64-bit
Now let's get into my steps up to the point and then my problem.
Note: In the kernel readme it states to use the toolchain 4.8 but when I use it, it complains of not being able to find gcc. Also in the read me it states "get Toolchain download and install arm-eabi-4.8 toolchain for ARM EABI.(64bit)" and when reading up on it, it says to use aarch64 for ARM 64 Bit devices.
Device Source Code can be found at Here
cd ~/android
export CROSS_COMPILE=~/android/ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-
cd ~/android/kernel
make ARCH=arm64 pxa1908_xcover3lte_eur_defconfig
make ARCH=arm64
This outputs: Image, Image.gz, .dts and .dtb files.
Where's the kernel readme (I believe this hasn't been update since kitkat) says the output will be,
- Kernel : Kernel/arch/arm/boot/zImage
- module : Kernel/drivers//.ko
Note: when trying to compile with the 32- bit ARM toolchain it fails, as the config is found in arm64, wheres other configs are found in arm.
So know I have a kernel (Image or Image.gz), and some .dts and .dtb files. Now to unpack boot.img, this is where problems occur. When trying to use tools like abootimg or the various different versions of unmkbootimg, they complain about non-standard boot.img.
or
While also try saving it as a zImage when its meant to be a Image.gz, or they extract it without throwing any errors, but when looking at the extracted files with a hex editor, it is all 00 throughout the files, therefore a useless file.
So therefor I tried manually unpacking with a hex editor and managed to get the kernel. Left is my Compiled and Right is the hex version.
Notice the difference in size, is this because the kernel in boot.img is stripped of its debugging items while mine isn't? If so I should look up on how to fix that.
But I am having troubles trying to extract the ramdisk via hex.
So is anyone able to Teach/Help me extract the boot.img properly (with tools like unmkbootimg or with a hex editor)
I have attached necessary files if you want to have a look at them yourself.
Files: Samsung xCover3 Files
Any help is appreciated.
After Numerous trial and error, I finally managed to output ramdisk.cpio.gz.
The start of a Gzip file in hex is, 1F 8B 08, therefor when using the search function in you had editor application you can narrow down your results to 1 or 2 files (2 Files for me as my kernel and ramdisk are both gzipped). You then follow it all the way down till you find a big bunch of zeros(seems like they are passing between files). When you reach the bunch of zeros include the first "00" at the end of the other hexidecial. E.G. End of one of my gzip files is "CE 24 00 00 00....00 (ZERO PADDING BETWEEN FILES), Threaded the end of my file is "CE 24 00".
Knowing this I was able to successfully extract and verify both my kernel and ramdisk files are correct.

Android Kernel Compilation - Files

Good day for you. I just started to learn and work with android kernel development or internals. I purchased a development board on-line that uses AM3359 - TI Processor. Works fine with factory Images and I booted from SD_CARD.
Later I read the documentation and I tried to compile the kernel. Everything went well as expected. I do have a little questions that I would like to clear it regarding the files that were created.
I had a section in documentation in which I was asked to Create a Root FileSystem which gave me a file called ubi.img - What is this file ?
Later I was asked to create a tarball file providing the roots path which created me an other file rootfs.tar.bz2 - What is this file ?
My question is... both the files used the files from rootfs directory to create these files. What are these files for? What exactly ubi.img does and what is it used for? Is it used for flashing it to nand and rootfs.tar.bz2 is to boot if I am booting from SD_CARD ???
Thanks & Regards
I don't know much about AM3359 - TI Processor, but on most smartphones and also in the linux kernel requires a ramdisk which is usually compressed mostly it's a .gz file.
According to my experience when the file is decompressed and usually it contains hardware initialization routines which the kernel runs first during startup.
The .img files are where everything is stored.
Most commonly :
BOOT.img - Read Only Contains ramdisk and
the rootfs this are usually zImage + rootfs.tar.bz2
System.img- Also read only although can be remounted as read+write Contains
the operating system files e.g binaries like su, busybox etc.
Userdata.img- This is where all the users data and settings are stored.
The above are all that's necessary to get a system up and running.But we might have others such as Uboot.img Preloader etc, it varies depending on the platform.

how to check whether the kernel is for android or linux?

I have the source code of a kernel. but i don't know whether the kernel is android kernel or Linux kernel. I have searched about it on google but i haven't found any proper answer. As i know ,android kernel is Linux kernel and some patches applied on it. so i think we can identify the kernel is for Linux or android.
1.Can i know this by seeing the source code, or by running any command or by any other method?
2.if it is android kernel, whether will it able to mount the Ubuntu file system?
A simple method to check if a kernel is for android.
If there is a file named "android.c" in "drivers/usb/gadget" folder, the kernel seems to be a android kernel, otherwise, it is not for android.
Though not very accurate, but very simple
Look for AndroidKernel.mk in the kernel source root, if it's an Android kernel, it should be there.
The Ubuntu file system is ext4 by default. I'm pretty sure all default kernel configurations include support for this filesystem. What is the motivation behind this?
BTW the presence of binder does NOT mean it is an Android kernel. The binder exists in the staging directory for all Linux kernels

Categories

Resources