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:
n2460 2013-06-25 06:58:53 +00:00
parent 49056aa624
commit 7900fdfa34

View File

@ -7,7 +7,7 @@
*2* *2*
testSharpID testSharpID
testSharpID Makefile.testSharpID
(1) dummyKey dev, prod (1) dummyKey dev, prod
eFuse_aesKey.bin, eFuse_privKey.der, eFuse_pubKey.der ( OK) eFuse_aesKey.bin, eFuse_privKey.der, eFuse_pubKey.der ( OK)
@ -29,18 +29,21 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h>
#ifdef DEV_CYGWIN #ifdef DEV_CYGWIN
#include <conio.h> #include <conio.h>
#else // Cygwin #else // Cygwin
#include <termios.h> #include <termios.h>
#include <unistd.h>
#endif // Linux #endif // Linux
#include "cr_generate_id.h" #include "cr_generate_id.h"
#define BONDING_OPTION_PROD 0 // 製品用ID #define BONDING_OPTION_PROD 0 // 製品用ID
#define BONDING_OPTION_DEV 1 // 開発用ID #define BONDING_OPTION_DEV 1 // 開発用ID
#define BONDING_OPTION_DEBUGGER 2 // デバッガ
#define DEFAULT_OUTPUT_PATH_BASE "ID"
// extern const int isDummyPrivateKey; // extern const int isDummyPrivateKey;
@ -204,15 +207,25 @@ static double gettimeofday_sec(void)
return tv.tv_sec + (double)tv.tv_usec*1e-6; 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; u8 bonding_option = BONDING_OPTION_PROD;
char output_path[512] = "";
u32 output_number = 0xffffffff;
u32 device_id[CR_NUM_OF_DEVICEID]; u32 device_id[CR_NUM_OF_DEVICEID];
u8 id[CR_ID_BUF_SIZE]; /* 256byte(2048bit) */ u8 id[CR_ID_BUF_SIZE]; /* 256byte(2048bit) */
int ret_code; int ret_code;
int c; int c;
FILE *fp; FILE *fp;
char path[512];
double time_start,time_end; double time_start,time_end;
long double time_total = 0; long double time_total = 0;
int time_count = 0; int time_count = 0;
@ -228,47 +241,55 @@ int main(int ac, char *argv[])
#endif #endif
// コマンドライン引数チェック // コマンドライン引数チェック
if ( ac == 1 ) int opt;
while ((opt = getopt( argc, argv, "b:p:n:h")) != -1)
{ {
printf( "Usage : %s BO [FILE]\n", argv[0] ); switch (opt)
return 0;
}
if ( ac >= 2 )
{
u32 temp;
str_to_u32( &temp, argv[1] );
switch (temp)
{ {
case BONDING_OPTION_DEV : case 'b' :
bonding_option = BONDING_OPTION_DEV; {
break; u32 temp;
case BONDING_OPTION_PROD : str_to_u32( &temp, optarg );
bonding_option = BONDING_OPTION_PROD; if (temp != BONDING_OPTION_PROD && temp != BONDING_OPTION_DEV && temp != BONDING_OPTION_DEBUGGER)
break; {
default : printf( "Invalid Bonding Option!\n" );
printf( "Invalid BondingOption %s\n", argv[1] ); 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; 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( output_path, "w" );
fp = fopen( path, "w" );
if( fp == NULL ) if( fp == NULL )
{ {
fprintf( stderr, "failed to fopen %s\n", argv[2] ); fprintf( stderr, "failed to fopen %s\n", argv[2] );
@ -300,7 +321,7 @@ int main(int ac, char *argv[])
goto end; goto end;
} }
for( i = 1 ; i < 0xffffffff; i++ ) for( i = 0 ; i < output_number; i++ )
{ {
u64 unit; u64 unit;
@ -309,7 +330,7 @@ int main(int ac, char *argv[])
counter2_bak = counter2; counter2_bak = counter2;
// counter0 は、1 ずつ加算 // counter0 は、1 ずつ加算
counter0 = i; counter0 = i + 1;
if( counter0 == 0 ) if( counter0 == 0 )
{ {
counter0 = 1; counter0 = 1;