refactor(init): use memory pool for boot params
Use the memory pool for the boot parameters instead
of the stack. The 'boot_params' structure has a few
arrays that can grow, by using the memory pool we avoid
issues with the stack.
Signed-off-by: J-Alves <joao.alves@arm.com>
Change-Id: Iea3ba9e6cbf6d448b9efddc9bff6aade465a29ad
diff --git a/src/init.c b/src/init.c
index 423b9fa..371b77f 100644
--- a/src/init.c
+++ b/src/init.c
@@ -69,7 +69,7 @@
struct string manifest_fname = STRING_INIT("manifest.dtb");
struct fdt fdt;
enum manifest_return_code manifest_ret;
- struct boot_params params;
+ struct boot_params *params;
struct boot_params_update update;
struct memiter cpio;
struct memiter manifest_it;
@@ -91,14 +91,22 @@
panic("Unable to map FDT.");
}
- if (!boot_flow_get_params(¶ms, &fdt)) {
+ static_assert(sizeof(struct boot_params) <= MM_PPOOL_ENTRY_SIZE,
+ "The sizeof boot params must fit an entry of the mpool.");
+ params = (struct boot_params *)mpool_alloc(&ppool);
+
+ if (params == NULL) {
+ panic("Could not use memory pool to allocate boot params.");
+ }
+
+ if (!boot_flow_get_params(params, &fdt)) {
panic("Could not parse boot params.");
}
- for (i = 0; i < params.mem_ranges_count; ++i) {
+ for (i = 0; i < params->mem_ranges_count; ++i) {
dlog_info("Memory range: %#x - %#x\n",
- pa_addr(params.mem_ranges[i].begin),
- pa_addr(params.mem_ranges[i].end) - 1);
+ pa_addr(params->mem_ranges[i].begin),
+ pa_addr(params->mem_ranges[i].end) - 1);
}
/*
@@ -108,21 +116,21 @@
* shall be looked up from the ramdisk. If zero, assume the address
* passed to Hafnium entry point is the manifest address.
*/
- if (pa_addr(params.initrd_begin)) {
+ if (pa_addr(params->initrd_begin)) {
dlog_info("Ramdisk range: %#x - %#x\n",
- pa_addr(params.initrd_begin),
- pa_addr(params.initrd_end) - 1);
+ pa_addr(params->initrd_begin),
+ pa_addr(params->initrd_end) - 1);
/* Map initrd in, and initialise cpio parser. */
- initrd = mm_identity_map(mm_stage1_locked, params.initrd_begin,
- params.initrd_end, MM_MODE_R, &ppool);
+ initrd = mm_identity_map(mm_stage1_locked, params->initrd_begin,
+ params->initrd_end, MM_MODE_R, &ppool);
if (!initrd) {
panic("Unable to map initrd.");
}
- memiter_init(
- &cpio, initrd,
- pa_difference(params.initrd_begin, params.initrd_end));
+ memiter_init(&cpio, initrd,
+ pa_difference(params->initrd_begin,
+ params->initrd_end));
if (!cpio_get_file(&cpio, &manifest_fname, &manifest_it)) {
panic("Could not find manifest in initrd.");
@@ -138,7 +146,7 @@
}
manifest_ret = manifest_init(mm_stage1_locked, &manifest, &manifest_it,
- ¶ms, &ppool);
+ params, &ppool);
if (manifest_ret != MANIFEST_SUCCESS) {
panic("Could not parse manifest: %s.",
@@ -155,7 +163,7 @@
panic("Unable to unmap FDT.");
}
- cpu_module_init(params.cpu_ids, params.cpu_count);
+ cpu_module_init(params->cpu_ids, params->cpu_count);
if (!plat_interrupts_controller_driver_init(&fdt, mm_stage1_locked,
&ppool)) {
@@ -164,7 +172,7 @@
/* Load all VMs. */
update.reserved_ranges_count = 0;
- if (!load_vms(mm_stage1_locked, manifest, &cpio, ¶ms, &update,
+ if (!load_vms(mm_stage1_locked, manifest, &cpio, params, &update,
&ppool)) {
panic("Unable to load VMs.");
}
@@ -174,6 +182,9 @@
panic("Unable to update boot flow.");
}
+ /* Free space allocated for the boot parameters. */
+ mpool_free(&ppool, params);
+
/* Now manifest parsing has completed free the resourses used. */
manifest_deinit(&ppool);