Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 13 Feb 2018 03:44:50 +0000 (UTC)
From:      Justin Hibbits <jhibbits@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r329190 - in head/stand: . common mips/beri/loader powerpc/kboot powerpc/ofw sparc64/loader uboot/common uboot/lib
Message-ID:  <201802130344.w1D3ioVT081427@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhibbits
Date: Tue Feb 13 03:44:50 2018
New Revision: 329190
URL: https://svnweb.freebsd.org/changeset/base/329190

Log:
  Unify metadata load files for arm, mips, powerpc, sparc64
  
  Summary:
  All metadata.c files are very similar, with only trivial changes.  Unify them
  into a single common file, with minor special-casing where needed.
  
  Reviewed By: imp
  Differential Revision: https://reviews.freebsd.org/D13978

Added:
  head/stand/common/metadata.c
     - copied, changed from r329189, head/stand/powerpc/ofw/metadata.c
Deleted:
  head/stand/mips/beri/loader/metadata.c
  head/stand/powerpc/kboot/metadata.c
  head/stand/powerpc/ofw/metadata.c
  head/stand/sparc64/loader/metadata.c
  head/stand/uboot/common/metadata.c
Modified:
  head/stand/loader.mk
  head/stand/mips/beri/loader/Makefile
  head/stand/mips/beri/loader/exec.c
  head/stand/mips/beri/loader/loader.h
  head/stand/powerpc/kboot/Makefile
  head/stand/powerpc/kboot/main.c
  head/stand/powerpc/ofw/Makefile
  head/stand/sparc64/loader/Makefile
  head/stand/uboot.mk
  head/stand/uboot/lib/elf_freebsd.c

Copied and modified: head/stand/common/metadata.c (from r329189, head/stand/powerpc/ofw/metadata.c)
==============================================================================
--- head/stand/powerpc/ofw/metadata.c	Tue Feb 13 02:11:39 2018	(r329189, copy source)
+++ head/stand/common/metadata.c	Tue Feb 13 03:44:50 2018	(r329190)
@@ -34,12 +34,63 @@ __FBSDID("$FreeBSD$");
 #include <sys/reboot.h>
 #include <sys/linker.h>
 #include <sys/boot.h>
+#if defined(LOADER_FDT_SUPPORT)
 #include <fdt_platform.h>
+#endif
 
 #include <machine/metadata.h>
 
 #include "bootstrap.h"
 
+#if defined(__sparc64__)
+#include <openfirm.h>
+
+extern struct tlb_entry *dtlb_store;
+extern struct tlb_entry *itlb_store;
+
+extern int dtlb_slot;
+extern int itlb_slot;
+
+static int
+md_bootserial(void)
+{
+    char        buf[64];
+    ihandle_t        inst;
+    phandle_t        input;
+    phandle_t        node;
+    phandle_t        output;
+
+    if ((node = OF_finddevice("/options")) == -1)
+        return(-1);
+    if (OF_getprop(node, "input-device", buf, sizeof(buf)) == -1)
+        return(-1);
+    input = OF_finddevice(buf);
+    if (OF_getprop(node, "output-device", buf, sizeof(buf)) == -1)
+        return(-1);
+    output = OF_finddevice(buf);
+    if (input == -1 || output == -1 ||
+        OF_getproplen(input, "keyboard") >= 0) {
+        if ((node = OF_finddevice("/chosen")) == -1)
+            return(-1);
+        if (OF_getprop(node, "stdin", &inst, sizeof(inst)) == -1)
+            return(-1);
+        if ((input = OF_instance_to_package(inst)) == -1)
+            return(-1);
+        if (OF_getprop(node, "stdout", &inst, sizeof(inst)) == -1)
+            return(-1);
+        if ((output = OF_instance_to_package(inst)) == -1)
+            return(-1);
+    }
+    if (input != output)
+        return(-1);
+    if (OF_getprop(input, "device_type", buf, sizeof(buf)) == -1)
+        return(-1);
+    if (strcmp(buf, "serial") != 0)
+        return(-1);
+    return(0);
+}
+#endif
+
 int
 md_getboothowto(char *kargs)
 {
@@ -47,7 +98,7 @@ md_getboothowto(char *kargs)
     int		howto;
     int		active;
     int		i;
-    
+
     /* Parse kargs */
     howto = 0;
     if (kargs != NULL) {
@@ -98,14 +149,20 @@ md_getboothowto(char *kargs)
 	    cp++;
 	}
     }
