cfi_flash: support of u32 cmd
PATCH v2 1/1 cfi_flash: support of u32 cmd
Some NOR flash chips have commands with length greater than the maximum value size of uchar.
Based on an U-Boot Patch by Vasiliy Leoenenko <[email protected]>
Only tested with little endian on an intel cfi_flash.
Signed-off-by Teresa Gámez <[email protected]>
--- drivers/nor/cfi_flash.c | 35 ++++++++++++++++++++++++++--------- drivers/nor/cfi_flash.h | 11 +++++++---- drivers/nor/cfi_flash_amd.c | 8 ++++---- drivers/nor/cfi_flash_intel.c | 2 +- 4 files changed, 38 insertions(+), 18 deletions(-)
drivers/nor/cfi_flash.c +26 -9
@@ -820,20 +820,35 @@ int flash_generic_status_check (struct flash_info *info, flash_sect_t sector,/* * make a proper sized command based on the port and chip widths */ -void flash_make_cmd (struct flash_info *info,u8 cmd,cfiword_t *cmdbuf) +void flash_make_cmd (struct flash_info *info,u32 cmd,cfiword_t *cmdbuf) { -cfiword_t result =0 ; -int i = info->portwidth / info->chipwidth; +int i; +int cp_offset; +int cword_offset; +uchar val; +uchar *cp; + + *cmdbuf =0 ; + cp = (uchar *)cmdbuf; -while (i--) - result = (result << (8 * info->chipwidth)) | cmd; - *cmdbuf = result; +for (i = info->portwidth; i >0 ; i--) { + cword_offset = (info->portwidth-i) % info->chipwidth; +#if __BYTE_ORDER == __LITTLE_ENDIAN + cp_offset = info->portwidth - i; + val = *((uchar *)&cmd + cword_offset); +#else + cp_offset = i -1 ; + val = *((uchar *)&cmd +sizeof (u32) - cword_offset -1 ); +#endif + cp[cp_offset] = (cword_offset >=sizeof (u32)) ?0x00 : val; + } }/* * Write a proper sized command to the correct address */ -void flash_write_cmd (struct flash_info *info,flash_sect_t sect,uint offset,uchar cmd) +void flash_write_cmd (struct flash_info *info,flash_sect_t sect, +uint offset,u32 cmd) {uchar *addr;
@@ -845,7 +860,8 @@ void flash_write_cmd (struct flash_info *info, flash_sect_t sect, uint offset, uflash_write_word (info, cword, addr); } -int flash_isequal (struct flash_info *info,flash_sect_t sect,uint offset,uchar cmd) +int flash_isequal (struct flash_info *info,flash_sect_t sect, +uint offset,u32 cmd) {void *addr;cfiword_t cword;
@@ -882,7 +898,8 @@ int flash_isequal (struct flash_info *info, flash_sect_t sect, uint offset, uchareturn retval; } -int flash_isset (struct flash_info *info,flash_sect_t sect,uint offset,uchar cmd) +int flash_isset (struct flash_info *info,flash_sect_t sect, +uint offset,u32 cmd) {void *addr =flash_make_addr (info, sect, offset);cfiword_t cword;
drivers/nor/cfi_flash.h +7 -4
@@ -231,16 +231,19 @@ extern struct cfi_cmd_set cfi_cmd_set_amd;#define CFI_FLASH_SHIFT_WIDTH 3/* Prototypes */ -int flash_isset (struct flash_info *info,flash_sect_t sect,uint offset,uchar cmd); -void flash_write_cmd (struct flash_info *info,flash_sect_t sect,uint offset,uchar cmd); +int flash_isset (struct flash_info *info,flash_sect_t sect, +uint offset,u32 cmd); +void flash_write_cmd (struct flash_info *info,flash_sect_t sect, +uint offset,u32 cmd);flash_sect_t find_sector (struct flash_info *info,ulong addr);int flash_status_check (struct flash_info *info,flash_sect_t sector,uint64_t tout,char *prompt);int flash_generic_status_check (struct flash_info *info,flash_sect_t sector,uint64_t tout,char *prompt); -int flash_isequal (struct flash_info *info,flash_sect_t sect,uint offset,uchar cmd); -void flash_make_cmd (struct flash_info *info,uchar cmd,cfiword_t *cmdbuf); +int flash_isequal (struct flash_info *info,flash_sect_t sect, +uint offset,u32 cmd); +void flash_make_cmd (struct flash_info *info,u32 cmd,cfiword_t *cmdbuf);static inline void flash_write8 (u8 value,void *addr) {
drivers/nor/cfi_flash_amd.c +4 -4
@@ -142,28 +142,28 @@ static int amd_flash_write_cfibuffer (struct flash_info *info, ulong dest, constif (bankwidth_is_1 (info)) { cnt = len; -flash_write_cmd (info, sector,0 , (uchar ) cnt -1 ); +flash_write_cmd (info, sector,0 , (u32 )cnt -1 );while (cnt-- >0 ) {flash_write8 (flash_read8 (src), dst); src +=1 , dst +=1 ; } }else if (bankwidth_is_2 (info)) { cnt = len >>1 ; -flash_write_cmd (info, sector,0 , (uchar ) cnt -1 ); +flash_write_cmd (info, sector,0 , (u32 )cnt -1 );while (cnt-- >0 ) {flash_write16 (flash_read16 (src), dst); src +=2 , dst +=2 ; } }else if (bankwidth_is_4 (info)) { cnt = len >>2 ; -flash_write_cmd (info, sector,0 , (uchar ) cnt -1 ); +flash_write_cmd (info, sector,0 , (u32 )cnt -1 );while (cnt-- >0 ) {flash_write32 (flash_read32 (src), dst); src +=4 , dst +=4 ; } }else if (bankwidth_is_8 (info)) { cnt = len >>3 ; -flash_write_cmd (info, sector,0 , (uchar ) cnt -1 ); +flash_write_cmd (info, sector,0 , (u32 )cnt -1 );while (cnt-- >0 ) {flash_write64 (flash_read64 (src), dst); src +=8 , dst +=8 ;
drivers/nor/cfi_flash_intel.c +1 -1
@@ -70,7 +70,7 @@ static int intel_flash_write_cfibuffer (struct flash_info *info, ulong dest, con/* reduce the number of loops by the width of the port */ cnt = len >> (info->portwidth -1 ); -flash_write_cmd (info, sector,0 , (uchar ) cnt -1 ); +flash_write_cmd (info, sector,0 , (u32 )cnt -1 );while (cnt-- >0 ) {if (bankwidth_is_1 (info)) {flash_write8 (flash_read8 (src), dst);
Signature · 7 lines
1.7.0.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
AppliedQuoted 8 lines · Teresa Gámez
Some NOR flash chips have commands with length greater than the maximum value size of uchar.
Based on an U-Boot Patch by Vasiliy Leoenenko <[email protected]>
Only tested with little endian on an intel
cfi_flash.Signed-off-by Teresa Gámez <[email protected]>
Applied to next.
Sascha
Quoted 156 lines
--- drivers/nor/cfi_flash.c | 35 ++++++++++++++++++++++++++--------- drivers/nor/cfi_flash.h | 11 +++++++---- drivers/nor/cfi_flash_amd.c | 8 ++++---- drivers/nor/cfi_flash_intel.c | 2 +- 4 files changed, 38 insertions(+), 18 deletions(-)drivers/nor/cfi_flash.c +26
-9@@ -820,20 +820,35 @@ int flash_generic_status_check (struct flash_info *info, flash_sect_t sector,/* * make a proper sized command based on the port and chip widths */ -void flash_make_cmd (struct flash_info *info,u8 cmd,cfiword_t *cmdbuf) +void flash_make_cmd (struct flash_info *info,u32 cmd,cfiword_t *cmdbuf) { -cfiword_t result =0 ; -int i = info->portwidth / info->chipwidth; +int i; +int cp_offset; +int cword_offset; +uchar val; +uchar *cp; + + *cmdbuf =0 ; + cp = (uchar *)cmdbuf; -while (i--) - result = (result << (8 * info->chipwidth)) | cmd; - *cmdbuf = result; +for (i = info->portwidth; i >0 ; i--) { + cword_offset = (info->portwidth-i) % info->chipwidth; +#if __BYTE_ORDER == __LITTLE_ENDIAN + cp_offset = info->portwidth - i; + val = *((uchar *)&cmd + cword_offset); +#else + cp_offset = i -1 ; + val = *((uchar *)&cmd +sizeof (u32) - cword_offset -1 ); +#endif + cp[cp_offset] = (cword_offset >=sizeof (u32)) ?0x00 : val; + } }/* * Write a proper sized command to the correct address */ -void flash_write_cmd (struct flash_info *info,flash_sect_t sect,uint offset,uchar cmd) +void flash_write_cmd (struct flash_info *info,flash_sect_t sect, +uint offset,u32 cmd) {uchar *addr;@@ -845,7 +860,8 @@ void flash_write_cmd (struct flash_info *info, flash_sect_t sect, uint offset, uflash_write_word (info, cword, addr); } -int flash_isequal (struct flash_info *info,flash_sect_t sect,uint offset,uchar cmd) +int flash_isequal (struct flash_info *info,flash_sect_t sect, +uint offset,u32 cmd) {void *addr;cfiword_t cword;@@ -882,7 +898,8 @@ int flash_isequal (struct flash_info *info, flash_sect_t sect, uint offset, uchareturn retval; } -int flash_isset (struct flash_info *info,flash_sect_t sect,uint offset,uchar cmd) +int flash_isset (struct flash_info *info,flash_sect_t sect, +uint offset,u32 cmd) {void *addr =flash_make_addr (info, sect, offset);cfiword_t cword;drivers/nor/cfi_flash.h +7
-4@@ -231,16 +231,19 @@ extern struct cfi_cmd_set cfi_cmd_set_amd;#define CFI_FLASH_SHIFT_WIDTH 3/* Prototypes */ -int flash_isset (struct flash_info *info,flash_sect_t sect,uint offset,uchar cmd); -void flash_write_cmd (struct flash_info *info,flash_sect_t sect,uint offset,uchar cmd); +int flash_isset (struct flash_info *info,flash_sect_t sect, +uint offset,u32 cmd); +void flash_write_cmd (struct flash_info *info,flash_sect_t sect, +uint offset,u32 cmd);flash_sect_t find_sector (struct flash_info *info,ulong addr);int flash_status_check (struct flash_info *info,flash_sect_t sector,uint64_t tout,char *prompt);int flash_generic_status_check (struct flash_info *info,flash_sect_t sector,uint64_t tout,char *prompt); -int flash_isequal (struct flash_info *info,flash_sect_t sect,uint offset,uchar cmd); -void flash_make_cmd (struct flash_info *info,uchar cmd,cfiword_t *cmdbuf); +int flash_isequal (struct flash_info *info,flash_sect_t sect, +uint offset,u32 cmd); +void flash_make_cmd (struct flash_info *info,u32 cmd,cfiword_t *cmdbuf);static inline void flash_write8 (u8 value,void *addr) {drivers/nor/cfi_flash_amd.c +4
-4@@ -142,28 +142,28 @@ static int amd_flash_write_cfibuffer (struct flash_info *info, ulong dest, constif (bankwidth_is_1 (info)) { cnt = len; -flash_write_cmd (info, sector,0 , (uchar ) cnt -1 ); +flash_write_cmd (info, sector,0 , (u32 )cnt -1 );while (cnt-- >0 ) {flash_write8 (flash_read8 (src), dst); src +=1 , dst +=1 ; } }else if (bankwidth_is_2 (info)) { cnt = len >>1 ; -flash_write_cmd (info, sector,0 , (uchar ) cnt -1 ); +flash_write_cmd (info, sector,0 , (u32 )cnt -1 );while (cnt-- >0 ) {flash_write16 (flash_read16 (src), dst); src +=2 , dst +=2 ; } }else if (bankwidth_is_4 (info)) { cnt = len >>2 ; -flash_write_cmd (info, sector,0 , (uchar ) cnt -1 ); +flash_write_cmd (info, sector,0 , (u32 )cnt -1 );while (cnt-- >0 ) {flash_write32 (flash_read32 (src), dst); src +=4 , dst +=4 ; } }else if (bankwidth_is_8 (info)) { cnt = len >>3 ; -flash_write_cmd (info, sector,0 , (uchar ) cnt -1 ); +flash_write_cmd (info, sector,0 , (u32 )cnt -1 );while (cnt-- >0 ) {flash_write64 (flash_read64 (src), dst); src +=8 , dst +=8 ;drivers/nor/cfi_flash_intel.c +1
-1@@ -70,7 +70,7 @@ static int intel_flash_write_cfibuffer (struct flash_info *info, ulong dest, con/* reduce the number of loops by the width of the port */ cnt = len >> (info->portwidth -1 ); -flash_write_cmd (info, sector,0 , (uchar ) cnt -1 ); +flash_write_cmd (info, sector,0 , (u32 )cnt -1 );while (cnt-- >0 ) {if (bankwidth_is_1 (info)) {flash_write8 (flash_read8 (src), dst);Signature · 1 line
1.7.0.4
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox