summaryrefslogtreecommitdiffstats
path: root/flashrom.c
diff options
context:
space:
mode:
authorAarya Chaumal <aarya.chaumal@gmail.com>2022-12-21 21:05:43 +0530
committerAnastasia Klimchuk <aklm@chromium.org>2023-02-13 04:57:07 +0000
commit3631884b0d34dad47b31e51bbd285968734b4620 (patch)
tree6d3e97bcb106896558885ea96773f467f62b61ef /flashrom.c
parent8fbe405038cf52149902e6e148716064e25ec7b3 (diff)
downloadflashrom-3631884b0d34dad47b31e51bbd285968734b4620.tar.gz
flashrom-3631884b0d34dad47b31e51bbd285968734b4620.tar.bz2
flashrom-3631884b0d34dad47b31e51bbd285968734b4620.zip
flashrom.c: Add new erase_by_layout and walk_by_layout implementations
Add [erase,walk]_by_layout_new to use optimised implementations of the erase function selection algorithm. Change-Id: Id79ae943eb9d6a817da28381db477725834faaf6 Signed-off-by: Aarya Chaumal <aarya.chaumal@gmail.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/71173 Reviewed-by: Edward O'Callaghan <quasisec@chromium.org> Reviewed-by: Thomas Heijligen <src@posteo.de> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'flashrom.c')
-rw-r--r--flashrom.c83
1 files changed, 81 insertions, 2 deletions
diff --git a/flashrom.c b/flashrom.c
index 1790ad96a..d17e04bdb 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -33,6 +33,7 @@
#include "programmer.h"
#include "hwaccess_physmap.h"
#include "chipdrivers.h"
+#include "erasure_layout.h"
static bool use_legacy_erase_path = true;
@@ -1537,11 +1538,54 @@ static int erase_by_layout_legacy(struct flashctx *const flashctx)
return walk_by_layout(flashctx, &info, &erase_block, &all_skipped);
}
+static int erase_by_layout_new(struct flashctx *const flashctx)
+{
+ bool all_skipped = true;
+ const uint32_t flash_size = flashctx->chip->total_size * 1024;
+ uint8_t* curcontents = malloc(flash_size);
+ uint8_t* newcontents = malloc(flash_size);
+ struct erase_layout *erase_layout;
+ create_erase_layout(flashctx, &erase_layout);
+ int ret = 0;
+
+ //erase layout creation failed
+ if (!erase_layout) {
+ ret = 1;
+ goto _ret;
+ }
+
+ //not enough memory
+ if (!curcontents || !newcontents) {
+ ret = 1;
+ goto _ret;
+ }
+
+ memset(curcontents, ~ERASED_VALUE(flashctx), flash_size);
+ memset(newcontents, ERASED_VALUE(flashctx), flash_size);
+
+ const struct flashrom_layout *const flash_layout = get_layout(flashctx);
+ const struct romentry *entry = NULL;
+ while ((entry = layout_next_included(flash_layout, entry))) {
+ ret = erase_write(flashctx, entry->region.start, entry->region.end, curcontents, newcontents, erase_layout, &all_skipped);
+ if (ret) {
+ ret = 1;
+ msg_cerr("Erase Failed");
+ goto _ret;
+ }
+ }
+
+_ret:
+ free(curcontents);
+ free(newcontents);
+ free_erase_layout(erase_layout, count_usable_erasers(flashctx));
+ return ret;
+}
+
static int erase_by_layout(struct flashctx *const flashctx)
{
if (use_legacy_erase_path)
return erase_by_layout_legacy(flashctx);
- return 1; /* unimplemented. */
+ return erase_by_layout_new(flashctx);
}
static int read_erase_write_block(struct flashctx *const flashctx,
@@ -1662,13 +1706,48 @@ static int write_by_layout_legacy(struct flashctx *const flashctx,
return walk_by_layout(flashctx, &info, read_erase_write_block, all_skipped);
}
+static int write_by_layout_new(struct flashctx *const flashctx,
+ void *const curcontents, const void *const newcontents,
+ bool *all_skipped)
+{
+ const int erasefn_count = count_usable_erasers(flashctx);
+ int ret = 1;
+
+ const struct flashrom_layout *const flash_layout = get_layout(flashctx);
+ struct erase_layout *erase_layout;
+ create_erase_layout(flashctx, &erase_layout);
+
+ if (!flash_layout) {
+ goto _ret;
+ }
+ if (!erase_layout) {
+ goto _ret;
+ }
+
+ const struct romentry *entry = NULL;
+ while ((entry = layout_next_included(flash_layout, entry))) {
+ ret = erase_write(flashctx, entry->region.start,
+ entry->region.end,
+ curcontents,
+ (uint8_t *)newcontents,
+ erase_layout, all_skipped);
+ if (ret) {
+ msg_cerr("Write Failed!");
+ goto _ret;
+ }
+ }
+_ret:
+ free_erase_layout(erase_layout, erasefn_count);
+ return ret;
+}
+
static int write_by_layout(struct flashctx *const flashctx,
uint8_t *const curcontents, const uint8_t *const newcontents,
bool *all_skipped)
{
if (use_legacy_erase_path)
return write_by_layout_legacy(flashctx, curcontents, newcontents, all_skipped);
- return 1; /* unimplemented. */
+ return write_by_layout_new(flashctx, curcontents, newcontents, all_skipped);
}
/**