This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RM46L852: Attempting to use CAN Bootloader to Update the Bootloader itself cause a hang on flash erase.

Part Number: RM46L852

I am trying to update a boot loader using the boot loader itself. my code is based off the spna189.zip sample code. My bootloader can update the software after the boot loader with out any issue, but when i try to enable the bootloader update and update the bootloader itself the code crashes at the Erase step, I have updated the  sections code in the linker command as other articles have suggested, and changed the calls to Fapi_enableMainBankSectors(0xFFFF); 

What else could i be missing?

My linker file

/* Memory Map */

MEMORY
{
VECTORS (X) : origin=0x00000000 length=0x00000020
FLASH_API (RX) : origin=0x00000020 length=0x00003FE0
FLASHBOOT (RX) : origin=0x00012000 length=0x00012000
STACKS (RW) : origin=0x08000000 length=0x00002000
RAM (RW) : origin=0x08002000 length=0x0003E000

/* USER CODE BEGIN (2) */
// Provider configuration area in flash. Used to configure IP address,
// subnet mask, default gateway, MAC address, and device ID
// used by the bootloader.
PROVIDER_CFG_AND_STATUS (RW) : origin=0x00004000 length=0x00008000
/* USER CODE END */
}

/* USER CODE BEGIN (3) */
/* USER CODE END */


/*----------------------------------------------------------------------------*/
/* Section Configuration */


