devicetree: use edt.pickle more
Consolidate creation of edtlib.EDT objects from a build directory's
devicetree into one place by loading it from build/zephyr/edt.pickle
everywhere. A previous commit creates edt.pickle from gen_defines.py.
In addition to probably speeding things up slightly by not reparsing
the devicetree, the main benefit of this approach is creating a single
point of truth for the bindings directories and warnings
configuration, meaning we don't have to worry about them getting out
of sync while being passed around between devicetree creation and
usage time.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
diff --git a/scripts/west_commands/sign.py b/scripts/west_commands/sign.py
index f4001fb..54c0844 100644
--- a/scripts/west_commands/sign.py
+++ b/scripts/west_commands/sign.py
@@ -6,6 +6,7 @@
import argparse
import os
import pathlib
+import pickle
import shutil
import subprocess
import sys
@@ -20,10 +21,9 @@
from zephyr_ext_common import Forceable, cached_runner_config, \
ZEPHYR_SCRIPTS
+# This is needed to load edt.pickle files.
sys.path.append(str(ZEPHYR_SCRIPTS / 'dts'))
-import edtlib
-
SIGN_DESCRIPTION = '''\
This command automates some of the drudgery of creating signed Zephyr
binaries for chain-loading by a bootloader.
@@ -208,7 +208,7 @@
vtoff = self.get_cfg(command, bcfg, 'CONFIG_ROM_START_OFFSET')
# Flash device write alignment and the partition's slot size
# come from devicetree:
- flash = self.edt_flash_node(b, cache)
+ flash = self.edt_flash_node(b)
align, addr, size = self.edt_flash_params(flash)
runner_config = cached_runner_config(build_dir, cache)
@@ -280,30 +280,21 @@
return None
@staticmethod
- def edt_flash_node(b, cache):
+ def edt_flash_node(b):
# Get the EDT Node corresponding to the zephyr,flash chosen DT
- # node.
-
- # Retrieve the list of devicetree bindings from cache.
- try:
- bindings = cache.get_list('CACHED_DTS_ROOT_BINDINGS')
- log.dbg('DTS bindings:', bindings, level=log.VERBOSE_VERY)
- except KeyError:
- log.die('CMake cache has no CACHED_DTS_ROOT_BINDINGS.'
- '\n Try again after re-building your application.')
+ # node; 'b' is the build directory as a pathlib object.
# Ensure the build directory has a compiled DTS file
# where we expect it to be.
- dts = b / 'zephyr' / (cache['CACHED_BOARD'] + '.dts.pre.tmp')
- if not dts.is_file():
- log.die("can't find DTS; expected:", dts)
+ dts = b / 'zephyr' / 'zephyr.dts'
log.dbg('DTS file:', dts, level=log.VERBOSE_VERY)
+ edt_pickle = b / 'zephyr' / 'edt.pickle'
+ if not edt_pickle.is_file():
+ log.die("can't load devicetree; expected to find:", edt_pickle)
- # Parse the devicetree using bindings from cache.
- try:
- edt = edtlib.EDT(dts, bindings)
- except edtlib.EDTError as e:
- log.die("can't parse devicetree:", e)
+ # Load the devicetree.
+ with open(edt_pickle, 'rb') as f:
+ edt = pickle.load(f)
# By convention, the zephyr,flash chosen node contains the
# partition information about the zephyr image to sign.