Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Tools/ardupilotwaf/boards.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def __init__(self):

def configure(self, cfg):
cfg.env.TOOLCHAIN = cfg.options.toolchain or self.toolchain
cfg.env.ROMFS_FILES = []
if hasattr(self,'configure_toolchain'):
self.configure_toolchain(cfg)
else:
Expand Down
51 changes: 19 additions & 32 deletions Tools/ardupilotwaf/chibios.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,32 +514,6 @@ def setup_canperiph_build(cfg):

cfg.get_board().with_can = True

def load_env_vars_handle_kv_pair(env, kv_pair):
'''handle a key/value pair out of the hwdef generator'''
(k, v) = kv_pair
if k == 'ROMFS_FILES':
env.ROMFS_FILES += v
return
hal_common.load_env_vars_handle_kv_pair(env, kv_pair)

def load_env_vars(env, hwdef_env):
'''load environment variables from the hwdef generator'''
hal_common.load_env_vars(env, hwdef_env, kv_handler=load_env_vars_handle_kv_pair)

if env.DEBUG or env.DEBUG_SYMBOLS:
env.CHIBIOS_BUILD_FLAGS += ' ENABLE_DEBUG_SYMBOLS=yes'
if env.ENABLE_ASSERTS:
env.CHIBIOS_BUILD_FLAGS += ' ENABLE_ASSERTS=yes'
if env.ENABLE_MALLOC_GUARD:
env.CHIBIOS_BUILD_FLAGS += ' ENABLE_MALLOC_GUARD=yes'
if env.ENABLE_STATS:
env.CHIBIOS_BUILD_FLAGS += ' ENABLE_STATS=yes'
if env.ENABLE_DFU_BOOT and env.BOOTLOADER:
env.CHIBIOS_BUILD_FLAGS += ' USE_ASXOPT=-DCRT0_ENTRY_HOOK=TRUE'
if env.AP_BOARD_START_TIME:
env.CHIBIOS_BUILD_FLAGS += ' AP_BOARD_START_TIME=0x%x' % env.AP_BOARD_START_TIME


def setup_optimization(env):
'''setup optimization flags for build'''
if env.DEBUG:
Expand Down Expand Up @@ -601,12 +575,24 @@ def bldpath(path):
env.DEFAULT_PARAMETERS = cfg.options.default_parameters

try:
hwdef_env, hwdef_files = generate_hwdef_h(env)
hwdef_obj = generate_hwdef_h(env)
except Exception:
traceback.print_exc()
cfg.fatal("Failed to process hwdef.dat")
load_env_vars(cfg.env, hwdef_env)
hal_common.handle_hwdef_files(cfg, hwdef_files)
hal_common.process_hwdef_results(cfg, hwdef_obj)

if env.DEBUG or env.DEBUG_SYMBOLS:
env.CHIBIOS_BUILD_FLAGS += ' ENABLE_DEBUG_SYMBOLS=yes'
if env.ENABLE_ASSERTS:
env.CHIBIOS_BUILD_FLAGS += ' ENABLE_ASSERTS=yes'
if env.ENABLE_MALLOC_GUARD:
env.CHIBIOS_BUILD_FLAGS += ' ENABLE_MALLOC_GUARD=yes'
if env.ENABLE_STATS:
env.CHIBIOS_BUILD_FLAGS += ' ENABLE_STATS=yes'
if env.ENABLE_DFU_BOOT and env.BOOTLOADER:
env.CHIBIOS_BUILD_FLAGS += ' USE_ASXOPT=-DCRT0_ENTRY_HOOK=TRUE'
if env.AP_BOARD_START_TIME:
env.CHIBIOS_BUILD_FLAGS += ' AP_BOARD_START_TIME=0x%x' % env.AP_BOARD_START_TIME

if env.HAL_NUM_CAN_IFACES and not env.AP_PERIPH:
setup_canmgr_build(cfg)
Expand Down Expand Up @@ -639,7 +625,7 @@ def generate_hwdef_h(env):
if env.HWDEF_EXTRA:
hwdef.append(env.HWDEF_EXTRA)

