How to repack boot.img with modified kernel? - General Questions and Answers

I downloaded the Xiaomi ROM, unzipped it, and extracted the boot.img with
abootimg -x boot.img
Then I recreated the boot.img with the modified kernel
abootimg --create boot.img -f bootimg.cfg -k $SCRIPT_DIR/devices/$DEVICE/kernel/k/arch/arm64/boot/Image -r initrd.img
and flashed it
fastboot flash boot boot.img
but then the phone boots right into fastboot mode.
I then reflashed the original boot.img from the ROM and it worked.
Then I thought I had compiled the kernel wrongly somehow, so I tried just unpacking the ORIGINAL boot.img from the ROM and repacking it, without changing the kernel:
abootimg -x boot.img
abootimg --create boot.img -f bootimg.cfg -k zImage -r initrd.img
but it boots right into fastboot mode again. So the problem is not in my kernel but in my repacking method for boot.img
How should I repack the boot.img?

Related

[Q] Need help modifying boot blob

Could someone point me to some instructions on how to unpack, modify, and repack a boot.blob out of a kernel?
I'm trying to update bryce's kernel to use Data2SD mod, and I'm following the instructions from here:
http://forum.xda-developers.com/showpost.php?p=29532041&postcount=15
However, I tried unpacking and repacking without even modifying anything and I just get bootlooped.
Read this: http://forum.xda-developers.com/showpost.php?p=36925180&postcount=4
Do you want to use the Data2SD mod with CM or with CROMI? For CROMI I posted a kernel with auto-detection of Data2SD in bryce's thread - only for CM you'd have to do it yourself.
Thanks for the help. I actually just figured out a different way right before seeing your reply. I use blobpack and blobunpack from BlobTools git, and abootimg installed from Ubuntu repository. This script has the extracted bryce kernel zip in a directory called result, so I overwrite his boot.blob with my new one.
Code:
#!/bin/bash
#Clean:
rm out boot.img new_boot.img boot2.blob linux_processed.zip -r
mkdir -p out
echo;echo "**** Unpacking boot.blob to boot.img";echo
cp result/boot.blob .
../linux/blobunpack boot.blob
mv boot.blob.LNX boot.img
cd out
# now in out
echo;echo "**** Unpacking boot.img";echo
abootimg -x ../boot.img
#zcat initramfs|cpio -tiv
echo;echo "**** Extracting initrd.img";echo
mkdir -p initramfs
cp initrd.img initramfs/initramfs.gz
mv initrd.img old_initrd.img
cd initramfs
# now in old/initramfs
gzip -d initramfs.gz
cpio -i < initramfs
echo;echo "**** Modifying boot information";echo
perl -pi -e 's/mmcblk0p2/mmcblk1p3/g' *
perl -pi -e 's/mmcblk0p8/mmcblk1p2/g' *
echo;echo "**** Recompressing initrd.img";echo
find | cpio -H newc -o | lzma -9 > ../initrd.img
cd ..
# now in out
echo;echo "**** Creating new_boot.img";echo
abootimg --create ../new_boot.img -f bootimg.cfg -k zImage -r initrd.img
cd ..
#now out of out
echo;echo "**** Pack boot2.blob";echo
../linux/blobpack boot2.blob LNX new_boot.img
cp boot2.blob result/boot.blob
cd result
echo;echo "**** Zip it all up";echo
zip ../linux_processed.zip * -r
cd ..
I am trying to get bryce's CM10.1 kernel working with Data2SD. I thought all I needed to do was change the mount commands in fstab.cardhu so that data (and I'm trying to do cache too) moved to external partitions.
Those perl pie commands in the middle were supposed to change internal data partition and internal cache partition into the external SD card partition 2 and 3, respectively. As far as I can tell, the changes were made correctly and the blob and zip were re-created, but it didn't work when I booted with the new blob.
Any ideas why it doesn't seem to have worked? Are there other changes I'm missing?
Edit:
Looks like my boot.blob is not being applied. I've tried both flashing the zip and dd'ing it to mmcblk0p4, but in both cases, I do not get the bootloader update screen on reboot, it just boots straight into my old settings. What am I missing?
Edit again:
Oops, I had stopped adding the signature on the blobs for some reason, looks like I'm off a few steps, because now I get bootloops again.
AW: [Q] Need help modifying boot blob
oblib__ said:
Thanks for the help. I actually just figured out a different way right before seeing your reply. I use blobpack and blobunpack from BlobTools git, and abootimg installed from Ubuntu repository. This script has the extracted bryce kernel zip in a directory called result, so I overwrite his boot.blob with my new one.
Code:
#!/bin/bash
#Clean:
rm out boot.img new_boot.img boot2.blob linux_processed.zip -r
mkdir -p out
echo;echo "**** Unpacking boot.blob to boot.img";echo
cp result/boot.blob .
../linux/blobunpack boot.blob
mv boot.blob.LNX boot.img
cd out
# now in out
echo;echo "**** Unpacking boot.img";echo
abootimg -x ../boot.img
#zcat initramfs|cpio -tiv
echo;echo "**** Extracting initrd.img";echo
mkdir -p initramfs
cp initrd.img initramfs/initramfs.gz
mv initrd.img old_initrd.img
cd initramfs
# now in old/initramfs
gzip -d initramfs.gz
cpio -i < initramfs
echo;echo "**** Modifying boot information";echo
perl -pi -e 's/mmcblk0p2/mmcblk1p3/g' *
perl -pi -e 's/mmcblk0p8/mmcblk1p2/g' *
echo;echo "**** Recompressing initrd.img";echo
find | cpio -H newc -o | lzma -9 > ../initrd.img
cd ..
# now in out
echo;echo "**** Creating new_boot.img";echo
abootimg --create ../new_boot.img -f bootimg.cfg -k zImage -r initrd.img
cd ..
#now out of out
echo;echo "**** Pack boot2.blob";echo
../linux/blobpack boot2.blob LNX new_boot.img
cp boot2.blob result/boot.blob
cd result
echo;echo "**** Zip it all up";echo
zip ../linux_processed.zip * -r
cd ..
I am trying to get bryce's CM10.1 kernel working with Data2SD. I thought all I needed to do was change the mount commands in fstab.cardhu so that data (and I'm trying to do cache too) moved to external partitions.
Those perl pie commands in the middle were supposed to change internal data partition and internal cache partition into the external SD card partition 2 and 3, respectively. As far as I can tell, the changes were made correctly and the blob and zip were re-created, but it didn't work when I booted with the new blob.
Any ideas why it doesn't seem to have worked? Are there other changes I'm missing?
Edit:
Looks like my boot.blob is not being applied. I've tried both flashing the zip and dd'ing it to mmcblk0p4, but in both cases, I do not get the bootloader update screen on reboot, it just boots straight into my old settings. What am I missing?
Edit again:
Oops, I had stopped adding the signature on the blobs for some reason, looks like I'm off a few steps, because now I get bootloops again.
Click to expand...
Click to collapse
I had a hard time getting this done too. I couldn't find working blob tools at first. So I ended up using blob tools for windows. They also sign them directly. But I am also running Ubuntu in a vm
Sent from my Nexus 4 using xda premium

