Arthur Heymans has uploaded this change for review.

View Change

[RFC]Don't make layoutfile and --ifd mutually exclusive

Simply append the --ifd entries to the entries found in the layout
file.

When there are multiple entries with the same name the first one
encountered will be used. If an entry occurs in the layoutfile
and is generated the ifd the one in the layoutfile will take
precedence.

Change-Id: I8602196e56e8903a4a22f8070a97f39628e0cc13
Signed-off-by: Arthur Heymans <arthur@aheymans.xyz>
---
M cli_classic.c
M layout.c
M libflashrom.c
3 files changed, 23 insertions(+), 25 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/78/23678/1
diff --git a/cli_classic.c b/cli_classic.c
index 441fc91..66d31af 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -223,17 +223,9 @@
"more than once. Aborting.\n");
cli_classic_abort_usage();
}
- if (ifd) {
- fprintf(stderr, "Error: --layout and --ifd both specified. Aborting.\n");
- cli_classic_abort_usage();
- }
layoutfile = strdup(optarg);
break;
case 0x0100:
- if (layoutfile) {
- fprintf(stderr, "Error: --layout and --ifd both specified. Aborting.\n");
- cli_classic_abort_usage();
- }
ifd = 1;
break;
case 'i':
@@ -390,10 +382,6 @@
ret = 1;
goto out;
}
- if (!ifd && process_include_args(get_global_layout())) {
- ret = 1;
- goto out;
- }
/* Does a chip with the requested name exist in the flashchips array? */
if (chip_to_probe) {
for (chip = flashchips; chip && chip->name; chip++)
@@ -543,10 +531,13 @@
goto out_shutdown;
}

- if (layoutfile) {
- layout = get_global_layout();
- } else if (ifd && (flashrom_layout_read_from_ifd(&layout, fill_flash, NULL, 0) ||
- process_include_args(layout))) {
+ layout = get_global_layout();
+ if (ifd && (flashrom_layout_read_from_ifd(&layout, fill_flash, NULL, 0))) {
+ ret = 1;
+ goto out_shutdown;
+ }
+
+ if (process_include_args(layout)) {
ret = 1;
goto out_shutdown;
}
diff --git a/layout.c b/layout.c
index 7ce7c57..61e41b5 100644
--- a/layout.c
+++ b/layout.c
@@ -53,7 +53,6 @@
{
FILE *romlayout;
char tempstr[256];
- int i;

romlayout = fopen(name, "r");

@@ -93,18 +92,23 @@
layout.num_entries++;
}

- for (i = 0; i < layout.num_entries; i++) {
- msg_gdbg("romlayout %08x - %08x named %s\n",
- layout.entries[i].start,
- layout.entries[i].end, layout.entries[i].name);
- }
-
(void)fclose(romlayout);

return 0;
}
#endif

+static void print_layout(void)
+{
+ int i;
+
+ for (i = 0; i < layout.num_entries; i++) {
+ msg_gdbg("romlayout %08x - %08x named %s\n",
+ layout.entries[i].start,
+ layout.entries[i].end, layout.entries[i].name);
+ }
+}
+
/* returns the index of the entry (or a negative value if it is not found) */
static int find_include_arg(const char *const name)
{
@@ -167,6 +171,8 @@
int i;
unsigned int found = 0;

+ print_layout();
+
if (num_include_args == 0)
return 0;

diff --git a/libflashrom.c b/libflashrom.c
index 6e0f42c..32ad891 100644
--- a/libflashrom.c
+++ b/libflashrom.c
@@ -334,7 +334,7 @@
return 6;
#else
struct ich_layout dump_layout;
- int ret = 1;
+ int ret = 1, i;

void *const desc = malloc(0x1000);
struct ich_layout *const chip_layout = malloc(sizeof(*chip_layout));
@@ -373,7 +373,8 @@
}
}

- *layout = (struct flashrom_layout *)chip_layout;
+ for (i = 0; i < chip_layout->base.num_entries; i++)
+ (*layout)->entries[(*layout)->num_entries++] = chip_layout->entries[i];
ret = 0;

_finalize_ret:

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

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8602196e56e8903a4a22f8070a97f39628e0cc13
Gerrit-Change-Number: 23678
Gerrit-PatchSet: 1
Gerrit-Owner: Arthur Heymans <arthur@aheymans.xyz>