⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tmsei.c

📁 可用于TM1300/PNX1300系列DSP(主要用于视频处理)压缩库即应用例子。
💻 C
📖 第 1 页 / 共 3 页
字号:
   if (copy_image(image_file) != True)
         return False;
   FinishImage();

   return True;
}

/*-------------------------------------------------------------------*/

void print_help(){
      printf("usage: %s -load begin_mem,end_mem input-file [-e[l|b]] [-host type] \\\n", progname);
      printf("   [-v] [-tm_freq freq] [-mmio_base address] [-cache support] [-sei begin,end]\\\n");
      printf("   [-inmi] [-cflags \"ccstring\"] [-ldflags \"ldstring\"] [-o output-file]\n");
      printf("   [-tcs \"tcspath\"] [-cpath \"-sourcepath\"]\n");
      printf("   \n");
      printf("   '%s' creates a Self Extacting Image (SEI) output file, given an input\n",progname);
      printf("   file. The input image file will be embedded in a compressed form in the output file.\n");
      printf("   The output image file can be downloaded and run, where the original memory image will\n");
      printf("   be uncompressed, copied to SDRAM and executed.\n\n");

      printf("   -load begin_mem,end_mem : Specify download memory region of input file\n");
      printf("   input-file : name of executable to be extracted by SEI output file\n");
      printf("   -e[lb] : specify endianness of SEI output file\n");
      printf("       -eb for big endian (default) \n");
      printf("       -el for little endian;\n");
      printf("   -host type : Specify one of the following types of host processor \n");
      printf("       nohost    : No Host (default)\n");
      printf("       tmsim     : TM Simulator is Host\n");
      printf("       Win95     : Win95 is Host\n");
      printf("       MacOS     : MacOS is Host\n");
      printf("       WinNT     : WinNT is Host\n");
      printf("   -v : Specify that the auto-generated part of output is verbose\n");
      printf("   -tm_freq freq : Specify the TM clock frequency. 100000000 is default\n");
      printf("   -mmio_base address : Specify MMIO base address. 0xefe00000 is default\n");
      printf("   -cache support : Specification of setting the resposiblity of setting the cacheable\n");
      printf("       limit and the cachelocked regions\n");
      printf("       LeaveCachingToUser: cacheable limit and cachelocked \n");
      printf("           entirely under control of the user, the regions are downloader code won't\n");
      printf("           touch it.\n");
      printf("       LeaveCachingToDownloader: cachelocked regions and cacheble limit are entirely\n");
      printf("           under control of the downloader, which will use this control to intelligently\n");
      printf("           map the different cached/uncached/cachelocked sections within the specified\n");
      printf("           sdram, partitioned in different caching property regions, and let the downloaded\n");
      printf("           program set cacheable limit and cachelocked regions accordingly. (default)\n");
      printf("       CachesOff: cachelocked regions and cacheble limit are entirely under control of the\n");
      printf("           downloader, which will let the downloaded program run with 'cache off'.\n");
      printf("   -sei begin,end : Specify download memory region for optional SEI memory image\n");
      printf("   -inmi : input file is a memory image. \n");
      printf("   -cflags \"cc_string\" : A string of arguements to pass to tmcc when compiling sources for\n");
      printf("       SEI application.\n");
      printf("   -ldflags \"ld_string\" : A string of arguements to pass to tmcc when linking SEI\n");
      printf("       application.\n");
      printf("   -o output-file: name of SEI output-file that will be created. default output name\n");
      printf("        is 'a.out'. \n");
      printf("   -tcs \"tcspath\" : Current TCS path that tmSEI will use to build TriMedia image.\n");
#ifdef _WIN32
      printf("        default is C:\\\\TriMedia \n");
#else
      printf("        default is /usr/local/tcs \n");
#endif
      printf("   -cpath \"sourcepath\" : path of c source file, tmunpackimage.c, that tmSEI will use\n");
#ifdef _WIN32
      printf("        to create a TriMeida image. default is .\\\\tmunpackimage \n");
#else
      printf("        to create a TriMeida image. default is ./tmunpackimage\n");
#endif
      
      exit(1);
}

