[flashrom] [PATCH 5/6] layout: Add preliminary support for flags.

Stefan Tauner stefan.tauner at student.tuwien.ac.at
Tue Sep 24 01:14:05 CEST 2013


Signed-off-by: Stefan Tauner <stefan.tauner at student.tuwien.ac.at>
---
 flashrom.8.tmpl | 14 ++++++++------
 layout.c        | 27 ++++++++++++++++++++-------
 2 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/flashrom.8.tmpl b/flashrom.8.tmpl
index 765d7f6..b4fd5c9 100644
--- a/flashrom.8.tmpl
+++ b/flashrom.8.tmpl
@@ -218,27 +218,29 @@ quotes, or else only the part before the first space will be recognized.
 Each layout entry describes an address region of the flash chip and gives it a name (hereinafter referred to as
 a region). One entry per line is allowed with the following syntax:
 .sp
-.B "  startaddr:endaddr regionname"
+.B "  startaddr:endaddr regionname [flags]"
 .sp
 .BR "startaddr " "and " "endaddr "
 are addresses within the ROM image representing the flash ROM contents. They are interpreted in the 'usual' form
 i.e.\ a leading 0 means octal, leading 0x or 0X means hexadecimal, everything else is just decimal. Negative
 numbers are interpreted as addresses aligned to the top of the current chip's address space, for example
-.sp
-  0:-0 "whole chip"
-.sp
+.B  0:-0
 will always describe the complete flash space no matter which chip is used. This syntax is useful for specifying
-"the top 1MB" (-0x100000:-0) etc.
+"the top 1MB" (-0xfffff:-0) etc.
 .sp
 .BR "regionname " "is the name for the region from " "startaddr " "to " "endaddr " "(both addresses included)."
 If the name contains spaces it has to be written in double quotes, or else only the part before the first space
 will be used.
 .sp
+.B flags
+is an optional field to further describe regions by a list of possibly quoted strings separated by commas.
+.RB "Currently only " rw " is supported which denotes a region to be readable and writeable."
+.sp
 Example content of file rom.layout:
 .sp
   # flashrom layout v2
   source /home/flashrom/include.layout
-  0x00000000:0x00008fff "gfx rom"
+  0x00000000:0x00008fff "gfx rom" rw
   0x00009000:0x0003ffff normal
   0x00040000:0x0007ffff fallback
 .sp
diff --git a/layout.c b/layout.c
index d94cbe0..d522348 100644
--- a/layout.c
+++ b/layout.c
@@ -54,7 +54,7 @@ static char *include_args[MAX_ROMLAYOUT];
 static int num_include_args = 0; /* the number of valid include_args. */
 
 /* returns the index of the entry (or a negative value if it is not found) */
-static int find_romentry(char *name)
+static int find_romentry(const char *name)
 {
 	int i;
 	msg_gspew("Looking for region \"%s\"... ", name);
@@ -200,10 +200,23 @@ static int parse_entry(char *file_name, unsigned int linecnt, char *buf, romentr
 			 "Could not find region name in \"%s\".\n", file_name, linecnt, buf);
 		return -1;
 	}
+	const char *region_name = tmp_str;
+
+	/* Parse flags. */
+	tmp_str = endptr + strspn(endptr, WHITESPACE_CHARS);
+	strtok_r(tmp_str, ",", &endptr);
+	while (tmp_str != NULL && *tmp_str != '\0') {
+		if (strcmp(tmp_str, "rw") != 0) {
+			msg_gerr("Error parsing version 2 layout entry in file \"%s\" at line %d:\n"
+				 "Invalid flag \"%s\" detected.\n", file_name, linecnt, tmp_str);
+			return -1;
+		}
+		tmp_str = strtok_r(NULL, ",", &endptr);
+	}
 
 	msg_gdbg2("Parsed entry: 0x%" PRIxCHIPADDR " (%s) : 0x%" PRIxCHIPADDR " (%s) named \"%s\"\n",
 		  start, start_topalign ? "top-aligned" : "bottom-aligned",
-		  end, end_topalign ? "top-aligned" : "bottom-aligned", tmp_str);
+		  end, end_topalign ? "top-aligned" : "bottom-aligned", region_name);
 
 	/* We can only check address ranges if the chip size is available in case one address is relative to
 	 * the top and the other to the bottom. But if they are both relative to the same end we can without
@@ -211,13 +224,13 @@ static int parse_entry(char *file_name, unsigned int linecnt, char *buf, romentr
 	if ((!start_topalign && !end_topalign && start > end) ||
 	    (start_topalign && end_topalign && start < end)) {
 		msg_gerr("Error parsing version 2 layout entry in file \"%s\" at line %d:\n"
-			 "Length of region \"%s\" is not positive.\n", file_name, linecnt, tmp_str);
+			 "Length of region \"%s\" is not positive.\n", file_name, linecnt, region_name);
 		return -1;
 	}
 
-	if (find_romentry(tmp_str) >= 0) {
+	if (find_romentry(region_name) >= 0) {
 		msg_gerr("Error parsing version 2 layout entry in file \"%s\" at line %d:\n"
-			 "Region name \"%s\" used multiple times.\n", file_name, linecnt, tmp_str);
+			 "Region name \"%s\" used multiple times.\n", file_name, linecnt, region_name);
 		return -1;
 	}
 
@@ -225,11 +238,11 @@ static int parse_entry(char *file_name, unsigned int linecnt, char *buf, romentr
 	if (strlen(endptr) != 0)
 		msg_gwarn("Warning parsing version 2 layout entry in file \"%s\" at line %d:\n"
 			  "Region name \"%s\" is not followed by white space only.\n",
-			  file_name, linecnt, tmp_str);
+			  file_name, linecnt, region_name);
 
 
 	if (entry != NULL) {
-		entry->name = strdup(tmp_str);
+		entry->name = strdup(region_name);
 		if (entry->name == NULL) {
 			msg_gerr("Out of memory!\n");
 			return -1;
-- 
Kind regards, Stefan Tauner





More information about the flashrom mailing list