Help installing kernel image

I've been running Linux (debian/ubuntu based on rabits's stuff) on my tablet, with no ability to (easily) boot Android, for a few months now.
My System partition still has 9.4.5.26 on it, and I'd like to reinstall a 9.4.5.26 kernel, without wiping my System partition, so I can switch back to Android.
I've (I think) extracted a kernel image and a ramdisk image from a 9.4.5.26 install image, and I'm trying to create a install image containing just the kernel and ramdisk, and copy it to the Staging partition with dd.
I've created a Makefile to create the blobfile, and (seemingly) successfully created the blobfile, but after I do the dd, and reboot, debian/ubuntu boots as usual, instead of some kind of install process.
I've included the Makefile that I'm using below.
Any idea what I'm doing wrong, or what's wrong with my expectations?
Something I have yet to try is an alternative to dd (such as fastboot or nvflash)
Also, maybe I'd have better luck trying to create something that I could install from TWRP.
Code:
kern = zImage
bootimg_filename = boot.img
blobpack = ./blobpack
blob_img = blob.LNX
recovery_part = /dev/mmcblk0p4
$(bootimg_filename) : initrd.img $(kern)
abootimg --create $(bootimg_filename) -k $(kern) -r initrd.img
blob.LNX: $(bootimg_filename)
$(blobpack) blob.LNX LNX $(bootimg_filename)
install.dd:
dd if=$(blob_img) of=$(recovery_part)
bsammon said:
I've been running Linux (debian/ubuntu based on rabits's stuff) on my tablet, with no ability to (easily) boot Android, for a few months now.
My System partition still has 9.4.5.26 on it, and I'd like to reinstall a 9.4.5.26 kernel, without wiping my System partition, so I can switch back to Android.
I've (I think) extracted a kernel image and a ramdisk image from a 9.4.5.26 install image, and I'm trying to create a install image containing just the kernel and ramdisk, and copy it to the Staging partition with dd.
I've created a Makefile to create the blobfile, and (seemingly) successfully created the blobfile, but after I do the dd, and reboot, debian/ubuntu boots as usual, instead of some kind of install process.
I've included the Makefile that I'm using below.
Any idea what I'm doing wrong, or what's wrong with my expectations?
Something I have yet to try is an alternative to dd (such as fastboot or nvflash)
Also, maybe I'd have better luck trying to create something that I could install from TWRP.
Code:
kern = zImage
bootimg_filename = boot.img
blobpack = ./blobpack
blob_img = blob.LNX
recovery_part = /dev/mmcblk0p4
$(bootimg_filename) : initrd.img $(kern)
abootimg --create $(bootimg_filename) -k $(kern) -r initrd.img
blob.LNX: $(bootimg_filename)
$(blobpack) blob.LNX LNX $(bootimg_filename)
install.dd:
dd if=$(blob_img) of=$(recovery_part)
Click to expand...
Click to collapse
So you just want to install what you have made to your staging partition, so on next boot the tablet will install it on your tablet is that right??
bsammon said:
Any idea what I'm doing wrong, or what's wrong with my expectations?
Click to expand...
Click to collapse
Maybe your blob is missing the signature header. Read my kernel repacking guide here:
http://forum.xda-developers.com/showpost.php?p=36925180&postcount=4
Why is your extracted kernel separated in zImage and ramdisk? After unpacking the 9.4.5.26 blob, you should get blob.LNX directly without needing to recombine with abootimg.
_that said:
Maybe your blob is missing the signature header. Read my kernel repacking guide here:
http://forum.xda-developers.com/showpost.php?p=36925180&postcount=4
Click to expand...
Click to collapse
Yes! -- that was it -- after two tries, I got a working Makefile.
_that said:
Why is your extracted kernel separated in zImage and ramdisk? After unpacking the 9.4.5.26 blob, you should get blob.LNX directly without needing to recombine with abootimg.
Click to expand...
Click to collapse
Well, doing things the (somewhat) harder way is more educational, and I end up with a makefile that I can reuse for kernels and ramdisks that I make/modify myself.
If anyone's interested, here's the Makefile that I ended up with:
Code:
kern = zImage
bootimg_filename = boot.img
blobpack = ./blobpack
unsigned_blob = blob.LNX.in
signature = blob.sign
blob_img = blob.LNX
staging_part = /dev/mmcblk0p4
$(bootimg_filename) : initrd.img $(kern)
abootimg --create $(bootimg_filename) -k $(kern) -r initrd.img
$(unsigned_blob): $(bootimg_filename)
$(blobpack) $(unsigned_blob) LNX $(bootimg_filename)
$(signature):
echo -n "-SIGNED-BY-SIGNBLOB-" > $(signature)
dd if=/dev/zero bs=1 count=8 >> $(signature)
$(blob_img): $(signature) $(unsigned_blob)
cat $(signature) $(unsigned_blob) > $(blob_img)
install.dd:
dd if=$(blob_img) of=$(staging_part)