void
parse_options(int argc, char *argv[]){
   
  int		ax;
  void *	ptr;

  if(!tsaCmdOptParse(argc, argv, Nelts(options), options, Null)){
     printf("Parsing options Failen\n" );
     exit(-1);
  }

  /* initialize global variable */
  *sei_ldflags = '\0';
  download_unshuffled = False;

  /* get first/default parameters */

  /* get compression value */
  NoCompression = (Bool)tsaCmdOptOption(Opt_NoCompression);
  /* get inmi value */
  inmi = (Bool)tsaCmdOptOption(Opt_inmi);
  /* get out value */
  out = (Bool)tsaCmdOptOption(Opt_out);
  /* get host value */
  host = (char *)tsaCmdOptOption(Opt_host);
  /* get inmi value */
  tm_freq = (int)tsaCmdOptOption(Opt_tm_freq);
  /* get out value */
  mmio_base = (int)tsaCmdOptOption(Opt_mmio_base);
  /* get default support value */
  cache_support = TMDwnLdr_LeaveCachingToDownloader;
  /* get endian value */
  bigendian = (char *)tsaCmdOptOption(Opt_bigendian);
  /* get output value */
  output =  (char *)tsaCmdOptOption(Opt_output);

  unshuffled  = (Bool)tsaCmdOptOption(Opt_unshuffled);

  verbose  = (Bool)tsaCmdOptOption(Opt_verbose);

  /* get ldflags value */
  ldflags =  (char *)tsaCmdOptOption(Opt_ldflags);
  /* get cflags value */
  cflags =  (char *)tsaCmdOptOption(Opt_cflags);
  /* get tcspath value */
  tcspath =  (char *)tsaCmdOptOption(Opt_tcspath);
  /* get cpath value */
  cpath =  (char *)tsaCmdOptOption(Opt_cpath);


  
  /* check to make sure input parameters are correct */
  
  /* must be exactly two arguements */
  if(tsaCmdOptNumberOfArguments() !=2){
     print_help();
     exit(-1);
  }

  /* load option must be present */
  if(tsaCmdOptPresent(Opt_load) == False){
     printf("error: load option must be present\n");
     print_help();
     exit(-1);
  }

  /* if the input is a mi, the output cant be
   standard *.out image */
  if(inmi ==  True && out == True){
     fprintf(stdout, "Error: input is memory image cannot be stored as executable\n");
     print_help();
     exit(-1);
  }



  /* output is a *.out */
  if( out == True){
     
     /* cache support should not be specified */
     if(tsaCmdOptPresent(Opt_cache_support) == True){
        fprintf(stdout, "Error: cache should not be specified for this configuration.\n");
        print_help();
        exit(-1);
     }

     /* tm_freq should not be specified */
     if(tsaCmdOptPresent(Opt_tm_freq) == True){
        fprintf(stdout, "Error: tm_freq should not be specified for this configuration.\n");
        print_help();
        exit(-1);
     }

     /* mmio_base should not be specified */
     if(tsaCmdOptPresent(Opt_mmio_base) == True){
        fprintf(stdout, "Error: mmio_base should not be specified for this configuration.\n");
        print_help();
        exit(-1);
     }

  }

  /* if input is a mi or output is a *.out */
  if(inmi == False && unshuffled == True){
     printf("error: 'unshuffled' only valid with 'inmi'.\n");
     print_help();
     exit(-1);
  }

  /* parse input arguements as reqired */

  /* set up default values */
  image_file = tsaCmdOptArgument(1);

  /* parse input options as reqired */

  /* load should have 2 elements in list */
  if(!(ax = tsaCmdOptOptionAfter(Opt_load, 0, &ptr))){
     printf("error: load requires two values \n");
     print_help();
     exit(-1);
  }

  /* convert first load arguement */
  if(parse_number(ptr, '\0', 0x0,  &mem_start) != True){
     printf("error: first load arguement invalid\n");
     print_help();
     exit(-1);
  }

  /* get second load arguement */
  if(!tsaCmdOptOptionAfter(Opt_load, ax, &ptr)){
     printf("error: load a second value arguements\n");
     print_help();
     exit(-1);
  }

  /* convert second load arguement */
  if(parse_number(ptr, '\0', 0x0,  &mem_end) != True){
     printf("error: second load arguement invalid\n");
     print_help();
     exit(-1);
  }


  if(strcmp(host,"nohost") == 0)
     host_int  =  tmNoHost;
  else if(strcmp(host,"tmsim") == 0) 
     host_int  = tmTmSimHost;
  else if(strcmp(host,"Win95") == 0) 
     host_int  = tmWin95Host;
  else if(strcmp(host,"MacOS") == 0) 
     host_int  = tmMacOSHost;
  else if(strcmp(host,"WinNT") == 0) 
     host_int  = tmWinNTHost;
  else {
     printf("error: specified host type '%s' not valid\n",ptr);
     print_help();
     exit(-1);
  }


  if(tsaCmdOptPresent(Opt_cache_support) == True){

     if(!tsaCmdOptOptionAfter(Opt_cache_support, 0, &ptr)){
        printf("error: cache requires one arguement only.\n");
        print_help();
        exit(-1);
     }

     if(strcmp(ptr,"LeaveCachingToUser") == 0)
        cache_support  =  TMDwnLdr_LeaveCachingToUser;
     else if(strcmp(ptr,"LeaveCachingToDownloader") == 0) 
        cache_support  = TMDwnLdr_LeaveCachingToDownloader;
     else if(strcmp(ptr,"CachesOff") == 0) 
        cache_support  = TMDwnLdr_CachesOff;
     else {
        printf("error: specified cache support '%s' not valid\n",ptr);
        print_help();
        exit(-1);
     }     
  }

  /* if sei is specified */
  if(tsaCmdOptPresent(Opt_sei) == True){

     /* sei should have 2 elements in list */
     if(!(ax=tsaCmdOptOptionAfter(Opt_sei, 0, &ptr))){
        printf("error: sei requires two values\n");
        print_help();
        exit(-1);
     }

     /* convert first sei arguement */
     if(parse_number(ptr, '\0', 0x0,  &sei_start) != True){
        printf("error: first load arguement invalid\n");
        print_help();
        exit(-1);
     }
     
     /* get second sei arguement */
     if(!tsaCmdOptOptionAfter(Opt_sei, ax, &ptr)){
        printf("error: sei requires a second\n");
        print_help();
        exit(-1);
     }
     
     /* convert second sei arguement */
     if(parse_number(ptr, '\0', 0x0,  &sei_end) != True){
        printf("error: second sei arguement invalid\n");
        print_help();
        exit(-1);
     }

     if(host_int  ==  tmNoHost)
        /* fill in extra ldflags */
        sprintf(sei_ldflags, " -tmld -mi -load 0x%x,0x%x -tm_freq=%d -mmio_base=0x%x --",sei_start,sei_end,tm_freq,mmio_base);
     else
        /* fill in extra ldflags */
        sprintf(sei_ldflags, " -tmld -mi -load 0x%x,0x%x -R __syscall=0x%x -tm_freq=%d -mmio_base=0x%x --"
              ,sei_start,sei_end,mmio_base,tm_freq,mmio_base);
  }
     
  /* check if big Endian or little Endian support required */
       if(strcmp(bigendian,"l") == 0) { /* don't use endianness here */ }
  else if(strcmp(bigendian,"b") == 0) { /* don't use endianness here */ }
  else {
     printf("error: specified endianness support '%s' not valid\n",ptr);
     print_help();
     exit(-1);
  }     
  

  /* if input is a out and is stored as an mi */
  if(inmi == False && out == False){
     download_unshuffled = True;
  }


  /* output file should only have one parameter */
  if(tsaCmdOptPresent(Opt_output) == True){

     if(!tsaCmdOptOptionAfter(Opt_output, 0, &ptr)){
        printf("error: output requires one arguement only.\n");
        print_help();
        exit(-1);
     }

     output = ptr;
              
  }
      
}
/*************************************************************************
//
**************************************************************************/

