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.

AM62A7: 9.02 Firmware Builder built issue

Part Number: AM62A7

Tool/software:

Hi Team,

This question is the follow-up question for the query https://e2e.ti.com/support/processors-group/processors/f/processors-forum/1357235/am62a7-query-regarding-the-edge-ai-demo-application

I am successfully run the demo application with 1GB DDR in the SDK 9.00.

While migrating the same changes to the 9.02 I am facing built errors.

I issued the below commands without modifying the gen_linker_mem_map.py file. Attached the error log also.

export SOC=am62a
export TISDK_IMAGE=edgeai
./sdk_builder/scripts/setup_psdk_rtos.sh
export PATH=$PATH:~/.local/bin
cd vision_apps/tools/PyTI_PSDK_RTOS
pip3 install -e . --user
cd -
cd vision_apps/platform/am62a/rtos
./gen_linker_mem_map.py
cd -
cd sdk_builder/
BUILD_EDGEAI=yes make sdk_clean -j`nproc`
BUILD_EDGEAI=yes make sdk -j`nproc`

2262.firmware_builder_sdk_9.02_build_error.txt

Also attached the am62a_linker_freertos_mcuplus.cmd which is auto generated for the 9.00 package and for the 9.02 Package

/*=========================*/
/*     Linker Settings     */
/*=========================*/
--ram_model
--retain="*(.bootCode)"
--retain="*(.startupCode)"
--retain="*(.startupData)"
--retain="*(.irqStack)"
--retain="*(.fiqStack)"
--retain="*(.abortStack)"
--retain="*(.undStack)"
--retain="*(.svcStack)"

--fill_value=0
--stack_size=0x8000
--heap_size=0x10000
--entry_point=_self_reset_start

-stack  0x8000  /* SOFTWARE STACK SIZE */
-heap   0x10000 /* HEAP AREA SIZE      */

/*-------------------------------------------*/
/*       Stack Sizes for various modes       */
/*-------------------------------------------*/
__IRQ_STACK_SIZE   = 0x1000;
__FIQ_STACK_SIZE   = 0x0100;
__ABORT_STACK_SIZE = 0x0100;
__UNDEFINED_STACK_SIZE   = 0x0100;
__SVC_STACK_SIZE   = 0x0100;

/*--------------------------------------------------------------*/
/*                     Section Configuration                    */
/*--------------------------------------------------------------*/
SECTIONS
{
    .vectors            : {} palign(8)      > DDR_DM_R5F
    .bootCode           : align = 8, load = R5F_TCMB0, run = R5F_TCMA
    .startupCode        : align = 8, load = R5F_TCMB0 , run = R5F_TCMA
    .startupData        : align = 8, load = R5F_TCMB0 , run = R5F_TCMA, type = NOINIT
    GROUP
    {
        .text.hwi       : palign(8)
        .text.cache     : palign(8)
        .text.mpu       : palign(8)
        .text.boot      : palign(8)
    } load = R5F_TCMB0, run = R5F_TCMA
    .mpu_cfg            : align = 8, load = R5F_TCMB0, run = R5F_TCMA
    .text               : {} palign(8)      > DDR_DM_R5F
    .const              : {} palign(8)      > DDR_DM_R5F
    .rodata             : {} palign(8)      > DDR_DM_R5F
    .cinit              : {} palign(8)      > DDR_DM_R5F
    .far                : {} align(4)       > DDR_DM_R5F
    .data               : {} palign(128)    > DDR_DM_R5F
    .sysmem             : {}                > DDR_DM_R5F
    .data_buffer        : {} palign(128)    > DDR_DM_R5F
    .const.devgroup     : {*(.const.devgroup*)} align(4)       > DDR_DM_R5F
    .boardcfg_data      : {} align(4)       > DDR_DM_R5F
    .resource_table          :
    {
        __RESOURCE_TABLE = .;
    }                                           > DDR_DM_R5F_RESOURCE_TABLE

    .tracebuf                : {} align(1024)   > DDR_DM_R5F_IPC_TRACEBUF
    .stack                   : {} align(4)      > DDR_DM_R5F  (HIGH)

    .bss:ddr_local_mem      (NOLOAD) : {} > DDR_DM_R5F_LOCAL_HEAP
    .bss:app_log_mem        (NOLOAD) : {} > APP_LOG_MEM
    .bss:app_fileio_mem     (NOLOAD) : {} > APP_FILEIO_MEM
    .bss:tiovx_obj_desc_mem (NOLOAD) : {} > TIOVX_OBJ_DESC_MEM
    .bss:ipc_vring_mem      (NOLOAD) : {} > IPC_VRING_MEM

    GROUP {
        .bss:    {} palign(4)   /* This is where uninitialized globals go */
        RUN_START(__BSS_START)
	.bss.devgroup     : {*(.bss.devgroup*)} align(4)  
	.bss:taskStackSection  : {} align(4)  
        RUN_END(__BSS_END)
    } > DDR_DM_R5F

    .irqStack   : {. = . + __IRQ_STACK_SIZE;} align(4)      > DDR_DM_R5F  (HIGH)
    RUN_START(__IRQ_STACK_START)
    RUN_END(__IRQ_STACK_END)

    .fiqStack   : {. = . + __FIQ_STACK_SIZE;} align(4)      > DDR_DM_R5F  (HIGH)
    RUN_START(__FIQ_STACK_START)
    RUN_END(__FIQ_STACK_END)

    .abortStack : {. = . + __ABORT_STACK_SIZE;} align(4)    > DDR_DM_R5F  (HIGH)
    RUN_START(__ABORT_STACK_START)
    RUN_END(__ABORT_STACK_END)

    .undStack   : {. = . + __UNDEFINED_STACK_SIZE;} align(4) > DDR_DM_R5F  (HIGH)
    RUN_START(__UNDEFINED_STACK_START)
    RUN_END(__UNDEFINED_STACK_END)

    .svcStack   : {. = . + __SVC_STACK_SIZE;} align(4)      > DDR_DM_R5F  (HIGH)
    RUN_START(__SVC_STACK_START)
    RUN_END(__SVC_STACK_END)
}

/*=========================*/
/*     Linker Settings     */
/*=========================*/
--ram_model
--retain="*(.bootCode)"
--retain="*(.startupCode)"
--retain="*(.startupData)"
--retain="*(.irqStack)"
--retain="*(.fiqStack)"
--retain="*(.abortStack)"
--retain="*(.undStack)"
--retain="*(.svcStack)"

--fill_value=0
--stack_size=0x8000
--heap_size=0x10000
--entry_point=_self_reset_start

-stack  0x8000  /* SOFTWARE STACK SIZE */
-heap   0x10000 /* HEAP AREA SIZE      */

/*-------------------------------------------*/
/*       Stack Sizes for various modes       */
/*-------------------------------------------*/
__IRQ_STACK_SIZE   = 0x1000;
__FIQ_STACK_SIZE   = 0x0100;
__ABORT_STACK_SIZE = 0x0100;
__UNDEFINED_STACK_SIZE   = 0x0100;
__SVC_STACK_SIZE   = 0x0100;
__DM_STUB_STACK_SIZE = 0x0400; /* DM stub stack size */
/*--------------------------------------------------------------*/
/*                     Section Configuration                    */
/*--------------------------------------------------------------*/
SECTIONS
{
    .vectors            : {} palign(8)      > DDR_DM_R5F
    .bootCode           : align = 8, load = R5F_TCMB0, run = R5F_TCMA
    .startupCode        : align = 8, load = R5F_TCMB0 , run = R5F_TCMA
    .startupData        : align = 8, load = R5F_TCMB0 , run = R5F_TCMA, type = NOINIT
    GROUP
    {
        .text.hwi       : palign(8)
        .text.cache     : palign(8)
        .text.mpu       : palign(8)
        .text.boot      : palign(8)
    } load = R5F_TCMB0, run = R5F_TCMA
    .mpu_cfg            : align = 8, load = R5F_TCMB0, run = R5F_TCMA
    .fs_stub (NOLOAD)   : {} align(4)       > DDR_FS_STUB
    .text               : {} palign(8)      > DDR_DM_R5F
    .const              : {} palign(8)      > DDR_DM_R5F
    .rodata             : {} palign(8)      > DDR_DM_R5F
    .cinit              : {} palign(8)      > DDR_DM_R5F
    .far                : {} align(4)       > DDR_DM_R5F
    .data               : {} palign(128)    > DDR_DM_R5F
    .sysmem             : {}                > DDR_DM_R5F
    .data_buffer        : {} palign(128)    > DDR_DM_R5F
    .const.devgroup     : {*(.const.devgroup*)} align(4)       > DDR_DM_R5F
    .boardcfg_data      : {} align(4)       > DDR_DM_R5F
    .resource_table          :
    {
        __RESOURCE_TABLE = .;
    }                                           > DDR_DM_R5F_RESOURCE_TABLE

    .tracebuf                : {} align(1024)   > DDR_DM_R5F_IPC_TRACEBUF
    .stack                   : {} align(4)      > DDR_DM_R5F  (HIGH)

    GROUP{

        .dm_stub_text : {
            _privileged_code_begin = .;
            _text_secure_start = .;
            dm_stub*(.text)
        }  palign(8)

        .dm_stub_data : {
            _privileged_data_begin = .;
            dm_stub*(.data)
            _privileged_data_end = .;
        }  palign(8)

        .dm_stub_bss : {
            _start_bss = .;
            dm_stub*(.bss)
            _end_bss = .;
        }  palign(8)

        .dm_stub_rodata : {
            _start_rodata = .;
            dm_stub*(.rodata)
            _end_rodata = .;
        }  palign(8)

    .dm_stub_stack : {
            _start_stack = .;
            . += __DM_STUB_STACK_SIZE;
            _end_stack = .;
        }  palign(8)
    }  load = R5F_TCMB0, run = R5F_TCMA

    /* Trace buffer used during low power mode */
    .lpm_trace_buf : (NOLOAD) {} > R5F_TCMA_TRACE_BUFF

    .bss:ddr_local_mem      (NOLOAD) : {} > DDR_DM_R5F_LOCAL_HEAP
    .bss:app_log_mem        (NOLOAD) : {} > APP_LOG_MEM
    .bss:app_fileio_mem     (NOLOAD) : {} > APP_FILEIO_MEM
    .bss:tiovx_obj_desc_mem (NOLOAD) : {} > TIOVX_OBJ_DESC_MEM
    .bss:ipc_vring_mem      (NOLOAD) : {} > IPC_VRING_MEM

    GROUP {
        .bss:    {} palign(4)   /* This is where uninitialized globals go */
        RUN_START(__BSS_START)
	.bss.devgroup     : {*(.bss.devgroup*)} align(4)  
	.bss:taskStackSection  : {} align(4)  
        RUN_END(__BSS_END)
    } > DDR_DM_R5F

    .irqStack   : {. = . + __IRQ_STACK_SIZE;} align(4)      > DDR_DM_R5F  (HIGH)
    RUN_START(__IRQ_STACK_START)
    RUN_END(__IRQ_STACK_END)

    .fiqStack   : {. = . + __FIQ_STACK_SIZE;} align(4)      > DDR_DM_R5F  (HIGH)
    RUN_START(__FIQ_STACK_START)
    RUN_END(__FIQ_STACK_END)

    .abortStack : {. = . + __ABORT_STACK_SIZE;} align(4)    > DDR_DM_R5F  (HIGH)
    RUN_START(__ABORT_STACK_START)
    RUN_END(__ABORT_STACK_END)

    .undStack   : {. = . + __UNDEFINED_STACK_SIZE;} align(4) > DDR_DM_R5F  (HIGH)
    RUN_START(__UNDEFINED_STACK_START)
    RUN_END(__UNDEFINED_STACK_END)

    .svcStack   : {. = . + __SVC_STACK_SIZE;} align(4)      > DDR_DM_R5F  (HIGH)
    RUN_START(__SVC_STACK_START)
    RUN_END(__SVC_STACK_END)
}

While comparing these two files I am observing some partition for DM stub regions which is missing in the 9.00 Package.

Could you please help me to figure out why this error is coming with the 9.02 firmware builder.

Regards,

