Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 4 Sep 2014 21:05:05 +0000 (UTC)
From:      Ed Maste <emaste@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r271136 - in stable/10/sys/boot/amd64: . boot1.efi
Message-ID:  <201409042105.s84L55Oa052196@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: emaste
Date: Thu Sep  4 21:05:04 2014
New Revision: 271136
URL: http://svnweb.freebsd.org/changeset/base/271136

Log:
  MFC boot1.efi stub loader
  
  r264391 (nwhitehorn):
  
    Add a simple EFI stub loader. This is a quick and dirty of boot1.chrp
    from the PowerPC port with all the Open Firmware bits removed and
    replaced by their EFI counterparts. On the whole, I think I prefer
    Open Firmware.
  
    This code is supposed to be an immutable shim that sits on the EFI
    system partition, loads /boot/loader.efi from UFS and tells the real
    loader what disk/partition to look at. It finds the UFS root partition
    by the somewhat braindead approach of picking the first UFS partition
    it can find. Better approaches are called for, but this works for now.
    This shim loader will also be useful for secure boot in the future,
    which will require some rearchitecture.
  
  r264403 (nwhitehorn):
  
    Fix buildworld. I had some local bits in my build tree that caused
    this to work by accident.
  
  r264404 (nwhitehorn):
  
    Add my copyright here. Most of this is unmodified from the original
    sparc64 version, but at least some indication of changes that postdate
    the actual invention of EFI is probably a good idea.
  
  r264414 (nwhitehorn):
  
    Apparently some of the i386 boot blocks are so close to full that
    adding single lines to ufsread.c spills them over. Duplicate a whole
    bunch of code to get file sizes into boot1.efi/boot1.c rather than
    modifying ufsread.c.
  
  r264975 (nwhitehorn):
  
    Add generation of an EFI filesystem to hold boot1.efi. This is a near-
    exact copy of the code from boot1.chrp again.
  
    The resulting image is installed to /boot/boot1.efifat. If dd'ed to an
    800K "efi" partition, it should result in a bootable system.
  
  r268975 (sbruno): Remove boot1.efi during clean target.
  
  Relnotes:	Yes
  Sponsored by:	The FreeBSD Foundation

Added:
  stable/10/sys/boot/amd64/boot1.efi/
     - copied from r264391, head/sys/boot/amd64/boot1.efi/
  stable/10/sys/boot/amd64/boot1.efi/Makefile.fat
     - copied unchanged from r264975, head/sys/boot/amd64/boot1.efi/Makefile.fat
  stable/10/sys/boot/amd64/boot1.efi/fat.tmpl.bz2.uu
     - copied unchanged from r264975, head/sys/boot/amd64/boot1.efi/fat.tmpl.bz2.uu
  stable/10/sys/boot/amd64/boot1.efi/generate-fat.sh
     - copied unchanged from r264975, head/sys/boot/amd64/boot1.efi/generate-fat.sh
Modified:
  stable/10/sys/boot/amd64/Makefile
  stable/10/sys/boot/amd64/boot1.efi/Makefile
  stable/10/sys/boot/amd64/boot1.efi/boot1.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/boot/amd64/Makefile
==============================================================================
--- stable/10/sys/boot/amd64/Makefile	Thu Sep  4 21:01:10 2014	(r271135)
+++ stable/10/sys/boot/amd64/Makefile	Thu Sep  4 21:05:04 2014	(r271136)
@@ -2,6 +2,6 @@
 
 .include <bsd.own.mk>
 
-SUBDIR=		efi
+SUBDIR=		efi boot1.efi
 
 .include <bsd.subdir.mk>

Modified: stable/10/sys/boot/amd64/boot1.efi/Makefile
==============================================================================
--- head/sys/boot/amd64/boot1.efi/Makefile	Sun Apr 13 01:14:25 2014	(r264391)
+++ stable/10/sys/boot/amd64/boot1.efi/Makefile	Thu Sep  4 21:05:04 2014	(r271136)
@@ -22,11 +22,11 @@ CFLAGS+=	-I${.CURDIR}/../../efi/include/
 CFLAGS+=	-I${.CURDIR}/../../../contrib/dev/acpica/include
 CFLAGS+=	-I${.CURDIR}/../../..
 
