waf: added --enable-check-firmware option

This commit is contained in:
Andrew Tridgell 2022-08-18 18:16:41 +10:00
parent 9734925b52
commit e3412f7352
4 changed files with 26 additions and 12 deletions

View File

@ -110,6 +110,7 @@ COMMON_VEHICLE_DEPENDENT_LIBRARIES = [
'AP_FETtecOneWire', 'AP_FETtecOneWire',
'AP_Torqeedo', 'AP_Torqeedo',
'AP_OpenDroneID', 'AP_OpenDroneID',
'AP_CheckFirmware',
] ]
def get_legacy_defines(sketch_name, bld): def get_legacy_defines(sketch_name, bld):

View File

@ -105,6 +105,16 @@ class Board:
else: else:
cfg.msg("Enabled OpenDroneID", 'no', color='YELLOW') cfg.msg("Enabled OpenDroneID", 'no', color='YELLOW')
# allow enable of firmware ID checking for any board
if cfg.options.enable_check_firmware:
env.CHECK_FIRMWARE_ENABLED = True
env.DEFINES.update(
AP_CHECK_FIRMWARE_ENABLED=1,
)
cfg.msg("Enabled firmware ID checking", 'yes')
else:
cfg.msg("Enabled firmware ID checking", 'no', color='YELLOW')
d = env.get_merged_dict() d = env.get_merged_dict()
# Always prepend so that arguments passed in the command line get # Always prepend so that arguments passed in the command line get
# the priority. # the priority.

View File

@ -237,17 +237,11 @@ class set_app_descriptor(Task.Task):
def keyword(self): def keyword(self):
return "app_descriptor" return "app_descriptor"
def run(self): def run(self):
if not 'APP_DESCRIPTOR' in self.env: descriptor = b'\x40\xa2\xe4\xf1\x64\x68\x91\x06'
return
if self.env.APP_DESCRIPTOR == 'MissionPlanner':
descriptor = b'\x40\xa2\xe4\xf1\x64\x68\x91\x06'
else:
Logs.error("Bad APP_DESCRIPTOR %s" % self.env.APP_DESCRIPTOR)
return
img = open(self.inputs[0].abspath(), 'rb').read() img = open(self.inputs[0].abspath(), 'rb').read()
offset = img.find(descriptor) offset = img.find(descriptor)
if offset == -1: if offset == -1:
Logs.error("Failed to find %s APP_DESCRIPTOR" % self.env.APP_DESCRIPTOR) Logs.info("No APP_DESCRIPTOR found")
return return
offset += 8 offset += 8
# next 8 bytes is 64 bit CRC. We set first 4 bytes to # next 8 bytes is 64 bit CRC. We set first 4 bytes to
@ -264,7 +258,7 @@ class set_app_descriptor(Task.Task):
githash = to_unsigned(int('0x' + os.environ.get('GIT_VERSION', self.generator.bld.git_head_hash(short=True)),16)) githash = to_unsigned(int('0x' + os.environ.get('GIT_VERSION', self.generator.bld.git_head_hash(short=True)),16))
desc = struct.pack('<IIII', crc1, crc2, len(img), githash) desc = struct.pack('<IIII', crc1, crc2, len(img), githash)
img = img[:offset] + desc + img[offset+desc_len:] img = img[:offset] + desc + img[offset+desc_len:]
Logs.info("Applying %s APP_DESCRIPTOR %08x%08x" % (self.env.APP_DESCRIPTOR, crc1, crc2)) Logs.info("Applying APP_DESCRIPTOR %08x%08x" % (crc1, crc2))
open(self.inputs[0].abspath(), 'wb').write(img) open(self.inputs[0].abspath(), 'wb').write(img)
class generate_apj(Task.Task): class generate_apj(Task.Task):
@ -388,12 +382,17 @@ def chibios_firmware(self):
default_params_task.set_run_after(self.link_task) default_params_task.set_run_after(self.link_task)
generate_bin_task.set_run_after(default_params_task) generate_bin_task.set_run_after(default_params_task)
if self.env.APP_DESCRIPTOR: # we need to setup the app descriptor so the bootloader can validate the firmware
if not self.bld.env.BOOTLOADER:
app_descriptor_task = self.create_task('set_app_descriptor', src=bin_target) app_descriptor_task = self.create_task('set_app_descriptor', src=bin_target)
app_descriptor_task.set_run_after(generate_bin_task) app_descriptor_task.set_run_after(generate_bin_task)
generate_apj_task.set_run_after(app_descriptor_task) generate_apj_task.set_run_after(app_descriptor_task)
if hex_task is not None: if hex_task is not None:
hex_task.set_run_after(app_descriptor_task) hex_task.set_run_after(app_descriptor_task)
else:
generate_apj_task.set_run_after(generate_bin_task)
if hex_task is not None:
hex_task.set_run_after(generate_bin_task)
if self.bld.options.upload: if self.bld.options.upload:
_upload_task = self.create_task('upload_fw', src=apj_target) _upload_task = self.create_task('upload_fw', src=apj_target)

View File

@ -229,6 +229,10 @@ submodules at specific revisions.
default=False, default=False,
help="Enables OpenDroneID") help="Enables OpenDroneID")
g.add_option('--enable-check-firmware', action='store_true',
default=False,
help="Enables firmware ID checking on boot")
g = opt.ap_groups['linux'] g = opt.ap_groups['linux']
linux_options = ('--prefix', '--destdir', '--bindir', '--libdir') linux_options = ('--prefix', '--destdir', '--bindir', '--libdir')