Ann Rose Antony

  • Hi Antony,

    Thanks for reaching out to Texas Instruments E2E support forum.

    Can you please tell what is the size of memory allocated to R5F_TCMA_TRACE_BUFF?

    I can see from the above logs that you are getting build error because the memory allocated for section ".lpm_trace_buf" is not enough.

    Can you please share the *.map file of the binary for which the build failed.(i.e. vx_app_rtos_linux_mcu1_0.out)?

    Regards,

    Tushar

  • Hi Tushar,

    I have not updated any values in the package other than issuing the above mentioned commands.

    Attaching the map file for which the build got fail.

    vx_app_rtos_linux_mcu1_0.out.map.txt

    Thanks and Regards,

    Ann Rose Antony

  • Hi Antony,

    Thanks for providing the above file. I am able to replicate the issue at my end.

    Please allow some time to revert back.

    Regards,

    Tushar

  • Hi Tushar,

    Thanks for your response.

    When I was debugging it seems like the linker_mem_map.cmd is getting modified without the values like R5F_TCMA_TRACE_BUFF,  R5F_TCMB0_TRACE_BUFF and DDR_FS_STUB. These values are updated when we run the python script gen_linker_mem_map.py. I am hoping that the python script is not taken care for the 9.02 firmware builder package. It is same as the 9.00 firmware package. Could you please let me know which all changes needs to be taken care for the gen_linker_mem_map.py file as a part of 9.02 firmware builder package.

    Regards,

    Ann Rose Antony   

  • Hello Antony,

    The linker_mem_map.cmd file generated using the gen_linker_mem_map.py script is not correct. The file generated using the script is missing R5F_TCMB0_TRACE_BUFF, R5F_TCMA_TRACE_BUFF & DDR_FS_STUB memory section in the linker_mem_map.cmd file.

    Can you please try with the below linker_mem_map.cmd file and let us know the result?

    Replace the linker_mem_map.cmd file with the below code. Do not run the ./gen_linker_mem_map.py script.

    /* 
     * This file is AUTO GENERATED by PyTI_PSDK_RTOS tool. 
     * It is NOT recommended to manually edit this file 
     */ 
    /* 
     * 
     * Copyright (c) 2018 Texas Instruments Incorporated 
     * 
     * All rights reserved not granted herein. 
     * 
     * Limited License. 
     * 
     * Texas Instruments Incorporated grants a world-wide, royalty-free, non-exclusive 
     * license under copyrights and patents it now or hereafter owns or controls to make, 
     * have made, use, import, offer to sell and sell ("Utilize") this software subject to the 
     * terms herein.  With respect to the foregoing patent license, such license is granted 
     * solely to the extent that any such patent is necessary to Utilize the software alone. 
     * The patent license shall not apply to any combinations which include this software, 
     * other than combinations with devices manufactured by or for TI ("TI Devices"). 
     * No hardware patent is licensed hereunder. 
     * 
     * Redistributions must preserve existing copyright notices and reproduce this license 
     * (including the above copyright notice and the disclaimer and (if applicable) source 
     * code license limitations below) in the documentation and/or other materials provided 
     * with the distribution 
     * 
     * Redistribution and use in binary form, without modification, are permitted provided 
     * that the following conditions are met: 
     * 
     *        No reverse engineering, decompilation, or disassembly of this software is 
     * permitted with respect to any software provided in binary form. 
     * 
     *        any redistribution and use are licensed by TI for use only with TI Devices. 
     * 
     *        Nothing shall obligate TI to provide you with source code for the software 
     * licensed and provided to you in object code. 
     * 
     * If software source code is provided to you, modification and redistribution of the 
     * source code are permitted provided that the following conditions are met: 
     * 
     *        any redistribution and use of the source code, including any resulting derivative 
     * works, are licensed by TI for use only with TI Devices. 
     * 
     *        any redistribution and use of any object code compiled from the source code 
     * and any resulting derivative works, are licensed by TI for use only with TI Devices. 
     * 
     * Neither the name of Texas Instruments Incorporated nor the names of its suppliers 
     * 
     * may be used to endorse or promote products derived from this software without 
     * specific prior written permission. 
     * 
     * DISCLAIMER. 
     * 
     * THIS SOFTWARE IS PROVIDED BY TI AND TI'S LICENSORS "AS IS" AND ANY EXPRESS 
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
     * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
     * IN NO EVENT SHALL TI AND TI'S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
     * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
     * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
     * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
     * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
     * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
     * OF THE POSSIBILITY OF SUCH DAMAGE. 
     * 
     */ 
    
    MEMORY
    {
        /* R5F_TCMA_VECS [ size 64 B ] */
        R5F_TCMA_VECS            (    X ) : ORIGIN = 0x00000000 , LENGTH = 0x00000040
        /* R5F_TCMA [ size 29.94 KB ] */
        R5F_TCMA                 (    X ) : ORIGIN = 0x00000040 , LENGTH = 0x000077C0
        /* R5F_TCMA_TRACE_BUFF [ size 2 KB ] */
        R5F_TCMA_TRACE_BUFF      ( RWIX ) : ORIGIN = 0x00007800 LENGTH = 0x0000800
        /* R5F_TCMB0_VECS [ size 64 B ] */
        R5F_TCMB0_VECS           ( RWIX ) : ORIGIN = 0x41010000 , LENGTH = 0x00000040
        /* R5F_TCMB0 [ size 29.94 KB ] */
        R5F_TCMB0                ( RWIX ) : ORIGIN = 0x41010040 , LENGTH = 0x000077C0
        /* R5F_TCMB0_TRACE_BUFF [ size 2 KB ] */
        R5F_TCMB0_TRACE_BUFF      ( RWIX ) : ORIGIN = 0x41017800 LENGTH = 0x0000800
        /* DDR for DM R5F for Linux IPC [ size 1024.00 KB ] */
        DDR_DM_R5F_IPC           ( RWIX ) : ORIGIN = 0x9C800000 , LENGTH = 0x00100000
        /* DDR for DM R5F for Linux resource table [ size 1024 B ] */
        DDR_DM_R5F_RESOURCE_TABLE ( RWIX ) : ORIGIN = 0x9C900000 , LENGTH = 0x00000400
        /* DDR for DM R5F for Linux IPC tracebuffer [ size 1023.00 KB ] */
        DDR_DM_R5F_IPC_TRACEBUF  ( RWIX ) : ORIGIN = 0x9C900400 , LENGTH = 0x000FFC00
        /* DDR for FS Stub binary [ size 32.00 KB ] */
        DDR_FS_STUB              ( RWIX ) : ORIGIN = 0x9CA00000 LENGTH = 0x00008000
        /* DDR for DM R5F for code/data [ size 28.00 MB ] */
        DDR_DM_R5F               ( RWIX ) : ORIGIN = 0x9CA08000 , LENGTH = 0x01C00000
        /* Memory for IPC Vring's. MUST be non-cached or cache-coherent [ size 16.00 MB ] */
        IPC_VRING_MEM                     : ORIGIN = 0xA0000000 , LENGTH = 0x01000000
        /* Memory for remote core logging [ size 256.00 KB ] */
        APP_LOG_MEM                       : ORIGIN = 0xA1000000 , LENGTH = 0x00040000
        /* Memory for TI OpenVX shared memory. MUST be non-cached or cache-coherent [ size 15.75 MB ] */
        TIOVX_OBJ_DESC_MEM                : ORIGIN = 0xA1040000 , LENGTH = 0x00FC0000
        /* Memory for remote core file operations [ size  4.00 MB ] */
        APP_FILEIO_MEM                    : ORIGIN = 0xA2000000 , LENGTH = 0x00400000
        /* Memory for shared memory buffers in DDR [ size 176.00 MB ] */
        DDR_SHARED_MEM                    : ORIGIN = 0xA3000000 , LENGTH = 0x0B000000
        /* DDR for DM R5F for local heap [ size 16.00 MB ] */
        DDR_DM_R5F_LOCAL_HEAP    ( RWIX ) : ORIGIN = 0xAF000000 , LENGTH = 0x01000000
    }
    

    After replacing the file with above code rebuild the SDK using below commands.

    BUILD_EDGEAI=yes make sdk_clean -j`nproc`
    BUILD_EDGEAI=yes make sdk -j`nproc`

    You should now be able to build the SDK without any errors.

    Regards,

    Tushar

  • HI Tushar,

    If I modify the linker_mem_map.cmd file with the code which you have shared, the built is successful.

    My task is to update the DDR size to 1GB. For implementing the same I need to update the gen_linker_mem_map.py with the updated memory values and need to run the python script as mentioned in the User Documentation for the firmware builder. Hence after running the same, the linker_mem_map.cmd file generated is missing the R5F_TCMB0_TRACE_BUFF, R5F_TCMA_TRACE_BUFF & DDR_FS_STUB memory sections.

    Could you please help me to exactly modify the python script in such a way that it will modify the partitions in the linker_mem_map.cmd file properly.

    Regards,

    Ann Rose Antony

  • Hello Antony,

    Could you please help me to exactly modify the python script in such a way that it will modify the partitions in the linker_mem_map.cmd file properly.

    Can you please try with the below code provided for gen_linker_mem_map.py script and let us know the result?

    Replace the gen_linker_mem_map.py script with the below code.

    #!/usr/bin/env python3
    #
    # Copyright (c) 2018 Texas Instruments Incorporated
    #
    # All rights reserved not granted herein.
    #
    # Limited License.
    #
    # Texas Instruments Incorporated grants a world-wide, royalty-free, non-exclusive
    # license under copyrights and patents it now or hereafter owns or controls to make,
    # have made, use, import, offer to sell and sell ("Utilize") this software subject to the
    # terms herein.  With respect to the foregoing patent license, such license is granted
    # solely to the extent that any such patent is necessary to Utilize the software alone.
    # The patent license shall not apply to any combinations which include this software,
    # other than combinations with devices manufactured by or for TI ("TI Devices").
    # No hardware patent is licensed hereunder.
    #
    # Redistributions must preserve existing copyright notices and reproduce this license
    # (including the above copyright notice and the disclaimer and (if applicable) source
    # code license limitations below) in the documentation and/or other materials provided
    # with the distribution
    #
    # Redistribution and use in binary form, without modification, are permitted provided
    # that the following conditions are met:
    #
    #       No reverse engineering, decompilation, or disassembly of this software is
    # permitted with respect to any software provided in binary form.
    #
    #       any redistribution and use are licensed by TI for use only with TI Devices.
    #
    #       Nothing shall obligate TI to provide you with source code for the software
    # licensed and provided to you in object code.
    #
    # If software source code is provided to you, modification and redistribution of the
    # source code are permitted provided that the following conditions are met:
    #
    #       any redistribution and use of the source code, including any resulting derivative
    # works, are licensed by TI for use only with TI Devices.
    #
    #       any redistribution and use of any object code compiled from the source code
    # and any resulting derivative works, are licensed by TI for use only with TI Devices.
    #
    # Neither the name of Texas Instruments Incorporated nor the names of its suppliers
    #
    # may be used to endorse or promote products derived from this software without
    # specific prior written permission.
    #
    # DISCLAIMER.
    #
    # THIS SOFTWARE IS PROVIDED BY TI AND TI'S LICENSORS "AS IS" AND ANY EXPRESS
    # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    # IN NO EVENT SHALL TI AND TI'S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT,
    # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
    # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
    # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
    # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
    # OF THE POSSIBILITY OF SUCH DAMAGE.
    #
    #
    
    #
    # This script is used to generate 'MEMORY' section for multiple CPUs
    # in different CPU specific linker command files.
    #
    # This helps to define the memory map in one file vs having to manually
    # keep the system memory map consistant across multiple CPUs
    # in different linker commnd files.
    #
    # Make sure PyTI_PSDK_RTOS module is installed before running this script.
    # See vision_apps/tools/PyTI_PSDK_RTOS/README.txt to install PyTI_PSDK_RTOS module.
    #
    # Edit this file to change the memory map
    #
    # Run this script by doing below,
    # ./gen_linker_mem_map.py
    #
    # This will generate linker command file at below folders
    # ./<cpu name>/linker_mem_map.cmd
    #
    # Here CPU name is mpu1, c7x_1, mcu1_0
    #
    #
    from ti_psdk_rtos_tools import *
    import math
    
    def roundUp(x,y):
            return int(math.ceil(x / y)) * y
    
    KB = 1024;
    MB = KB*KB;
    GB = KB*MB;
    
    #
    # Notes,
    # - recommend to keep all memory segment sizes in units of KB at least
    #
    
    #
    # On AM62A, there is a total of 2GB
    # but here a memory map of just 1GB is considered
    #
    # Linux Kernel address starts at 0x8000_0000 of size 512MB
    # RTOS carveout address starts at 0xA000_0000 of size 384MB
    # Linux user space address starts at 0xB800_0000 of size 128MB
    #
    
    ddr_mem_addr_1  = 0x0099800000;
    ddr_mem_size_1  = 80*MB
    
    ddr_mem_addr_2 = 0xA0000000;
    ddr_mem_size_2 = 515*MB
    
    #
    # Other constant sizes
    #
    linux_ddr_ipc_size = 1*MB;
    linux_ddr_resource_table_size = 1*KB;
    linux_ddr_ipc_tracebuf_size = 1*MB - linux_ddr_resource_table_size;
    
    #
    # MSMC memory allocation for various CPUs
    #
    #dmsc_msmc_size   = 64*KB;
    #mpu1_msmc_size   = 128*KB;
    
    #
    # C7x L1, L2 memory allocation
    #
    # L2 main - 1MB SRAM
    # L2 aux  - 256KB SRAM
    c7x_1_l2_main_addr  = 0x7e000000;
    c7x_1_l2_main_size  = 1*MB;
    c7x_1_l2_aux_addr  = 0x7f000000;
    c7x_1_l2_aux_size  = 240*KB;
    c7x_1_l2_aux_as_l1_addr  = c7x_1_l2_aux_addr + c7x_1_l2_aux_size;
    c7x_1_l2_aux_as_l1_size  = 16*KB;
    
    #
    # DDR memory allocation for various CPUs
    #
    c7x_1_ddr_ipc_addr = ddr_mem_addr_1;
    c7x_1_ddr_resource_table_addr = c7x_1_ddr_ipc_addr + linux_ddr_ipc_size;
    c7x_1_ddr_ipc_tracebuf_addr = c7x_1_ddr_resource_table_addr + linux_ddr_resource_table_size
    c7x_1_ddr_boot_addr = c7x_1_ddr_ipc_tracebuf_addr + linux_ddr_ipc_tracebuf_size;
    c7x_1_ddr_boot_addr = roundUp(c7x_1_ddr_boot_addr, 1*MB);
    c7x_1_ddr_boot_size = 1*KB;
    c7x_1_ddr_vecs_addr = c7x_1_ddr_ipc_tracebuf_addr + 2*MB;
    c7x_1_ddr_vecs_addr = roundUp(c7x_1_ddr_vecs_addr, 2*MB);
    c7x_1_ddr_vecs_size = 16*KB;
    c7x_1_ddr_addr = c7x_1_ddr_vecs_addr + c7x_1_ddr_vecs_size;
    c7x_1_ddr_addr = roundUp(c7x_1_ddr_addr, 64*KB);
    c7x_1_ddr_size = 32*MB - (c7x_1_ddr_addr-c7x_1_ddr_ipc_addr);
    
    
    mcu_r5f_ddr_ipc_addr = c7x_1_ddr_addr + c7x_1_ddr_size ;
    mcu_r5f_ddr_resource_table_addr = mcu_r5f_ddr_ipc_addr + linux_ddr_ipc_size;
    mcu_r5f_ddr_ipc_tracebuf_addr = mcu_r5f_ddr_resource_table_addr + linux_ddr_resource_table_size
    mcu_r5f_ddr_addr = mcu_r5f_ddr_ipc_tracebuf_addr + linux_ddr_ipc_tracebuf_size;
    mcu_r5f_ddr_size = 16*MB - (mcu_r5f_ddr_addr-mcu_r5f_ddr_ipc_addr);
    
    dm_r5f_ddr_ipc_addr = mcu_r5f_ddr_addr + mcu_r5f_ddr_size;
    dm_r5f_ddr_resource_table_addr = dm_r5f_ddr_ipc_addr + linux_ddr_ipc_size;
    dm_r5f_ddr_ipc_tracebuf_addr = dm_r5f_ddr_resource_table_addr + linux_ddr_resource_table_size
    dm_r5f_ddr_addr = dm_r5f_ddr_ipc_tracebuf_addr + linux_ddr_ipc_tracebuf_size;
    dm_r5f_ddr_size = 31*MB - (dm_r5f_ddr_addr-dm_r5f_ddr_ipc_addr);
    
    tifs_lpm_ctx_addr = dm_r5f_ddr_addr + dm_r5f_ddr_size;
    tifs_lpm_ctx_size = 512*KB;
    atf_addr = tifs_lpm_ctx_addr + tifs_lpm_ctx_size;
    atf_size = 512*KB;
    optee_addr = atf_addr + atf_size;
    optee_size = 24*MB;
    
    #
    # DDR memory allocation for various shared memories
    #
    carveout_size = 0
    # Keeping 16MB additional for VRING start, so that IPC Shared memory starts
    # exactly at 0xAA000000 offset. This gap of 16MB is not currently used and
    # can be used for Linux..
    ipc_vring_mem_addr      = ddr_mem_addr_2;
    ipc_vring_mem_size      = 16*MB;
    carveout_size += ipc_vring_mem_size
    
    app_log_mem_addr        = ipc_vring_mem_addr + ipc_vring_mem_size;
    app_log_mem_size        = 256*KB;
    carveout_size += app_log_mem_size
    
    tiovx_obj_desc_mem_addr = app_log_mem_addr + app_log_mem_size;
    tiovx_obj_desc_mem_size = 16*MB - app_log_mem_size;
    carveout_size += tiovx_obj_desc_mem_size
    
    app_fileio_mem_addr        = tiovx_obj_desc_mem_addr + tiovx_obj_desc_mem_size;
    app_fileio_mem_size        = 4*MB;
    carveout_size += app_fileio_mem_size
    
    tiovx_log_rt_mem_addr   = app_fileio_mem_addr + app_fileio_mem_size;
    tiovx_log_rt_mem_size   = 16*MB - app_fileio_mem_size;
    carveout_size += tiovx_log_rt_mem_size
    
    # Shared memory for Buffers/ION allocator
    ddr_shared_mem_addr     = tiovx_log_rt_mem_addr + tiovx_log_rt_mem_size;
    ddr_shared_mem_size     = 176*MB;
    carveout_size += ddr_shared_mem_size
    
    mcu_r5f_ddr_local_heap_addr  = ddr_shared_mem_addr + ddr_shared_mem_size;
    mcu_r5f_ddr_local_heap_size  = 16*MB;
    carveout_size += mcu_r5f_ddr_local_heap_size
    
    dm_r5f_ddr_local_heap_addr  = mcu_r5f_ddr_local_heap_addr + mcu_r5f_ddr_local_heap_size;
    dm_r5f_ddr_local_heap_size  = 16*MB;
    carveout_size += dm_r5f_ddr_local_heap_size
    
    c7x_1_ddr_local_heap_non_cacheable_addr  = dm_r5f_ddr_local_heap_addr + dm_r5f_ddr_local_heap_size;
    c7x_1_ddr_local_heap_non_cacheable_size  = 16*MB;
    carveout_size += c7x_1_ddr_local_heap_non_cacheable_size
    
    c7x_1_ddr_scratch_non_cacheable_addr     = c7x_1_ddr_local_heap_non_cacheable_addr + c7x_1_ddr_local_heap_non_cacheable_size;
    c7x_1_ddr_scratch_non_cacheable_size     = 16*MB;
    carveout_size += c7x_1_ddr_scratch_non_cacheable_size
    
    c7x_1_ddr_local_heap_addr  = c7x_1_ddr_scratch_non_cacheable_addr + c7x_1_ddr_scratch_non_cacheable_size;
    c7x_1_ddr_local_heap_size  = 112*MB;
    carveout_size += c7x_1_ddr_local_heap_size
    
    c7x_1_ddr_scratch_addr     = c7x_1_ddr_local_heap_addr + c7x_1_ddr_local_heap_size;
    c7x_1_ddr_scratch_size     = 112*MB;
    carveout_size += c7x_1_ddr_scratch_size
    
    assert carveout_size <= ddr_mem_size_2
    
    #
    # Create memory section based on addr and size defined above, including
    # any CPU specific internal memories
    #
    
    # r5f local memory sections
    mcu_r5f_tcma_vecs  = MemSection("R5F_TCMA_VECS" , "X"   , 0x00000000, (KB >> 4));
    mcu_r5f_tcma       = MemSection("R5F_TCMA" , "X"   , 0x00000040, 0x000077C0);
    mcu_r5f_tcma_trace_buff = MemSection("R5F_TCMA_TRACE_BUFF" , "X"   , 0x00007800, (2*KB));
    
    r5f_tcmb0      = MemSection("R5F_TCMB0", "RWIX", 0x41010000, 32*KB);
    mcu_r5f_tcmb0_vecs   = MemSection("R5F_TCMB0_VECS", "RWIX", 0x41010000, (KB >> 4));
    mcu_r5f_tcmb0        = MemSection("R5F_TCMB0", "RWIX", 0x41010040, 0x000077C0);
    mcu_r5f_tcmb0_trace_buff = MemSection("R5F_TCMB0_TRACE_BUFF", "RWIX", 0x41017800, (2*KB));
    
    # C7x L1/L2/L3 memory sections
    c7x_1_l3   = MemSection("L2RAM_C7x_1_MAIN", "RWIX", c7x_1_l2_main_addr  , c7x_1_l2_main_size  , "L3 for C7x_1");
    c7x_1_l2   = MemSection("L2RAM_C7x_1_AUX", "RWIX", c7x_1_l2_aux_addr  , c7x_1_l2_aux_size  , "L2 for C7x_1");
    c7x_1_l1   = MemSection("L2RAM_C7x_1_AUX_AS_L1", "RWIX", c7x_1_l2_aux_as_l1_addr  , c7x_1_l2_aux_as_l1_size  , "L1 for C7x_1");
    
    # CPU code/data memory sections in DDR
    mcu_r5f_ddr_ipc             = MemSection("DDR_MCU_R5F_IPC", "RWIX", mcu_r5f_ddr_ipc_addr, linux_ddr_ipc_size, "DDR for MCU R5F for Linux IPC");
    mcu_r5f_ddr_ipc.setDtsName("edgeai_mcu_r5fss0_core0_dma_memory_region", "edgeai-dm-r5f-dma-memory");
    mcu_r5f_ddr_resource_table  = MemSection("DDR_MCU_R5F_RESOURCE_TABLE", "RWIX", mcu_r5f_ddr_resource_table_addr, linux_ddr_resource_table_size, "DDR for MCU R5F for Linux resource table");
    mcu_r5f_ddr_ipc_tracebuf    = MemSection("DDR_MCU_R5F_IPC_TRACEBUF", "RWIX", mcu_r5f_ddr_ipc_tracebuf_addr, linux_ddr_ipc_tracebuf_size, "DDR for MCU R5F for Linux IPC tracebuffer");
    mcu_r5f_ddr                 = MemSection("DDR_MCU_R5F", "RWIX", mcu_r5f_ddr_addr, mcu_r5f_ddr_size, "DDR for MCU R5F for code/data");
    mcu_r5f_ddr_local_heap      = MemSection("DDR_MCU_R5F_LOCAL_HEAP", "RWIX", mcu_r5f_ddr_local_heap_addr, mcu_r5f_ddr_local_heap_size, "DDR for MCU R5F for local heap");
    mcu_r5f_ddr_total           = MemSection("DDR_MCU_R5F_DTS", "", 0, 0, "DDR for MCU R5F for all sections, used for reserving memory in DTS file");
    mcu_r5f_ddr_total.concat(mcu_r5f_ddr_resource_table);
    mcu_r5f_ddr_total.concat(mcu_r5f_ddr_ipc_tracebuf);
    mcu_r5f_ddr_total.concat(mcu_r5f_ddr);
    mcu_r5f_ddr_total.setDtsName("edgeai_mcu_r5fss0_core0_memory_region", "edgeai-r5f-memory");
    
    dm_r5f_ddr_ipc             = MemSection("DDR_DM_R5F_IPC", "RWIX", dm_r5f_ddr_ipc_addr, linux_ddr_ipc_size, "DDR for DM R5F for Linux IPC");
    dm_r5f_ddr_ipc.setDtsName("edgeai_dm_r5fss0_core0_dma_memory_region", "edgeai-dm-r5f-dma-memory");
    dm_r5f_ddr_resource_table  = MemSection("DDR_DM_R5F_RESOURCE_TABLE", "RWIX", dm_r5f_ddr_resource_table_addr, linux_ddr_resource_table_size, "DDR for DM R5F for Linux resource table");
    dm_r5f_ddr_ipc_tracebuf    = MemSection("DDR_DM_R5F_IPC_TRACEBUF", "RWIX", dm_r5f_ddr_ipc_tracebuf_addr, linux_ddr_ipc_tracebuf_size, "DDR for DM R5F for Linux IPC tracebuffer");
    ddr_fs_stub                = MemSection("DDR_FS_STUB", "RWIX", 0x9CA00000, (32*KB), "DDR for FS Stub binary");
    dm_r5f_ddr                 = MemSection("DDR_DM_R5F", "RWIX", 0x9CA08000, (28*MB), "DDR for DM R5F for code/data");
    dm_r5f_ddr_local_heap      = MemSection("DDR_DM_R5F_LOCAL_HEAP", "RWIX", dm_r5f_ddr_local_heap_addr, dm_r5f_ddr_local_heap_size, "DDR for DM R5F for local heap");
    dm_r5f_ddr_total           = MemSection("DDR_DM_R5F_DTS", "", 0, 0, "DDR for DM R5F for all sections, used for reserving memory in DTS file");
    dm_r5f_ddr_total.concat(dm_r5f_ddr_resource_table);
    dm_r5f_ddr_total.concat(dm_r5f_ddr_ipc_tracebuf);
    dm_r5f_ddr_total.concat(ddr_fs_stub);
    dm_r5f_ddr_total.concat(dm_r5f_ddr);
    dm_r5f_ddr_total.setDtsName("edgeai_dm_r5fss0_core0_memory_region", "edgeai-r5f-memory");
    
    c7x_1_ddr_ipc             = MemSection("DDR_C7x_1_IPC", "RWIX", c7x_1_ddr_ipc_addr, linux_ddr_ipc_size, "DDR for C7x_1 for Linux IPC");
    c7x_1_ddr_ipc.setDtsName("edgeai_c71_0_dma_memory_region", "edgeai-c71-dma-memory");
    c7x_1_ddr_resource_table  = MemSection("DDR_C7x_1_RESOURCE_TABLE", "RWIX", c7x_1_ddr_resource_table_addr, linux_ddr_resource_table_size, "DDR for C7x_1 for Linux resource table");
    c7x_1_ddr_ipc_tracebuf    = MemSection("DDR_C7X_1_IPC_TRACEBUF", "RWIX", c7x_1_ddr_ipc_tracebuf_addr, linux_ddr_ipc_tracebuf_size, "DDR for C7X_1 for Linux IPC tracebuffer");
    c7x_1_ddr_boot            = MemSection("DDR_C7x_1_BOOT", "RWIX", c7x_1_ddr_boot_addr, c7x_1_ddr_boot_size, "DDR for C7x_1 for boot section");
    c7x_1_ddr_vecs            = MemSection("DDR_C7x_1_VECS", "RWIX", c7x_1_ddr_vecs_addr, c7x_1_ddr_vecs_size, "DDR for C7x_1 for vecs section");
    c7x_1_ddr                 = MemSection("DDR_C7x_1", "RWIX", c7x_1_ddr_addr, c7x_1_ddr_size, "DDR for C7x_1 for code/data");
    c7x_1_ddr_local_heap_non_cacheable      = MemSection("DDR_C7X_1_LOCAL_HEAP_NON_CACHEABLE", "RWIX", c7x_1_ddr_local_heap_non_cacheable_addr, c7x_1_ddr_local_heap_non_cacheable_size, "DDR for c7x_1 for non cacheable local heap");
    c7x_1_ddr_scratch_non_cacheable         = MemSection("DDR_C7X_1_SCRATCH_NON_CACHEABLE", "RWIX", c7x_1_ddr_scratch_non_cacheable_addr, c7x_1_ddr_scratch_non_cacheable_size, "DDR for c7x_1 for non cacheable scratch Memory");
    c7x_1_ddr_local_heap      = MemSection("DDR_C7X_1_LOCAL_HEAP", "RWIX", c7x_1_ddr_local_heap_addr, c7x_1_ddr_local_heap_size, "DDR for c7x_1 for local heap");
    c7x_1_ddr_scratch         = MemSection("DDR_C7X_1_SCRATCH", "RWIX", c7x_1_ddr_scratch_addr, c7x_1_ddr_scratch_size, "DDR for c7x_1 for Scratch Memory");
    c7x_1_ddr_total           = MemSection("DDR_C7x_1_DTS", "", 0, 0, "DDR for C7x_1 for all sections, used for reserving memory in DTS file");
    c7x_1_ddr_total.concat(c7x_1_ddr_resource_table);
    c7x_1_ddr_total.concat(c7x_1_ddr_ipc_tracebuf);
    c7x_1_ddr_total.concat(c7x_1_ddr_boot);
    c7x_1_ddr_total.concat(c7x_1_ddr_vecs);
    c7x_1_ddr_total.concat(c7x_1_ddr);
    c7x_1_ddr_total.setDtsName("edgeai_c71_0_memory_region", "edgeai-c71-memory");
    
    tifs_lpm_mem       = MemSection("TIFS_LPM_CTX"        , "", tifs_lpm_ctx_addr       , tifs_lpm_ctx_size       , "TIFS LPM context save memory");
    atf_mem            = MemSection("ATF_MEM"        , "", atf_addr       , atf_size       , "ARM Trusted Firmware");
    optee_mem          = MemSection("OPTEE_MEM"        , "", optee_addr       , optee_size       , "Open Portable Trusted Execution Environment");
    
    # Shared memory memory sections in DDR
    app_log_mem            = MemSection("APP_LOG_MEM"        , "", app_log_mem_addr       , app_log_mem_size       , "Memory for remote core logging");
    tiovx_obj_desc_mem     = MemSection("TIOVX_OBJ_DESC_MEM" , "", tiovx_obj_desc_mem_addr, tiovx_obj_desc_mem_size, "Memory for TI OpenVX shared memory. MUST be non-cached or cache-coherent");
    app_fileio_mem        = MemSection("APP_FILEIO_MEM"        , "", app_fileio_mem_addr       , app_fileio_mem_size       , "Memory for remote core file operations");
    tiovx_log_rt_mem     = MemSection("TIOVX_LOG_RT_MEM" , "", tiovx_log_rt_mem_addr, tiovx_log_rt_mem_size, "Memory for TI OpenVX shared memory for Run-time logging. MUST be non-cached or cache-coherent");
    
    ipc_vring_mem      = MemSection("IPC_VRING_MEM"     , "", ipc_vring_mem_addr     , ipc_vring_mem_size     , "Memory for IPC Vring's. MUST be non-cached or cache-coherent");
    ipc_vring_mem.setDtsName("edgeai_rtos_ipc_memory_region", "edgeai-rtos-ipc-memory-region");
    ipc_vring_mem.setAlignment(True)
    ipc_vring_mem.setPrintCompatibility(False)
    ipc_vring_mem.setOriginTag(False);
    
    edgeai_ddr_total  = MemSection("DDR_EDGEAI_DTS", "", 0                      , 0                      , "DDR for EdgeAI for all sections, used for reserving memory in DTS file");
    edgeai_ddr_total.concat(app_log_mem);
    edgeai_ddr_total.concat(tiovx_obj_desc_mem);
    edgeai_ddr_total.concat(app_fileio_mem);
    edgeai_ddr_total.concat(tiovx_log_rt_mem);
    edgeai_ddr_total.setDtsName("edgeai_memory_region", "edgeai-dma-memory");
    
    # this region should NOT have the "no-map" flag since we want ION to map this memory and do cache ops on it as needed
    ddr_shared_mem     = MemSection("DDR_SHARED_MEM"    , "", ddr_shared_mem_addr    , ddr_shared_mem_size    , "Memory for shared memory buffers in DDR");
    ddr_shared_mem.setDtsName("edgeai_shared_region", "edgeai_shared-memories");
    ddr_shared_mem.setCompatibility("dma-heap-carveout");
    ddr_shared_mem.setNoMap(False);
    ddr_shared_mem.setOriginTag(False);
    
    edgeai_core_heaps = MemSection("DDR_EDGEAI_CORE_HEAPS_DTS", "", 0, 0, "EdgeAI Core Heaps in 32bit address range of DDR");
    edgeai_core_heaps.concat(mcu_r5f_ddr_local_heap);
    edgeai_core_heaps.concat(dm_r5f_ddr_local_heap);
    edgeai_core_heaps.concat(c7x_1_ddr_local_heap);
    edgeai_core_heaps.concat(c7x_1_ddr_scratch);
    edgeai_core_heaps.setDtsName("edgeai_core_heaps", "edgeai-core-heap-memory");
    
    #
    # Create CPU specific memory maps using memory sections created above
    #
    
    mcu_r5f_mmap = MemoryMap("mcu_r5f");
    mcu_r5f_mmap.addMemSection( mcu_r5f_tcma_vecs );
    mcu_r5f_mmap.addMemSection( mcu_r5f_tcma      );
    mcu_r5f_mmap.addMemSection( mcu_r5f_tcma_trace_buff      );
    mcu_r5f_mmap.addMemSection( mcu_r5f_tcmb0_vecs   );
    mcu_r5f_mmap.addMemSection( mcu_r5f_tcmb0        );
    mcu_r5f_mmap.addMemSection( mcu_r5f_tcmb0_trace_buff        );
    mcu_r5f_mmap.addMemSection( mcu_r5f_ddr_ipc       );
    mcu_r5f_mmap.addMemSection( mcu_r5f_ddr_resource_table  );
    mcu_r5f_mmap.addMemSection( mcu_r5f_ddr_ipc_tracebuf  );
    mcu_r5f_mmap.addMemSection( mcu_r5f_ddr           );
    mcu_r5f_mmap.addMemSection( app_log_mem          );
    mcu_r5f_mmap.addMemSection( tiovx_obj_desc_mem   );
    mcu_r5f_mmap.addMemSection( app_fileio_mem          );
    mcu_r5f_mmap.addMemSection( ipc_vring_mem        );
    mcu_r5f_mmap.addMemSection( mcu_r5f_ddr_local_heap  );
    mcu_r5f_mmap.addMemSection( ddr_shared_mem       );
    mcu_r5f_mmap.checkOverlap();
    
    dm_r5f_mmap = MemoryMap("dm_r5f");
    dm_r5f_mmap.addMemSection( mcu_r5f_tcma_vecs );
    dm_r5f_mmap.addMemSection( mcu_r5f_tcma      );
    dm_r5f_mmap.addMemSection( mcu_r5f_tcma_trace_buff      );
    dm_r5f_mmap.addMemSection( mcu_r5f_tcmb0_vecs   );
    dm_r5f_mmap.addMemSection( mcu_r5f_tcmb0        );
    dm_r5f_mmap.addMemSection( mcu_r5f_tcmb0_trace_buff        );
    dm_r5f_mmap.addMemSection( dm_r5f_ddr_ipc       );
    dm_r5f_mmap.addMemSection( dm_r5f_ddr_resource_table  );
    dm_r5f_mmap.addMemSection( dm_r5f_ddr_ipc_tracebuf  );
    dm_r5f_mmap.addMemSection( ddr_fs_stub  );
    dm_r5f_mmap.addMemSection( dm_r5f_ddr           );
    dm_r5f_mmap.addMemSection( app_log_mem          );
    dm_r5f_mmap.addMemSection( tiovx_obj_desc_mem   );
    dm_r5f_mmap.addMemSection( app_fileio_mem          );
    dm_r5f_mmap.addMemSection( ipc_vring_mem        );
    dm_r5f_mmap.addMemSection( dm_r5f_ddr_local_heap  );
    dm_r5f_mmap.addMemSection( ddr_shared_mem       );
    dm_r5f_mmap.checkOverlap();
    
    c7x_1_mmap = MemoryMap("c7x_1");
    c7x_1_mmap.addMemSection( c7x_1_l3           );
    c7x_1_mmap.addMemSection( c7x_1_l2           );
    c7x_1_mmap.addMemSection( c7x_1_l1           );
    c7x_1_mmap.addMemSection( c7x_1_ddr_ipc      );
    c7x_1_mmap.addMemSection( c7x_1_ddr_resource_table      );
    c7x_1_mmap.addMemSection( c7x_1_ddr_ipc_tracebuf        );
    c7x_1_mmap.addMemSection( c7x_1_ddr_boot     );
    c7x_1_mmap.addMemSection( c7x_1_ddr_vecs     );
    c7x_1_mmap.addMemSection( c7x_1_ddr          );
    c7x_1_mmap.addMemSection( app_log_mem        );
    c7x_1_mmap.addMemSection( tiovx_obj_desc_mem );
    c7x_1_mmap.addMemSection( app_fileio_mem        );
    c7x_1_mmap.addMemSection( ipc_vring_mem      );
    c7x_1_mmap.addMemSection( c7x_1_ddr_local_heap_non_cacheable  );
    c7x_1_mmap.addMemSection( c7x_1_ddr_scratch_non_cacheable  );
    c7x_1_mmap.addMemSection( c7x_1_ddr_local_heap  );
    c7x_1_mmap.addMemSection( c7x_1_ddr_scratch  );
    c7x_1_mmap.addMemSection( ddr_shared_mem     );
    c7x_1_mmap.checkOverlap();
    
    html_mmap = MemoryMap("System Memory Map for Linux+RTOS mode");
    
    html_mmap.addMemSection( c7x_1_l3           );
    html_mmap.addMemSection( c7x_1_l2           );
    html_mmap.addMemSection( c7x_1_l1           );
    html_mmap.addMemSection( mcu_r5f_ddr_ipc     );
    html_mmap.addMemSection( mcu_r5f_ddr_resource_table      );
    html_mmap.addMemSection( mcu_r5f_ddr_ipc_tracebuf      );
    html_mmap.addMemSection( mcu_r5f_ddr         );
    html_mmap.addMemSection( mcu_r5f_ddr_local_heap );
    html_mmap.addMemSection( dm_r5f_ddr_ipc     );
    html_mmap.addMemSection( dm_r5f_ddr_resource_table      );
    html_mmap.addMemSection( dm_r5f_ddr_ipc_tracebuf      );
    html_mmap.addMemSection( ddr_fs_stub      );
    html_mmap.addMemSection( dm_r5f_ddr         );
    html_mmap.addMemSection( dm_r5f_ddr_local_heap );
    html_mmap.addMemSection( c7x_1_ddr_ipc     );
    html_mmap.addMemSection( c7x_1_ddr_resource_table     );
    html_mmap.addMemSection( c7x_1_ddr_ipc_tracebuf     );
    html_mmap.addMemSection( c7x_1_ddr_boot    );
    html_mmap.addMemSection( c7x_1_ddr_vecs    );
    html_mmap.addMemSection( c7x_1_ddr_local_heap_non_cacheable );
    html_mmap.addMemSection( c7x_1_ddr_scratch_non_cacheable );
    html_mmap.addMemSection( c7x_1_ddr_local_heap         );
    html_mmap.addMemSection( c7x_1_ddr_scratch );
    html_mmap.addMemSection( c7x_1_ddr         );
    html_mmap.addMemSection( tifs_lpm_mem      );
    html_mmap.addMemSection( atf_mem      );
    html_mmap.addMemSection( optee_mem      );
    html_mmap.addMemSection( app_log_mem        );
    html_mmap.addMemSection( tiovx_obj_desc_mem );
    html_mmap.addMemSection( app_fileio_mem        );
    html_mmap.addMemSection( ipc_vring_mem      );
    html_mmap.addMemSection( ddr_shared_mem     );
    html_mmap.addMemSection( tiovx_log_rt_mem );
    html_mmap.checkOverlap();
    
    c_header_mmap = MemoryMap("Memory Map for C header file");
    c_header_mmap.addMemSection( c7x_1_l3           );
    c_header_mmap.addMemSection( c7x_1_l2           );
    c_header_mmap.addMemSection( c7x_1_l1           );
    c_header_mmap.addMemSection( mcu_r5f_ddr_ipc     );
    c_header_mmap.addMemSection( dm_r5f_ddr_ipc     );
    c_header_mmap.addMemSection( c7x_1_ddr_ipc     );
    c_header_mmap.addMemSection( mcu_r5f_ddr_total     );
    c_header_mmap.addMemSection( dm_r5f_ddr_total     );
    c_header_mmap.addMemSection( c7x_1_ddr_total     );
    
    c_header_mmap.addMemSection( mcu_r5f_ddr_local_heap);
    c_header_mmap.addMemSection( dm_r5f_ddr_local_heap);
    c_header_mmap.addMemSection( c7x_1_ddr_local_heap_non_cacheable);
    c_header_mmap.addMemSection( c7x_1_ddr_scratch_non_cacheable);
    c_header_mmap.addMemSection( c7x_1_ddr_local_heap);
    c_header_mmap.addMemSection( c7x_1_ddr_scratch);
    c_header_mmap.addMemSection( tiovx_log_rt_mem );
    c_header_mmap.addMemSection( app_log_mem        );
    c_header_mmap.addMemSection( tiovx_obj_desc_mem );
    c_header_mmap.addMemSection( app_fileio_mem        );
    c_header_mmap.addMemSection( ipc_vring_mem      );
    c_header_mmap.addMemSection( ddr_shared_mem     );
    c_header_mmap.checkOverlap();
    
    dts_mmap = MemoryMap("Memory Map for Linux kernel dts/dtsi file");
    dts_mmap.addMemSection( mcu_r5f_ddr_ipc     );
    dts_mmap.addMemSection( mcu_r5f_ddr_total   );
    dts_mmap.addMemSection( dm_r5f_ddr_ipc     );
    dts_mmap.addMemSection( dm_r5f_ddr_total   );
    dts_mmap.addMemSection( c7x_1_ddr_ipc      );
    dts_mmap.addMemSection( c7x_1_ddr_total    );
    dts_mmap.addMemSection( edgeai_ddr_total );
    dts_mmap.addMemSection( ipc_vring_mem      );
    dts_mmap.addMemSection( ddr_shared_mem     );
    dts_mmap.addMemSection( edgeai_core_heaps );
    dts_mmap.checkOverlap();
    
    #
    # Generate linker command files containing "MEMORY" definitions
    #
    LinkerCmdFile(c7x_1_mmap , "./c7x_1/linker_mem_map.cmd" ).export();
    LinkerCmdFile(dm_r5f_mmap, "./mcu1_0/linker_mem_map.cmd").export();
    
    HtmlMmapTable(html_mmap, "./system_memory_map.html").export();
    
    CHeaderFile(c_header_mmap, 0,0, "./app_mem_map.h").export();
    
    DtsFile(dts_mmap, "./k3-am62a7-sk.dts").export();
    

    After replacing the file with above code rebuild the SDK.

    Please let us know if the above solution works.

    Regards,

    Tushar

  • Hi Tushar,

    Thanks for the update. After taking the above mentioned python script, I am able to built the firmware. 

    Unfortunately, while running the edgeAI applications which is the final use case I am observing errors the below errors:

    MEM: ERROR: Alloc failed with status = 12 !!!
    157.730040 s: VX_ZONE_ERROR:[tivxMemBufferAlloc:90] Shared mem ptr allocation failed
    MEM: ERROR: Alloc failed with status = 12 !!!
    157.731135 s: VX_ZONE_ERROR:[tivxMemBufferAlloc:90] Shared mem ptr allocation failed
    MEM: ERROR: Alloc failed with status = 12 !!!
    157.732476 s: VX_ZONE_ERROR:[tivxMemBufferAlloc:90] Shared mem ptr allocation failed
    MEM: ERROR: Alloc failed with status = 12 !!!
    157.747750 s: VX_ZONE_ERROR:[tivxMemBufferAlloc:90] Shared mem ptr allocation failed

    I am using the memory mapping as shown below. I took the reference from the Firmware Builder User Guide:

    Partition Start Address Size
    DDR_C7x_1_IPC 0x99800000 1024.00 KB
    DDR_C7x_1_RESOURCE_TABLE 0x99900000 1024.00 B
    DDR_C7X_1_IPC_TRACEBUF 0x99900400 1023.00 KB
    DDR_C7x_1_BOOT 0x99A00000 1024.00 B
    DDR_C7x_1_VECS 0x99C00000 16.00 KB
    DDR_C7x_1 0x99C10000 15.94 MB
    DDR_MCU_R5F_IPC 0x9B800000 1024.00 KB
    DDR_MCU_R5F_RESOURCE_TABLE 0x9B900000 1024.00 B
    DDR_MCU_R5F_IPC_TRACEBUF 0x9B900400 1023.00 KB
    DDR_MCU_R5F 0x9BA00000 14.00 MB
    DDR_DM_R5F_IPC 0x9C800000 1024.00 KB
    DDR_DM_R5F_RESOURCE_TABLE 0x9C900000 1024 B
    DDR_DM_R5F_IPC_TRACEBUF 0x9C900400 1023.00 KB
    DDR_DM_R5F 0x9CA00000 29.00 MB
    TIFS_LPM_CTX 9E700000 512.00 KB
    ATF_MEM 9E780000 512.00 KB
    OPTEE_MEM 9E800000 24.00 MB
    IPC_VRING_MEM A0000000 16.00 MB
    APP_LOG_MEM A1000000 256.00 KB
    TIOVX_OBJ_DESC_MEM A1040000 15.75 MB
    TIOVX_LOG_RT_MEM A2000000 16.00 MB
    DDR_SHARED_MEM A3000000 96.00 MB
    DDR_MCU_R5F_LOCAL_HEAP A9000000 16.00 MB
    DDR_DM_R5F_LOCAL_HEAP AA000000 16.00 MB
    DDR_C7X_1_LOCAL_HEAP_NON_CACHEABLE AB000000 16.00 MB
    DDR_C7X_1_SCRATCH_NON_CACHEABLE AC000000 16.00 MB
    DDR_C7X_1_LOCAL_HEAP AD000000 32.00 MB
    DDR_C7X_1_SCRATCH 0xAF000000 16.00 MB

    Does the partitioning is having any issue? Or whether I need to handle any extra partitions in the memory map table?

    Regards,

    Ann Rose Antony

  • Hi Antony,

    Are you not following the memory section specified in the firmware builder documentation?

    Please refer Current Memory Map for more info. 

    Regards,

    Tushar

  • Hi Tushar,

    I am following the documentation, but I am updating the memory partitions to make the DDR size to 1GB.

    Regards,

    Ann Rose Antony

  • Hi Rose,

    I can see in the above memory partition you have configured the DDR_SHARED_MEM region to 96 MB which is by default configured to 176MB.

    MEM: ERROR: Alloc failed with status = 12 !!!
    157.747750 s: VX_ZONE_ERROR:[tivxMemBufferAlloc:90] Shared mem ptr allocation failed

    From the above error logs also it seems that the application is failing at shared mem ptr allocation. Can you please try increasing the size of DDR_SHARED_MEM memory region and check are you still getting the error or not?

    Regards,

    Tushar

  • Hi Tushar,

    We increased the DDR_SHARED_MEM and able to run the demo application. 

    Thanks for the support.

    Regards,

    Ann Rose Antony

  • Hi Antony,

    Thanks for the confirmation.

    Closing the thread.

    Thanks for the support.

    Happy to help. Slight smile

    Regards,

    Tushar