cfi_flash: Add manufact_match helper function
PATCH 1/4 cfi_flash: Add manufact_match helper function
Consolidate manufacturer matching into the function manufact_match() and use it.
--- drivers/mtd/cfi_flash.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/mtd/cfi_flash.c +9 -7
@@ -1425,13 +1425,18 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)return flash_write_cfiword (info, wp, cword); } +static inline int manufact_match (flash_info_t *info,u32 manu) +{ +return info->manufacturer_id == ((manu &FLASH_VENDMASK ) >>16 ); +} +/*----------------------------------------------------------------------- */ #ifdef CONFIG_SYS_FLASH_PROTECTION static int cfi_protect_bugfix (flash_info_t *info,long sector,int prot) { -if (info->manufacturer_id == ((INTEL_MANUFACT &FLASH_VENDMASK ) >>16 ) +if (manufact_match (info,INTEL_MANUFACT ) && info->device_id ==NUMONYX_256MBIT ) {/* * see errata called
@@ -1488,8 +1493,7 @@ int flash_real_protect (flash_info_t * info, long sector, int prot)case CFI_CMDSET_AMD_EXTENDED :case CFI_CMDSET_AMD_STANDARD :/* U-Boot only checks the first byte */ -if (info->manufacturer_id == - ((ATM_MANUFACT &FLASH_VENDMASK ) >>16 )) { +if (manufact_match (info,ATM_MANUFACT )) {if (prot) {flash_unlock_seq (info,0 ); flash_write_cmd (info, 0,
@@ -1507,8 +1511,7 @@ int flash_real_protect (flash_info_t * info, long sector, int prot) 0, ATM_CMD_UNLOCK_SECT); } } -if (info->manufacturer_id == - ((AMD_MANUFACT &FLASH_VENDMASK ) >>16 )) { +if (manufact_match (info,AMD_MANUFACT )) {int flag =disable_interrupts ();int lock_flag;
@@ -1738,8 +1741,7 @@ static int cmdset_amd_init(flash_info_t *info, struct cfi_qry *qry)flash_write_cmd (info,0 , info->cfi_offset,FLASH_CMD_CFI );#ifdef CONFIG_SYS_FLASH_PROTECTION -if (info->ext_addr && info->manufacturer_id == - ((AMD_MANUFACT &FLASH_VENDMASK ) >>16 )) { +if (info->ext_addr &&manufact_match (info,AMD_MANUFACT )) {ushort spus;/* read sector protect/unprotect scheme */
Signature · 1 line
1.8.0.1
PATCH v2 2/4 cfi_flash: Read PPB sector protection from device for AMD/Spansion chips
Patch 66863b05 [cfi_flash: add support for Spansion flash PPB sector protection] introduced the PPB (Persistent Protection Bit) locking for Spansion chips. But right now the sector protection status (locked vs unlocked) is set to unlocked for all sectors upon bootup. The real sector protection status is ignored.
This patch now reads the current sector protection status and uses it for these AMD/Spansion flash chips.
---
v2:
- Added reset command before issuing the autoselect command (FLASH_CMD_READ_ID). Otherwise STM flash chips didn't report the correct protection status (on a4m2k board)
- Line length reduced (checkpatch warning)
drivers/mtd/cfi_flash.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/mtd/cfi_flash.c +21 -0
@@ -2160,6 +2160,27 @@ ulong flash_get_size (phys_addr_t base, int banknum)FLASH_OFFSET_PROTECT , FLASH_STATUS_PROTECT);break ; +case CFI_CMDSET_AMD_EXTENDED : +case CFI_CMDSET_AMD_STANDARD : +if (!manufact_match (info,AMD_MANUFACT )) { +/* default: not protected */ + info->protect[sect_cnt] =0 ; +break ; + } + +/* Read protection (PPB) from sector */ +flash_write_cmd (info,0 ,0 , + info->cmd_reset); +flash_unlock_seq (info,0 ); +flash_write_cmd (info,0 , + info->addr_unlock1, +FLASH_CMD_READ_ID ); + info->protect[sect_cnt] = +flash_isset ( + info, sect_cnt, +FLASH_OFFSET_PROTECT , +FLASH_STATUS_PROTECT ); +break ;default :/* default: not protected */ info->protect[sect_cnt] =0 ;
Signature · 1 line
1.8.0.1
PATCH v2 2/4 cfi_flash: Read PPB sector protection from device for AMD/Spansion chips
Hi Stefan,
Quoted 6 lines · Stefan Roese
Patch
66863b05[cfi_flash: add support for Spansion flash PPB sector protection] introduced the PPB (Persistent Protection Bit) locking for Spansion chips. But right now the sector protection status (locked vs unlocked) is set to unlocked for all sectors upon bootup. The real sector protection status is ignored.
Quoted 7 lines
This patch now reads the current sector protection status and uses it for these AMD/Spansion flash chips.
Signed-off-by Stefan Roese <[email protected]>Cc Anatolij Gustschin <[email protected]>Cc Holger Brunck <[email protected]>---
Regards
Holger
PATCH 3/4 cfi_flash: Enable PPB protection for all AMD cmdset flash chips
In reply to Stefan RoeseNot only Spansion supports the Persistent Protection Bits (PPB) locking. Other devices like the Micron JS28F512M29EWx also support this type of locking/unlocking. Detection of support is done in the same way as done for the Spansion chips - via the 0x49 CFI word.
This patch enables this PPB protection mechanism for all AMD type (AMD commandset) chips.
--- drivers/mtd/cfi_flash.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/mtd/cfi_flash.c +5 -8
@@ -1511,7 +1511,7 @@ int flash_real_protect (flash_info_t * info, long sector, int prot) 0, ATM_CMD_UNLOCK_SECT); } } -if (manufact_match (info,AMD_MANUFACT )) { +if (info->legacy_unlock) {int flag =disable_interrupts ();int lock_flag;
@@ -1741,12 +1741,9 @@ static int cmdset_amd_init(flash_info_t *info, struct cfi_qry *qry)flash_write_cmd (info,0 , info->cfi_offset,FLASH_CMD_CFI );#ifdef CONFIG_SYS_FLASH_PROTECTION -if (info->ext_addr &&manufact_match (info,AMD_MANUFACT )) { -ushort spus; - -/* read sector protect/unprotect scheme */ - spus =flash_read_uchar (info, info->ext_addr +9 ); -if (spus ==0x8 ) +if (info->ext_addr) { +/* read sector protect/unprotect scheme (at 0x49) */ +if (flash_read_uchar (info, info->ext_addr +9 ) ==0x8 ) info->legacy_unlock =1 ; }#endif
@@ -2162,7 +2159,7 @@ ulong flash_get_size (phys_addr_t base, int banknum)break ;case CFI_CMDSET_AMD_EXTENDED :case CFI_CMDSET_AMD_STANDARD : -if (!manufact_match (info,AMD_MANUFACT )) { +if (!info->legacy_unlock) {/* default: not protected */ info->protect[sect_cnt] =0 ;break ;
Signature · 1 line
1.8.0.1
PATCH 3/4 cfi_flash: Enable PPB protection for all AMD cmdset flash chips
Hi Stefan,
Quoted 8 lines · Stefan Roese
Not only Spansion supports the Persistent Protection Bits (PPB) locking. Other devices like the Micron JS28F512M29EWx also support this type of locking/unlocking. Detection of support is done in the same way as done for the Spansion chips - via the
0x49CFI word.This patch enables this PPB protection mechanism for all AMD type (AMD commandset) chips.
Quoted 7 lines
Signed-off-by Stefan Roese <[email protected]>Cc Anatolij Gustschin <[email protected]>Cc Holger Brunck <[email protected]>--- drivers/mtd/cfi_flash.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
Regards
Holger
PATCH 4/4 cfi_flash: Report Advanced Sector Protection (PPB) with flinfo cmd
In reply to Stefan RoeseReport the usage of the Advanced Sector Protection (PPB) to the user upon 'flinfo' command. E.g:
Bank # 1: CFI conformant flash (16 x 16) Size: 64 MB in 512 Sectors
AMD Standard command set, Manufacturer ID: 0x01, Device ID: 0x227E2301 Advanced Sector Protection (PPB) enabled
Erase timeout: 16384 ms, write timeout: 2 ms
Buffer write timeout: 5 ms, buffer size: 32 bytes
Sector Start Addresses:
FC000000 E FC020000 E RO FC040000 E FC060000 E FC080000 E
...
--- drivers/mtd/cfi_flash.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/mtd/cfi_flash.c +2 -0
@@ -1247,6 +1247,8 @@ void flash_print_info (flash_info_t * info)printf (info->chipwidth ==FLASH_CFI_16BIT ?"%04X" :"%02X" , info->device_id2); } +if ((info->vendor ==CFI_CMDSET_AMD_STANDARD ) && (info->legacy_unlock)) +printf ("\n Advanced Sector Protection (PPB) enabled" );printf ("\n Erase timeout: %ld ms, write timeout: %ld ms\n" , info->erase_blk_tout, info->write_tout);
Signature · 1 line
1.8.0.1
PATCH 4/4 cfi_flash: Report Advanced Sector Protection (PPB) with flinfo cmd
Hi Stefan,
Quoted 13 lines · Stefan Roese
Report the usage of the Advanced Sector Protection (PPB) to the user upon 'flinfo' command. E.g:
Bank # 1: CFI conformant flash (16 x 16) Size: 64 MB in 512 Sectors
AMD Standard command set, Manufacturer ID:0x01, Device ID:0x227E2301Advanced Sector Protection (PPB) enabled
Erase timeout: 16384 ms, write timeout: 2 ms
Buffer write timeout: 5 ms, buffer size: 32 bytesSector Start Addresses:
FC000000 E FC020000 E RO FC040000 E FC060000 E FC080000 E
...
Quoted 7 lines
Signed-off-by Stefan Roese <[email protected]>Cc Anatolij Gustschin <[email protected]>Cc Holger Brunck <[email protected]>--- drivers/mtd/cfi_flash.c | 2 ++ 1 file changed, 2 insertions(+)
Regards
Holger
PATCH 1/4 cfi_flash: Add manufact_match helper function
In reply to Stefan RoeseQuoted 2 lines · Stefan Roese
Consolidate manufacturer matching into the function
manufact_match()and use it.
For all patches of this series (1...4):
Applied to u-boot-cfi-flash/master.
Thanks,
Stefan