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/init.c b/src/init.c
index 9f8f829..702235b 100644
--- a/src/init.c
+++ b/src/init.c
@@ -72,8 +72,7 @@
 void one_time_init(void)
 {
 	struct string manifest_fname = STRING_INIT("manifest.dtb");
-	struct fdt_header *fdt;
-	struct fdt_node fdt_root;
+	struct fdt fdt;
 	struct manifest manifest;
 	enum manifest_return_code manifest_ret;
 	struct boot_params params;
@@ -92,17 +91,12 @@
 
 	mm_stage1_locked = mm_lock_stage1();
 
-	fdt = fdt_map(mm_stage1_locked, plat_boot_flow_get_fdt_addr(),
-		      &fdt_root, &ppool);
-	if (fdt == NULL) {
+	if (!fdt_map(&fdt, mm_stage1_locked, plat_boot_flow_get_fdt_addr(),
+		     &ppool)) {
 		panic("Unable to map FDT.");
 	}
 
-	if (!fdt_find_child(&fdt_root, "")) {
-		panic("Unable to find FDT root node.");
-	}
-
-	if (!boot_flow_get_params(&params, &fdt_root)) {
+	if (!boot_flow_get_params(&params, &fdt)) {
 		panic("Could not parse boot params.");
 	}
 
@@ -141,11 +135,11 @@
 		      manifest_strerror(manifest_ret));
 	}
 
-	if (!plat_iommu_init(&fdt_root, mm_stage1_locked, &ppool)) {
+	if (!plat_iommu_init(&fdt, mm_stage1_locked, &ppool)) {
 		panic("Could not initialize IOMMUs.");
 	}
 
-	if (!fdt_unmap(mm_stage1_locked, fdt, &ppool)) {
+	if (!fdt_unmap(&fdt, mm_stage1_locked, &ppool)) {
 		panic("Unable to unmap FDT.");
 	}