mirror of
https://github.com/rvtr/ctr_eFuse.git
synced 2025-11-02 00:11:04 -04:00
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_eFuse@213 ff987cc8-cf2f-4642-8568-d52cce064691
148 lines
4.1 KiB
C
148 lines
4.1 KiB
C
#include <stdio.h>
|
||
|
||
#include "cr_generate_id.h"
|
||
#include "util.h"
|
||
|
||
int main(int argc, char* argv[])
|
||
{
|
||
int i;
|
||
int ret_code = 0;
|
||
|
||
u8 id_buf[CR_ID_BUF_SIZE]; // 出力される ID の格納されるバッファ
|
||
u32 device_id[CR_NUM_OF_DEVICEID]; // 生成関数に入力する ID
|
||
int bonding_option = -1; // ボンディングオプション
|
||
|
||
// 時間計測用
|
||
double time_start = 0;
|
||
double time_end = 0;
|
||
long double time_total = 0;
|
||
int time_count = 0;
|
||
|
||
// カウンタ
|
||
u32 counter0 = 0;
|
||
u64 counter1 = 0;
|
||
u64 counter2 = 0;
|
||
|
||
// 引数チェック
|
||
if ( argc == 1 )
|
||
{
|
||
printf("Usage : %s bonding_option\n", argv[0]);
|
||
printf("\tbonding_option : 00 01 10\n", argv[0]);
|
||
return 0;
|
||
}
|
||
if ( argc >= 2 && strlen(argv[1]) >= 2 )
|
||
{
|
||
u8 bo_hi = argv[1][0] - '0';
|
||
u8 bo_lo = argv[1][1] - '0';
|
||
bonding_option = bo_hi*2 + bo_lo;
|
||
}
|
||
if ( bonding_option < 0 || 2 <= bonding_option )
|
||
{
|
||
printf("Invalid bonding_option\n");
|
||
return -1;
|
||
}
|
||
|
||
printf("Now Initializing ... ");
|
||
fflush(stdout);
|
||
|
||
// cr_generate_id を使用する前に呼び出す
|
||
ret_code = cr_generate_id_initialize( id_buf );
|
||
if ( ret_code != CR_GENID_SUCCESS )
|
||
{
|
||
printf( "error : cr_generate_id_initialize\n" );
|
||
return -1;
|
||
}
|
||
printf("done.\n");
|
||
|
||
// 入力のための初期化
|
||
keyboard_initialize();
|
||
|
||
for ( i = 1; i < 0xffffffff; i++ )
|
||
{
|
||
u64 unit;
|
||
|
||
// counter0 は 1 ずつ加算
|
||
counter0 = i;
|
||
if( counter0 == 0 )
|
||
{
|
||
counter0 = 1;
|
||
}
|
||
|
||
// counter1 は、"1~4 の乱数値" を加算
|
||
unit = (u64)( ( rand() & 0x03 ) + 1 );
|
||
counter1 += unit;
|
||
|
||
// counter2 は、"0 以外の 32bit 乱数値" を加算
|
||
do {
|
||
unit = ((u64)rand() & 0xffff) | ( ((u64)rand() & 0xffff) << 16 );
|
||
} while( unit == 0 );
|
||
counter2 += unit;
|
||
|
||
// counter から device_id を作成
|
||
device_id[0] = counter0;
|
||
device_id[1] = (u32)(counter1 & 0xffffffff );
|
||
device_id[2] = (u32)( (counter1 >> 32) & 0xffffffff );
|
||
device_id[3] = (u32)(counter2 & 0xffffffff );
|
||
device_id[4] = (u32)( (counter2 >> 32) & 0xffffffff );
|
||
|
||
// ID 生成
|
||
time_start = gettimeofday_sec();
|
||
ret_code = cr_generate_id( device_id, id_buf, bonding_option );
|
||
if( ret_code != CR_GENID_SUCCESS )
|
||
{
|
||
fprintf(stderr, "cr_generate_id failed c=0x%08x\n", counter0);
|
||
}
|
||
else
|
||
{
|
||
time_end = gettimeofday_sec();
|
||
time_total += (long double)(time_end - time_start);
|
||
time_count++;
|
||
}
|
||
|
||
counter0++;
|
||
counter1 += (u64)rand();
|
||
counter2 += (u64)rand();
|
||
|
||
if ( keyboard_is_hit() != 0 )
|
||
{
|
||
char c = keyboard_get_char();
|
||
// p で ID, eFuseID, 処理時間を表示
|
||
// s で eFuseID を保存
|
||
// q で終了
|
||
switch ( c )
|
||
{
|
||
case 'p' :
|
||
printf("ID[0] = 0x%08x\n", device_id[0]);
|
||
printf("ID[1] = 0x%08x%08x\n", device_id[2], device_id[1] );
|
||
printf("ID[2] = 0x%08x%08x\n", device_id[4], device_id[3] );
|
||
debug_print_array( "eFuseID", id_buf, sizeof(id_buf) );
|
||
printf("time av. = %8.8f sec\n", (double)(time_total/(long double)time_count));
|
||
break;
|
||
|
||
case 's' :
|
||
debug_file_output( device_id[0], "bin", id_buf, sizeof(id_buf) );
|
||
printf("./0x%08x.%s is saved.\n", device_id[0], "bin");
|
||
break;
|
||
|
||
case 'q' :
|
||
goto end;
|
||
}
|
||
}
|
||
}
|
||
|
||
end:
|
||
// 入力終了
|
||
keyboard_finalize();
|
||
|
||
// cr_generate_id を使用した後に呼び出す
|
||
if ( cr_generate_id_finalize( id_buf ) != CR_GENID_SUCCESS )
|
||
{
|
||
printf( "error : cr_generate_id_finalize\n" );
|
||
return 0; // error
|
||
}
|
||
|
||
printf( "end of main.\n" );
|
||
|
||
return 0;
|
||
}
|