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.

How to fill gaps and unused Flash with known values?

Other Parts Discussed in Thread: MSP432E401Y, SHA-256

Hi forum,

I'm using CCS 10.4.0.00006 with an MSP432E401Y.  It has 1024K of Flash memory (length of 0x00100000 bytes).  Our code currently uses only about 0x00050000 bytes, but is still growing.

I need to calculate a SHA-256 over the entire Flash (or at least the used Flash) so that a host computer the MSP432 is connected to can verify that the correct firmware is installed.

How can I fill gaps or unused code space (Flash) with a known value (like 0xFF - seems like the normal "erased" value)?

Alternatively, is there a way to programmatically get the end of used Flash memory so that I can calculate the SHA-256 over just that space instead?

Seems like the drawback of filling all of Flash memory with 0xFF's is that I'd have to download 1024K every time, which obviously would take much longer during edit/compile/debug cycles.

Thanks for your help!

Scott

  • FYI, from looking at the linker map file, it appears that there are some holes in the output that are filled with 0 by default.  These are indicated with "--HOLE-- [fill = 0]"

    Scott

  • Hi Scott,

    Yes, I believe in the cmd file you can append fill = "FFFFFFFF", or whatever value you choose.

    For example:

    MEMORY
    {
        FLASH (RX) : origin = 0x00000000, length = 0x00100000, fill = 0x00000000
        SRAM (RWX) : origin = 0x20000000, length = 0x00040000
    }

    Now, regarding calculating an SHA-256 on the entire 1M memory doesn't make sense, I agree.

    Check out this posting link.

    I did some poking around and found, what I think will work for you, in the MSP430 Assembler/Linker guide, section 8.5.10.7.  I also found similar information in the MSP432 Assembler guide, but frankly the MSP430 guide was more informative.  Plus I tested a simple program and it worked.  I hope this is what you were looking for.

    Here is a portion of my modified linker cmd file.

    MEMORY
    {
        FLASH (RX) : origin = 0x00000000, length = 0x00100000 LAST(_flashmem_end)
        SRAM (RWX) : origin = 0x20000000, length = 0x00040000
    }
    
    /* Section allocation in memory */
    
    SECTIONS
    {
        .intvecs:   > 0x00000000
        .text   :   > FLASH
        				START(_text_start), END(_text_end)
        .const  :   > FLASH
        .cinit  :   > FLASH
        .pinit  :   > FLASH
    	.rodata :   > FLASH
        .init_array : > FLASH

    Here is my simple code to see if it is possible to access the symbols during run-time.

    #include "msp.h"
    extern char _text_start;
    extern char _text_end;
    extern char _flashmem_end;
    int main(void)
    {
    
        uint32_t beginAddr = _symval(&_text_start);
        uint32_t endAddrs = _symval(&_text_end);
        uint32_t flashMemorySize = _symval(&_flashmem_end);
    
        return 0;
    }

  • Thanks Dennis!

    I came across a similar solution just before I saw your post.  My linker command file looks like:

    #define APP_BASE 0x00000000
    
    MEMORY
    {
        FLASH (RX) : origin = APP_BASE, length = 0x00100000
        SRAM (RWX) : origin = 0x20000000, length = 0x00040000
    }
    SECTIONS
    {
        .intvecs:   > APP_BASE
        .text   :   > FLASH
        .const  :   > FLASH
    /* Creates global symbol IMG_END_ADDR at end of program image */
        .cinit  :   LOAD_END(IMG_END_ADDR) > FLASH
        .pinit  :   > FLASH
    	.rodata :   > FLASH
        .init_array : > FLASH
        .vtable :   > 0x20000000
        .data   :   > SRAM
        .bss    :   > SRAM
        .sysmem :   > SRAM
        .stack  :   > SRAM
    }
    
    __STACK_TOP = __stack + 512;
    

    Then I added the following to calculate the SHA-256 over the Flash image space, using _symval(IMG_END_ADDR) similar to your experiment:

    uint32_t hash[8]; // Buffer to hold calculated SHA-256
    
    void Init_SHA256(void)
    {
        // Setup cryptographic control module
        MAP_SysCtlPeripheralDisable(SYSCTL_PERIPH_CCM0);
        MAP_SysCtlPeripheralReset(SYSCTL_PERIPH_CCM0);
        MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_CCM0);
    
        // Wait for the cryptographic control module to be ready
        while (!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_CCM0))
        {
        }
    
        // Reset the SHA/MD5 module
        MAP_SHAMD5Reset(SHAMD5_BASE);
    
        // Configure it for SHA256
        MAP_SHAMD5ConfigSet(SHAMD5_BASE, SHAMD5_ALGO_SHA256);
    
        // Calculate the length of the image
        uint32_t* imgStartAddr = (uint32_t *) 0x0;
        extern uint32_t IMG_END_ADDR;
        uint32_t imgLengthBytes = _symval(&IMG_END_ADDR);
    
        // Calculate hash value
        MAP_SHAMD5DataProcess(SHAMD5_BASE, imgStartAddr, imgLengthBytes, hash);
    }
    

    Have voted your answer as a solution, since it addressed the filling with a known value and how to insert and obtain the end of the Flash image.  Posting my solution here in hopes it will help someone in the future!

    Best regards,

    Scott