[flashrom] [PATCH 1/3] layout: change return type and name of find_next_included_romentry
Stefan Tauner
stefan.tauner at student.tuwien.ac.at
Mon Aug 15 06:43:36 CEST 2011
- rename from find_next_included_romentry to get_next_included_romentry
- return a pointer to a rom_entry instead of just its index
Signed-off-by: Stefan Tauner <stefan.tauner at student.tuwien.ac.at>
---
layout.c | 38 +++++++++++++++++++-------------------
1 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/layout.c b/layout.c
index d719a05..6b9627a 100644
--- a/layout.c
+++ b/layout.c
@@ -34,14 +34,12 @@ static int romimages = 0;
#define MAX_ROMLAYOUT 32
-typedef struct {
+static struct rom_entry {
unsigned int start;
unsigned int end;
unsigned int included;
char name[256];
-} romlayout_t;
-
-static romlayout_t rom_entries[MAX_ROMLAYOUT];
+} rom_entries[MAX_ROMLAYOUT];
#if CONFIG_INTERNAL == 1 /* FIXME: Move the whole block to cbtable.c? */
static char *def_name = "DEFAULT";
@@ -215,26 +213,28 @@ int find_romentry(char *name)
return -1;
}
-int find_next_included_romentry(unsigned int start)
+struct rom_entry *get_next_included_romentry(unsigned int start)
{
int i;
unsigned int best_start = UINT_MAX;
- int best_entry = -1;
+ struct rom_entry *best_entry = NULL;
+ struct rom_entry *cur;
/* First come, first serve for overlapping regions. */
for (i = 0; i < romimages; i++) {
- if (!rom_entries[i].included)
+ cur = &rom_entries[i];
+ if (!cur->included)
continue;
/* Already past the current entry? */
- if (start > rom_entries[i].end)
+ if (start > cur->end)
continue;
/* Inside the current entry? */
- if (start >= rom_entries[i].start)
- return i;
+ if (start >= cur->start)
+ return cur;
/* Entry begins after start. */
- if (best_start > rom_entries[i].start) {
- best_start = rom_entries[i].start;
- best_entry = i;
+ if (best_start > cur->start) {
+ best_start = cur->start;
+ best_entry = cur;
}
}
return best_entry;
@@ -243,7 +243,7 @@ int find_next_included_romentry(unsigned int start)
int handle_romentries(struct flashchip *flash, uint8_t *oldcontents, uint8_t *newcontents)
{
unsigned int start = 0;
- int entry;
+ struct rom_entry *entry;
unsigned int size = flash->total_size * 1024;
/* If no layout file was specified or the layout file was empty, assume
@@ -255,18 +255,18 @@ int handle_romentries(struct flashchip *flash, uint8_t *oldcontents, uint8_t *ne
* The union of all included romentries is used from the new image.
*/
while (start < size) {
- entry = find_next_included_romentry(start);
+ entry = get_next_included_romentry(start);
/* No more romentries for remaining region? */
- if (entry < 0) {
+ if (entry == NULL) {
memcpy(newcontents + start, oldcontents + start,
size - start);
break;
}
- if (rom_entries[entry].start > start)
+ if (entry->start > start)
memcpy(newcontents + start, oldcontents + start,
- rom_entries[entry].start - start);
+ entry->start - start);
/* Skip to location after current romentry. */
- start = rom_entries[entry].end + 1;
+ start = entry->end + 1;
/* Catch overflow. */
if (!start)
break;
--
1.7.1
More information about the flashrom
mailing list