mirror of
https://github.com/rvtr/ctr_eFuse.git
synced 2025-11-02 00:11:04 -04:00
outputSharpID:getopt でコマンドライン引数の処理を一新。
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_eFuse@218 ff987cc8-cf2f-4642-8568-d52cce064691
This commit is contained in:
parent
49056aa624
commit
7900fdfa34
105
trunk/main3.c
105
trunk/main3.c
@ -7,7 +7,7 @@
|
||||
|
||||
*注意2*
|
||||
testSharpID で検証する場合は真の鍵で行う必要があります。
|
||||
そのため testSharpID において
|
||||
そのため Makefile.testSharpID において
|
||||
|
||||
(1) dummyKey フォルダの dev, prod それぞれに対して
|
||||
eFuse_aesKey.bin, eFuse_privKey.der, eFuse_pubKey.der を差し替える (他はそのままで OK)
|
||||
@ -29,18 +29,21 @@
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef DEV_CYGWIN
|
||||
#include <conio.h>
|
||||
#else // Cygwin
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#endif // Linux
|
||||
|
||||
#include "cr_generate_id.h"
|
||||
|
||||
#define BONDING_OPTION_PROD 0 // 製品用ID
|
||||
#define BONDING_OPTION_DEV 1 // 開発用ID
|
||||
#define BONDING_OPTION_PROD 0 // 製品用ID
|
||||
#define BONDING_OPTION_DEV 1 // 開発用ID
|
||||
#define BONDING_OPTION_DEBUGGER 2 // デバッガ
|
||||
|
||||
#define DEFAULT_OUTPUT_PATH_BASE "ID"
|
||||
|
||||
// extern const int isDummyPrivateKey;
|
||||
|
||||
@ -204,15 +207,25 @@ static double gettimeofday_sec(void)
|
||||
return tv.tv_sec + (double)tv.tv_usec*1e-6;
|
||||
}
|
||||
|
||||
int main(int ac, char *argv[])
|
||||
void showHelp(const char* program)
|
||||
{
|
||||
printf( "%s [OPTION]\n", program );
|
||||
printf( "\t-b bonding_option : Default=0, 0(Prod) 1(Dev) 2(Dev Debugger)\n" );
|
||||
printf( "\t-p output_path : Default=%s[PID]_[BONDING_OPTION].txt\n", DEFAULT_OUTPUT_PATH_BASE );
|
||||
printf( "\t-n output_number : Default=4294967295(0xffffffff)\n" );
|
||||
printf( "\t-h : Show this Help\n" );
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
u8 bonding_option = BONDING_OPTION_PROD;
|
||||
char output_path[512] = "";
|
||||
u32 output_number = 0xffffffff;
|
||||
u32 device_id[CR_NUM_OF_DEVICEID];
|
||||
u8 id[CR_ID_BUF_SIZE]; /* 256byte(2048bit) */
|
||||
int ret_code;
|
||||
int c;
|
||||
FILE *fp;
|
||||
char path[512];
|
||||
double time_start,time_end;
|
||||
long double time_total = 0;
|
||||
int time_count = 0;
|
||||
@ -228,47 +241,55 @@ int main(int ac, char *argv[])
|
||||
#endif
|
||||
|
||||
// コマンドライン引数チェック
|
||||
if ( ac == 1 )
|
||||
int opt;
|
||||
while ((opt = getopt( argc, argv, "b:p:n:h")) != -1)
|
||||
{
|
||||
printf( "Usage : %s BO [FILE]\n", argv[0] );
|
||||
return 0;
|
||||
}
|
||||
if ( ac >= 2 )
|
||||
{
|
||||
u32 temp;
|
||||
str_to_u32( &temp, argv[1] );
|
||||
switch (temp)
|
||||
switch (opt)
|
||||
{
|
||||
case BONDING_OPTION_DEV :
|
||||
bonding_option = BONDING_OPTION_DEV;
|
||||
break;
|
||||
case BONDING_OPTION_PROD :
|
||||
bonding_option = BONDING_OPTION_PROD;
|
||||
break;
|
||||
default :
|
||||
printf( "Invalid BondingOption %s\n", argv[1] );
|
||||
case 'b' :
|
||||
{
|
||||
u32 temp;
|
||||
str_to_u32( &temp, optarg );
|
||||
if (temp != BONDING_OPTION_PROD && temp != BONDING_OPTION_DEV && temp != BONDING_OPTION_DEBUGGER)
|
||||
{
|
||||
printf( "Invalid Bonding Option!\n" );
|
||||
showHelp( argv[0] );
|
||||
return 0;
|
||||
}
|
||||
bonding_option = temp;
|
||||
break;
|
||||
}
|
||||
case 'p' :
|
||||
{
|
||||
sprintf( output_path, "%s", optarg );
|
||||
break;
|
||||
}
|
||||
case 'n' :
|
||||
{
|
||||
str_to_u32( &output_number, optarg );
|
||||
break;
|
||||
}
|
||||
case 'h' :
|
||||
{
|
||||
showHelp( argv[0] );
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if ( ac == 3 )
|
||||
{
|
||||
sprintf( path, "%s", argv[2] );
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bonding_option == BONDING_OPTION_DEV)
|
||||
{
|
||||
sprintf( path, "output/outputSharpID_Dev.txt" );
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( path, "output/outputSharpID_Prod.txt" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// デフォルトパス設定
|
||||
if (output_path[0] == '\0')
|
||||
{
|
||||
sprintf( output_path, "%s_pid%d_bond%d.txt", DEFAULT_OUTPUT_PATH_BASE, getpid(), bonding_option );
|
||||
}
|
||||
|
||||
// 設定表示
|
||||
printf( "bonding_option = %d\n", bonding_option );
|
||||
printf( "output_file = %s\n", output_path );
|
||||
printf( "output_number = %u\n", (unsigned int)output_number );
|
||||
|
||||
// ファイルを開く
|
||||
printf("path=%s\n", path);
|
||||
fp = fopen( path, "w" );
|
||||
fp = fopen( output_path, "w" );
|
||||
if( fp == NULL )
|
||||
{
|
||||
fprintf( stderr, "failed to fopen %s\n", argv[2] );
|
||||
@ -300,7 +321,7 @@ int main(int ac, char *argv[])
|
||||
goto end;
|
||||
}
|
||||
|
||||
for( i = 1 ; i < 0xffffffff; i++ )
|
||||
for( i = 0 ; i < output_number; i++ )
|
||||
{
|
||||
u64 unit;
|
||||
|
||||
@ -309,7 +330,7 @@ int main(int ac, char *argv[])
|
||||
counter2_bak = counter2;
|
||||
|
||||
// counter0 は、1 ずつ加算
|
||||
counter0 = i;
|
||||
counter0 = i + 1;
|
||||
if( counter0 == 0 )
|
||||
{
|
||||
counter0 = 1;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user