[Miscellaneous Android Development] jcadduono:
Hello developers of Exynos devices!

I've come up with a solution to integrate dtb.img building into Exynos kernel sources.

This will allow you to easily build your own dtb.img from Samsung's sources, rather than use dtb.img files pulled from stock kernels.

First, you'll need to apply a patch to the kernel sources.

This is an example taken from the Note 8 tree. You may need to make minor adjustments to get it to apply cleanly on your own tree. That means using git apply --rej then manually inserting contents from rej files most likely.

https://github.com/jcadduono/androi...45a8df88cf1d783407a36b660e8c767634a1968.patch

Once that's done, you will need to manually add some device specific additions. Samsung has already done this on a few of their kernel trees.

See https://github.com/jcadduono/androi...mmit/ebc62a93a80685a262516883b0b059d828d038b7 for an example on the Galaxy Note 8.

This is a config declaration of the variant of your device, used to determine which DTB files to build. You'll have to look around in arch/arm64/boot/dts folder for dts files regarding your device.

dtbtool_exynos is based on Ketut Putu Kumajaya's work, (using his load_dtbh_block function) then making a tool similar to Qualcomm's dtbTool. It takes arguments in a way that makes it easy to integrate in the Linux build system.

It produces 100% bit-exact dtb.img files compared to Samsung's stock images if you have the same dts sources.

jc@arkyn:~/build/kernel/android/samsung_universal8895$ build/scripts/dtbtool_exynos/dtbtool --help
usage: dtbtool
-o|--output <filename>
[ -s|--pagesize <pagesize> ]
[ --platform <hex platform code> ]
[ --subtype <hex subtype code> ]
[ -d|--dtb <dtb path> ]...
[ <dtb file> ]...

I have included defaults which apply across most Samsung devices. It requires at least 1 dtb file generated by the kernel build system to make a dtb.img.

Note that when using -d, it scans a directory's first level and sorts the dtbs in alphabetical order. (00, 01, 02, 05, 07, etc.)

When using dtb files by themselves as arguments, you will want to sort them yourself!

You can mix and match arguments however you like, so ./dtbtool -o dtb.img somefile1.dtb somefile2.dtb -d /somepath/ somefile3.dtb -d /someotherpath/ would actually scan and write them in that order.

You can use `make your-defconfig dtb.img` with CONFIG_EXYNOS_DTBTOOL=y in your device defconfig to immediately build the dtbtool, followed by the dtb files, followed by dtb.img. If CONFIG_EXYNOS_DTBTOOL=y then make/make all will build the dtb.img with your zImage.

I tried to make this as seamless and easy as possible. :)

You can then build your own boot image with https://github.com/jcadduono/android_external_libbootimg (make bootimg) or flash the dtb.img alongside ramdisk modifications, kernel images, etc. using LazyFlasher. (see more here)

HOW DO I KNOW THE PLATFORM/SUBTYPE CODES FOR MY DEVICE?

All you need is the original dtb.img from a stock boot/recovery image for your device.

If you only have a boot.img or recovery.img, use the above mentioned bootimg tool.

./bootimg x boot.img boot --dt

You will find dtb.img as boot/boot.img-dt.

This command will give you the values based on what is used in the original image:

xxd -e -s16 -l8 dtb.img | awk '{ print "platform code: 0x"$2; print "subtype code: 0x"$3 }'

The values will likely be the same on most devices. These are the defaults used by dtbtool_exynos:

platform code: 0x000050a6
subtype code: 0x217584da