Pass layout directly to verify_by_layout()
It used the current layout from the flash context, before. This made
it necessary to replace the pointer on-the-fly. Passing the layout
directly, works without that stunt.
Change-Id: Id496deec85c18bdfe968df6a798b626eb9cfbed5
Signed-off-by: Nico Huber <nico.h@gmx.de>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/33520
Original-Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Original-Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Original-Reviewed-by: Peter Marheine <pmarheine@chromium.org>
Original-Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/72216
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/flashrom.c b/flashrom.c
index 361f135..8017849 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -1451,16 +1451,18 @@
* contents will be compared.
*
* @param flashctx Flash context to be used.
+ * @param layout Flash layout information.
* @param curcontents A buffer of full chip size to read current chip contents into.
* @param newcontents The new image to compare to.
* @return 0 on success,
* 1 if reading failed,
* 3 if the contents don't match.
*/
-static int verify_by_layout(struct flashctx *const flashctx,
- void *const curcontents, const uint8_t *const newcontents)
+static int verify_by_layout(
+ struct flashctx *const flashctx,
+ const struct flashrom_layout *const layout,
+ void *const curcontents, const uint8_t *const newcontents)
{
- const struct flashrom_layout *const layout = get_layout(flashctx);
const struct romentry *entry = NULL;
while ((entry = layout_next_included(layout, entry))) {
@@ -1969,6 +1971,8 @@
const size_t flash_size = flashctx->chip->total_size * 1024;
const bool verify_all = flashctx->flags.verify_whole_chip;
const bool verify = flashctx->flags.verify_after_write;
+ const struct flashrom_layout *const verify_layout =
+ verify_all ? get_default_layout(flashctx) : get_layout(flashctx);
if (buffer_len != flash_size)
return 4;
@@ -2057,19 +2061,14 @@
/* Verify only if we actually changed something. */
if (verify && !all_skipped) {
- const struct flashrom_layout *const layout_bak = flashctx->layout;
-
msg_cinfo("Verifying flash... ");
/* Work around chips which need some time to calm down. */
programmer_delay(1000*1000);
- if (verify_all) {
+ if (verify_all)
combine_image_by_layout(flashctx, newcontents, oldcontents);
- flashctx->layout = NULL;
- }
- ret = verify_by_layout(flashctx, curcontents, newcontents);
- flashctx->layout = layout_bak;
+ ret = verify_by_layout(flashctx, verify_layout, curcontents, newcontents);
/* If we tried to write, and verification now fails, we
might have an emergency situation. */
if (ret)
@@ -2105,6 +2104,7 @@
*/
int flashrom_image_verify(struct flashctx *const flashctx, const void *const buffer, const size_t buffer_len)
{
+ const struct flashrom_layout *const layout = get_layout(flashctx);
const size_t flash_size = flashctx->chip->total_size * 1024;
if (buffer_len != flash_size)
@@ -2123,7 +2123,7 @@
goto _free_ret;
msg_cinfo("Verifying flash... ");
- ret = verify_by_layout(flashctx, curcontents, newcontents);
+ ret = verify_by_layout(flashctx, layout, curcontents, newcontents);
if (!ret)
msg_cinfo("VERIFIED.\n");