Browse Source

scripts: updated gen_handles.py to take Zephyr base as argument

The script gen_handles.py was introduce in #32127 but relies on
ZEPHYR_BASE being set in environment.

However, it is not a requirement to set Zephyr base in the users
environment, therefore this is changed to an argument `-z` or
`--zephyr-base` which will be passed from the build system to the
script.

If `-z` or `--zephyr-base` is not provided, the environment will be
checked for a ZEPHYR_BASE setting there.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
pull/33244/head
Torsten Rasmussen 4 years ago committed by Anas Nashif
parent
commit
b92b580835
  1. 1
      CMakeLists.txt
  2. 17
      scripts/gen_handles.py

1
CMakeLists.txt

@ -773,6 +773,7 @@ add_custom_command(
${ZEPHYR_BASE}/scripts/gen_handles.py ${ZEPHYR_BASE}/scripts/gen_handles.py
--output-source dev_handles.c --output-source dev_handles.c
--kernel $<TARGET_FILE:${ZEPHYR_PREBUILT_EXECUTABLE}> --kernel $<TARGET_FILE:${ZEPHYR_PREBUILT_EXECUTABLE}>
--zephyr-base ${ZEPHYR_BASE}
DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE} DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE}
) )
set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_SOURCE_FILES dev_handles.c) set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_SOURCE_FILES dev_handles.c)

17
scripts/gen_handles.py

@ -41,9 +41,6 @@ import elftools.elf.enums
if LooseVersion(elftools.__version__) < LooseVersion('0.24'): if LooseVersion(elftools.__version__) < LooseVersion('0.24'):
sys.exit("pyelftools is out of date, need version 0.24 or later") sys.exit("pyelftools is out of date, need version 0.24 or later")
ZEPHYR_BASE = os.getenv("ZEPHYR_BASE")
sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/dts"))
scr = os.path.basename(sys.argv[0]) scr = os.path.basename(sys.argv[0])
def debug(text): def debug(text):
@ -65,10 +62,24 @@ def parse_args():
parser.add_argument("-v", "--verbose", action="store_true", parser.add_argument("-v", "--verbose", action="store_true",
help="Print extra debugging information") help="Print extra debugging information")
parser.add_argument("-z", "--zephyr-base",
help="Path to current Zephyr base. If this argument \
is not provided the environment will be checked for \
the ZEPHYR_BASE environment variable.")
args = parser.parse_args() args = parser.parse_args()
if "VERBOSE" in os.environ: if "VERBOSE" in os.environ:
args.verbose = 1 args.verbose = 1
ZEPHYR_BASE = args.zephyr_base or os.getenv("ZEPHYR_BASE")
if ZEPHYR_BASE is None:
sys.exit("-z / --zephyr-base not provided. Please provide "
"--zephyr-base or set ZEPHYR_BASE in environment")
sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/dts"))
def symbol_data(elf, sym): def symbol_data(elf, sym):
addr = sym.entry.st_value addr = sym.entry.st_value

Loading…
Cancel
Save