[Samsung Galaxy S20 / S20+ / S20 Ultra Questions & ] caelan-a:
Hi everyone,

I'm having trouble generating a boot.img using Android Image Kitchen to be the same size as the stock boot.img that I first unpacked! The stock boot.img is 69.1MB and if I unpack that and immediately repack it reduces to 39.1MB.

Specs

Samsung S20 Ultra 5G (G988B)

Android 10

PDA: G988BXXU4BTH5 (August 2020)

What I've Done So Far

I've compiled a custom kernel using source straight from Samsung's open source repo. For testing purposes I have made no changes and simply compiled with the relevant toolchains.

To take my compiled kernel and package it up into a boot.img I can flash with Odin, I have followed this guide how-to-unpack-and-edit-android-boot-img using osm0sis' Android Image Kitchen tools (AIK)

I have done the following:

Download custom firmware (PDA: G988BXXU4BTH5) and extract boot.img from AP archive

Unpack boot.img using AIK

unpackbootimg -i ./boot.img

Construct arguments for mkbootimg based on above step's output

Run mkbootimg with arguments:

#!/bin/bash
set -e
set -x

./bin/linux/x86_64/mkbootimg \
--kernel ./boot.img-kernel \
--ramdisk ./boot.img-ramdisk.gz \
--dtb ./boot.img-dtb \
--cmdline "$(cat ./boot.img-cmdline)" \
--base "$(cat ./boot.img-base)" \
--kernel_offset "$(cat ./boot.img-kernel_offset)" \
--ramdisk_offset "$(cat ./boot.img-ramdisk_offset)" \
--tags_offset "$(cat ./boot.img-tags_offset)" \
--dtb_offset "$(cat ./boot.img-dtb_offset)" \
--os_version "$(cat ./boot.img-os_version)" \
--os_patch_level "$(cat ./boot.img-os_patch_level)" \
--board "$(cat ./boot.img-board)" \
--pagesize "$(cat ./boot.img-pagesize)" \
--header_version "$(cat ./boot.img-header_version)" \
--hashtype "$(cat ./boot.img-hashtype)" \
--output ./new-boot.img \

For some reason the resulting boot.img file is 39.1MB whereas the stock boot.img is 69.1MB

To confirm it wasn't my custom kernel, I simply unpacked the stock boot.img and then repacked the extracted files. The output is again 39.1MB. This leads me to believe that AIK is either not extracting all the required files from the stock boot.img or is not packing all the required files into the generated boot.img

I came across this post in which someone successfully built a Samsung S21 boot.img, without size issues, using a fork of AIK however all projects I've used to generate boot.img give me the exact same size inconsistency.

I tried seeing what would happen if I flashed the 39.1MB boot.img on anyway and after succesfully flashing, I got a boot error:

ODIN MODE (DT Load Fail)!

[DTH] dt table header check Fail: FDT_ERR_BADMAGIC

[UFDT] DTB LOAD FAIL

View attachment 5344563

Does this suggest AIK is not packaging the dtb file correctly? Given boot.img-dtb is only 340.1KB, it must be missing more than just this.

I seem to be at an impasse and would be deeply appreciative if the smart people on XDA could lend some advice!

Thank you!

Update #1:

I was able to flash 39.1MB boot.img (with both stock and custom kernel) on and avoiding above DTB Load Fail by:

1. Ensuring name/dir structure is boot.img inside boot.img.tar

2. Using stock dtb file

It then bootloops until I am presented with recovery and error:

View attachment 5344617

From this post it seems like repacking changes hash leading to 'integrity_failed' error above.

Update #2:

I managed to successfully load generated boot.img with custom kernel. I had to disable Android Verified Boot by flashing vbmeta_disabled.tar in the UserData tab in ODIN. This disables integrity checking in the bootloader sequence when the ROM bootloader passes control to the kernel in boot.img

I hope this helps others!