Finally, easy to prevent erase or overwrite protected partition
platform/msm_shared/nand.c
Code:
int flash_erase(struct ptentry *ptn)
{
unsigned block = ptn->start;
unsigned count = ptn->length;
if (ptn->perm == PERM_NON_WRITEABLE) {
dprintf(INFO, "%s partition is protected, can't be erased.\n", ptn->name);
return -1;
}
set_nand_configuration(ptn->type);
while(count-- > 0) {
if(flash_erase_block(flash_cmdlist, flash_ptrlist, block * 64)) {
dprintf(INFO, "cannot erase @ %d (bad block?)\n", block);
}
block++;
}
return 0;
}
int flash_write(struct ptentry *ptn, unsigned extra_per_page, const void *data,
unsigned bytes)
{
unsigned page = ptn->start * 64;
unsigned lastpage = (ptn->start + ptn->length) * 64;
unsigned *spare = (unsigned*) flash_spare;
const unsigned char *image = data;
unsigned wsize = flash_pagesize + extra_per_page;
unsigned n;
int r;
if (ptn->type == TYPE_MODEM_PARTITION)
{
dprintf(CRITICAL, "flash_write_image: model partition not supported\n");
return -1;
}
if (ptn->perm == PERM_NON_WRITEABLE) {
dprintf(INFO, "%s partition is protected, can't be overwrited.\n", ptn->name);
return -1;
}
Tested pass:
Quote:
E:\adb-tool>Fastboot flash TPCAL x:\cal.raw
sending 'TPCAL' (128 KB)... OKAY [ 0.110s]
writing 'TPCAL'... FAILED (remote: flash write failure)
finished. total time: 0.345s
E:\adb-tool>Fastboot erase TPCAL
erasing 'TPCAL'... FAILED (remote: failed to erase partition)
finished. total time: 0.692s
|