Edward O'Callaghan has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/64374 )
Change subject: flashrom.c: wrap chip->write() with a helper ......................................................................
flashrom.c: wrap chip->write() with a helper
Change-Id: I46490eba664f96df37310972141ee5db13e48877 Signed-off-by: Edward O'Callaghan quasisec@google.com --- M flashrom.c 1 file changed, 22 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/74/64374/1
diff --git a/flashrom.c b/flashrom.c index 7f54488..b2c60fe 100644 --- a/flashrom.c +++ b/flashrom.c @@ -1044,6 +1044,26 @@ return 0; }
+/* + * write_flash - wrapper for flash->write() with additional high-level policy + * + * @flash flash chip + * @buf buffer to write to flash + * @start start address in flash + * @len number of bytes to write + * + * TODO: Look up regions that are write-protected and avoid attempt to write + * to them at all. + */ +static int write_flash(struct flashctx *flash, const uint8_t *buf, + unsigned int start, unsigned int len) +{ + if (!flash || !flash->chip->write) + return -1; + + return flash->chip->write(flash, buf, start, len); +} + /** * @brief Reads the included layout regions into a buffer. * @@ -1318,7 +1338,7 @@ if (!writecount++) msg_cdbg("W"); /* Needs the partial write function signature. */ - if (flashctx->chip->write(flashctx, backup_contents + starthere, + if (write_flash(flashctx, backup_contents + starthere, info->erase_start + starthere, lenhere)) goto _free_ret; starthere += lenhere; @@ -1422,7 +1442,7 @@ if (!writecount++) msg_cdbg("W"); /* Needs the partial write function signature. */ - if (flashctx->chip->write(flashctx, newcontents + starthere, + if (write_flash(flashctx, newcontents + starthere, info->erase_start + starthere, lenhere)) goto _free_ret; starthere += lenhere;