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.

CCS/TMS570LS3137: How to avoid an application updated by the Bootloader from overwriting the content of another application.

Part Number: TMS570LS3137


Tool/software: Code Composer Studio

Hi,

I'm using Code Composer Studio(CCS) 9.3.0.00012, the hardware I use is TMS570LS31x HDK board.
With the help of QJ Wang, I successfully modified the Bootloader project into a Dual-application Bootloader project.(Special thanks for QJ Wang's help!)
Here's the URL: e2e.ti.com/.../880049

The Dual-application Bootloader can update and store two applications, which can update or launch the specified application.
This modified Bootloader can select two applications that I want to download or execute.
But I found that the application would overwrite the Flash memory space of another application.

Here is the problem I actually encountered:
The file sizes of "Application X" and "Application Y" displayed on the computer are 90kB and 27kB. (in decimal)
The APP_START_ADDRESS and APP_START_ADDRESS_2 I set in the Bootloader are 0x00010100 and 0x00020000.

Theoretically, the memory size of the first application cannot exceed the 38kB (in decimal) file size between the two applications.
(38kB is the capacity between 0x00010100 and 0x00020000 converted to decimal size. If my calculation is incorrect, please let me know.)
If "Application Y" is downloaded to the Flash memory address of 0x00010100,
and "Application X" is downloaded to the Flash memory address of 0x00020000, both applications will run correctly.
However, if I download "Application X" to Flash memory address 0x00010100, then "Application Y" with Flash memory address 0x00020000 will not work.

Apparently, the file size of "Application X" exceeds the space allocated for the application,
resulting in the content of "Application Y" being overwritten.

I try to modify the Flash memory settings in CCS:
Open Properties -> Debug -> Flash Settings
And select "Necessary Sectors Only (for Program Load)" at Erase Options in Flash Settings.
But the above attempts did not solve the problem of overwriting Flash memory space.

Is there any way to solve this situation?
Like limiting applications that exceed the file size or protecting applications that might be overwritten?


Thanks for your help!

Best Regards, Chen Yan-Li

  • Hello Yan-Li,

    As you said that the sector 2(32KB)+sector3 (32KB) is not big enough for your application X. Please program your 2nd application to sector 5 (0x40000)

  • Hello QJ Wang,

    Thanks for your reply!
    Understood, this is indeed the most direct solution.

    But is there a way to allow Bootlaoder to restrict oversized application files?
    For example, 1nd application was accidentally selected as an application that is larger than expected,
    but I do not want the 2nd application to be overwritten by a mistake.

    Can the bootloader pre-allocate the Flash memory space that each application can write to?
    Such as downloading will not continue to write when the allocated space is exceeded.


    Thanks for your help!

    Best Regards, Chen Yan-Li

  • Hi yan-Li,

    Yes, you can. Please refer to the function BLInternalFlashStartAddrCheck() in bl_flash.c. This is to check if the application is larger than the flash size. You can modify the code for your application:


    //*****************************************************************************
    //
    //! Checks whether a given start address is valid for a download.
    //!
    //! This function checks to determine whether the given address is a valid
    //! download image start address given the options defined in bl_config.h.
    //!
    //! \return Returns non-zero if the address is valid or 0 otherwise.
    //
    //*****************************************************************************
    uint32_t
    BLInternalFlashStartAddrCheck(uint32_t ulAddr, uint32_t ulImgSize)
    {
    uint32_t count=0, i;

    uint32_t ulWholeFlashSize;

    //
    // Determine the size of the flash available on the part in use.
    //
    ulWholeFlashSize = (uint32_t)flash_sector[NUMBEROFSECTORS-1].start + flash_sector[NUMBEROFSECTORS-1].length; /* 3MB */

    /* The start address must be at the begining of the sector */
    for (i = 0; i < NUMBEROFSECTORS; i++){
    if ((ulAddr >= (uint32_t)(flash_sector[i].start)) && (ulAddr < ((uint32_t)flash_sector[i].start + flash_sector[i].length)))
    {
    count++;
    }
    }
    if (count == 0){
    return(0);
    }

    //
    // Is the address we were passed a valid start address? We allow:
    //
    // 1. Address 0 if configured to update the boot loader.
    // 2. The start of the reserved block if parameter space is reserved (to
    // allow a download of the parameter block contents).
    // 3. The application start address specified in bl_config.h.
    //
    // The function fails if the address is not one of these, if the image
    // size is larger than the available space or if the address is not word
    // aligned.
    //
    if((
    #ifdef ENABLE_BL_UPDATE
    (ulAddr != 0) &&
    #endif
    (ulAddr != APP_START_ADDRESS)) ||
    ((ulAddr + ulImgSize) > ulWholeFlashSize) ||
    ((ulAddr & 3) != 0))
    {
    return(0);
    }
    else {
    return(1);
    }
    }

  • Hello QJ Wang,

    Thanks for your reply!
    I tried to modify BLInternalFlashStartAddrCheck () in bl_flash.c,
    but the Flash writing method of the Bootloader did not seem to be changed by modifying the Flash sector.
    Here's what I modified:

    ulWholeFlashSize = (uint32_t)flash_sector[3].start + flash_sector[3].length; /* 3MB */

    /* The start address must be at the begining of the sector */
    for (i = 0; i < NUMBEROFSECTORS; i++){
    if ((ulAddr >= (uint32_t)(flash_sector[3].start)) && (ulAddr < ((uint32_t)flash_sector[3].start + flash_sector[3].length)))
    {
    count++;
    }
    }
    if (count == 0){
    return(0);
    }

    if((
    #ifdef ENABLE_BL_UPDATE
    (ulAddr != 0) &&
    #endif
    (ulAddr != APP_START_ADDRESS)) ||
    ((ulAddr + ulImgSize) > ulWholeFlashSize) ||
    ((ulAddr & 3) != 0))
    {
    return(0);
    }
    else {
    return(1);
    }
    }

    However, the above modifications do not seem to change the sector allocation of Flash.
    Are there any incorrect parts of my changes?
    Could you give me some suggestions for modification?


    Thanks for your help!

    Best Regards, Chen Yan-Li