mirror of
				https://xff.cz/git/u-boot/
				synced 2025-10-27 08:33:10 +01:00 
			
		
		
		
	mtd: cfi: introduce CFI_FLASH_BANKS
Replace CONFIG_SYS_MAX_FLASH_BANKS by CFI_FLASH_BANKS to prepare Kconfig migration and avoid to redefine CONFIG_SYS_MAX_FLASH_BANKS in cfi_flash.h. After this patch CONFIG_SYS_MAX_FLASH_BANKS should be never used in the cfi code: use CFI_MAX_FLASH_BANKS for struct size or CFI_FLASH_BANKS for number of CFI banks which can be dynamic. This patch modify all the files which include mtd/cfi_flash.h. Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com> Reviewed-by: Stefan Roese <sr@denx.de>
This commit is contained in:
		
				
					committed by
					
						 Tom Rini
						Tom Rini
					
				
			
			
				
	
			
			
			
						parent
						
							c8363b12b2
						
					
				
				
					commit
					98150e7e8c
				
			| @@ -338,7 +338,7 @@ static int do_imls_nor(void) | |||||||
| 	void *hdr; | 	void *hdr; | ||||||
|  |  | ||||||
| 	for (i = 0, info = &flash_info[0]; | 	for (i = 0, info = &flash_info[0]; | ||||||
| 		i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) { | 		i < CFI_FLASH_BANKS; ++i, ++info) { | ||||||
|  |  | ||||||
| 		if (info->flash_id == FLASH_UNKNOWN) | 		if (info->flash_id == FLASH_UNKNOWN) | ||||||
| 			goto next_bank; | 			goto next_bank; | ||||||
|   | |||||||
							
								
								
									
										34
									
								
								cmd/flash.c
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								cmd/flash.c
									
									
									
									
									
								
							| @@ -60,7 +60,7 @@ abbrev_spec(char *str, flash_info_t **pinfo, int *psf, int *psl) | |||||||
|  |  | ||||||
| 	bank = dectoul(str, &ep); | 	bank = dectoul(str, &ep); | ||||||
| 	if (ep == str || *ep != '\0' || | 	if (ep == str || *ep != '\0' || | ||||||
| 	    bank < 1 || bank > CONFIG_SYS_MAX_FLASH_BANKS) | 	    bank < 1 || bank > CFI_FLASH_BANKS) | ||||||
| 		return -1; | 		return -1; | ||||||
|  |  | ||||||
| 	fp = &flash_info[bank - 1]; | 	fp = &flash_info[bank - 1]; | ||||||
| @@ -104,7 +104,7 @@ int flash_sect_roundb(ulong *addr) | |||||||
|  |  | ||||||
| 	/* find the end addr of the sector where the *addr is */ | 	/* find the end addr of the sector where the *addr is */ | ||||||
| 	found = 0; | 	found = 0; | ||||||
| 	for (bank = 0; bank < CONFIG_SYS_MAX_FLASH_BANKS && !found; ++bank) { | 	for (bank = 0; bank < CFI_FLASH_BANKS && !found; ++bank) { | ||||||
| 		info = &flash_info[bank]; | 		info = &flash_info[bank]; | ||||||
| 		for (i = 0; i < info->sector_count && !found; ++i) { | 		for (i = 0; i < info->sector_count && !found; ++i) { | ||||||
| 			/* get the end address of the sector */ | 			/* get the end address of the sector */ | ||||||
| @@ -201,13 +201,13 @@ flash_fill_sect_ranges(ulong addr_first, ulong addr_last, | |||||||
|  |  | ||||||
| 	*s_count = 0; | 	*s_count = 0; | ||||||
|  |  | ||||||
| 	for (bank = 0; bank < CONFIG_SYS_MAX_FLASH_BANKS; ++bank) { | 	for (bank = 0; bank < CFI_FLASH_BANKS; ++bank) { | ||||||
| 		s_first[bank] = -1;	/* first sector to erase	*/ | 		s_first[bank] = -1;	/* first sector to erase	*/ | ||||||
| 		s_last[bank] = -1;	/* last  sector to erase	*/ | 		s_last[bank] = -1;	/* last  sector to erase	*/ | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	for (bank = 0, info = &flash_info[0]; | 	for (bank = 0, info = &flash_info[0]; | ||||||
| 	     (bank < CONFIG_SYS_MAX_FLASH_BANKS) && (addr_first <= addr_last); | 	     (bank < CFI_FLASH_BANKS) && (addr_first <= addr_last); | ||||||
| 	     ++bank, ++info) { | 	     ++bank, ++info) { | ||||||
| 		ulong b_end; | 		ulong b_end; | ||||||
| 		int sect; | 		int sect; | ||||||
| @@ -278,7 +278,7 @@ static int do_flinfo(struct cmd_tbl *cmdtp, int flag, int argc, | |||||||
|  |  | ||||||
| #ifdef CONFIG_MTD_NOR_FLASH | #ifdef CONFIG_MTD_NOR_FLASH | ||||||
| 	if (argc == 1) {	/* print info for all FLASH banks */ | 	if (argc == 1) {	/* print info for all FLASH banks */ | ||||||
| 		for (bank = 0; bank < CONFIG_SYS_MAX_FLASH_BANKS; ++bank) { | 		for (bank = 0; bank < CFI_FLASH_BANKS; ++bank) { | ||||||
| 			printf("\nBank # %ld: ", bank + 1); | 			printf("\nBank # %ld: ", bank + 1); | ||||||
|  |  | ||||||
| 			flash_print_info(&flash_info[bank]); | 			flash_print_info(&flash_info[bank]); | ||||||
| @@ -287,9 +287,9 @@ static int do_flinfo(struct cmd_tbl *cmdtp, int flag, int argc, | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	bank = hextoul(argv[1], NULL); | 	bank = hextoul(argv[1], NULL); | ||||||
| 	if (bank < 1 || bank > CONFIG_SYS_MAX_FLASH_BANKS) { | 	if (bank < 1 || bank > CFI_FLASH_BANKS) { | ||||||
| 		printf("Only FLASH Banks # 1 ... # %d supported\n", | 		printf("Only FLASH Banks # 1 ... # %d supported\n", | ||||||
| 		       CONFIG_SYS_MAX_FLASH_BANKS); | 		       CFI_FLASH_BANKS); | ||||||
| 		return 1; | 		return 1; | ||||||
| 	} | 	} | ||||||
| 	printf("\nBank # %ld: ", bank); | 	printf("\nBank # %ld: ", bank); | ||||||
| @@ -316,7 +316,7 @@ static int do_flerase(struct cmd_tbl *cmdtp, int flag, int argc, | |||||||
| 		return CMD_RET_USAGE; | 		return CMD_RET_USAGE; | ||||||
|  |  | ||||||
| 	if (strcmp(argv[1], "all") == 0) { | 	if (strcmp(argv[1], "all") == 0) { | ||||||
| 		for (bank = 1; bank <= CONFIG_SYS_MAX_FLASH_BANKS; ++bank) { | 		for (bank = 1; bank <= CFI_FLASH_BANKS; ++bank) { | ||||||
| 			printf("Erase Flash Bank # %ld ", bank); | 			printf("Erase Flash Bank # %ld ", bank); | ||||||
| 			info = &flash_info[bank - 1]; | 			info = &flash_info[bank - 1]; | ||||||
| 			rcode = flash_erase(info, 0, info->sector_count - 1); | 			rcode = flash_erase(info, 0, info->sector_count - 1); | ||||||
| @@ -366,9 +366,9 @@ static int do_flerase(struct cmd_tbl *cmdtp, int flag, int argc, | |||||||
|  |  | ||||||
| 	if (strcmp(argv[1], "bank") == 0) { | 	if (strcmp(argv[1], "bank") == 0) { | ||||||
| 		bank = hextoul(argv[2], NULL); | 		bank = hextoul(argv[2], NULL); | ||||||
| 		if (bank < 1 || bank > CONFIG_SYS_MAX_FLASH_BANKS) { | 		if (bank < 1 || bank > CFI_FLASH_BANKS) { | ||||||
| 			printf("Only FLASH Banks # 1 ... # %d supported\n", | 			printf("Only FLASH Banks # 1 ... # %d supported\n", | ||||||
| 			       CONFIG_SYS_MAX_FLASH_BANKS); | 			       CFI_FLASH_BANKS); | ||||||
| 			return 1; | 			return 1; | ||||||
| 		} | 		} | ||||||
| 		printf("Erase Flash Bank # %ld ", bank); | 		printf("Erase Flash Bank # %ld ", bank); | ||||||
| @@ -397,7 +397,7 @@ int flash_sect_erase(ulong addr_first, ulong addr_last) | |||||||
| { | { | ||||||
| 	flash_info_t *info; | 	flash_info_t *info; | ||||||
| 	ulong bank; | 	ulong bank; | ||||||
| 	int s_first[CONFIG_SYS_MAX_FLASH_BANKS], s_last[CONFIG_SYS_MAX_FLASH_BANKS]; | 	int s_first[CFI_FLASH_BANKS], s_last[CFI_FLASH_BANKS]; | ||||||
| 	int erased = 0; | 	int erased = 0; | ||||||
| 	int planned; | 	int planned; | ||||||
| 	int rcode = 0; | 	int rcode = 0; | ||||||
| @@ -406,7 +406,7 @@ int flash_sect_erase(ulong addr_first, ulong addr_last) | |||||||
|  |  | ||||||
| 	if (planned && rcode == 0) { | 	if (planned && rcode == 0) { | ||||||
| 		for (bank = 0, info = &flash_info[0]; | 		for (bank = 0, info = &flash_info[0]; | ||||||
| 		     bank < CONFIG_SYS_MAX_FLASH_BANKS && rcode == 0; | 		     bank < CFI_FLASH_BANKS && rcode == 0; | ||||||
| 		     ++bank, ++info) { | 		     ++bank, ++info) { | ||||||
| 			if (s_first[bank] >= 0) { | 			if (s_first[bank] >= 0) { | ||||||
| 				erased += s_last[bank] - s_first[bank] + 1; | 				erased += s_last[bank] - s_first[bank] + 1; | ||||||
| @@ -463,7 +463,7 @@ static int do_protect(struct cmd_tbl *cmdtp, int flag, int argc, | |||||||
|  |  | ||||||
| #ifdef CONFIG_MTD_NOR_FLASH | #ifdef CONFIG_MTD_NOR_FLASH | ||||||
| 	if (strcmp(argv[2], "all") == 0) { | 	if (strcmp(argv[2], "all") == 0) { | ||||||
| 		for (bank = 1; bank <= CONFIG_SYS_MAX_FLASH_BANKS; ++bank) { | 		for (bank = 1; bank <= CFI_FLASH_BANKS; ++bank) { | ||||||
| 			info = &flash_info[bank - 1]; | 			info = &flash_info[bank - 1]; | ||||||
| 			if (info->flash_id == FLASH_UNKNOWN) | 			if (info->flash_id == FLASH_UNKNOWN) | ||||||
| 				continue; | 				continue; | ||||||
| @@ -547,9 +547,9 @@ static int do_protect(struct cmd_tbl *cmdtp, int flag, int argc, | |||||||
|  |  | ||||||
| 	if (strcmp(argv[2], "bank") == 0) { | 	if (strcmp(argv[2], "bank") == 0) { | ||||||
| 		bank = hextoul(argv[3], NULL); | 		bank = hextoul(argv[3], NULL); | ||||||
| 		if (bank < 1 || bank > CONFIG_SYS_MAX_FLASH_BANKS) { | 		if (bank < 1 || bank > CFI_FLASH_BANKS) { | ||||||
| 			printf("Only FLASH Banks # 1 ... # %d supported\n", | 			printf("Only FLASH Banks # 1 ... # %d supported\n", | ||||||
| 			       CONFIG_SYS_MAX_FLASH_BANKS); | 			       CFI_FLASH_BANKS); | ||||||
| 			return 1; | 			return 1; | ||||||
| 		} | 		} | ||||||
| 		printf("%sProtect Flash Bank # %ld\n", | 		printf("%sProtect Flash Bank # %ld\n", | ||||||
| @@ -596,7 +596,7 @@ int flash_sect_protect(int p, ulong addr_first, ulong addr_last) | |||||||
| { | { | ||||||
| 	flash_info_t *info; | 	flash_info_t *info; | ||||||
| 	ulong bank; | 	ulong bank; | ||||||
| 	int s_first[CONFIG_SYS_MAX_FLASH_BANKS], s_last[CONFIG_SYS_MAX_FLASH_BANKS]; | 	int s_first[CFI_FLASH_BANKS], s_last[CFI_FLASH_BANKS]; | ||||||
| 	int protected, i; | 	int protected, i; | ||||||
| 	int planned; | 	int planned; | ||||||
| 	int rcode; | 	int rcode; | ||||||
| @@ -607,7 +607,7 @@ int flash_sect_protect(int p, ulong addr_first, ulong addr_last) | |||||||
|  |  | ||||||
| 	if (planned && rcode == 0) { | 	if (planned && rcode == 0) { | ||||||
| 		for (bank = 0, info = &flash_info[0]; | 		for (bank = 0, info = &flash_info[0]; | ||||||
| 		     bank < CONFIG_SYS_MAX_FLASH_BANKS; ++bank, ++info) { | 		     bank < CFI_FLASH_BANKS; ++bank, ++info) { | ||||||
| 			if (info->flash_id == FLASH_UNKNOWN) | 			if (info->flash_id == FLASH_UNKNOWN) | ||||||
| 				continue; | 				continue; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -91,7 +91,7 @@ addr2info(ulong addr) | |||||||
| 	flash_info_t *info; | 	flash_info_t *info; | ||||||
| 	int i; | 	int i; | ||||||
|  |  | ||||||
| 	for (i=0, info = &flash_info[0]; i<CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) { | 	for (i = 0, info = &flash_info[0]; i < CFI_FLASH_BANKS; ++i, ++info) { | ||||||
| 		if (info->flash_id != FLASH_UNKNOWN && | 		if (info->flash_id != FLASH_UNKNOWN && | ||||||
| 		    addr >= info->start[0] && | 		    addr >= info->start[0] && | ||||||
| 		    /* WARNING - The '- 1' is needed if the flash | 		    /* WARNING - The '- 1' is needed if the flash | ||||||
|   | |||||||
| @@ -112,12 +112,12 @@ static int update_flash_protect(int prot, ulong addr_first, ulong addr_last) | |||||||
|  |  | ||||||
| 	if (prot == 0) { | 	if (prot == 0) { | ||||||
| 		saved_prot_info = | 		saved_prot_info = | ||||||
| 			calloc(CONFIG_SYS_MAX_FLASH_BANKS * CONFIG_SYS_MAX_FLASH_SECT, 1); | 			calloc(CFI_FLASH_BANKS * CONFIG_SYS_MAX_FLASH_SECT, 1); | ||||||
| 		if (!saved_prot_info) | 		if (!saved_prot_info) | ||||||
| 			return 1; | 			return 1; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	for (bank = 0; bank < CONFIG_SYS_MAX_FLASH_BANKS; ++bank) { | 	for (bank = 0; bank < CFI_FLASH_BANKS; ++bank) { | ||||||
| 		cnt = 0; | 		cnt = 0; | ||||||
| 		info = &flash_info[bank]; | 		info = &flash_info[bank]; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -191,7 +191,7 @@ static flash_info_t *flash_get_info(ulong base) | |||||||
| 	int i; | 	int i; | ||||||
| 	flash_info_t *info; | 	flash_info_t *info; | ||||||
|  |  | ||||||
| 	for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++) { | 	for (i = 0; i < CFI_FLASH_BANKS; i++) { | ||||||
| 		info = &flash_info[i]; | 		info = &flash_info[i]; | ||||||
| 		if (info->size && info->start[0] <= base && | 		if (info->size && info->start[0] <= base && | ||||||
| 		    base <= info->start[0] + info->size - 1) | 		    base <= info->start[0] + info->size - 1) | ||||||
| @@ -2419,7 +2419,7 @@ unsigned long flash_init(void) | |||||||
| #endif | #endif | ||||||
|  |  | ||||||
| 	/* Init: no FLASHes known */ | 	/* Init: no FLASHes known */ | ||||||
| 	for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) { | 	for (i = 0; i < CFI_FLASH_BANKS; ++i) { | ||||||
| 		flash_info[i].flash_id = FLASH_UNKNOWN; | 		flash_info[i].flash_id = FLASH_UNKNOWN; | ||||||
|  |  | ||||||
| 		/* Optionally write flash configuration register */ | 		/* Optionally write flash configuration register */ | ||||||
|   | |||||||
| @@ -207,10 +207,10 @@ int cfi_mtd_init(void) | |||||||
| 	int error, i; | 	int error, i; | ||||||
| #ifdef CONFIG_MTD_CONCAT | #ifdef CONFIG_MTD_CONCAT | ||||||
| 	int devices_found = 0; | 	int devices_found = 0; | ||||||
| 	struct mtd_info *mtd_list[CONFIG_SYS_MAX_FLASH_BANKS]; | 	struct mtd_info *mtd_list[CFI_FLASH_BANKS]; | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| 	for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++) { | 	for (i = 0; i < CFI_FLASH_BANKS; i++) { | ||||||
| 		fi = &flash_info[i]; | 		fi = &flash_info[i]; | ||||||
| 		mtd = &cfi_mtd_info[i]; | 		mtd = &cfi_mtd_info[i]; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -3707,9 +3707,8 @@ int spi_nor_scan(struct spi_nor *nor) | |||||||
| 	int ret; | 	int ret; | ||||||
| 	int cfi_mtd_nb = 0; | 	int cfi_mtd_nb = 0; | ||||||
|  |  | ||||||
| #ifdef CONFIG_SYS_MAX_FLASH_BANKS | 	if (IS_ENABLED(CONFIG_FLASH_CFI_MTD)) | ||||||
| 	cfi_mtd_nb = CONFIG_SYS_MAX_FLASH_BANKS; | 		cfi_mtd_nb = CFI_FLASH_BANKS; | ||||||
| #endif |  | ||||||
|  |  | ||||||
| 	/* Reset SPI protocol for all commands. */ | 	/* Reset SPI protocol for all commands. */ | ||||||
| 	nor->reg_proto = SNOR_PROTO_1_1_1; | 	nor->reg_proto = SNOR_PROTO_1_1_1; | ||||||
|   | |||||||
| @@ -154,21 +154,24 @@ struct cfi_pri_hdr { | |||||||
| /* | /* | ||||||
|  * CFI_MAX_FLASH_BANKS only used for flash_info struct declaration. |  * CFI_MAX_FLASH_BANKS only used for flash_info struct declaration. | ||||||
|  * |  * | ||||||
|  * Use CONFIG_SYS_MAX_FLASH_BANKS_DETECT if defined |  * CFI_FLASH_BANKS selects the correct number of available banks = | ||||||
|  |  * cfi_flash_num_flash_banks when CONFIG_SYS_MAX_FLASH_BANKS_DETECT is defined | ||||||
|  |  * or CONFIG_SYS_MAX_FLASH_BANKS | ||||||
|  */ |  */ | ||||||
| #if defined(CONFIG_SYS_MAX_FLASH_BANKS_DETECT) | #if defined(CONFIG_SYS_MAX_FLASH_BANKS_DETECT) | ||||||
| #define CFI_MAX_FLASH_BANKS	CONFIG_SYS_MAX_FLASH_BANKS_DETECT | #define CFI_MAX_FLASH_BANKS	CONFIG_SYS_MAX_FLASH_BANKS_DETECT | ||||||
| /* map to cfi_flash_num_flash_banks only when supported */ | /* map to cfi_flash_num_flash_banks only when supported */ | ||||||
| #if IS_ENABLED(CONFIG_FLASH_CFI_DRIVER) && \ | #if IS_ENABLED(CONFIG_FLASH_CFI_DRIVER) && \ | ||||||
|     (!IS_ENABLED(CONFIG_SPL_BUILD) || IS_ENABLED(CONFIG_SPL_MTD_SUPPORT)) |     (!IS_ENABLED(CONFIG_SPL_BUILD) || IS_ENABLED(CONFIG_SPL_MTD_SUPPORT)) | ||||||
| #define CONFIG_SYS_MAX_FLASH_BANKS	(cfi_flash_num_flash_banks) | #define CFI_FLASH_BANKS		(cfi_flash_num_flash_banks) | ||||||
| /* board code can update this variable before CFI detection */ | /* board code can update this variable before CFI detection */ | ||||||
| extern int cfi_flash_num_flash_banks; | extern int cfi_flash_num_flash_banks; | ||||||
| #else | #else | ||||||
| #define CONFIG_SYS_MAX_FLASH_BANKS	CONFIG_SYS_MAX_FLASH_BANKS_DETECT | #define CFI_FLASH_BANKS		CONFIG_SYS_MAX_FLASH_BANKS_DETECT | ||||||
| #endif | #endif | ||||||
| #else | #else | ||||||
| #define CFI_MAX_FLASH_BANKS	CONFIG_SYS_MAX_FLASH_BANKS | #define CFI_MAX_FLASH_BANKS	CONFIG_SYS_MAX_FLASH_BANKS | ||||||
|  | #define CFI_FLASH_BANKS		CONFIG_SYS_MAX_FLASH_BANKS | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| phys_addr_t cfi_flash_bank_addr(int i); | phys_addr_t cfi_flash_bank_addr(int i); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user