Contiki: Error if ELF File contains calculation with several unsinged int

被刻印的时光 ゝ 提交于 2019-12-13 05:19:55

问题


I encountered some problems while working with the contiki ELF-loader and hope that someone would be so kind to provide me more insight or some hints to solve these problems. In the following I try to keep the problem description short.

My aim is to:

  • Execute an ELF file on a T-Mote-Sky.

  • This ELF file contains a contiki process with a computation (linear regression of data samples over time).

  • Using "cooja" for simulation

Code specific information:

  • ELF file size about 2000 bytes

  • quite large computation of several unsigned-int-16 numbers:


    for (i = 0; i < 10; i++) {
    sum_x += records[i].index;
    sum_y += records[i].energy;
    sum_xx += ((uint16_t) records[i].index) * ((uint16_t) records[i].index);
    sum_xy += ((uint16_t) records[i].index) * ((uint16_t) records[i].energy);
    }
    slope = ((size * sum_xy) - (sum_x * sum_y)) / ((size * sum_xx) - (sum_x * sum_x));

  • "records" is initialised and defined in the main process, which calls the elfloader, and is accessed via the extern definition

  • it works if I use constants for the computation

Problems:

  • if I try to use multiplication with "*" it leads to the error message: Symbol not found: __MPY

  • if I try to use division with "/" it leads to a similar error message

    • so my workaround is that the multiplications and divisions are based upon additions, and it works (in most cases)
  • Still, I get the error: "Segment not found:" as soon as I try to calculate the slope.

    • I deduce its an issue with the memory size or trying to get data from the main process via extern, because calculating the slope works if I use constants only.

Many thanks in advance for your help and best regards,

Ca Way Le


回答1:


I had a similar problem (symbol not found) when trying to load an elf file containing calculations with floats, so I used a workaround in case anyone is interested

  • Compile the elf file

    make elfname.ce SMALL=0
    
  • Open the elf file with a hex viewer and locate the part where symbols are stored. It is near the end of file.

  • Let's assume that the symbols stored there are: timer_set __addsf3 __subsf3, printf puts autostart_processes. (The name of the process to be loaded is also among these values, but ignore it)
  • Create a new file mysymbols.c in the project directory with the following contents

    #include "loader/symbols.h"
    
    extern int __addsf3();
    extern int __subsf3();
    extern int etimer_set();
    int printf(const char *, ...);
    extern int puts();
    
    const int symbols_nelts = 7;
    const struct symbols symbols[7] = {
    { "__addsf3", (void *)&__addsf3 },
    { "__subsf3", (void *)&__subsf3 },
    { "autostart_processes", (void *)&autostart_processes },
    { "etimer_set", (void *)&etimer_set },
    { "printf", (void *)&printf },
    { "puts", (void *)&puts },
    { (const char *)0, (void *)0} };
    

    (notice that the symbols must be sorted)

  • Add the following code in the makefile

    ifdef CORE
    .PHONY: symbols.c symbols.h
    symbols.c:
         $(NM) $(CORE) | awk -f $(CONTIKI)/tools/mknmlist > symbols.c
    else
         symbols.c symbols.h:
         cp mysymbols.c symbols.c
         cp ${CONTIKI}/tools/empty-symbols.h symbols.h
    endif
    
  • Now compile the file which contains the main process

    make TARGET=sky clean CLEAN=symbols.?
    make your-file.sky TARGET=sky SMALL=0
    
  • Load the elf file to the mote running the main process and see what happens when the elfloader loads the elf

This worked for me for the case of symbol not found error.



来源:https://stackoverflow.com/questions/26240516/contiki-error-if-elf-file-contains-calculation-with-several-unsinged-int

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!