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 get .text section size at run time using CCS 5.1 on TM4C129x?

Other Parts Discussed in Thread: SYSBIOS, TM4C1294NCPDT

We have a requirement to checksum the contents of the .text segment from a C program during run time.

There doesn't appear to be a pragma available with CCS 5.1 that provides any information about the text segment that I can use, so I'm wondering whether TivaWare has an API I can call to obtain the necessary information about its address and length?

  • Hello Mike

    I don't think that is possible and it needs to be done once the out/bin file is generated by another PC application.

    Regards

    Amit

  • Hi,

    A possible alternative - look for spnu118k.pdf - ARM Assembly Tools v5.0.pdf - paragraph 7.9 shows up how to.

    7.9

    7.9.1

    Linker-Generated CRC Tables

    The linker supports an extension to the link command file syntax that enables the verification of code or data by means of a CRC. The linker computes a CRC value for the specified region at link time, and stores that value in target memory such that it is accessible at boot or run time. The application code can then compute the CRC for that region and ensure that the value matches the linker-computed value. The run-time-support library does not supply a routine to calculate CRC values at boot or run time. ....

    Petrei

     

  • Hi Amit:

    I know that I can access the address of _c_int00 using an extern reference to ti_sysbios_family_arm_m3_Hwi_resetVectors[1].

    I assume that contains the address of the boot loader.  Would it be possible to derive the address of my main() function from that?

    We really must support this requirement, so I wonder if it’s possible to achieve more easily using another compiler?  On other systems I’ve used pragmas or reserved symbols such as _TEXT__ to get similar information.

    -- Mike

  • Hi Petrei:

    Hmm, that's interesting.  I'll read this, but I'm unsure that it really would solve my problem, since our requirement is to (re) compute the .text segment's CRC at various times while the system is running, to determine whether the code has been changed by a malicious attacker.

    -- Mike

     

  • Hello Mike,

    CCS Forum should be able to help a lot more. Do you want me to move the thread?

    Regards

    Amit

  • Yes, thank you -- Mike

     

  • Mike Ryan2 said:
    On other systems I’ve used pragmas or reserved symbols such as _TEXT__ to get similar information.

    The TI compilers don't have such reserved symbols defined by default. However, you can add your own Address and Dimension Operators to the linker command file. See section 8.5 Linker Command Files in the ARM Assembly Language Tools User's Guide for details.

    e.g. in the SECTIONS part of the linker command file create symbols for the start address and size of the .text segment:

        .text   :   > FLASH START(text_start), SIZE(text_size)

    These symbols can then be referenced in your program. e.g.:

    #include <stdio.h>
    
    extern char text_start[];
    extern size_t text_size[];
    
    int main(void) {
    	printf ("text_start=0x%p, text_size=0x%x\n", text_start, text_size);
    	
    	return 0;
    }
    

    Which when ran produced the output:

    text_start=0x208, text_size=0x2cbc

    Which matched the values given in the linker map:

    SEGMENT ALLOCATION MAP

    run origin  load origin   length   init length attrs members
    ----------  ----------- ---------- ----------- ----- -------
    00000000    00000000    00003068   00003068    r-x
      00000000    00000000    00000208   00000208    r-- .intvecs
      00000208    00000208    00002cbc   00002cbc    r-x .text
      00002ec4    00002ec4    00000102   00000102    r-- .const
      00002fc8    00002fc8    000000a0   000000a0    r-- .cinit

  • Petrei said:
    A possible alternative - look for spnu118k.pdf - ARM Assembly Tools v5.0.pdf - paragraph 7.9 shows up how to.

    7.9

    7.9.1

    Linker-Generated CRC Tables

    The linker supports an extension to the link command file syntax that enables the verification of code or data by means of a CRC. The linker computes a CRC value for the specified region at link time, and stores that value in target memory such that it is accessible at boot or run time. The application code can then compute the CRC for that region and ensure that the value matches the linker-computed value. The run-time-support library does not supply a routine to calculate CRC values at boot or run time. ....

    Petrei

    The linker generated CRC value sounds a good idea, since it means the user doesn't have to compute and insert a "checksum" into the image.

    While the ARM Assembly Language Tools v5.1 User's Guide SPNU118L mentions that the linker only supports a CRC algorithm type of TMS570_CRC64_ISO and the user needs to create their own code to calculate CRC values, found that the linker in TI ARM compiler v5.1.7 actually also supports CRC algorithms of type CRC32_PRIME, CRC16_802_15_4, CRC16_ALT or CRC32_C. These types are supported by the CRC module inside the Tiva TM4C129 devices, which means TivaWare can be used to calculate a "actual" CRC value for a segment which can be compared against the "expected" CRC calculated by the linker.

    The attached 7673.TI_ARM_text_segment_size.zip is a CCSv6 project for a TM4C1294NCPDT which uses the linker to generate 4 different CRC algorithms on different segments in flash and use TivaWare to calculate the actual CRC values, which in a test of not injecting errors were reported as a match:

    CRC32_PRIME actual CRC=0xdb245516, expected CRC=0xdb245516
    CRC32_C actual CRC=0x28b2f07a, expected CRC=0x28b2f07a
    CRC16_802_15_4 actual CRC=0x8fad, expected CRC=0x8fad
    CRC16_ALT actual CRC=0x206c, expected CRC=0x206c

  • Perfect!  Exactly what I needed, thanks.

    -- Mike

     

  • I'll look into this but likely the built-in support won't work for us, as for various reasons we will probably calculate a keyed hash over the text segment during run time.

    -- Mike