-# Always add MI sources 
-.PATH:		${.CURDIR}/../../common ../efi
+# Always add MI sources and REGULAR efi loader bits
+.PATH:		${.CURDIR}/../efi ${.CURDIR}/../../common
 CFLAGS+=	-I${.CURDIR}/../../common
 
-FILES=	boot1.efi
+FILES=	boot1.efi boot1.efifat
 FILESMODE_boot1.efi=	${BINMODE}
 
 LDSCRIPT=	${.CURDIR}/../efi/ldscript.${MACHINE_CPUARCH}
@@ -55,13 +55,29 @@ boot1.efi: loader.sym
 
 CFLAGS+=	-I${.CURDIR}/../../common
 
+boot1.o: ${.CURDIR}/../../common/ufsread.c
+
+# The following inserts out objects into a template FAT file system
+# created by generate-fat.sh
+
+.include "${.CURDIR}/Makefile.fat"
+
+boot1.efifat: boot1.efi
+	echo ${.OBJDIR}
+	uudecode ${.CURDIR}/fat.tmpl.bz2.uu
+	mv fat.tmpl.bz2 ${.TARGET}.bz2
+	bzip2 -f -d ${.TARGET}.bz2
+	dd if=boot1.efi of=${.TARGET} seek=${BOOT1_OFFSET} conv=notrunc
+
+CLEANFILES= boot1.efifat
+
 .endif # ${COMPILER_TYPE} != "gcc"
 
 .include <bsd.prog.mk>
 
 beforedepend ${OBJS}: machine x86
 
-CLEANFILES+=   machine x86
+CLEANFILES+=   machine x86 boot1.efi
 
 machine:
 	ln -sf ${.CURDIR}/../../../amd64/include machine

Copied: stable/10/sys/boot/amd64/boot1.efi/Makefile.fat (from r264975, head/sys/boot/amd64/boot1.efi/Makefile.fat)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/10/sys/boot/amd64/boot1.efi/Makefile.fat	Thu Sep  4 21:05:04 2014	(r271136, copy of r264975, head/sys/boot/amd64/boot1.efi/Makefile.fat)
@@ -0,0 +1,3 @@
+# This file autogenerated by generate-fat.sh - DO NOT EDIT
+# $FreeBSD$
+BOOT1_OFFSET=0x2d

Modified: stable/10/sys/boot/amd64/boot1.efi/boot1.c
==============================================================================
--- head/sys/boot/amd64/boot1.efi/boot1.c	Sun Apr 13 01:14:25 2014	(r264391)
+++ stable/10/sys/boot/amd64/boot1.efi/boot1.c	Thu Sep  4 21:05:04 2014	(r271136)
@@ -3,6 +3,8 @@
  * All rights reserved.
  * Copyright (c) 2001 Robert Drehmel
  * All rights reserved.
+ * Copyright (c) 2014 Nathan Whitehorn
+ * All rights reserved.
  *
  * Redistribution and use in source and binary forms are freely
  * permitted provided that the above copyright notice and this
@@ -167,6 +169,88 @@ dskread(void *buf, u_int64_t lba, int nb
 
 #include "ufsread.c"
 
+static ssize_t
+fsstat(ufs_ino_t inode)
+{
+#ifndef UFS2_ONLY
+	static struct ufs1_dinode dp1;
+	ufs1_daddr_t addr1;
+#endif
+#ifndef UFS1_ONLY
+	static struct ufs2_dinode dp2;
+#endif
+	static struct fs fs;
+	static ufs_ino_t inomap;
+	char *blkbuf;
+	void *indbuf;
+	size_t n, nb, size, off, vboff;
+	ufs_lbn_t lbn;
+	ufs2_daddr_t addr2, vbaddr;
+	static ufs2_daddr_t blkmap, indmap;
+	u_int u;
+
+	blkbuf = dmadat->blkbuf;
+	indbuf = dmadat->indbuf;
+	if (!dsk_meta) {
+		inomap = 0;
+		for (n = 0; sblock_try[n] != -1; n++) {
+			if (dskread(dmadat->sbbuf, sblock_try[n] / DEV_BSIZE,
+			    SBLOCKSIZE / DEV_BSIZE))
+				return -1;
+			memcpy(&fs, dmadat->sbbuf, sizeof(struct fs));
+			if ((
+#if defined(UFS1_ONLY)
+			    fs.fs_magic == FS_UFS1_MAGIC
+#elif defined(UFS2_ONLY)
+			    (fs.fs_magic == FS_UFS2_MAGIC &&
+			    fs.fs_sblockloc == sblock_try[n])
+#else
+			    fs.fs_magic == FS_UFS1_MAGIC ||
+			    (fs.fs_magic == FS_UFS2_MAGIC &&
+			    fs.fs_sblockloc == sblock_try[n])
+#endif
+			    ) &&
+			    fs.fs_bsize <= MAXBSIZE &&
+			    fs.fs_bsize >= sizeof(struct fs))
+				break;
+		}
+		if (sblock_try[n] == -1) {
+			printf("Not ufs\n");
+			return -1;
+		}
+		dsk_meta++;
+	} else
+		memcpy(&fs, dmadat->sbbuf, sizeof(struct fs));
+	if (!inode)
+		return 0;
+	if (inomap != inode) {
+		n = IPERVBLK(&fs);
+		if (dskread(blkbuf, INO_TO_VBA(&fs, n, inode), DBPERVBLK))
+			return -1;
+		n = INO_TO_VBO(n, inode);
+#if defined(UFS1_ONLY)
+		memcpy(&dp1, (struct ufs1_dinode *)blkbuf + n,
+		    sizeof(struct ufs1_dinode));
+#elif defined(UFS2_ONLY)
+		memcpy(&dp2, (struct ufs2_dinode *)blkbuf + n,
+		    sizeof(struct ufs2_dinode));
+#else
+		if (fs.fs_magic == FS_UFS1_MAGIC)
+			memcpy(&dp1, (struct ufs1_dinode *)blkbuf + n,
+			    sizeof(struct ufs1_dinode));
+		else
+			memcpy(&dp2, (struct ufs2_dinode *)blkbuf + n,
+			    sizeof(struct ufs2_dinode));
+#endif
+		inomap = inode;
+		fs_off = 0;
+		blkmap = indmap = 0;
+	}
+	size = DIP(di_size);
+	n = size - fs_off;
+	return (n);
+}
+
 static struct dmadat __dmadat;
                 
 static int
@@ -201,7 +285,7 @@ load(const char *fname)
 		return;
 	}
 
-	bufsize = fsread(ino, NULL, -1);
+	bufsize = fsstat(ino);
 	status = systab->BootServices->AllocatePool(EfiLoaderData,
 	    bufsize, &buffer);
 	fsread(ino, buffer, bufsize);

