From 7900fdfa346360b18443dd16ba9d0585ab529dad Mon Sep 17 00:00:00 2001 From: n2460 Date: Tue, 25 Jun 2013 06:58:53 +0000 Subject: [PATCH] =?UTF-8?q?outputSharpID:getopt=20=E3=81=A7=E3=82=B3?= =?UTF-8?q?=E3=83=9E=E3=83=B3=E3=83=89=E3=83=A9=E3=82=A4=E3=83=B3=E5=BC=95?= =?UTF-8?q?=E6=95=B0=E3=81=AE=E5=87=A6=E7=90=86=E3=82=92=E4=B8=80=E6=96=B0?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_eFuse@218 ff987cc8-cf2f-4642-8568-d52cce064691 --- trunk/main3.c | 105 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 63 insertions(+), 42 deletions(-) diff --git a/trunk/main3.c b/trunk/main3.c index fe0df9c..f05e3cd 100644 --- a/trunk/main3.c +++ b/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 #include #include +#include #ifdef DEV_CYGWIN #include #else // Cygwin #include -#include #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;