blob: 18c59ac1e255a34a33829437e314741d43296f70 [file] [log] [blame]
Simon Glassd7faa082021-09-22 11:34:43 -06001#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0+
3#
4# dtc-version dtc-command
5#
6# Prints the dtc version of `dtc-command' in a canonical 6-digit form
7# such as `010404' for dtc 1.4.4
8#
9
10dtc="$*"
11
12if [ ${#dtc} -eq 0 ]; then
Simon Glass93b19652021-09-22 11:34:44 -060013 echo "Error: No dtc command specified"
Simon Glassd7faa082021-09-22 11:34:43 -060014 printf "Usage:\n\t$0 <dtc-command>\n"
15 exit 1
16fi
17
Dragan Simic5b3f9692024-02-06 12:00:04 +010018if ! which $dtc > /dev/null 2>&1 ; then
Simon Glass93b19652021-09-22 11:34:44 -060019 echo "Error: Cannot find dtc: $dtc"
20 exit 1
21fi
22
Martin Hundebøllf0738152023-05-03 12:23:39 +020023MAJOR=$($dtc -v | head -1 | awk '{print $NF}' | cut -d . -f 1 | tr -d v)
Simon Glassd7faa082021-09-22 11:34:43 -060024MINOR=$($dtc -v | head -1 | awk '{print $NF}' | cut -d . -f 2)
25PATCH=$($dtc -v | head -1 | awk '{print $NF}' | cut -d . -f 3 | cut -d - -f 1)
26
27printf "%02d%02d%02d\\n" $MAJOR $MINOR $PATCH