Skip to content

Instantly share code, notes, and snippets.

@aakbar5
Created April 5, 2018 17:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aakbar5/60e432b4e16843bef8656de88ab1e1b7 to your computer and use it in GitHub Desktop.
Save aakbar5/60e432b4e16843bef8656de88ab1e1b7 to your computer and use it in GitHub Desktop.
dts <> dtb
# To convert dts file into dtb
<kernel-source>/scripts/dtc/dtc -I dts -O dtb <dts_file> -o <dtb_file>
# To convert dtb to dts
<kernel-source>/scripts/dtc/dtc -I dtb -O dts <dtb_file> -o <dts_file>
# Both of above commands are using dtc built with linux kernel source.
# However you can also use dtc binary comes with ubuntu packages. For this you
# need to install following package:
sudo apt-get install -y device-tree-compiler
# Ubuntu device-tree-compiler package comes with another utility known as fdtdump.
# fdtdump can also be used to convert dtb file into dts.
fdtdump <dtb_file> > <dts_dump>
# !/bin/bash
#
# This script uses forked dtc to generate flat device tree.
#
# Change these path as per your machine
COMPILER='arm-linux-gnueabihf-gcc'
KERNEL_FOLDER='/your/linux/source/code'
DTS_FILE_NAME='dra7-evm.dts'
FORKED_DTC='/forked/dtc/executable'
# Setup useful env
DTS_FOLDER=$KERNEL_FOLDER/arch/arm/boot/dts
DTS_INCLUDE=$DTS_FOLDER/include
KERNEL_INCLUDE=$KERNEL_FOLDER/include
DTS_FILE=$KERNEL_FOLDER/arch/arm/boot/dts/$DTS_FILE_NAME
echo "Generate flat dts file...(an intermediate file)"
$COMPILER -E -nostdinc -undef -D__DTS__ -x assembler-with-cpp -I$DTS_FOLDER -I$DTS_INCLUDE -o $DTS_FILE_NAME.flat $DTS_FILE
echo "Generate merge dts file...($DTS_FILE_NAME.merge)"
$FORKED_DTC/dtc -i$DTS_FOLDER -i$DTS_INCLUDE -I dts -O dts -m -g $DTS_FILE_NAME.flat -o $DTS_FILE_NAME.merge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment