Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 6 Apr 2018 20:24:51 +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: r332150 - in stable/11/stand: . common mips/beri/loader powerpc/kboot powerpc/ofw sparc64/loader uboot/common uboot/lib
Message-ID:  <201804062024.w36KOpTi058529@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Fri Apr  6 20:24:50 2018
New Revision: 332150
URL: https://svnweb.freebsd.org/changeset/base/332150

Log:
  MFC r329190, r329315, r330131: metadata load file unification
  
  r329190: 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.
  
  r329315: stand: Fix ubldr after r329190
  
  metadata load files were consolidated in r329190, and these relocation fixup
  bits were inadvertently dropped in the process. Re-add them to fix boot with
  ubldr.
  
  r330131: Fix module loading on arm after the metadata.c unification in
  r329190. Arm modules need an additional address fixup not needed by other
  platforms.

Added:
  stable/11/stand/common/metadata.c
     - copied, changed from r329190, head/stand/common/metadata.c
Deleted:
  stable/11/stand/mips/beri/loader/metadata.c
  stable/11/stand/powerpc/kboot/metadata.c
  stable/11/stand/powerpc/ofw/metadata.c
  stable/11/stand/sparc64/loader/metadata.c
  stable/11/stand/uboot/common/metadata.c
Modified:
  stable/11/stand/loader.mk
  stable/11/stand/mips/beri/loader/Makefile
  stable/11/stand/mips/beri/loader/exec.c
  stable/11/stand/mips/beri/loader/loader.h
  stable/11/stand/powerpc/kboot/Makefile
  stable/11/stand/powerpc/kboot/main.c
  stable/11/stand/powerpc/ofw/Makefile
  stable/11/stand/sparc64/loader/Makefile
  stable/11/stand/uboot.mk
  stable/11/stand/uboot/lib/elf_freebsd.c
Directory Properties:
  stable/11/   (props changed)

Copied and modified: stable/11/stand/common/metadata.c (from r329190, head/stand/common/metadata.c)
==============================================================================
--- head/stand/common/metadata.c	Tue Feb 13 03:44:50 2018	(r329190, copy source)
+++ stable/11/stand/common/metadata.c	Fri Apr  6 20:24:50 2018	(r332150)
@@ -38,6 +38,9 @@ __FBSDID("$FreeBSD$");
 #include <fdt_platform.h>
 #endif
 
+#ifdef __arm__
+#include <machine/elf.h>
+#endif
 #include <machine/metadata.h>
 
 #include "bootstrap.h"
@@ -262,6 +265,7 @@ md_copymodules(vm_offset_t addr, int kern64)
     struct preloaded_file	*fp;
     struct file_metadata	*md;
     uint64_t			scratch64;
+    uint32_t			scratch32;
     int				c;
 
     c = addr != 0;
