Programmatic use of load module - VxWorks

This is a discussion on Programmatic use of load module - VxWorks ; Hello, I have read the windriver tech tip 4179, which explains how to programmaticaly load modules from RAM/ROM. I am interested in doing this, since I want to split my code in multiple modules on my standalone application: updating my ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Programmatic use of load module

  1. Programmatic use of load module

    Hello,

    I have read the windriver tech tip 4179, which explains how to
    programmaticaly load modules from RAM/ROM.

    I am interested in doing this, since I want to split my code in
    multiple modules on my standalone application: updating my code would
    only require updating a couple of modules (the link to my standalone
    application has a very limited bandwidth). Also at startup, I would be
    able to load different modules, and chose which version of my code to
    run.

    However, I have encoutered 2 major problems:

    1) I intend to load code modules from flash from UsrAppInit. There is a
    problem though: from UsrAppInit, I cannot invoke any function from the
    modules I intend to load, since these functions are not defined in the
    scope of the bootable image. I have tried a forward declaration of
    these functions (using extern, which works for downloadable
    applications) but the code just does not compile ("undefined
    reference").

    2) When modules have a cyclic relationship - Module A invokes Module B,
    and Module B invokes Module A - the sequential VxWorks loader does not
    work. Since loading Module A first will generate errors due to
    undefined symbols from Module B, and vice versa. I have tried to
    declare a "fake" module B in module A (create an empty library, used to
    register Module B symbols in the symbol table). Then I load module B to
    overwrite the fake symbols defined by module A. The idea is to
    pre-register module B's symbols when module A is loaded.
    >From what I read in the VxWorks user's guide on page 259, this is

    possible: "The system symbol table allows name clashes to occur. For
    example, suppose a function func exists in the system. A second symbol
    named func is added to the system symbol table as part of a load. From
    this point, all links to func are to the most recently loaded
    symbol...". I have tried multiple options for the loader, but it just
    does not work: the symbols defined by module B, even if they use the
    same name do not overwrite the fake symbols defined by module A.

    Could someone help me please?

    Thank you in advance!

    Jean-Sebastien


  2. Re: Programmatic use of load module

    Jeanseb said the following:
    [snip]
    > 1) I intend to load code modules from flash from UsrAppInit. There is a
    > problem though: from UsrAppInit, I cannot invoke any function from the
    > modules I intend to load, since these functions are not defined in the
    > scope of the bootable image.

    [snip]
    You'll have to use function pointer, which you initialize after module load.
    Look into symLib to find out how to get the addresses.
    > 2) When modules have a cyclic relationship

    [snip]
    No cyclic relation allowed! All symbols must be resolved while download
    and won't ever be changed.
    If you update a module, unload the old one, load the new one and refresh
    the function pointers of the unmodified modules.

    !!! Take special care that the processor does not try to call a function
    in one of the changed modules while you try to update !!!

    HTH
    Michael

  3. Re: Programmatic use of load module


    Jeanseb wrote:
    > Hello,
    >
    > I have read the windriver tech tip 4179, which explains how to
    > programmaticaly load modules from RAM/ROM.
    >
    > I am interested in doing this, since I want to split my code in
    > multiple modules on my standalone application: updating my code would
    > only require updating a couple of modules (the link to my standalone
    > application has a very limited bandwidth). Also at startup, I would be
    > able to load different modules, and chose which version of my code to
    > run.
    >
    > However, I have encoutered 2 major problems:
    >
    > 1) I intend to load code modules from flash from UsrAppInit. There is a
    > problem though: from UsrAppInit, I cannot invoke any function from the
    > modules I intend to load, since these functions are not defined in the
    > scope of the bootable image. I have tried a forward declaration of
    > these functions (using extern, which works for downloadable
    > applications) but the code just does not compile ("undefined
    > reference").
    >
    > 2) When modules have a cyclic relationship - Module A invokes Module B,
    > and Module B invokes Module A - the sequential VxWorks loader does not
    > work. Since loading Module A first will generate errors due to
    > undefined symbols from Module B, and vice versa. I have tried to
    > declare a "fake" module B in module A (create an empty library, used to
    > register Module B symbols in the symbol table). Then I load module B to
    > overwrite the fake symbols defined by module A. The idea is to
    > pre-register module B's symbols when module A is loaded.
    > >From what I read in the VxWorks user's guide on page 259, this is

    > possible: "The system symbol table allows name clashes to occur. For
    > example, suppose a function func exists in the system. A second symbol
    > named func is added to the system symbol table as part of a load. From
    > this point, all links to func are to the most recently loaded
    > symbol...". I have tried multiple options for the loader, but it just
    > does not work: the symbols defined by module B, even if they use the
    > same name do not overwrite the fake symbols defined by module A.
    >
    > Could someone help me please?
    >
    > Thank you in advance!
    >
    > Jean-Sebastien


    Jean,
    There are some info I have gathered from this group which may be
    relevant to your query.I am pasting it below for your reference.I
    believe it will be of help to you,Though I am not exactly sure how far
    this will be solving your query.


    Collected info:
    --------------------------------------------------
    Hi,

    I have two VxWorks images in flash. I boot from one of the images. I
    image
    I boot from to transfer the second image into RAM and run it. I can
    transfer the second image into RAM but I am not sure how to run it.

    Can anybody offer any ideas?

    Dan J

    Michael R. Kesti (mkesti@gv.net)
    After the second image is loaded into memory (presumably using
    loadModule()
    or loadModuleAt() ), use symFindByName() to locate that image's entry
    point
    and then call the entry point.

    Is loadModuleAt() not used for loading .out files? I have a bootable
    VxWorks image?
    Dan J


    Bill Pringlemeir (spam_account@sympatico.ca)
    This is true. You will have to make a modification to the vxWorks RAM
    image. Specifically, you have to look at if it is going to setup
    memory mappings. For instance, the RAM image may assume that it is
    loaded at a particular memory address. Is the RAM image compressed,
    etc. You also didn't mention if the RAM image was pre-built, you are
    creating it with the project, or via a makefile.

    In any case, there are several possibilities. You jump to the first of
    the image. This is usually romInit.s, etc. If the image is not
    compressed and just assumes that it is loaded at the right place, then
    a jump to "usrInit()" might work. Some images have this address
    placed at a fixed offset in the image.

    btw, there was no way for Michael to know that you are loading a
    binary image versus a elf/coff file. Can you see the need to give
    more info?

    fwiw,
    Bill Pringlemeir.

    shafi (shafi4u@rediffmail.com)
    Jump to the starting entry routine location on the second image you
    loaded on the RAM. check bootConfig.c sample file. That's what it does
    there using a function 'go' to jump and execute the image loaded.
    ----------------------------- ends here----------------


    Query 2:

    JT (mail@mail.mail)
    163)Hi,

    I am trying to keep my VxWorks image and my application image separate.

    Maybe that is really not necessary, but in our product we will quite
    often
    be upgrading the application. So I thought it would be a good idea to
    keep
    the VxWorks image (boot-image), separate from the application.

    The problem is: How do I link the VxWorks-image to my application image

    when
    my application image is changing all the time?

    My plan is to place the application image on the target hard disk. This

    provides for easy means for our customers to upgrade to new versions of

    our
    application. The VxWorks image will then, in usrAppInit(), perform a
    loadModule() to load our application module from disk to memory.

    The plan is then to call "MyApplicationStart()". However, I can not
    link the
    VxWorks image directly to my application, as the application will
    change
    over and over again, and thus the address of MyApplicationStart().
    Therefore
    I get problems when builing the VxWorks image.

    So, what is the best way to achieve this? Could I search for
    MyApplicationStart() in the SymTable after performing the loadModule?
    Or is
    there any other way of linking the VxWorks-image to something that will

    be
    dynamically loaded?

    Thanks for any help!

    Best regards,

    Jostein Trones
    1

    Tapani Leppänen (tapani.leppanen@heinolapoistatamasm.fi)
    I dont know about the "best way", but this is what we do. We load the
    VxWorks image separately and use startup script in boot parameter to
    specify
    script file. That file loads our application and starts it.

    example of bootparams

    .........

    target name (tn) : phobos

    startup script (s) : /flashDisk/test.sct

    other (o) : ei

    ..........

    example of test.sct file

    -----------

    cd "/flashDisk/contcom/bin"

    ld
    applicationInit(2)

    -----------

    regards,

    Tapani


    JT (mail@mail.mail)
    Hi, thanks!

    I actually got it to work myself, in a different way. In usrAppInit()
    (in
    the VxWorks image), I use loadModule() to load our application module,
    then
    I use symFindByName() to find the address of my start-function.

    Works well!

    Thanks for your input!

    -jostein

    forums_mp@hotmail.com)
    ----------------------- ends here---------------

    Query 3:
    Hi Everyone.


    Did you use 'loadModule()' in vxWorks 5.5?
    After loadModule(), I want to start a task in the module.
    what do I do?


    Example>
    /*----------------------------*----------------------*/
    /* Source Code */
    void foo(void)
    {
    printf("Hello!");



    }


    in foo.o

    /*----------------------------*----------------------*/
    /* LoadModule */
    void usrAppInit (void)
    {
    fdX = open ("/devX/foo.o", O_RDONLY);
    loadModule (fdX, LOAD_ALL_SYMBOLS);
    close (fdX);



    }


    and

    I want to start foo function..


    Help me!


    Use symFindByName to get the address of foo() and call that address.
    -----------------------------------------------ends here--------------

    Query 4:
    272)Hi,


    I'm attempting to load a .out file into RAM and extract a smbol from
    the
    module using symFindByName. I cannot work out how I find a value for
    the
    first parameter (SYMTAB_ID symTblId) to this function for the symbol
    table
    I haver loaded using loadModule?


    Any suggestions?


    Daniel.


    #include
    #include

    f()
    {
    char * pValue;
    SM_TYPE pType;


    if (symFindByName(sysSymTbl, "whatever", &pValue, &pType) == OK) {
    ...
    }
    else
    ; /* error */


    Hi,


    If the .out file I load already contains some symbols that are already
    in
    the symbol table, how will the OS cope. I want the symbols in the .out
    file
    to take presedence.


    I have noticed when you download an two versions of an .out file to a
    target
    the shell displays an option with the version of the symbol you want to

    invoke if you attempt to run a function for example.


    Regards,


    Daniel


    Hi,


    For some reason, the loadModule function returns a failure. I transfer
    a
    ..out file from flash into RAM using the 'write' function with an
    associated
    file descriptor. I then pass this file descriptor to the loadModule
    function and a NULL value is returned.


    Why might this happen? Could it be because I'm running the test code
    as a
    downloadable object as well? Something to do with the symbol table
    setup?


    Regards,


    Daniel

    See below for the code I'm using. I have created a file called
    File.out
    which contains a symbol I want to call (called 'main').


    I download another piece of test code called loader in an .out file and
    run
    it from the shell. It attempts to load the File.out
    file and extract the symbol but fails the loadModule function. I can
    use
    the ld < File.out from the shell to load the file from
    my host o the host but I need to be able to do this just the target.


    Any idea's why the loadModule function fails?


    Daniel.


    #include "pxlib.h"
    #include "ioLib.h"
    #include "loadlib.h"
    #include "ramDrv.h"
    #include "dosFsLib.h"
    #include "symLib.h"
    #include "sysSymtbl.h"


    void loader(void)
    {
    char fullFileNameForRAM[46];
    int fd;
    FUNCPTR start;
    UINT8 symType;
    int tid;
    STATUS rc;
    char buff[100];


    // Extract the .out file with the 'main' symbol
    // out of flash (BSP function). The flash
    // file system doesn't support file descriptors
    PX_Ptr px = PX::GetPX();
    PXFlashObject_Ptr fobj = px->GetFlashObject("File.out")*;


    // Check the file was successfully
    // retrieved.
    if(fobj != 0)
    {
    // Create a RAM device
    BLK_DEV* blk = ramDevCreate(0, 1024, 0, 50176, 0);


    if(blk != NULL)
    {
    // Create a file system
    DOS_VOL_DESC* pVolDesc= dosFsMkfs("/ram", blk);


    // Construct the file name for the
    // fd to be created
    memset(fullFileNameForRAM, 0, 46);


    strcat(fullFileNameForRAM, (const char*)"/ram/File.out");


    fd = creat(fullFileNameForRAM, 2);


    // Write the contents of the flash file (.out)
    // to the fd
    write(fd, (char*)fobj->GetData(), fobj->GetSize()));


    // Attempt to load the symbols
    // THIS IS WHERE IS FAILS
    if((loadModule(fd, LOAD_ALL_SYMBOLS)) == NULL)
    {
    printf("Error in load module\n");
    }
    else
    {
    printf("No error in loading\n");
    }


    if(symFindByName(sysSymTbl, "main", (char**)&start, &symType)
    ==
    OK)
    {
    printf("Symbol found\n");
    }
    else
    {
    printf("Symbol not found\n");
    }
    }
    else
    {
    printf("RAM Device creation failed\n");
    }
    }
    else
    {
    printf("Failure to extract file from Flash\n");
    }


    }

    Could be that this is the problem. main is a name you should not use in

    VxWorks, as it is reserved for the OS itself. Try it again with the
    main
    symbol renamed to (for example) my_main.
    What is the value of errno after the call to loadModule?

    Kind regards,
    Johan
    --------------------------------------------------------------


    Hope you would have understood it from the above 4 querys how to do
    it.Another alternative is to google here with in this group for 2
    functions LoadModule() and SymFindByName() which will further help you
    to know about dynamic loading.

    Regards,
    s.subbarayan


+ Reply to Thread