[Q] "FAILED (remote: dtb not found)" error when flashing image on Xperia Z3

Hello,
I am facing error when flashing image on Xperia Z3. I rooted the device using the link posted on "theunlockr.com"
Now, I am trying to flash a new image on the device. I am extracting the exisiting image from the device, modifying the init.rc file and repacking the image (myboot.img) and then flashing it using fastboot method. This is when it gives me this error.
When I flash the original image that I extracted, it works fine.
I tried following methods: -
1. Changing init.rc file and repacking the .img file and flashing it
When I extract initrd.img (using abootimg), it shows me only these files ( I usually find init.rc file when I extract initrd.img but not in this device, is this expected?): -
- XZ3-AdvStkKernel_DooMLoRD_ramdisk.gz
- logo.rle
- init (linking to sbin/init.sh)
- sbin/bootrec-device
- sbin/ramdisk-recovery-cwm.cpio
- sbin/busybox
- sbin/ramdisk.cpio
- sbin/init.sh
I extracted sbin/ramdisk.cpio file to get the init.rc file using the command: -
cpio -idmv < ramdisk.cpio
After modifying the init.rc file, I repacked the cpio file using the command: -
ls | cpio -ov > ramdisk.cpio
I made sure that none of the extra stuff was not there in the folder before repacking the cpio file.
Now that my ramdisk.cpio file is updated, I created new image using the command: -
find . | cpio -o -H newc | gzip -9 > ../newramdisk.cpio.gz
and created myboot.img using abootimg
When I flashed this image file, I get the "dtb not found" error
2. Second method that I tried was I simply unpacked the boot.img (original image) and repacked it using abootimg in to myboot.img without changing anything.
This also gives the same error.
It looks like there is some issue with the unpacking and repacking of the boot image.
Is there any other way to resolve this issue?
asurion.acc said:
Is there any other way to resolve this issue?
Click to expand...
Click to collapse
use this instruction and tools, but when you will build your boot.img, use this cmd line
Code:
./mkbootimg --base 0x00000000 --kernel zImage --ramdisk_offset 0x02000000 --tags_offset 0x01E00000 --pagesize 2048 --cmdline "androidboot.hardware=qcom user_debug=31 msm_rtb.filter=0xb7 ehci-hcd.park=3 dwc3.maximum_speed=high dwc3_msm.prop_chg_detect=Y" --ramdisk ramdisk.cpio.gz --dt dt.img -o boot.img
with that instruction all work fine. I've tested many times
Thanks for replying to me.
I just want to modify init.rc file to add few lines. The only file that I see is ramdisk.cpio which contains init.rc. I unpacked it , modified it and repacked ramdisk.cpio. Instead of creating new dt.img, I directly flashed the new img file onto the device and that soft bricked the device. :crying: The steps that you suggested mentions creating a new kernel and creating a new dt.img. Do I need to do that even though I just need to modify just init.rc file?
At this point, I am just trying to unbrick the device using flash tool. I tried cwmrecovery but it did not work so trying flashing tool now. once its done, if it is necessary to create a new dt.img and new zImage using toolchains, I will use that method. Please let me know if you think that is the step that I am missing which caused the device to brick.
Thanks a lot.
UPDATE:
Device is unbricked.!
I just need to root it again and follow the steps that you mentioned. Please confirm if I need new ZImage and dt.img even if I just need to edit init.rc.
Thanks a lot.

