Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 Feb 2019 18:48:37 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r344375 - in stable/11/stand/uboot: common fdt
Message-ID:  <201902201848.x1KImbTe004633@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Wed Feb 20 18:48:36 2019
New Revision: 344375
URL: https://svnweb.freebsd.org/changeset/base/344375

Log:
  MFC r335869, r335933: stand: uboot behavioral fixes
  
  r335869:
  stand: uboot: Do not panic if we can't find a boot device
  
  It is really anoying to panic when there is no boot device as you
  cannot see the availables ones.
  
  r335933:
  loader: fdt: Try to load every possible DTB from u-boot
  
  U-Boot setup a few variables :
  
   - fdt_addr which is the board static dtb (most of the time loaded before
     u-boot or coming from some hardware like a ROM)
   - fdt_addr_r which is a location in RAM that holds the DTB loaded by
     u-boot or before u-boot
  
  In the case of u-boot + rpi firmware the DTB is loaded in RAM but the location
  still end up in the fdt_addr variable and the fdt_addr_r variable exist.
  
  Change the behavior so we test that a DTB exists for every possible variable :
  
   - fdt_addr_r is checked first as if u-boot needed to modify it the
     correct DTB will live there.
   - fdt_addr is checked second as if we run on a hardware with DTB in ROM
     it means that we what/need to run that
   - fdtaddr looks like a FreeBSD-ism but since I'm not sure leave it.

Modified:
  stable/11/stand/uboot/common/main.c
  stable/11/stand/uboot/fdt/uboot_fdt.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/stand/uboot/common/main.c
==============================================================================
--- stable/11/stand/uboot/common/main.c	Wed Feb 20 18:46:31 2019	(r344374)
+++ stable/11/stand/uboot/common/main.c	Wed Feb 20 18:48:36 2019	(r344375)
@@ -444,8 +444,10 @@ main(int argc, char **argv)
 	/*
 	 * Enumerate U-Boot devices
 	 */
-	if ((devs_no = ub_dev_enum()) == 0)
-		panic("no U-Boot devices found");
+	if ((devs_no = ub_dev_enum()) == 0) {
+		printf("no U-Boot devices found");
+		goto do_interact;
+	}
 	printf("Number of U-Boot devices: %d\n", devs_no);
 
 	get_load_device(&load_type, &load_unit, &load_slice, &load_partition);
@@ -492,6 +494,7 @@ main(int argc, char **argv)
 	env_setenv("loaddev", EV_VOLATILE, ldev, env_noset, env_nounset);
 	printf("Booting from %s\n", ldev);
 
+do_interact:
 	setenv("LINES", "24", 1);		/* optional */
 	setenv("prompt", "loader>", 1);
 

Modified: stable/11/stand/uboot/fdt/uboot_fdt.c
==============================================================================
--- stable/11/stand/uboot/fdt/uboot_fdt.c	Wed Feb 20 18:46:31 2019	(r344374)
+++ stable/11/stand/uboot/fdt/uboot_fdt.c	Wed Feb 20 18:48:36 2019	(r344375)
@@ -39,6 +39,30 @@ __FBSDID("$FreeBSD$");
 #define STR(number) #number
 #define STRINGIFY(number) STR(number)
 
+static int
+fdt_platform_load_from_ubenv(const char *var)
+{
+	struct fdt_header *hdr;
+	const char *s;
+	char *p;
+
+	s = ub_env_get(var);
+	if (s == NULL || *s == '\0')
+		return (1);
+
+	hdr = (struct fdt_header *)strtoul(s, &p, 16);
+	if (*p != '\0')
+		return (1);
+
+	if (fdt_load_dtb_addr(hdr) == 0) {
+		printf("Using DTB provided by U-Boot at "
+		    "address %p.\n", hdr);
+		return (0);
+	}
+
+	return (1);
+}
+
 int
 fdt_platform_load_dtb(void)
 {
@@ -53,22 +77,12 @@ fdt_platform_load_dtb(void)
 	 * variable for fdt data loaded into ram is fdt_addr_r, so try that
 	 * first.  Board vendors also use both fdtaddr and fdt_addr names.
 	 */
-	s = ub_env_get("fdt_addr_r");
-	if (s == NULL)
-		s = ub_env_get("fdtaddr");
-	if (s == NULL)
-		s = ub_env_get("fdt_addr");
-	if (s != NULL && *s != '\0') {
-		hdr = (struct fdt_header *)strtoul(s, &p, 16);
-		if (*p == '\0') {
-			if (fdt_load_dtb_addr(hdr) == 0) {
-				printf("Using DTB provided by U-Boot at "
-				    "address %p.\n", hdr);
-				rv = 0;
-				goto exit;
-			}
-		}
-	}
+	if ((rv = fdt_platform_load_from_ubenv("fdt_addr_r")) == 0)
+		goto exit;
+	if ((rv = fdt_platform_load_from_ubenv("fdt_addr")) == 0)
+		goto exit;
+	if ((rv = fdt_platform_load_from_ubenv("fdtaddr")) == 0)
+		goto exit;
 
 	rv = 1;
 



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