Skip to content

Commit fc416ca

Browse files
mbolivar-nordicnashif
authored andcommitted
cmake: run dtc after gen_defines.py and friends
Curently, any and all devicetree syntax errors are being handled by dtc, because it runs before gen_defines.py. This means that any improvements we make to devicetree error handling and reporting in dtlib or edtlib will never be noticed by users that have dtc installed. (This also has the unfortunate effect of hiding dtlib error reporting from me, since my systems all have dtc installed.) Move dtc to after gen_defines.py, so that initial error handling and warnings all come from python. If DTC has some additional warnings or errors to report, let them come last. They will still halt the build if anything is wrong. Signed-off-by: Martí Bolívar <[email protected]>
1 parent 6c65b15 commit fc416ca

File tree

1 file changed

+43
-44
lines changed

1 file changed

+43
-44
lines changed

cmake/dts.cmake

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -182,50 +182,6 @@ if(SUPPORTS_DTS)
182182
${DTS_CMAKE_SCRIPT}
183183
)
184184

185-
#
186-
# Run the C devicetree compiler on *.dts.pre.tmp, just to catch any
187-
# warnings/errors from it. dtlib and edtlib parse the devicetree files
188-
# themselves, so we don't rely on the C compiler otherwise.
189-
#
190-
191-
if(DTC)
192-
set(DTC_WARN_UNIT_ADDR_IF_ENABLED "")
193-
check_dtc_flag("-Wunique_unit_address_if_enabled" check)
194-
if (check)
195-
set(DTC_WARN_UNIT_ADDR_IF_ENABLED "-Wunique_unit_address_if_enabled")
196-
endif()
197-
set(DTC_NO_WARN_UNIT_ADDR "")
198-
check_dtc_flag("-Wno-unique_unit_address" check)
199-
if (check)
200-
set(DTC_NO_WARN_UNIT_ADDR "-Wno-unique_unit_address")
201-
endif()
202-
set(VALID_EXTRA_DTC_FLAGS "")
203-
foreach(extra_opt ${EXTRA_DTC_FLAGS})
204-
check_dtc_flag(${extra_opt} check)
205-
if (check)
206-
list(APPEND VALID_EXTRA_DTC_FLAGS ${extra_opt})
207-
endif()
208-
endforeach()
209-
set(EXTRA_DTC_FLAGS ${VALID_EXTRA_DTC_FLAGS})
210-
execute_process(
211-
COMMAND ${DTC}
212-
-O dts
213-
-o - # Write output to stdout, which we discard below
214-
-b 0
215-
-E unit_address_vs_reg
216-
${DTC_NO_WARN_UNIT_ADDR}
217-
${DTC_WARN_UNIT_ADDR_IF_ENABLED}
218-
${EXTRA_DTC_FLAGS} # User settable
219-
${BOARD}.dts.pre.tmp
220-
OUTPUT_QUIET # Discard stdout
221-
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
222-
RESULT_VARIABLE ret
223-
)
224-
if(NOT "${ret}" STREQUAL "0")
225-
message(FATAL_ERROR "command failed with return code: ${ret}")
226-
endif()
227-
endif(DTC)
228-
229185
#
230186
# Run gen_defines.py to create a header file, zephyr.dts, and edt.pickle.
231187
#
@@ -269,6 +225,49 @@ if(SUPPORTS_DTS)
269225
include(${DTS_CMAKE})
270226
endif()
271227

228+
#
229+
# Run the C devicetree compiler on *.dts.pre.tmp, just to catch any
230+
# warnings/errors from it. dtlib and edtlib parse the devicetree files
231+
# themselves, so we don't rely on the C compiler otherwise.
232+
#
233+
234+
if(DTC)
235+
set(DTC_WARN_UNIT_ADDR_IF_ENABLED "")
236+
check_dtc_flag("-Wunique_unit_address_if_enabled" check)
237+
if (check)
238+
set(DTC_WARN_UNIT_ADDR_IF_ENABLED "-Wunique_unit_address_if_enabled")
239+
endif()
240+
set(DTC_NO_WARN_UNIT_ADDR "")
241+
check_dtc_flag("-Wno-unique_unit_address" check)
242+
if (check)
243+
set(DTC_NO_WARN_UNIT_ADDR "-Wno-unique_unit_address")
244+
endif()
245+
set(VALID_EXTRA_DTC_FLAGS "")
246+
foreach(extra_opt ${EXTRA_DTC_FLAGS})
247+
check_dtc_flag(${extra_opt} check)
248+
if (check)
249+
list(APPEND VALID_EXTRA_DTC_FLAGS ${extra_opt})
250+
endif()
251+
endforeach()
252+
set(EXTRA_DTC_FLAGS ${VALID_EXTRA_DTC_FLAGS})
253+
execute_process(
254+
COMMAND ${DTC}
255+
-O dts
256+
-o - # Write output to stdout, which we discard below
257+
-b 0
258+
-E unit_address_vs_reg
259+
${DTC_NO_WARN_UNIT_ADDR}
260+
${DTC_WARN_UNIT_ADDR_IF_ENABLED}
261+
${EXTRA_DTC_FLAGS} # User settable
262+
${BOARD}.dts.pre.tmp
263+
OUTPUT_QUIET # Discard stdout
264+
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
265+
RESULT_VARIABLE ret
266+
)
267+
if(NOT "${ret}" STREQUAL "0")
268+
message(FATAL_ERROR "command failed with return code: ${ret}")
269+
endif()
270+
endif(DTC)
272271
else()
273272
file(WRITE ${DEVICETREE_UNFIXED_H} "/* WARNING. THIS FILE IS AUTO-GENERATED. DO NOT MODIFY! */")
274273
file(WRITE ${DEVICE_EXTERN_H} "/* WARNING. THIS FILE IS AUTO-GENERATED. DO NOT MODIFY! */")

0 commit comments

Comments
 (0)