We have a generic unlocking infrastructure, but all SPI chips ignored it. Fix it. Actually check if the unlock worked instead of just assuming it worked.
This depends on [PATCH] Convert SPI chips to partial write.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
diff -ur flashrom-partial_write_spi_intermediate/bitbang_spi.c flashrom-spi_unlock_refactor/bitbang_spi.c --- flashrom-partial_write_spi_intermediate/bitbang_spi.c 2010-07-09 19:11:10.000000000 +0200 +++ flashrom-spi_unlock_refactor/bitbang_spi.c 2010-07-10 02:55:40.000000000 +0200 @@ -141,6 +141,5 @@
int bitbang_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len) { - spi_disable_blockprotect(); return spi_write_chunked(flash, buf, start, len, 256); } diff -ur flashrom-partial_write_spi_intermediate/buspirate_spi.c flashrom-spi_unlock_refactor/buspirate_spi.c --- flashrom-partial_write_spi_intermediate/buspirate_spi.c 2010-07-08 12:15:05.000000000 +0200 +++ flashrom-spi_unlock_refactor/buspirate_spi.c 2010-07-10 02:53:48.000000000 +0200 @@ -311,6 +311,5 @@
int buspirate_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len) { - spi_disable_blockprotect(); return spi_write_chunked(flash, buf, start, len, 12); } diff -ur flashrom-partial_write_spi_intermediate/chipdrivers.h flashrom-spi_unlock_refactor/chipdrivers.h --- flashrom-partial_write_spi_intermediate/chipdrivers.h 2010-07-09 19:04:47.000000000 +0200 +++ flashrom-spi_unlock_refactor/chipdrivers.h 2010-07-10 02:53:42.000000000 +0200 @@ -47,7 +47,7 @@ int spi_chip_write_256_new(struct flashchip *flash, uint8_t *buf, int start, int len); int spi_chip_read(struct flashchip *flash, uint8_t *buf, int start, int len); uint8_t spi_read_status_register(void); -int spi_disable_blockprotect(void); +int spi_disable_blockprotect(struct flashchip *flash); int spi_byte_program(int addr, uint8_t databyte); int spi_nbyte_program(int addr, uint8_t *bytes, int len); int spi_nbyte_read(int addr, uint8_t *bytes, int len); diff -ur flashrom-partial_write_spi_intermediate/flashchips.c flashrom-spi_unlock_refactor/flashchips.c --- flashrom-partial_write_spi_intermediate/flashchips.c 2010-07-09 19:05:21.000000000 +0200 +++ flashrom-spi_unlock_refactor/flashchips.c 2010-07-10 02:52:48.000000000 +0200 @@ -335,6 +335,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -369,6 +370,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -403,6 +405,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -437,6 +440,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -471,6 +475,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -505,6 +510,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -539,6 +545,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -573,6 +580,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -607,6 +615,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -641,6 +650,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -697,6 +707,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -731,6 +742,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -765,6 +777,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -781,6 +794,7 @@ .tested = TEST_UNTESTED, .probe = probe_spi_rdid, .probe_timing = TIMING_ZERO, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, },*/ @@ -1184,6 +1198,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1215,6 +1230,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1392,6 +1408,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_1, .read = read_memmapped, }, @@ -1422,6 +1439,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1452,6 +1470,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1482,6 +1501,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1512,6 +1532,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1543,6 +1564,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1574,6 +1596,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1605,6 +1628,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1636,6 +1660,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1667,6 +1692,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1698,6 +1724,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1729,6 +1756,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1760,6 +1788,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1791,6 +1820,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1822,6 +1852,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1853,6 +1884,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1884,6 +1916,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1918,6 +1951,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1952,6 +1986,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1986,6 +2021,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2020,6 +2056,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2051,6 +2088,7 @@ .block_erase = spi_block_erase_c7, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2082,6 +2120,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2113,6 +2152,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2144,6 +2184,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2687,6 +2728,7 @@ .block_erase = spi_block_erase_c7, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2718,6 +2760,7 @@ .block_erase = spi_block_erase_c7, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2752,6 +2795,7 @@ .block_erase = spi_block_erase_c7, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2786,6 +2830,7 @@ .block_erase = spi_block_erase_c7, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2820,6 +2865,7 @@ .block_erase = spi_block_erase_c7, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2854,6 +2900,7 @@ .block_erase = spi_block_erase_c7, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2885,6 +2932,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2916,6 +2964,7 @@ .block_erase = spi_block_erase_c7, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2947,6 +2996,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2978,6 +3028,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3009,6 +3060,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3189,6 +3241,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3217,6 +3270,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3245,6 +3299,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3273,6 +3328,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3301,6 +3357,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3329,6 +3386,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3363,6 +3421,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3391,6 +3450,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3419,6 +3479,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3453,6 +3514,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3481,6 +3543,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3715,6 +3778,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3772,6 +3836,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3797,6 +3862,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3831,6 +3897,7 @@ .block_erase = spi_block_erase_c7, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_1, .read = spi_chip_read, }, @@ -3865,6 +3932,7 @@ .block_erase = spi_block_erase_c7, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_1, .read = spi_chip_read, }, @@ -3893,6 +3961,7 @@ .block_erase = spi_block_erase_60, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_1, .read = spi_chip_read, }, @@ -3927,6 +3996,7 @@ .block_erase = spi_block_erase_c7, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_1, .read = spi_chip_read, }, @@ -3955,6 +4025,7 @@ .block_erase = spi_block_erase_60, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_1, .read = spi_chip_read, }, @@ -3989,6 +4060,7 @@ .block_erase = spi_block_erase_c7, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_1, .read = spi_chip_read, }, @@ -4023,6 +4095,7 @@ .block_erase = spi_block_erase_c7, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_1, .read = spi_chip_read, }, @@ -4803,6 +4876,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -4833,6 +4907,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_1, /* 128 */ .read = spi_chip_read, }, @@ -4858,6 +4933,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -4884,6 +4960,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_1, /* 128 */ .read = spi_chip_read, }, @@ -4909,6 +4986,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -4934,6 +5012,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -4959,6 +5038,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -4984,6 +5064,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -5009,6 +5090,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -5034,6 +5116,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -5059,6 +5142,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -5084,6 +5168,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -5765,6 +5850,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -5799,6 +5885,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -5833,6 +5920,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -5867,6 +5955,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -5895,6 +5984,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -5923,6 +6013,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -5951,6 +6042,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -5979,6 +6071,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -6013,6 +6106,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -6047,6 +6141,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -6081,6 +6176,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, diff -ur flashrom-partial_write_spi_intermediate/ft2232_spi.c flashrom-spi_unlock_refactor/ft2232_spi.c --- flashrom-partial_write_spi_intermediate/ft2232_spi.c 2010-07-08 12:15:05.000000000 +0200 +++ flashrom-spi_unlock_refactor/ft2232_spi.c 2010-07-10 02:55:44.000000000 +0200 @@ -290,7 +290,6 @@
int ft2232_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len) { - spi_disable_blockprotect(); return spi_write_chunked(flash, buf, start, len, 256); }
diff -ur flashrom-partial_write_spi_intermediate/ichspi.c flashrom-spi_unlock_refactor/ichspi.c --- flashrom-partial_write_spi_intermediate/ichspi.c 2010-07-09 19:12:42.000000000 +0200 +++ flashrom-spi_unlock_refactor/ichspi.c 2010-07-10 02:53:55.000000000 +0200 @@ -690,7 +690,6 @@ if (spi_controller == SPI_CONTROLLER_VIA) maxdata = 16;
- spi_disable_blockprotect(); return spi_write_chunked(flash, buf, start, len, maxdata); }
diff -ur flashrom-partial_write_spi_intermediate/it87spi.c flashrom-spi_unlock_refactor/it87spi.c --- flashrom-partial_write_spi_intermediate/it87spi.c 2010-07-09 23:28:52.000000000 +0200 +++ flashrom-spi_unlock_refactor/it87spi.c 2010-07-10 02:55:48.000000000 +0200 @@ -355,7 +355,6 @@ spi_chip_write_1_new(flash, buf, start, len); } else { int writehere; - spi_disable_blockprotect();
if (start % 256) { /* start to the end of the page or start + len, diff -ur flashrom-partial_write_spi_intermediate/sb600spi.c flashrom-spi_unlock_refactor/sb600spi.c --- flashrom-partial_write_spi_intermediate/sb600spi.c 2010-05-31 00:36:09.000000000 +0200 +++ flashrom-spi_unlock_refactor/sb600spi.c 2010-07-10 02:53:50.000000000 +0200 @@ -50,7 +50,6 @@
int sb600_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len) { - spi_disable_blockprotect(); return spi_write_chunked(flash, buf, start, len, 5); }
diff -ur flashrom-partial_write_spi_intermediate/spi25.c flashrom-spi_unlock_refactor/spi25.c --- flashrom-partial_write_spi_intermediate/spi25.c 2010-07-09 23:40:22.000000000 +0200 +++ flashrom-spi_unlock_refactor/spi25.c 2010-07-10 02:56:49.000000000 +0200 @@ -436,12 +436,6 @@ .readarr = NULL, }}; - result = spi_disable_blockprotect(); - if (result) { - msg_cerr("spi_disable_blockprotect failed\n"); - return result; - } - result = spi_send_multicommand(cmds); if (result) { msg_cerr("%s failed during command execution\n", @@ -482,12 +476,6 @@ .readarr = NULL, }};
- result = spi_disable_blockprotect(); - if (result) { - msg_cerr("spi_disable_blockprotect failed\n"); - return result; - } - result = spi_send_multicommand(cmds); if (result) { msg_cerr("%s failed during command execution\n", __func__); @@ -841,7 +829,7 @@ return result; }
-int spi_disable_blockprotect(void) +int spi_disable_blockprotect(struct flashchip *flash) { uint8_t status; int result; @@ -855,6 +843,11 @@ msg_cerr("spi_write_status_register failed\n"); return result; } + status = spi_read_status_register(); + if ((status & 0x3c) != 0) { + msg_cerr("Block protection could not be disabled!\n"); + /* Should we error out here? */ + } } return 0; } @@ -970,7 +963,6 @@ { int i, result = 0;
- spi_disable_blockprotect(); for (i = start; i < start + len; i++) { result = spi_byte_program(i, buf[i]); if (result) @@ -984,7 +976,6 @@
int spi_chip_write_1(struct flashchip *flash, uint8_t *buf) { - spi_disable_blockprotect(); /* Erase first */ msg_cinfo("Erasing flash before programming... "); if (erase_flash(flash)) { diff -ur flashrom-partial_write_spi_intermediate/spi.c flashrom-spi_unlock_refactor/spi.c --- flashrom-partial_write_spi_intermediate/spi.c 2010-07-09 19:16:09.000000000 +0200 +++ flashrom-spi_unlock_refactor/spi.c 2010-07-10 02:54:07.000000000 +0200 @@ -215,7 +215,6 @@ { int ret;
- spi_disable_blockprotect(); msg_pinfo("Erasing flash before programming... "); if (erase_flash(flash)) { msg_perr("ERASE FAILED!\n");
Am Samstag, den 10.07.2010, 03:05 +0200 schrieb Carl-Daniel Hailfinger:
-int spi_disable_blockprotect(void); +int spi_disable_blockprotect(struct flashchip *flash);
This change makes sense, but you don't use the flash parameter yet.
@@ -1392,6 +1408,7 @@ .block_erase = spi_block_erase_c7, } },
.write = spi_chip_write_1, .read = read_memmapped, },.unlock = spi_disable_blockprotect,
OUCH! "blame" me for committing that! read must not be "read_memmapped". Should I submit a fixup patch for that or do you want to fix that in one of your patches?
-int spi_disable_blockprotect(void) +int spi_disable_blockprotect(struct flashchip *flash) { uint8_t status; int result; @@ -855,6 +843,11 @@ msg_cerr("spi_write_status_register failed\n"); return result; }
status = spi_read_status_register();
if ((status & 0x3c) != 0) {
msg_cerr("Block protection could not be disabled!\n");
/* Should we error out here? */
Good question. As long as we have no partial write, we really should error out here. But when we get partial writes, it would be great to have flashrom being able to flash the lower part of the chip even if the upper part is write protected. This would need major code changes, though (unlocking would need to get the range to be unlocked), so for now erroring out seems like the best option and as soon as not erroring out might be sensible, we need to touch the code anyway.
Regards, Michael Karcher
On 10.07.2010 20:30, Michael Karcher wrote:
Am Samstag, den 10.07.2010, 03:05 +0200 schrieb Carl-Daniel Hailfinger:
-int spi_disable_blockprotect(void); +int spi_disable_blockprotect(struct flashchip *flash);
This change makes sense, but you don't use the flash parameter yet.
@@ -1392,6 +1408,7 @@ .block_erase = spi_block_erase_c7, } },
.write = spi_chip_write_1, .read = read_memmapped, },.unlock = spi_disable_blockprotect,
OUCH! "blame" me for committing that! read must not be "read_memmapped". Should I submit a fixup patch for that or do you want to fix that in one of your patches?
Can you fix it up? Such a change is
Acked-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
-int spi_disable_blockprotect(void) +int spi_disable_blockprotect(struct flashchip *flash) { uint8_t status; int result; @@ -855,6 +843,11 @@ msg_cerr("spi_write_status_register failed\n"); return result; }
status = spi_read_status_register();
if ((status & 0x3c) != 0) {
msg_cerr("Block protection could not be disabled!\n");
/* Should we error out here? */
Good question. As long as we have no partial write, we really should error out here. But when we get partial writes, it would be great to have flashrom being able to flash the lower part of the chip even if the upper part is write protected. This would need major code changes, though (unlocking would need to get the range to be unlocked), so for now erroring out seems like the best option and as soon as not erroring out might be sensible, we need to touch the code anyway.
OK, will change the code to error out.
Thanks for your review.
Regards, Carl-Daniel
Am Samstag, den 10.07.2010, 21:26 +0200 schrieb Carl-Daniel Hailfinger:
.write = spi_chip_write_1, .read = read_memmapped,.unlock = spi_disable_blockprotect,
OUCH! "blame" me for committing that! read must not be "read_memmapped". Should I submit a fixup patch for that or do you want to fix that in one of your patches?
Can you fix it up? Such a change is
Acked-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
r1074.
Regards, Michael Karcher
On 10.07.2010 21:26, Carl-Daniel Hailfinger wrote:
On 10.07.2010 20:30, Michael Karcher wrote:
Am Samstag, den 10.07.2010, 03:05 +0200 schrieb Carl-Daniel Hailfinger:
-int spi_disable_blockprotect(void); +int spi_disable_blockprotect(struct flashchip *flash);
This change makes sense, but you don't use the flash parameter yet.
That's mostly because large parts of the SPI core do not use the flash parameter. IMHO that should be changed eventually to be able to move some intelligence to lower layers. Right now this change is just there to satisfy the requirement for a prototype which matches the other unlock functions.
New version, should address all issues.
We have a generic unlocking infrastructure. Use it for SPI chips. Actually check if the unlock worked instead of just assuming it worked.
This depends on [PATCH] Convert SPI chips to partial write.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
diff -ur flashrom-partial_write_spi_intermediate/bitbang_spi.c flashrom-spi_unlock_refactor/bitbang_spi.c --- flashrom-partial_write_spi_intermediate/bitbang_spi.c 2010-07-09 19:11:10.000000000 +0200 +++ flashrom-spi_unlock_refactor/bitbang_spi.c 2010-07-10 02:55:40.000000000 +0200 @@ -141,6 +141,5 @@
int bitbang_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len) { - spi_disable_blockprotect(); return spi_write_chunked(flash, buf, start, len, 256); } diff -ur flashrom-partial_write_spi_intermediate/buspirate_spi.c flashrom-spi_unlock_refactor/buspirate_spi.c --- flashrom-partial_write_spi_intermediate/buspirate_spi.c 2010-07-08 12:15:05.000000000 +0200 +++ flashrom-spi_unlock_refactor/buspirate_spi.c 2010-07-10 02:53:48.000000000 +0200 @@ -311,6 +311,5 @@
int buspirate_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len) { - spi_disable_blockprotect(); return spi_write_chunked(flash, buf, start, len, 12); } diff -ur flashrom-partial_write_spi_intermediate/chipdrivers.h flashrom-spi_unlock_refactor/chipdrivers.h --- flashrom-partial_write_spi_intermediate/chipdrivers.h 2010-07-09 19:04:47.000000000 +0200 +++ flashrom-spi_unlock_refactor/chipdrivers.h 2010-07-10 02:53:42.000000000 +0200 @@ -47,7 +47,7 @@ int spi_chip_write_256_new(struct flashchip *flash, uint8_t *buf, int start, int len); int spi_chip_read(struct flashchip *flash, uint8_t *buf, int start, int len); uint8_t spi_read_status_register(void); -int spi_disable_blockprotect(void); +int spi_disable_blockprotect(struct flashchip *flash); int spi_byte_program(int addr, uint8_t databyte); int spi_nbyte_program(int addr, uint8_t *bytes, int len); int spi_nbyte_read(int addr, uint8_t *bytes, int len); diff -ur flashrom-partial_write_spi_intermediate/dummyflasher.c flashrom-spi_unlock_refactor/dummyflasher.c --- flashrom-partial_write_spi_intermediate/dummyflasher.c 2010-07-11 00:05:10.000000000 +0200 +++ flashrom-spi_unlock_refactor/dummyflasher.c 2010-07-11 00:11:42.000000000 +0200 @@ -173,6 +173,5 @@ */ int dummy_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len) { - spi_disable_blockprotect(); return spi_write_chunked(flash, buf, start, len, 256); } diff -ur flashrom-partial_write_spi_intermediate/flashchips.c flashrom-spi_unlock_refactor/flashchips.c --- flashrom-partial_write_spi_intermediate/flashchips.c 2010-07-11 00:48:32.000000000 +0200 +++ flashrom-spi_unlock_refactor/flashchips.c 2010-07-11 00:43:39.000000000 +0200 @@ -335,6 +335,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -369,6 +370,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -403,6 +405,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -437,6 +440,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -471,6 +475,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -505,6 +510,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -539,6 +545,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -573,6 +580,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -607,6 +615,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -641,6 +650,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -697,6 +707,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -731,6 +742,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -765,6 +777,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -781,6 +794,7 @@ .tested = TEST_UNTESTED, .probe = probe_spi_rdid, .probe_timing = TIMING_ZERO, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, },*/ @@ -1184,6 +1198,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1215,6 +1230,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1392,6 +1408,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_1, .read = spi_chip_read, }, @@ -1422,6 +1439,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1452,6 +1470,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1482,6 +1501,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1512,6 +1532,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1543,6 +1564,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1574,6 +1596,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1605,6 +1628,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1636,6 +1660,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1667,6 +1692,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1698,6 +1724,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1729,6 +1756,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1760,6 +1788,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1791,6 +1820,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1822,6 +1852,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1853,6 +1884,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1884,6 +1916,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1918,6 +1951,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1952,6 +1986,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -1986,6 +2021,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2020,6 +2056,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2051,6 +2088,7 @@ .block_erase = spi_block_erase_c7, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2082,6 +2120,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2113,6 +2152,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2144,6 +2184,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2687,6 +2728,7 @@ .block_erase = spi_block_erase_c7, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2718,6 +2760,7 @@ .block_erase = spi_block_erase_c7, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2752,6 +2795,7 @@ .block_erase = spi_block_erase_c7, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2786,6 +2830,7 @@ .block_erase = spi_block_erase_c7, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2820,6 +2865,7 @@ .block_erase = spi_block_erase_c7, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2854,6 +2900,7 @@ .block_erase = spi_block_erase_c7, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2885,6 +2932,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2916,6 +2964,7 @@ .block_erase = spi_block_erase_c7, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2947,6 +2996,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -2978,6 +3028,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3009,6 +3060,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3189,6 +3241,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3217,6 +3270,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3245,6 +3299,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3273,6 +3328,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3301,6 +3357,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3329,6 +3386,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3363,6 +3421,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3391,6 +3450,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3419,6 +3479,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3453,6 +3514,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3481,6 +3543,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3715,6 +3778,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3772,6 +3836,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3797,6 +3862,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -3831,6 +3897,7 @@ .block_erase = spi_block_erase_c7, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_1, .read = spi_chip_read, }, @@ -3865,6 +3932,7 @@ .block_erase = spi_block_erase_c7, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_1, .read = spi_chip_read, }, @@ -3893,6 +3961,7 @@ .block_erase = spi_block_erase_60, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_1, .read = spi_chip_read, }, @@ -3927,6 +3996,7 @@ .block_erase = spi_block_erase_c7, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_1, .read = spi_chip_read, }, @@ -3955,6 +4025,7 @@ .block_erase = spi_block_erase_60, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_1, .read = spi_chip_read, }, @@ -3989,6 +4060,7 @@ .block_erase = spi_block_erase_c7, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_1, .read = spi_chip_read, }, @@ -4023,6 +4095,7 @@ .block_erase = spi_block_erase_c7, }, }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_1, .read = spi_chip_read, }, @@ -4803,6 +4876,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -4833,6 +4907,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_1, /* 128 */ .read = spi_chip_read, }, @@ -4858,6 +4933,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -4884,6 +4960,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_1, /* 128 */ .read = spi_chip_read, }, @@ -4909,6 +4986,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -4934,6 +5012,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -4959,6 +5038,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -4984,6 +5064,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -5009,6 +5090,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -5034,6 +5116,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -5059,6 +5142,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -5084,6 +5168,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -5765,6 +5850,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -5799,6 +5885,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -5833,6 +5920,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -5867,6 +5955,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -5895,6 +5984,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -5923,6 +6013,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -5951,6 +6042,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -5979,6 +6071,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -6013,6 +6106,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -6047,6 +6141,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, @@ -6081,6 +6176,7 @@ .block_erase = spi_block_erase_c7, } }, + .unlock = spi_disable_blockprotect, .write = spi_chip_write_256, .read = spi_chip_read, }, diff -ur flashrom-partial_write_spi_intermediate/ft2232_spi.c flashrom-spi_unlock_refactor/ft2232_spi.c --- flashrom-partial_write_spi_intermediate/ft2232_spi.c 2010-07-08 12:15:05.000000000 +0200 +++ flashrom-spi_unlock_refactor/ft2232_spi.c 2010-07-10 02:55:44.000000000 +0200 @@ -290,7 +290,6 @@
int ft2232_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len) { - spi_disable_blockprotect(); return spi_write_chunked(flash, buf, start, len, 256); }
diff -ur flashrom-partial_write_spi_intermediate/ichspi.c flashrom-spi_unlock_refactor/ichspi.c --- flashrom-partial_write_spi_intermediate/ichspi.c 2010-07-09 19:12:42.000000000 +0200 +++ flashrom-spi_unlock_refactor/ichspi.c 2010-07-10 02:53:55.000000000 +0200 @@ -690,7 +690,6 @@ if (spi_controller == SPI_CONTROLLER_VIA) maxdata = 16;
- spi_disable_blockprotect(); return spi_write_chunked(flash, buf, start, len, maxdata); }
diff -ur flashrom-partial_write_spi_intermediate/it87spi.c flashrom-spi_unlock_refactor/it87spi.c --- flashrom-partial_write_spi_intermediate/it87spi.c 2010-07-10 19:00:06.000000000 +0200 +++ flashrom-spi_unlock_refactor/it87spi.c 2010-07-10 19:00:19.000000000 +0200 @@ -361,7 +361,6 @@ spi_chip_write_1_new(flash, buf, start, len); } else { int writehere; - spi_disable_blockprotect();
if (start % 256) { /* start to the end of the page or start + len, diff -ur flashrom-partial_write_spi_intermediate/sb600spi.c flashrom-spi_unlock_refactor/sb600spi.c --- flashrom-partial_write_spi_intermediate/sb600spi.c 2010-05-31 00:36:09.000000000 +0200 +++ flashrom-spi_unlock_refactor/sb600spi.c 2010-07-10 02:53:50.000000000 +0200 @@ -50,7 +50,6 @@
int sb600_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len) { - spi_disable_blockprotect(); return spi_write_chunked(flash, buf, start, len, 5); }
diff -ur flashrom-partial_write_spi_intermediate/spi25.c flashrom-spi_unlock_refactor/spi25.c --- flashrom-partial_write_spi_intermediate/spi25.c 2010-07-09 23:40:22.000000000 +0200 +++ flashrom-spi_unlock_refactor/spi25.c 2010-07-11 00:26:58.000000000 +0200 @@ -436,12 +436,6 @@ .readarr = NULL, }}; - result = spi_disable_blockprotect(); - if (result) { - msg_cerr("spi_disable_blockprotect failed\n"); - return result; - } - result = spi_send_multicommand(cmds); if (result) { msg_cerr("%s failed during command execution\n", @@ -482,12 +476,6 @@ .readarr = NULL, }};
- result = spi_disable_blockprotect(); - if (result) { - msg_cerr("spi_disable_blockprotect failed\n"); - return result; - } - result = spi_send_multicommand(cmds); if (result) { msg_cerr("%s failed during command execution\n", __func__); @@ -841,7 +829,7 @@ return result; }
-int spi_disable_blockprotect(void) +int spi_disable_blockprotect(struct flashchip *flash) { uint8_t status; int result; @@ -855,6 +843,11 @@ msg_cerr("spi_write_status_register failed\n"); return result; } + status = spi_read_status_register(); + if ((status & 0x3c) != 0) { + msg_cerr("Block protection could not be disabled!\n"); + return 1; + } } return 0; } @@ -970,7 +963,6 @@ { int i, result = 0;
- spi_disable_blockprotect(); for (i = start; i < start + len; i++) { result = spi_byte_program(i, buf[i]); if (result) @@ -984,7 +976,6 @@
int spi_chip_write_1(struct flashchip *flash, uint8_t *buf) { - spi_disable_blockprotect(); /* Erase first */ msg_cinfo("Erasing flash before programming... "); if (erase_flash(flash)) { diff -ur flashrom-partial_write_spi_intermediate/spi.c flashrom-spi_unlock_refactor/spi.c --- flashrom-partial_write_spi_intermediate/spi.c 2010-07-11 00:09:26.000000000 +0200 +++ flashrom-spi_unlock_refactor/spi.c 2010-07-11 00:46:59.000000000 +0200 @@ -196,8 +196,6 @@ /* * Program chip using page (256 bytes) programming. * Some SPI masters can't do this, they use single byte programming instead. - * The redirect to single byte programming is achieved by setting - * .write_256 = spi_chip_write_1 */ /* real chunksize is up to 256, logical chunksize is 256 */ int spi_chip_write_256_new(struct flashchip *flash, uint8_t *buf, int start, int len) @@ -217,7 +215,6 @@ { int ret;
- spi_disable_blockprotect(); msg_pinfo("Erasing flash before programming... "); if (erase_flash(flash)) { msg_perr("ERASE FAILED!\n");
Am Sonntag, den 11.07.2010, 00:56 +0200 schrieb Carl-Daniel Hailfinger:
We have a generic unlocking infrastructure. Use it for SPI chips. Actually check if the unlock worked instead of just assuming it worked.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Acked-by: Michael Karcher flashrom@mkarcher.dialup.fu-berlin.de
@@ -196,8 +196,6 @@ /*
- Program chip using page (256 bytes) programming.
- Some SPI masters can't do this, they use single byte programming instead.
- The redirect to single byte programming is achieved by setting
*/
- .write_256 = spi_chip_write_1
/* real chunksize is up to 256, logical chunksize is 256 */ int spi_chip_write_256_new(struct flashchip *flash, uint8_t *buf, int start, int len)
Just tell me to learn reading! The comment explicitly says how the redirection happens, please leave it in, it was good.
Regards, Michael Karcher
On 11.07.2010 09:17, Michael Karcher wrote:
Am Sonntag, den 11.07.2010, 00:56 +0200 schrieb Carl-Daniel Hailfinger:
We have a generic unlocking infrastructure. Use it for SPI chips. Actually check if the unlock worked instead of just assuming it worked.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Acked-by: Michael Karcher flashrom@mkarcher.dialup.fu-berlin.de
Thanks, will commit once [PATCH] Convert SPI chips to partial write is in.
@@ -196,8 +196,6 @@ /*
- Program chip using page (256 bytes) programming.
- Some SPI masters can't do this, they use single byte programming instead.
- The redirect to single byte programming is achieved by setting
*/
- .write_256 = spi_chip_write_1
/* real chunksize is up to 256, logical chunksize is 256 */ int spi_chip_write_256_new(struct flashchip *flash, uint8_t *buf, int start, int len)
Just tell me to learn reading!
I added that comment after you complained about a lack of clarity, so your reading skills are beyound doubt. This hunk should not have been marked as deletion, it was added in some other patch. Maybe I screwed up the diff command.
The comment explicitly says how the redirection happens, please leave it in, it was good.
Sure, will do.
Regards, Carl-Daniel
On 11.07.2010 09:17, Michael Karcher wrote:
Am Sonntag, den 11.07.2010, 00:56 +0200 schrieb Carl-Daniel Hailfinger:
We have a generic unlocking infrastructure. Use it for SPI chips. Actually check if the unlock worked instead of just assuming it worked.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Acked-by: Michael Karcher flashrom@mkarcher.dialup.fu-berlin.de
Thanks, committed in r1082.
Regards, Carl-Daniel