0
  "   ˆl–Ü4ý( ©³( 	Å€fàB¦-ÿÁƒ|/µÀ¿ #ê    #!/usr/bin/bash
# SPDX-License-Identifier: GPL-2.0-only

# Copyright (C) 2015 Frank Rowand
#


usage() {

	# use spaces instead of tabs in the usage message
	cat >&2 <<eod

Usage:

   `basename $0` DTx
        decompile DTx

   `basename $0` DTx_1 DTx_2
        diff DTx_1 and DTx_2


      --annotate    synonym for -T
      --color       synonym for -c (requires diff with --color support)
       -c           enable colored output
       -f           print full dts in diff (--unified=99999)
       -h           synonym for --help
       -help        synonym for --help
      --help        print this message and exit
       -s SRCTREE   linux kernel source tree is at path SRCTREE
                        (default is current directory)
       -S           linux kernel source tree is at root of current git repo
       -T           annotate output .dts with input source file and line
                        (-T -T for more details)
       -u           unsorted, do not sort DTx


Each DTx is processed by the dtc compiler to produce a sorted dts source
file.  If DTx is a dts source file then it is pre-processed in the same
manner as done for the compile of the dts source file in the Linux kernel
build system ('#include' and '/include/' directives are processed).

If two DTx are provided, the resulting dts source files are diffed.

If DTx is a directory, it is treated as a DT subtree, such as
  /proc/device-tree.

If DTx contains the binary blob magic value in the first four bytes,
  it is treated as a binary blob (aka .dtb or FDT).

Otherwise DTx is treated as a dts source file (aka .dts).

   If this script is not run from the root of the linux source tree,
   and DTx utilizes '#include' or '/include/' then the path of the
   linux source tree can be provided by '-s SRCTREE' or '-S' so that
   include paths will be set properly.

   The shell variable \${ARCH} must provide the architecture containing
   the dts source file for include paths to be set properly for '#include'
   or '/include/' to be processed.

   If DTx_1 and DTx_2 are in different architectures, then this script
   may not work since \${ARCH} is part of the include path.  Two possible
   workarounds:

      `basename $0` \\
          <(ARCH=arch_of_dtx_1 `basename $0` DTx_1) \\
          <(ARCH=arch_of_dtx_2 `basename $0` DTx_2)

      `basename $0` ARCH=arch_of_dtx_1 DTx_1 >tmp_dtx_1.dts
      `basename $0` ARCH=arch_of_dtx_2 DTx_2 >tmp_dtx_2.dts
      `basename $0` tmp_dtx_1.dts tmp_dtx_2.dts
      rm tmp_dtx_1.dts tmp_dtx_2.dts

   If DTx_1 and DTx_2 are in different directories, then this script will
   add the path of DTx_1 and DTx_2 to the include paths.  If DTx_2 includes
   a local file that exists in both the path of DTx_1 and DTx_2 then the
   file in the path of DTx_1 will incorrectly be included.  Possible
   workaround:

      `basename $0` DTx_1 >tmp_dtx_1.dts
      `basename $0` DTx_2 >tmp_dtx_2.dts
      `basename $0` tmp_dtx_1.dts tmp_dtx_2.dts
      rm tmp_dtx_1.dts tmp_dtx_2.dts

eod
}


compile_to_dts() {

	dtx="$1"
	dtc_include="$2"

	if [ -d "${dtx}" ] ; then

		# -----  input is file tree

		if ( ! ${DTC} -I fs ${dtx} ) ; then
			exit 3
		fi

	elif [ -f "${dtx}" ] && [ -r "${dtx}" ] ; then

		magic=`hexdump -n 4 -e '/1 "%02x"' ${dtx}`
		if [ "${magic}" = "d00dfeed" ] ; then

			# -----  input is FDT (binary blob)

			if ( ! ${DTC} -I dtb ${dtx} ) ; then
				exit 3
			fi

			return

		fi

		# -----  input is DTS (source)

		if ( cpp ${cpp_flags} -x assembler-with-cpp ${dtx} \
			| ${DTC} ${dtc_include} -I dts ) ; then
			return
		fi

		echo ""                                                      >&2
		echo "Possible hints to resolve the above error:"            >&2
		echo "  (hints might not fix the problem)"                   >&2

		hint_given=0

		if [ "${ARCH}" = "" ] ; then
			hint_given=1
			echo ""                                              >&2
			echo "  shell variable \$ARCH not set"               >&2
		fi

		dtx_arch=`echo "/${dtx}" | sed -e 's|.*/arch/||' -e 's|/.*||'`

		if [