summaryrefslogtreecommitdiffstats
path: root/s25f.c
diff options
context:
space:
mode:
authorNikolai Artemiev <nartemiev@google.com>2022-12-05 12:49:14 +1100
committerEdward O'Callaghan <quasisec@chromium.org>2023-01-19 12:41:58 +0000
commit673cb357d411e6d95be7cbf31513b46615355e12 (patch)
tree20deb2eb0aef676695d49ca8fd52dff1a80a9ebc /s25f.c
parent7cab790a46f8459789e258a106e743275e306a2d (diff)
downloadflashrom-673cb357d411e6d95be7cbf31513b46615355e12.tar.gz
flashrom-673cb357d411e6d95be7cbf31513b46615355e12.tar.bz2
flashrom-673cb357d411e6d95be7cbf31513b46615355e12.zip
tree/: Change chip restore data type from uint8_t to void ptr
Chip restore callbacks currently are used by - spi25_statusreg.c unlock functions to restore status register 1. - s25f.c to restore config register 3. Both of these cases only need to save a single uint8_t value to restore the original chip state, however storing a void pointer will allow more flexible chip restore behaviour. In particular, it will allow flashrom_wp_cfg objects to be saved and restored, enabling writeprotect-based unlocking. BUG=b:237485865,b:247421511 BRANCH=none TEST=Tested on grunt DUT (prog: sb600spi, flash: W25Q128.W): `flashrom --wp-range 0x0,0x1000000 \ flashrom --wp-status # Result: range=0x0,0x1000000 \ flashrom -w random.bin # Result: success \ flashrom -v random.bin # Result: success \ flashrom --wp-status # Result: range=0x0,0x1000000` Change-Id: I311b468a4b0349f4da9584c12b36af6ec2394527 Signed-off-by: Nikolai Artemiev <nartemiev@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/70349 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Diffstat (limited to 's25f.c')
-rw-r--r--s25f.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/s25f.c b/s25f.c
index 605a56075..549883b94 100644
--- a/s25f.c
+++ b/s25f.c
@@ -21,6 +21,7 @@
* TODO: Implement fancy hybrid sector architecture helpers.
*/
+#include <stdlib.h>
#include <string.h>
#include "chipdrivers.h"
@@ -230,10 +231,13 @@ static int s25fs_write_cr(const struct flashctx *flash,
return s25f_poll_status(flash);
}
-static int s25fs_restore_cr3nv(struct flashctx *flash, uint8_t cfg)
+static int s25fs_restore_cr3nv(struct flashctx *flash, void *data)
{
int ret = 0;
+ uint8_t cfg = *(uint8_t *)data;
+ free(data);
+
msg_cdbg("Restoring CR3NV value to 0x%02x\n", cfg);
ret |= s25fs_write_cr(flash, CR3NV_ADDR, cfg);
ret |= s25fs_software_reset(flash);
@@ -285,8 +289,15 @@ int s25fs_block_erase_d8(struct flashctx *flash, unsigned int addr, unsigned int
msg_cdbg("\n%s: CR3NV updated (0x%02x -> 0x%02x)\n",
__func__, cfg,
s25fs_read_cr(flash, CR3NV_ADDR));
+
/* Restore CR3V when flashrom exits */
- register_chip_restore(s25fs_restore_cr3nv, flash, cfg);
+ uint8_t *data = calloc(sizeof(uint8_t), 1);
+ if (!data) {
+ msg_cerr("Out of memory!\n");
+ return 1;
+ }
+ *data = cfg;
+ register_chip_restore(s25fs_restore_cr3nv, flash, data);
}
cr3nv_checked = 1;