[RFC,13/13] external/ffspart: Use new interface

Message ID 20170829062506.8317-14-cyril.bur@au1.ibm.com
State New
Headers show
Series
  • Rework flash TOC generation
Related show

Commit Message

Cyril Bur Aug. 29, 2017, 6:25 a.m.
This also updated the pflash tests which use ffspart to generate pnors

Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com>
---
 external/ffspart/ffspart.c                         | 527 +++++++++++++--------
 external/ffspart/test/files/03-tiny-pnor.in        |   8 +-
 .../ffspart/test/files/03.1-tiny-pnor-backup.in    |   4 -
 .../ffspart/test/files/03.1-tiny-pnor-backup.out   | Bin 3840 -> 0 bytes
 external/ffspart/test/files/04-tiny-pnor2.in       |   8 +-
 external/ffspart/test/files/05-hdr-overlap.in      |   8 +-
 .../ffspart/test/files/05.1-hdr-overlap-backup.in  |   3 -
 external/ffspart/test/files/06-small-flash.in      |  10 +-
 external/ffspart/test/files/07-big-files.in        |   8 +-
 external/ffspart/test/files/08-small-files.in      |   8 +-
 external/ffspart/test/files/10-bad-input.in        |   8 +-
 external/ffspart/test/files/11-long-name.in        |   8 +-
 external/ffspart/test/files/12-bad-numbers-base.in |   8 +-
 external/ffspart/test/files/13-bad-numbers-size.in |   8 +-
 external/ffspart/test/files/14-bad-input-flags.in  |   8 +-
 .../test/files/15-overlapping-partitions.in        |   8 +-
 external/ffspart/test/results/01-param-sanity.err  |   1 -
 external/ffspart/test/results/01-param-sanity.out  |   5 -
 .../ffspart/test/results/01.1-param-sanity.err     |   0
 .../{02-param-sides.out => 01.1-param-sanity.out}  |   5 -
 external/ffspart/test/results/02-param-sides.err   |   1 -
 external/ffspart/test/results/05-hdr-overlap.err   |   5 +-
 external/ffspart/test/results/05-hdr-overlap.out   |   3 -
 .../test/results/05.1-hdr-overlap-backup.err       |   2 -
 .../test/results/05.1-hdr-overlap-backup.out       |   4 -
 external/ffspart/test/results/06-small-flash.err   |   5 +-
 external/ffspart/test/results/06-small-flash.out   |   2 -
 external/ffspart/test/results/07-big-files.err     |   5 +-
 external/ffspart/test/results/07-big-files.out     |   1 -
 external/ffspart/test/results/08-small-files.err   |   2 +
 external/ffspart/test/results/08-small-files.out   |   4 -
 external/ffspart/test/results/10-bad-input.err     |   5 +-
 external/ffspart/test/results/11-long-name.err     |   6 +-
 external/ffspart/test/results/11-long-name.out     |   4 -
 .../ffspart/test/results/12-bad-numbers-base.err   |   5 +-
 .../ffspart/test/results/13-bad-numbers-size.err   |   5 +-
 .../ffspart/test/results/14-bad-input-flags.err    |   5 +-
 .../test/results/15-overlapping-partitions.err     |   5 +-
 .../test/results/15-overlapping-partitions.out     |   2 -
 external/ffspart/test/tests/01-param-sanity        |   6 +-
 external/ffspart/test/tests/01.1-param-sanity      |  12 +
 external/ffspart/test/tests/02-param-sides         |  16 -
 external/ffspart/test/tests/03.1-tiny-pnor-backup  |  19 -
 external/ffspart/test/tests/05-hdr-overlap         |   7 +-
 .../ffspart/test/tests/05.1-hdr-overlap-backup     |  19 -
 external/ffspart/test/tests/06-small-flash         |   5 +-
 external/ffspart/test/tests/07-big-files           |   4 +
 external/ffspart/test/tests/10-bad-input           |   2 +
 external/ffspart/test/tests/12-bad-numbers-base    |   2 +
 external/ffspart/test/tests/13-bad-numbers-size    |   2 +
 external/ffspart/test/tests/14-bad-input-flags     |   2 +
 .../ffspart/test/tests/15-overlapping-partitions   |   4 +-
 external/pflash/test/files/01-info.ffs             |   8 +-
 external/pflash/test/files/02-erase.ffs            |   8 +-
 external/pflash/test/files/03-erase-parts.ffs      |   8 +-
 external/pflash/test/files/04-program-rand.ffs     |   8 +-
 external/pflash/test/files/05-bad-numbers.ffs      |   8 +-
 external/pflash/test/files/06-miscprint.ffs        |   8 +-
 external/pflash/test/results/06-miscprint.out      |   2 +-
 libflash/libffs.c                                  |   5 +-
 60 files changed, 480 insertions(+), 389 deletions(-)
 delete mode 100644 external/ffspart/test/files/03.1-tiny-pnor-backup.in
 delete mode 100644 external/ffspart/test/files/03.1-tiny-pnor-backup.out
 delete mode 100644 external/ffspart/test/files/05.1-hdr-overlap-backup.in
 create mode 100644 external/ffspart/test/results/01.1-param-sanity.err
 rename external/ffspart/test/results/{02-param-sides.out => 01.1-param-sanity.out} (67%)
 delete mode 100644 external/ffspart/test/results/02-param-sides.err
 delete mode 100644 external/ffspart/test/results/05.1-hdr-overlap-backup.err
 delete mode 100644 external/ffspart/test/results/05.1-hdr-overlap-backup.out
 create mode 100644 external/ffspart/test/tests/01.1-param-sanity
 delete mode 100644 external/ffspart/test/tests/02-param-sides
 delete mode 100644 external/ffspart/test/tests/03.1-tiny-pnor-backup
 delete mode 100644 external/ffspart/test/tests/05.1-hdr-overlap-backup

Patch

diff --git a/external/ffspart/ffspart.c b/external/ffspart/ffspart.c
index 9b66f4fe..0f5d7d6f 100644
--- a/external/ffspart/ffspart.c
+++ b/external/ffspart/ffspart.c
@@ -1,4 +1,4 @@ 
-/* Copyright 2013-2016 IBM Corp.
+/* Copyright 2013-2017 IBM Corp.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -14,6 +14,7 @@ 
  * limitations under the License.
  */
 
+#include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <getopt.h>
@@ -50,11 +51,250 @@ 
  *  Lets do 50.
  */
 #define MAX_LINE 100
+#define MAX_TOCS 10
 #define SEPARATOR ','
 
 /* Full version number (possibly includes gitid). */
 extern const char version[];
 
