Beispiel #1
0
/*---------------------------------------------------------------------*/
void
codeprop_exit_program(void)
{
  if(elfloader_autostart_processes != NULL) {
    autostart_exit(elfloader_autostart_processes);
  }
}
Beispiel #2
0
/*---------------------------------------------------------------------*/
PROCESS_THREAD(tcp_loader_process, ev, data)
{
  PROCESS_BEGIN();

  rudolph0_open(&rudolph0, 20, &rudolph0_call);
  
  tcp_listen(HTONS(CODEPROP_DATA_PORT));
  
  while(1) {
    PROCESS_YIELD();
    if(ev == tcpip_event && uip_conn->lport == HTONS(CODEPROP_DATA_PORT)) {
      if(uip_connected()) {	/* Really uip_connecting()!!! */
	if(data == NULL) {
	  PT_INIT(&s.tcpthread_pt);
	  process_poll(&tcp_loader_process);
	  tcp_markconn(uip_conn, &s);

	  if(elfloader_autostart_processes != NULL) {
	    PRINTF("Stopping old programs.\n");
	    autostart_exit(elfloader_autostart_processes);
	    elfloader_autostart_processes = NULL;
	  }
	} else {
	  PRINTF(("codeprop: uip_connected() and data != NULL\n"));
	  uip_abort();
	}
      }
      recv_tcpthread(&s.tcpthread_pt); /* Run thread */

      if(uip_closed() || uip_aborted() || uip_timedout()) {
	PRINTF(("codeprop: connection down\n"));
	tcp_markconn(uip_conn, NULL);
      }
    }
  }
  
  PROCESS_END();
}
Beispiel #3
0
/*---------------------------------------------------------------------*/
static void
write_chunk(struct rudolph0_conn *c, int offset, int flag,
	    uint8_t *data, int datalen)
{
  int fd;

  leds_toggle(LEDS_YELLOW);
  
  if(flag == RUDOLPH0_FLAG_NEWFILE) {
    printf("+++ rudolph0 new file incoming at %u\n", clock_time());
    fd = cfs_open("codeprop.out", CFS_WRITE);
    
    if(elfloader_autostart_processes != NULL) {
      PRINTF("Stopping old programs.\n");
      autostart_exit(elfloader_autostart_processes);
      elfloader_autostart_processes = NULL;
    }

  } else {
    fd = cfs_open("codeprop.out", CFS_WRITE + CFS_APPEND);
  }
  
  if(datalen > 0) {
    int ret;
    cfs_seek(fd, offset, CFS_SEEK_SET);
    ret = cfs_write(fd, data, datalen);
    /*    printf("write_chunk wrote %d bytes at %d, %d\n", ret, offset, (unsigned char)data[0]);*/
  }

  cfs_close(fd);

  if(flag == RUDOLPH0_FLAG_LASTCHUNK) {
    printf("+++ rudolph0 entire file received at %u\n", clock_time());
    start_program();
    leds_off(LEDS_YELLOW);
  }
}
Beispiel #4
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(console_server, ev, data)
{
  static uint8_t buf[257];
  static uint8_t processingFile = 0;
  static uint32_t received = 0;
  static struct cfs_dirent dirent;
  static struct cfs_dir dir;
  static uint32_t fdFile;
  static char *filename;
  PROCESS_BEGIN();

  elfloader_init();

  printf("Console server started !\n");
  while(1) {

    PROCESS_YIELD();
    if (ev == serial_line_event_message) {
      if (!strcmp(data, "ls")) {
        if(cfs_opendir(&dir, ".") == 0) {
          while(cfs_readdir(&dir, &dirent) != -1) {
            printf("File: %s (%ld bytes)\n",
                dirent.name, (long)dirent.size);
          }
          cfs_closedir(&dir);
        }
      }
      else if (!strcmp(data, "format")) {
        /* format the flash */
        printf("Formatting\n");
        printf("It takes around 3 minutes\n");
        printf("...\n");

        fdFile = cfs_coffee_format();
        printf("Formatted with result %ld\n", fdFile);
      }
      else if (strstr(data, "cat") == data) {
        int n, jj;
        char* tmp = strstr(data, " ");
        tmp++;
        fdFile = cfs_open(tmp, CFS_READ);
        if (fdFile < 0) printf("error opening the file %s\n", tmp);
        while ((n = cfs_read(fdFile, buf, 60)) > 0) {
          for (jj = 0 ; jj < n ; jj++) printf("%c", (char)buf[jj]);
        }
        printf("\n");
        cfs_close(fdFile);
        if (n!=0)
          printf("Some error reading the file\n");

      }
      else if (strstr(data, "loadelf") == data) {
        filename = strstr(data, " ");
        filename++;
        // Cleanup previous loads
        if (elfloader_autostart_processes != NULL)
          autostart_exit(elfloader_autostart_processes);
        elfloader_autostart_processes = NULL;

        // Load elf file
        fdFile = cfs_open(filename, CFS_READ | CFS_WRITE);
        received = elfloader_load(fdFile);
        cfs_close(fdFile);
        printf("Result of loading %lu\n", received);

        // As the file has been modified and can't be reloaded, remove it
        printf("Remove dirty firmware '%s'\n", filename);
        cfs_remove(filename);

        // execute the program
        if (ELFLOADER_OK == received) {
          if (elfloader_autostart_processes) {
            PRINT_PROCESSES(elfloader_autostart_processes);
            autostart_start(elfloader_autostart_processes);
          }
        }
        else if (ELFLOADER_SYMBOL_NOT_FOUND == received) {
          printf("Symbol not found: '%s'\n", elfloader_unknown);
        }

      }
      else if (strstr(data, "rm") == data) {
        int n, jj;
        char* tmp = strstr(data, " ");
        tmp++;
        cfs_remove(tmp);
      }
      else if (strstr(data, "upload") == data) {
        char* tmp = strstr(data, " ");
        tmp++;
        fdFile = cfs_open(tmp, CFS_READ | CFS_WRITE);
        printf("Uploading file %s\n", tmp);
        processingFile = 1;
      }
      else if (!strcmp(data, "endupload")) {
        cfs_close(fdFile);
        printf("File uploaded (%ld bytes)\n", received);
        received = 0;
        processingFile = 0;
      }
      else if (processingFile) {
        int n = strlen(data);
        int r = decode(data, n, buf);
        received += r;
        cfs_write(fdFile, buf, r);
      }
      else  {
        printf("%s (%lu bytes received)\n", (char*)data, received);
      }
    }
  }
  PROCESS_END();
}
Beispiel #5
0
static int exec_file(char *name, char **error)
{
  int fd;
  int ret;
  *error = 0;

  /* Kill any old processes. */
  if(elfloader_autostart_processes != NULL) {
    autostart_exit(elfloader_autostart_processes);
  }

  fd = cfs_open(name, CFS_READ | CFS_WRITE);
  if(fd < 0) {
#if DEBUG
      error = "Could not open file";
#endif
  } else {
    ret = elfloader_load(fd);
    cfs_close(fd);

#if DEBUG
    switch(ret) {
    case ELFLOADER_OK:
      *error = "OK";
      break;
    case ELFLOADER_BAD_ELF_HEADER:
      *error = "Bad ELF header";
      break;
    case ELFLOADER_NO_SYMTAB:
      *error = "No symbol table";
      break;
    case ELFLOADER_NO_STRTAB:
      *error = "No string table";
      break;
    case ELFLOADER_NO_TEXT:
      *error = "No text segment";
      break;
    case ELFLOADER_SYMBOL_NOT_FOUND:
      *error = "Symbol not found";
      // symbol = elfloader_unknown;
      PRINTF("Symbol not found: %s\n", elfloader_unknown);
      break;
    case ELFLOADER_SEGMENT_NOT_FOUND:
      *error = "Segment not found";
      // symbol = elfloader_unknown;
      PRINTF("Segment not found: %s\n", elfloader_unknown);
      break;
    case ELFLOADER_NO_STARTPOINT:
      *error = "No starting point";
      break;
    default:
      *error = "Unknown return code from the ELF loader (internal bug)";
      break;
    }
#endif

    if(ret == ELFLOADER_OK) {
      autostart_start(elfloader_autostart_processes);
      return 0;
    }
  }

  return 1;
}