event: Add an event for device tree fixups

At present there is a confusing array of functions that handle the
device tree fix-ups needed for booting an OS. We should be able to switch
to using events to clean this up.

As a first step, create a new event type and call it from the standard
place.

Note that this event uses the ofnode interface only, since this can
support live tree which is more efficient when making lots of updates.

Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/boot/image-fdt.c b/boot/image-fdt.c
index 9db2cee..5e5b246 100644
--- a/boot/image-fdt.c
+++ b/boot/image-fdt.c
@@ -21,6 +21,7 @@
 #include <linux/libfdt.h>
 #include <mapmem.h>
 #include <asm/io.h>
+#include <dm/ofnode.h>
 #include <tee/optee.h>
 
 #ifndef CONFIG_SYS_FDT_PAD
@@ -668,6 +669,16 @@
 			goto err;
 		}
 	}
+	if (CONFIG_IS_ENABLED(EVENT)) {
+		struct event_ft_fixup fixup;
+
+		fixup.tree = oftree_default();
+		ret = event_notify(EVT_FT_FIXUP, &fixup, sizeof(fixup));
+		if (ret) {
+			printf("ERROR: fdt fixup event failed: %d\n", ret);
+			goto err;
+		}
+	}
 
 	/* Delete the old LMB reservation */
 	if (lmb)
diff --git a/common/event.c b/common/event.c
index af1ed41..3e34550 100644
--- a/common/event.c
+++ b/common/event.c
@@ -35,6 +35,9 @@
 
 	/* init hooks */
 	"misc_init_f",
+
+	/* fdt hooks */
+	"ft_fixup",
 };
 
 _Static_assert(ARRAY_SIZE(type_name) == EVT_COUNT, "event type_name size");
diff --git a/include/event.h b/include/event.h
index fb0734e..e8f2f55 100644
--- a/include/event.h
+++ b/include/event.h
@@ -10,6 +10,8 @@
 #ifndef __event_h
 #define __event_h
 
+#include <dm/ofnode_decl.h>
+
 /**
  * enum event_t - Types of events supported by U-Boot
  *
@@ -29,6 +31,9 @@
 	/* Init hooks */
 	EVT_MISC_INIT_F,
 
+	/* Device tree fixups before booting */
+	EVT_FT_FIXUP,
+
 	EVT_COUNT
 };
 
@@ -50,6 +55,15 @@
 	struct event_dm {
 		struct udevice *dev;
 	} dm;
+
+	/**
+	 * struct event_ft_fixup - FDT fixup before booting
+	 *
+	 * @tree: tree to update
+	 */
+	struct event_ft_fixup {
+		oftree tree;
+	} ft_fixup;
 };
 
 /**
diff --git a/test/py/tests/test_event_dump.py b/test/py/tests/test_event_dump.py
index b753e80..1700177 100644
--- a/test/py/tests/test_event_dump.py
+++ b/test/py/tests/test_event_dump.py
@@ -16,5 +16,6 @@
     out = util.run_and_log(cons, ['scripts/event_dump.py', sandbox])
     expect = '''.*Event type            Id                              Source location
 --------------------  ------------------------------  ------------------------------
+EVT_FT_FIXUP          bootmeth_vbe_simple_ft_fixup    boot/vbe_simple.c:.*
 EVT_MISC_INIT_F       sandbox_misc_init_f             .*arch/sandbox/cpu/start.c:'''
     assert re.match(expect, out, re.MULTILINE) is not None