Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Aug 2018 13:38:38 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r338250 - head/stand/efi/loader
Message-ID:  <201808231338.w7NDcc2O023938@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Thu Aug 23 13:38:38 2018
New Revision: 338250
URL: https://svnweb.freebsd.org/changeset/base/338250

Log:
  efiloader: Setup FDT in autoload to fix overlays clobbering kenv
  
  manu found in the noted PR that overlays seemed to be clobbering the kenv
  and killing the boot. Further inspection revealed that one can `fdt ls` at
  the loader prompt for a successful boot, but autoboot breaks it.
  
  In the autoboot case, first setup of FDT is happening in the middle of
  bi_load, which triggers loading of the DTBO from /boot.
  
  This is bad, bad, bad. Files in the loader are loaded somewhere in the
  middle of the address space one after another. bi_load starts building the
  needed kernel bootinfo immediately after the highest-addr loaded file. File
  loads in the middle of bi_load suddenly clobber bootinfo and everything goes
  off the rails.
  
  The solution to this is to use take advantage of arch_autoload to setup FDT
  in efiloader compiled with LOADER_FDT_SUPPORT. This matches how it works in
  ubldr land, and is how it should have worked when overlay support was added
  to efiloader since fdt_setup_fdtp now has the potential to load files
  (courtesy of fdt_platform_load_dtb).
  
  PR:		230804
  Discussed with:	imp
  MFC after:	1 week
  Differential Revision:	https://reviews.freebsd.org/D16858

Modified:
  head/stand/efi/loader/autoload.c

Modified: head/stand/efi/loader/autoload.c
==============================================================================
--- head/stand/efi/loader/autoload.c	Thu Aug 23 13:25:32 2018	(r338249)
+++ head/stand/efi/loader/autoload.c	Thu Aug 23 13:38:38 2018	(r338250)
@@ -27,11 +27,30 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
+#if defined(LOADER_FDT_SUPPORT)
+#include <sys/param.h>
+#include <fdt_platform.h>
+#endif
+
 #include "loader_efi.h"
 
 int
 efi_autoload(void)
 {
 
+#if defined(LOADER_FDT_SUPPORT)
+	/*
+	 * Setup the FDT early so that we're not loading files during bi_load.
+	 * Any such loading is inherently broken since bi_load uses the space
+	 * just after all currently loaded files for the data that will be
+	 * passed to the kernel and newly loaded files will be positioned in
+	 * that same space.
+	 *
+	 * We're glossing over errors here because LOADER_FDT_SUPPORT does not
+	 * imply that we're on a platform where FDT is a requirement.  If we
+	 * fix this, then the error handling here should be fixed accordingly.
+	 */
+	fdt_setup_fdtp();
+#endif
 	return (0);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201808231338.w7NDcc2O023938>