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/inc/hf/boot_flow.h b/inc/hf/boot_flow.h
index 2517fdf..3ecf25f 100644
--- a/inc/hf/boot_flow.h
+++ b/inc/hf/boot_flow.h
@@ -18,6 +18,7 @@
#include "hf/boot_params.h"
#include "hf/manifest.h"
+#include "hf/memiter.h"
#include "hf/mm.h"
bool boot_flow_init(struct mm_stage1_locked stage1_locked,
@@ -25,4 +26,5 @@
struct mpool *ppool);
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);
diff --git a/inc/hf/plat/boot_flow.h b/inc/hf/plat/boot_flow.h
index b404394..5a6b02b 100644
--- a/inc/hf/plat/boot_flow.h
+++ b/inc/hf/plat/boot_flow.h
@@ -19,6 +19,7 @@
#include "hf/addr.h"
#include "hf/boot_params.h"
#include "hf/fdt.h"
+#include "hf/memiter.h"
#include "hf/mm.h"
paddr_t plat_boot_flow_get_fdt_addr(void);
@@ -26,4 +27,5 @@
bool plat_boot_flow_get_initrd_range(const struct fdt_node *fdt_root,
paddr_t *begin, paddr_t *end);
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);
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);
}
diff --git a/src/init.c b/src/init.c
index 1b3abf2..4948697 100644
--- a/src/init.c
+++ b/src/init.c
@@ -116,7 +116,7 @@
panic("Unable to load VMs.");
}
- if (!boot_flow_update(mm_stage1_locked, &update, &ppool)) {
+ if (!boot_flow_update(mm_stage1_locked, &update, &cpio, &ppool)) {
panic("Unable to update boot flow.");
}
diff --git a/src/load.c b/src/load.c
index b179ba9..fd4bff3 100644
--- a/src/load.c
+++ b/src/load.c
@@ -66,9 +66,8 @@
* null-terminated, so we use a memory iterator to represent it. The file, if
* found, is returned in the "it" argument.
*/
-static bool memiter_find_file(const struct memiter *cpio,
- const struct memiter *filename,
- struct memiter *it)
+static bool find_file(const struct memiter *cpio,
+ const struct memiter *filename, struct memiter *it)
{
const char *fname;
const void *fcontents;
@@ -85,28 +84,6 @@
return false;
}
-/**
- * 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;
-}
-
static bool load_kernel(struct mm_stage1_locked stage1_locked, paddr_t begin,
paddr_t end, const struct manifest_vm *manifest_vm,
const struct memiter *cpio, struct mpool *ppool)
@@ -123,7 +100,7 @@
return true;
}
- if (!memiter_find_file(cpio, &kernel_filename, &kernel)) {
+ if (!find_file(cpio, &kernel_filename, &kernel)) {
dlog("Could not find kernel file \"%s\".\n",
manifest_vm->kernel_filename);
return false;
@@ -148,12 +125,11 @@
static bool load_primary(struct mm_stage1_locked stage1_locked,
const struct manifest *manifest,
const struct memiter *cpio, uintreg_t kernel_arg,
- struct boot_params_update *update, struct mpool *ppool)
+ struct mpool *ppool)
{
paddr_t primary_begin = layout_primary_begin();
const struct manifest_vm *manifest_vm =
&manifest->vm[HF_PRIMARY_VM_ID - HF_VM_ID_OFFSET];
- struct memiter initrd;
/*
* TODO: This bound is currently meaningless but will be addressed when
@@ -167,14 +143,6 @@
return false;
}
- if (!find_file(cpio, "initrd.img", &initrd)) {
- dlog("Unable to find initrd.img\n");
- return false;
- }
-
- update->initrd_begin = pa_from_va(va_from_ptr(initrd.next));
- update->initrd_end = pa_from_va(va_from_ptr(initrd.limit));
-
{
struct vm *vm;
struct vcpu_locked vcpu_locked;
@@ -342,7 +310,7 @@
size_t i;
if (!load_primary(stage1_locked, manifest, cpio, params->kernel_arg,
- update, ppool)) {
+ ppool)) {
dlog("Unable to load primary VM.\n");
return false;
}