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.
Change-Id: Ia769f99e2221f12c79a364c3ad323c31d39c98f3
diff --git a/inc/hf/boot_flow.h b/inc/hf/boot_flow.h
index e96ad1b..2517fdf 100644
--- a/inc/hf/boot_flow.h
+++ b/inc/hf/boot_flow.h
@@ -23,3 +23,6 @@
bool boot_flow_init(struct mm_stage1_locked stage1_locked,
struct manifest *manifest, struct boot_params *boot_params,
struct mpool *ppool);
+
+bool boot_flow_update(struct mm_stage1_locked stage1_locked,
+ struct boot_params_update *p, struct mpool *ppool);
diff --git a/inc/hf/boot_params.h b/inc/hf/boot_params.h
index 59b62d5..a55ee73 100644
--- a/inc/hf/boot_params.h
+++ b/inc/hf/boot_params.h
@@ -47,7 +47,3 @@
paddr_t initrd_begin;
paddr_t initrd_end;
};
-
-bool boot_params_init(struct boot_params *p, const struct fdt_node *fdt_root);
-bool boot_params_patch_fdt(struct mm_stage1_locked stage1_locked,
- struct boot_params_update *p, struct mpool *ppool);
diff --git a/inc/hf/plat/boot_flow.h b/inc/hf/plat/boot_flow.h
index daaf5a6..b404394 100644
--- a/inc/hf/plat/boot_flow.h
+++ b/inc/hf/plat/boot_flow.h
@@ -17,9 +17,13 @@
#pragma once
#include "hf/addr.h"
+#include "hf/boot_params.h"
#include "hf/fdt.h"
+#include "hf/mm.h"
-paddr_t plat_get_fdt_addr(void);
-uintreg_t plat_get_kernel_arg(void);
-bool plat_get_initrd_range(const struct fdt_node *fdt_root, paddr_t *begin,
- paddr_t *end);
+paddr_t plat_boot_flow_get_fdt_addr(void);
+uintreg_t plat_boot_flow_get_kernel_arg(void);
+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);
diff --git a/src/BUILD.gn b/src/BUILD.gn
index 0f17b0a..964509e 100644
--- a/src/BUILD.gn
+++ b/src/BUILD.gn
@@ -27,7 +27,6 @@
# src targets will merge!
source_set("src_not_testable_yet") {
sources = [
- "boot_params.c",
"cpio.c",
"init.c",
"load.c",
diff --git a/src/arch/aarch64/boot_flow/linux.S b/src/arch/aarch64/boot_flow/linux.S
index 581a656..419f9a4 100644
--- a/src/arch/aarch64/boot_flow/linux.S
+++ b/src/arch/aarch64/boot_flow/linux.S
@@ -18,7 +18,7 @@
.global plat_boot_flow_hook
plat_boot_flow_hook:
/* Save the FDT pointer to a global variable. */
- adrp x25, plat_fdt_addr
- add x25, x25, :lo12:plat_fdt_addr
+ adrp x25, plat_boot_flow_fdt_addr
+ add x25, x25, :lo12:plat_boot_flow_fdt_addr
str x0, [x25]
ret
diff --git a/src/boot_flow/android.c b/src/boot_flow/android.c
index 4917ef4..73797e9 100644
--- a/src/boot_flow/android.c
+++ b/src/boot_flow/android.c
@@ -21,7 +21,7 @@
* FDT was compiled into Hafnium. Return physical address of the `.plat.fdt`
* section of Hafnium image.
*/
-paddr_t plat_get_fdt_addr(void)
+paddr_t plat_boot_flow_get_fdt_addr(void)
{
return layout_fdt_begin();
}
@@ -29,7 +29,7 @@
/**
* Android boot flow does not use kernel arguments. Pass zero.
*/
-uintreg_t plat_get_kernel_arg(void)
+uintreg_t plat_boot_flow_get_kernel_arg(void)
{
return 0;
}
@@ -37,8 +37,8 @@
/**
* Initrd was compiled into Hafnium. Return range of the '.plat.initrd' section.
*/
-bool plat_get_initrd_range(const struct fdt_node *fdt_root, paddr_t *begin,
- paddr_t *end)
+bool plat_boot_flow_get_initrd_range(const struct fdt_node *fdt_root,
+ paddr_t *begin, paddr_t *end)
{
(void)fdt_root;
@@ -46,3 +46,16 @@
*end = layout_initrd_end();
return true;
}
+
+/**
+ * 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)
+{
+ (void)stage1_locked;
+ (void)p;
+ (void)ppool;
+
+ return true;
+}
diff --git a/src/boot_flow/common.c b/src/boot_flow/common.c
index d211df6..d489faa 100644
--- a/src/boot_flow/common.c
+++ b/src/boot_flow/common.c
@@ -20,6 +20,21 @@
#include "hf/plat/boot_flow.h"
/**
+ * Extract the boot parameters from the FDT and the boot-flow driver.
+ */
+static bool boot_params_init(struct boot_params *p,
+ const struct fdt_node *fdt_root)
+{
+ p->mem_ranges_count = 0;
+ p->kernel_arg = plat_boot_flow_get_kernel_arg();
+
+ return plat_boot_flow_get_initrd_range(fdt_root, &p->initrd_begin,
+ &p->initrd_end) &&
+ fdt_find_cpus(fdt_root, p->cpu_ids, &p->cpu_count) &&
+ fdt_find_memory_ranges(fdt_root, p);
+}
+
+/**
* Parses information from FDT needed to initialize Hafnium.
* FDT is mapped at the beginning and unmapped before exiting the function.
*/
@@ -33,7 +48,8 @@
enum manifest_return_code manifest_ret;
/* Get the memory map from the FDT. */
- fdt = fdt_map(stage1_locked, plat_get_fdt_addr(), &fdt_root, ppool);
+ fdt = fdt_map(stage1_locked, plat_boot_flow_get_fdt_addr(), &fdt_root,
+ ppool);
if (fdt == NULL) {
dlog("Unable to map FDT.\n");
return false;
@@ -66,3 +82,12 @@
return ret;
}
+
+/**
+ * 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)
+{
+ return plat_boot_flow_update(stage1_locked, p, ppool);
+}
diff --git a/src/boot_flow/linux.c b/src/boot_flow/linux.c
index 52fcb8a..e301da1 100644
--- a/src/boot_flow/linux.c
+++ b/src/boot_flow/linux.c
@@ -18,31 +18,38 @@
#include "hf/plat/boot_flow.h"
/* Set by arch-specific boot-time hook. */
-uintreg_t plat_fdt_addr;
+uintreg_t plat_boot_flow_fdt_addr;
/**
* Returns the physical address of board FDT. This was passed to Hafnium in the
* first kernel arg by the boot loader.
*/
-paddr_t plat_get_fdt_addr(void)
+paddr_t plat_boot_flow_get_fdt_addr(void)
{
- return pa_init((uintpaddr_t)plat_fdt_addr);
+ return pa_init((uintpaddr_t)plat_boot_flow_fdt_addr);
}
/**
* When handing over to the primary, give it the same FDT address that was given
* to Hafnium. The FDT may have been modified during Hafnium init.
*/
-uintreg_t plat_get_kernel_arg(void)
+uintreg_t plat_boot_flow_get_kernel_arg(void)
{
- return plat_fdt_addr;
+ return plat_boot_flow_fdt_addr;
}
/**
* Load initrd range from the board FDT.
*/
-bool plat_get_initrd_range(const struct fdt_node *fdt_root, paddr_t *begin,
- paddr_t *end)
+bool plat_boot_flow_get_initrd_range(const struct fdt_node *fdt_root,
+ paddr_t *begin, paddr_t *end)
{
return fdt_find_initrd(fdt_root, begin, end);
}
+
+bool plat_boot_flow_update(struct mm_stage1_locked stage1_locked,
+ struct boot_params_update *p, struct mpool *ppool)
+{
+ return fdt_patch(stage1_locked, plat_boot_flow_get_fdt_addr(), p,
+ ppool);
+}
diff --git a/src/boot_params.c b/src/boot_params.c
deleted file mode 100644
index 8fbd77d..0000000
--- a/src/boot_params.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2019 The Hafnium Authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "hf/boot_params.h"
-
-#include "hf/dlog.h"
-#include "hf/fdt_handler.h"
-#include "hf/layout.h"
-#include "hf/manifest.h"
-#include "hf/plat/boot_flow.h"
-
-/**
- * Extract the boot parameters from the FDT and the boot-flow driver.
- */
-bool boot_params_init(struct boot_params *p, const struct fdt_node *fdt_root)
-{
- p->mem_ranges_count = 0;
- p->kernel_arg = plat_get_kernel_arg();
-
- return plat_get_initrd_range(fdt_root, &p->initrd_begin,
- &p->initrd_end) &&
- fdt_find_cpus(fdt_root, p->cpu_ids, &p->cpu_count) &&
- fdt_find_memory_ranges(fdt_root, p);
-}
-
-/**
- * Updates the FDT before being passed to the primary VM's kernel.
- *
- * TODO: in future, each VM will declare whether it expects an argument passed
- * and that will be static data e.g. it will provide its own FDT so there will
- * be no FDT modification. This is done because each VM has a very different
- * view of the system and we don't want to force VMs to require loader code when
- * another loader can load the data for it.
- */
-bool boot_params_patch_fdt(struct mm_stage1_locked stage1_locked,
- struct boot_params_update *p, struct mpool *ppool)
-{
- return fdt_patch(stage1_locked, plat_get_fdt_addr(), p, ppool);
-}
diff --git a/src/init.c b/src/init.c
index 4ed8c87..1b3abf2 100644
--- a/src/init.c
+++ b/src/init.c
@@ -116,9 +116,8 @@
panic("Unable to load VMs.");
}
- /* Prepare to run by updating bootparams as seen by primary VM. */
- if (!boot_params_patch_fdt(mm_stage1_locked, &update, &ppool)) {
- panic("plat_update_boot_params failed");
+ if (!boot_flow_update(mm_stage1_locked, &update, &ppool)) {
+ panic("Unable to update boot flow.");
}
mm_defrag(mm_stage1_locked, &ppool);