You are here

Sharing Function / Variable between bootloader and application | Cypress Semiconductor

Sharing Function / Variable between bootloader and application

Summary: 2 Replies, Latest post by Jonathan on 04 Nov 2016 09:24 AM PDT
Verified Answers: 0
Last post
Log in to post new comments.
Jonathan's picture
User
8 posts

I've got a project which includes separate OTA bootloader (Fixed Stack) and bootloadable / application code. I'm trying to implement some mechanism such that the application code can know the version of the bootloader code that's on the device.

Inside the OTA bootloader code, I've added the following code

In main.h

#define FIRMWARE_VERSION_MAJOR              0x00
#define FIRMWARE_VERSION_MINOR              0x01
#define FIRMWARE_VERSION_BUILD              0x02

typedef struct
{
    uint8         major;
    uint8         minor;
    uint8       build;

}BTL_FIRMWARE_VERSION;

In main.c

BTL_FIRMWARE_VERSION GetBootloaderVersion(void)
{
    BTL_FIRMWARE_VERSION bootloader_firmware;
    
    bootloader_firmware.major = FIRMWARE_VERSION_MAJOR;
    bootloader_firmware.minor = FIRMWARE_VERSION_MINOR;
    bootloader_firmware.build = FIRMWARE_VERSION_BUILD;
    
    return bootloader_firmware;
}

And then I've updated the linker file (cm0gcc.ld) to include the following two lines:

KEEP(*(i.GetBootloaderVersion*))

KEEP(*(.text.GetBootloaderVersion*))

After making those updates, I've compiled the bootloader project and run the mk.bat script without any problems/errors/warnings. Then I've updated my application code to include the following:

In the header file:

typedef struct
{
    uint8         major;
    uint8         minor;
    uint8       build;

}BTL_FIRMWARE_VERSION;

extern BTL_FIRMWARE_VERSION GetBootloaderVersion(void);

In the .c file

BTL_FIRMWARE_VERSION bootloader_firmware = GetBootloaderVersion();

However, when I compile the application code, I get an error on the line above in my .c file which states "Build error: undefined reference to 'GetBootloaderVersion'.

This leads me to believe that I am doing something wrong with the linker script and the function is getting optimized out of the bootloader, but I'm not sure what else I should try, as I'm having NO problem sharing all the relevant BLE stack functions between the bootloader and the application with the linker script in the same fashion.

Any insight or suggestions on how I can easily achieve this would be greatly appreciated! Thanks in advance!

HIMA's picture
Cypress Employee
203 posts

I just want to check if you can attach the project.

 

Thanks,

Hima

Jonathan's picture
User
8 posts

Hello Hima,

I can share the project with you directly, as you are a Cypress Employee, however I am not able to post it to the public forum for everyone to have access to. Please let me know the best way to share the project with you. Thanks!

-Jonathan

Log in to post new comments.