@@ -2334,14 +2334,18 @@ static int sjtag_unlock(int argc, char **argv)
23342334
23352335 ret = switchtec_sjtag_status_get (cfg .dev , & status );
23362336 if (ret )
2337- switchtec_perror ("mfg sjtag-sts-get" );
2337+ {
2338+ switchtec_perror ("Failed to retrive the SJTAG Status from the device" );
2339+ ret = -1 ;
2340+ break ;
2341+ }
23382342
23392343 if (true == cfg .verbose )
23402344 {
23412345 printf ("SJTAG Mode: %x\n" , (status .data & 0x03 ));
23422346 }
23432347
2344- /* For Open mode - Unlock status(status.data[3 ]) should 1 */
2348+ /* For Open mode - Unlock status(status.data[2 ]) should 1 */
23452349 if ((((status .data & 0x03 ) == 0x00 ) || ((status .data & 0x04 ) == 0x04 )) && (false == cfg .force_hr ))
23462350 {
23472351 printf ("SJTAG is in Open State\n" );
@@ -2352,50 +2356,63 @@ static int sjtag_unlock(int argc, char **argv)
23522356 }
23532357 else
23542358 {
2355- if (cfg .sjtag_debug_token_file ) {
2359+ if (cfg .sjtag_debug_token_file )
2360+ {
23562361 ret = switchtec_read_sjtag_debug_token_file (cfg .sjtag_debug_token , & debug_token );
23572362 fclose (cfg .sjtag_debug_token );
2358- if (ret ) {
2359- printf ("Invalid SJTAG Debug Token File\n" );
2360- ret = -6 ;
2363+ if (ret )
2364+ {
2365+ switchtec_perror ("Invalid SJTAG Debug Token File" );
2366+ ret = -1 ;
23612367 break ;
23622368 }
23632369 }
23642370 else
23652371 {
23662372 ret = switchtec_sjtag_get_uuid_idcode (cfg .dev , uuid .uuid , sjtag_unlock .idcode );
23672373 if (ret )
2368- switchtec_perror ("mfg sjtag-get-uuid" );
2374+ {
2375+ switchtec_perror ("Failed to retrive the UUID/IDCODE from the device" );
2376+ ret = -1 ;
2377+ break ;
2378+ }
23692379
23702380 ret = switchtec_sn_ver_get (cfg .dev , & sn_info );
2381+ if (ret )
2382+ {
2383+ switchtec_perror ("Failed to retrive the SUV from the device" );
2384+ ret = -1 ;
2385+ break ;
2386+ }
23712387
23722388 ret = sjtag_debug_token_gen (sjtag_unlock .idcode , uuid .uuid , (uint8_t * )& sn_info .ver_sec_unlock , debug_token .debug_token , cfg .verbose );
23732389 if (ret )
23742390 {
23752391 ret = -1 ;
23762392 break ;
23772393 }
2378- debug_token_bin_file = fopen ("sjtag_debug_token.bin" , "wb" );
23792394
2380- if (NULL == debug_token_bin_file ) {
2381- perror ("Error opening file" );
2395+ debug_token_bin_file = fopen ("sjtag_debug_token.bin" , "wb" );
2396+ if (NULL == debug_token_bin_file )
2397+ {
2398+ switchtec_perror ("Error opening file" );
2399+ ret = -1 ;
2400+ break ;
23822401 }
23832402
23842403 fwrite (debug_token .debug_token , sizeof (uint8_t ), SJTAG_DEBUG_TOKEN_LEN , debug_token_bin_file );
23852404 fclose (debug_token_bin_file );
2386- if (getcwd (dir_path , sizeof (dir_path )) == NULL )
2387- {
2388- printf ("Error getting the current working directory. sjtag_debug_token.bin was saved in the current directory" );
2389- }
2390- else
2391- {
2392- printf ("Generated SJTAG Debug Token Path: %s/sjtag_debug_token.bin\n" , dir_path );
2393- }
2405+ getcwd (dir_path , sizeof (dir_path ));
2406+ printf ("Generated SJTAG Debug Token Path: %s/sjtag_debug_token.bin\n" , dir_path );
23942407 }
23952408
23962409 ret = switchtec_sjtag_get_nonce (cfg .dev , & nonce );
23972410 if (ret )
2398- switchtec_perror ("mfg sjtag-get-uuid-nonce" );
2411+ {
2412+ switchtec_perror ("Failed to retrive the Nonce from the device" );
2413+ ret = -1 ;
2414+ break ;
2415+ }
23992416
24002417 sjtag_hr_calc (debug_token .debug_token , nonce .nonce , sjtag_hr , cfg .verbose );
24012418
0 commit comments