I am trying to make a sensor that runs on Contiki OS to execute a new binary and replace the current one, if an event occurs.
I am using Cooja simulator and sky note and I uploaded the binary into the coffee file system of the node(using cooja script) and I want to execute the hello-world.ce
To compile my current program(reboot.c) that i will dynamicaly load a module from I used the following commands:
- make TARGET=sky clean CLEAN=symbols.?
- make reboot.sky TARGET=sky
- make CORE=reboot.sky TARGET=sky reboot.sky
And for the hello-world that will be loaded I used:
- make TARGET=sky hello-world.ce
Here is part of my code (reboot.c) from where i am trying to execute hello-world
#include "contiki.h"
#include "core/loader/elfloader.h"
#include "cfs/cfs.h"
PROCESS(hello_world_process, "Reboot process");
AUTOSTART_PROCESSES(&hello_world_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(hello_world_process, ev, data)
{
PROCESS_BEGIN();
int i;
int binFile,ret;
elfloader_init();
binFile=cfs_open("hello-world.ce",CFS_READ);
printf("cfs_open:%d\n",binFile); //returns 0 so the file is opened
ret=elfloader_load(binFile);
cfs_close(binFile);
printf("loader returned: %d\n",ret); //returns 0 ->meaning everything is ok
if(ret == ELFLOADER_OK){
printf("elf OK\n");
for(i=0; elfloader_autostart_processes[i] != NULL; i++) {
printf("exec: starting process %s. \n", elfloader_autostart_processes[i]->name);
}
autostart_start(elfloader_autostart_processes);
}
printf("end of rebooting program\n”);
PROCESS_END();
}
It seems that the elfloader_autostart_processes is set to null since the print statement is not executed in the for loop. The program continues and prints "end of rebooting program" and I was expecting it to print hello-world as an indicator that the binary has been loaded and started.
Can you provide any help?
elfloader_autostart_processes
data structure definied and initialized? – Calamineret == ELFLOADER_OK
is true so you get to the for loop at all? – Calamineelfloader_autostart_processes
is defined at the header of core/loader/elfloader.h and it is initialised from the library as far as I know – Melodramatize