11#include <errno.h>
22#include <getopt.h>
3+ #include <inttypes.h>
34#include <libgen.h>
45#include <stdbool.h>
56#include <stdint.h>
2930#define DEFAULT_RESET_ATTEMPTS 4
3031#define DEFAULT_RESET_DELAY 500
3132
32- #define DEFAULT_CHIP CHIP_TYPE_ARCS
33+ #define DEFAULT_CHIP CHIP_TYPE_4
3334
34- #define CHIP_TO_STR (chip ) \
35- ((chip) == CHIP_TYPE_3 ? "3" : \
36- (chip) == CHIP_TYPE_4 ? "4" : \
37- (chip) == CHIP_TYPE_6 ? "6" : \
38- (chip) == CHIP_TYPE_ARCS ? "arcs" : "unknown")
35+ #define CHIP_TO_STR (chip ) \
36+ ((chip) == CHIP_TYPE_3 ? "3" \
37+ : (chip) == CHIP_TYPE_4 ? "4" \
38+ : (chip) == CHIP_TYPE_6 ? "6" \
39+ : (chip) == CHIP_TYPE_ARCS ? "arcs" \
40+ : "unknown")
3941
4042static struct option long_options [] = {
4143 {"help" , no_argument , NULL , 'h' },
@@ -62,6 +64,7 @@ static struct option long_options[] = {
6264 {"nand-dat1" , required_argument , NULL , 0 },
6365 {"nand-dat2" , required_argument , NULL , 0 },
6466 {"nand-dat3" , required_argument , NULL , 0 },
67+ {"emmc" , no_argument , NULL , 0 },
6568 {"ram" , no_argument , NULL , 'r' },
6669 {"jump" , required_argument , NULL , 0 },
6770 {"chip-id" , no_argument , NULL , 0 },
@@ -72,7 +75,6 @@ static struct option long_options[] = {
7275 {"unlock" , no_argument , NULL , 0 },
7376 {"verify" , required_argument , NULL , 0 },
7477 {"verify-all" , no_argument , NULL , 0 },
75- {"emmc" , no_argument , NULL , 0 },
7678 {"probe-timeout" , required_argument , NULL , 0 },
7779 {"reset-attempts" , required_argument , NULL , 0 },
7880 {"reset-delay" , required_argument , NULL , 0 },
@@ -128,7 +130,7 @@ static struct {
128130 bool repeat ;
129131 cskburn_protocol_t protocol ;
130132 cskburn_action_t action ;
131- uint32_t chip ;
133+ chip_type_t chip ;
132134#ifndef WITHOUT_USB
133135 char * usb ;
134136 int16_t usb_bus ;
@@ -265,6 +267,8 @@ print_help(const char *progname)
265267 LOGI (" verify all partitions after burning" );
266268 LOGI (" -n, --nand" );
267269 LOGI (" burn to NAND flash (CSK6 only)" );
270+ LOGI (" --emmc" );
271+ LOGI (" burn to eMMC (arcs only)" );
268272 LOGI (" --probe-timeout <ms>" );
269273 LOGI (" timeout for probing device (default: %d ms)" , DEFAULT_PROBE_TIMEOUT );
270274 LOGI (" --reset-attempts <n>" );
@@ -293,8 +297,6 @@ print_help(const char *progname)
293297 LOGI (" unlock the flash" );
294298 LOGI (" --verify <addr:size>" );
295299 LOGI (" verify specified flash region" );
296- LOGI (" --emmc" );
297- LOGI (" burn to emmc (arcs only)" );
298300 LOGI ("" );
299301
300302 LOGI ("Example:" );
@@ -353,15 +355,15 @@ main(int argc, char **argv)
353355 options .chip = CHIP_TYPE_ARCS ;
354356 } else {
355357 if (!scan_int (optarg , & options .chip )) {
356- LOGE ("ERROR: Only 3, 4 6 or arcs of chip is supported" );
358+ LOGE ("ERROR: Only 3, 4, 6 or arcs of chip is supported" );
357359 return EINVAL ;
358360 }
359361 }
360- if (options .chip != 6 && options .chip != 4 && options .chip != 3 && options .chip != CHIP_TYPE_ARCS ) {
361- LOGE ("ERROR: Only 3, 4 6 or arcs of chip is supported" );
362+ if (options .chip != 6 && options .chip != 4 && options .chip != 3 &&
363+ options .chip != CHIP_TYPE_ARCS ) {
364+ LOGE ("ERROR: Only 3, 4, 6 or arcs of chip is supported" );
362365 return EINVAL ;
363366 }
364- if (options .chip == 3 ) options .chip = CHIP_TYPE_4 ;
365367 break ;
366368 case 'n' :
367369 options .target = TARGET_NAND ;
@@ -651,14 +653,13 @@ main(int argc, char **argv)
651653
652654 if (options .chip == CHIP_TYPE_ARCS && options .target == TARGET_FLASH ) {
653655 if (options .erase_count + parts_cnt > MAX_ERASE_PARTS ) {
654- LOGE ("ERROR: Only up to %d partitions can be erased at the same time" ,
655- MAX_ERASE_PARTS );
656+ LOGE ("ERROR: Only up to %d partitions can be erased at the same time" , MAX_ERASE_PARTS );
656657 ret = EINVAL ;
657658 goto exit ;
658659 }
659660 for (int i = options .erase_count ; i < options .erase_count + parts_cnt ; i ++ ) {
660661 options .erase_parts [i ].addr = parts [i ].addr ;
661- options .erase_parts [i ].size = (parts [i ].reader -> size + 4095 ) & ~ 4095 ;
662+ options .erase_parts [i ].size = align_up (parts [i ].reader -> size , 4096 ) ;
662663 }
663664 options .erase_count += parts_cnt ;
664665 }
@@ -902,27 +903,27 @@ serial_burn(cskburn_partition_t *parts, int parts_cnt)
902903
903904 LOGD ("flash-id: %02X%02X%02X" , (flash_id ) & 0xFF , (flash_id >> 8 ) & 0xFF ,
904905 (flash_id >> 16 ) & 0xFF );
905- LOGI ("Detected flash size: %lu MB" , flash_size >> 20 );
906+ LOGI ("Detected flash size: %" PRIu64 " MB" , flash_size >> 20 );
906907 } else if (options .target == TARGET_NAND ) {
907908 if ((ret = cskburn_serial_init_nand (dev , & nand_config , & flash_size )) != 0 ) {
908909 LOGE_RET (ret , "ERROR: Failed initializing NAND" );
909910 goto err_enter ;
910911 }
911912
912- LOGI ("Detected NAND size: %lu MB" , flash_size >> 20 );
913+ LOGI ("Detected NAND size: %" PRIu64 " MB" , flash_size >> 20 );
913914 } else if (options .target == TARGET_EMMC ) {
914915 card_info_t card_info ;
915916
916917 if ((ret = cskburn_serial_get_emmc_info (dev , & card_info )) != 0 ) {
917- LOGE_RET (ret , "ERROR: Failed get emmc info" );
918+ LOGE_RET (ret , "ERROR: Failed get eMMC info" );
918919 goto err_enter ;
919920 }
920921
921- LOGI ("Detected emmc info, sctcnts: 0x%x sctsize: 0x%x erasize: 0x%x cardtype: %u" ,
922- card_info .sctcnts , card_info .sctsize , card_info .erasize , card_info .cardtype );
922+ LOGD ("Detected eMMC info, sctcnts: 0x%x sctsize: 0x%x erasize: 0x%x cardtype: %u" ,
923+ card_info .sctcnts , card_info .sctsize , card_info .erasize , card_info .cardtype );
923924
924925 flash_size = (uint64_t )card_info .sctcnts * card_info .sctsize ;
925- LOGI ("flash_size : %lu MB" , flash_size >> 20 );
926+ LOGI ("Detected eMMC size : %" PRIu64 " MB" , flash_size >> 20 );
926927 }
927928
928929 if (options .unlock ) {
@@ -935,13 +936,13 @@ serial_burn(cskburn_partition_t *parts, int parts_cnt)
935936 for (int i = 0 ; i < options .read_count ; i ++ ) {
936937 if (options .read_parts [i ].addr >= flash_size ) {
937938 LOGE ("ERROR: The starting boundary of read address (0x%08X) exceeds the capacity of "
938- "flash (%lu MB)" ,
939+ "flash (%" PRIu64 " MB)" ,
939940 options .read_parts [i ].addr , flash_size >> 20 );
940941 ret = - EINVAL ;
941942 goto err_enter ;
942943 } else if (options .read_parts [i ].addr + options .read_parts [i ].size > flash_size ) {
943944 LOGE ("ERROR: The ending boundary of read address (0x%08X) exceeds the capacity of "
944- "flash (%lu MB)" ,
945+ "flash (%" PRIu64 " MB)" ,
945946 options .read_parts [i ].addr + options .read_parts [i ].size , flash_size >> 20 );
946947 ret = - EINVAL ;
947948 goto err_enter ;
@@ -951,12 +952,12 @@ serial_burn(cskburn_partition_t *parts, int parts_cnt)
951952 for (int i = 0 ; i < options .verify_count ; i ++ ) {
952953 if (options .verify_parts [i ].addr >= flash_size ) {
953954 LOGE ("ERROR: The starting boundary of verify address (0x%08X) exceeds the capacity of "
954- "flash (%lu MB)" ,
955+ "flash (%" PRIu64 " MB)" ,
955956 options .verify_parts [i ].addr , flash_size >> 20 );
956957 goto err_enter ;
957958 } else if (options .verify_parts [i ].addr + options .verify_parts [i ].size > flash_size ) {
958959 LOGE ("ERROR: The ending boundary of verify address (0x%08X) exceeds the capacity of "
959- "flash (%lu MB)" ,
960+ "flash (%" PRIu64 " MB)" ,
960961 options .verify_parts [i ].addr + options .verify_parts [i ].size , flash_size >> 20 );
961962 goto err_enter ;
962963 }
@@ -973,13 +974,13 @@ serial_burn(cskburn_partition_t *parts, int parts_cnt)
973974 goto err_enter ;
974975 } else if (options .erase_parts [i ].addr >= flash_size ) {
975976 LOGE ("ERROR: The starting boundary of erase address (0x%08X) exceeds the capacity of "
976- "flash (%lu MB)" ,
977+ "flash (%" PRIu64 " MB)" ,
977978 options .erase_parts [i ].addr , flash_size >> 20 );
978979 ret = - EINVAL ;
979980 goto err_enter ;
980981 } else if (options .erase_parts [i ].addr + options .erase_parts [i ].size > flash_size ) {
981982 LOGE ("ERROR: The ending boundary of erase address (0x%08X) exceeds the capacity of "
982- "flash (%lu MB)" ,
983+ "flash (%" PRIu64 " MB)" ,
983984 options .erase_parts [i ].addr + options .erase_parts [i ].size , flash_size >> 20 );
984985 ret = - EINVAL ;
985986 goto err_enter ;
@@ -1006,13 +1007,13 @@ serial_burn(cskburn_partition_t *parts, int parts_cnt)
10061007 if (options .target == TARGET_FLASH || options .target == TARGET_NAND ) {
10071008 if (parts [i ].addr >= flash_size ) {
10081009 LOGE ("ERROR: The starting boundary of partition %d (0x%08X) exceeds the capacity "
1009- "of target (%lu MB)" ,
1010+ "of target (%" PRIu64 " MB)" ,
10101011 i + 1 , parts [i ].addr , flash_size >> 20 );
10111012 ret = - EINVAL ;
10121013 goto err_enter ;
10131014 } else if (parts [i ].addr + parts [i ].reader -> size > flash_size ) {
10141015 LOGE ("ERROR: The ending boundary of partition %d (0x%08X) exceeds the capacity of "
1015- "target (%lu MB)" ,
1016+ "target (%" PRIu64 " MB)" ,
10161017 i + 1 , parts [i ].addr + parts [i ].reader -> size , flash_size >> 20 );
10171018 ret = - EINVAL ;
10181019 goto err_enter ;
0 commit comments