Attention is currently required from: Aarya.
Bill XIE has uploaded this change for review.
erasure_layout: Add an option to sacrifice unchanged blocks for speed
Someone may prefer to sacrifice sub-blocks needless to change within a
larger erase block for programming speed. These people who are okay to
fry their chip sooner can set this option. If the percentage of
sub-blocks needless to change within a larger erase block is lower
than the given value, the whole larger erase block will be erased.
Change-Id: I154e8a713f626c37dbbe118db700055b96d24803
Signed-off-by: persmule <persmule@hardenedlinux.org>
---
M cli_classic.c
M erasure_layout.c
M include/flash.h
3 files changed, 25 insertions(+), 3 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/21/84721/1
diff --git a/cli_classic.c b/cli_classic.c
index 3343438..dc51259 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -45,6 +45,7 @@
OPTION_WP_DISABLE,
OPTION_WP_LIST,
OPTION_PROGRESS,
+ OPTION_SACRIFICE_RATIO,
};
struct cli_options {
@@ -73,6 +74,7 @@
char *logfile;
char *referencefile;
const char *chip_to_probe;
+ int sacrifice_ratio;
};
static void cli_classic_usage(const char *name)
@@ -119,6 +121,10 @@
" --flash-contents <ref-file> assume flash contents to be <ref-file>\n"
" -L | --list-supported print supported devices\n"
" --progress show progress percentage on the standard output\n"
+ " --sacrifice-ratio <ratio> The percentage of overall sub-blocks needless to\n"
+ " change within a larger erase block to be sacrificed\n"
+ " for programming speed, default 0, max 100\n"
+ " DANGEROUS! It wears your chip harder!\n"
" -p | --programmer <name>[:<param>] specify the programmer device. One of\n");
list_programmers_linebreak(4, 80, 0);
printf(".\n\nYou can specify one of -h, -R, -L, "
@@ -810,6 +816,10 @@
case OPTION_PROGRESS:
options->show_progress = true;
break;
+ case OPTION_SACRIFICE_RATIO:
+ /* It is okay to convert invalid input to 0. */
+ options->sacrifice_ratio = atoi(optarg);
+ break;
default:
cli_classic_abort_usage(NULL);
break;
@@ -879,6 +889,7 @@
{"version", 0, NULL, 'R'},
{"output", 1, NULL, 'o'},
{"progress", 0, NULL, OPTION_PROGRESS},
+ {"sacrifice-ratio", 1, NULL, OPTION_SACRIFICE_RATIO},
{NULL, 0, NULL, 0},
};
@@ -1125,6 +1136,14 @@
goto out_shutdown;
}
+ if (options.sacrifice_ratio) {
+ if (options.sacrifice_ratio > 100) {
+ msg_ginfo("Invalid input, use default.\n");
+ options.sacrifice_ratio = 0;
+ }
+ fill_flash->sacrifice_ratio = options.sacrifice_ratio;
+ }
+
if (options.ifd && (flashrom_layout_read_from_ifd(&options.layout, fill_flash, NULL, 0) ||
process_include_args(options.layout, options.include_args))) {
ret = 1;
diff --git a/erasure_layout.c b/erasure_layout.c
index 7f3bb46..56da450 100644
--- a/erasure_layout.c
+++ b/erasure_layout.c
@@ -249,9 +249,10 @@
}
const int total_blocks = sub_block_end - sub_block_start + 1;
- if (count == total_blocks) {
- /* We are selecting one large block instead, so send opcode once
- * instead of sending many smaller ones.
+ if (total_blocks - count <= total_blocks * flashctx->sacrifice_ratio / 100) {
+ /* Number of smaller blocks needless to change is lower than the
+ * sacrifice ratio, we are selecting one large block instead, so
+ * send opcode once instead of sending many smaller ones.
*/
if (ll->start_addr >= rstart && ll->end_addr <= rend) {
/* Deselect all smaller blocks covering the same region. */
diff --git a/include/flash.h b/include/flash.h
index d0e55af..90a9201 100644
--- a/include/flash.h
+++ b/include/flash.h
@@ -587,6 +587,8 @@
/* Progress reporting */
flashrom_progress_callback *progress_callback;
struct flashrom_progress *progress_state;
+ /* Sacrifice ratio */
+ int sacrifice_ratio;
};
/* Timing used in probe routines. ZERO is -2 to differentiate between an unset
To view, visit change 84721. To unsubscribe, or for help writing mail filters, visit settings.