@@ -85,6 +85,8 @@ static struct option long_options[] = {
8585		{"read" , required_argument , NULL , 0 },
8686		{"erase" , required_argument , NULL , 0 },
8787		{"erase-all" , no_argument , NULL , 0 },
88+ 		{"lock" , no_argument , NULL , 0 },
89+ 		{"unlock" , no_argument , NULL , 0 },
8890		{"verify" , required_argument , NULL , 0 },
8991		{"verify-all" , no_argument , NULL , 0 },
9092		{"probe-timeout" , required_argument , NULL , 0 },
@@ -164,6 +166,8 @@ static struct {
164166		uint32_t  size ;
165167	} erase_parts [MAX_ERASE_PARTS ];
166168	bool  erase_all ;
169+ 	bool  lock ;
170+ 	bool  unlock ;
167171	uint16_t  verify_count ;
168172	struct  {
169173		uint32_t  addr ;
@@ -199,6 +203,8 @@ static struct {
199203		.read_count  =  0 ,
200204		.erase_count  =  0 ,
201205		.erase_all  =  false,
206+ 		.lock  =  false,
207+ 		.unlock  =  false,
202208		.verify_count  =  0 ,
203209		.verify_all  =  false,
204210		.probe_timeout  =  DEFAULT_PROBE_TIMEOUT ,
@@ -299,6 +305,10 @@ print_help(const char *progname)
299305	LOGI ("    erase specified flash region" );
300306	LOGI ("  --erase-all" );
301307	LOGI ("    erase the entire flash" );
308+ 	LOGI ("  --lock" );
309+ 	LOGI ("    lock the flash" );
310+ 	LOGI ("  --unlock" );
311+ 	LOGI ("    unlock the flash" );
302312	LOGI ("  --verify <addr:size>" );
303313	LOGI ("    verify specified flash region" );
304314	LOGI ("" );
@@ -527,6 +537,12 @@ main(int argc, char **argv)
527537				} else  if  (strcmp (name , "emmc" ) ==  0 ) {
528538					options .target  =  TARGET_EMMC ;
529539					break ;
540+ 				} else  if  (strcmp (name , "lock" ) ==  0 ) {
541+ 					options .lock  =  true;
542+ 					break ;
543+ 				} else  if  (strcmp (name , "unlock" ) ==  0 ) {
544+ 					options .unlock  =  true;
545+ 					break ;
530546				} else  {
531547					print_help (argv [0 ]);
532548					return  0 ;
@@ -924,6 +940,13 @@ serial_burn(cskburn_partition_t *parts, int parts_cnt)
924940		LOGI ("Detected eMMC size: %"  PRIu64  " MB" , flash_size  >> 20 );
925941	}
926942
943+ 	if  (options .unlock ) {
944+ 		if  ((ret  =  cskburn_serial_unlock (dev , options .target )) !=  0 ) {
945+ 			LOGE_RET (ret , "ERROR: Failed locking device" );
946+ 			goto err_enter ;
947+ 		}
948+ 	}
949+ 
927950	for  (int  i  =  0 ; i  <  options .read_count ; i ++ ) {
928951		if  (options .read_parts [i ].addr  >= flash_size ) {
929952			LOGE ("ERROR: The starting boundary of read address (0x%08X) exceeds the capacity of " 
@@ -1108,6 +1131,13 @@ serial_burn(cskburn_partition_t *parts, int parts_cnt)
11081131		}
11091132	}
11101133
1134+ 	if  (options .lock ) {
1135+ 		if  ((ret  =  cskburn_serial_lock (dev , options .target )) !=  0 ) {
1136+ 			LOGE_RET (ret , "ERROR: Failed unlocking device" );
1137+ 			goto err_enter ;
1138+ 		}
1139+ 	}
1140+ 
11111141	if  (jump_addr ) {
11121142		LOGI ("Jumping to 0x%08X..." , jump_addr );
11131143	} else  if  (!options .no_reset ) {
0 commit comments