Move boot params update to the boot_flow module.

Not all boot flows want to be doing updates so leave that decision to
the module responsible for coordinating the boot details.

There is likely a cleaner or more configurable way to acheive this but
the goal for the moment is to isolate the current boot flows that we
have.

Change-Id: Ib0a1d43293e0a70bea897fd4f4695515627bf150
diff --git a/src/boot_flow/android.c b/src/boot_flow/android.c
index 73797e9..cf7246e 100644
--- a/src/boot_flow/android.c
+++ b/src/boot_flow/android.c
@@ -51,10 +51,12 @@
  * Android boot flow does not change based on the updates.
  */
 bool plat_boot_flow_update(struct mm_stage1_locked stage1_locked,
-			   struct boot_params_update *p, struct mpool *ppool)
+			   struct boot_params_update *p, struct memiter *cpio,
+			   struct mpool *ppool)
 {
 	(void)stage1_locked;
 	(void)p;
+	(void)cpio;
 	(void)ppool;
 
 	return true;
diff --git a/src/boot_flow/common.c b/src/boot_flow/common.c
index d489faa..586d3d2 100644
--- a/src/boot_flow/common.c
+++ b/src/boot_flow/common.c
@@ -87,7 +87,8 @@
  * Takes action on any updates that were generated.
  */
 bool boot_flow_update(struct mm_stage1_locked stage1_locked,
-		      struct boot_params_update *p, struct mpool *ppool)
+		      struct boot_params_update *p, struct memiter *cpio,
+		      struct mpool *ppool)
 {
-	return plat_boot_flow_update(stage1_locked, p, ppool);
+	return plat_boot_flow_update(stage1_locked, p, cpio, ppool);
 }
diff --git a/src/boot_flow/linux.c b/src/boot_flow/linux.c
index e301da1..f4f34e0 100644
--- a/src/boot_flow/linux.c
+++ b/src/boot_flow/linux.c
@@ -14,8 +14,33 @@
  * limitations under the License.
  */
 
+#include "hf/cpio.h"
+#include "hf/dlog.h"
 #include "hf/fdt_handler.h"
 #include "hf/plat/boot_flow.h"
+#include "hf/std.h"
+
+/**
+ * Looks for a file in the given cpio archive. The file, if found, is returned
+ * in the "it" argument.
+ */
+static bool find_file(const struct memiter *cpio, const char *name,
+		      struct memiter *it)
+{
+	const char *fname;
+	const void *fcontents;
+	size_t fsize;
+	struct memiter iter = *cpio;
+
+	while (cpio_next(&iter, &fname, &fcontents, &fsize)) {
+		if (!strcmp(fname, name)) {
+			memiter_init(it, fcontents, fsize);
+			return true;
+		}
+	}
+
+	return false;
+}
 
 /* Set by arch-specific boot-time hook. */
 uintreg_t plat_boot_flow_fdt_addr;
@@ -48,8 +73,19 @@
 }
 
 bool plat_boot_flow_update(struct mm_stage1_locked stage1_locked,
-			   struct boot_params_update *p, struct mpool *ppool)
+			   struct boot_params_update *update,
+			   struct memiter *cpio, struct mpool *ppool)
 {
-	return fdt_patch(stage1_locked, plat_boot_flow_get_fdt_addr(), p,
+	struct memiter primary_initrd;
+
+	if (!find_file(cpio, "initrd.img", &primary_initrd)) {
+		dlog("Unable to find initrd.img\n");
+		return false;
+	}
+
+	update->initrd_begin = pa_from_va(va_from_ptr(primary_initrd.next));
+	update->initrd_end = pa_from_va(va_from_ptr(primary_initrd.limit));
+
+	return fdt_patch(stage1_locked, plat_boot_flow_get_fdt_addr(), update,
 			 ppool);
 }