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.

AUDIO-AM275-EVM: Unable to Pass Valid argv[] Content via loadti for C7x Application on AM275x

Part Number: AUDIO-AM275-EVM


Tool/software:

Hi TI Team,

I'm working on the AM275x platform and trying to pass command-line arguments to main() using loadti. I referred to the script at:
`C:\ti\ccs2011\ccs\ccs_base\scripting\examples\loadti\loadti.bat` which mentions support for passing up to 40 parameters.

To test this, I modified the hello_world example with the following code:

int main(int argc, char *argv[]) {
    printf("Argument count: %d\n", argc);
    for (int i = 0; i < argc; ++i) {
        printf("argv[%d]: %s\n", i, argv[i]);
    } ...
}

Then I ran the following command to load and execute the program:

C:\ti\ccs2011\ccs\ccs_base\scripting\examples\loadti\loadti.bat -q -c "C:/ti_config/AM275X_XDS110.ccxml" "C:\ti\AM275-AWE-SDK_11.00.00.17\mcu_plus_sdk\am275x\examples\hello_world\am275x-evm\c75ss0-0_freertos\build\hello_world_c7X.out" "-h" "-S" "-M"

Observed Output:

testEnv.outFiles: C:\ti\AM275-AWE-SDK_11.00.00.17\mcu_plus_sdk\am275x\examples\hello_world\am275x-evm\c75ss0-0_freertos\build\hello_world_c7X.out
Argument count: 4
argv[0]:
argv[1]:
argv[2]:
argv[3]:

So, while argc reflects the correct number of arguments (4), all entries in argv[] are empty strings.

Could you please confirm:

  • Is this the expected behavior?

  • If not, is there a specific way to ensure the argument values are passed correctly to argv[] when using loadti?

  • Alternatively, is there another supported method to simulate passing runtime arguments to a C7x application via JTAG?

Any guidance or examples would be greatly appreciated.

Thanks,

  • Hello,

    To test this, I modified the hello_world example with the following code:

    int main(int argc, char *argv[]) {
        printf("Argument count: %d\n", argc);
        for (int i = 0; i < argc; ++i) {
            printf("argv[%d]: %s\n", i, argv[i]);
        } ...
    }

    Then I ran the following command to load and execute the program:

    Did you also enable the linker option to allocate the .args section to support this in your application?

    Section 3.6 of: https://www.ti.com/lit/ug/spruig8k/spruig8k.pdf

    Thanks

    ki

  • Hi Ki,

    I figured out the issue, argv[] passed on to the main is wrong, whereas __c_args__ memory is intact.

    Example code:
    ```

    #include <stdio.h>
    #include <stdint.h>

    int main_wrap(int argc, char *argv[])
    {
        printf("In main_wrap()\n");
        printf("Address of argc: %p, value: %d\n", (void *)&argc, argc);
        printf("Address of argv: %p, value: %p\n", (void *)&argv, (void *)argv);
        

        for (int i = 0; i < argc; ++i) {
            printf("argv[%d] @ %p = \"%s\"\n", i, (void *)argv[i], argv[i]);
        }

        return 0;
    }

    extern void * __c_args__;

    void main(int _argc, char *_argv[]) {

        printf("In main()\n");
        printf("Address of argc: %p, value: %d\n", (void *)&_argc, _argc);
        printf("Address of argv: %p, value: %p\n", (void *)&_argv, (void *)_argv);
        printf("---------------------------------------");

        uint8_t *base = (uint8_t *)&__c_args__;
        uint32_t argc = *(uint32_t *)base;
        char **argv = (char **)(base + 4);
        main_wrap(argc, argv);
    }

    ```
    Result for the same test as earlier:
    ```
    In main()
    Address of argc: 7e007fe8, value: 4
    Address of argv: 7e007fe0, value: 7e00b664
    ---------------------------------------In main_wrap()
    Address of argc: 7e007fb0, value: 4
    Address of argv: 7e007fa8, value: 7e00b660

    argv[0] @ 7e00b688 = "hello_world_c7X.out"
    argv[1] @ 7e00b69c = "-h"
    argv[2] @ 7e00b69f = "-S"
    argv[3] @ 7e00b6a2 = "-M"
    ```