+static int read_u32(const char *input, uint32_t *val)
+{
+	char *endptr;
+	*val = strtoul(input, &endptr, 0);
+	return (*endptr == SEPARATOR) ? 0 : 1;
+}
+
+static const char *advance_line(const char *input)
+{
+	char *pos = strchr(input, SEPARATOR);
+	if (!pos)
+		return NULL;
+	return pos + 1;
+}
+
+static struct ffs_hdr *parse_toc(const char *line, uint32_t block_size,
+		uint32_t block_count)
+{
+	struct ffs_entry_user user;
+	struct ffs_entry *ent;
+	struct ffs_hdr *hdr;
+	uint32_t tbase;
+	int rc;
+
+	if (read_u32(line, &tbase)) {
+		fprintf(stderr, "Couldn't parse TOC base address\n");
+		return NULL;
+	}
+
+	line = advance_line(line);
+	if (!line) {
+		fprintf(stderr, "Couldn't find TOC flags\n");
+		return NULL;
+	}
+
+	rc = ffs_string_to_entry_user(line, strlen(line), &user);
+	if (rc) {
+		fprintf(stderr, "Couldn't parse TOC flags\n");
+		return NULL;
+	}
+
+	rc = ffs_entry_new("part", tbase, 0, &ent);
+	if (rc) {
+		fprintf(stderr, "Couldn't make entry for TOC@0x%08x\n", tbase);
+		return NULL;
+	}
+
+	rc = ffs_entry_user_set(ent, &user);
+	if (rc) {
+		fprintf(stderr, "Invalid TOC flag\n");
+		ffs_entry_put(ent);
+		return NULL;
+	}
+
+	rc = ffs_hdr_new(block_size, block_count, &ent, &hdr);
+	if (rc) {
+		hdr = NULL;
+		fprintf(stderr, "Couldn't make header for TOC@0x%08x\n", tbase);
+	}
+
+	ffs_entry_put(ent);
+	return hdr;
+}
+
+static int parse_entry(struct blocklevel_device *bl,
+		struct ffs_hdr **tocs, const char *line)
+{
+	char name[FFS_PART_NAME_MAX + 2] = { 0 };
+	struct ffs_entry_user user = { 0 };
+	uint32_t pbase, psize, pactual;
+	struct ffs_entry *new_entry;
+	struct stat data_stat;
+	const char *filename;
+	bool added = false;
+	uint8_t *data_ptr;
+	int data_fd, rc;
+	char *pos;
+
+	memcpy(name, line, FFS_PART_NAME_MAX + 1);
+	pos = strchr(name, SEPARATOR);
+	/* There is discussion to be had as to if we should bail here */
+	if (!pos) {
+		fprintf(stderr, "WARNING: Long partition name will get truncated to '%s'\n",
+				name);
+		name[FFS_PART_NAME_MAX] = '\0';
+	} else {
+		*pos = '\0';
+	}
+
+	line = advance_line(line);
+	if (!line || read_u32(line, &pbase)) {
+		fprintf(stderr, "Couldn't parse '%s' partition base address\n",
+				name);
+		return -1;
+	}
+
+	line = advance_line(line);
+	if (!line || read_u32(line, &psize)) {
+		fprintf(stderr, "Couldn't parse '%s' partition length\n",
+				name);
+		return -1;
+	}
+
+	line = advance_line(line);
+	if (!line || !advance_line(line)) {
+		fprintf(stderr, "Couldn't find '%s' partition flags\n",
+				name);
+		return -1;
+	}
+
+	rc = ffs_string_to_entry_user(line, advance_line(line) - 1 - line, &user);
+	if (rc) {
+		fprintf(stderr, "Couldn't parse '%s' partition flags\n",
+				name);
+		return -1;
+	}
+	line = advance_line(line);
+	/* Already checked return value */
+
+	rc = ffs_entry_new(name, pbase, psize, &new_entry);
+	if (rc) {
+		fprintf(stderr, "Invalid entry '%s' 0x%08x for 0x%08x\n",
+				name, pbase, psize);
+		return -1;
+	}
+
+	rc = ffs_entry_user_set(new_entry, &user);
+	if (rc) {
+		fprintf(stderr, "Couldn't set '%s' partition flags\n",
+				name);
+		ffs_entry_put(new_entry);
+		return -1;
+	}
+
+	if (has_flag(new_entry, FFS_MISCFLAGS_BACKUP)) {
+		rc = ffs_entry_set_act_size(new_entry, 0);
+		if (rc) {
+			fprintf(stderr, "Couldn't set '%s' partition actual size\n",
+					name);
+			ffs_entry_put(new_entry);
+			return -1;
+		}
+	}
+
+	if (!advance_line(line)) {
+		fprintf(stderr, "Missing TOC field for '%s' partition\n",
+				name);
+		ffs_entry_put(new_entry);
+		return -1;
+	}
+
+	while (*line != SEPARATOR) {
+		int toc = *(line++);
+
+		if (!isdigit(toc)) {
+			fprintf(stderr, "Bad TOC value %d (%c) for '%s' partition\n",
+					toc, toc, name);
+			ffs_entry_put(new_entry);
+			return -1;
+		}
+		toc -= '0';
+		if (!tocs[toc]) {
+			fprintf(stderr, "No TOC with ID %d for '%s' partition\n",
+					toc, name);
+			ffs_entry_put(new_entry);
+			return -1;
+		}
+		rc = ffs_entry_add(tocs[toc], new_entry);
+		if (rc) {
+			fprintf(stderr, "Couldn't add '%s' parition to TOC %d\n",
+					name, toc);
+			ffs_entry_put(new_entry);
+			return rc;
+		}
+		added = true;
+	}
+	if (!added) {
+		/*
+		 * They didn't specify a TOC in the TOC field, use
+		 * TOC@0 as the default
+		 */
+		rc = ffs_entry_add(tocs[0], new_entry);
+		if (rc) {
+			fprintf(stderr, "Couldn't add '%s' partition to default TOC: %d\n",
+					name, rc);
+			ffs_entry_put(new_entry);
+			return rc;
+		}
+	}
+	ffs_entry_put(new_entry);
+
+	if (*line != '\0' && *(line + 1) != '\0') {
+		filename = line + 1;
+		data_fd = open(filename, O_RDONLY);
+		if (data_fd == -1) {
+			fprintf(stderr, "Couldn't open file '%s' for '%s' partition "
+					"(%m)\n", filename, name);
+			return -1;
+		}
+
+		if (fstat(data_fd, &data_stat) == -1) {
+			fprintf(stderr, "Couldn't stat file '%s' for '%s' partition "
+				"(%m)\n", filename, name);
+			close(data_fd);
+			return -1;
+		}
+		pactual = data_stat.st_size;
+
+		/*
+		 * Sanity check that the file isn't too large for
+		 * partition
+		 */
+		if (pactual > psize) {
+			fprintf(stderr, "File '%s' for partition '%s' is too large\n",
+					filename, name);
+			close(data_fd);
+			return -1;
+		}
+
+		data_ptr = mmap(NULL, pactual, PROT_READ, MAP_SHARED, data_fd, 0);
+		if (!data_ptr) {
+			fprintf(stderr, "Couldn't mmap file '%s' for '%s' partition "
+				"(%m)\n", filename, name);
+			close(data_fd);
+			return -1;
+		}
+
+		rc = blocklevel_write(bl, pbase, data_ptr, pactual);
+		if (rc)
+			fprintf(stderr, "Couldn't write file '%s' for '%s' partition to PNOR "
+					"(%m)\n", filename, name);
+		munmap(data_ptr, pactual);
+		close(data_fd);
+	}
+
+	return 0;
+}
+
 static void print_version(void)
 {
 	printf("Open-Power FFS format tool %s\n", version);
@@ -77,20 +317,19 @@  static void print_help(const char *pname)
 
 int main(int argc, char *argv[])
 {
-	const char *pname = argv[0];
-	struct blocklevel_device *bl = NULL;
+	char *pnor = NULL, *input = NULL, line[MAX_LINE];
+	bool toc_created = false, bad_input = false;
 	uint32_t block_size = 0, block_count = 0;
-	bool bad_input = false;
-	char *pnor = NULL, *input = NULL;
-	struct ffs_hdr *new_hdr;
+	struct ffs_hdr *tocs[MAX_TOCS] = { 0 };
+	struct blocklevel_device *bl = NULL;
+	const char *pname = argv[0];
+	int line_number, rc, i;
 	FILE *in_file;
-	char line[MAX_LINE];
-	int rc;
 
 	while(1) {
 		struct option long_opts[] = {
-			{"block_size",	required_argument,	NULL,	's'},
 			{"block_count",	required_argument,	NULL,	'c'},
+			{"block_size",	required_argument,	NULL,	's'},
 			{"debug",	no_argument,	NULL,	'g'},
 			{"input",	required_argument,	NULL,	'i'},
 			{"pnor",	required_argument,	NULL,	'p'},
@@ -98,7 +337,7 @@  int main(int argc, char *argv[])
 		};
 		int c, oidx = 0;
 
-		c = getopt_long(argc, argv, "c:gi:p:s:", long_opts, &oidx);
+		c = getopt_long(argc, argv, "+:c:gi:p:s:", long_opts, &oidx);
 		if (c == EOF)
 			break;
 		switch(c) {
@@ -109,50 +348,55 @@  int main(int argc, char *argv[])
 			libflash_debug = true;
 			break;
 		case 'i':
+			free(input);
 			input = strdup(optarg);
+			if (!input)
+				fprintf(stderr, "Out of memory!\n");
 			break;
 		case 'p':
+			free(pnor);
 			pnor = strdup(optarg);
+			if (!pnor)
+				fprintf(stderr, "Out of memory!\n");
 			break;
 		case 's':
 			block_size = strtoul(optarg, NULL, 0);
 			break;
+		case ':':
+			fprintf(stderr, "Unrecognised option \"%s\" to '%c'\n",
+					optarg, optopt);
+			bad_input = true;
+			break;
+		case '?':
+			fprintf(stderr, "Unrecognised option '%c'\n", optopt);
+			bad_input = true;
+			break;
 		default:
-			exit(1);
+			fprintf(stderr , "Encountered unknown error parsing options\n");
+			bad_input = true;
 		}
 	}
 
-	if (!block_size || !block_count || !input || !pnor)
-		bad_input = true;
-
-	if (bad_input) {
+	if (bad_input || !block_size || !block_count || !input || !pnor) {
 		print_help(pname);
-		rc = 1;
-		goto out;
-	}
-
-	rc = ffs_hdr_new(block_size, block_count, NULL, &new_hdr);
-	if (rc) {
-		if (rc == FFS_ERR_BAD_SIZE) {
-			/* Well this check is a tad redudant now */
-			fprintf(stderr, "Bad parametres passed to libffs\n");
-		} else {
-			fprintf(stderr, "Error %d initialising new TOC\n", rc);
-		}
-		goto out;
+		return 1;
 	}
 
 	in_file = fopen(input, "r");
 	if (!in_file) {
-		rc = errno;
-		fprintf(stderr, "Couldn't open your input file %s because %s\n", input, strerror(errno));
-		goto out_free_hdr;
+		fprintf(stderr, "Couldn't open your input file %s: %m\n", input);
+		return 2;
 	}
 
+	/*
+	 * TODO: This won't create the file.
+	 * We should do this
+	 */
 	rc = arch_flash_init(&bl, pnor, true);
 	if (rc) {
 		fprintf(stderr, "Couldn't initialise architecture flash structures\n");
-		goto out_close_f;
+		fclose(in_file);
+		return 3;
 	}
 
 	/*
@@ -161,16 +405,14 @@  int main(int argc, char *argv[])
 	 */
 	rc = blocklevel_erase(bl, 0, block_size * block_count);
 	if (rc) {
-		fprintf(stderr, "Couldn't erase file\n");
-		goto out_close_bl;
+		fprintf(stderr, "Couldn't erase '%s' pnor file\n", pnor);
+		fclose(in_file);
+		return 4;
 	}
 
+	line_number = 0;
 	while (fgets(line, MAX_LINE, in_file) != NULL) {
-		struct ffs_entry *new_entry;
-		struct ffs_entry_user user = { 0 };
-		char *pos, *old_pos;
-		char *name, *endptr;
-		uint32_t pbase, psize, pactual = 0;
+		line_number++;
 
 		/* Inline comments in input file */
 		if (line[0] == '#')
@@ -179,180 +421,71 @@  int main(int argc, char *argv[])
 		if (line[strlen(line) - 1] == '\n')
 			line[strlen(line) - 1] = '\0';
 
-		pos = strchr(line, SEPARATOR);
-		if (!pos) {
-			fprintf(stderr, "Invalid input file format: Couldn't find name\n");
-			rc = -1;
-			goto out_close_bl;
-		}
-		*pos = '\0';
-		name = line;
-		/* There is discussion to be had as to if we should bail here */
-		if (pos - line > FFS_PART_NAME_MAX)
-			fprintf(stderr, "WARNING: Long partition '%s' name will get truncated\n",
-					line);
-
-		pos++;
-		old_pos = pos;
-		pos = strchr(pos, SEPARATOR);
-		if (!pos) {
-			fprintf(stderr, "Invalid input file format: Couldn't find base\n");
-			rc = -1;
-			goto out_close_bl;
-		}
-		*pos = '\0';
-		pbase = strtoul(old_pos, &endptr, 0);
-		if (*endptr != '\0') {
-			fprintf(stderr, "Invalid input file format: Couldn't parse "
-					"'%s' partition base address\n", name);
-			rc = -1;
-			goto out_close_bl;
-		}
-
-		pos++;
-		old_pos = pos;
-		pos = strchr(pos, SEPARATOR);
-		if (!pos) {
-			fprintf(stderr, "Invalid input file format: Couldn't find size\n");
-			rc = -1;
-			goto out_close_bl;
-		}
-		*pos = '\0';
-		psize = strtoul(old_pos, &endptr, 0);
-		if (*endptr != '\0') {
-			fprintf(stderr, "Invalid input file format: Couldn't parse "
-					"'%s' partition length\n", name);
-			rc = -1;
-			goto out_close_bl;
-		}
+		if (line[0] == '@') {
+			int toc_num = line[1];
+			rc = 5;
 
-		pos++;
-		while (*pos != '\0' && *pos != SEPARATOR) {
-			switch (*pos) {
-			case 'E':
-				user.datainteg |= FFS_ENRY_INTEG_ECC;
-				break;
-			case 'V':
-				user.vercheck |= FFS_VERCHECK_SHA512V;
-				break;
-			case 'I':
-				user.vercheck |= FFS_VERCHECK_SHA512EC;
-				break;
-			case 'P':
-				user.miscflags |= FFS_MISCFLAGS_PRESERVED;
-				break;
-			case 'R':
-				user.miscflags |= FFS_MISCFLAGS_READONLY;
-				break;
-			case 'F':
-				user.miscflags |= FFS_MISCFLAGS_REPROVISION;
-				break;
-			/* Not sure these are valid */
-			case 'B':
-				user.miscflags |= FFS_MISCFLAGS_BACKUP;
-				break;
-			default:
-				fprintf(stderr, "Unknown flag '%c'\n", *pos);
-				rc = -1;
-				goto out_close_bl;
+			if (!isdigit(toc_num)) {
+				fprintf(stderr, "Invalid TOC ID %d (%c)\n",
+						toc_num, toc_num);
+				goto parse_out;
 			}
-			pos++;
-		}
-
-		printf("Adding '%s' 0x%08x, 0x%08x\n", name, pbase, psize);
-		rc = ffs_entry_new(name, pbase, psize, &new_entry);
-		if (rc) {
-			fprintf(stderr, "Invalid entry '%s' 0x%08x for 0x%08x\n",
-					name, pbase, psize);
-			goto out_close_bl;
-		}
 
-		rc = ffs_entry_user_set(new_entry, &user);
-		if (rc) {
-			fprintf(stderr, "Invalid flag passed to ffs_entry_user_set\n");
-			goto out_while;
-		}
+			toc_num -= '0';
 
-		rc = ffs_entry_add(new_hdr, new_entry);
-		if (rc) {
-			fprintf(stderr, "Couldn't add entry '%s' 0x%08x for 0x%08x\n",
-					name, pbase, psize);
-			goto out_while;
-		}
+			if (line[2] != SEPARATOR) {
+				fprintf(stderr, "TOC ID too long\n");
+				goto parse_out;
+			}
 
-		if (*pos != '\0') {
-			struct stat data_stat;
-			int data_fd;
-			uint8_t *data_ptr;
-			char *data_fname = pos + 1;
-
-			data_fd = open(data_fname, O_RDONLY);
-			if (data_fd == -1) {
-				fprintf(stderr, "Couldn't open data file for partition '%s' (filename: %s)\n",
-						name, data_fname);
-				rc = -1;
-				goto out_while;
+			if (tocs[toc_num]) {
+				fprintf(stderr, "Duplicate TOC ID %d\n", toc_num);
+				goto parse_out;
 			}
 
-			if (fstat(data_fd, &data_stat) == -1) {
-				fprintf(stderr, "Couldn't stat data file for partition '%s': %s\n",
-						name, strerror(errno));
-				rc = -1;
-				goto out_if;
+			tocs[toc_num] = parse_toc(&line[3], block_size, block_count);
+			if (!tocs[toc_num])
+				goto parse_out;
+			toc_created = true;
+		} else {
+			if (!toc_created) {
+				fprintf(stderr, "WARNING: Attempting to parse a partition line without any TOCs created.\n");
+				fprintf(stderr, "         Generating a default TOC at zero\n");
+				rc = ffs_hdr_new(block_size, block_count, NULL, &tocs[0]);
+				if (rc) {
+					rc = 7;
+					fprintf(stderr, "Couldn't generate a default TOC at zero\n");
+					goto parse_out;
+				}
+				toc_created = true;
 			}
-			pactual = data_stat.st_size;
-
-			/*
-			 * Sanity check that the file isn't too large for
-			 * partition
-			 */
-			if (pactual > psize) {
-				fprintf(stderr, "Data file for partition '%s' is too large\n",
-						name);
-				rc = -1;
-				goto out_if;
+			rc = parse_entry(bl, tocs, line);
+			if (rc) {
+				rc = 6;
+				goto parse_out;
 			}
+		}
+	}
 
-			data_ptr = mmap(NULL, pactual, PROT_READ, MAP_SHARED, data_fd, 0);
-			if (!data_ptr) {
-				fprintf(stderr, "Couldn't mmap data file for partition '%s': %s\n",
-						name, strerror(errno));
-				rc = -1;
-				goto out_if;
+	for(i = 0; i < MAX_TOCS; i++) {
+		if (tocs[i]) {
+			rc = ffs_hdr_finalise(bl, tocs[i]);
+			if (rc) {
+				rc = 7;
+				fprintf(stderr, "Failed to write out TOC values\n");
+				break;
 			}
-
-			rc = blocklevel_write(bl, pbase, data_ptr, pactual);
-			if (rc)
-				fprintf(stderr, "Couldn't write data file for partition '%s' to pnor file:"
-					    " %s\n", name, strerror(errno));
-
-			munmap(data_ptr, pactual);
-out_if:
-			close(data_fd);
-			if (rc)
-				goto out_while;
-			/*
-			 * TODO: Update the actual size within the partition table.
-			 */
 		}
-
-		continue;
-out_while:
-		ffs_entry_put(new_entry);
-		goto out_close_bl;
 	}
 
-	rc = ffs_hdr_finalise(bl, new_hdr);
-	if (rc)
-		fprintf(stderr, "Failed to write out TOC values\n");
-
-out_close_bl:
+parse_out:
+	if (rc == 5 || rc == 6)
+		fprintf(stderr, "Failed to parse input file '%s' at line %d\n",
+				input, line_number);
 	arch_flash_close(bl, pnor);
-out_close_f:
 	fclose(in_file);
-out_free_hdr:
-	ffs_hdr_free(new_hdr);
-out:
+	for(i = 0; i < MAX_TOCS; i++)
+		ffs_hdr_free(tocs[i]);
 	free(input);
 	free(pnor);
 	return rc;
diff --git a/external/ffspart/test/files/03-tiny-pnor.in b/external/ffspart/test/files/03-tiny-pnor.in
index 3c02b029..90ad9c27 100644
--- a/external/ffspart/test/files/03-tiny-pnor.in
+++ b/external/ffspart/test/files/03-tiny-pnor.in
@@ -1,4 +1,4 @@ 
-ONE,0x00400,0x00000100,EV,/dev/zero
-TWO,0x00500,0x00000100,EF,/dev/zero
-THREE,0x600,0x00000100,EF,/dev/zero
-FOUR,0x0700,0x00000100,EF,/dev/zero
+ONE,0x00400,0x00000100,EV,,/dev/zero
+TWO,0x00500,0x00000100,EF,,/dev/zero
+THREE,0x600,0x00000100,EF,,/dev/zero
+FOUR,0x0700,0x00000100,EF,,/dev/zero
diff --git a/external/ffspart/test/files/03.1-tiny-pnor-backup.in b/external/ffspart/test/files/03.1-tiny-pnor-backup.in
deleted file mode 100644
index b5527503..00000000
--- a/external/ffspart/test/files/03.1-tiny-pnor-backup.in
+++ /dev/null
@@ -1,4 +0,0 @@ 
-ONE,0x00400,0x100,EV,/dev/zero
-TWO,0x00500,0x100,EF,/dev/zero
-THREE,0x600,0x100,EF,/dev/zero
-FOUR,0x0700,0x100,EF,/dev/zero
diff --git a/external/ffspart/test/files/03.1-tiny-pnor-backup.out b/external/ffspart/test/files/03.1-tiny-pnor-backup.out
deleted file mode 100644
index e173e9e75451d5359d97aca9e16e411bd255f0eb..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 3840
zcmWG=3<_ajU|<Ad79ef_Vm1hufgi|50RfJ|HwqGqN>BtL9G3q;0Azy9VTRBk<ERVz
z=XLh@`?;bU3bKe1YCjW*4N(B4P*gX7J%}Pi0>@yZ_0N!Se{>zJKmnNjP``teV7H$^
z09`xr{M9=Qe};GjxuS&tFuvgSgTn%1BK7Tmw_In3n}28!nv2<y><5Pht?b{qKzqHD
zqqBEtKzsls*@A8229mJ!2M!B}{nSr?EB9=E14?J3U^E0qLtr!nMnhmU1V%$(Xomo_
gApvSEff@`AKs?(11qK2(FxvhdZT}AK+>Ysb0KP^AFaQ7m

diff --git a/external/ffspart/test/files/04-tiny-pnor2.in b/external/ffspart/test/files/04-tiny-pnor2.in
index 34bfbde9..0369bf66 100644
--- a/external/ffspart/test/files/04-tiny-pnor2.in
+++ b/external/ffspart/test/files/04-tiny-pnor2.in
@@ -1,4 +1,4 @@ 
-ONE,0x00000300,0x00000100,EV,SEDCATCH_1
-TWO,0x00000400,0x00000100,EF,SEDCATCH_2
-THREE,0x00000500,0x00000100,EF,SEDCATCH_3
-FOUR,0x00000600,0x00000100,EF,SEDCATCH_4
+ONE,0x00000300,0x00000100,EV,,SEDCATCH_1
+TWO,0x00000400,0x00000100,EF,,SEDCATCH_2
+THREE,0x00000500,0x00000100,EF,,SEDCATCH_3
+FOUR,0x00000600,0x00000100,EF,,SEDCATCH_4
diff --git a/external/ffspart/test/files/05-hdr-overlap.in b/external/ffspart/test/files/05-hdr-overlap.in
index 0dd37116..8af94d2d 100644
--- a/external/ffspart/test/files/05-hdr-overlap.in
+++ b/external/ffspart/test/files/05-hdr-overlap.in
@@ -1,4 +1,4 @@ 
-ONE,0x00000200,0x00000100,EV,/dev/zero
-TWO,0x00000300,0x00000100,EF,/dev/zero
-THREE,0x00000400,0x00000100,EF,/dev/zero
-FOUR,0x00000500,0x00000100,EF,/dev/zero
+ONE,0x00000200,0x00000100,EV,,/dev/zero
+TWO,0x00000300,0x00000100,EF,,/dev/zero
+THREE,0x00000400,0x00000100,EF,,/dev/zero
+FOUR,0x00000500,0x00000100,EF,,/dev/zero
diff --git a/external/ffspart/test/files/05.1-hdr-overlap-backup.in b/external/ffspart/test/files/05.1-hdr-overlap-backup.in
deleted file mode 100644
index c6cf6e65..00000000
--- a/external/ffspart/test/files/05.1-hdr-overlap-backup.in
+++ /dev/null
@@ -1,3 +0,0 @@ 
-ONE,0x00000200,0x00000100,EV,/dev/zero
-TWO,0x00000300,0x00000100,EF,/dev/zero
-THREE,0x00000400,0x00000100,EF,/dev/zero
diff --git a/external/ffspart/test/files/06-small-flash.in b/external/ffspart/test/files/06-small-flash.in
index a4af6205..a717888b 100644
--- a/external/ffspart/test/files/06-small-flash.in
+++ b/external/ffspart/test/files/06-small-flash.in
@@ -1,5 +1,5 @@ 
-ONE,0x00000300,0x00000100,EV,/dev/zero
-TWO,0x00000400,0x00000100,EF,/dev/zero
-THREE,0x00000500,0x00000100,EF,/dev/zero
-FOUR,0x00000600,0x00000100,EF,/dev/zero
-FIVE,0x00000700,0x00000100,EF,/dev/zero
+ONE,0x00000300,0x00000100,EV,,/dev/zero
+TWO,0x00000400,0x00000100,EF,,/dev/zero
+THREE,0x00000500,0x00000100,EF,,/dev/zero
+FOUR,0x00000600,0x00000100,EF,,/dev/zero
+FIVE,0x00000700,0x00000100,EF,,/dev/zero
diff --git a/external/ffspart/test/files/07-big-files.in b/external/ffspart/test/files/07-big-files.in
index 34bfbde9..0369bf66 100644
--- a/external/ffspart/test/files/07-big-files.in
+++ b/external/ffspart/test/files/07-big-files.in
@@ -1,4 +1,4 @@ 
-ONE,0x00000300,0x00000100,EV,SEDCATCH_1
-TWO,0x00000400,0x00000100,EF,SEDCATCH_2
-THREE,0x00000500,0x00000100,EF,SEDCATCH_3
-FOUR,0x00000600,0x00000100,EF,SEDCATCH_4
+ONE,0x00000300,0x00000100,EV,,SEDCATCH_1
+TWO,0x00000400,0x00000100,EF,,SEDCATCH_2
+THREE,0x00000500,0x00000100,EF,,SEDCATCH_3
+FOUR,0x00000600,0x00000100,EF,,SEDCATCH_4
diff --git a/external/ffspart/test/files/08-small-files.in b/external/ffspart/test/files/08-small-files.in
index 34bfbde9..0369bf66 100644
--- a/external/ffspart/test/files/08-small-files.in
+++ b/external/ffspart/test/files/08-small-files.in
@@ -1,4 +1,4 @@ 
-ONE,0x00000300,0x00000100,EV,SEDCATCH_1
-TWO,0x00000400,0x00000100,EF,SEDCATCH_2
-THREE,0x00000500,0x00000100,EF,SEDCATCH_3
-FOUR,0x00000600,0x00000100,EF,SEDCATCH_4
+ONE,0x00000300,0x00000100,EV,,SEDCATCH_1
+TWO,0x00000400,0x00000100,EF,,SEDCATCH_2
+THREE,0x00000500,0x00000100,EF,,SEDCATCH_3
+FOUR,0x00000600,0x00000100,EF,,SEDCATCH_4
diff --git a/external/ffspart/test/files/10-bad-input.in b/external/ffspart/test/files/10-bad-input.in
index 6015a521..5c4c90ee 100644
--- a/external/ffspart/test/files/10-bad-input.in
+++ b/external/ffspart/test/files/10-bad-input.in
@@ -1,4 +1,4 @@ 
-ONE0x00000300,0x00000100,EV,/dev/zero
-TWO,0x00000400,0x00000100,EF,/dev/zero
-THREE,0x00000500,0x00000100,EF,/dev/zero
-FOUR,0x00000600,0x00000100,EF,/dev/zero
+ONE0x00000300,0x00000100,EV,,/dev/zero
+TWO,0x00000400,0x00000100,EF,,/dev/zero
+THREE,0x00000500,0x00000100,EF,,/dev/zero
+FOUR,0x00000600,0x00000100,EF,,/dev/zero
diff --git a/external/ffspart/test/files/11-long-name.in b/external/ffspart/test/files/11-long-name.in
index a194de0c..bd32ea89 100644
--- a/external/ffspart/test/files/11-long-name.in
+++ b/external/ffspart/test/files/11-long-name.in
@@ -1,4 +1,4 @@ 
-This_is_more_than_15_characters,0x00000300,0x00000100,EV,/dev/zero
-This_is_exactly,0x00000400,0x00000100,EF,/dev/zero
-This_is_one_le,0x00000500,0x00000100,EF,/dev/zero
-This_is_one_more,0x00000600,0x00000100,EF,/dev/zero
+This_is_more_than_15_characters,0x00000300,0x00000100,EV,,/dev/zero
+This_is_exactly,0x00000400,0x00000100,EF,,/dev/zero
+This_is_one_le,0x00000500,0x00000100,EF,,/dev/zero
+This_is_one_more,0x00000600,0x00000100,EF,,/dev/zero
diff --git a/external/ffspart/test/files/12-bad-numbers-base.in b/external/ffspart/test/files/12-bad-numbers-base.in
index f3de343a..8f6fd27a 100644
--- a/external/ffspart/test/files/12-bad-numbers-base.in
+++ b/external/ffspart/test/files/12-bad-numbers-base.in
@@ -1,4 +1,4 @@ 
-ONE,0xg0000300,0x00000100,EV,/dev/zero
-TWO,0x00000400,0x00000100,EF,/dev/zero
-THREE,0x00000500,0x00000100,EF,/dev/zero
-FOUR,0x00000600,0x00000100,EF,/dev/zero
+ONE,0xg0000300,0x00000100,EV,,/dev/zero
+TWO,0x00000400,0x00000100,EF,,/dev/zero
+THREE,0x00000500,0x00000100,EF,,/dev/zero
+FOUR,0x00000600,0x00000100,EF,,/dev/zero
diff --git a/external/ffspart/test/files/13-bad-numbers-size.in b/external/ffspart/test/files/13-bad-numbers-size.in
index 56fd5df1..b1dacc73 100644
--- a/external/ffspart/test/files/13-bad-numbers-size.in
+++ b/external/ffspart/test/files/13-bad-numbers-size.in
@@ -1,4 +1,4 @@ 
-ONE,0x00000300,0x00001g00,EV,/dev/zero
-TWO,0x00000400,0x00000100,EF,/dev/zero
-THREE,0x00000500,0x00000100,EF,/dev/zero
-FOUR,0x00000600,0x00000100,EF,/dev/zero
+ONE,0x00000300,0x00001g00,EV,,/dev/zero
+TWO,0x00000400,0x00000100,EF,,/dev/zero
+THREE,0x00000500,0x00000100,EF,,/dev/zero
+FOUR,0x00000600,0x00000100,EF,,/dev/zero
diff --git a/external/ffspart/test/files/14-bad-input-flags.in b/external/ffspart/test/files/14-bad-input-flags.in
index c483f57f..dcf18f24 100644
--- a/external/ffspart/test/files/14-bad-input-flags.in
+++ b/external/ffspart/test/files/14-bad-input-flags.in
@@ -1,4 +1,4 @@ 
-ONE,0x00000300,0x00000100,EVZ,/dev/zero
-TWO,0x00000400,0x00000100,EF,/dev/zero
-THREE,0x00000500,0x00000100,EF,/dev/zero
-FOUR,0x00000600,0x00000100,EF,/dev/zero
+ONE,0x00000300,0x00000100,EVZ,,/dev/zero
+TWO,0x00000400,0x00000100,EF,,/dev/zero
+THREE,0x00000500,0x00000100,EF,,/dev/zero
+FOUR,0x00000600,0x00000100,EF,,/dev/zero
diff --git a/external/ffspart/test/files/15-overlapping-partitions.in b/external/ffspart/test/files/15-overlapping-partitions.in
index 47c3837d..e496afa1 100644
--- a/external/ffspart/test/files/15-overlapping-partitions.in
+++ b/external/ffspart/test/files/15-overlapping-partitions.in
@@ -1,4 +1,4 @@ 
-ONE,0x00000300,0x00000100,EV,/dev/zero
-TWO,0x00000350,0x00000100,EF,/dev/zero
-THREE,0x00000500,0x00000100,EF,/dev/zero
-FOUR,0x00000600,0x00000100,EF,/dev/zero
+ONE,0x00000300,0x00000100,EV,,/dev/zero
+TWO,0x00000350,0x00000100,EF,,/dev/zero
+THREE,0x00000500,0x00000100,EF,,/dev/zero
+FOUR,0x00000600,0x00000100,EF,,/dev/zero
diff --git a/external/ffspart/test/results/01-param-sanity.err b/external/ffspart/test/results/01-param-sanity.err
index 7b8bb3ba..e69de29b 100644
--- a/external/ffspart/test/results/01-param-sanity.err
+++ b/external/ffspart/test/results/01-param-sanity.err
@@ -1 +0,0 @@ 
-Greater than two sides is not supported
diff --git a/external/ffspart/test/results/01-param-sanity.out b/external/ffspart/test/results/01-param-sanity.out
index 19eedc74..3ad0441d 100644
--- a/external/ffspart/test/results/01-param-sanity.out
+++ b/external/ffspart/test/results/01-param-sanity.out
@@ -11,11 +11,6 @@  Usage: ./ffspart [options] -s size -c num -i layout_file -p pnor_file ...
 	-i, --input=file
 		File containing the required partition data
 
-	-o, --order=( ADB | ABD )
-		Ordering of the TOC, Data and Backup TOC. Currently only ADB (default)
-		is supported
 	-p, --pnor=file
 		Output file to write data
 
-	-t, --sides=( 1 | 2 )
-		Number of sides to the flash (Default: 1)
diff --git a/external/ffspart/test/results/01.1-param-sanity.err b/external/ffspart/test/results/01.1-param-sanity.err
new file mode 100644
index 00000000..e69de29b
diff --git a/external/ffspart/test/results/02-param-sides.out b/external/ffspart/test/results/01.1-param-sanity.out
similarity index 67%
rename from external/ffspart/test/results/02-param-sides.out
rename to external/ffspart/test/results/01.1-param-sanity.out
index 19eedc74..3ad0441d 100644
--- a/external/ffspart/test/results/02-param-sides.out
+++ b/external/ffspart/test/results/01.1-param-sanity.out
@@ -11,11 +11,6 @@  Usage: ./ffspart [options] -s size -c num -i layout_file -p pnor_file ...
 	-i, --input=file
 		File containing the required partition data
 
-	-o, --order=( ADB | ABD )
-		Ordering of the TOC, Data and Backup TOC. Currently only ADB (default)
-		is supported
 	-p, --pnor=file
 		Output file to write data
 
-	-t, --sides=( 1 | 2 )
-		Number of sides to the flash (Default: 1)
diff --git a/external/ffspart/test/results/02-param-sides.err b/external/ffspart/test/results/02-param-sides.err
deleted file mode 100644
index faf9d9ff..00000000
--- a/external/ffspart/test/results/02-param-sides.err
+++ /dev/null
@@ -1 +0,0 @@ 
-Invalid block_count 1 for sides 2
diff --git a/external/ffspart/test/results/05-hdr-overlap.err b/external/ffspart/test/results/05-hdr-overlap.err
index 55f07c6c..ff8aca20 100644
--- a/external/ffspart/test/results/05-hdr-overlap.err
+++ b/external/ffspart/test/results/05-hdr-overlap.err
@@ -1,2 +1,5 @@ 
+WARNING: Attempting to parse a partition line without any TOCs created.
+         Generating a default TOC at zero
 Adding partition 'THREE' would cause partition 'ONE' at 0x00000200 to overlap with the header
-Couldn't add entry 'THREE' 0x00000400 for 0x00000100
+Couldn't add 'THREE' partition to default TOC: 107
+Failed to parse input file 'FILE' at line 3
diff --git a/external/ffspart/test/results/05-hdr-overlap.out b/external/ffspart/test/results/05-hdr-overlap.out
index 2dbf5a43..e69de29b 100644
--- a/external/ffspart/test/results/05-hdr-overlap.out
+++ b/external/ffspart/test/results/05-hdr-overlap.out
@@ -1,3 +0,0 @@ 
-Adding 'ONE' 0x00000200, 0x00000100
-Adding 'TWO' 0x00000300, 0x00000100
-Adding 'THREE' 0x00000400, 0x00000100
diff --git a/external/ffspart/test/results/05.1-hdr-overlap-backup.err b/external/ffspart/test/results/05.1-hdr-overlap-backup.err
deleted file mode 100644
index 55f07c6c..00000000
--- a/external/ffspart/test/results/05.1-hdr-overlap-backup.err
+++ /dev/null
@@ -1,2 +0,0 @@ 
-Adding partition 'THREE' would cause partition 'ONE' at 0x00000200 to overlap with the header
-Couldn't add entry 'THREE' 0x00000400 for 0x00000100
diff --git a/external/ffspart/test/results/05.1-hdr-overlap-backup.out b/external/ffspart/test/results/05.1-hdr-overlap-backup.out
deleted file mode 100644
index dbcdcb1d..00000000
--- a/external/ffspart/test/results/05.1-hdr-overlap-backup.out
+++ /dev/null
@@ -1,4 +0,0 @@ 
-Adding 'ONE' 0x00000200, 0x00000100
-Adding 'TWO' 0x00000300, 0x00000100
-Adding 'THREE' 0x00000400, 0x00000100
-Freeing hdr
diff --git a/external/ffspart/test/results/06-small-flash.err b/external/ffspart/test/results/06-small-flash.err
index a95149bd..a5316a90 100644
--- a/external/ffspart/test/results/06-small-flash.err
+++ b/external/ffspart/test/results/06-small-flash.err
@@ -1 +1,4 @@ 
-Couldn't add entry 'TWO' 0x00000400 for 0x00000100
+WARNING: Attempting to parse a partition line without any TOCs created.
+         Generating a default TOC at zero
+Couldn't add 'TWO' partition to default TOC: 108
+Failed to parse input file 'FILE' at line 2
diff --git a/external/ffspart/test/results/06-small-flash.out b/external/ffspart/test/results/06-small-flash.out
index 25214672..e69de29b 100644
--- a/external/ffspart/test/results/06-small-flash.out
+++ b/external/ffspart/test/results/06-small-flash.out
@@ -1,2 +0,0 @@ 
-Adding 'ONE' 0x00000300, 0x00000100
-Adding 'TWO' 0x00000400, 0x00000100
diff --git a/external/ffspart/test/results/07-big-files.err b/external/ffspart/test/results/07-big-files.err
index f179a53d..083bad20 100644
--- a/external/ffspart/test/results/07-big-files.err
+++ b/external/ffspart/test/results/07-big-files.err
@@ -1 +1,4 @@ 
-Data file for partition 'ONE' is too large
+WARNING: Attempting to parse a partition line without any TOCs created.
+         Generating a default TOC at zero
+File 'FILE_ONE' for partition 'ONE' is too large
+Failed to parse input file 'FILE' at line 1
diff --git a/external/ffspart/test/results/07-big-files.out b/external/ffspart/test/results/07-big-files.out
index 0555381e..e69de29b 100644
--- a/external/ffspart/test/results/07-big-files.out
+++ b/external/ffspart/test/results/07-big-files.out
@@ -1 +0,0 @@ 
-Adding 'ONE' 0x00000300, 0x00000100
diff --git a/external/ffspart/test/results/08-small-files.err b/external/ffspart/test/results/08-small-files.err
index e69de29b..c902b642 100644
--- a/external/ffspart/test/results/08-small-files.err
+++ b/external/ffspart/test/results/08-small-files.err
@@ -0,0 +1,2 @@ 
+WARNING: Attempting to parse a partition line without any TOCs created.
+         Generating a default TOC at zero
diff --git a/external/ffspart/test/results/08-small-files.out b/external/ffspart/test/results/08-small-files.out
index fdf70bf8..e69de29b 100644
--- a/external/ffspart/test/results/08-small-files.out
+++ b/external/ffspart/test/results/08-small-files.out
@@ -1,4 +0,0 @@ 
-Adding 'ONE' 0x00000300, 0x00000100
-Adding 'TWO' 0x00000400, 0x00000100
-Adding 'THREE' 0x00000500, 0x00000100
-Adding 'FOUR' 0x00000600, 0x00000100
diff --git a/external/ffspart/test/results/10-bad-input.err b/external/ffspart/test/results/10-bad-input.err
index 08d2fcff..01c43d81 100644
--- a/external/ffspart/test/results/10-bad-input.err
+++ b/external/ffspart/test/results/10-bad-input.err
@@ -1 +1,4 @@ 
-Invalid input file format: Couldn't parse 'ONE0x00000300' partition length
+WARNING: Attempting to parse a partition line without any TOCs created.
+         Generating a default TOC at zero
+Couldn't parse 'ONE0x00000300' partition length
+Failed to parse input file 'FILE' at line 1
diff --git a/external/ffspart/test/results/11-long-name.err b/external/ffspart/test/results/11-long-name.err
index 824062ec..cf8dcc32 100644
--- a/external/ffspart/test/results/11-long-name.err
+++ b/external/ffspart/test/results/11-long-name.err
@@ -1,2 +1,4 @@ 
-WARNING: Long partition 'This_is_more_than_15_characters' name will get truncated
-WARNING: Long partition 'This_is_one_more' name will get truncated
+WARNING: Attempting to parse a partition line without any TOCs created.
+         Generating a default TOC at zero
+WARNING: Long partition name will get truncated to 'This_is_more_tha'
+WARNING: Long partition name will get truncated to 'This_is_one_more'
diff --git a/external/ffspart/test/results/11-long-name.out b/external/ffspart/test/results/11-long-name.out
index 2d7dcb32..e69de29b 100644
--- a/external/ffspart/test/results/11-long-name.out
+++ b/external/ffspart/test/results/11-long-name.out
@@ -1,4 +0,0 @@ 
-Adding 'This_is_more_than_15_characters' 0x00000300, 0x00000100
-Adding 'This_is_exactly' 0x00000400, 0x00000100
-Adding 'This_is_one_le' 0x00000500, 0x00000100
-Adding 'This_is_one_more' 0x00000600, 0x00000100
diff --git a/external/ffspart/test/results/12-bad-numbers-base.err b/external/ffspart/test/results/12-bad-numbers-base.err
index 7312b034..cdd836ea 100644
--- a/external/ffspart/test/results/12-bad-numbers-base.err
+++ b/external/ffspart/test/results/12-bad-numbers-base.err
@@ -1 +1,4 @@ 
-Invalid input file format: Couldn't parse 'ONE' partition base address
+WARNING: Attempting to parse a partition line without any TOCs created.
+         Generating a default TOC at zero
+Couldn't parse 'ONE' partition base address
+Failed to parse input file 'FILE' at line 1
diff --git a/external/ffspart/test/results/13-bad-numbers-size.err b/external/ffspart/test/results/13-bad-numbers-size.err
index 592fec20..19078d5d 100644
--- a/external/ffspart/test/results/13-bad-numbers-size.err
+++ b/external/ffspart/test/results/13-bad-numbers-size.err
@@ -1 +1,4 @@ 
-Invalid input file format: Couldn't parse 'ONE' partition length
+WARNING: Attempting to parse a partition line without any TOCs created.
+         Generating a default TOC at zero
+Couldn't parse 'ONE' partition length
+Failed to parse input file 'FILE' at line 1
diff --git a/external/ffspart/test/results/14-bad-input-flags.err b/external/ffspart/test/results/14-bad-input-flags.err
index fecdb6ea..613525c3 100644
--- a/external/ffspart/test/results/14-bad-input-flags.err
+++ b/external/ffspart/test/results/14-bad-input-flags.err
@@ -1 +1,4 @@ 
-Unknown flag 'Z'
+WARNING: Attempting to parse a partition line without any TOCs created.
+         Generating a default TOC at zero
+Couldn't parse 'ONE' partition flags
+Failed to parse input file 'FILE' at line 1
diff --git a/external/ffspart/test/results/15-overlapping-partitions.err b/external/ffspart/test/results/15-overlapping-partitions.err
index d92f443e..c81d3c0e 100644
--- a/external/ffspart/test/results/15-overlapping-partitions.err
+++ b/external/ffspart/test/results/15-overlapping-partitions.err
@@ -1 +1,4 @@ 
-Couldn't add entry 'TWO' 0x00000350 for 0x00000100
+WARNING: Attempting to parse a partition line without any TOCs created.
+         Generating a default TOC at zero
+Couldn't add 'TWO' partition to default TOC: 107
+Failed to parse input file 'FILE' at line 2
diff --git a/external/ffspart/test/results/15-overlapping-partitions.out b/external/ffspart/test/results/15-overlapping-partitions.out
index 04e04c30..e69de29b 100644
--- a/external/ffspart/test/results/15-overlapping-partitions.out
+++ b/external/ffspart/test/results/15-overlapping-partitions.out
@@ -1,2 +0,0 @@ 
-Adding 'ONE' 0x00000300, 0x00000100
-Adding 'TWO' 0x00000350, 0x00000100
diff --git a/external/ffspart/test/tests/01-param-sanity b/external/ffspart/test/tests/01-param-sanity
index 28acf511..d6373600 100644
--- a/external/ffspart/test/tests/01-param-sanity
+++ b/external/ffspart/test/tests/01-param-sanity
@@ -1,10 +1,6 @@ 
 #! /bin/sh
 
-#This test has become a little redundant now.
-#TODO Do more sanity checking
-return 0
-
-run_binary "./ffspart" "-s 1 -c 3 -i /dev/null -p /dev/null"
+run_binary "./ffspart" "-c 3 -i /dev/null -p /dev/null"
 if [ "$?" -ne 1 ] ; then
 	fail_test
 fi
diff --git a/external/ffspart/test/tests/01.1-param-sanity b/external/ffspart/test/tests/01.1-param-sanity
new file mode 100644
index 00000000..1ce1f906
--- /dev/null
+++ b/external/ffspart/test/tests/01.1-param-sanity
@@ -0,0 +1,12 @@ 
+#! /bin/sh
+
+run_binary "./ffspart" "-s 1 -i /dev/null -p /dev/null"
+if [ "$?" -ne 1 ] ; then
+	fail_test
+fi
+
+strip_version_from_result "ffspart"
+
+diff_with_result
+
+pass_test
diff --git a/external/ffspart/test/tests/02-param-sides b/external/ffspart/test/tests/02-param-sides
deleted file mode 100644
index 17a2461e..00000000
--- a/external/ffspart/test/tests/02-param-sides
+++ /dev/null
@@ -1,16 +0,0 @@ 
-#! /bin/sh
-
-#The parameter has been removed
-#TODO Something clever with this test
-return 0
-
-run_binary "./ffspart" "-s 1 -c 1 -i /dev/null -p /dev/null"
-if [ "$?" -ne 1 ] ; then
-	fail_test
-fi
-
-strip_version_from_result "ffspart"
-
-diff_with_result
-
-pass_test
diff --git a/external/ffspart/test/tests/03.1-tiny-pnor-backup b/external/ffspart/test/tests/03.1-tiny-pnor-backup
deleted file mode 100644
index 8fa8d4e4..00000000
--- a/external/ffspart/test/tests/03.1-tiny-pnor-backup
+++ /dev/null
@@ -1,19 +0,0 @@ 
-#! /bin/sh
-
-#The backup partition flag is gone
-#disable this test temporarily
-return 0
-
-touch $DATA_DIR/$CUR_TEST.gen
-
-run_binary "./ffspart" "-b -s 0x100 -c 15 -i $DATA_DIR/$CUR_TEST.in -p $DATA_DIR/$CUR_TEST.gen"
-if [ "$?" -ne 0 ] ; then
-	fail_test
-fi
-
-if ! cmp -n $((0x100)) $DATA_DIR/$CUR_TEST.out $DATA_DIR/$CUR_TEST.gen ; then
-	echo "Output differs"
-	fail_test
-fi
-
-pass_test
diff --git a/external/ffspart/test/tests/05-hdr-overlap b/external/ffspart/test/tests/05-hdr-overlap
index 2fa050b1..39a1a140 100644
--- a/external/ffspart/test/tests/05-hdr-overlap
+++ b/external/ffspart/test/tests/05-hdr-overlap
@@ -3,13 +3,12 @@ 
 touch $DATA_DIR/$CUR_TEST.gen
 
 run_binary "./ffspart" "-s 0x100 -c 10 -i $DATA_DIR/$CUR_TEST.in -p $DATA_DIR/$CUR_TEST.gen"
-#expect this error code, which is FFS_ERR_BAD_PART_BASE becase we're
-#going to have too many partitions for header to fit before the first
-#partition
-if [ "$?" -ne 107 ] ; then
+if [ "$?" -ne 6 ] ; then
 	fail_test
 fi
 
+sed -i "s|$DATA_DIR/$CUR_TEST.in|FILE|" "$STDERR_OUT"
+
 diff_with_result
 
 pass_test
diff --git a/external/ffspart/test/tests/05.1-hdr-overlap-backup b/external/ffspart/test/tests/05.1-hdr-overlap-backup
deleted file mode 100644
index 0cbd9fa4..00000000
--- a/external/ffspart/test/tests/05.1-hdr-overlap-backup
+++ /dev/null
@@ -1,19 +0,0 @@ 
-#! /bin/sh
-
-#The backup partition flag is gone
-#disable this test temporarily
-return 0
-
-touch $DATA_DIR/$CUR_TEST.gen
-
-run_binary "./ffspart" "-s 0x100 -c 10 -i $DATA_DIR/$CUR_TEST.in -p $DATA_DIR/$CUR_TEST.gen"
-#expect this error code, which is FFS_ERR_BAD_PART_BASE becase we're
-#going to have too many partitions for header to fit before the first
-#partition
-if [ "$?" -ne 107 ] ; then
-	fail_test
-fi
-
-diff_with_result
-
-pass_test
diff --git a/external/ffspart/test/tests/06-small-flash b/external/ffspart/test/tests/06-small-flash
index b49f4578..7c41e33f 100644
--- a/external/ffspart/test/tests/06-small-flash
+++ b/external/ffspart/test/tests/06-small-flash
@@ -2,11 +2,12 @@ 
 touch $DATA_DIR/$CUR_TEST.gen
 
 run_binary "./ffspart" "-s 0x100 -c 4 -i $DATA_DIR/$CUR_TEST.in -p $DATA_DIR/$CUR_TEST.gen"
-#Expect FFS_ERR_BAD_PART_SIZE because the flash is too small
-if [ "$?" -ne 108 ] ; then
+if [ "$?" -ne 6 ] ; then
 	fail_test
 fi
 
+sed -i "s|$DATA_DIR/$CUR_TEST.in|FILE|" "$STDERR_OUT"
+
 diff_with_result
 
 pass_test
diff --git a/external/ffspart/test/tests/07-big-files b/external/ffspart/test/tests/07-big-files
index 2381824f..f7a0064d 100644
--- a/external/ffspart/test/tests/07-big-files
+++ b/external/ffspart/test/tests/07-big-files
@@ -17,6 +17,10 @@  if [ "$?" -eq 0 ] ; then
 	fail_test
 fi
 
+sed -i "s|$DATA_DIR/$CUR_TEST.1|FILE_ONE|" "$STDERR_OUT"
+
+sed -i "s|$DATA_DIR/$CUR_TEST.in|FILE|" "$STDERR_OUT"
+
 diff_with_result
 
 pass_test
diff --git a/external/ffspart/test/tests/10-bad-input b/external/ffspart/test/tests/10-bad-input
index e2f418ce..d7c43326 100644
--- a/external/ffspart/test/tests/10-bad-input
+++ b/external/ffspart/test/tests/10-bad-input
@@ -6,6 +6,8 @@  if [ "$?" -eq 0 ] ; then
 	fail_test
 fi
 
+sed -i "s|$DATA_DIR/$CUR_TEST.in|FILE|" "$STDERR_OUT"
+
 diff_with_result
 
 pass_test
diff --git a/external/ffspart/test/tests/12-bad-numbers-base b/external/ffspart/test/tests/12-bad-numbers-base
index e2f418ce..d7c43326 100644
--- a/external/ffspart/test/tests/12-bad-numbers-base
+++ b/external/ffspart/test/tests/12-bad-numbers-base
@@ -6,6 +6,8 @@  if [ "$?" -eq 0 ] ; then
 	fail_test
 fi
 
+sed -i "s|$DATA_DIR/$CUR_TEST.in|FILE|" "$STDERR_OUT"
+
 diff_with_result
 
 pass_test
diff --git a/external/ffspart/test/tests/13-bad-numbers-size b/external/ffspart/test/tests/13-bad-numbers-size
index e2f418ce..d7c43326 100644
--- a/external/ffspart/test/tests/13-bad-numbers-size
+++ b/external/ffspart/test/tests/13-bad-numbers-size
@@ -6,6 +6,8 @@  if [ "$?" -eq 0 ] ; then
 	fail_test
 fi
 
+sed -i "s|$DATA_DIR/$CUR_TEST.in|FILE|" "$STDERR_OUT"
+
 diff_with_result
 
 pass_test
diff --git a/external/ffspart/test/tests/14-bad-input-flags b/external/ffspart/test/tests/14-bad-input-flags
index e2f418ce..d7c43326 100644
--- a/external/ffspart/test/tests/14-bad-input-flags
+++ b/external/ffspart/test/tests/14-bad-input-flags
@@ -6,6 +6,8 @@  if [ "$?" -eq 0 ] ; then
 	fail_test
 fi
 
+sed -i "s|$DATA_DIR/$CUR_TEST.in|FILE|" "$STDERR_OUT"
+
 diff_with_result
 
 pass_test
diff --git a/external/ffspart/test/tests/15-overlapping-partitions b/external/ffspart/test/tests/15-overlapping-partitions
index 26c24d00..6d85748d 100644
--- a/external/ffspart/test/tests/15-overlapping-partitions
+++ b/external/ffspart/test/tests/15-overlapping-partitions
@@ -2,10 +2,12 @@ 
 touch $DATA_DIR/$CUR_TEST.gen
 
 run_binary "./ffspart" "-s 0x100 -c 10 -i $DATA_DIR/$CUR_TEST.in -p $DATA_DIR/$CUR_TEST.gen"
-if [ "$?" -ne 107 ] ; then
+if [ "$?" -ne 6 ] ; then
 	fail_test
 fi
 
+sed -i "s|$DATA_DIR/$CUR_TEST.in|FILE|" "$STDERR_OUT"
+
 diff_with_result
 
 pass_test
diff --git a/external/pflash/test/files/01-info.ffs b/external/pflash/test/files/01-info.ffs
index 517dc47b..a22143a3 100644
--- a/external/pflash/test/files/01-info.ffs
+++ b/external/pflash/test/files/01-info.ffs
@@ -1,4 +1,4 @@ 
-ONE,0x00000300,0x00000100,EV,/dev/zero
-TWO,0x00000400,0x00000100,EF,/dev/zero
-THREE,0x00000500,0x00000100,EF,/dev/zero
-FOUR,0x00000600,0x00000100,EF,/dev/zero
+ONE,0x00000300,0x00000100,EV,,/dev/zero
+TWO,0x00000400,0x00000100,EF,,/dev/zero
+THREE,0x00000500,0x00000100,EF,,/dev/zero
+FOUR,0x00000600,0x00000100,EF,,/dev/zero
diff --git a/external/pflash/test/files/02-erase.ffs b/external/pflash/test/files/02-erase.ffs
index 7efcd717..ff64d4e6 100644
--- a/external/pflash/test/files/02-erase.ffs
+++ b/external/pflash/test/files/02-erase.ffs
@@ -1,4 +1,4 @@ 
-ONE,0x00000300,0x00000100,EV,/dev/urandom
-TWO,0x00000400,0x00000100,EF,/dev/urandom
-THREE,0x00000500,0x00000100,EF,/dev/urandom
-FOUR,0x00000600,0x00000100,EF,/dev/urandom
+ONE,0x00000300,0x00000100,EV,,/dev/urandom
+TWO,0x00000400,0x00000100,EF,,/dev/urandom
+THREE,0x00000500,0x00000100,EF,,/dev/urandom
+FOUR,0x00000600,0x00000100,EF,,/dev/urandom
diff --git a/external/pflash/test/files/03-erase-parts.ffs b/external/pflash/test/files/03-erase-parts.ffs
index 7efcd717..ff64d4e6 100644
--- a/external/pflash/test/files/03-erase-parts.ffs
+++ b/external/pflash/test/files/03-erase-parts.ffs
@@ -1,4 +1,4 @@ 
-ONE,0x00000300,0x00000100,EV,/dev/urandom
-TWO,0x00000400,0x00000100,EF,/dev/urandom
-THREE,0x00000500,0x00000100,EF,/dev/urandom
-FOUR,0x00000600,0x00000100,EF,/dev/urandom
+ONE,0x00000300,0x00000100,EV,,/dev/urandom
+TWO,0x00000400,0x00000100,EF,,/dev/urandom
+THREE,0x00000500,0x00000100,EF,,/dev/urandom
+FOUR,0x00000600,0x00000100,EF,,/dev/urandom
diff --git a/external/pflash/test/files/04-program-rand.ffs b/external/pflash/test/files/04-program-rand.ffs
index 7efcd717..ff64d4e6 100644
--- a/external/pflash/test/files/04-program-rand.ffs
+++ b/external/pflash/test/files/04-program-rand.ffs
@@ -1,4 +1,4 @@ 
-ONE,0x00000300,0x00000100,EV,/dev/urandom
-TWO,0x00000400,0x00000100,EF,/dev/urandom
-THREE,0x00000500,0x00000100,EF,/dev/urandom
-FOUR,0x00000600,0x00000100,EF,/dev/urandom
+ONE,0x00000300,0x00000100,EV,,/dev/urandom
+TWO,0x00000400,0x00000100,EF,,/dev/urandom
+THREE,0x00000500,0x00000100,EF,,/dev/urandom
+FOUR,0x00000600,0x00000100,EF,,/dev/urandom
diff --git a/external/pflash/test/files/05-bad-numbers.ffs b/external/pflash/test/files/05-bad-numbers.ffs
index 7efcd717..ff64d4e6 100644
--- a/external/pflash/test/files/05-bad-numbers.ffs
+++ b/external/pflash/test/files/05-bad-numbers.ffs
@@ -1,4 +1,4 @@ 
-ONE,0x00000300,0x00000100,EV,/dev/urandom
-TWO,0x00000400,0x00000100,EF,/dev/urandom
-THREE,0x00000500,0x00000100,EF,/dev/urandom
-FOUR,0x00000600,0x00000100,EF,/dev/urandom
+ONE,0x00000300,0x00000100,EV,,/dev/urandom
+TWO,0x00000400,0x00000100,EF,,/dev/urandom
+THREE,0x00000500,0x00000100,EF,,/dev/urandom
+FOUR,0x00000600,0x00000100,EF,,/dev/urandom
diff --git a/external/pflash/test/files/06-miscprint.ffs b/external/pflash/test/files/06-miscprint.ffs
index 8f916f39..160ed51f 100644
--- a/external/pflash/test/files/06-miscprint.ffs
+++ b/external/pflash/test/files/06-miscprint.ffs
@@ -1,4 +1,4 @@ 
-PRESERVED,0x00300,0x100,P,/dev/zero
-READONLY,0x000400,0x100,R,/dev/zero
-REPROVISION,0x500,0x100,F,/dev/zero
-BACKUP,0x00000600,0x100,B,/dev/zero
+PRESERVED,0x00300,0x100,P,,/dev/zero
+READONLY,0x000400,0x100,R,,/dev/zero
+REPROVISION,0x500,0x100,F,,/dev/zero
+BACKUP,0x00000600,0x100,B,,/dev/zero
diff --git a/external/pflash/test/results/06-miscprint.out b/external/pflash/test/results/06-miscprint.out
index e90976d6..6d3377f1 100644
--- a/external/pflash/test/results/06-miscprint.out
+++ b/external/pflash/test/results/06-miscprint.out
@@ -30,7 +30,7 @@  Name:
 BACKUP (ID=04)
 
 Start       End         Actual    
-0x00000600  0x00000700  0x00000100
+0x00000600  0x00000700  0x00000000
 
 Flags:
 BACKUP [B]
diff --git a/libflash/libffs.c b/libflash/libffs.c
index 5accf1ff..a1418f4f 100644
--- a/libflash/libffs.c
+++ b/libflash/libffs.c
@@ -562,8 +562,11 @@  int ffs_entry_add(struct ffs_hdr *hdr, struct ffs_entry *entry)
 	uint32_t smallest_base;
 	int i;
 
+	FL_DBG("LIBFFS: Adding '%s' at 0x%08x..0x%08x\n",
+		entry->name, entry->base, entry->base + entry->size);
+
 	if (hdr->count == 0) {
-		FL_DBG("Adding an entry to an empty header\n");
+		FL_DBG("LIBFFS: Adding an entry to an empty header\n");
 		hdr->entries[hdr->count++] = entry;
 	}
 	if (entry->base + entry->size > hdr->block_size * hdr->block_count)