+
     /* get equivalents from the environment */
     for (i = 0; howto_names[i].ev != NULL; i++)
 	if (getenv(howto_names[i].ev) != NULL)
 	    howto |= howto_names[i].mask;
+#if defined(__sparc64__)
+    if (md_bootserial() != -1)
+	howto |= RB_SERIAL;
+#else
     if (!strcmp(getenv("console"), "comconsole"))
 	howto |= RB_SERIAL;
     if (!strcmp(getenv("console"), "nullconsole"))
 	howto |= RB_MUTE;
+#endif
     return(howto);
 }
 
@@ -114,11 +171,11 @@ md_getboothowto(char *kargs)
  * Each variable is formatted as <name>=<value>, with a single nul
  * separating each variable, and a double nul terminating the environment.
  */
-vm_offset_t
+static vm_offset_t
 md_copyenv(vm_offset_t addr)
 {
     struct env_var	*ep;
-    
+
     /* traverse the environment */
     for (ep = environ; ep != NULL; ep = ep->ev_next) {
 	archsw.arch_copyin(ep->ev_name, addr, strlen(ep->ev_name));
@@ -199,7 +256,7 @@ static int align;
     COPY32(0, a, c);				\
 }
 
-vm_offset_t
+static vm_offset_t
 md_copymodules(vm_offset_t addr, int kern64)
 {
     struct preloaded_file	*fp;
@@ -235,7 +292,7 @@ md_copymodules(vm_offset_t addr, int kern64)
 }
 
 /*
- * Load the information expected by a powerpc kernel.
+ * Load the information expected by a kernel.
  *
  * - The 'boothowto' argument is constructed
  * - The 'bootdev' argument is constructed
@@ -251,7 +308,9 @@ md_load_dual(char *args, vm_offset_t *modulep, vm_offs
     vm_offset_t			kernend;
     vm_offset_t			addr;
     vm_offset_t			envp;
+#if defined(LOADER_FDT_SUPPORT)
     vm_offset_t			fdtp;
+#endif
     vm_offset_t			size;
     uint64_t			scratch64;
     char			*rootdevname;
@@ -260,40 +319,45 @@ md_load_dual(char *args, vm_offset_t *modulep, vm_offs
     align = kern64 ? 8 : 4;
     howto = md_getboothowto(args);
 
-    /* 
-     * Allow the environment variable 'rootdev' to override the supplied device 
-     * This should perhaps go to MI code and/or have $rootdev tested/set by
-     * MI code before launching the kernel.
+    /*
+     * Allow the environment variable 'rootdev' to override the supplied
+     * device. This should perhaps go to MI code and/or have $rootdev
+     * tested/set by MI code before launching the kernel.
      */
     rootdevname = getenv("rootdev");
     if (rootdevname == NULL)
-	    rootdevname = getenv("currdev");
+	rootdevname = getenv("currdev");
     /* Try reading the /etc/fstab file to select the root device */
     getrootmount(rootdevname);
 
-    /* find the last module in the chain */
+    /* Find the last module in the chain */
     addr = 0;
     for (xp = file_findfile(NULL, NULL); xp != NULL; xp = xp->f_next) {
 	if (addr < (xp->f_addr + xp->f_size))
 	    addr = xp->f_addr + xp->f_size;
     }
-    /* pad to a page boundary */
+    /* Pad to a page boundary */
     addr = roundup(addr, PAGE_SIZE);
 
-    /* copy our environment */
+    /* Copy our environment */
     envp = addr;
     addr = md_copyenv(addr);
 
-    /* pad to a page boundary */
+    /* Pad to a page boundary */
     addr = roundup(addr, PAGE_SIZE);
 
+#if defined(LOADER_FDT_SUPPORT)
     /* Copy out FDT */
-    *dtb = fdtp = 0;
-    if (getenv("usefdt") != NULL) {
-        size = fdt_copy(addr);
-        *dtb = fdtp = addr;
-        addr = roundup(addr + size, PAGE_SIZE);
+    fdtp = 0;
+#if defined(__powerpc__)
+    if (getenv("usefdt") != NULL)
+#endif
+    {
+	size = fdt_copy(addr);
+	fdtp = addr;
+	addr = roundup(addr + size, PAGE_SIZE);
     }
+#endif
 
     kernend = 0;
     kfp = file_findfile(NULL, kern64 ? "elf64 kernel" : "elf32 kernel");
@@ -305,19 +369,35 @@ md_load_dual(char *args, vm_offset_t *modulep, vm_offs
     if (kern64) {
 	scratch64 = envp;
 	file_addmetadata(kfp, MODINFOMD_ENVP, sizeof scratch64, &scratch64);
-        if (fdtp != 0) {
+#if defined(LOADER_FDT_SUPPORT)
+	if (fdtp != 0) {
 	    scratch64 = fdtp;
 	    file_addmetadata(kfp, MODINFOMD_DTBP, sizeof scratch64, &scratch64);
-        }
+	}
+#endif
 	scratch64 = kernend;
-	file_addmetadata(kfp, MODINFOMD_KERNEND, sizeof scratch64, &scratch64);
+	file_addmetadata(kfp, MODINFOMD_KERNEND,
+		sizeof scratch64, &scratch64);
     } else {
 	file_addmetadata(kfp, MODINFOMD_ENVP, sizeof envp, &envp);
-        if (fdtp != 0)
+#if defined(LOADER_FDT_SUPPORT)
+	if (fdtp != 0)
 	    file_addmetadata(kfp, MODINFOMD_DTBP, sizeof fdtp, &fdtp);
+#endif
 	file_addmetadata(kfp, MODINFOMD_KERNEND, sizeof kernend, &kernend);
     }
 
+#if defined(__sparc64__)
+    file_addmetadata(kfp, MODINFOMD_DTLB_SLOTS,
+	sizeof dtlb_slot, &dtlb_slot);
+    file_addmetadata(kfp, MODINFOMD_ITLB_SLOTS,
+	sizeof itlb_slot, &itlb_slot);
+    file_addmetadata(kfp, MODINFOMD_DTLB,
+	dtlb_slot * sizeof(*dtlb_store), dtlb_store);
+    file_addmetadata(kfp, MODINFOMD_ITLB,
+	itlb_slot * sizeof(*itlb_store), itlb_store);
+#endif
+
     *modulep = addr;
     size = md_copymodules(0, kern64);
     kernend = roundup(addr + size, PAGE_SIZE);
@@ -329,8 +409,12 @@ md_load_dual(char *args, vm_offset_t *modulep, vm_offs
     } else {
 	bcopy(&kernend, md->md_data, sizeof kernend);
     }
-	
+
     (void)md_copymodules(addr, kern64);
+#if defined(LOADER_FDT_SUPPORT)
+    if (dtb != NULL)
+	*dtb = fdtp;
+#endif
 
     return(0);
 }
@@ -341,9 +425,10 @@ md_load(char *args, vm_offset_t *modulep, vm_offset_t 
     return (md_load_dual(args, modulep, dtb, 0));
 }
 
+#if defined(__mips__) || defined(__powerpc__)
 int
 md_load64(char *args, vm_offset_t *modulep, vm_offset_t *dtb)
 {
     return (md_load_dual(args, modulep, dtb, 1));
 }
-
+#endif

Modified: head/stand/loader.mk
==============================================================================
--- head/stand/loader.mk	Tue Feb 13 02:11:39 2018	(r329189)
+++ head/stand/loader.mk	Tue Feb 13 03:44:50 2018	(r329190)
@@ -20,12 +20,16 @@ SRCS+=	load_elf32.c reloc_elf32.c
 .elif ${MACHINE_CPUARCH} == "powerpc"
 SRCS+=	load_elf32.c reloc_elf32.c
 SRCS+=	load_elf64.c reloc_elf64.c
+SRCS+=	metadata.c
 .elif ${MACHINE_CPUARCH} == "sparc64"
 SRCS+=	load_elf64.c reloc_elf64.c
+SRCS+=	metadata.c
 .elif ${MACHINE_ARCH:Mmips64*} != ""
 SRCS+= load_elf64.c reloc_elf64.c
+SRCS+=	metadata.c
 .elif ${MACHINE} == "mips"
 SRCS+=	load_elf32.c reloc_elf32.c
+SRCS+=	metadata.c
 .endif
 
 .if ${LOADER_DISK_SUPPORT:Uyes} == "yes"

Modified: head/stand/mips/beri/loader/Makefile
==============================================================================
--- head/stand/mips/beri/loader/Makefile	Tue Feb 13 02:11:39 2018	(r329189)
+++ head/stand/mips/beri/loader/Makefile	Tue Feb 13 03:44:50 2018	(r329190)
@@ -47,7 +47,6 @@ SRCS=		start.S						\
 		main.c						\
 		devicename.c					\
 		exec.c						\
-		metadata.c					\
 		vers.c						\
 		arch.c
 

Modified: head/stand/mips/beri/loader/exec.c
==============================================================================
--- head/stand/mips/beri/loader/exec.c	Tue Feb 13 02:11:39 2018	(r329189)
+++ head/stand/mips/beri/loader/exec.c	Tue Feb 13 03:44:50 2018	(r329190)
@@ -85,7 +85,7 @@ beri_elf64_exec(struct preloaded_file *fp)
 	}
 	ehdr = (Elf_Ehdr *)md->md_data;
 
-	error = md_load64(fp->f_args, &mdp);
+	error = md_load64(fp->f_args, &mdp, NULL);
 	if (error) {
 		printf("%s: md_load64 failed\n", fp->f_name);
 		return (error);

Modified: head/stand/mips/beri/loader/loader.h
==============================================================================
--- head/stand/mips/beri/loader/loader.h	Tue Feb 13 02:11:39 2018	(r329189)
+++ head/stand/mips/beri/loader/loader.h	Tue Feb 13 03:44:50 2018	(r329190)
@@ -56,7 +56,7 @@ extern char		**boot2_envv;
 extern struct bootinfo	 boot2_bootinfo;
 
 /* metadata.c */
-int	md_load64(char *args, vm_offset_t *modulep);
+int	md_load64(char *args, vm_offset_t *modulep, vm_offset_t *dtbp);
 
 /* vers.c */
 extern char		bootprog_info[];

Modified: head/stand/powerpc/kboot/Makefile
==============================================================================
--- head/stand/powerpc/kboot/Makefile	Tue Feb 13 02:11:39 2018	(r329189)
+++ head/stand/powerpc/kboot/Makefile	Tue Feb 13 03:44:50 2018	(r329190)
@@ -17,7 +17,7 @@ NEWVERSWHAT=	"kboot loader" ${MACHINE_ARCH}
 INSTALLFLAGS=	-b
 
 # Architecture-specific loader code
-SRCS=		conf.c metadata.c vers.c main.c ppc64_elf_freebsd.c
+SRCS=		conf.c vers.c main.c ppc64_elf_freebsd.c
 SRCS+=		host_syscall.S hostcons.c hostdisk.c kerneltramp.S kbootfdt.c
 SRCS+=		ucmpdi2.c
 

Modified: head/stand/powerpc/kboot/main.c
==============================================================================
--- head/stand/powerpc/kboot/main.c	Tue Feb 13 02:11:39 2018	(r329189)
+++ head/stand/powerpc/kboot/main.c	Tue Feb 13 03:44:50 2018	(r329190)
@@ -291,6 +291,7 @@ main(int argc, const char **argv)
 	setenv("currdev", bootdev, 1);
 	setenv("loaddev", bootdev, 1);
 	setenv("LINES", "24", 1);
+	setenv("usefdt", "1", 1);
 
 	interact();			/* doesn't return */
 

Modified: head/stand/powerpc/ofw/Makefile
==============================================================================
--- head/stand/powerpc/ofw/Makefile	Tue Feb 13 02:11:39 2018	(r329189)
+++ head/stand/powerpc/ofw/Makefile	Tue Feb 13 03:44:50 2018	(r329190)
@@ -17,7 +17,7 @@ NEWVERSWHAT=	"Open Firmware loader" ${MACHINE_ARCH}
 INSTALLFLAGS=	-b
 
 # Architecture-specific loader code
-SRCS=		conf.c metadata.c vers.c start.c
+SRCS=		conf.c vers.c start.c
 SRCS+=		ucmpdi2.c
 
 .include	"${BOOTSRC}/fdt.mk"

Modified: head/stand/sparc64/loader/Makefile
==============================================================================
--- head/stand/sparc64/loader/Makefile	Tue Feb 13 02:11:39 2018	(r329189)
+++ head/stand/sparc64/loader/Makefile	Tue Feb 13 03:44:50 2018	(r329190)
@@ -21,7 +21,7 @@ INSTALLFLAGS=	-b
 
 # Architecture-specific loader code
 .PATH:		${BOOTSRC}/sparc64/loader
-SRCS=		locore.S main.c metadata.c vers.c
+SRCS=		locore.S main.c vers.c
 
 .if ${LOADER_DEBUG} == "yes"
 CFLAGS+=	-DLOADER_DEBUG

Modified: head/stand/uboot.mk
==============================================================================
--- head/stand/uboot.mk	Tue Feb 13 02:11:39 2018	(r329189)
+++ head/stand/uboot.mk	Tue Feb 13 03:44:50 2018	(r329190)
@@ -1,6 +1,6 @@
 # $FreeBSD$
 
-SRCS+=	main.c metadata.c
+SRCS+=	main.c
 
 .PATH:		${UBOOTSRC}/common
 
@@ -10,6 +10,9 @@ CFLAGS+=	-I${UBOOTSRC}/common
 LIBUBOOT=	${BOOTOBJ}/uboot/lib/libuboot.a
 CFLAGS+=	-I${UBOOTSRC}/lib
 CFLAGS+=	-I${BOOTOBJ}/uboot/lib
+.if ${MACHINE_CPUARCH} == "arm"
+SRCS+=	metadata.c
+.endif
 
 .include "${BOOTSRC}/fdt.mk"
 

Modified: head/stand/uboot/lib/elf_freebsd.c
==============================================================================
--- head/stand/uboot/lib/elf_freebsd.c	Tue Feb 13 02:11:39 2018	(r329189)
+++ head/stand/uboot/lib/elf_freebsd.c	Tue Feb 13 03:44:50 2018	(r329190)
@@ -44,7 +44,7 @@ __FBSDID("$FreeBSD$");
 #include "bootstrap.h"
 #include "libuboot.h"
 
-extern vm_offset_t md_load(char *, vm_offset_t *);
+extern vm_offset_t md_load(char *, vm_offset_t *, vm_offset_t *);
 
 int
 __elfN(uboot_load)(char *filename, u_int64_t dest,
@@ -81,7 +81,7 @@ __elfN(uboot_exec)(struct preloaded_file *fp)
 
 	e = (Elf_Ehdr *)&fmp->md_data;
 
-	if ((error = md_load(fp->f_args, &mdp)) != 0)
+	if ((error = md_load(fp->f_args, &mdp, NULL)) != 0)
 		return (error);
 
 	entry = (void *)e->e_entry;



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