修改spif和uboot,加上写保护与解除保护

This commit is contained in:
2025-01-21 15:58:55 +08:00
parent a10ff1b209
commit 10e6767b22
10 changed files with 456 additions and 15 deletions

View File

@@ -3873,6 +3873,9 @@ static int spi_nor_setup(struct spi_nor *nor, const struct flash_info *info,
static int sunxi_lock_init(struct spi_nor *nor)
{
uint8_t mask = 0;
uint8_t status1 = 0;
uint8_t status2 = 0;
struct mtd_info *mtd = &nor->mtd;
const struct flash_info *info = nor->info;
@@ -3884,6 +3887,67 @@ static int sunxi_lock_init(struct spi_nor *nor)
if (sunxi_individual_lock_is_enable(nor))
sunxi_individual_unlock_global(nor);
if (JEDEC_MFR(nor->info) == SNOR_MFR_PUYA)
{
if (nor->info->id[2] == 0x19) // py25q256hb id:0x852019
{
status1 = (uint8_t)read_sr(nor);
/* check cmp first */
status2 = (uint8_t)read_sr2(nor);
// if ((status2 < 0) || (status1 < 0))
// {
// printf("read err!:%x %x\n", status1, status2);
// }
if (status2 & (SR2_CMP_GD)) // cmp=1
{
mask = (SR_BP2 | SR_BP3);
status1 |= mask;
printf("cmp=1\n");
}
else // cmp=0
{
printf("cmp=0\n");
mask = (uint8_t) ~(SR_BP0 | SR_BP1 | SR_BP2 | SR_BP3);
status1 &= mask;
}
if (write_sr_and_check(nor, status1, mask) != 0)
{
printf("py_unlock sr err!:%x\n", status1);
return -1;
}
return 0;
}
else if (nor->info->id[2] == 0x18) // py25q128ha id:0x852018
{
status1 = (uint8_t)read_sr(nor);
/* check cmp first */
status2 = (uint8_t)read_sr2(nor);
// if ((status2 < 0) || (status1 < 0))
// {
// printf("read err!:%x %x\n", status1, status2);
// }
if (status2 & (SR2_CMP_GD)) // cmp=1
{
mask = (SR_BP0 | SR_BP1 | SR_BP2);
status1 |= mask;
printf("cmp=1\n");
}
else // cmp=0
{
printf("cmp=0\n");
mask = (uint8_t) ~(SR_BP0 | SR_BP1 | SR_BP2);
status1 &= mask;
}
if (write_sr_and_check(nor, status1, mask) != 0)
{
printf("py_unlock sr err!:%x\n", status1);
return -1;
}
return 0;
}
}
if (JEDEC_MFR(info) == SNOR_MFR_ST ||
JEDEC_MFR(info) == SNOR_MFR_MICRON ||
JEDEC_MFR(info) == SNOR_MFR_SST)