Avoid to re-generate string table from ufdt to fdt
String table contains the strings of all property name in a fdt.
The ufdt_apply_overlay() converts two dtbs from fdt to ufdt,
overlays, and converts merged ufdt to fdt. These operations
shouldn't create new peroperty names, so we can just re-use the
string tables in original dtbs, and just copy them into merged
fdt. This solution can enhance a lot of performance for device
tree overlaying.
To avoid the error that some users could use string offset in
string table, the solution also give a same string offset for
the name properties by ufdt_prop_dict;
Futher, the patch also removed unused header files after
changing algorithm.
Bug: 35255584
Test: ./tests/run_tests.sh
Change-Id: Id422730115531bd20d21117285291bdd860915ff
diff --git a/ufdt_overlay.c b/ufdt_overlay.c
index 05f949f..d6e250e 100644
--- a/ufdt_overlay.c
+++ b/ufdt_overlay.c
@@ -540,8 +540,24 @@
/* END of updating local references (phandle values) in the overlay ufdt. */
+static int _ufdt_overlay_fdtps(struct ufdt *main_tree,
+ const struct ufdt *overlay_tree) {
+ for (int i = 0; i < overlay_tree->num_used_fdtps; i++) {
+ void *fdt = overlay_tree->fdtps[i];
+ if (ufdt_add_fdt(main_tree, fdt) < 0) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
static int ufdt_overlay_apply(struct ufdt *main_tree, struct ufdt *overlay_tree,
size_t overlay_length) {
+ if (_ufdt_overlay_fdtps(main_tree, overlay_tree) < 0) {
+ dto_error("failed to add more fdt into main ufdt tree.\n");
+ return -1;
+ }
+
if (overlay_length < sizeof(struct fdt_header)) {
dto_error("Overlay_length %zu smaller than header size %zu\n",
overlay_length, sizeof(struct fdt_header));