[Samsung 5.1.1] Why wont phone boot custom boot.img with a repacked ramdisk.cpio.gz

As the title states, why can't I boot a custom boot.img when I repack the ramdisk.cpio.gz. It freezes and doesn't boot past the logo, with the text "KERNEL is not SEANDROIDENFORCING". BUT I know that the phone can boot custom boot.img 's as I removed the word "SEANDORIDENFORCING" from the original boot.img via a hex editor and flashed it to my phone. My phone booted up all the way and did not freeze or get stuck, even when the red text (KERNEL IS NOT SEANDROID ENFORCING) was shown at the top of my phone
I belive it has to do with the unpacking/repacking of the ramdisk.cpio.gz file. When ever I try to boot an image with a repacked ramdisk the phone won't boot.
Usefull info:
I am not using any scripts to unpack the boot.img as none of them seem to be able to handle a boot.img designed for a armv8 (arm64 (64 bit)) CPU (As they try to extract the kernel as a zImage when it is Image.gz, thus ending prematurely and not working). Therefore I manually unpack the boot.img via a hex editor. I know I have extracted the files properly as it would throw an error anytime you would try to extract it if it wasn't properly copied from the boot.img.
The Commands Used:
Unpack:
Code:
mkdir ramdisk
cd ramdisk
gunzip -c ../ramdisk.cpio.gz | cpio -I
Then to pack it up:
Code:
find . |cpio -o -H newc | gzip > ../ramdisk-custom.cpio.gz
OR repacking it with root ownership
Code:
find . |cpio -o -H newc -R 0.0 | gzip > ../ramdisk-custom.cpio.gz
Little Phone Info: Samsung XCover 3 Lollipop 5.1.1, No Root, Flashing via Odin.
Am I correct in assuming that the repacked ramdisk is not letting the phone boot? Or is there something I am missing or doing wrong or is just plain obvious. Any Info would be great.
In relation to this thread: http://forum.xda-developers.com/android/development/4-4-4-5-1-1-6-0-1-samsung-xcover3-t3465132/page2

How to edit boot.img for SM-T585?

I want to edit the boot.img for SM-T585, but I can't edit initrd.img. I'm using abootimg and I tested that it works by unpacking and repacking the boot.img without doing any thing to the initrd.img:
Code:
abootimg -x boot.img
abootimg --create newboot.img -k zImage -r initrd.img -f bootimg.cng
and this image can be flashed and the device boot normally, but when I try to modify the initrd.img:
Code:
mkdir initrd_folder && cd initrd_folder
# extract the [B]initrd.img[/B]
zcat ../initrd.img | cpio -idmv
# pack it again
find . | cpio --create --format='newc' | gzip -9 > ../newinitrd.img
From: How To Modify initrd.img
and then create the new boot.img with the new initrd.img
Code:
abootimg --create newboot.img -k zImage -r newinitrd.img -f bootimg.cfg
This new boot.img doesn't make the device boot and it only shows the Samsung logo and then reboots

Categories

Resources