Exemplo n.º 1
0
ezResult ezTexConv2::ParseAssetHeader()
{
  const ezStringView ext = ezPathUtils::GetFileExtension(m_sOutputFile);

  if (!ext.StartsWith_NoCase("ez"))
    return EZ_SUCCESS;

  const auto pCmd = ezCommandLineUtils::GetGlobalInstance();

  ezUInt32 tmp = m_Processor.m_Descriptor.m_uiAssetVersion;
  EZ_SUCCEED_OR_RETURN(ParseUIntOption("-assetVersion", 1, 0xFFFF, tmp));
  m_Processor.m_Descriptor.m_uiAssetVersion = tmp;

  const ezUInt64 uiHashLow = ezConversionUtils::ConvertHexStringToUInt32(pCmd->GetStringOption("-assetHashLow"));
  const ezUInt64 uiHashHigh = ezConversionUtils::ConvertHexStringToUInt32(pCmd->GetStringOption("-assetHashHigh"));

  m_Processor.m_Descriptor.m_uiAssetHash = (uiHashHigh << 32) | uiHashLow;

  if (m_Processor.m_Descriptor.m_uiAssetHash == 0)
  {
    ezLog::Error("'-assetHashLow 0xHEX32' and '-assetHashHigh 0xHEX32' have not been specified.");
    return EZ_FAILURE;
  }

  return EZ_SUCCESS;
}
Exemplo n.º 2
0
ezResult ezTexConv2::ParseInputFiles()
{
  if (m_Processor.m_Descriptor.m_OutputType == ezTexConvOutputType::Atlas)
    return EZ_SUCCESS;

  ezStringBuilder tmp, res;
  const auto pCmd = ezCommandLineUtils::GetGlobalInstance();

  auto& files = m_Processor.m_Descriptor.m_InputFiles;

  for (ezUInt32 i = 0; i < 64; ++i)
  {
    tmp.Format("-in{0}", i);

    res = pCmd->GetStringOption(tmp);

    // stop once an option was not found
    if (res.IsEmpty())
      break;

    files.EnsureCount(i + 1);
    files[i] = res;
  }

  // if no numbered inputs were given, try '-in', ignore it otherwise
  if (files.IsEmpty())
  {
    // short version for -in1
    res = pCmd->GetStringOption("-in");

    if (!res.IsEmpty())
    {
      files.PushBack(res);
    }
  }

  if (m_Processor.m_Descriptor.m_OutputType == ezTexConvOutputType::Cubemap)
  {
    // 0 = +X = Right
    // 1 = -X = Left
    // 2 = +Y = Top
    // 3 = -Y = Bottom
    // 4 = +Z = Front
    // 5 = -Z = Back

    if (files.IsEmpty() && (pCmd->GetOptionIndex("-right") != -1 || pCmd->GetOptionIndex("-px") != -1))
    {
      files.SetCount(6);

      files[0] = pCmd->GetStringOption("-right", 0, files[0]);
      files[1] = pCmd->GetStringOption("-left", 0, files[1]);
      files[2] = pCmd->GetStringOption("-top", 0, files[2]);
      files[3] = pCmd->GetStringOption("-bottom", 0, files[3]);
      files[4] = pCmd->GetStringOption("-front", 0, files[4]);
      files[5] = pCmd->GetStringOption("-back", 0, files[5]);

      files[0] = pCmd->GetStringOption("-px", 0, files[0]);
      files[1] = pCmd->GetStringOption("-nx", 0, files[1]);
      files[2] = pCmd->GetStringOption("-py", 0, files[2]);
      files[3] = pCmd->GetStringOption("-ny", 0, files[3]);
      files[4] = pCmd->GetStringOption("-pz", 0, files[4]);
      files[5] = pCmd->GetStringOption("-nz", 0, files[5]);
    }
  }

  for (ezUInt32 i = 0; i < files.GetCount(); ++i)
  {
    if (files[i].IsEmpty())
    {
      ezLog::Error("Input file {} is not specified", i);
      return EZ_FAILURE;
    }

    ezLog::Info("Input file {}: '{}'", i, files[i]);
  }

  if (m_Processor.m_Descriptor.m_InputFiles.IsEmpty())
  {
    ezLog::Error("No input files were specified. Use \'-in \"path/to/file\"' to specify an input file. Use '-in0', '-in1' etc. to specify "
                 "multiple input files.");
    return EZ_FAILURE;
  }

  return EZ_SUCCESS;
}
Exemplo n.º 3
0
void
ParseArgs (int argc, const char *argv[])
{
  int  argi;
  int  i;
  int  printHelp = FALSE;
  int  exitCode = EXIT_SUCCESS;
  char dbStr[MAX_STRING_LEN];              /* Debug option string. */
  int  number;
  int  argCount;
  const char **argVect;
  struct stat st;

  if (db4) printf(">>> ParseArgs\n");
  argCount = argc;
  argVect = argv;

  for (argi = 1; argi < argCount; argi++) {
    if (db4) printf("argv[%d] = '%s'\n", argi, argVect[argi]);
    if (strncmp(argVect[argi], "--from", 6) == 0) {
      if (GetStringOption(&argi, argCount, argVect, host1, "--from") == 0) {
        printHelp = TRUE;
        exitCode = EXIT_FAILURE;
      }
      else {
        printf("Host: %s %s\n", host1, host2);
        if (sscanf(host1, "%x-%x-%x-%x-%x-%x", &i, &i, &i, &i, &i, &i) == 6) {
          printf("Ethernet address\n");
        }
      }
    }

    else if (strncmp(argVect[argi], "--device", 8) == 0) {
      if (GetStringOption(&argi, argCount, argVect, device, "--device") == 0) {
        printHelp = TRUE;
        exitCode = EXIT_FAILURE;
      }
    }

    else if (strncmp(argVect[argi], "--network", 9) == 0) {
      netBoot = TRUE;
      serBoot = FALSE;
      strcpy(device, "eth0");
      strcpy(boot_loader_file, INTERNAL_NW);
    }

    else if (strncmp(argVect[argi], "--serial", 8) == 0) {
      serBoot = TRUE;
      netBoot = FALSE;
      strcpy(device, "/dev/ttyS0");
      strcpy(boot_loader_file, INTERNAL_SER);
    }

    else if (strncmp(argVect[argi], "--noleds", 8) == 0) {
      noleds = TRUE;
    }

    else if (strncmp(argVect[argi], "--images", 8) == 0) {
      int i = 0;

      printf("Internal images:\n");

      while(boot_image_info[i].name) {
        printf("'%s', %s, size %lu bytes.\n",
               boot_image_info[i].name,
               boot_image_info[i].info,
               boot_image_info[i].len
               );
        i++;
      }
      exit(EXIT_SUCCESS);
    }

    else if (strncmp(argv[argi], "--baudrate", 10) == 0) {
      if (GetNumberOption (&argi, argCount, argVect, &set_baudrate, "--baudrate", 10) == 0) {
        printHelp = TRUE;
        exitCode = EXIT_FAILURE;
      }
    }

    else if (strncmp(argVect[argi], "--tofiles", 9) == 0) {
      toFiles = TRUE;
    }

    else if (strncmp(argVect[argi], "--cmdsonly", 10) == 0) {
      cmdsOnly = TRUE;
    }

    else if (strncmp(argVect[argi], "--to", 4) == 0) {
      if ((GetStringOption(&argi, argCount, argVect, host2, "--to") == 0)) {
        printHelp = TRUE;
        exitCode = EXIT_FAILURE;
      }
      else {
        printf("Host: %s %s\n", host1, host2);
        both_addresses = TRUE;
        if (sscanf(host2, "%x-%x-%x-%x-%x-%x", &i, &i, &i, &i, &i, &i) == 6) {
          printf("Ethernet address\n");
        }
      }
    }

    else if (strncmp(argVect[argi], "--printp", 8) == 0) {
      pPacket = 1;
    }

    else if (strncmp(argVect[argi], "--printascii", 11) == 0) {
      pPacket = 1;
      printPacketType = ASCII;
    }

    else if (strncmp(argVect[argi], "--printudec", 11) == 0) {
      pPacket = 1;
      printPacketType = UDEC;
    }

    else if (strncmp(argVect[argi], "--printhex", 10) == 0) {
      pPacket = 1;
      printPacketType = HEX;
    }

    else if (strncmp(argVect[argi], "--bpl", 5) == 0) {
      if (GetNumberOption(&argi, argCount, argVect, &p_packet_bpl, "--bpl", 10) == 0) {
        printHelp = TRUE;
        exitCode = EXIT_FAILURE;
      }
    }

    else if (strncmp(argVect[argi], "--promisc", 11) == 0) {
      promisc = 1;
    }

    else if (strncmp(argVect[argi], "--5400", 6) == 0) {
      boot_cmds[boot_cmds_cnt++] = SET_REGISTER;
      boot_cmds[boot_cmds_cnt++] = 0xb0000000;
      boot_cmds[boot_cmds_cnt++] = 0x000095b6;
      boot_cmds[boot_cmds_cnt++] = SET_REGISTER;
      boot_cmds[boot_cmds_cnt++] = 0xb0000008;
      boot_cmds[boot_cmds_cnt++] = 0x0000e751;
      boot_cmds[boot_cmds_cnt++] = SET_REGISTER;
      boot_cmds[boot_cmds_cnt++] = 0xb000000c;
      boot_cmds[boot_cmds_cnt++] = 0x12604040;
    }

    else if (strncmp(argVect[argi], "--5600", 6) == 0) {
      boot_cmds[boot_cmds_cnt++] = SET_REGISTER;
      boot_cmds[boot_cmds_cnt++] = 0xb0000000;
      boot_cmds[boot_cmds_cnt++] = 0x000095b6;
      boot_cmds[boot_cmds_cnt++] = SET_REGISTER;
      boot_cmds[boot_cmds_cnt++] = 0xb0000008;
      boot_cmds[boot_cmds_cnt++] = 0x00006751;
      boot_cmds[boot_cmds_cnt++] = SET_REGISTER;
      boot_cmds[boot_cmds_cnt++] = 0xb000000c;
      boot_cmds[boot_cmds_cnt++] = 0x12204040;
    }

    else if (strncmp(argVect[argi], "--testcardlx", 12) == 0) {
      boot_cmds[boot_cmds_cnt++] = SET_REGISTER;
      boot_cmds[boot_cmds_cnt++] = (unsigned int)R_DRAM_CONFIG;
      boot_cmds[boot_cmds_cnt++] = 0x12604040;
      boot_cmds[boot_cmds_cnt++] = SET_REGISTER;
      boot_cmds[boot_cmds_cnt++] = (unsigned int)R_DRAM_TIMING;
      boot_cmds[boot_cmds_cnt++] = 0x0000e751;
      boot_cmds[boot_cmds_cnt++] = SET_REGISTER;
      boot_cmds[boot_cmds_cnt++] = (unsigned int)R_WAITSTATES;
      boot_cmds[boot_cmds_cnt++] = 0x00b395b5;
      boot_cmds[boot_cmds_cnt++] = SET_REGISTER;
      boot_cmds[boot_cmds_cnt++] = (unsigned int)R_BUS_CONFIG;
      boot_cmds[boot_cmds_cnt++] = 0x00000207;
    }

    else if (strncmp(argVect[argi], "--testcard", 10) == 0) {
      boot_cmds[boot_cmds_cnt++] = SET_REGISTER;
      boot_cmds[boot_cmds_cnt++] = (unsigned int)R_WAITSTATES;
      boot_cmds[boot_cmds_cnt++] = 0x000010b3;
      boot_cmds[boot_cmds_cnt++] = SET_REGISTER;
      boot_cmds[boot_cmds_cnt++] = (unsigned int)R_DRAM_TIMING;
      boot_cmds[boot_cmds_cnt++] = 0x00006543;
      boot_cmds[boot_cmds_cnt++] = SET_REGISTER;
      boot_cmds[boot_cmds_cnt++] = (unsigned int)R_DRAM_CONFIG;
      boot_cmds[boot_cmds_cnt++] = 0x12966060;
    }

    else if (strncmp(argVect[argi], "--devboard", 10) == 0) {
      /* Printing on serial port will not work until PORT_PB is set... */
      boot_cmds[boot_cmds_cnt++] = SET_REGISTER;
      boot_cmds[boot_cmds_cnt++] = (unsigned int)R_PORT_PB_SET;
      boot_cmds[boot_cmds_cnt++] = 0x01001ef3;
      boot_cmds[boot_cmds_cnt++] = SET_REGISTER;
      boot_cmds[boot_cmds_cnt++] = (unsigned int)R_PORT_PA_SET;
      boot_cmds[boot_cmds_cnt++] = 0x00001df0;
      boot_cmds[boot_cmds_cnt++] = SET_REGISTER;
      boot_cmds[boot_cmds_cnt++] = (unsigned int)R_WAITSTATES;
      boot_cmds[boot_cmds_cnt++] = 0x000095a6;
      boot_cmds[boot_cmds_cnt++] = SET_REGISTER;
      boot_cmds[boot_cmds_cnt++] = (unsigned int)R_DRAM_CONFIG;
      boot_cmds[boot_cmds_cnt++] = 0x1a200040;
      boot_cmds[boot_cmds_cnt++] = SET_REGISTER;
      boot_cmds[boot_cmds_cnt++] = (unsigned int)R_DRAM_TIMING;
      boot_cmds[boot_cmds_cnt++] = 0x00005611;
      boot_cmds[boot_cmds_cnt++] = SET_REGISTER;
      boot_cmds[boot_cmds_cnt++] = (unsigned int)R_BUS_CONFIG;
      boot_cmds[boot_cmds_cnt++] = 0x00000104;
    }

    else if (strncmp(argVect[argi], "--verify", 8) == 0) {
      boot_cmds[boot_cmds_cnt++] = MEM_VERIFY;
      GetNumberOption(&argi, argCount, argVect, &boot_cmds[boot_cmds_cnt++], "--verify", 16);
      GetNumberOption(&argi, argCount, argVect, &boot_cmds[boot_cmds_cnt++], "--verify", 16);
    }

    else if (strncmp(argVect[argi], "--setreg", 8) == 0) {
      boot_cmds[boot_cmds_cnt++] = SET_REGISTER;
      if ((argVect[argi+1][0] >= 'A') && (argVect[argi+1][0] <= 'Z')) {
        GetRegisterOption(&argi, argCount, argVect, &boot_cmds[boot_cmds_cnt++], "--setreg", 16);
      }
      else {
        GetNumberOption(&argi, argCount, argVect, &boot_cmds[boot_cmds_cnt++], "--setreg", 16);
      }
      GetNumberOption(&argi, argCount, argVect, &boot_cmds[boot_cmds_cnt++], "--setreg", 16);
    }

    else if (strncmp(argVect[argi], "--getreg", 8) == 0) {
      boot_cmds[boot_cmds_cnt++] = GET_REGISTER;
      if ((argVect[argi+1][0] >= 'A') && (argVect[argi+1][0] <= 'Z')) {
        GetRegisterOption(&argi, argCount, argVect, &boot_cmds[boot_cmds_cnt++], "--getreg", 16);
      }
      else {
        GetNumberOption(&argi, argCount, argVect, &boot_cmds[boot_cmds_cnt++], "--getreg", 16);
      }
    }

    else if (strncmp(argVect[argi], "--pause", 7) == 0) {
      boot_cmds[boot_cmds_cnt++] = PAUSE_LOOP;
      GetNumberOption(&argi, argCount, argVect, &boot_cmds[boot_cmds_cnt++], "--pause", 16);
    }

    else if (strncmp(argVect[argi], "--memtest", 9) == 0) {
      boot_cmds[boot_cmds_cnt++] = MEM_TEST;
      GetNumberOption(&argi, argCount, argVect, &boot_cmds[boot_cmds_cnt++], "--memtest", 16);
      GetNumberOption(&argi, argCount, argVect, &boot_cmds[boot_cmds_cnt++], "--memtest", 16);
    }

    else if (strncmp(argVect[argi], "--loop", 6) == 0) {
      char str[MAX_STRING_LEN];
      boot_cmds[boot_cmds_cnt++] = LOOP;
      GetNumberOption(&argi, argCount, argVect, &boot_cmds[boot_cmds_cnt++], "--loop", 16);
      GetStringOption(&argi, argCount, argVect, str, argVect[argi]);
      new_label(&loop_label, boot_cmds_cnt+1, str);
      boot_cmds_cnt++;
    }

    else if (strncmp(argVect[argi], "--label", 7) == 0) {
      char str[MAX_STRING_LEN];
      GetStringOption(&argi, argCount, argVect, str, "--label");
      new_label(&label, boot_cmds_cnt, str);
    }

    else if (strncmp(argVect[argi], "--memdump", 9) == 0) {
      boot_cmds[boot_cmds_cnt++] = MEM_DUMP;
      GetNumberOption(&argi, argCount, argVect, &boot_cmds[boot_cmds_cnt++], "--memdump", 16);
      GetNumberOption(&argi, argCount, argVect, &boot_cmds[boot_cmds_cnt++], "--memdump", 16);
    }

    else if (strncmp(argVect[argi], "--memclear", 10) == 0) {
      boot_cmds[boot_cmds_cnt++] = MEM_CLEAR;
      GetNumberOption(&argi, argCount, argVect, &boot_cmds[boot_cmds_cnt++], "--memclear", 16);
      GetNumberOption(&argi, argCount, argVect, &boot_cmds[boot_cmds_cnt++], "--memclear", 16);
    }

    else if (strncmp(argVect[argi], "--flash", 7) == 0) {
            boot_cmds[boot_cmds_cnt++] = FLASH;
            GetNumberOption(&argi, argCount, argVect, &boot_cmds[boot_cmds_cnt++], "--flash", 16);
            GetNumberOption(&argi, argCount, argVect, &boot_cmds[boot_cmds_cnt++], "--flash", 16);
            GetNumberOption(&argi, argCount, argVect, &boot_cmds[boot_cmds_cnt++], "--flash", 16);
            doing_flash = TRUE;
    }

    else if (strncmp(argVect[argi], "--jump", 6) == 0) {
      boot_cmds[boot_cmds_cnt++] = JUMP;
      GetNumberOption(&argi, argCount, argVect, &boot_cmds[boot_cmds_cnt++], "--jump", 16);
    }

    else if (strncmp(argVect[argi], "--file", 6) == 0) {
      char str[MAX_STRING_LEN];
      boot_cmds[boot_cmds_cnt++] = PACKET_INFO;
      GetStringOption(&argi, argCount, argVect,
                      str, "--file");   /* file name */
      GetNumberOption(&argi, argCount, argVect,
                      &boot_cmds[boot_cmds_cnt++], str, 16); /* address */
      last_boot_file = allocate_boot_file(last_boot_file);
      first_boot_file = first_boot_file ? first_boot_file : last_boot_file;
      last_boot_file->fileName = malloc(strlen(str) + 1);
      strcpy(last_boot_file->fileName, str);
      last_boot_file->size_p = &boot_cmds[boot_cmds_cnt];
      last_boot_file->size_sent = 0;
      if (strncmp(str, "-", 1) != 0) {
        if (stat(last_boot_file->fileName, &st) == -1) {
          printf("Cannot get size of file '%s'. %s.\n",
                 last_boot_file->fileName, strerror(errno));
          exit(EXIT_FAILURE);
        }
        if (db2) printf("* size is %d 0x%8.8x\n",
                        (int)st.st_size, (unsigned int)st.st_size);
        last_boot_file->size = st.st_size;
        boot_cmds[boot_cmds_cnt++] = st.st_size;
      }
      else {
        GetNumberOption(&argi, argCount, argVect,
                        &last_boot_file->size , str, 16); /* size */

        boot_cmds[boot_cmds_cnt++] = last_boot_file->size;
        printf("* size is %d 0x%8.8x\n", last_boot_file->size,
               last_boot_file->size);
      }
    }

    else if (strncmp(argVect[argi], "--bootfile", 10) == 0) {
      GetStringOption(&argi, argCount, argVect,
                      boot_loader_file, "--bootfile");
    }

    else if (strncmp(argVect[argi], "-d", 2) == 0) {
      if (GetNumberOption (&argi, argCount, argVect, &number, "-d", 10) == 0) {
        printHelp = TRUE;
        exitCode = EXIT_FAILURE;
      }
      else {
        sprintf(dbStr, "%d", number);
        for (i = 0; i != (int) strlen(dbStr); i++) {
          switch (dbStr[i] - '0') {
          case 1:
            db1 = TRUE;
            break;
          case 2:
            db2 = TRUE;
            break;
          case 3:
            db3 = TRUE;
            break;
          case 4:
            db4 = TRUE;
            break;
          default:
            printf("ERROR! Debug level %d is not defined.\n", dbStr[i] - '0');
            printHelp = TRUE;
            exitCode = EXIT_FAILURE;
            break;
          }
        }
      }
    }

    else if (strncmp(argVect[argi], "--find", 6) == 0) {
      GetStringOption(&argi, argCount, argVect, needle, "--find");
      /* convert control characters like /n to the real ascii valure */
      {
        int i;
        int j = 0;
        char c;
        int esc = 0;

        for (i = 0; (c = needle[i]); i++,j++) {
//        printf("c = %d, i %d, j %d\n", (int)c, i, j);
          if (c == '\\') {
//          printf("esc\n");
            esc = 1;
            continue;
          }
          else if (esc) {
            esc = 0;
            switch(c) {
            case 'r':
              c = '\r';
              break;

            case 'n':
              c = '\n';
              break;

            case '\\':
              c = '\\';
              break;

            default:
              printf("Uknown escape sequence '\\%c'\n", c);
              exit(EXIT_FAILURE);
            }
            j--;
          }
          //      printf("setting j %d to %d\n", j, (int)c);
          needle[j] = c;
        }
        needle_len = j;
      }

      for (i = 0; needle[i]; i++) {
        //printf("i = %d, c %d\n", i,(int)needle[i]);
      }
    }

    else if (strncmp(argVect[argi], "--exitonfind", 12) == 0) {
      exitonfind = TRUE;
    }

    else if (strncmp(argVect[argi], "--help", 6) == 0) {
      printHelp = TRUE;
    }

    else {
      printf("ERROR! Don't understand option '%s'\n", argVect[argi]);
      printHelp = TRUE;
      exitCode = EXIT_FAILURE;
    }
  }

  if (printHelp == TRUE) {
    PrintHelp();
    exit(exitCode);
  }

  if (noleds) {
    strcpy(&boot_loader_file[strlen(boot_loader_file)], "_NOLEDS");
  }

  handle_labels();
}