mirror of
https://gitee.com/Vancouver2017/luban-lite-t3e-pro.git
synced 2025-12-16 19:38:56 +00:00
V1.0.5
This commit is contained in:
@@ -55,6 +55,10 @@ extern "C" {
|
||||
#define SFUD_INFO(...) sfud_log_info(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#ifndef SFUD_WP_INFO
|
||||
#define SFUD_WP_INFO(...) sfud_log_info(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
/* assert for developer. */
|
||||
#ifdef SFUD_DEBUG_MODE
|
||||
#define SFUD_ASSERT(EXPR) \
|
||||
@@ -190,6 +194,11 @@ extern void sfud_log_info(const char *format, ...);
|
||||
/* maximum number of erase type support on JESD216 (V1.0) */
|
||||
#define SFUD_SFDP_ERASE_TYPE_MAX_NUM 4
|
||||
|
||||
/* write protection state mask */
|
||||
#ifndef SFUD_WRITE_PROTECTION_MASK
|
||||
#define SFUD_WRITE_PROTECTION_MASK 0xFC
|
||||
#endif
|
||||
|
||||
/**
|
||||
* status register bits
|
||||
*/
|
||||
|
||||
@@ -75,6 +75,7 @@ static sfud_err read_jedec_id(sfud_flash *flash);
|
||||
sfud_err set_write_enabled(const sfud_flash *flash, bool enabled);
|
||||
static sfud_err set_4_byte_address_mode(sfud_flash *flash, bool enabled);
|
||||
static void make_adress_byte_array(const sfud_flash *flash, uint32_t addr, uint8_t *array);
|
||||
static sfud_err check_wp_mode(sfud_flash *flash);
|
||||
|
||||
/**
|
||||
* SFUD initialize by flash device
|
||||
@@ -401,6 +402,7 @@ static sfud_err hardware_init(sfud_flash *flash) {
|
||||
quad_enable_func qe = flash->quad_enable;
|
||||
qe(flash);
|
||||
#endif /* SFUD_USING_QSPI */
|
||||
check_wp_mode(flash);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1027,6 +1029,8 @@ sfud_err set_write_enabled(const sfud_flash *flash, bool enabled) {
|
||||
|
||||
if (result == SFUD_SUCCESS) {
|
||||
result = sfud_read_status(flash, ®ister_status);
|
||||
if (register_status & SFUD_WRITE_PROTECTION_MASK)
|
||||
SFUD_WP_INFO("Flash is in write protection state: 0x%x.\n", register_status);
|
||||
}
|
||||
|
||||
if (result == SFUD_SUCCESS) {
|
||||
@@ -1120,6 +1124,8 @@ static sfud_err wait_busy(const sfud_flash *flash) {
|
||||
if (result == SFUD_SUCCESS && ((status & SFUD_STATUS_REGISTER_BUSY)) == 0) {
|
||||
break;
|
||||
}
|
||||
if (status & SFUD_WRITE_PROTECTION_MASK)
|
||||
SFUD_WP_INFO("Flash is in write protection state: 0x%x.\n", status);
|
||||
/* retry counts */
|
||||
SFUD_RETRY_PROCESS(flash->retry.delay, retry_times, result);
|
||||
}
|
||||
@@ -1238,3 +1244,44 @@ sfud_err sfud_read_reg(const sfud_flash *flash, uint8_t reg, uint8_t *status) {
|
||||
|
||||
return flash->spi.wr(&flash->spi, &cmd, 1, status, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* ensure the flash is not in write protect state
|
||||
*
|
||||
* @note The value of status regester0 is 0 or the falsh may be in the state of write protection.
|
||||
*
|
||||
* @param flash flash device
|
||||
*
|
||||
* @return result
|
||||
*/
|
||||
static sfud_err check_wp_mode(sfud_flash *flash) {
|
||||
|
||||
sfud_err result = SFUD_SUCCESS;
|
||||
uint8_t reg = 0x5;
|
||||
uint8_t val = 0x0;
|
||||
|
||||
SFUD_ASSERT(flash);
|
||||
|
||||
result = sfud_read_reg(flash, reg, &val);
|
||||
if (result == SFUD_SUCCESS) {
|
||||
if (val & SFUD_WRITE_PROTECTION_MASK)
|
||||
SFUD_INFO("Flash is in write protection state: 0x%x.\n", val);
|
||||
} else {
|
||||
pr_warn("Read status register0 failed.\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
result = sfud_write_status(flash, true, 0x00);
|
||||
if (result != SFUD_SUCCESS) {
|
||||
pr_warn("Write status register0 failed.\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
result = sfud_read_reg(flash, reg, &val);
|
||||
if (result == SFUD_SUCCESS) {
|
||||
if (val & SFUD_WRITE_PROTECTION_MASK)
|
||||
SFUD_WP_INFO("Flash is in write protection state: 0x%x.\n", val);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -30,6 +30,8 @@ static int spi_nor_write_16bit_cr_and_check(sfud_flash *flash, uint8_t cr)
|
||||
ret = sfud_read_status(flash, sr_cr);
|
||||
if (ret)
|
||||
return ret;
|
||||
if (sr_cr[0] & SFUD_WRITE_PROTECTION_MASK)
|
||||
SFUD_WP_INFO("Flash is in write protection state: 0x%x.\n", sr_cr[0]);
|
||||
|
||||
sr_cr[1] = cr;
|
||||
|
||||
@@ -42,6 +44,8 @@ static int spi_nor_write_16bit_cr_and_check(sfud_flash *flash, uint8_t cr)
|
||||
ret = sfud_read_status(flash, sr_cr);
|
||||
if (ret)
|
||||
return ret;
|
||||
if (sr_cr[0] & SFUD_WRITE_PROTECTION_MASK)
|
||||
SFUD_WP_INFO("Flash is in write protection state: 0x%x.\n", sr_cr[0]);
|
||||
|
||||
/* Only check the writable bits */
|
||||
if (sr_written != (sr_cr[0] & SR1_RW_MSK)) {
|
||||
@@ -83,6 +87,8 @@ static int spi_nor_write_sr1_and_check(sfud_flash *flash, uint8_t sr1)
|
||||
ret = sfud_read_status(flash, &status);
|
||||
if (ret)
|
||||
return ret;
|
||||
if (status & SFUD_WRITE_PROTECTION_MASK)
|
||||
SFUD_WP_INFO("Flash is in write protection state: 0x%x.\n", status);
|
||||
|
||||
if (status!= sr1) {
|
||||
SFUD_INFO("SR1: read back test failed\n");
|
||||
|
||||
Reference in New Issue
Block a user