3 Replies Latest reply on Dec 21, 2016 9:50 PM by hima

    Sharing Function / Variable between bootloader and application

    jonathan_1936891

      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!