David Hendricks has uploaded this change for review.

View Change

WIP: Add romentry flags and function to append a single layout entry

This is an experimental patch to make the partial writes work as
originally intended in patch 23022.

Currently, if no layout is specified then a fallback layout with an
entry covering the entire address space of the chip is used to write
to the chip. If a layout is specified then only the entries in the
layout are used. Consequently, "-i region:fill -w filename" is used
then the -w arg will be ignored.

This hopes to fix the latter case by appending the layout specified
by the user with an entry covering the entire chip when an argument
to '-w' is used.

One upside is that We can potentially get rid of the fallback layout
by using this mechanism to append a "complete chip" entry whenever
'-w' is used.

Signed-off-by: David Hendricks <david.hendricks@gmail.com>

Change-Id: I9eb4a7751681c639028d6854d877558daf59e567
---
M cli_classic.c
M layout.c
M layout.h
3 files changed, 46 insertions(+), 0 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/53/23353/1
diff --git a/cli_classic.c b/cli_classic.c
index a1f1cad..09da268 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -554,6 +554,20 @@

if (layoutfile) {
layout = get_global_layout();
+
+ if (filename) {
+ struct romentry entry = {
+ .start = 0,
+ .end = fill_flash->chip->total_size * 1024 - 1,
+ .included = true,
+ .name = "complete flash",
+ .file = filename,
+ .flags = ROMENTRY_FLAG_IGNORE_OVERLAP,
+ };
+ if (append_layout(&entry))
+ goto out_shutdown;
+ }
+
} else if (ifd && (flashrom_layout_read_from_ifd(&layout, fill_flash, NULL, 0) ||
process_include_args(layout))) {
ret = 1;
diff --git a/layout.c b/layout.c
index 4912a33..0b17a1f 100644
--- a/layout.c
+++ b/layout.c
@@ -48,6 +48,30 @@
return &flashctx->fallback_layout.base;
}

+/* FIXME: read_romlayout() should probably be modified to call this */
+int append_layout(const struct romentry *entry)
+{
+ if (layout.num_entries >= MAX_ROMLAYOUT) {
+ msg_gerr("Cannot add any more layout entries.\n");
+ return 1;
+ }
+
+ layout.entries[layout.num_entries].start = entry->start;
+ layout.entries[layout.num_entries].end = entry->end;
+ layout.entries[layout.num_entries].included = entry->included;
+ strncpy(layout.entries[layout.num_entries].name,
+ entry->name, sizeof(layout.entries[layout.num_entries].name));
+ layout.entries[layout.num_entries].file = entry->file;
+ layout.entries[layout.num_entries].flags = entry->flags;
+ msg_gdbg("appended romlayout %08x - %08x named \"%s\"\n",
+ layout.entries[layout.num_entries].start,
+ layout.entries[layout.num_entries].end,
+ layout.entries[layout.num_entries].name);
+ layout.num_entries++;
+
+ return 0;
+}
+
#ifndef __LIBPAYLOAD__
int read_romlayout(const char *name)
{
@@ -243,6 +267,10 @@
if (l->entries[i].end < l->entries[j].start)
continue;

+ if ((l->entries[i].flags & ROMENTRY_FLAG_IGNORE_OVERLAP) ||
+ (l->entries[j].flags & ROMENTRY_FLAG_IGNORE_OVERLAP))
+ continue;
+
msg_gdbg("Regions %s [0x%08x-0x%08x] and "
"%s [0x%08x-0x%08x] overlap\n",
l->entries[i].name, l->entries[i].start,
diff --git a/layout.h b/layout.h
index 9131b06..881b85a 100644
--- a/layout.h
+++ b/layout.h
@@ -38,12 +38,15 @@

#define MAX_ROMLAYOUT 32

+#define ROMENTRY_FLAG_IGNORE_OVERLAP (1 << 0)
+
struct romentry {
chipoff_t start;
chipoff_t end;
bool included;
char name[256];
char *file;
+ unsigned int flags;
};

struct flashrom_layout {
@@ -62,6 +65,7 @@
struct flashrom_flashctx;
const struct flashrom_layout *get_layout(const struct flashrom_flashctx *const flashctx);

+int append_layout(const struct romentry *const entry);
int process_include_args(struct flashrom_layout *);
int included_regions_overlap(const struct flashrom_layout *const flashrom_layout);
int get_num_include_args_with_files(const struct flashrom_layout *const layout);

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

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9eb4a7751681c639028d6854d877558daf59e567
Gerrit-Change-Number: 23353
Gerrit-PatchSet: 1
Gerrit-Owner: David Hendricks <david.hendricks@gmail.com>