Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 22 Feb 2014 22:18:20 +0000 (UTC)
From:      Ian Lepore <ian@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r262347 - head/sys/boot/fdt
Message-ID:  <201402222218.s1MMIKaf075900@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ian
Date: Sat Feb 22 22:18:20 2014
New Revision: 262347
URL: http://svnweb.freebsd.org/changeset/base/262347

Log:
  Add a feature for automatically finding and loading a dtb file by name.
  The name is taken from the u-boot env vars fdtfile or fdt_file.  If the
  name isn't fully-qualified a search is done in module_path locations.
  
  The search order for a usable dtb in fdt_setup_fdtp() is now
  
   - A dtb loaded with an explicit "load -t dtb" command.
   - A dtb already loaded into memory somehow[*] and pointed to by fdt_to_load.
   - A dtb in the memory pointed to by the u-boot env vars fdtaddr or fdt_addr.
   - A file named by the u-boot env vars fdtfile or fdt_file.
   - A static dtb compiled into the kernel.
  
  * Presumably by some arch-specific command or code.

Modified:
  head/sys/boot/fdt/fdt_loader_cmd.c

Modified: head/sys/boot/fdt/fdt_loader_cmd.c
==============================================================================
--- head/sys/boot/fdt/fdt_loader_cmd.c	Sat Feb 22 22:07:16 2014	(r262346)
+++ head/sys/boot/fdt/fdt_loader_cmd.c	Sat Feb 22 22:18:20 2014	(r262347)
@@ -254,11 +254,36 @@ fdt_load_dtb_addr(struct fdt_header *hea
 }
 
 static int
+fdt_load_dtb_file(const char * filename)
+{
+	struct preloaded_file *bfp, *oldbfp;
+	int err;
+
+	debugf("fdt_load_dtb_file(%s)\n", filename);
+
+	oldbfp = file_findfile(NULL, "dtb");
+
+	/* Attempt to load and validate a new dtb from a file. */
+	if ((bfp = file_loadraw(filename, "dtb")) == NULL) {
+		sprintf(command_errbuf, "failed to load file '%s'", filename);
+		return (1);
+	}
+	if ((err = fdt_load_dtb(bfp->f_addr)) != 0) {
+		file_discard(bfp);
+		return (err);
+	}
+
+	/* A new dtb was validated, discard any previous file. */
+	if (oldbfp)
+		file_discard(oldbfp);
+	return (0);
+}
+
+static int
 fdt_setup_fdtp()
 {
 	struct preloaded_file *bfp;
 	struct fdt_header *hdr;
-	int err;
 	const char *s;
 	char *p;
 	vm_offset_t va;
@@ -268,7 +293,8 @@ fdt_setup_fdtp()
 	/* If we already loaded a file, use it. */
 	if ((bfp = file_findfile(NULL, "dtb")) != NULL) {
 		if (fdt_load_dtb(bfp->f_addr) == 0) {
-			printf("Using DTB from loaded file.\n");
+			printf("Using DTB from loaded file '%s'.\n", 
+			    bfp->f_name);
 			return (0);
 		}
 	}
@@ -295,12 +321,26 @@ fdt_setup_fdtp()
 		if (*p == '\0') {
 			if (fdt_load_dtb_addr(hdr) == 0) {
 				printf("Using DTB provided by U-Boot at "
-				    "address 0x%08X.\n", hdr);
+				    "address 0x%p.\n", hdr);
 				return (0);
 			}
 		}
 	}
 
+	/*
+	 * If the U-boot environment contains a variable giving the name of a
+	 * file, use it if we can load and validate it.
+	 */
+	s = ub_env_get("fdtfile");
+	if (s == NULL)
+		s = ub_env_get("fdt_file");
+	if (s != NULL && *s != '\0') {
+		if (fdt_load_dtb_file(s) == 0) {
+			printf("Loaded DTB from file '%s'.\n", s);
+			return (0);
+		}
+	}
+
 	/* If there is a dtb compiled into the kernel, use it. */
 	if ((va = fdt_find_static_dtb()) != 0) {
 		if (fdt_load_dtb(va) == 0) {



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