You copied the Doc URL to your clipboard.

Building a Secure image using a previously generated import library

You can build a new version of a Secure image and use the same addresses for the entry points that were present in the previous version. You specify the import library that is generated for the previous version of the Secure image and generate another import library for the new Secure image.

The following procedure is not a complete example, and assumes that your code sets up the Secure Attribution Unit (SAU) and calls the Non-secure startup code. It assumes you have the import library package created using the ARMv8-M Security Extension. The import library package identifies the entry points for the Secure image.

Procedure

  1. Create an interface header file, myinterface_v2.h, to be used by Non-secure code:
       int entry1(int x);
       int entry2(int x);
       int entry3(int x);
       int entry4(int x);
    
  1. In the C program for your Secure code, secure.c, include the following:
       #include <arm_cmse.h>
       #include "myinterface_v2.h"
       
       int func1(int x) { return x; }
       int __attribute__((cmse_nonsecure_entry)) entry1(int x) { return func1(x) ; }
       int __attribute__((cmse_nonsecure_entry)) entry2(int x) { return entry1(x); }
       int __attribute__((cmse_nonsecure_entry)) entry3(int x) { return func1(x) + entry1(x) ; }
       int __attribute__((cmse_nonsecure_entry)) entry4(int x) { return entry1(x) * entry2(x); }
    
       int main(void) { return 0; }

    In addition to the implementation of the two entry functions, the code defines the function func1() that can only be called by Secure code.

  1. Create an object file using the armclang -mcmse -mfloat-abi=soft command-line options:

        $ armclang -c --target arm-arm-none-eabi -march=ARMv8-M.main -mcmse -mfloat-abi=soft secure.c -o secure.o

  1. To see the disassembly of the machine code that is generated by armclang, enter:

      $ armclang -c --target arm-arm-none-eabi -march=ARMv8-M.main -mcmse -mfloat-abi=soft -S secure.c

    The disassembly is stored in the file secure.s, for example:

            .text
            ...
            .code 16
            .thumb_func
    
            ...
    
        func1:
            .fnstart
            ...
            BX LR
    
            ...
    
        __acle_se_entry1:
        entry1:
            .fnstart
        @ BB#0:
            .save	{R7, LR}
            PUSH	{R7, LR}
            ...
            BL func1
            POP.W {R7, LR}
            ...
            BXNS LR
    
            ...
    
        __acle_se_entry4:
        entry4:
            .fnstart
        @ BB#0:
            .save	{R7, LR}
            PUSH	{R7, LR}
            ...
            BL entry1
            ...
            POP.W {R7, LR}
            BXNS LR
    
            ...
    
        main:
            .fnstart
        @ BB#0:
            ...
            MOVS R0, #0
            ...
            BX LR
    
            ...

    An entry function does not start with a Secure Gateway (SG) instruction. The two symbols __acle_se_entry_name and entry_name indicate the start of an entry function to the linker.

  1. You can control the placement of the section with the veneers using a scatter file and place it in your NSC memory region. Create a scatter file containing the Veneer$$CMSE selector to place the entry function veneers, for example:
        LOAD_REGION 0x0 0x3000
        {
            EXEC_R 0x0
            {
                *(+RO,+RW,+ZI)
            }
            EXEC_NSCR 0x4000 0x1000
            {
                *(Veneer$$CMSE)
            }
            ARM_LIB_STACK 0x700000 EMPTY -0x10000
            {
            }
            ARM_LIB_HEAP  +0 EMPTY 0x10000
            {
            }
        }
        ...
  1. Using armclang, link the object file using the armlink --fpu softvfp, --import-cmse-lib-out, --import-cmse-lib-in command-line option and the preprocessed scatter file to create the Secure image:

      $ armlink secure.o -o secure.axf --cpu 8-M.Main --fpu SoftVFP --import-cmse-lib-out importlib_v2.o --import-cmse-lib-in importlib_v1.o --scatter secure.scf

    In addition to the final image, the link in this example also produces the import library, importlib_v2.o, for use when building a Non-secure image. Assuming that the section with veneers is at address 0x4000, the import library consists of a relocatable file containing only a symbol table with the following entries:

    Symbol type

    Name

    Address

    STB_GLOBAL, SHN_ABS, STT_FUNC

    entry1

    0x4001

    STB_GLOBAL, SHN_ABS, STT_FUNC

    entry2

    0x4009

    STB_GLOBAL, SHN_ABS, STT_FUNC

    entry3

    0x4021

    STB_GLOBAL, SHN_ABS, STT_FUNC

    entry4

    0x4029

  1. When you link the relocatable file corresponding to this assembly code into an image, the linker creates veneers in a section containing only entry veneers. To see the entry veneers generated by the linker, enter:

        $ fromelf --text -s -c secure.axf

    The following entry veneers are generated in the EXEC_NSCR execute-only (XO) region for this example:

        ...
    
        ** Section #3 'EXEC_NSCR' (SHT_PROGBITS) [SHF_ALLOC + SHF_EXECINSTR + SHF_ARM_NOREAD]
            Size   : 64 bytes (alignment 32)
            Address: 0x00004000
    
            $t
            entry1
                0x00004000:    E97FE97F    ....    SG        ; [0x3E08]
                0x00004004:    F7FCB85E    ..^.    B        __acle_se_entry1 ; 0xC4
            entry2
                0x00004008:    E97FE97F    ....    SG        ; [0x3E10]
                0x0000400c:    F7FCB86C    ..l.    B        __acle_se_entry2 ; 0xE8
    
        ...
    
            entry3
                0x00004020:    E97FE97F    ....    SG        ; [0x3E28]
                0x00004024:    F7FCB872    ..r.    B        __acle_se_entry3 ; 0x10C
            entry4
                0x00004028:    E97FE97F    ....    SG        ; [0x3E30]
                0x0000402c:    F7FCB888    ....    B        __acle_se_entry4 ; 0x140
        ...

    The section with the veneers is aligned on a 32-byte boundary and padded to a 32-byte boundary.

    If you do not use a scatter file, the entry veneers are placed in an ER_XO section as the first execution region. The entry veneers for the existing entry points are placed in a CMSE veneer section. For example:

        ...
    
        ** Section #1 'ER_XO' (SHT_PROGBITS) [SHF_ALLOC + SHF_EXECINSTR + SHF_ARM_NOREAD]
            Size   : 32 bytes (alignment 32)
            Address: 0x00008000
    
            $t
            entry3
                0x00008000:    E97FE97F    ....    SG        ; [0x7E08]
                0x00008004:    F000B87E    ..~.    B.W      __acle_se_entry3 ; 0x8104
            entry4
                0x00008008:    E97FE97F    ....    SG        ; [0x7E10]
                0x0000800c:    F000B894    ....    B.W      __acle_se_entry4 ; 0x8138
    
        ...
    
        ** Section #4 'ER$$Veneer$$CMSE_AT_0x00004000' (SHT_PROGBITS) [SHF_ALLOC + SHF_EXECINSTR + SHF_ARM_NOREAD]
            Size   : 32 bytes (alignment 32)
            Address: 0x00004000
    
            $t
            entry1
                0x00004000:    E97FE97F    ....    SG        ; [0x3E08]
                0x00004004:    F004B85A    ..Z.    B.W      __acle_se_entry1 ; 0x80BC
            entry2
                0x00004008:    E97FE97F    ....    SG        ; [0x3E10]
                0x0000400c:    F004B868    ..h.    B.W      __acle_se_entry2 ; 0x80E0
    
        ...

Postrequisites

After you have built your updated Secure image:

  1. Pre-load the updated Secure image onto your device.
  2. Deliver your device with the pre-loaded image, together with the new import library package, to a party who develops the Non-secure code for this device. The import library package contains:
  • The interface header file, h.
  • The import library, o.
Was this page helpful? Yes No