SECTIONS
{
.intvecs : {} > VECTORS
flashAPI :
{
../Debug_HDK/src/Fapi_UserDefinedFunctions.obj (.text)
../Debug_HDK/src/bl_flash.obj (.text)
../Debug_HDK/src/bl_dcan.obj (.text)
../Debug_HDK/src/bl_flash.obj (.const)
//../Debug_HDK/src/uartstdio.obj (.text)

--library= ../../lib/F021_API_CortexR4_LE.lib (.text)
} load = FLASH_API, run = RAM, LOAD_START(api_load), RUN_START(api_run), SIZE(api_size)
.text : {} > FLASHBOOT
.const : {} > FLASHBOOT
.cinit : {} > FLASHBOOT
.pinit : {} > FLASHBOOT
.bss : {} > RAM
.data : {} > RAM
.sysmem : {} > RAM

/* USER CODE BEGIN (4) */
/* USER CODE END */
}

  • Hello Casey,

    To update the bootloader itself, you have to copy the current bootloader to SRAM and execute it from SRAM. The example bootloader only copies the F021 flash APIs related function and variables to SRAM.

  • How would i do that? What do i have to do differently in my linker command file for that to work?

  • Hello,

    You need to modify your linker cmd file to define the load address and run address. Then copy those sections to RAM in main()

    1. Linker CMD file: 

    /* Section Configuration */
    SECTIONS
    {
    .intvecs : {} load=FLASH0, RUN=RAM, LOAD_START(load0), RUN_START(run0), SIZE(size0)
    .text : {} load=FLASH0, RUN=RAM, LOAD_START(load1), RUN_START(run1), SIZE(size1)
    .const : {} load=FLASH0, RUN=RAM, LOAD_START(load2), RUN_START(run2), SIZE(size2)
    .cinit : {} load=FLASH0, RUN=RAM, LOAD_START(load3), RUN_START(run3), SIZE(size3)
    .pinit : {} load=FLASH0, RUN=RAM, LOAD_START(load4), RUN_START(run4), SIZE(size4)

    .bss : {} > RAM
    .data : {} > RAM
    .sysmem : {} > RAM

    FEE_TEXT_SECTION : {} load=FLASH0, RUN=RAM, LOAD_START(load5), RUN_START(run5), SIZE(size5)
    FEE_CONST_SECTION : {} load=FLASH0, RUN=RAM, LOAD_START(load6), RUN_START(run6), SIZE(size6)
    FEE_DATA_SECTION : {} > RAM
    /* USER CODE BEGIN (4) */
    /* USER CODE END */
    }

    2. main()

    /* Copy the flash APIs to SRAM*/
    memcpy(&run0, &load0, (uint32)&size0);
    memcpy(&run1, &load1, (uint32)&size1);
    memcpy(&run2, &load2, (uint32)&size2);
    memcpy(&run3, &load3, (uint32)&size3);
    memcpy(&run4, &load4, (uint32)&size4);
    memcpy(&run5, &load5, (uint32)&size5);
    memcpy(&run6, &load6, (uint32)&size6);

  • This got my started down the right road, but I am still having issues here is my linker file and the errors i get during compile:

    --retain="*(.intvecs)"
    
    /* USER CODE BEGIN (1) */
    /* USER CODE END */
    
    /*----------------------------------------------------------------------------*/
    /* Memory Map                                                                 */
    
    MEMORY
    {
        VECTORS     (X)     : origin=0x00000000 length=0x00000020
        FLASH_API   (RX)    : origin=0x00000020 length=0x00003FE0
        FLASHBOOT   (RX)    : origin=0x00012000 length=0x00012000
        STACKS      (RW)    : origin=0x08000000 length=0x00002000
        RAM         (RW)    : origin=0x08002000 length=0x0003E000
    
    /* USER CODE BEGIN (2) */
        // Provider configuration area in flash.  Used to configure IP address,
        // subnet mask, default gateway, MAC address, and device ID
        // used by the bootloader.
        PROVIDER_CFG_AND_STATUS  (RW)  :  origin=0x00004000 length=0x00008000
    /* USER CODE END */
    }
    
    /* USER CODE BEGIN (3) */
    /* USER CODE END */
    
    
    /*----------------------------------------------------------------------------*/
    /* Section Configuration                                                      */
    
    SECTIONS
    {
        .intvecs : {} > VECTORS
       flashAPI :
       {
         ../Debug_HDK/src/Fapi_UserDefinedFunctions.obj (.text)
         --library= ../../lib/F021_API_CortexR4_LE.lib  (.text)
       } load = FLASH_API, run = RAM, LOAD_START(api_load), RUN_START(api_run), SIZE(api_size)
       for_rts_decompress {
        rtsv7R4_T_le_v3D16_eabi.lib<copy_decompress_none.obj>(.text:decompress:none)
        rtsv7R4_T_le_v3D16_eabi.lib<memcpy_t2.obj>(.text)
        rtsv7R4_T_le_v3D16_eabi.lib<memset_t2.obj>(.text)
        rtsv7R4_T_le_v3D16_eabi.lib<copy_zero_init.obj>(.text)
        rtsv7R4_T_le_v3D16_eabi.lib<copy_decompress_rle.obj>(.text)
    } > FLASHBOOT
       bootLoadCore :
       {
       * (.text)
       * (.const)
       } load=FLASHBOOT, RUN=RAM, LOAD_START(load0), RUN_START(run0), SIZE(size0)
        .cinit   : {} > FLASHBOOT
        .pinit   : {} > FLASHBOOT
        .bss     : {} > RAM
        .data    : {} > RAM
    	.sysmem  : {} > RAM
    	
    
    
    /* USER CODE BEGIN (4) */
    /* USER CODE END */
    }

    And the resulting compile says this:

    <Linking>
    "../sys_link_boot_debug_hdk.cmd", line 47: error #10099-D: program will not fit into available memory. placement with alignment fails for section ".intvecs" size 0x20 . Available memory ranges:
    VECTORS size: 0x20 unused: 0x20 max hole: 0x20
    error #10010: errors encountered during linking; "RM46_Can.out" not built

    >> Compilation failure

    I get all sorts of errors if i try to put everything you listed into ram which led me to a post that suggest the lines for the 

    rtsv7R4_T_le_v3D16_eabi library.
  • I was able to get it working with a variation of the command linker file, it looks like this:

    SECTIONS
    {
        .intvecs : {} > VECTORS
         for_rts_decompress {
        rtsv7R4_T_le_v3D16_eabi.lib<copy_decompress_none.obj>(.text:decompress:none)
        rtsv7R4_T_le_v3D16_eabi.lib<memcpy_t2.obj>(.text)
        rtsv7R4_T_le_v3D16_eabi.lib<memset_t2.obj>(.text)
        rtsv7R4_T_le_v3D16_eabi.lib<copy_zero_init.obj>(.text)
        rtsv7R4_T_le_v3D16_eabi.lib<copy_decompress_rle.obj>(.text)
    } > FLASHBOOT
       flashAPI :
       {
         ../Debug_HDK/src/Fapi_UserDefinedFunctions.obj (.text)
         ../Debug_HDK/src/bl_flash.obj (.text)
         ../Debug_HDK/src/bl_flash.obj (.const)
         ../Debug_HDK/src/hw_sci.obj (.text)
         ../Debug_HDK/src/bl_dcan.obj (.text)
         //../Debug_HDK/src/hw_dcan.obj (.const)
         ../Debug_HDK/src/uartstdio.obj (.text)
         ../Debug_HDK/src/sci_common.obj (.text)
         --library= ../../lib/F021_API_CortexR4_LE.lib  (.text)
         --library= rtsv7R4_T_le_v3D16_eabi.lib  (.text)
       } load = FLASH_API, run = RAM, LOAD_START(api_load), RUN_START(api_run), SIZE(api_size)
        .text    : {} > FLASHBOOT
        .const   : {} > FLASHBOOT
        .cinit   : {} > FLASHBOOT
        .pinit   : {} > FLASHBOOT
        .bss     : {} > RAM
        .data    : {} > RAM
    	.sysmem  : {} > RAM
    
    
    /* USER CODE BEGIN (4) */
    /* USER CODE END */
    }
    

    I tried doing exactly as above and it failed. Basically i had to put just the parts of my program and the runtime that i needed for this to work into RAM.

  • I found the source of this error, the above linker file does not make sure that the sys_startup.obj is in FLASH, and it needs to be because it is where the copy is, so i did this:

    SECTIONS
    {
    .intvecs : {} > VECTORS
    for_rts_decompress {
    rtsv7R4_T_le_v3D16_eabi.lib<copy_decompress_none.obj>(.text:decompress:none)
    rtsv7R4_T_le_v3D16_eabi.lib<memcpy_t2.obj>(.text)
    rtsv7R4_T_le_v3D16_eabi.lib<memset_t2.obj>(.text)
    rtsv7R4_T_le_v3D16_eabi.lib<copy_zero_init.obj>(.text)
    rtsv7R4_T_le_v3D16_eabi.lib<copy_decompress_rle.obj>(.text)
    ../Debug_HDK/source/sys_startup.obj (.text)
    } > FLASHBOOT
    flashAPI :
    {
    ../Debug_HDK/source/Fapi_UserDefinedFunctions.obj (.text)
    --library= ../../lib/F021_API_CortexR4_LE.lib (.text)
    } load = FLASH_API, run = RAM, LOAD_START(api_load), RUN_START(api_run), SIZE(api_size)
    
    .text : {} load = FLASHBOOT, run = RAM, LOAD_START(bl_load), RUN_START(bl_run), SIZE(bl_size)
    .const : {} load = FLASHBOOT, run = RAM, LOAD_START(const_load), RUN_START(const_run), SIZE(const_size)
    .cinit : {} load = FLASHBOOT, run = RAM, LOAD_START(cinit_load), RUN_START(cinit_run), SIZE(cinit_size)
    .pinit : {} load = FLASHBOOT, run = RAM, LOAD_START(pinit_load), RUN_START(pinit_run), SIZE(pinit_size)
    .bss : {} > RAM
    .data : {} > RAM
    .sysmem : {} > RAM
    
    /* USER CODE BEGIN (4) */
    /* USER CODE END */
    }

    and made the copy to ram the FIRST thing i do in the 

    void _c_int00(void)
    {
        
    /* USER CODE BEGIN (5) */
    	   // _copyAPI2RAM_();
    	    memcpy(&api_run, &api_load, (uint32_t)&api_size);
    	    memcpy(&bl_run, &bl_load, (uint32_t)&bl_size);
    	    memcpy(&cinit_run, &cinit_load, (uint32_t)&cinit_size);
    
    	    memcpy(&pinit_run, &pinit_load, (uint32_t)&pinit_size);
    	    memcpy(&const_run, &const_load, (uint32_t)&const_size);
    /* USER CODE END */
    

    Now my code works, and the linker command file is a little less complicated.

  • Thanks for update. I will close this thread.