Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) #! /bin/bash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) # SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) # Copyright (C) 2015 Frank Rowand
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) usage() {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 	# use spaces instead of tabs in the usage message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 	cat >&2 <<eod
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) Usage:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)    `basename $0` DTx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)         decompile DTx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)    `basename $0` DTx_1 DTx_2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)         diff DTx_1 and DTx_2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)       --annotate    synonym for -T
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)       --color       synonym for -c (requires diff with --color support)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)        -c           enable colored output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)        -f           print full dts in diff (--unified=99999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)        -h           synonym for --help
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)        -help        synonym for --help
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)       --help        print this message and exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)        -s SRCTREE   linux kernel source tree is at path SRCTREE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)                         (default is current directory)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)        -S           linux kernel source tree is at root of current git repo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)        -T           annotate output .dts with input source file and line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)                         (-T -T for more details)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)        -u           unsorted, do not sort DTx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) Each DTx is processed by the dtc compiler to produce a sorted dts source
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) file.  If DTx is a dts source file then it is pre-processed in the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) manner as done for the compile of the dts source file in the Linux kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) build system ('#include' and '/include/' directives are processed).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) If two DTx are provided, the resulting dts source files are diffed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) If DTx is a directory, it is treated as a DT subtree, such as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)   /proc/device-tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) If DTx contains the binary blob magic value in the first four bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)   it is treated as a binary blob (aka .dtb or FDT).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) Otherwise DTx is treated as a dts source file (aka .dts).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)    If this script is not run from the root of the linux source tree,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)    and DTx utilizes '#include' or '/include/' then the path of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)    linux source tree can be provided by '-s SRCTREE' or '-S' so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)    include paths will be set properly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)    The shell variable \${ARCH} must provide the architecture containing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)    the dts source file for include paths to be set properly for '#include'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)    or '/include/' to be processed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)    If DTx_1 and DTx_2 are in different architectures, then this script
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)    may not work since \${ARCH} is part of the include path.  The following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)    workaround can be used:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)       `basename $0` ARCH=arch_of_dtx_1 DTx_1 >tmp_dtx_1.dts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)       `basename $0` ARCH=arch_of_dtx_2 DTx_2 >tmp_dtx_2.dts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)       `basename $0` tmp_dtx_1.dts tmp_dtx_2.dts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)       rm tmp_dtx_1.dts tmp_dtx_2.dts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)    If DTx_1 and DTx_2 are in different directories, then this script will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)    add the path of DTx_1 and DTx_2 to the include paths.  If DTx_2 includes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)    a local file that exists in both the path of DTx_1 and DTx_2 then the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)    file in the path of DTx_1 will incorrectly be included.  Possible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)    workaround:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)       `basename $0` DTx_1 >tmp_dtx_1.dts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)       `basename $0` DTx_2 >tmp_dtx_2.dts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)       `basename $0` tmp_dtx_1.dts tmp_dtx_2.dts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)       rm tmp_dtx_1.dts tmp_dtx_2.dts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) eod
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) compile_to_dts() {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	dtx="$1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	dtc_include="$2"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if [ -d "${dtx}" ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		# -----  input is file tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		if ( ! ${DTC} -I fs ${dtx} ) ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			exit 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	elif [ -f "${dtx}" ] && [ -r "${dtx}" ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		magic=`hexdump -n 4 -e '/1 "%02x"' ${dtx}`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		if [ "${magic}" = "d00dfeed" ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			# -----  input is FDT (binary blob)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			if ( ! ${DTC} -I dtb ${dtx} ) ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 				exit 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		# -----  input is DTS (source)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		if ( cpp ${cpp_flags} -x assembler-with-cpp ${dtx} \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			| ${DTC} ${dtc_include} -I dts ) ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		echo ""                                                      >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		echo "Possible hints to resolve the above error:"            >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		echo "  (hints might not fix the problem)"                   >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		hint_given=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		if [ "${ARCH}" = "" ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			hint_given=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			echo ""                                              >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			echo "  shell variable \$ARCH not set"               >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		dtx_arch=`echo "/${dtx}" | sed -e 's|.*/arch/||' -e 's|/.*||'`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		if [ "${dtx_arch}" != ""  -a "${dtx_arch}" != "${ARCH}" ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			hint_given=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			echo ""                                              >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 			echo "  architecture ${dtx_arch} is in file path,"   >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			echo "  but does not match shell variable \$ARCH"    >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			echo "  >>\$ARCH<< is: >>${ARCH}<<"                  >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		if [ ! -d ${srctree}/arch/${ARCH} ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			hint_given=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			echo ""                                              >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			echo "  ${srctree}/arch/${ARCH}/ does not exist"     >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			echo "  Is \$ARCH='${ARCH}' correct?"                >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			echo "  Possible fix: use '-s' option"               >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			git_root=`git rev-parse --show-toplevel 2>/dev/null`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			if [ -d ${git_root}/arch/ ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 				echo "  Possible fix: use '-S' option"       >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		if [ $hint_given = 0 ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			echo ""                                              >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			echo "  No hints available."                         >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		echo ""                                                      >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		exit 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		echo ""                                                     >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		echo "ERROR: ${dtx} does not exist or is not readable"      >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		echo ""                                                     >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		exit 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) # -----  start of script
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) annotate=""
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) cmd_diff=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) diff_flags="-u"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) diff_color=""
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) dtx_file_1=""
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) dtx_file_2=""
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) dtc_sort="-s"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) help=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) srctree=""
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) while [ $# -gt 0 ] ; do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	case $1 in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	-c | --color )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		if diff --color /dev/null /dev/null 2>/dev/null ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			diff_color="--color=always"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		shift
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	-f )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		diff_flags="--unified=999999"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		shift
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	-h | -help | --help )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		help=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		shift
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	-s )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		srctree="$2"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		shift 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	-S )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		git_root=`git rev-parse --show-toplevel 2>/dev/null`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		srctree="${git_root}"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		shift
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	-T | --annotate )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		if [ "${annotate}"  = "" ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 			annotate="-T"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		elif [ "${annotate}"  = "-T" ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			annotate="-T -T"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		shift
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	-u )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		dtc_sort=""
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		shift
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	*)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		if [ "${dtx_file_1}"  = "" ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			dtx_file_1="$1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		elif [ "${dtx_file_2}" = "" ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			dtx_file_2="$1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			echo ""                                             >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			echo "ERROR: Unexpected parameter: $1"              >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 			echo ""                                             >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 			exit 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		shift
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	esac
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if [ "${srctree}" = "" ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	srctree="."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if [ "${dtx_file_2}" != "" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	cmd_diff=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (( ${help} )) ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	usage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) # this must follow check for ${help}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if [ "${dtx_file_1}" = "" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	echo ""                                                             >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	echo "ERROR: parameter DTx required"                                >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	echo ""                                                             >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	exit 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) # -----  prefer dtc from linux kernel, allow fallback to dtc in $PATH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if [ "${KBUILD_OUTPUT:0:2}" = ".." ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	__KBUILD_OUTPUT="${srctree}/${KBUILD_OUTPUT}"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) elif [ "${KBUILD_OUTPUT}" = "" ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	__KBUILD_OUTPUT="."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	__KBUILD_OUTPUT="${KBUILD_OUTPUT}"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) DTC="${__KBUILD_OUTPUT}/scripts/dtc/dtc"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) if [ ! -x ${DTC} ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	__DTC="dtc"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	if grep -q "^CONFIG_DTC=y" ${__KBUILD_OUTPUT}/.config 2>/dev/null; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		make_command='
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)          make scripts'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		make_command='
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)          Enable CONFIG_DTC in the kernel configuration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)          make scripts'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	if ( ! which ${__DTC} >/dev/null ) ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		# use spaces instead of tabs in the error message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		cat >&2 <<eod
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) ERROR: unable to find a 'dtc' program
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)    Preferred 'dtc' (built from Linux kernel source tree) was not found or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)    is not executable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)       'dtc' is: ${DTC}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)       If it does not exist, create it from the root of the Linux source tree:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) ${make_command}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)       If not at the root of the Linux kernel source tree -s SRCTREE or -S
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)       may need to be specified to find 'dtc'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)       If 'O=\${dir}' is specified in your Linux builds, this script requires
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)       'export KBUILD_OUTPUT=\${dir}' or add \${dir}/scripts/dtc to \$PATH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)       before running.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)       If \${KBUILD_OUTPUT} is a relative path, then '-s SRCDIR', -S, or run
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)       this script from the root of the Linux kernel source tree is required.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)    Fallback '${__DTC}' was also not in \${PATH} or is not executable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) eod
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		exit 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	DTC=${__DTC}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) # -----  cpp and dtc flags same as for linux source tree build of .dtb files,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) #        plus directories of the dtx file(s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) dtx_path_1_dtc_include="-i `dirname ${dtx_file_1}`"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) dtx_path_2_dtc_include=""
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) if (( ${cmd_diff} )) ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	dtx_path_2_dtc_include="-i `dirname ${dtx_file_2}`"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) cpp_flags="\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	-nostdinc                                  \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	-I${srctree}/scripts/dtc/include-prefixes  \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	-undef -D__DTS__"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) DTC="\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	${DTC}                                     \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	-i ${srctree}/scripts/dtc/include-prefixes \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	-O dts -qq -f ${dtc_sort} ${annotate} -o -"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) # -----  do the diff or decompile
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) if (( ${cmd_diff} )) ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	diff ${diff_flags} ${diff_color} --label "${dtx_file_1}" --label "${dtx_file_2}" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		<(compile_to_dts "${dtx_file_1}" "${dtx_path_1_dtc_include}") \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		<(compile_to_dts "${dtx_file_2}" "${dtx_path_2_dtc_include}")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	compile_to_dts "${dtx_file_1}" "${dtx_path_1_dtc_include}"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) fi