Copied: stable/10/sys/boot/amd64/boot1.efi/fat.tmpl.bz2.uu (from r264975, head/sys/boot/amd64/boot1.efi/fat.tmpl.bz2.uu)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/10/sys/boot/amd64/boot1.efi/fat.tmpl.bz2.uu	Thu Sep  4 21:05:04 2014	(r271136, copy of r264975, head/sys/boot/amd64/boot1.efi/fat.tmpl.bz2.uu)
@@ -0,0 +1,22 @@
+FAT template boot filesystem created by generate-fat.sh
+DO NOT EDIT
+$FreeBSD$
+begin 644 fat.tmpl.bz2
+M0EIH.3%!62936?1V`!$`&J7____[ZZKJJ_^N_ZO^Z_^[ON_\`4`00!0$#$$"
+M0D)$6&(<P`(Y=SNY1(2DHTC":::-`!H`&@-````#)IH#3(&@:`!IIDT--,@E
+M53TFCWZJGJ`-!D`-`#(::```:```&@:!D`!D``&*B3:C]4T]0#0`:``-`T``
+M``````````&@)131/4T-*>IZC3RGZH\B&$,U&AH#)B:,$8TAF@@]0T>IZF&A
+M&GZID,1IZFAMO%FPGL0"(QIZV"3_!`$@N(@`DD$?C&$["`)`!)$6@#\HOB42
+M0`"2(X0FGX1#L"`'7E,'#-'HM!'QUD0\R,?9U,6ZE8F,Y6*L<9S<6PH)"%_"
+MX'_PL4A),QB"(`B(=14*-"8,(QCG.(2$A(1J'010CB&R$(0B00FPP(0A"$)E
+M#`A"$(1]LB&!"$(0B4&1#`A"$(14W<9J.:&A@8&!@8'`Z$(D(02@^L=UL>:+
+MBG:Q5+4&'[/P4@D2?M<,E!0&YBF8+],4^%$`4<YVD4=K")O.IZ\#)``!CU-1
+M``!L%C7V^RL80`#K(AUU+"D])9/B4@>*%$N9MF:Z29-_VG2G7<$LJ-44RST&
+MB53YE@H%(G5G$.FU;=L[DQVA]"(V4B1+%BP%.A<-10-%#R#NKR='@\'#"_'U
+M'I36ZT:8QIN*3E$:HZIZRJ?$Y1L&<1'C)G(=8,E.L(KU<9X=%/NX.6\=@^IW
+M\-PC$B&I"T\!(VI3"K!X:\%.01Y#X/83[SH.J*H5BH:ILFV1'X/D/V1$W6'\
+MFY>YE:*(I!.X@'D>H_(PY'(W1+B;:,Y?H8Y%(Q')!>DDE;\J1-DRXJJ/O(1@
+M'X/24=!+/V8S1)B(R:UE"0&&1:PUS(1`!$04``++GZ/8(CE5P1P8?^7QB[DB
+(G"A(>CL`"(``
+`
+end

Copied: stable/10/sys/boot/amd64/boot1.efi/generate-fat.sh (from r264975, head/sys/boot/amd64/boot1.efi/generate-fat.sh)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/10/sys/boot/amd64/boot1.efi/generate-fat.sh	Thu Sep  4 21:05:04 2014	(r271136, copy of r264975, head/sys/boot/amd64/boot1.efi/generate-fat.sh)
@@ -0,0 +1,54 @@
+#!/bin/sh
+
+# This script generates the dummy FAT filesystem used for the EFI boot
+# blocks. It uses newfs_msdos to generate a template filesystem with the
+# relevant interesting files. These are then found by grep, and the offsets
+# written to a Makefile snippet.
+#
+# Because it requires root, and because it is overkill, we do not
+# do this as part of the normal build. If makefs(8) grows workable FAT
+# support, this should be revisited.
+
+# $FreeBSD$
+
+FAT_SIZE=1600 			#Size in 512-byte blocks of the produced image
+
+BOOT1_SIZE=64k
+
+# Generate 800K FAT image
+OUTPUT_FILE=fat.tmpl
+
+dd if=/dev/zero of=$OUTPUT_FILE bs=512 count=$FAT_SIZE
+DEVICE=`mdconfig -a -f $OUTPUT_FILE`
+newfs_msdos -F 12 $DEVICE
+mkdir stub
+mount -t msdosfs /dev/$DEVICE stub
+
+# Create and bless a directory for the boot loader
+mkdir -p stub/efi/boot
+
+# Make a dummy file for boot1
+echo 'Boot1 START' | dd of=stub/efi/boot/BOOTx64.efi cbs=$BOOT1_SIZE count=1 conv=block
+
+umount stub
+mdconfig -d -u $DEVICE
+rmdir stub
+
+# Locate the offsets of the two fake files
+BOOT1_OFFSET=$(hd $OUTPUT_FILE | grep 'Boot1 START' | cut -f 1 -d ' ')
+
+# Convert to numbers of blocks
+BOOT1_OFFSET=$(echo 0x$BOOT1_OFFSET | awk '{printf("%x\n",$1/512);}')
+
+echo '# This file autogenerated by generate-fat.sh - DO NOT EDIT' > Makefile.fat
+echo '# $FreeBSD$' >> Makefile.fat
+echo "BOOT1_OFFSET=0x$BOOT1_OFFSET" >> Makefile.fat
+
+bzip2 $OUTPUT_FILE
+echo 'FAT template boot filesystem created by generate-fat.sh' > $OUTPUT_FILE.bz2.uu
+echo 'DO NOT EDIT' >> $OUTPUT_FILE.bz2.uu
+echo '$FreeBSD$' >> $OUTPUT_FILE.bz2.uu
+
+uuencode $OUTPUT_FILE.bz2 $OUTPUT_FILE.bz2 >> $OUTPUT_FILE.bz2.uu
+rm $OUTPUT_FILE.bz2
+



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