int main(int argc, char *argv[])
{
   int ret = 0;
   DIR *dirp;
   struct dirent *direntp;
   
   progname = argv[0];

   /* extract user input options */
   parse_options(argc, argv);
   
   /* remove old output first (if it exists) */
   chmod(output,0x1FF);
   unlink(output);

   printf("Creating temporary directory\n");
   /* make temperary sub directory */
   mkdir(TEMP_DIR,0x1FF);

   printf("Copying files to temporary directory\n");

   sprintf(buffer,"%s%stmunpackimage.c",TEMP_DIR,SLASH);
   sprintf(tcspath_buffer,"%s%stmunpackimage.c",cpath,SLASH);

   copy(tcspath_buffer, buffer);
   
   printf("Packing image\n");

   /* read image file into *.t and *.h files */
   if(ReadImage() != True){
      printf("Fatal Error; Reading image %s\n",image_file);
      goto end;
   }

   printf("Building Self Extracting Image\n");

   /* do a make in temp */

   sprintf(buffer,"%s%sbin%stmcc -e%s -host %s %stmunpackimage.c -c tmunpackimage.o %s %s",tcspath, SLASH, SLASH,bigendian,host,TEMP_DIR SLASH,cflags,shrinkflags);

   rewrite_slashes( buffer );

   printf("%s\n",buffer);
   if((ret = system(buffer)) != EXIT_SUCCESS){
      printf("Fatal Error %d %d; Following \"System Call\" failed :\n %s\n",ret,errno,buffer);
      goto end;   
   }

   /* copy object file to temp dir */
   sprintf(buffer,"%stmunpackimage.o",TEMP_DIR SLASH);
   copy("tmunpackimage.o",buffer);
   chmod("tmunpackimage.o",0x1FF);
   unlink("tmunpackimage.o");

   sprintf(buffer,"%s%sbin%stmcc -e%s -host %s -bremoveunusedcode -bcompact -bfoldcode %stmunpackimage.o %stmpackedimage.t -o %stmunpackimage.out -lz -lload %s %s %s %s",tcspath,SLASH,SLASH,bigendian,host,TEMP_DIR SLASH,TEMP_DIR SLASH,TEMP_DIR SLASH,sei_ldflags,cflags,ldflags,shrinkflags);
   
   rewrite_slashes( buffer );

   printf("%s\n",buffer);
   if((ret = system(buffer)) != EXIT_SUCCESS){
      printf("Fatal Error %d; Following \"System Call\" failed :\n %s\n",ret,buffer);
      goto end;   
   }
       
   printf("Moving %s\n",output);

   /* copy tmunpackimage.out file to home dir with new executable name */
   sprintf(buffer,"%s%stmunpackimage.out",TEMP_DIR,SLASH);
   copy(buffer,output);
   
end:

   sprintf(buffer,".%s%s",SLASH,TEMP_DIR);
   dirp = opendir(buffer );

   if (dirp) {
      while ( (direntp = readdir( dirp )) != NULL ) {
         if (strcmp(direntp->d_name,".") != 0 && strcmp(direntp->d_name,"..") != 0) {
            
            sprintf(buffer,"%s%s%s",TEMP_DIR,SLASH,direntp->d_name);
            
            chmod(buffer,0x1FF);
            unlink(buffer);
         }
      }
      (void)closedir(dirp);
   }
   
   /* remove temporary directory */
   chmod(TEMP_DIR,0x1FF);
   
   printf("Removing temporary directory\n"); 
   rmdir(TEMP_DIR);
   
   /* exit */
   return ret;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -