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

📄 tmwrb.c

📁 可用于TM1300/PNX1300系列DSP(主要用于视频处理)压缩库即应用例子。
💻 C
📖 第 1 页 / 共 3 页
字号:
   InitImage();
   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] [-nostandard]\\\n");
      printf("   [-flashbsp] [-inmi] [-cflags \"ccstring\"] [-ldflags \"ldstring\"] \n");
      printf("   [-o output-file] [-tcs \"tcspath\"] [-cpath \"sourcepath\"]\n");
      printf("   \n");
      printf("   '%s' creates a Writable Boot (WRB) 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 written to Flash as the boot image.\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 WRB output file.\n");
      printf("   -e[lb] : specify endianness of WRB 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("   -nostandard : Disable usage of 'TriMedia' Flash.\n");
      printf("   -flashbsp : Use BSP as the flash file system hardware interface (default).\n");
      printf("       To disable this option use the -noflashbsp option which causes\n");
      printf("       tmWRB to use flash specific driver as specified in the makefile.\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("       WRB application.\n");
      printf("   -ldflags \"ld_string\" : A string of arguements to pass to tmcc when linking WRB\n");
      printf("       application.\n");
      printf("   -o output-file: name of WRB output-file that will be created. default output name\n");
      printf("       is 'a.out'.\n");
      printf("   -tcs \"tcspath\" : Current TCS path that tmWRB 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 tmWRB 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 */
  *nostandard_buf = '\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);
  /* get unshuffling values */
  unshuffled  = (Bool)tsaCmdOptOption(Opt_unshuffled);
  /* verbosity */
  verbose  = (Bool)tsaCmdOptOption(Opt_verbose);
  /* get nostandard value */
  nostandard = (Bool)tsaCmdOptOption(Opt_nostandard);
  /* get flashbsp value */
  flashbsp = (Bool)tsaCmdOptOption(Opt_flashbsp);
  /* 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);
  }

  /* if 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);
     }     
  }

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

  /* if to use standard Flash i.e. nostandard is Flase */
  if(nostandard == False){
     strcpy(nostandard_buf,"-lio  -tmld -u _FlashFS --");
  }       
}
/*************************************************************************
//
**************************************************************************/

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);
   chmod(TEMP_DIR,0x1FF);

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

   sprintf(buffer,".%stmunpackboot.c",SLASH TEMP_DIR SLASH);
   sprintf(tcspath_buffer,"%s%stmunpackboot.c", cpath,SLASH);
   unlink(buffer);
   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 Write Booter Image\n");

   /* do a make in temp */
   sprintf(buffer,"%s%sbin%stmcc -e%s -host %s  %stmunpackboot.c -c tmunpackboot.o %s",tcspath, SLASH, SLASH,bigendian,host,TEMP_DIR SLASH,cflags);

   rewrite_slashes( buffer );

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

   /* copy object file to temp dir */
   chmod("tmunpackboot.o",0x1FF);
   sprintf(buffer,".%stmunpackboot.o",SLASH TEMP_DIR SLASH);
   copy("tmunpackboot.o",buffer);
   unlink("tmunpackboot.o");
   
   /* if using standard TriMedia Flash specific source file*/
   if (nostandard == False  && flashbsp == False){

      sprintf(tcspath_buffer,MY_FLASHSPECIFIC);
      sprintf(buffer,"%sFlashSpecific.c",TEMP_DIR SLASH);

      unlink(buffer);
      copy(tcspath_buffer, buffer);
      
      sprintf(buffer,"%s%sbin%stmcc -e%s -host %s  %sFlashSpecific.c -c FlashSpecific.o %s",tcspath, SLASH, SLASH, bigendian,host,TEMP_DIR SLASH,cflags);
      
      rewrite_slashes( buffer );

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

      /* copy object file to temp dir */
      chmod("FlashSpecific.o",0x1FF);
      sprintf(buffer,".%sFlashSpecific.o",SLASH TEMP_DIR SLASH);
      copy("FlashSpecific.o",buffer);
      unlink("FlashSpecific.o");
      
      sprintf(buffer,"%s%sbin%stmcc -e%s -host %s %stmunpackboot.o %sFlashSpecific.o %stmpackedboot.t -o %stmunpackboot.out -lz -lload %s %s",tcspath, SLASH, SLASH,bigendian,host,TEMP_DIR SLASH,TEMP_DIR SLASH,TEMP_DIR SLASH,TEMP_DIR SLASH,ldflags,nostandard_buf);

      rewrite_slashes( buffer );
      
      printf("%s\n",buffer);      
      if(system(buffer) != EXIT_SUCCESS){
         printf("Fatal Error; Following \"System Call\" failed :\n %s\n",buffer);
         goto end;   
      }
   }
   else{
      
      sprintf(buffer,"%s%sbin%stmcc -e%s -host %s %stmunpackboot.o %stmpackedboot.t -o %stmunpackboot.out -lz -lload %s %s",tcspath, SLASH, SLASH,bigendian,host,TEMP_DIR SLASH,TEMP_DIR SLASH,TEMP_DIR SLASH,ldflags,nostandard_buf);

      rewrite_slashes( buffer );

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

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

   sprintf(buffer,".%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",TEMP_DIR SLASH,direntp->d_name);
            
            chmod(buffer,0x1FF);
            unlink(buffer);
         }
      }
      (void)closedir(dirp);
   }
   
   /* remove temporary directory */
   printf("Removing temporary directory\n"); 
   rmdir(TEMP_DIR);
   
   /* exit */
   return ret;
}

⌨️ 快捷键说明

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