Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Tools/ardupilotwaf/boards.py
Views: 1798
# encoding: utf-812from collections import OrderedDict3import re4import sys, os5import fnmatch6import platform78import waflib9from waflib import Utils10from waflib.Configure import conf11import json12_board_classes = {}13_board = None1415# modify our search path:16sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../libraries/AP_HAL_ChibiOS/hwdef/scripts'))17import chibios_hwdef18import build_options1920class BoardMeta(type):21def __init__(cls, name, bases, dct):22super(BoardMeta, cls).__init__(name, bases, dct)2324if 'abstract' not in cls.__dict__:25cls.abstract = False26if cls.abstract:27return2829if not hasattr(cls, 'toolchain'):30cls.toolchain = 'native'3132board_name = getattr(cls, 'name', name)33if board_name in _board_classes:34raise Exception('board named %s already exists' % board_name)35_board_classes[board_name] = cls3637class Board:38abstract = True3940def __init__(self):41self.with_can = False4243def configure(self, cfg):44cfg.env.TOOLCHAIN = cfg.options.toolchain or self.toolchain45cfg.env.ROMFS_FILES = []46if hasattr(self,'configure_toolchain'):47self.configure_toolchain(cfg)48else:49cfg.load('toolchain')50cfg.load('cxx_checks')5152# don't check elf symbols by default53cfg.env.CHECK_SYMBOLS = False5455env = waflib.ConfigSet.ConfigSet()56def srcpath(path):57return cfg.srcnode.make_node(path).abspath()58env.SRCROOT = srcpath('')5960self.configure_env(cfg, env)6162# Setup scripting:63env.DEFINES.update(64LUA_32BITS = 1,65)6667env.AP_LIBRARIES += [68'AP_Scripting',69'AP_Scripting/lua/src',70]7172if cfg.options.enable_scripting:73env.DEFINES.update(74AP_SCRIPTING_ENABLED = 1,75)76elif cfg.options.disable_scripting:77env.DEFINES.update(78AP_SCRIPTING_ENABLED = 0,79)8081# allow GCS disable for AP_DAL example82if cfg.options.no_gcs:83env.CXXFLAGS += ['-DHAL_GCS_ENABLED=0']8485# configurations for XRCE-DDS86if cfg.options.enable_dds:87cfg.recurse('libraries/AP_DDS')88env.ENABLE_DDS = True89env.AP_LIBRARIES += [90'AP_DDS'91]92env.DEFINES.update(AP_DDS_ENABLED = 1)93# check for microxrceddsgen94cfg.find_program('microxrceddsgen',mandatory=True)95else:96env.ENABLE_DDS = False97env.DEFINES.update(AP_DDS_ENABLED = 0)9899# setup for supporting onvif cam control100if cfg.options.enable_onvif:101cfg.recurse('libraries/AP_ONVIF')102env.ENABLE_ONVIF = True103env.ROMFS_FILES += [('scripts/ONVIF_Camera_Control.lua',104'libraries/AP_Scripting/applets/ONVIF_Camera_Control.lua')]105env.DEFINES.update(106ENABLE_ONVIF=1,107SCRIPTING_ENABLE_DEFAULT=1,108)109env.AP_LIBRARIES += [110'AP_ONVIF'111]112else:113env.ENABLE_ONVIF = False114env.DEFINES.update(115ENABLE_ONVIF=0,116)117118# allow enable of OpenDroneID for any board119if cfg.options.enable_opendroneid:120env.ENABLE_OPENDRONEID = True121env.DEFINES.update(122AP_OPENDRONEID_ENABLED=1,123)124cfg.msg("Enabled OpenDroneID", 'yes')125else:126cfg.msg("Enabled OpenDroneID", 'no', color='YELLOW')127128# allow enable of firmware ID checking for any board129if cfg.options.enable_check_firmware:130env.CHECK_FIRMWARE_ENABLED = True131env.DEFINES.update(132AP_CHECK_FIRMWARE_ENABLED=1,133)134cfg.msg("Enabled firmware ID checking", 'yes')135else:136cfg.msg("Enabled firmware ID checking", 'no', color='YELLOW')137138if cfg.options.enable_gps_logging:139env.DEFINES.update(140AP_GPS_DEBUG_LOGGING_ENABLED=1,141)142cfg.msg("GPS Debug Logging", 'yes')143else:144cfg.msg("GPS Debug Logging", 'no', color='YELLOW')145146# allow enable of custom controller for any board147# enabled on sitl by default148if (cfg.options.enable_custom_controller or self.get_name() == "sitl") and not cfg.options.no_gcs:149env.ENABLE_CUSTOM_CONTROLLER = True150env.DEFINES.update(151AP_CUSTOMCONTROL_ENABLED=1,152)153env.AP_LIBRARIES += [154'AC_CustomControl'155]156cfg.msg("Enabled custom controller", 'yes')157else:158env.DEFINES.update(159AP_CUSTOMCONTROL_ENABLED=0,160)161cfg.msg("Enabled custom controller", 'no', color='YELLOW')162163# support enabling any option in build_options.py164for opt in build_options.BUILD_OPTIONS:165enable_option = opt.config_option().replace("-","_")166disable_option = "disable_" + enable_option[len("enable-"):]167if getattr(cfg.options, enable_option, False):168env.CXXFLAGS += ['-D%s=1' % opt.define]169cfg.msg("Enabled %s" % opt.label, 'yes', color='GREEN')170elif getattr(cfg.options, disable_option, False):171env.CXXFLAGS += ['-D%s=0' % opt.define]172cfg.msg("Enabled %s" % opt.label, 'no', color='YELLOW')173174if cfg.options.disable_networking:175env.CXXFLAGS += ['-DAP_NETWORKING_ENABLED=0']176177if cfg.options.enable_networking_tests:178env.CXXFLAGS += ['-DAP_NETWORKING_TESTS_ENABLED=1']179180if cfg.options.enable_iomcu_profiled_support:181env.CXXFLAGS += ['-DAP_IOMCU_PROFILED_SUPPORT_ENABLED=1']182183d = env.get_merged_dict()184# Always prepend so that arguments passed in the command line get185# the priority.186for k, val in d.items():187# Dictionaries (like 'DEFINES') are converted to lists to188# conform to waf conventions.189if isinstance(val, dict):190keys = list(val.keys())191if not isinstance(val, OrderedDict):192keys.sort()193val = ['%s=%s' % (vk, val[vk]) for vk in keys]194195if k in cfg.env and isinstance(cfg.env[k], list):196cfg.env.prepend_value(k, val)197else:198cfg.env[k] = val199200cfg.ap_common_checks()201202cfg.env.prepend_value('INCLUDES', [203cfg.srcnode.find_dir('libraries/AP_Common/missing').abspath()204])205if os.path.exists(os.path.join(env.SRCROOT, '.vscode/c_cpp_properties.json')) and 'AP_NO_COMPILE_COMMANDS' not in os.environ:206# change c_cpp_properties.json configure the VSCode Intellisense env207c_cpp_properties = json.load(open(os.path.join(env.SRCROOT, '.vscode/c_cpp_properties.json')))208for config in c_cpp_properties['configurations']:209config['compileCommands'] = "${workspaceFolder}/build/%s/compile_commands.json" % self.get_name()210json.dump(c_cpp_properties, open(os.path.join(env.SRCROOT, './.vscode/c_cpp_properties.json'), 'w'), indent=4)211cfg.msg("Configured VSCode Intellisense", 'yes')212else:213cfg.msg("Configured VSCode Intellisense:", 'no', color='YELLOW')214215def cc_version_gte(self, cfg, want_major, want_minor):216if cfg.env.TOOLCHAIN == "custom":217return True218(major, minor, patchlevel) = cfg.env.CC_VERSION219return (int(major) > want_major or220(int(major) == want_major and int(minor) >= want_minor))221222def configure_env(self, cfg, env):223# Use a dictionary instead of the conventional list for definitions to224# make easy to override them. Convert back to list before consumption.225env.DEFINES = {}226227env.with_can = self.with_can228229# potentially set extra defines from an environment variable:230if cfg.options.define is not None:231for (n, v) in [d.split("=") for d in cfg.options.define]:232cfg.msg("Defining: %s" % (n, ), v)233env.CFLAGS += ['-D%s=%s' % (n, v)]234env.CXXFLAGS += ['-D%s=%s' % (n, v)]235236env.CFLAGS += [237'-ffunction-sections',238'-fdata-sections',239'-fsigned-char',240241'-Wall',242'-Wextra',243'-Werror=format',244'-Wpointer-arith',245'-Wcast-align',246'-Wno-missing-field-initializers',247'-Wno-unused-parameter',248'-Wno-redundant-decls',249'-Wno-unknown-pragmas',250'-Wno-trigraphs',251'-Werror=shadow',252'-Werror=return-type',253'-Werror=unused-result',254'-Werror=unused-variable',255'-Werror=narrowing',256'-Werror=attributes',257'-Werror=overflow',258'-Werror=parentheses',259'-Werror=format-extra-args',260'-Werror=ignored-qualifiers',261'-Werror=undef',262'-DARDUPILOT_BUILD',263]264265if cfg.options.scripting_checks:266env.DEFINES.update(267AP_SCRIPTING_CHECKS = 1,268)269270cfg.msg("CXX Compiler", "%s %s" % (cfg.env.COMPILER_CXX, ".".join(cfg.env.CC_VERSION)))271272if cfg.options.assert_cc_version:273cfg.msg("Checking compiler", "%s %s" % (cfg.options.assert_cc_version, ".".join(cfg.env.CC_VERSION)))274have_version = cfg.env.COMPILER_CXX+"-"+'.'.join(list(cfg.env.CC_VERSION))275want_version = cfg.options.assert_cc_version276if have_version != want_version:277cfg.fatal("cc version mismatch: %s should be %s" % (have_version, want_version))278279if 'clang' in cfg.env.COMPILER_CC:280env.CFLAGS += [281'-fcolor-diagnostics',282'-Wno-gnu-designator',283'-Wno-inconsistent-missing-override',284'-Wno-mismatched-tags',285'-Wno-gnu-variable-sized-type-not-at-end',286'-Werror=implicit-fallthrough',287'-cl-single-precision-constant',288]289env.CXXFLAGS += [290'-cl-single-precision-constant',291]292else:293env.CFLAGS += [294'-Wno-format-contains-nul',295'-fsingle-precision-constant', # force const vals to be float , not double. so 100.0 means 100.0f296]297if self.cc_version_gte(cfg, 7, 4):298env.CXXFLAGS += [299'-Werror=implicit-fallthrough',300]301env.CXXFLAGS += [302'-fsingle-precision-constant',303'-Wno-psabi',304]305306if cfg.env.DEBUG:307env.CFLAGS += [308'-g',309'-O0',310]311env.DEFINES.update(312HAL_DEBUG_BUILD = 1,313)314elif cfg.options.debug_symbols:315env.CFLAGS += [316'-g',317]318if cfg.env.COVERAGE:319env.CFLAGS += [320'-fprofile-arcs',321'-ftest-coverage',322]323env.CXXFLAGS += [324'-fprofile-arcs',325'-ftest-coverage',326]327env.LINKFLAGS += [328'-lgcov',329'-coverage',330]331env.DEFINES.update(332HAL_COVERAGE_BUILD = 1,333)334335if cfg.options.bootloader:336# don't let bootloaders try and pull scripting in337cfg.options.disable_scripting = True338if cfg.options.signed_fw:339env.DEFINES.update(340ENABLE_HEAP = 1,341)342else:343env.DEFINES.update(344ENABLE_HEAP = 1,345)346347if cfg.options.enable_math_check_indexes:348env.CXXFLAGS += ['-DMATH_CHECK_INDEXES']349350if cfg.options.private_key:351env.PRIVATE_KEY = cfg.options.private_key352353env.CXXFLAGS += [354'-std=gnu++11',355356'-fdata-sections',357'-ffunction-sections',358'-fno-exceptions',359'-fsigned-char',360361'-Wall',362'-Wextra',363'-Wpointer-arith',364'-Wno-unused-parameter',365'-Wno-missing-field-initializers',366'-Wno-redundant-decls',367'-Wno-unknown-pragmas',368'-Wno-expansion-to-defined',369'-Werror=reorder',370'-Werror=cast-align',371'-Werror=attributes',372'-Werror=format-security',373'-Werror=format-extra-args',374'-Werror=enum-compare',375'-Werror=format',376'-Werror=array-bounds',377'-Werror=uninitialized',378'-Werror=init-self',379'-Werror=narrowing',380'-Werror=return-type',381'-Werror=switch',382'-Werror=sign-compare',383'-Werror=type-limits',384'-Werror=undef',385'-Werror=unused-result',386'-Werror=shadow',387'-Werror=unused-value',388'-Werror=unused-variable',389'-Werror=delete-non-virtual-dtor',390'-Wfatal-errors',391'-Wno-trigraphs',392'-Werror=parentheses',393'-DARDUPILOT_BUILD',394'-Wuninitialized',395'-Warray-bounds',396]397398if 'clang++' in cfg.env.COMPILER_CXX:399env.CXXFLAGS += [400'-fcolor-diagnostics',401402'-Werror=address-of-packed-member',403404'-Werror=inconsistent-missing-override',405'-Werror=overloaded-virtual',406407# catch conversion issues:408'-Werror=bitfield-enum-conversion',409'-Werror=bool-conversion',410'-Werror=constant-conversion',411'-Werror=enum-conversion',412'-Werror=int-conversion',413'-Werror=literal-conversion',414'-Werror=non-literal-null-conversion',415'-Werror=null-conversion',416'-Werror=objc-literal-conversion',417# '-Werror=shorten-64-to-32', # ARRAY_SIZE() creates this all over the place as the caller typically takes a uint32_t not a size_t418'-Werror=string-conversion',419# '-Werror=sign-conversion', # can't use as we assign into AP_Int8 from uint8_ts420421'-Wno-gnu-designator',422'-Wno-mismatched-tags',423'-Wno-gnu-variable-sized-type-not-at-end',424'-Werror=implicit-fallthrough',425]426else:427env.CXXFLAGS += [428'-Wno-format-contains-nul',429'-Werror=unused-but-set-variable'430]431if self.cc_version_gte(cfg, 5, 2):432env.CXXFLAGS += [433'-Werror=suggest-override',434]435if self.cc_version_gte(cfg, 7, 4):436env.CXXFLAGS += [437'-Werror=implicit-fallthrough',438'-Werror=maybe-uninitialized',439'-Werror=duplicated-cond',440]441if self.cc_version_gte(cfg, 8, 4):442env.CXXFLAGS += [443'-Werror=sizeof-pointer-div',444]445if self.cc_version_gte(cfg, 13, 2):446env.CXXFLAGS += [447'-Werror=use-after-free',448]449env.CFLAGS += [450'-Werror=use-after-free',451]452453if cfg.options.Werror:454errors = ['-Werror',455'-Werror=missing-declarations',456'-Werror=float-equal',457'-Werror=undef',458]459env.CFLAGS += errors460env.CXXFLAGS += errors461462if cfg.env.DEBUG:463env.CXXFLAGS += [464'-g',465'-O0',466]467468if cfg.env.DEST_OS == 'darwin':469if self.cc_version_gte(cfg, 15, 0):470env.LINKFLAGS += [471'-Wl,-dead_strip,-ld_classic',472]473else:474env.LINKFLAGS += [475'-Wl,-dead_strip',476]477else:478env.LINKFLAGS += [479'-fno-exceptions',480'-Wl,--gc-sections',481]482483if self.with_can:484# for both AP_Perip and main fw enable deadlines485env.DEFINES.update(CANARD_ENABLE_DEADLINE = 1)486487if not cfg.env.AP_PERIPH:488env.AP_LIBRARIES += [489'AP_DroneCAN',490'modules/DroneCAN/libcanard/*.c',491]492if cfg.options.enable_dronecan_tests:493env.DEFINES.update(AP_TEST_DRONECAN_DRIVERS = 1)494495env.DEFINES.update(496DRONECAN_CXX_WRAPPERS = 1,497USE_USER_HELPERS = 1,498CANARD_ALLOCATE_SEM=1499)500501502503if cfg.options.build_dates:504env.build_dates = True505506# We always want to use PRI format macros507cfg.define('__STDC_FORMAT_MACROS', 1)508509if cfg.options.postype_single:510env.CXXFLAGS += ['-DHAL_WITH_POSTYPE_DOUBLE=0']511512if cfg.options.osd or cfg.options.osd_fonts:513env.CXXFLAGS += ['-DOSD_ENABLED=1', '-DHAL_MSP_ENABLED=1']514515if cfg.options.osd_fonts:516for f in os.listdir('libraries/AP_OSD/fonts'):517if fnmatch.fnmatch(f, "font*bin"):518env.ROMFS_FILES += [(f,'libraries/AP_OSD/fonts/'+f)]519520if cfg.options.ekf_double:521env.CXXFLAGS += ['-DHAL_WITH_EKF_DOUBLE=1']522523if cfg.options.ekf_single:524env.CXXFLAGS += ['-DHAL_WITH_EKF_DOUBLE=0']525526if cfg.options.consistent_builds:527# squash all line numbers to be the number 17528env.CXXFLAGS += [529"-D__AP_LINE__=17",530]531else:532env.CXXFLAGS += [533"-D__AP_LINE__=__LINE__",534]535536# add files from ROMFS_custom537custom_dir = 'ROMFS_custom'538if os.path.exists(custom_dir):539for root, subdirs, files in os.walk(custom_dir):540for f in files:541if fnmatch.fnmatch(f,"*~"):542# exclude emacs tmp files543continue544fname = root[len(custom_dir)+1:]+"/"+f545if fname.startswith("/"):546fname = fname[1:]547env.ROMFS_FILES += [(fname,root+"/"+f)]548549def pre_build(self, bld):550'''pre-build hook that gets called before dynamic sources'''551if bld.env.ROMFS_FILES:552self.embed_ROMFS_files(bld)553554def build(self, bld):555bld.ap_version_append_str('GIT_VERSION', bld.git_head_hash(short=True))556bld.ap_version_append_int('GIT_VERSION_INT', int("0x" + bld.git_head_hash(short=True), base=16))557bld.ap_version_append_str('AP_BUILD_ROOT', bld.srcnode.abspath())558import time559ltime = time.localtime()560if bld.env.build_dates:561bld.ap_version_append_int('BUILD_DATE_YEAR', ltime.tm_year)562bld.ap_version_append_int('BUILD_DATE_MONTH', ltime.tm_mon)563bld.ap_version_append_int('BUILD_DATE_DAY', ltime.tm_mday)564565def embed_ROMFS_files(self, ctx):566'''embed some files using AP_ROMFS'''567import embed568header = ctx.bldnode.make_node('ap_romfs_embedded.h').abspath()569if not embed.create_embedded_h(header, ctx.env.ROMFS_FILES, ctx.env.ROMFS_UNCOMPRESSED):570ctx.fatal("Failed to created ap_romfs_embedded.h")571572ctx.env.CXXFLAGS += ['-DHAL_HAVE_AP_ROMFS_EMBEDDED_H']573574# Allow lua to load from ROMFS if any lua files are added575for file in ctx.env.ROMFS_FILES:576if file[0].startswith("scripts") and file[0].endswith(".lua"):577ctx.env.CXXFLAGS += ['-DHAL_HAVE_AP_ROMFS_EMBEDDED_LUA']578break579580Board = BoardMeta('Board', Board.__bases__, dict(Board.__dict__))581582def add_dynamic_boards_chibios():583'''add boards based on existance of hwdef.dat in subdirectories for ChibiOS'''584dirname, dirlist, filenames = next(os.walk('libraries/AP_HAL_ChibiOS/hwdef'))585for d in dirlist:586if d in _board_classes.keys():587continue588hwdef = os.path.join(dirname, d, 'hwdef.dat')589if os.path.exists(hwdef):590newclass = type(d, (chibios,), {'name': d})591592@conf593def get_chibios_board_cls(ctx, name, hwdef):594if name in _board_classes.keys():595_board_classes[name].hwdef = hwdef596return _board_classes[name]597newclass = type(name, (chibios,), {'name': name})598newclass.hwdef = hwdef599return newclass600601def add_dynamic_boards_esp32():602'''add boards based on existance of hwdef.dat in subdirectories for ESP32'''603dirname, dirlist, filenames = next(os.walk('libraries/AP_HAL_ESP32/hwdef'))604for d in dirlist:605if d in _board_classes.keys():606continue607hwdef = os.path.join(dirname, d, 'hwdef.dat')608if os.path.exists(hwdef):609mcu_esp32s3 = True if (d[0:7] == "esp32s3") else False610if mcu_esp32s3:611newclass = type(d, (esp32s3,), {'name': d})612else:613newclass = type(d, (esp32,), {'name': d})614615def get_boards_names():616add_dynamic_boards_chibios()617add_dynamic_boards_esp32()618619return sorted(list(_board_classes.keys()), key=str.lower)620621def is_board_based(board, cls):622return issubclass(_board_classes[board], cls)623624def get_ap_periph_boards():625'''Add AP_Periph boards based on existance of periph keywork in hwdef.dat or board name'''626list_ap = [s for s in list(_board_classes.keys()) if "periph" in s]627dirname, dirlist, filenames = next(os.walk('libraries/AP_HAL_ChibiOS/hwdef'))628for d in dirlist:629if d in list_ap:630continue631hwdef = os.path.join(dirname, d, 'hwdef.dat')632if os.path.exists(hwdef):633ch = chibios_hwdef.ChibiOSHWDef(hwdef=[hwdef], quiet=True)634try:635if ch.is_periph_fw_unprocessed():636list_ap.append(d)637except chibios_hwdef.ChibiOSHWDefIncludeNotFoundException as e:638print(f"{e.includer} includes {e.hwdef} which does not exist")639sys.exit(1)640641list_ap = list(set(list_ap))642return list_ap643644def get_removed_boards():645'''list of boards which have been removed'''646return sorted(['px4-v1', 'px4-v2', 'px4-v3', 'px4-v4', 'px4-v4pro'])647648@conf649def get_board(ctx):650global _board651if not _board:652if not ctx.env.BOARD:653ctx.fatal('BOARD environment variable must be set before first call to get_board()')654if ctx.env.BOARD in get_removed_boards():655ctx.fatal('''656The board target %s has been removed from ArduPilot with the removal of NuttX support and HAL_PX4.657658Please use a replacement build as follows:659660px4-v2 Use Pixhawk1 build661px4-v3 Use Pixhawk1 or CubeBlack builds662px4-v4 Use Pixracer build663px4-v4pro Use DrotekP3Pro build664''' % ctx.env.BOARD)665666boards = _board_classes.keys()667if ctx.env.BOARD not in boards:668ctx.fatal("Invalid board '%s': choices are %s" % (ctx.env.BOARD, ', '.join(sorted(boards, key=str.lower))))669_board = _board_classes[ctx.env.BOARD]()670return _board671672# NOTE: Keeping all the board definitions together so we can easily673# identify opportunities to simplify common flags. In the future might674# be worthy to keep board definitions in files of their own.675676class sitl(Board):677678def __init__(self):679self.with_can = True680681def configure_env(self, cfg, env):682super(sitl, self).configure_env(cfg, env)683env.DEFINES.update(684CONFIG_HAL_BOARD = 'HAL_BOARD_SITL',685CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_NONE',686AP_SCRIPTING_CHECKS = 1, # SITL should always do runtime scripting checks687AP_BARO_PROBE_EXTERNAL_I2C_BUSES = 1,688)689690env.BOARD_CLASS = "SITL"691692cfg.define('AP_SIM_ENABLED', 1)693cfg.define('HAL_WITH_SPI', 1)694cfg.define('HAL_WITH_RAMTRON', 1)695cfg.define('AP_OPENDRONEID_ENABLED', 1)696cfg.define('AP_SIGNED_FIRMWARE', 0)697698cfg.define('AP_NOTIFY_LP5562_BUS', 2)699cfg.define('AP_NOTIFY_LP5562_ADDR', 0x30)700701# turn on fencepoint and rallypoint protocols so they're still tested:702env.CXXFLAGS.extend([703'-DAP_MAVLINK_RALLY_POINT_PROTOCOL_ENABLED=HAL_GCS_ENABLED&&HAL_RALLY_ENABLED',704'-DAC_POLYFENCE_FENCE_POINT_PROTOCOL_SUPPORT=HAL_GCS_ENABLED&&AP_FENCE_ENABLED'705])706707try:708env.CXXFLAGS.remove('-DHAL_NAVEKF2_AVAILABLE=0')709except ValueError:710pass711env.CXXFLAGS += ['-DHAL_NAVEKF2_AVAILABLE=1']712713if self.with_can:714cfg.define('HAL_NUM_CAN_IFACES', 2)715env.DEFINES.update(CANARD_MULTI_IFACE=1,716CANARD_IFACE_ALL = 0x3,717CANARD_ENABLE_CANFD = 1,718CANARD_ENABLE_ASSERTS = 1)719if not cfg.options.force_32bit:720# needed for cygwin721env.CXXFLAGS += [ '-DCANARD_64_BIT=1' ]722env.CFLAGS += [ '-DCANARD_64_BIT=1' ]723if Utils.unversioned_sys_platform().startswith("linux"):724cfg.define('HAL_CAN_WITH_SOCKETCAN', 1)725else:726cfg.define('HAL_CAN_WITH_SOCKETCAN', 0)727728env.CXXFLAGS += [729'-Werror=float-equal',730'-Werror=missing-declarations',731]732733if not cfg.options.disable_networking and not 'clang' in cfg.env.COMPILER_CC:734# lwip doesn't build with clang735env.CXXFLAGS += ['-DAP_NETWORKING_ENABLED=1']736737if cfg.options.ubsan or cfg.options.ubsan_abort:738env.CXXFLAGS += [739"-fsanitize=undefined",740"-fsanitize=float-cast-overflow",741"-DUBSAN_ENABLED",742]743env.LINKFLAGS += [744"-fsanitize=undefined",745"-lubsan",746]747748if cfg.options.ubsan_abort:749env.CXXFLAGS += [750"-fno-sanitize-recover"751]752753if not cfg.env.DEBUG:754env.CXXFLAGS += [755'-O3',756]757758if 'clang++' in cfg.env.COMPILER_CXX and cfg.options.asan:759env.CXXFLAGS += [760'-fsanitize=address',761'-fno-omit-frame-pointer',762]763764env.LIB += [765'm',766]767768cfg.check_librt(env)769cfg.check_feenableexcept()770771env.LINKFLAGS += ['-pthread',]772773if cfg.env.DEBUG and 'clang++' in cfg.env.COMPILER_CXX and cfg.options.asan:774env.LINKFLAGS += ['-fsanitize=address']775776env.AP_LIBRARIES += [777'AP_HAL_SITL',778'AP_CSVReader',779]780781env.AP_LIBRARIES += [782'SITL',783]784785# wrap malloc to ensure memory is zeroed786if cfg.env.DEST_OS == 'cygwin':787# on cygwin we need to wrap _malloc_r instead788env.LINKFLAGS += ['-Wl,--wrap,_malloc_r']789elif platform.system() != 'Darwin':790env.LINKFLAGS += ['-Wl,--wrap,malloc']791792if cfg.options.enable_sfml:793if not cfg.check_SFML(env):794cfg.fatal("Failed to find SFML libraries")795796if cfg.options.enable_sfml_joystick:797if not cfg.check_SFML(env):798cfg.fatal("Failed to find SFML libraries")799env.CXXFLAGS += ['-DSFML_JOYSTICK']800801if cfg.options.sitl_osd:802env.CXXFLAGS += ['-DWITH_SITL_OSD','-DOSD_ENABLED=1']803for f in os.listdir('libraries/AP_OSD/fonts'):804if fnmatch.fnmatch(f, "font*bin"):805env.ROMFS_FILES += [(f,'libraries/AP_OSD/fonts/'+f)]806807for f in os.listdir('Tools/autotest/models'):808if fnmatch.fnmatch(f, "*.json") or fnmatch.fnmatch(f, "*.parm"):809env.ROMFS_FILES += [('models/'+f,'Tools/autotest/models/'+f)]810811# include locations.txt so SITL on windows can lookup by name812env.ROMFS_FILES += [('locations.txt','Tools/autotest/locations.txt')]813814# embed any scripts from ROMFS/scripts815if os.path.exists('ROMFS/scripts'):816for f in os.listdir('ROMFS/scripts'):817if fnmatch.fnmatch(f, "*.lua"):818env.ROMFS_FILES += [('scripts/'+f,'ROMFS/scripts/'+f)]819820if cfg.options.sitl_rgbled:821env.CXXFLAGS += ['-DWITH_SITL_RGBLED']822823if cfg.options.enable_sfml_audio:824if not cfg.check_SFML_Audio(env):825cfg.fatal("Failed to find SFML Audio libraries")826env.CXXFLAGS += ['-DWITH_SITL_TONEALARM']827828if cfg.env.DEST_OS == 'cygwin':829env.LIB += [830'winmm',831]832833if Utils.unversioned_sys_platform() == 'cygwin':834env.CXXFLAGS += ['-DCYGWIN_BUILD']835836if 'clang++' in cfg.env.COMPILER_CXX:837print("Disabling SLP for clang++")838env.CXXFLAGS += [839'-fno-slp-vectorize' # compiler bug when trying to use SLP840]841842if cfg.options.force_32bit:843# 32bit platform flags844env.CXXFLAGS += [845'-m32',846]847env.CFLAGS += [848'-m32',849]850env.LDFLAGS += [851'-m32',852]853854# whitelist of compilers which we should build with -Werror855gcc_whitelist = frozenset([856('11','3','0'),857('11','4','0'),858('12','1','0'),859])860861# initialise werr_enabled from defaults:862werr_enabled = bool('g++' in cfg.env.COMPILER_CXX and cfg.env.CC_VERSION in gcc_whitelist)863864# now process overrides to that default:865if (cfg.options.Werror is not None and866cfg.options.Werror == cfg.options.disable_Werror):867cfg.fatal("Asked to both enable and disable Werror")868869if cfg.options.Werror is not None:870werr_enabled = cfg.options.Werror871elif cfg.options.disable_Werror is not None:872werr_enabled = not cfg.options.disable_Werror873874if werr_enabled:875cfg.msg("Enabling -Werror", "yes")876if '-Werror' not in env.CXXFLAGS:877env.CXXFLAGS += [ '-Werror' ]878else:879cfg.msg("Enabling -Werror", "no")880if '-Werror' in env.CXXFLAGS:881env.CXXFLAGS.remove('-Werror')882883def get_name(self):884return self.__class__.__name__885886887class sitl_periph(sitl):888def configure_env(self, cfg, env):889cfg.env.AP_PERIPH = 1890super(sitl_periph, self).configure_env(cfg, env)891env.DEFINES.update(892HAL_BUILD_AP_PERIPH = 1,893PERIPH_FW = 1,894HAL_RAM_RESERVE_START = 0,895896CANARD_ENABLE_CANFD = 1,897CANARD_ENABLE_TAO_OPTION = 1,898CANARD_MULTI_IFACE = 1,899900# FIXME: SITL library should not be using AP_AHRS:901AP_AHRS_ENABLED = 1,902AP_AHRS_BACKEND_DEFAULT_ENABLED = 0,903AP_AHRS_DCM_ENABLED = 1, # need a default backend904HAL_EXTERNAL_AHRS_ENABLED = 0,905906HAL_MAVLINK_BINDINGS_ENABLED = 1,907908AP_AIRSPEED_AUTOCAL_ENABLE = 0,909AP_CAN_SLCAN_ENABLED = 0,910AP_ICENGINE_ENABLED = 0,911AP_MISSION_ENABLED = 0,912AP_RCPROTOCOL_ENABLED = 0,913AP_RTC_ENABLED = 0,914AP_SCHEDULER_ENABLED = 0,915AP_SCRIPTING_ENABLED = 0,916AP_STATS_ENABLED = 0,917AP_UART_MONITOR_ENABLED = 1,918COMPASS_CAL_ENABLED = 0,919COMPASS_LEARN_ENABLED = 0,920COMPASS_MOT_ENABLED = 0,921HAL_CAN_DEFAULT_NODE_ID = 0,922HAL_CANMANAGER_ENABLED = 0,923HAL_GCS_ENABLED = 0,924HAL_GENERATOR_ENABLED = 0,925HAL_LOGGING_ENABLED = 0,926HAL_LOGGING_MAVLINK_ENABLED = 0,927HAL_PROXIMITY_ENABLED = 0,928HAL_RALLY_ENABLED = 0,929HAL_SUPPORT_RCOUT_SERIAL = 0,930AP_TERRAIN_AVAILABLE = 0,931AP_CUSTOMROTATIONS_ENABLED = 0,932)933934try:935env.CXXFLAGS.remove('-DHAL_NAVEKF2_AVAILABLE=1')936except ValueError:937pass938env.CXXFLAGS += ['-DHAL_NAVEKF2_AVAILABLE=0']939940class sitl_periph_universal(sitl_periph):941def configure_env(self, cfg, env):942super(sitl_periph_universal, self).configure_env(cfg, env)943env.DEFINES.update(944CAN_APP_NODE_NAME = '"org.ardupilot.ap_periph_universal"',945APJ_BOARD_ID = 100,946947HAL_PERIPH_ENABLE_GPS = 1,948HAL_PERIPH_ENABLE_AIRSPEED = 1,949HAL_PERIPH_ENABLE_MAG = 1,950HAL_PERIPH_ENABLE_BARO = 1,951HAL_PERIPH_ENABLE_IMU = 1,952HAL_PERIPH_ENABLE_RANGEFINDER = 1,953HAL_PERIPH_ENABLE_BATTERY = 1,954HAL_PERIPH_ENABLE_EFI = 1,955HAL_PERIPH_ENABLE_RPM = 1,956HAL_PERIPH_ENABLE_RPM_STREAM = 1,957HAL_PERIPH_ENABLE_RC_OUT = 1,958HAL_PERIPH_ENABLE_ADSB = 1,959HAL_PERIPH_ENABLE_SERIAL_OPTIONS = 1,960AP_AIRSPEED_ENABLED = 1,961AP_BATTERY_ESC_ENABLED = 1,962HAL_PWM_COUNT = 32,963HAL_WITH_ESC_TELEM = 1,964AP_EXTENDED_ESC_TELEM_ENABLED = 1,965AP_TERRAIN_AVAILABLE = 1,966HAL_GYROFFT_ENABLED = 0,967)968969class sitl_periph_gps(sitl_periph):970def configure_env(self, cfg, env):971cfg.env.AP_PERIPH = 1972super(sitl_periph_gps, self).configure_env(cfg, env)973env.DEFINES.update(974HAL_BUILD_AP_PERIPH = 1,975PERIPH_FW = 1,976CAN_APP_NODE_NAME = '"org.ardupilot.ap_periph_gps"',977APJ_BOARD_ID = 101,978979HAL_PERIPH_ENABLE_GPS = 1,980)981982class sitl_periph_battmon(sitl_periph):983def configure_env(self, cfg, env):984cfg.env.AP_PERIPH = 1985super(sitl_periph_battmon, self).configure_env(cfg, env)986env.DEFINES.update(987HAL_BUILD_AP_PERIPH = 1,988PERIPH_FW = 1,989CAN_APP_NODE_NAME = '"org.ardupilot.ap_periph_battmon"',990APJ_BOARD_ID = 101,991992HAL_PERIPH_ENABLE_BATTERY = 1,993)994995class esp32(Board):996abstract = True997toolchain = 'xtensa-esp32-elf'998def configure_env(self, cfg, env):999env.BOARD_CLASS = "ESP32"10001001def expand_path(p):1002print("USING EXPRESSIF IDF:"+str(env.idf))1003return cfg.root.find_dir(env.IDF+p).abspath()1004try:1005env.IDF = os.environ['IDF_PATH']1006except:1007env.IDF = cfg.srcnode.abspath()+"/modules/esp_idf"10081009super(esp32, self).configure_env(cfg, env)1010cfg.load('esp32')1011env.DEFINES.update(1012CONFIG_HAL_BOARD = 'HAL_BOARD_ESP32',1013)10141015tt = self.name[5:] #leave off 'esp32' so we just get 'buzz','diy','icarus, etc10161017# this makes sure we get the correct subtype1018env.DEFINES.update(1019CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_ESP32_%s' % tt.upper() ,1020)10211022if self.name.endswith("empty"):1023# for empty targets build as SIM-on-HW1024env.DEFINES.update(AP_SIM_ENABLED = 1)1025env.AP_LIBRARIES += [1026'SITL',1027]1028else:1029env.DEFINES.update(AP_SIM_ENABLED = 0)10301031# FreeRTOS component from esp-idf expects this define1032env.DEFINES.update(ESP_PLATFORM = 1)10331034env.AP_LIBRARIES += [1035'AP_HAL_ESP32',1036]10371038env.CFLAGS += [1039'-fno-inline-functions',1040'-mlongcalls',1041'-fsingle-precision-constant',1042]1043env.CFLAGS.remove('-Werror=undef')10441045env.CXXFLAGS += ['-mlongcalls',1046'-Os',1047'-g',1048'-ffunction-sections',1049'-fdata-sections',1050'-fno-exceptions',1051'-fno-rtti',1052'-nostdlib',1053'-fstrict-volatile-bitfields',1054'-Wno-sign-compare',1055'-fno-inline-functions',1056'-mlongcalls',1057'-fsingle-precision-constant', # force const vals to be float , not double. so 100.0 means 100.0f1058'-fno-threadsafe-statics']1059env.CXXFLAGS.remove('-Werror=undef')1060env.CXXFLAGS.remove('-Werror=shadow')10611062# wrap malloc to ensure memory is zeroed1063env.LINKFLAGS += ['-Wl,--wrap,malloc']10641065# TODO: remove once hwdef.dat support is in place1066defaults_file = 'libraries/AP_HAL_ESP32/hwdef/%s/defaults.parm' % self.get_name()1067if os.path.exists(defaults_file):1068env.ROMFS_FILES += [('defaults.parm', defaults_file)]1069env.DEFINES.update(1070HAL_PARAM_DEFAULTS_PATH='"@ROMFS/defaults.parm"',1071)10721073env.INCLUDES += [1074cfg.srcnode.find_dir('libraries/AP_HAL_ESP32/boards').abspath(),1075]1076env.AP_PROGRAM_AS_STLIB = True1077#if cfg.options.enable_profile:1078# env.CXXFLAGS += ['-pg',1079# '-DENABLE_PROFILE=1']1080def pre_build(self, bld):1081'''pre-build hook that gets called before dynamic sources'''1082from waflib.Context import load_tool1083module = load_tool('esp32', [], with_sys_path=True)1084fun = getattr(module, 'pre_build', None)1085if fun:1086fun(bld)1087super(esp32, self).pre_build(bld)108810891090def build(self, bld):1091super(esp32, self).build(bld)1092bld.load('esp32')10931094def get_name(self):1095return self.__class__.__name__10961097class esp32s3(esp32):1098abstract = True1099toolchain = 'xtensa-esp32s3-elf'11001101class chibios(Board):1102abstract = True1103toolchain = 'arm-none-eabi'11041105def configure_env(self, cfg, env):1106if hasattr(self, 'hwdef'):1107cfg.env.HWDEF = self.hwdef1108super(chibios, self).configure_env(cfg, env)11091110cfg.load('chibios')1111env.BOARD = self.name1112env.BOARD_CLASS = "ChibiOS"11131114env.DEFINES.update(1115CONFIG_HAL_BOARD = 'HAL_BOARD_CHIBIOS',1116HAVE_STD_NULLPTR_T = 0,1117USE_LIBC_REALLOC = 0,1118)11191120env.AP_LIBRARIES += [1121'AP_HAL_ChibiOS',1122]11231124# make board name available for USB IDs1125env.CHIBIOS_BOARD_NAME = 'HAL_BOARD_NAME="%s"' % self.name1126env.HAL_MAX_STACK_FRAME_SIZE = 'HAL_MAX_STACK_FRAME_SIZE=%d' % 1300 # set per Wframe-larger-than, ensure its same1127env.CFLAGS += cfg.env.CPU_FLAGS + [1128'-Wlogical-op',1129'-Wframe-larger-than=1300',1130'-Wno-attributes',1131'-fno-exceptions',1132'-Wall',1133'-Wextra',1134'-Wno-sign-compare',1135'-Wfloat-equal',1136'-Wpointer-arith',1137'-Wmissing-declarations',1138'-Wno-unused-parameter',1139'-Werror=array-bounds',1140'-Wfatal-errors',1141'-Werror=uninitialized',1142'-Werror=init-self',1143'-Werror=unused-but-set-variable',1144'-Wno-missing-field-initializers',1145'-Wno-trigraphs',1146'-fno-strict-aliasing',1147'-fomit-frame-pointer',1148'-falign-functions=16',1149'-ffunction-sections',1150'-fdata-sections',1151'-fno-strength-reduce',1152'-fno-builtin-printf',1153'-fno-builtin-fprintf',1154'-fno-builtin-vprintf',1155'-fno-builtin-vfprintf',1156'-fno-builtin-puts',1157'-mno-thumb-interwork',1158'-mthumb',1159'--specs=nano.specs',1160'--specs=nosys.specs',1161'-D__USE_CMSIS',1162'-Werror=deprecated-declarations',1163'-DNDEBUG=1'1164]1165if not cfg.options.Werror:1166env.CFLAGS += [1167'-Wno-error=double-promotion',1168'-Wno-error=missing-declarations',1169'-Wno-error=float-equal',1170'-Wno-error=cpp',1171]11721173env.CXXFLAGS += env.CFLAGS + [1174'-fno-rtti',1175'-fno-threadsafe-statics',1176]1177env.CFLAGS += [1178'-std=c11'1179]11801181if Utils.unversioned_sys_platform() == 'cygwin':1182env.CXXFLAGS += ['-DCYGWIN_BUILD']11831184bldnode = cfg.bldnode.make_node(self.name)1185env.BUILDROOT = bldnode.make_node('').abspath()11861187env.LINKFLAGS = cfg.env.CPU_FLAGS + [1188'-fomit-frame-pointer',1189'-falign-functions=16',1190'-ffunction-sections',1191'-fdata-sections',1192'-u_port_lock',1193'-u_port_unlock',1194'-u_exit',1195'-u_kill',1196'-u_getpid',1197'-u_errno',1198'-uchThdExit',1199'-fno-common',1200'-nostartfiles',1201'-mno-thumb-interwork',1202'-mthumb',1203'--specs=nano.specs',1204'--specs=nosys.specs',1205'-L%s' % env.BUILDROOT,1206'-L%s' % cfg.srcnode.make_node('modules/ChibiOS/os/common/startup/ARMCMx/compilers/GCC/ld/').abspath(),1207'-L%s' % cfg.srcnode.make_node('libraries/AP_HAL_ChibiOS/hwdef/common/').abspath(),1208'-Wl,-Map,Linker.map,%s--cref,--gc-sections,--no-warn-mismatch,--library-path=/ld,--script=ldscript.ld,--defsym=__process_stack_size__=%s,--defsym=__main_stack_size__=%s' % ("--print-memory-usage," if cfg.env.EXT_FLASH_SIZE_MB > 0 and cfg.env.INT_FLASH_PRIMARY == 0 else "", cfg.env.PROCESS_STACK, cfg.env.MAIN_STACK)1209]12101211if cfg.env.DEBUG:1212env.CFLAGS += [1213'-gdwarf-4',1214'-g3',1215]1216env.LINKFLAGS += [1217'-gdwarf-4',1218'-g3',1219]12201221if cfg.env.COMPILER_CXX == "g++":1222if not self.cc_version_gte(cfg, 10, 2):1223# require at least 10.2 compiler1224cfg.fatal("ChibiOS build requires g++ version 10.2.1 or later, found %s" % '.'.join(cfg.env.CC_VERSION))12251226if cfg.env.ENABLE_ASSERTS:1227cfg.msg("Enabling ChibiOS asserts", "yes")1228env.CFLAGS += [ '-DHAL_CHIBIOS_ENABLE_ASSERTS' ]1229env.CXXFLAGS += [ '-DHAL_CHIBIOS_ENABLE_ASSERTS' ]1230else:1231cfg.msg("Enabling ChibiOS asserts", "no")123212331234if cfg.env.SAVE_TEMPS:1235env.CXXFLAGS += [ '-S', '-save-temps=obj' ]12361237if cfg.options.disable_watchdog:1238cfg.msg("Disabling Watchdog", "yes")1239env.CFLAGS += [ '-DDISABLE_WATCHDOG' ]1240env.CXXFLAGS += [ '-DDISABLE_WATCHDOG' ]1241else:1242cfg.msg("Disabling Watchdog", "no")12431244if cfg.env.ENABLE_MALLOC_GUARD:1245cfg.msg("Enabling malloc guard", "yes")1246env.CFLAGS += [ '-DHAL_CHIBIOS_ENABLE_MALLOC_GUARD' ]1247env.CXXFLAGS += [ '-DHAL_CHIBIOS_ENABLE_MALLOC_GUARD' ]1248else:1249cfg.msg("Enabling malloc guard", "no")12501251if cfg.env.ENABLE_STATS:1252cfg.msg("Enabling ChibiOS thread statistics", "yes")1253env.CFLAGS += [ '-DHAL_ENABLE_THREAD_STATISTICS' ]1254env.CXXFLAGS += [ '-DHAL_ENABLE_THREAD_STATISTICS' ]1255else:1256cfg.msg("Enabling ChibiOS thread statistics", "no")12571258if cfg.env.SIM_ENABLED:1259env.DEFINES.update(1260AP_SIM_ENABLED = 1,1261)1262env.AP_LIBRARIES += [1263'SITL',1264]1265else:1266env.DEFINES.update(1267AP_SIM_ENABLED = 0,1268)12691270env.LIB += ['gcc', 'm']12711272env.GIT_SUBMODULES += [1273'ChibiOS',1274]12751276env.INCLUDES += [1277cfg.srcnode.find_dir('libraries/AP_GyroFFT/CMSIS_5/include').abspath(),1278cfg.srcnode.find_dir('modules/lwip/src/include/compat/posix').abspath()1279]12801281# whitelist of compilers which we should build with -Werror1282gcc_whitelist = frozenset([1283('4','9','3'),1284('6','3','1'),1285('9','2','1'),1286('9','3','1'),1287('10','2','1'),1288('11','3','0'),1289('11','4','0'),1290])12911292if cfg.env.HAL_CANFD_SUPPORTED:1293env.DEFINES.update(CANARD_ENABLE_CANFD=1)1294else:1295env.DEFINES.update(CANARD_ENABLE_TAO_OPTION=1)1296if not cfg.options.bootloader and cfg.env.HAL_NUM_CAN_IFACES:1297if int(cfg.env.HAL_NUM_CAN_IFACES) >= 1:1298env.DEFINES.update(CANARD_IFACE_ALL=(1<<int(cfg.env.HAL_NUM_CAN_IFACES))-1)1299if cfg.options.Werror or cfg.env.CC_VERSION in gcc_whitelist:1300cfg.msg("Enabling -Werror", "yes")1301if '-Werror' not in env.CXXFLAGS:1302env.CXXFLAGS += [ '-Werror' ]1303else:1304cfg.msg("Enabling -Werror", "no")13051306if cfg.options.signed_fw:1307cfg.define('AP_SIGNED_FIRMWARE', 1)1308env.CFLAGS += [1309'-DAP_SIGNED_FIRMWARE=1',1310]1311else:1312cfg.define('AP_SIGNED_FIRMWARE', 0)1313env.CFLAGS += [1314'-DAP_SIGNED_FIRMWARE=0',1315]13161317try:1318import intelhex1319env.HAVE_INTEL_HEX = True1320cfg.msg("Checking for intelhex module:", 'OK')1321except Exception:1322cfg.msg("Checking for intelhex module:", 'disabled', color='YELLOW')1323env.HAVE_INTEL_HEX = False13241325if cfg.options.enable_new_checking:1326env.CHECK_SYMBOLS = True1327else:1328# disable new checking on ChibiOS by default to save flash1329# we enable it in a CI test to catch incorrect usage1330env.CXXFLAGS += [1331"-DNEW_NOTHROW=new",1332"-fcheck-new", # rely on -fcheck-new ensuring nullptr checks1333]13341335def build(self, bld):1336super(chibios, self).build(bld)1337bld.ap_version_append_str('CHIBIOS_GIT_VERSION', bld.git_submodule_head_hash('ChibiOS', short=True))1338bld.load('chibios')13391340def pre_build(self, bld):1341'''pre-build hook that gets called before dynamic sources'''1342from waflib.Context import load_tool1343module = load_tool('chibios', [], with_sys_path=True)1344fun = getattr(module, 'pre_build', None)1345if fun:1346fun(bld)1347super(chibios, self).pre_build(bld)13481349def get_name(self):1350return self.name13511352class linux(Board):1353def __init__(self):1354if self.toolchain == 'native':1355self.with_can = True1356else:1357self.with_can = False13581359def configure_env(self, cfg, env):1360if cfg.options.board == 'linux':1361self.with_can = True1362super(linux, self).configure_env(cfg, env)13631364env.BOARD_CLASS = "LINUX"13651366env.DEFINES.update(1367CONFIG_HAL_BOARD = 'HAL_BOARD_LINUX',1368CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_NONE',1369AP_SIM_ENABLED = 0,1370)13711372if not cfg.env.DEBUG:1373env.CXXFLAGS += [1374'-O3',1375]13761377env.LIB += [1378'm',1379]13801381cfg.check_librt(env)1382cfg.check_lttng(env)1383cfg.check_libdl(env)1384cfg.check_libiio(env)13851386env.LINKFLAGS += ['-pthread',]1387env.AP_LIBRARIES += [1388'AP_HAL_Linux',1389]13901391# wrap malloc to ensure memory is zeroed1392# note that this also needs to be done in the CMakeLists.txt files1393env.LINKFLAGS += ['-Wl,--wrap,malloc']13941395if cfg.options.force_32bit:1396env.DEFINES.update(1397HAL_FORCE_32BIT = 1,1398)1399# 32bit platform flags1400cfg.env.CXXFLAGS += [1401'-m32',1402]1403cfg.env.CFLAGS += [1404'-m32',1405]1406cfg.env.LDFLAGS += [1407'-m32',1408]1409else:1410env.DEFINES.update(1411HAL_FORCE_32BIT = 0,1412)1413if self.with_can and cfg.options.board == 'linux':1414cfg.env.HAL_NUM_CAN_IFACES = 21415cfg.define('HAL_NUM_CAN_IFACES', 2)1416cfg.define('HAL_CANFD_SUPPORTED', 1)1417cfg.define('CANARD_ENABLE_CANFD', 1)14181419if self.with_can:1420env.DEFINES.update(CANARD_MULTI_IFACE=1,1421CANARD_IFACE_ALL = 0x3)14221423if cfg.options.apstatedir:1424cfg.define('AP_STATEDIR', cfg.options.apstatedir)14251426defaults_file = 'libraries/AP_HAL_Linux/boards/%s/defaults.parm' % self.get_name()1427if os.path.exists(defaults_file):1428env.ROMFS_FILES += [('defaults.parm', defaults_file)]1429env.DEFINES.update(1430HAL_PARAM_DEFAULTS_PATH='"@ROMFS/defaults.parm"',1431)14321433def build(self, bld):1434super(linux, self).build(bld)1435if bld.options.upload:1436waflib.Options.commands.append('rsync')1437# Avoid infinite recursion1438bld.options.upload = False14391440def get_name(self):1441# get name of class1442return self.__class__.__name__144314441445class navigator(linux):1446toolchain = 'arm-linux-gnueabihf'14471448def configure_env(self, cfg, env):1449super(navigator, self).configure_env(cfg, env)14501451env.DEFINES.update(1452CONFIG_HAL_BOARD_SUBTYPE='HAL_BOARD_SUBTYPE_LINUX_NAVIGATOR',1453)14541455class navigator64(linux):1456toolchain = 'aarch64-linux-gnu'14571458def configure_env(self, cfg, env):1459super(navigator64, self).configure_env(cfg, env)14601461env.DEFINES.update(1462CONFIG_HAL_BOARD_SUBTYPE='HAL_BOARD_SUBTYPE_LINUX_NAVIGATOR',1463)146414651466class erleboard(linux):1467toolchain = 'arm-linux-gnueabihf'14681469def configure_env(self, cfg, env):1470super(erleboard, self).configure_env(cfg, env)14711472env.DEFINES.update(1473CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_ERLEBOARD',1474)14751476class navio(linux):1477toolchain = 'arm-linux-gnueabihf'14781479def configure_env(self, cfg, env):1480super(navio, self).configure_env(cfg, env)14811482env.DEFINES.update(1483CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_NAVIO',1484)14851486class navio2(linux):1487toolchain = 'arm-linux-gnueabihf'14881489def configure_env(self, cfg, env):1490super(navio2, self).configure_env(cfg, env)14911492env.DEFINES.update(1493CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_NAVIO2',1494)14951496class edge(linux):1497toolchain = 'arm-linux-gnueabihf'14981499def __init__(self):1500self.with_can = True15011502def configure_env(self, cfg, env):1503super(edge, self).configure_env(cfg, env)15041505env.DEFINES.update(1506CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_EDGE',1507)15081509class zynq(linux):1510toolchain = 'arm-xilinx-linux-gnueabi'15111512def configure_env(self, cfg, env):1513super(zynq, self).configure_env(cfg, env)15141515env.DEFINES.update(1516CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_ZYNQ',1517)15181519class ocpoc_zynq(linux):1520toolchain = 'arm-linux-gnueabihf'15211522def configure_env(self, cfg, env):1523super(ocpoc_zynq, self).configure_env(cfg, env)15241525env.DEFINES.update(1526CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_OCPOC_ZYNQ',1527)15281529class bbbmini(linux):1530toolchain = 'arm-linux-gnueabihf'15311532def __init__(self):1533self.with_can = True15341535def configure_env(self, cfg, env):1536super(bbbmini, self).configure_env(cfg, env)1537cfg.env.HAL_NUM_CAN_IFACES = 11538env.DEFINES.update(1539CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_BBBMINI',1540)15411542class blue(linux):1543toolchain = 'arm-linux-gnueabihf'15441545def __init__(self):1546self.with_can = True15471548def configure_env(self, cfg, env):1549super(blue, self).configure_env(cfg, env)1550cfg.env.HAL_NUM_CAN_IFACES = 115511552env.DEFINES.update(1553CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_BLUE',1554)15551556class pocket(linux):1557toolchain = 'arm-linux-gnueabihf'15581559def __init__(self):1560self.with_can = True15611562def configure_env(self, cfg, env):1563super(pocket, self).configure_env(cfg, env)1564cfg.env.HAL_NUM_CAN_IFACES = 115651566env.DEFINES.update(1567CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_POCKET',1568)15691570class pxf(linux):1571toolchain = 'arm-linux-gnueabihf'15721573def configure_env(self, cfg, env):1574super(pxf, self).configure_env(cfg, env)15751576env.DEFINES.update(1577CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_PXF',1578)15791580class bebop(linux):1581toolchain = 'arm-linux-gnueabihf'15821583def configure_env(self, cfg, env):1584super(bebop, self).configure_env(cfg, env)15851586env.DEFINES.update(1587CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_BEBOP',1588)15891590class vnav(linux):1591toolchain = 'arm-linux-gnueabihf'15921593def configure_env(self, cfg, env):1594super(vnav, self).configure_env(cfg, env)15951596env.DEFINES.update(1597CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_VNAV',1598)15991600class disco(linux):1601toolchain = 'arm-linux-gnueabihf'16021603def configure_env(self, cfg, env):1604super(disco, self).configure_env(cfg, env)16051606env.DEFINES.update(1607CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_DISCO',1608)16091610class erlebrain2(linux):1611toolchain = 'arm-linux-gnueabihf'16121613def configure_env(self, cfg, env):1614super(erlebrain2, self).configure_env(cfg, env)16151616env.DEFINES.update(1617CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_ERLEBRAIN2',1618)16191620class bhat(linux):1621toolchain = 'arm-linux-gnueabihf'16221623def configure_env(self, cfg, env):1624super(bhat, self).configure_env(cfg, env)16251626env.DEFINES.update(1627CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_BH',1628)16291630class dark(linux):1631toolchain = 'arm-linux-gnueabihf'16321633def configure_env(self, cfg, env):1634super(dark, self).configure_env(cfg, env)16351636env.DEFINES.update(1637CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_DARK',1638)16391640class pxfmini(linux):1641toolchain = 'arm-linux-gnueabihf'16421643def configure_env(self, cfg, env):1644super(pxfmini, self).configure_env(cfg, env)16451646env.DEFINES.update(1647CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_PXFMINI',1648)16491650class aero(linux):1651def __init__(self):1652self.with_can = True16531654def configure_env(self, cfg, env):1655super(aero, self).configure_env(cfg, env)16561657env.DEFINES.update(1658CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_AERO',1659)16601661class rst_zynq(linux):1662toolchain = 'arm-linux-gnueabihf'16631664def configure_env(self, cfg, env):1665super(rst_zynq, self).configure_env(cfg, env)16661667env.DEFINES.update(1668CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_RST_ZYNQ',1669)16701671class obal(linux):1672toolchain = 'arm-linux-gnueabihf'16731674def configure_env(self, cfg, env):1675super(obal, self).configure_env(cfg, env)16761677env.DEFINES.update(1678CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_OBAL_V1',1679)16801681class canzero(linux):1682toolchain = 'arm-linux-gnueabihf'16831684def __init__(self):1685self.with_can = True16861687def configure_env(self, cfg, env):1688super(canzero, self).configure_env(cfg, env)16891690env.DEFINES.update(1691CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_CANZERO',1692)16931694class SITL_static(sitl):1695def configure_env(self, cfg, env):1696super(SITL_static, self).configure_env(cfg, env)1697cfg.env.STATIC_LINKING = True16981699class SITL_x86_64_linux_gnu(SITL_static):1700toolchain = 'x86_64-linux-gnu'17011702class SITL_arm_linux_gnueabihf(SITL_static):1703toolchain = 'arm-linux-gnueabihf'17041705class QURT(Board):1706'''support for QURT based boards'''1707toolchain = 'custom'17081709def __init__(self):1710self.with_can = False17111712def configure_toolchain(self, cfg):1713cfg.env.CXX_NAME = 'gcc'1714cfg.env.HEXAGON_SDK_DIR = "/opt/hexagon-sdk/4.1.0.4-lite"1715cfg.env.CC_VERSION = ('4','1','0')1716cfg.env.TOOLCHAIN_DIR = cfg.env.HEXAGON_SDK_DIR + "/tools/HEXAGON_Tools/8.4.05/Tools"1717cfg.env.COMPILER_CC = cfg.env.TOOLCHAIN_DIR + "/bin/hexagon-clang"1718cfg.env.COMPILER_CXX = cfg.env.TOOLCHAIN_DIR + "/bin/hexagon-clang++"1719cfg.env.LINK_CXX = cfg.env.HEXAGON_SDK_DIR + "/tools/HEXAGON_Tools/8.4.05/Tools/bin/hexagon-link"1720cfg.env.CXX = ["ccache", cfg.env.COMPILER_CXX]1721cfg.env.CC = ["ccache", cfg.env.COMPILER_CC]1722cfg.env.CXX_TGT_F = ['-c', '-o']1723cfg.env.CC_TGT_F = ['-c', '-o']1724cfg.env.CCLNK_SRC_F = []1725cfg.env.CXXLNK_SRC_F = []1726cfg.env.CXXLNK_TGT_F = ['-o']1727cfg.env.CCLNK_TGT_F = ['-o']1728cfg.env.CPPPATH_ST = '-I%s'1729cfg.env.DEFINES_ST = '-D%s'1730cfg.env.AR = cfg.env.HEXAGON_SDK_DIR + "/tools/HEXAGON_Tools/8.4.05/Tools/bin/hexagon-ar"1731cfg.env.ARFLAGS = 'rcs'1732cfg.env.cxxstlib_PATTERN = 'lib%s.a'1733cfg.env.cstlib_PATTERN = 'lib%s.a'1734cfg.env.LIBPATH_ST = '-L%s'1735cfg.env.LIB_ST = '-l%s'1736cfg.env.SHLIB_MARKER = ''1737cfg.env.STLIBPATH_ST = '-L%s'1738cfg.env.STLIB_MARKER = ''1739cfg.env.STLIB_ST = '-l%s'1740cfg.env.LDFLAGS = [1741'-lgcc',1742cfg.env.TOOLCHAIN_DIR + '/target/hexagon/lib/v66/G0/pic/finiS.o'1743]17441745def configure_env(self, cfg, env):1746super(QURT, self).configure_env(cfg, env)17471748env.BOARD_CLASS = "QURT"1749env.HEXAGON_APP = "libardupilot.so"1750env.INCLUDES += [cfg.env.HEXAGON_SDK_DIR + "/rtos/qurt/computev66/include/qurt"]1751env.INCLUDES += [cfg.env.HEXAGON_SDK_DIR + "/rtos/qurt/computev66/include/posix"]17521753CFLAGS = "-MD -mv66 -fPIC -mcpu=hexagonv66 -G0 -fdata-sections -ffunction-sections -fomit-frame-pointer -fmerge-all-constants -fno-signed-zeros -fno-trapping-math -freciprocal-math -fno-math-errno -fno-strict-aliasing -fvisibility=hidden -fno-rtti -fmath-errno"1754env.CXXFLAGS += CFLAGS.split()1755env.CFLAGS += CFLAGS.split()17561757env.DEFINES.update(1758CONFIG_HAL_BOARD = 'HAL_BOARD_QURT',1759CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_NONE',1760AP_SIM_ENABLED = 0,1761)17621763env.LINKFLAGS = [1764"-march=hexagon",1765"-mcpu=hexagonv66",1766"-shared",1767"-call_shared",1768"-G0",1769cfg.env.TOOLCHAIN_DIR + "/target/hexagon/lib/v66/G0/pic/initS.o",1770f"-L{cfg.env.TOOLCHAIN_DIR}/target/hexagon/lib/v66/G0/pic",1771"-Bsymbolic",1772cfg.env.TOOLCHAIN_DIR + "/target/hexagon/lib/v66/G0/pic/libgcc.a",1773"--wrap=malloc",1774"--wrap=calloc",1775"--wrap=free",1776"--wrap=realloc",1777"--wrap=printf",1778"--wrap=strdup",1779"--wrap=__stack_chk_fail",1780"-lc"1781]17821783if not cfg.env.DEBUG:1784env.CXXFLAGS += [1785'-O3',1786]17871788env.AP_LIBRARIES += [1789'AP_HAL_QURT',1790]17911792def build(self, bld):1793super(QURT, self).build(bld)1794bld.load('qurt')17951796def get_name(self):1797# get name of class1798return self.__class__.__name__1799180018011802