Nico Huber merged this change.

View Change

Approvals: build bot (Jenkins): Verified Arthur Heymans: Looks good to me, approved
layout: Introduce layout_next_included()

Change-Id: Ib01c8af06c3f84eafbd585760e74c3c287b9fa7d
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/33518
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
---
M flashrom.c
M layout.c
M layout.h
3 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/flashrom.c b/flashrom.c
index 2d3cd18..b47d0a2 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -1597,14 +1597,11 @@
static int read_by_layout(struct flashctx *const flashctx, uint8_t *const buffer)
{
const struct flashrom_layout *const layout = get_layout(flashctx);
+ const struct romentry *entry = NULL;

- size_t i;
- for (i = 0; i < layout->num_entries; ++i) {
- if (!layout->entries[i].included)
- continue;
-
- const chipoff_t region_start = layout->entries[i].start;
- const chipsize_t region_len = layout->entries[i].end - layout->entries[i].start + 1;
+ while ((entry = layout_next_included(layout, entry))) {
+ const chipoff_t region_start = entry->start;
+ const chipsize_t region_len = entry->end - entry->start + 1;

if (flashctx->chip->read(flashctx, buffer + region_start, region_start, region_len))
return 1;
@@ -1681,17 +1678,14 @@
const per_blockfn_t per_blockfn)
{
const struct flashrom_layout *const layout = get_layout(flashctx);
+ const struct romentry *entry = NULL;

all_skipped = true;
msg_cinfo("Erasing and writing flash chip... ");

- size_t i;
- for (i = 0; i < layout->num_entries; ++i) {
- if (!layout->entries[i].included)
- continue;
-
- info->region_start = layout->entries[i].start;
- info->region_end = layout->entries[i].end;
+ while ((entry = layout_next_included(layout, entry))) {
+ info->region_start = entry->start;
+ info->region_end = entry->end;

size_t j;
int error = 1; /* retry as long as it's 1 */
@@ -1962,14 +1956,11 @@
void *const curcontents, const uint8_t *const newcontents)
{
const struct flashrom_layout *const layout = get_layout(flashctx);
+ const struct romentry *entry = NULL;

- size_t i;
- for (i = 0; i < layout->num_entries; ++i) {
- if (!layout->entries[i].included)
- continue;
-
- const chipoff_t region_start = layout->entries[i].start;
- const chipsize_t region_len = layout->entries[i].end - layout->entries[i].start + 1;
+ while ((entry = layout_next_included(layout, entry))) {
+ const chipoff_t region_start = entry->start;
+ const chipsize_t region_len = entry->end - entry->start + 1;

if (flashctx->chip->read(flashctx, curcontents + region_start, region_start, region_len))
return 1;
diff --git a/layout.c b/layout.c
index 52aa388..e49189e 100644
--- a/layout.c
+++ b/layout.c
@@ -252,6 +252,24 @@
return lowest;
}

+const struct romentry *layout_next_included(
+ const struct flashrom_layout *const layout, const struct romentry *iterator)
+{
+ const struct romentry *const end = layout->entries + layout->num_entries;
+
+ if (iterator)
+ ++iterator;
+ else
+ iterator = &layout->entries[0];
+
+ for (; iterator < end; ++iterator) {
+ if (!iterator->included)
+ continue;
+ return iterator;
+ }
+ return NULL;
+}
+
/**
* @addtogroup flashrom-layout
* @{
diff --git a/layout.h b/layout.h
index b9454a8..53a20d6 100644
--- a/layout.h
+++ b/layout.h
@@ -65,5 +65,6 @@

int process_include_args(struct flashrom_layout *l, const struct layout_include_args *const args);
const struct romentry *layout_next_included_region(const struct flashrom_layout *, chipoff_t);
+const struct romentry *layout_next_included(const struct flashrom_layout *, const struct romentry *);

#endif /* !__LAYOUT_H__ */

To view, visit change 33518. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ib01c8af06c3f84eafbd585760e74c3c287b9fa7d
Gerrit-Change-Number: 33518
Gerrit-PatchSet: 4
Gerrit-Owner: Nico Huber <nico.h@gmx.de>
Gerrit-Reviewer: Angel Pons <th3fanbus@gmail.com>
Gerrit-Reviewer: Arthur Heymans <arthur@aheymans.xyz>
Gerrit-Reviewer: David Hendricks <david.hendricks@gmail.com>
Gerrit-Reviewer: Nico Huber <nico.h@gmx.de>
Gerrit-Reviewer: Thomas Heijligen <src@posteo.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-MessageType: merged