Unmanaged bootloader broken in Mbed 5.11.2 (with possible fix)

29 Jan 2019

My custom bootloaders broke when I updated to Mbed 5.11.2. It looks like the target.app_offset option now sets up my bootloader to run at the app offset instead of the start of ROM. I was able to fix it by editing the _generate_bootloader_build function in tools/config/init.py . Under "if self.target.restrict_size is not None", the first few lines of code are:

new_size = int(self.target.restrict_size, 0)
new_size = Config._align_floor(start + new_size, self.sectors) - start

if self.target.app_offset:
    start = self._assign_new_offset(rom_start, start, self.target.app_offset, "application")

yield Region("application", start, new_size, True, None)

This seems to set the start address to the app offset when defining the application region. I moved the if statement further down the function, which fixed the problem:

if self.target.app_offset:
    start = self._assign_new_offset(rom_start, start, self.target.app_offset, "application")

yield Region("post_application", start, rom_end - start, False, None)

I'm not sure if this is the best fix, though. Is this a bug, or some intentional new behavior? I need to leave a few flash sectors between my bootloader and my application to store configuration data.