bloblist: Allow custom alignment for blobs

Some blobs need a larger alignment than the default. For example, ACPI
tables often start at a 4KB boundary. Add support for this.

Update the size of the test blob to allow these larger records.

Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/common/bloblist.c b/common/bloblist.c
index 173f28d..33b5862 100644
--- a/common/bloblist.c
+++ b/common/bloblist.c
@@ -83,18 +83,25 @@
 	return NULL;
 }
 
-static int bloblist_addrec(uint tag, int size, struct bloblist_rec **recp)
+static int bloblist_addrec(uint tag, int size, int align,
+			   struct bloblist_rec **recp)
 {
 	struct bloblist_hdr *hdr = gd->bloblist;
 	struct bloblist_rec *rec;
 	int data_start, new_alloced;
 
+	if (!align)
+		align = BLOBLIST_ALIGN;
+
 	/* Figure out where the new data will start */
-	data_start = hdr->alloced + sizeof(*rec);
-	data_start = ALIGN(data_start, BLOBLIST_ALIGN);
+	data_start = map_to_sysmem(hdr) + hdr->alloced + sizeof(*rec);
+
+	/* Align the address and then calculate the offset from ->alloced */
+	data_start = ALIGN(data_start, align) - map_to_sysmem(hdr);
 
 	/* Calculate the new allocated total */
-	new_alloced = data_start + ALIGN(size, BLOBLIST_ALIGN);
+	new_alloced = data_start + ALIGN(size, align);
+
 	if (new_alloced >= hdr->size) {
 		log(LOGC_BLOBLIST, LOGL_ERR,
 		    "Failed to allocate %x bytes size=%x, need size=%x\n",
@@ -117,7 +124,8 @@
 	return 0;
 }
 
-static int bloblist_ensurerec(uint tag, struct bloblist_rec **recp, int size)
+static int bloblist_ensurerec(uint tag, struct bloblist_rec **recp, int size,
+			      int align)
 {
 	struct bloblist_rec *rec;
 
@@ -130,7 +138,7 @@
 	} else {
 		int ret;
 
-		ret = bloblist_addrec(tag, size, &rec);
+		ret = bloblist_addrec(tag, size, align, &rec);
 		if (ret)
 			return ret;
 	}
@@ -152,22 +160,22 @@
 	return (void *)rec + rec->hdr_size;
 }
 
-void *bloblist_add(uint tag, int size)
+void *bloblist_add(uint tag, int size, int align)
 {
 	struct bloblist_rec *rec;
 
-	if (bloblist_addrec(tag, size, &rec))
+	if (bloblist_addrec(tag, size, align, &rec))
 		return NULL;
 
 	return (void *)rec + rec->hdr_size;
 }
 
-int bloblist_ensure_size(uint tag, int size, void **blobp)
+int bloblist_ensure_size(uint tag, int size, int align, void **blobp)
 {
 	struct bloblist_rec *rec;
 	int ret;
 
-	ret = bloblist_ensurerec(tag, &rec, size);
+	ret = bloblist_ensurerec(tag, &rec, size, align);
 	if (ret)
 		return ret;
 	*blobp = (void *)rec + rec->hdr_size;
@@ -179,7 +187,7 @@
 {
 	struct bloblist_rec *rec;
 
-	if (bloblist_ensurerec(tag, &rec, size))
+	if (bloblist_ensurerec(tag, &rec, size, 0))
 		return NULL;
 
 	return (void *)rec + rec->hdr_size;
@@ -190,7 +198,7 @@
 	struct bloblist_rec *rec;
 	int ret;
 
-	ret = bloblist_ensurerec(tag, &rec, *sizep);
+	ret = bloblist_ensurerec(tag, &rec, *sizep, 0);
 	if (ret == -ESPIPE)
 		*sizep = rec->size;
 	else if (ret)