int dm3xx_boot_rec_make(char * rec_fn)
{
	// generates SD card boot header for RBL and additional  data
	FILE * f = fopen(rec_fn,"w+");
	struct stat s={0,0,0,0,0,0,0,0};
	stat(getenv2("sdboot"), &s);
	printf("Image %s:", rec_fn);
	dm3xx_boot_data_addr=strtol(getenv2("dm3xx_boot_data_addr"),0,0);
	//trvx(dm3xx_boot_data_addr);
	if (! dm3xx_boot_data_addr ) {
		printf("please define dm3xx_boot_data_addr \n");
		exit(1);
	}
	fwrite_int(MAGIC_NUMBER_VALID,f);
	fwrite_int(UBL_GNU_ENTRY,f);
	//fwrite_int(UBL_CCS_ENTRY,f);
	fwrite_int(SDBOOT_SIZE/BLOCK,f);
	assert(s.st_size  < SDBOOT_SIZE * BLOCK);
	//fwrite_int((s.st_size+BLOCK-1)/BLOCK,f);
	fwrite_int((dm3xx_boot_data_addr+SDBOOT_SDC) / BLOCK,f);
	fwrite_int(0,f);
	fwrite_int(0,f);
	fwrite_int(0,f);
	fwrite_int(0,f);
	fwrite_int(dm3xx_boot_data_addr,f); // sdboot looks for data at this address on SD card
	fclose(f);
	printf("\n", rec_fn);
	return 0;
}
int main()
{
	if (! getenv("dm3xx_boot_rec") && ! getenv("dm3xx_boot_data") ) {
		printf("please define env var 'dm3xx_boot_rec' or 'dm3xx_boot_data'\n");
		exit(1);
	}
	if ( getenv("dm3xx_boot_rec") )
		dm3xx_boot_rec_make(getenv2("dm3xx_boot_rec"));
	if ( getenv("dm3xx_boot_data") )
		sdcard_build_data(getenv2("dm3xx_boot_data"));
	return 0;
}
Пример #3
0
const char *
get_property (const char *filename, const char *propname, int mode)
{
  char line[MAXBUFSIZE], *p = NULL;
  FILE *fh;
  const char *value_s = NULL;

  if ((fh = fopen (filename, "r")) != 0)        // opening the file in text mode
    {                                           //  avoids trouble on DOS
      while (fgets (line, sizeof line, fh) != NULL)
        if ((value_s = get_property_from_string (line, propname,
               PROPERTY_SEPARATOR, PROPERTY_COMMENT)) != NULL)
          break;

      fclose (fh);
    }

  p = getenv2 (propname);
  if (*p != 0)                                  // getenv2() never returns NULL
    value_s = p;

  if (value_s)
    if (mode == PROPERTY_MODE_FILENAME)
      {
        static char tmp[FILENAME_MAX];

        realpath2 (value_s, tmp);
        value_s = tmp;
    }

  return value_s;
}
int sdcard_build_data(char * data_fn)
{
	printf("Writing %s\n",data_fn);
	FILE * f = fopen(data_fn,"r+"); // r,w, don't truncate
	if (!f) {
		perror("openning data file");
		exit(1);
	}
	fprintf(f,"dm3xx_boot_magic: sdboot: %x UBL:%x test:%x U-boot:%x kernel:%x root FS:%x\n\n",
			SDBOOT_SDC,TEST_SDC, UBL_SDC, UBOOT_SDC, KERNEL_SDC, ROOTFS_SDC);
	copy_file(getenv2("sdboot"),f,SDBOOT_SDC);
	copy_123(f,TEST_SDC);
	copy_file(getenv2("ubl"),f,UBL_SDC);
	copy_file(getenv2("uboot"),f,UBOOT_SDC);
	if (getenv("kernel") && strlen(getenv("kernel"))) copy_file(getenv2("kernel"),f,KERNEL_SDC);
	if (getenv("rootfs") && strlen(getenv("rootfs"))) copy_file(getenv2("rootfs"),f,ROOTFS_SDC);
	fclose(f);
}
Пример #5
0
void *thread_fun1(void *arg){
  pthread_join(tid1, NULL);
  pthread_join(tid2, NULL);

  char name[]="PATH";
  char buf[800];
  getenv2(name,buf,200);
  printf("value=%s\n",buf);

}
Пример #6
0
char *
tmpnam2 (char *temp)
// tmpnam() clone
{
  char *p = getenv2 ("TEMP");

  srand (time (0));

  *temp = 0;
  while (!(*temp) || !access (temp, F_OK))      // must work for files AND dirs
    sprintf (temp, "%s%s%08x.tmp", p, FILE_SEPARATOR_S, rand());

  return temp;
}
Пример #7
0
char *
realpath2 (const char *path, char *full_path)
// enhanced realpath() which returns the absolute path of a file
{
  char path1[FILENAME_MAX];
  const char *path2;

  if (path[0] == '~')
    {
      if (path[1] == FILE_SEPARATOR
#ifdef  __CYGWIN__
          || path[1] == '\\'
#endif
         )
        sprintf (path1, "%s"FILE_SEPARATOR_S"%s", getenv2 ("HOME"), &path[2]);
      else if (path[1] == 0)
        strcpy (path1, getenv2 ("HOME"));
      path2 = path1;
    }
  else
    path2 = path;

  return realpath (path2, full_path);
}
Пример #8
0
const char *
get_property (const char *filename, const char *propname, int mode)
{
  char line[MAXBUFSIZE], *p = NULL;
  FILE *fh;
  const char *value_s = NULL;

  if ((fh = fopen (filename, "r")) != 0)        // opening the file in text mode
    {                                           //  avoids trouble under DOS
      while (fgets (line, sizeof line, fh) != NULL)
        if ((value_s = get_property_from_string (line, propname, PROPERTY_SEPARATOR, PROPERTY_COMMENT)))
          break;

      fclose (fh);
    }

  p = getenv2 (propname);
  if (*p == 0)                                  // getenv2() never returns NULL
    {
      if (!value_s)
        value_s = NULL;                         // value_s won't be changed
                                                  //  after this func (=ok)
    }
  else
    value_s = p;

  if (value_s)
    if (mode == PROPERTY_MODE_FILENAME)
      {
        static char tmp[FILENAME_MAX];

#ifdef  __CYGWIN__
        fix_character_set (value_s);
#endif
        realpath2 (value_s, tmp);

        value_s = tmp;
    }

  return value_s;
}
Пример #9
0
int loadParams(cgiRequestObj *request,
               char* (*getenv2)(const char*, void* thread_context),
               char *raw_post_data,
               ms_uint32 raw_post_data_length,
               void* thread_context)
{
  register int x,m=0;
  char *s, *queryString = NULL, *httpCookie = NULL;
  int debuglevel;
  int maxParams = MS_DEFAULT_CGI_PARAMS;

  if (getenv2==NULL)
    getenv2 = &msGetEnv;

  if(getenv2("REQUEST_METHOD", thread_context)==NULL) {
    msIO_printf("This script can only be used to decode form results and \n");
    msIO_printf("should be initiated as a CGI process via a httpd server.\n");
    return -1;
  }

  debuglevel = (int)msGetGlobalDebugLevel();

  if(strcmp(getenv2("REQUEST_METHOD", thread_context),"POST") == 0) { /* we've got a post from a form */
    char *post_data;
    int data_len;
    request->type = MS_POST_REQUEST;

    s = getenv2("CONTENT_TYPE", thread_context);
    if (s != NULL)
      request->contenttype = msStrdup(s);
    /* we've to set default Content-Type which is
     * application/octet-stream according to
     * W3 RFC 2626 section 7.2.1 */
    else request->contenttype = msStrdup("application/octet-stream");

    if (raw_post_data) {
      post_data = msStrdup(raw_post_data);
      data_len = raw_post_data_length;
    } else {
      if(MS_SUCCESS != readPostBody( request, &post_data ))
        return -1;
      data_len = strlen(post_data);
    }

    /* if the content_type is application/x-www-form-urlencoded,
       we have to parse it like the QUERY_STRING variable */
    if(strncmp(request->contenttype, "application/x-www-form-urlencoded", strlen("application/x-www-form-urlencoded")) == 0) {
      while( data_len > 0 && isspace(post_data[data_len-1]) )
        post_data[--data_len] = '\0';

      while( post_data[0] ) {
        if(m >= maxParams) {
          maxParams *= 2;
          request->ParamNames = (char **) msSmallRealloc(request->ParamNames,sizeof(char *) * maxParams);
          request->ParamValues = (char **) msSmallRealloc(request->ParamValues,sizeof(char *) * maxParams);
        }
        request->ParamValues[m] = makeword(post_data,'&');
        plustospace(request->ParamValues[m]);
        unescape_url(request->ParamValues[m]);
        request->ParamNames[m] = makeword(request->ParamValues[m],'=');
        m++;
      }
      free( post_data );
    } else
      request->postrequest = post_data;

    /* check the QUERY_STRING even in the post request since it can contain
       information. Eg a wfs request with  */
    s = getenv2("QUERY_STRING", thread_context);
    if(s) {
      if (debuglevel >= MS_DEBUGLEVEL_DEBUG)
        msDebug("loadParams() QUERY_STRING: %s\n", s);

      queryString = msStrdup(s);
      for(x=0; queryString[0] != '\0'; x++) {
        if(m >= maxParams) {
          maxParams *= 2;
          request->ParamNames = (char **) msSmallRealloc(request->ParamNames,sizeof(char *) * maxParams);
          request->ParamValues = (char **) msSmallRealloc(request->ParamValues,sizeof(char *) * maxParams);
        }
        request->ParamValues[m] = makeword(queryString,'&');
        plustospace(request->ParamValues[m]);
        unescape_url(request->ParamValues[m]);
        request->ParamNames[m] = makeword(request->ParamValues[m],'=');
        m++;
      }
    }
  } else {
    if(strcmp(getenv2("REQUEST_METHOD", thread_context),"GET") == 0) { /* we've got a get request */
      request->type = MS_GET_REQUEST;

      s = getenv2("QUERY_STRING", thread_context);
      if(s == NULL) {
        msIO_setHeader("Content-Type","text/html");
        msIO_sendHeaders();
        msIO_printf("No query information to decode. QUERY_STRING not set.\n");
        return -1;
      }

      if (debuglevel >= MS_DEBUGLEVEL_DEBUG)
        msDebug("loadParams() QUERY_STRING: %s\n", s);

      if(strlen(s)==0) {
        msIO_setHeader("Content-Type","text/html");
        msIO_sendHeaders();
        msIO_printf("No query information to decode. QUERY_STRING is set, but empty.\n");
        return -1;
      }

      /* don't modify the string returned by getenv2 */
      queryString = msStrdup(s);
      for(x=0; queryString[0] != '\0'; x++) {
        if(m >= maxParams) {
          maxParams *= 2;
          request->ParamNames = (char **) msSmallRealloc(request->ParamNames,sizeof(char *) * maxParams);
          request->ParamValues = (char **) msSmallRealloc(request->ParamValues,sizeof(char *) * maxParams);
        }
        request->ParamValues[m] = makeword(queryString,'&');
        plustospace(request->ParamValues[m]);
        unescape_url(request->ParamValues[m]);
        request->ParamNames[m] = makeword(request->ParamValues[m],'=');
        m++;
      }
    } else {
      msIO_setHeader("Content-Type","text/html");
      msIO_sendHeaders();
      msIO_printf("This script should be referenced with a METHOD of GET or METHOD of POST.\n");
      return -1;
    }
  }

  /* check for any available cookies */
  s = getenv2("HTTP_COOKIE", thread_context);
  if(s != NULL) {
    httpCookie = msStrdup(s);
    request->httpcookiedata = msStrdup(s);
    for(x=0; httpCookie[0] != '\0'; x++) {
      if(m >= maxParams) {
        maxParams *= 2;
        request->ParamNames = (char **) msSmallRealloc(request->ParamNames,sizeof(char *) * maxParams);
        request->ParamValues = (char **) msSmallRealloc(request->ParamValues,sizeof(char *) * maxParams);
      }
      request->ParamValues[m] = makeword(httpCookie,';');
      plustospace(request->ParamValues[m]);
      unescape_url(request->ParamValues[m]);
      request->ParamNames[m] = makeword_skip(request->ParamValues[m],'=',' ');
      m++;
    }
  }

  if (queryString)
    free(queryString);
  if (httpCookie)
    free(httpCookie);

  return(m);
}