diff --git a/Tools/ardupilotwaf/boards.py b/Tools/ardupilotwaf/boards.py index a1f3c46a5e..4f96db0f46 100644 --- a/Tools/ardupilotwaf/boards.py +++ b/Tools/ardupilotwaf/boards.py @@ -253,6 +253,10 @@ class Board: if cfg.options.bootloader: # don't let bootloaders try and pull scripting in cfg.options.disable_scripting = True + if cfg.options.signed_fw: + env.DEFINES.update( + ENABLE_HEAP = 1, + ) else: env.DEFINES.update( ENABLE_HEAP = 1, @@ -576,6 +580,7 @@ class sitl(Board): cfg.define('HAL_WITH_RAMTRON', 1) cfg.define('AP_GENERATOR_RICHENPOWER_ENABLED', 1) cfg.define('AP_OPENDRONEID_ENABLED', 1) + cfg.define('AP_SIGNED_FIRMWARE', 0) if self.with_can: cfg.define('HAL_NUM_CAN_IFACES', 2) @@ -1011,6 +1016,17 @@ class chibios(Board): else: cfg.msg("Enabling -Werror", "no") + if cfg.options.signed_fw: + cfg.define('AP_SIGNED_FIRMWARE', 1) + env.CFLAGS += [ + '-DAP_SIGNED_FIRMWARE=1', + ] + else: + cfg.define('AP_SIGNED_FIRMWARE', 0) + env.CFLAGS += [ + '-DAP_SIGNED_FIRMWARE=0', + ] + try: import intelhex env.HAVE_INTEL_HEX = True diff --git a/Tools/ardupilotwaf/chibios.py b/Tools/ardupilotwaf/chibios.py index 57bad93463..c49068e078 100644 --- a/Tools/ardupilotwaf/chibios.py +++ b/Tools/ardupilotwaf/chibios.py @@ -236,7 +236,11 @@ class set_app_descriptor(Task.Task): def keyword(self): return "app_descriptor" def run(self): - descriptor = b'\x40\xa2\xe4\xf1\x64\x68\x91\x06' + if self.generator.bld.env.AP_SIGNED_FIRMWARE: + descriptor = b'\x41\xa3\xe5\xf2\x65\x69\x92\x07' + else: + descriptor = b'\x40\xa2\xe4\xf1\x64\x68\x91\x06' + img = open(self.inputs[0].abspath(), 'rb').read() offset = img.find(descriptor) if offset == -1: @@ -251,11 +255,17 @@ class set_app_descriptor(Task.Task): upload_tools = self.env.get_flat('UPLOAD_TOOLS') sys.path.append(upload_tools) from uploader import crc32 - desc_len = 16 + if self.generator.bld.env.AP_SIGNED_FIRMWARE: + desc_len = 92 + else: + desc_len = 16 crc1 = to_unsigned(crc32(bytearray(img[:offset]))) crc2 = to_unsigned(crc32(bytearray(img[offset+desc_len:]))) githash = to_unsigned(int('0x' + os.environ.get('GIT_VERSION', self.generator.bld.git_head_hash(short=True)),16)) - desc = struct.pack('