-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoverlay_convert_and_validate
More file actions
executable file
·192 lines (149 loc) · 6.27 KB
/
overlay_convert_and_validate
File metadata and controls
executable file
·192 lines (149 loc) · 6.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#! /bin/bash
# Copyright 2016 Frank Rowand frowand.list@gmail.com
# Copyright 2017 Frank Rowand frowand.list@gmail.com
#
# license: GPL V2
# This file is subject to the terms and conditions of the GNU General Public
# License v2.
#
# Convert overlay dts file from hand-coded expanded form to new syntactic
# sugar form. Wrapper around overlay_convert_raw to add some validation.
#_______________________________________________________________________________
function usage
{
echo "" >&2
echo "usage:" >&2
echo " `basename $0` -h | -help | --help" >&2
echo " `basename $0` [options] OLD_DTS NEW_DTS" >&2
echo "" >&2
echo " Convert OLD_DTS from old overlay style to new overlay style" >&2
echo " using syntactic sugar." >&2
echo "" >&2
echo " Wrapper around overlay_convert_raw to add some validation." >&2
echo "" >&2
echo " Options:" >&2
echo " -h Synonym for --help" >&2
echo " --force Try to produce output even if errors exist" >&2
echo " --help Print this message" >&2
echo " --no-indent-fix do not remove extra leading tabs" >&2
echo " --overwrite Overwrite NEW_DTS if it already exists" >&2
echo " --verbose Print more information" >&2
echo "" >&2
echo " The early patches to dtc to support overlays required 'fragment'" >&2
echo " and '__overlay__' nodes in the .dts source. Later patches to dtc" >&2
echo " will not require these nodes (and may possibly disallow them)." >&2
echo " The new overlay style is expected to be the preferrred form." >&2
echo "" >&2
echo " Will not overwrite NEW_DTS if it already exists." >&2
echo "" >&2
echo " Exit status is:" >&2
echo " 0 success" >&2
echo " 1 general error" >&2
echo " 2 NEW_DTS already exists" >&2
echo " 3 conversion ERROR" >&2
echo " 4 conversion WARNING" >&2
echo " 5 'dtc -@ -O dts OLD_DTS' is different than 'dtc -@ -O dts NEW_DTS'" >&2
echo "" >&2
echo " If a conversion WARNING occurs, a diff of OLD_DTS and NEW_DTS" >&2
echo " will be attempted. If the diff succeeds, the exit status will" >&2
echo " be 4, else the exit status will be 5." >&2
echo "" >&2
}
unset force
unset new_dts
unset no_indent_fix
unset old_dts
unset overwrite
unset verbose
while [[ ($# -gt 0) ]] ; do
case $1 in
--force )
shift
force="--force"
;;
-h | -help | --help )
shift
help=1
;;
--no-indent-fix )
shift
no_indent_fix="--no-indent-fix"
;;
--overwrite )
shift
overwrite=1
;;
--verbose )
shift
verbose="--verbose"
;;
* )
if [[ "${old_dts}" != "" ]] ; then
if [[ "${new_dts}" != "" ]] ; then
echo "" >&2
echo "ERROR: too many arguments" >&2
echo "" >&2
exit 1
fi
new_dts=$1
shift
else
old_dts=$1
shift
fi
;;
esac
done
if [[ (${help} == 1) ]] ; then
usage
exit 1
fi
#_______________________________________________________________________________
if [[ -f ${new_dts} && overwrite -eq 0 ]] ; then
echo "" >&2
echo "ERROR: file '${new_dts}' already exists" >&2
echo "" >&2
exit 2
fi
#_______________________________________________________________________________
if which overlay_convert >/dev/null ; then
OVERLAY_CONVERT=overlay_convert
elif which ./overlay_convert >/dev/null ; then
OVERLAY_CONVERT=./overlay_convert
else
echo "" >&2
echo "ERROR: overlay_convert not found or not executable" >&2
echo "" >&2
exit 1
fi
OVERLAY_CONVERT_OPTIONS="${force} ${no_indent_fix} ${verbose}"
${OVERLAY_CONVERT} ${OVERLAY_CONVERT_OPTIONS} ${old_dts} > ${new_dts}
convert_status=$?
if [ ${convert_status} -ne 0 -a ${convert_status} -ne 3 ] ; then
echo "" >&2
echo "ERROR: unable to convert ${old_dts}" >&2
echo "" >&2
if [ "${force}" == "" ] ; then
rm ${new_dts}
fi
exit 3
fi
if ! which dtc >/dev/null ; then
echo "" >&2
echo "ERROR: dtc not found or not executable" >&2
echo " add the location of dtc to \$PATH" >&2
echo "" >&2
exit 1
fi
if ! diff -q \
<(dtc -@ -O dts ${old_dts} 2>/dev/null) \
<(dtc -@ -O dts ${new_dts} 2>/dev/null) \
> /dev/null 2>/dev/null ; then
echo "" >&2
echo "ERROR: ${new_dts} is not equivalent to ${old_dts}" >&2
echo "" >&2
exit 5
fi
if [ ${convert_status} -eq 3 ] ; then
exit 4
fi