array parameter passing

10 thoughts on “array parameter passing

  1. Hello,

    I am attemtping to port some code to run in AppZone on a GE910-QUAD. I’m using the GCC 4.9.3 provided with AppZone. I have an issue where parameters that are pointers to arrays of pointers are not working.  For example:

    static char const * const testlist[] = { “first”, “second”, “third” };

    void param(char const * const p[])
    {
        PrintToUart(“param first:%sn”, p[0]);
        PrintToUart(“param first address %08xn”, p[0]);
    }

    void direct(void)

    {

        PrintToUart(“AppzoneSerfDC Startupn”);
        PrintToUart(“first:%sn”, st), testlist[0]);
        PrintToUart(“first address %08xn”, testlist[0]);
        param(testlist);

    }

    The output is as follows:

    AppzoneSerfDC Startup
    first:first
    first address 6034d565
    param first:lvl
    param first address 4002f55d

    When the pointer is passed to the function, the output is corrupt. Is this a know issue with this compiler?

    Thanks,

    Jim

    1. Hi,
      there are known problems concerning dynamic relocation performed at runtime. The GCC toolchain used to compile the application cannot handle properly dynamic relocation causing pointers and arrays to target invalid addresses. We are working in order to fix this problem but it will take some time. 

      As a workaround you should try to assign the array runtime for example using an init function at the beginning on the code. 

      1. Thanks for the reply Cosmin,

        The function receives the address of the array of pointers correctly, but the dereference of the pointers in the array are incorrect. Is it possible for me to try this with a newer version of GCC?

        Regards,

        Jim Hartmann

        1. Hi,
          the problem will remain also changing the compiler. You can try this workaround to see if it works:

          1. Compile the application and flash it into the module
          2. Run the application on the module using AT+M2M=4,10,2

          While is running in another AT instance send this command:

          AT#M2MBA

          which will return the application base addresses.

          e.g for example:

          AT#M2MBA –ro_base 0x50000008 –rw_base 0x50016510

          OK

          where –ro_base is the starting address of the ROM (which contains the application) and –rw_base is the starting address of the RAM (data segment)

           

          3. Then, you will have to go in the AppZone SDK folder, arm_gcc493 subfolder and find the two  mod.dl and mod.ld script files. You will have to modify them according to the previously obtained base addresses.

          mod.dl:

          __ROM__ = 0x50000008; __RAM__ = 0x50016510;

          mod.ld

          MEMORY
          {
            FLASH (rx) : ORIGIN = 0x50000008, LENGTH = 0x00100000
            RAM   (wx) : ORIGIN = 0x50016510, LENGTH = 0x00400000
          }

          4. Save everything, clean and recompile the application (pay attention to leave its code unchanged!! ) and flash it again into the module.

          5. Now, the pointers targets should be correct, since we have provided the real runtime addresses to the linker and dynamic loader.

          Also, it is better that the FLASH and RAM address ranges do not overlap (i.e. the ROM length should not be bigger than (RAM start address ) – (ROM start address).

          in my example, 0x50016510 – 0x50000008 = 0x16508, so the mod.ld FLASH line should look like

          FLASH (rx) : ORIGIN = 0x50000008, LENGTH = 0x00016508

           

          Since the ROM and RAM base addresses need to be stored in the nvm during the module run time, it would be a good idea to put a starting delay in the application main, something like m2m_os_sleep_ms(3000) should be enough. In this way, even if the application crashes right away, the addresses will be stored.


          Unfortunately every time you change your code, you have to do again this procedure.. As I said, we are working on solution for this, but it will take time and testing.

           

          I hope that this would help.

          1. Hi Cosmin,

            I tried using the command AT#M2MBA on the 2nd instance on USB. If I execute it before the appzone starts, the response is “ERROR”. Once the appzone times out and starts, there is no longer a response on the second AT port, I presume because my application has crashed and hung the modem. 

            Thanks,

            Jim

          2. The AT#M2MBA command is not available on GE910 modules. That’s why the customer receives the ERROR message. Also, AT+M2M=4,10,2 is not supported (the third parameter). Only AT+M2M=4,10 is supported on that module.

            Also, how did you get the step by step procedure with AT#M2MBA? I wrote it some time ago (I recognized the text formatting in your post), but that command is not documented, so the procedure should be shared carefully.

          3. The AT#M2MBA command is not available on GE910 modules. That’s why the customer receives the ERROR message. Also, AT+M2M=4,10,2 is not supported (the third parameter). Only AT+M2M=4,10 is supported on that module.

            Also, how did you get the step by step procedure with AT#M2MBA? I wrote it some time ago (I recognized the text formatting in your post), but that command is not documented, so the procedure should be shared carefully.

            Hi Cosmin,

            You posted the procedure above. Is there a procedure that works with the GE910?

            Thanks,

            Jim

          4. Hi Cosmin,

            I tried using the command AT#M2MBA on the 2nd instance on USB. If I execute it before the appzone starts, the response is “ERROR”. Once the appzone times out and starts, there is no longer a response on the second AT port, I presume because my application has crashed and hung the modem. 

            Thanks,

            Jim

            Hi Jim, unfortunately on the GE910 there is not a procedure to overcome the dynamic relocation issue. The SW team is working on it, but it will take a long time.. You will have to write the code compliant with a relocating system (that is, using an init function that initializes all arrays at runtime). Defining the arrays data in compilation time will not work. I am sorry for the unconvenience.

            Regards

            Fabio

          5. Hi Cosmin,

            I tried using the command AT#M2MBA on the 2nd instance on USB. If I execute it before the appzone starts, the response is “ERROR”. Once the appzone times out and starts, there is no longer a response on the second AT port, I presume because my application has crashed and hung the modem. 

            Thanks,

            Jim

            Hi Jim, unfortunately on the GE910 there is not a procedure to overcome the dynamic relocation issue. The SW team is working on it, but it will take a long time.. You will have to write the code compliant with a relocating system (that is, using an init function that initializes all arrays at runtime). Defining the arrays data in compilation time will not work. I am sorry for the unconvenience.

            Regards

            Fabio

            Hi Fabio,

            I am checking back to see if any new releases are available for AppZone that will allow us to use it in the manner described in this thread? Alternatively, is there another modem besides the GE910 that we could target?

            Best Regards,

            Jim Hartmann

          6. Hi Jim, unfortunately on the GE910 there is not a procedure to overcome the dynamic relocation issue. The SW team is working on it, but it will take a long time.. You will have to write the code compliant with a relocating system (that is, using an init function that initializes all arrays at runtime). Defining the arrays data in compilation time will not work. I am sorry for the unconvenience.

            Regards

            Fabio

            Hi Fabio,

            I am checking back to see if any new releases are available for AppZone that will allow us to use it in the manner described in this thread? Alternatively, is there another modem besides the GE910 that we could target?

            Best Regards,

            Jim Hartmann

            Hi Jim,

            At the moment the GE910 module still uses dynamic relocation, but it is planned to change to a static relocation architecture. However, I do not have any ETA for the release date, I am sorry. AT#M2MBA is still unsupported, but with static relocation it will become useless.

            On the other hand, we already have a beta firmware release for HSPA modules, such as the HE910 module (which, in any case, already supported AT#M2MBA command), which uses static relocation by default, resolving compile-time arrays definition issues (the object of this thread). Also, HE910 module provides more RAM for the application than GE910 and there are more AppZone APIs available (GE910 will eventually receive them, too ). HSPA platform is also more tested on AppZone side.

            Best Regards,

            Fabio Pintus