6 years, 1 month ago.

Bootloader with header file does not boot

I'm trying to get a super simple bootloader up and running but I'm having issues when I introduce the application bootloader header. I'm running on an LPC1768.

Basically, I'm following the steps laid out here: https://os.mbed.com/docs/v5.10/tutorials/bootloader.html

I've got my example blinky project as my main application and create a new project from scratch for the bootloader. For the bootloader, here is my main for the bootloader:

#include "mbed.h"
#include <stdio.h>

int main()
{
    printf("Starting application...");
    mbed_start_application(POST_APPLICATION_ADDR);
}

Here's the bootloader's mbed_app.json:

{
    "target_overrides": {
        "LPC1768": {
            "target.restrict_size" : "0x20000"
        }
    }
}

and here's the bootloader's AND application's mbed_lib.json - two different files but share the exact same data, as specified is required in the link above:

{
    "name": "application_header",
    "target_overrides": {
        "*": {
            "target.header_format": [
                ["magic", "const", "32be", "0x5a51b3d4"],
                ["headerVersion", "const", "32be", "2"],
                ["firmwareVersion", "timestamp", "64be", null],
                ["firmwareSize", "size", "64be", ["application"]],
                ["firmwareHash", "digest", "SHA256", "application"],
                ["headerCRC", "digest", "CRCITT32be", "header"]
            ]
        }
    }
}

And finally, here is the required line in my main application's mbed_app.json:

"LPC1768": {
            "target.bootloader_img": "../mbed_bootloader/BUILD/LPC1768/GCC_ARM/mbed_bootloader.bin"
        }

When I compile and flash the main application (which bundles in the bootloader) I don't see the printf in the bootloader application at all. It's as if its not run at all for some reason. Yet, it's worth noting that when I remove the header mbed_lib.json from both projects, the bootloader kicks in just fine and I not only see the printf but it then successfully loads in the blinky application.

Can anyone help me? Even any general insight on how and where the bootloader header is used would also probably be useful.

Okay so after researching this a bit more, I found the solution to my problem which - in retrospect - is pretty obvious. I'll post it in case anyone in the future runs into the same problem.

Basically, I was looking through the different configuration items here: https://os.mbed.com/docs/v5.10/tools/configuring-tools.html and came across this line:

"You are responsible for the alignment of this address with respect to the flash layout and vector table size of the MCU you are using. When not used in conjunction with target.mbed_app_size, the application being built uses the remainder of ROM."

So there you have it. The LPC1768 has - I believe - a 1024 byte flash page size, so you need to align the application to boot after the bootloader on one of those boundries. In my case, I added "target.app_offset" : "0x20400", to both the bootloader and main application's mbed_lib.json file and everything works again.

posted by Niall Begley 29 Oct 2018
Be the first to answer this question.