Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SFUD会添加Block Protect功能支持吗? #44

Open
dmsg opened this issue Oct 13, 2020 · 4 comments
Open

SFUD会添加Block Protect功能支持吗? #44

dmsg opened this issue Oct 13, 2020 · 4 comments

Comments

@dmsg
Copy link

dmsg commented Oct 13, 2020

SFUD是否有计划支持Flash的Block Protect功能?

@armink
Copy link
Owner

armink commented Oct 13, 2020

暂不支持的,这块处理不同芯片差异很大的

@lazyguoguo
Copy link

暂不支持的,这块处理不同芯片差异很大的

发现驱动SST26VF016B 这玩意默认开启Block Protect,调用写成功,但数据始终不对,一直查硬件问题,后来仔细看手册才发现这个问题。。。

@armink
Copy link
Owner

armink commented May 19, 2021

暂不支持的,这块处理不同芯片差异很大的

发现驱动SST26VF016B 这玩意默认开启Block Protect,调用写成功,但数据始终不对,一直查硬件问题,后来仔细看手册才发现这个问题。。。

是的,所以这类芯片 SFUD 里都有特殊处理

SFUD/sfud/src/sfud.c

Lines 351 to 362 in 4b41297

/* The flash all blocks is protected,so need change the flash status to unprotected before write and erase operate. */
if (flash->chip.write_mode & SFUD_WM_AAI) {
result = sfud_write_status(flash, true, 0x00);
} else {
/* MX25L3206E */
if ((0xC2 == flash->chip.mf_id) && (0x20 == flash->chip.type_id) && (0x16 == flash->chip.capacity_id)) {
result = sfud_write_status(flash, false, 0x00);
}
}
if (result != SFUD_SUCCESS) {
return result;
}

@lazyguoguo
Copy link

lazyguoguo commented May 19, 2021

根据手册直接增加解锁函数,加入初始化最后面。

image

static sfud_err set_ULBPR(const sfud_flash *flash){
    uint8_t cmd;
    sfud_err result = SFUD_SUCCESS;
    const sfud_spi *spi = &flash->spi;
    SFUD_ASSERT(flash);
    if (spi->lock) {
          spi->lock(spi);
      }
    result = set_write_enabled(flash, true);
       if (result != SFUD_SUCCESS) {
           goto __exit;
       }
    cmd = 0x98;
    result = flash->spi.wr(&flash->spi, &cmd, 1, NULL, 0);
__exit:
        /* set the flash write disable */
        set_write_enabled(flash, false);
        /* unlock SPI */
        if (spi->unlock) {
            spi->unlock(spi);
        }
    return result;
}

放在sfud_device_init最后面

sfud_err sfud_device_init(sfud_flash *flash) {
    sfud_err result = SFUD_SUCCESS;
    /* hardware initialize */
    result = hardware_init(flash);
    if (result == SFUD_SUCCESS) {
        result = software_init(flash);
    }
    if (result == SFUD_SUCCESS) {
        flash->init_ok = true;
        SFUD_INFO("%s flash device is initialize success.", flash->name);
    } else {
        flash->init_ok = false;
        SFUD_INFO("Error: %s flash device is initialize fail.", flash->name);
    }
    result = set_ULBPR(flash);    // 全局解锁block保护
    return result;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants