svn commit: r327945 - stable/11/sys/boot/fdt

Kyle Evans kevans at FreeBSD.org
Sat Jan 13 21:27:37 UTC 2018


Author: kevans
Date: Sat Jan 13 21:27:36 2018
New Revision: 327945
URL: https://svnweb.freebsd.org/changeset/base/327945

Log:
  MFC (conceptually) r327376, r327416: Improve libfdt compatibility
  
  This is a direct commit to stable/11 due to restructuring of sys/boot =>
  stand in -HEAD. The diff remains the same and it is simply applied to the
  previous location.
  
  MFC r327376: stand/fdt: Swap libfdt include order
  
  libfdt.h should be included before fdt.h, as hinted at by all of libfdt/;
  standard include order being libfdt.h, libfdt_env.h, fdt.h.
  
  The current include order also causes problems when libfdt gets updated, as
  fdt.h requires some definitions from libfdt.h.
  
  MFC r327416: stand/fdt: Make fdt_overlay_apply signature-compatible with
      libfdt
  
  libfdt will assume a writable fdt overlay blob has been passed in, so make
  ours compatible to allow easier review when we try to drop libfdt into
  place. overlay from the calling context is writable, making it safe to
  simply rip out everything related to copying the overlay blob in
  fdt_overlay_apply.
  
  I note here that we still have problems: fdt_overlay_apply, both our version
  and libfdt's, may fail and have already clobbered the base fdt to some
  extent. Future work will make sure we don't apply a potentially bogus fdt,
  instead discarding the base fdt if we had an error.

Modified:
  stable/11/sys/boot/fdt/fdt_loader_cmd.c
  stable/11/sys/boot/fdt/fdt_overlay.c
  stable/11/sys/boot/fdt/fdt_overlay.h

Modified: stable/11/sys/boot/fdt/fdt_loader_cmd.c
==============================================================================
--- stable/11/sys/boot/fdt/fdt_loader_cmd.c	Sat Jan 13 21:19:55 2018	(r327944)
+++ stable/11/sys/boot/fdt/fdt_loader_cmd.c	Sat Jan 13 21:27:36 2018	(r327945)
@@ -31,8 +31,8 @@
 __FBSDID("$FreeBSD$");
 
 #include <stand.h>
-#include <fdt.h>
 #include <libfdt.h>
+#include <fdt.h>
 #include <sys/param.h>
 #include <sys/linker.h>
 #include <machine/elf.h>
@@ -385,7 +385,8 @@ fdt_apply_overlays()
 	for (fp = file_findfile(NULL, "dtbo"); fp != NULL; fp = fp->f_next) {
 		printf("applying DTB overlay '%s'\n", fp->f_name);
 		COPYOUT(fp->f_addr, overlay, fp->f_size);
-		fdt_overlay_apply(new_fdtp, overlay, fp->f_size);
+		/* Both overlay and new_fdtp may be modified in place */
+		fdt_overlay_apply(new_fdtp, overlay);
 	}
 
 	free(fdtp);

Modified: stable/11/sys/boot/fdt/fdt_overlay.c
==============================================================================
--- stable/11/sys/boot/fdt/fdt_overlay.c	Sat Jan 13 21:19:55 2018	(r327944)
+++ stable/11/sys/boot/fdt/fdt_overlay.c	Sat Jan 13 21:27:36 2018	(r327945)
@@ -409,41 +409,23 @@ fdt_overlay_apply_fragments(void *main_fdtp, void *ove
 }
 
 int
-fdt_overlay_apply(void *main_fdtp, void *overlay_fdtp, size_t overlay_length)
+fdt_overlay_apply(void *main_fdtp, void *overlay_fdtp)
 {
-	void *overlay_copy;
-	int rv;
 
-	rv = 0;
-
-	/* We modify overlay in-place, so we need writable copy */
-	overlay_copy = malloc(overlay_length);
-	if (overlay_copy == NULL) {
-		printf("failed to allocate memory for overlay copy\n");
+	if (fdt_overlay_do_fixups(main_fdtp, overlay_fdtp) < 0) {
+		printf("failed to perform fixups in overlay\n");
 		return (-1);
 	}
 
-	memcpy(overlay_copy, overlay_fdtp, overlay_length);
-
-	if (fdt_overlay_do_fixups(main_fdtp, overlay_copy) < 0) {
-		printf("failed to perform fixups in overlay\n");
-		rv = -1;
-		goto out;
-	}
-
-	if (fdt_overlay_do_local_fixups(main_fdtp, overlay_copy) < 0) {
+	if (fdt_overlay_do_local_fixups(main_fdtp, overlay_fdtp) < 0) {
 		printf("failed to perform local fixups in overlay\n");
-		rv = -1;
-		goto out;
+		return (-1);
 	}
 
-	if (fdt_overlay_apply_fragments(main_fdtp, overlay_copy) < 0) {
+	if (fdt_overlay_apply_fragments(main_fdtp, overlay_fdtp) < 0) {
 		printf("failed to apply fragments\n");
-		rv = -1;
+		return (-1);
 	}
 
-out:
-	free(overlay_copy);
-
-	return (rv);
+	return (0);
 }

Modified: stable/11/sys/boot/fdt/fdt_overlay.h
==============================================================================
--- stable/11/sys/boot/fdt/fdt_overlay.h	Sat Jan 13 21:19:55 2018	(r327944)
+++ stable/11/sys/boot/fdt/fdt_overlay.h	Sat Jan 13 21:27:36 2018	(r327945)
@@ -29,6 +29,6 @@
 #ifndef FDT_OVERLAY_H
 #define FDT_OVERLAY_H
 
-int fdt_overlay_apply(void *main_fdtp, void *overlay_fdtp, size_t overlay_length);
+int fdt_overlay_apply(void *main_fdtp, void *overlay_fdtp);
 
 #endif /* FDT_OVERLAY_H */


More information about the svn-src-all mailing list