Migrate to libfdt
Replace our custom FDT parser implementation with libfdt while retaining
the original API as a thin wrapper around libfdt. This minimizes the
changes to the rest of our code base and hides differences in coding
styles.
As a byproduct, this fixes an issue with unaligned memory accesses while
parsing as libfdt handles these correctly.
Bug: 150587116
Change-Id: I8d305d7094b1be04608048009d73d7c448a578a0
diff --git a/src/boot_flow/android.c b/src/boot_flow/android.c
index 88939bc..910d3bb 100644
--- a/src/boot_flow/android.c
+++ b/src/boot_flow/android.c
@@ -41,10 +41,10 @@
* (b) a fixed address range known at build time (INITRD_ADDR and INITRD_SIZE
* are not zero).
*/
-bool plat_boot_flow_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 *fdt, paddr_t *begin,
+ paddr_t *end)
{
- (void)fdt_root;
+ (void)fdt;
uintpaddr_t initrd_addr = (uintpaddr_t)(INITRD_ADDR);
size_t initrd_size = (size_t)(INITRD_SIZE);
diff --git a/src/boot_flow/common.c b/src/boot_flow/common.c
index dace9af..0f263a9 100644
--- a/src/boot_flow/common.c
+++ b/src/boot_flow/common.c
@@ -22,8 +22,7 @@
/**
* Extract the boot parameters from the FDT and the boot-flow driver.
*/
-bool boot_flow_get_params(struct boot_params *p,
- const struct fdt_node *fdt_root)
+bool boot_flow_get_params(struct boot_params *p, const struct fdt *fdt)
{
struct string memory = STRING_INIT("memory");
struct string device_memory = STRING_INIT("device-memory");
@@ -31,14 +30,14 @@
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,
+ return plat_boot_flow_get_initrd_range(fdt, &p->initrd_begin,
&p->initrd_end) &&
- fdt_find_cpus(fdt_root, p->cpu_ids, &p->cpu_count) &&
- fdt_find_memory_ranges(fdt_root, &memory, p->mem_ranges,
+ fdt_find_cpus(fdt, p->cpu_ids, &p->cpu_count) &&
+ fdt_find_memory_ranges(fdt, &memory, p->mem_ranges,
&p->mem_ranges_count, MAX_MEM_RANGES) &&
- fdt_find_memory_ranges(
- fdt_root, &device_memory, p->device_mem_ranges,
- &p->device_mem_ranges_count, MAX_DEVICE_MEM_RANGES);
+ fdt_find_memory_ranges(fdt, &device_memory, p->device_mem_ranges,
+ &p->device_mem_ranges_count,
+ MAX_DEVICE_MEM_RANGES);
}
/**
diff --git a/src/boot_flow/linux.c b/src/boot_flow/linux.c
index a3dff65..ffbfbec 100644
--- a/src/boot_flow/linux.c
+++ b/src/boot_flow/linux.c
@@ -18,6 +18,7 @@
#include "hf/cpio.h"
#include "hf/dlog.h"
#include "hf/fdt_handler.h"
+#include "hf/fdt_patch.h"
#include "hf/plat/boot_flow.h"
#include "hf/std.h"
@@ -45,10 +46,10 @@
/**
* Load initrd range from the board FDT.
*/
-bool plat_boot_flow_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 *fdt, paddr_t *begin,
+ paddr_t *end)
{
- return fdt_find_initrd(fdt_root, begin, end);
+ return fdt_find_initrd(fdt, begin, end);
}
bool plat_boot_flow_update(struct mm_stage1_locked stage1_locked,