@@ -278,7 +282,11 @@ md_copymodules(vm_offset_t addr, int kern64)
 		scratch64 = fp->f_size;
 		MOD_SIZE(addr, scratch64, c);
 	} else {
-		MOD_ADDR(addr, fp->f_addr, c);
+		scratch32 = fp->f_addr;
+#ifdef __arm__
+		scratch32 -= __elfN(relocation_offset);
+#endif
+		MOD_ADDR(addr, scratch32, c);
 		MOD_SIZE(addr, fp->f_size, c);
 	}
 	for (md = fp->f_metadata; md != NULL; md = md->md_next) {
@@ -315,7 +323,23 @@ md_load_dual(char *args, vm_offset_t *modulep, vm_offs
     uint64_t			scratch64;
     char			*rootdevname;
     int				howto;
+#ifdef __arm__
+    vm_offset_t			vaddr;
+    int				i;
 
+	/*
+	 * These metadata addreses must be converted for kernel after
+	 * relocation.
+	 */
+    uint32_t			mdt[] = {
+	    MODINFOMD_SSYM, MODINFOMD_ESYM, MODINFOMD_KERNEND,
+	    MODINFOMD_ENVP,
+#if defined(LOADER_FDT_SUPPORT)
+	    MODINFOMD_DTBP
+#endif
+    };
+#endif
+
     align = kern64 ? 8 : 4;
     howto = md_getboothowto(args);
 
@@ -409,6 +433,23 @@ md_load_dual(char *args, vm_offset_t *modulep, vm_offs
     } else {
 	bcopy(&kernend, md->md_data, sizeof kernend);
     }
+
+#ifdef __arm__
+    /* Convert addresses to the final VA */
+    *modulep -= __elfN(relocation_offset);
+
+    /* Do relocation fixup on metadata of each module. */
+    for (xp = file_findfile(NULL, NULL); xp != NULL; xp = xp->f_next) {
+        for (i = 0; i < nitems(mdt); i++) {
+            md = file_findmetadata(xp, mdt[i]);
+                if (md) {
+                    bcopy(md->md_data, &vaddr, sizeof vaddr);
+                    vaddr -= __elfN(relocation_offset);
+                    bcopy(&vaddr, md->md_data, sizeof vaddr);
+                }
+            }
+    }
+#endif
 
     (void)md_copymodules(addr, kern64);
 #if defined(LOADER_FDT_SUPPORT)

Modified: stable/11/stand/loader.mk
==============================================================================
--- stable/11/stand/loader.mk	Fri Apr  6 19:59:27 2018	(r332149)
+++ stable/11/stand/loader.mk	Fri Apr  6 20:24:50 2018	(r332150)
@@ -22,12 +22,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: stable/11/stand/mips/beri/loader/Makefile
==============================================================================
--- stable/11/stand/mips/beri/loader/Makefile	Fri Apr  6 19:59:27 2018	(r332149)
+++ stable/11/stand/mips/beri/loader/Makefile	Fri Apr  6 20:24:50 2018	(r332150)
@@ -47,7 +47,6 @@ SRCS=		start.S						\
 		main.c						\
 		devicename.c					\
 		exec.c						\
-		metadata.c					\
 		vers.c						\
 		arch.c
 

Modified: stable/11/stand/mips/beri/loader/exec.c
==============================================================================
--- stable/11/stand/mips/beri/loader/exec.c	Fri Apr  6 19:59:27 2018	(r332149)
+++ stable/11/stand/mips/beri/loader/exec.c	Fri Apr  6 20:24:50 2018	(r332150)
@@ -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: stable/11/stand/mips/beri/loader/loader.h
==============================================================================
--- stable/11/stand/mips/beri/loader/loader.h	Fri Apr  6 19:59:27 2018	(r332149)
+++ stable/11/stand/mips/beri/loader/loader.h	Fri Apr  6 20:24:50 2018	(r332150)
@@ -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: stable/11/stand/powerpc/kboot/Makefile
==============================================================================
--- stable/11/stand/powerpc/kboot/Makefile	Fri Apr  6 19:59:27 2018	(r332149)
+++ stable/11/stand/powerpc/kboot/Makefile	Fri Apr  6 20:24:50 2018	(r332150)
@@ -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: stable/11/stand/powerpc/kboot/main.c
==============================================================================
--- stable/11/stand/powerpc/kboot/main.c	Fri Apr  6 19:59:27 2018	(r332149)
+++ stable/11/stand/powerpc/kboot/main.c	Fri Apr  6 20:24:50 2018	(r332150)
@@ -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: stable/11/stand/powerpc/ofw/Makefile
==============================================================================
--- stable/11/stand/powerpc/ofw/Makefile	Fri Apr  6 19:59:27 2018	(r332149)
+++ stable/11/stand/powerpc/ofw/Makefile	Fri Apr  6 20:24:50 2018	(r332150)
@@ -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: stable/11/stand/sparc64/loader/Makefile
==============================================================================
--- stable/11/stand/sparc64/loader/Makefile	Fri Apr  6 19:59:27 2018	(r332149)
+++ stable/11/stand/sparc64/loader/Makefile	Fri Apr  6 20:24:50 2018	(r332150)
@@ -25,7 +25,7 @@ HAVE_ZFS=	yes
 
 # 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: stable/11/stand/uboot.mk
==============================================================================
--- stable/11/stand/uboot.mk	Fri Apr  6 19:59:27 2018	(r332149)
+++ stable/11/stand/uboot.mk	Fri Apr  6 20:24:50 2018	(r332150)
@@ -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: stable/11/stand/uboot/lib/elf_freebsd.c
==============================================================================
--- stable/11/stand/uboot/lib/elf_freebsd.c	Fri Apr  6 19:59:27 2018	(r332149)
+++ stable/11/stand/uboot/lib/elf_freebsd.c	Fri Apr  6 20:24:50 2018	(r332150)
@@ -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?201804062024.w36KOpTi058529>