Contiki:如果ELF文件包含带有多个未指定int的计算,则会出错 [英] Contiki: Error if ELF File contains calculation with several unsinged int

查看:152
本文介绍了Contiki:如果ELF文件包含带有多个未指定int的计算,则会出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用contiki ELF装载机时,我遇到了一些问题,希望有人能为我提供更多的见解或解决这些问题的提示.在下文中,我尝试使问题描述简短.

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.

我的目标是:

  • 在T-Mote-Sky上执行ELF文件.

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

此ELF文件包含带有计算的contiki进程 (数据样本随时间的线性回归).

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

使用"cooja"进行仿真

Using "cooja" for simulation

代码特定信息:

  • ELF文件大小约为2000字节

  • ELF file size about 2000 bytes

对多个unsigned-int-16数字进行了大量计算:

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));


  • 记录"是在主过程中初始化和定义的, 会调用elfloader,并通过extern定义进行访问


    • "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

      问题:

      • 如果我尝试对"*"使用乘法,则会导致 错误消息:Symbol not found: __MPY

      • 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.

      • 我推断出它与内存大小有关的问题 或尝试通过extern从主流程中获取数据, 因为如果仅使用常数,则计算斜率会起作用.
      • 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

      Ca Way Le

      推荐答案

      在尝试加载包含带浮点数的elf文件时,我遇到了类似的问题(未找到符号),因此在有人感兴趣的情况下,我使用了一种变通办法

      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

      • 编译elf文件

      • Compile the elf file

      make elfname.ce SMALL=0
      

    • 使用十六进制查看器打开elf文件,然后找到存储符号的部分.它在文件末尾附近.

    • Open the elf file with a hex viewer and locate the part where symbols are stored. It is near the end of file.

      在项目目录中创建具有以下内容的新文件 mysymbols.c

      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} };
      

      (注意符号必须排序)

      在makefile中添加以下代码

      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
      

    • 将elf文件加载到运行主进程的节点上,并查看elfloader加载elf时会发生什么情况

    • 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.

      这篇关于Contiki:如果ELF文件包含带有多个未指定int的计算,则会出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