From owner-svn-src-stable@freebsd.org Thu May 31 20:01:59 2018 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B6661FD4E9A; Thu, 31 May 2018 20:01:59 +0000 (UTC) (envelope-from gjb@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 646117BA9E; Thu, 31 May 2018 20:01:59 +0000 (UTC) (envelope-from gjb@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 460E11ED8C; Thu, 31 May 2018 20:01:59 +0000 (UTC) (envelope-from gjb@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w4VK1xgC093223; Thu, 31 May 2018 20:01:59 GMT (envelope-from gjb@FreeBSD.org) Received: (from gjb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w4VK1wgq093221; Thu, 31 May 2018 20:01:58 GMT (envelope-from gjb@FreeBSD.org) Message-Id: <201805312001.w4VK1wgq093221@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: gjb set sender to gjb@FreeBSD.org using -f From: Glen Barber Date: Thu, 31 May 2018 20:01:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r334444 - in stable/11: release/amd64 stand/efi/boot1 X-SVN-Group: stable-11 X-SVN-Commit-Author: gjb X-SVN-Commit-Paths: in stable/11: release/amd64 stand/efi/boot1 X-SVN-Commit-Revision: 334444 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 May 2018 20:02:00 -0000 Author: gjb Date: Thu May 31 20:01:58 2018 New Revision: 334444 URL: https://svnweb.freebsd.org/changeset/base/334444 Log: MFC r334310, r334337: r334310 (imp): Teach ufs_module.c about bsd labels and probe 'a' partition. If the check for a UFS partition at offset 0 on the disk fails, check to see if there's a BSD disklabel at block 1 (standard) or at offset 512 (install images assume 512 sector size). If found, probe for UFS on the 'a' partition. This fixes UEFI booting images from a BSD labeled MBR slice when the 'a' partiton isn't at offset 0. This is a stop-gap fix since we plan on removing boot1.efi in FreeBSD 12. We can't easily do that for 11.2, however, hence the short MFC window. r334337 (emaste): switch amd64 memstick installer images to MBR A good number of BIOSes have trouble booting from GPT in non-UEFI mode. With this change amd64 memsticks remain dual-mode (booting from either UEFI or CSM); the partitioning type is just switched from GPT to MBR. PR: 227954 Note, there are two changes specific to stable/11 where there is code that had diverged from head and never merged back. The two changes are an include in stand/efi/boot1/ufs_module.c, replacing sys/disk/bsd.h with sys/disklabel.h and replacing BSD_MAGIC with DISKMAGIC in the same file. The latter two are direct commits to stable/11 in order to avoid unexpected regressions at this point of the 11.2 cycle. Thank you to imp@ for pointing out what changes needed to be made. Approved by: re (marius) Sponsored by: The FreeBSD Foundation Modified: stable/11/release/amd64/make-memstick.sh stable/11/stand/efi/boot1/boot_module.h stable/11/stand/efi/boot1/ufs_module.c Directory Properties: stable/11/ (props changed) Modified: stable/11/release/amd64/make-memstick.sh ============================================================================== --- stable/11/release/amd64/make-memstick.sh Thu May 31 19:36:24 2018 (r334443) +++ stable/11/release/amd64/make-memstick.sh Thu May 31 20:01:58 2018 (r334444) @@ -36,12 +36,11 @@ makefs -B little -o label=FreeBSD_Install -o version=2 rm ${1}/etc/fstab rm ${1}/etc/rc.conf.local -mkimg -s gpt \ - -b ${1}/boot/pmbr \ +mkimg -s mbr \ + -b ${1}/boot/mbr \ -p efi:=${1}/boot/boot1.efifat \ - -p freebsd-boot:=${1}/boot/gptboot \ - -p freebsd-ufs:=${2}.part \ - -p freebsd-swap::1M \ + -p freebsd:-"mkimg -s bsd -b ${1}/boot/boot -p freebsd-ufs:=${2}.part" \ + -a 2 \ -o ${2} rm ${2}.part Modified: stable/11/stand/efi/boot1/boot_module.h ============================================================================== --- stable/11/stand/efi/boot1/boot_module.h Thu May 31 19:36:24 2018 (r334443) +++ stable/11/stand/efi/boot1/boot_module.h Thu May 31 20:01:58 2018 (r334444) @@ -50,6 +50,7 @@ typedef struct dev_info EFI_DEVICE_PATH *devpath; EFI_HANDLE *devhandle; void *devdata; + uint64_t partoff; BOOLEAN preferred; struct dev_info *next; } dev_info_t; Modified: stable/11/stand/efi/boot1/ufs_module.c ============================================================================== --- stable/11/stand/efi/boot1/ufs_module.c Thu May 31 19:36:24 2018 (r334443) +++ stable/11/stand/efi/boot1/ufs_module.c Thu May 31 20:01:58 2018 (r334444) @@ -36,10 +36,14 @@ #include #include #include +#include #include #include "boot_module.h" +#define BSD_LABEL_BUFFER 8192 +#define BSD_LABEL_OFFSET DEV_BSIZE + static dev_info_t *devinfo; static dev_info_t *devices; @@ -49,6 +53,7 @@ dskread(void *buf, uint64_t lba, int nblk) int size; EFI_STATUS status; + lba += devinfo->partoff; lba = lba / (devinfo->dev->Media->BlockSize / DEV_BSIZE); size = nblk * DEV_BSIZE; @@ -73,11 +78,50 @@ static struct dmadat __dmadat; static int init_dev(dev_info_t* dev) { + char buffer[BSD_LABEL_BUFFER]; + struct disklabel *dl; + uint64_t bs; + int ok; devinfo = dev; dmadat = &__dmadat; - return fsread(0, NULL, 0); + /* + * First try offset 0. This is the typical GPT case where we have no + * further partitioning (as well as the degenerate MBR case where + * the bsdlabel has a 0 offset). + */ + devinfo->partoff = 0; + ok = fsread(0, NULL, 0); + if (ok >= 0) + return (ok); + + /* + * Next, we look for a bsdlabel. This is technically located in sector + * 1. For 4k sectors, this offset is 4096, for 512b sectors it's + * 512. However, we have to fall back to 512 here because we create + * images that assume 512 byte blocks, but these can be put on devices + * who have 4k (or other) block sizes. If there's a crazy block size, we + * skip the 'at one sector' and go stright to checking at 512 bytes. + * There are other offsets that are historic, but we don't probe those + * since they were never used for MBR disks on FreeBSD on systems that + * could boot UEFI. UEFI is little endian only, as are BSD labels. We + * will retry fsread(0) only if there's a label found with a non-zero + * offset. + */ + if (dskread(buffer, 0, BSD_LABEL_BUFFER / DEV_BSIZE) != 0) + return (-1); + dl = NULL; + bs = devinfo->dev->Media->BlockSize; + if (bs != 0 && bs <= BSD_LABEL_BUFFER / 2) + dl = (struct disklabel *)&buffer[bs]; + if (dl == NULL || dl->d_magic != DISKMAGIC || dl->d_magic2 != DISKMAGIC) + dl = (struct disklabel *)&buffer[BSD_LABEL_OFFSET]; + if (dl->d_magic != DISKMAGIC || dl->d_magic2 != DISKMAGIC || + dl->d_partitions[0].p_offset == 0) + return (-1); + devinfo->partoff = dl->d_partitions[0].p_offset; + return (fsread(0, NULL, 0)); } static EFI_STATUS