c = chibios_hwdef.ChibiOSHWDef(
hwdef_obj = chibios_hwdef.ChibiOSHWDef(
outdir=hwdef_out,
bootloader=bootloader_flag,
signed_fw=bool(env.AP_SIGNED_FIRMWARE),
Expand All @@ -649,8 +635,9 @@ def generate_hwdef_h(env):
default_params_filepath=str(env.DEFAULT_PARAMETERS),
quiet=False,
)
c.run()
return c.env_vars, c.output_files
hwdef_obj.run()

return hwdef_obj

def pre_build(bld):
'''pre-build hook to change dynamic sources'''
Expand Down
15 changes: 8 additions & 7 deletions Tools/ardupilotwaf/esp32.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,11 @@ def bldpath(path):
print("USING EXPRESSIF IDF:"+str(env.IDF))

try:
hwdef_env, hwdef_files = generate_hwdef_h(env)
hwdef_obj = generate_hwdef_h(env)
except Exception:
traceback.print_exc()
cfg.fatal("Failed to generate hwdef")
hal_common.load_env_vars(cfg.env, hwdef_env)
hal_common.handle_hwdef_files(cfg, hwdef_files)
cfg.fatal("Failed to process hwdef.dat")
hal_common.process_hwdef_results(cfg, hwdef_obj)

def generate_hwdef_h(env):
'''run esp32_hwdef.py'''
Expand All @@ -77,13 +76,15 @@ def generate_hwdef_h(env):
hwdef = [env.HWDEF]
if env.HWDEF_EXTRA:
hwdef.append(env.HWDEF_EXTRA)
eh = esp32_hwdef.ESP32HWDef(

hwdef_obj = esp32_hwdef.ESP32HWDef(
outdir=hwdef_out,
hwdef=hwdef,
quiet=False,
)
eh.run()
return eh.env_vars, eh.output_files
hwdef_obj.run()

return hwdef_obj

# delete the output sdkconfig file when the input defaults changes. we take the
# stamp as the output so we can compute the path to the sdkconfig, yet it
Expand Down
40 changes: 11 additions & 29 deletions Tools/ardupilotwaf/hal_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,21 @@
"""


def load_env_vars(env, hwdef_env, kv_handler=None):
'''load environment variables from the hwdef generator'''
for kv in hwdef_env.items():
if kv_handler is not None:
kv_handler(env, kv)
continue
load_env_vars_handle_kv_pair(env, kv)


def load_env_vars_handle_kv_pair(env, kv_pair):
'''handle a key/value pair out of the hwdef generator'''
(k, v) = kv_pair
if k in env:
if isinstance(env[k], dict):
a = v.split('=')
env[k][a[0]] = '='.join(a[1:])
print("env updated %s=%s" % (k, v))
elif isinstance(env[k], list):
env[k].append(v)
print("env appended %s=%s" % (k, v))
def process_hwdef_results(cfg, hwdef_obj):
# load environment variables
env = cfg.env
for k, v in hwdef_obj.env_vars.items():
if k in env:
# don't want to encourage modifications from the hwdef
raise ValueError(f"hwdef redefines environment variable {k} "
f"with existing value {env[k]!r} to value {v!r}")
else:
env[k] = v
print("env added %s=%s" % (k, v))
else:
env[k] = v
print("env set %s=%s" % (k, v))
print("env set %s=%s" % (k, v))


def handle_hwdef_files(cfg, hwdef_files):
# note files generated by hwdef system as cfg_files. this ensures they
# don't get deleted on `./waf clean`. this also ensures their node exists
# so implicit dependencies are properly tracked.

bldnode = cfg.bldnode.make_node(cfg.variant)
for file in sorted(hwdef_files):
cfg.env.append_value("cfg_files", bldnode.make_node(file).abspath())
for file in sorted(hwdef_obj.output_files):
env.append_value("cfg_files", bldnode.make_node(file).abspath())
15 changes: 8 additions & 7 deletions Tools/ardupilotwaf/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@ def bldpath(path):
env.AP_PROGRAM_FEATURES += ['linux_ap_program']

try:
hwdef_env, hwdef_files = generate_hwdef_h(env)
hwdef_obj = generate_hwdef_h(env)
except Exception:
traceback.print_exc()
cfg.fatal("Failed to generate hwdef")
hal_common.load_env_vars(cfg.env, hwdef_env)
hal_common.handle_hwdef_files(cfg, hwdef_files)
cfg.fatal("Failed to process hwdef.dat")
hal_common.process_hwdef_results(cfg, hwdef_obj)


def generate_hwdef_h(env):
Expand All @@ -65,13 +64,15 @@ def generate_hwdef_h(env):
hwdef = [env.HWDEF]
if env.HWDEF_EXTRA:
hwdef.append(env.HWDEF_EXTRA)
lh = linux_hwdef.LinuxHWDef(

hwdef_obj = linux_hwdef.LinuxHWDef(
outdir=hwdef_out,
hwdef=hwdef,
quiet=False,
)
lh.run()
return lh.env_vars, lh.output_files
hwdef_obj.run()

return hwdef_obj


def pre_build(bld):
Expand Down
Loading