CVS commit: src/sys/arch/i386/stand/bootxx
Module Name:src Committed By: tsutsui Date: Fri Dec 8 16:29:04 UTC 2023 Modified Files: src/sys/arch/i386/stand/bootxx: pbr.S Log Message: Replace several magic numbers with macro to describe GPT's hybrid MBR boot. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/sys/arch/i386/stand/bootxx/pbr.S Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/i386/stand/bootxx/pbr.S diff -u src/sys/arch/i386/stand/bootxx/pbr.S:1.23 src/sys/arch/i386/stand/bootxx/pbr.S:1.24 --- src/sys/arch/i386/stand/bootxx/pbr.S:1.23 Wed May 11 14:58:00 2022 +++ src/sys/arch/i386/stand/bootxx/pbr.S Fri Dec 8 16:29:04 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: pbr.S,v 1.23 2022/05/11 14:58:00 andvar Exp $ */ +/* $NetBSD: pbr.S,v 1.24 2023/12/08 16:29:04 tsutsui Exp $ */ /*- * Copyright (c) 2003,2004 The NetBSD Foundation, Inc. @@ -71,6 +71,10 @@ #define MBR_AFTERBPB 62 /* BPB size in floppy master BR */ #endif +#define GPT_MAGIC 0x54504721 /* '!GPT' magic on hybrid MBR boot */ +#define GPT_ENTRY_OFF 20 /* GPT part entry in handover struct */ +#define GPT_ENT_LBA_OFF 32 /* ent_lba_start in struct gpt_ent */ + #ifdef TERSE_ERROR /* * Error codes. Done this way to save space. @@ -127,7 +131,7 @@ start0: mov %cx, %sp mov %cx, %es #ifndef BOOT_FROM_FAT - cmpl $0x54504721, %eax /* did a GPT hybrid MBR start us? */ + cmpl $GPT_MAGIC, %eax /* did a GPT hybrid MBR start us? */ je boot_gpt #endif mov %cx, %ds @@ -366,8 +370,9 @@ chs_read: #ifndef BOOT_FROM_FAT boot_gpt: - movl (20+32+0)(%si), %ebp - movl (20+32+4)(%si), %edi + /* DS:SI has a pointer to the hybrid MBR handover structure */ + movl (GPT_ENTRY_OFF+GPT_ENT_LBA_OFF+0)(%si), %ebp + movl (GPT_ENTRY_OFF+GPT_ENT_LBA_OFF+4)(%si), %edi movw %cx, %ds movl %ebp, lba_sector + 0 movl %edi, lba_sector + 4
CVS commit: src/sys/arch/i386/stand/bootxx
Module Name:src Committed By: tsutsui Date: Fri Dec 8 16:29:04 UTC 2023 Modified Files: src/sys/arch/i386/stand/bootxx: pbr.S Log Message: Replace several magic numbers with macro to describe GPT's hybrid MBR boot. To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/sys/arch/i386/stand/bootxx/pbr.S Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/arch/i386/stand/bootxx
Module Name:src Committed By: christos Date: Wed Aug 30 18:46:52 UTC 2023 Modified Files: src/sys/arch/i386/stand/bootxx/bootxx_msdos: Makefile src/sys/arch/i386/stand/bootxx/bootxx_ustarfs: Makefile Log Message: Override these two booters with -Oz for clang since it produces smaller code here. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/arch/i386/stand/bootxx/bootxx_msdos/Makefile cvs rdiff -u -r1.3 -r1.4 \ src/sys/arch/i386/stand/bootxx/bootxx_ustarfs/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/i386/stand/bootxx/bootxx_msdos/Makefile diff -u src/sys/arch/i386/stand/bootxx/bootxx_msdos/Makefile:1.4 src/sys/arch/i386/stand/bootxx/bootxx_msdos/Makefile:1.5 --- src/sys/arch/i386/stand/bootxx/bootxx_msdos/Makefile:1.4 Wed Jan 22 01:13:18 2020 +++ src/sys/arch/i386/stand/bootxx/bootxx_msdos/Makefile Wed Aug 30 14:46:51 2023 @@ -1,7 +1,11 @@ -# $NetBSD: Makefile,v 1.4 2020/01/22 06:13:18 martin Exp $ +# $NetBSD: Makefile,v 1.5 2023/08/30 18:46:51 christos Exp $ + +NOMAN=yes +.include PROG= bootxx_msdos FS= dosfs CPPFLAGS=-DBOOT_FROM_FAT -DTERSE_ERROR -DSA_DOSFS_NO_BIG_PART_SUPPORT .include <../Makefile.bootxx> +OPT_SIZE.clang += -Oz Index: src/sys/arch/i386/stand/bootxx/bootxx_ustarfs/Makefile diff -u src/sys/arch/i386/stand/bootxx/bootxx_ustarfs/Makefile:1.3 src/sys/arch/i386/stand/bootxx/bootxx_ustarfs/Makefile:1.4 --- src/sys/arch/i386/stand/bootxx/bootxx_ustarfs/Makefile:1.3 Wed Nov 18 16:02:16 2009 +++ src/sys/arch/i386/stand/bootxx/bootxx_ustarfs/Makefile Wed Aug 30 14:46:52 2023 @@ -1,7 +1,11 @@ -# $NetBSD: Makefile,v 1.3 2009/11/18 21:02:16 dsl Exp $ +# $NetBSD: Makefile,v 1.4 2023/08/30 18:46:52 christos Exp $ + +NOMAN=yes +.include FS=ustarfs BOOTXX_SECTORS=16 .include <../Makefile.bootxx> +OPT_SIZE.clang += -Oz
CVS commit: src/sys/arch/i386/stand/bootxx
Module Name:src Committed By: christos Date: Wed Aug 30 18:46:52 UTC 2023 Modified Files: src/sys/arch/i386/stand/bootxx/bootxx_msdos: Makefile src/sys/arch/i386/stand/bootxx/bootxx_ustarfs: Makefile Log Message: Override these two booters with -Oz for clang since it produces smaller code here. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/arch/i386/stand/bootxx/bootxx_msdos/Makefile cvs rdiff -u -r1.3 -r1.4 \ src/sys/arch/i386/stand/bootxx/bootxx_ustarfs/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Re: CVS commit: src/sys/arch/i386/stand/bootxx
Emmanuel Dreyfus writes: > On Thu, Jun 29, 2023 at 08:43:36PM -0400, Greg Troxel wrote: >> > Primary bootstrap is now able to read a GPT inside RAIDframe. >> did you also update documentation? > > We do not have any documentation specific to primary bootstrap. > x86/boot(8) domuent the behavior with no detail about primary > and secondary bootstrap distinct roles. > > The change makes primary bootstrap behavior in line with secondary > bootstrap and with what is already documented in x86/boot(8). Hence > there is no documentation update, we could consider it as a bug fix, > since the previosu behavior did not match x86/boot(8) documentation. Thank you for explaining. That sounds fine then.
Re: CVS commit: src/sys/arch/i386/stand/bootxx
On Thu, Jun 29, 2023 at 08:43:36PM -0400, Greg Troxel wrote: > > Primary bootstrap is now able to read a GPT inside RAIDframe. > did you also update documentation? We do not have any documentation specific to primary bootstrap. x86/boot(8) domuent the behavior with no detail about primary and secondary bootstrap distinct roles. The change makes primary bootstrap behavior in line with secondary bootstrap and with what is already documented in x86/boot(8). Hence there is no documentation update, we could consider it as a bug fix, since the previosu behavior did not match x86/boot(8) documentation. -- Emmanuel Dreyfus m...@netbsd.org
Re: CVS commit: src/sys/arch/i386/stand/bootxx
"Emmanuel Dreyfus" writes: > Log Message: > Primary bootstrap is now able to read a GPT inside RAIDframe. did you also update documentation?
CVS commit: src/sys/arch/i386/stand/bootxx
Module Name:src Committed By: manu Date: Thu Jun 29 14:18:58 UTC 2023 Modified Files: src/sys/arch/i386/stand/bootxx: boot1.c Log Message: Primary bootstrap is now able to read a GPT inside RAIDframe. Previously, primary bootstrap was able to boot on RAID-1 RAIDframe set with the limitation that the FFS filesystem had to start at bloc 0 in the RAID. That allowed inner RAID partitionning with a disklabel, but not with a GPT. When booting on a RAID-1 RAIDframe, primary bootstrap now first try a filesystem at bloc 0 of the RAID as before. On failure, it tries to read a GPT and load secondary bootstrap from, by priority; 1) the first partition with the bootme attribute set 2) the first partition of type FFS, LFS, CCD or CGD 3) the first partition present in the GPT To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/sys/arch/i386/stand/bootxx/boot1.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/i386/stand/bootxx/boot1.c diff -u src/sys/arch/i386/stand/bootxx/boot1.c:1.21 src/sys/arch/i386/stand/bootxx/boot1.c:1.22 --- src/sys/arch/i386/stand/bootxx/boot1.c:1.21 Thu Jun 24 01:23:16 2021 +++ src/sys/arch/i386/stand/bootxx/boot1.c Thu Jun 29 14:18:58 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: boot1.c,v 1.21 2021/06/24 01:23:16 gutteridge Exp $ */ +/* $NetBSD: boot1.c,v 1.22 2023/06/29 14:18:58 manu Exp $ */ /*- * Copyright (c) 2003 The NetBSD Foundation, Inc. @@ -30,15 +30,17 @@ */ #include -__RCSID("$NetBSD: boot1.c,v 1.21 2021/06/24 01:23:16 gutteridge Exp $"); +__RCSID("$NetBSD: boot1.c,v 1.22 2023/06/29 14:18:58 manu Exp $"); #include #include #include #include +#include #include #include +#include #include /* For RF_PROTECTED_SECTORS */ #define XSTR(x) #x @@ -49,6 +51,9 @@ static daddr_t bios_sector; static struct biosdisk_ll d; const char *boot1(uint32_t, uint64_t *); +#ifndef NO_GPT +static daddr_t gpt_lookup(daddr_t); +#endif extern void putstr(const char *); extern struct disklabel ptn_disklabel; @@ -90,6 +95,17 @@ boot1(uint32_t biosdev, uint64_t *sector fd = ob(); if (fd != -1) goto done; + +#ifndef NO_GPT + /* + * Test for a GPT inside the RAID + */ + bios_sector += gpt_lookup(bios_sector); + fd = ob(); + if (fd != -1) + goto done; +#endif + /* * Nothing at the start of the MBR partition, fallback on * partition 'a' from the disklabel in this MBR partition. @@ -144,3 +160,146 @@ blkdevstrategy(void *devdata, int flag, return 0; } + +#ifndef NO_GPT +static int +is_unused(struct gpt_ent *ent) +{ + const struct uuid unused = GPT_ENT_TYPE_UNUSED; + + return (memcmp(ent->ent_type, , sizeof(unused)) == 0); +} + +static int +is_bootable(struct gpt_ent *ent) +{ + /* GPT_ENT_TYPE_NETBSD_RAID omitted as we are already in a RAID */ + const struct uuid bootable[] = { + GPT_ENT_TYPE_NETBSD_FFS, + GPT_ENT_TYPE_NETBSD_LFS, + GPT_ENT_TYPE_NETBSD_CCD, + GPT_ENT_TYPE_NETBSD_CGD, + }; + int i; + + for (i = 0; i < sizeof(bootable) / sizeof(*bootable); i++) { + if (memcmp(ent->ent_type, [i], + sizeof(struct uuid)) == 0) + return 1; + } + + return 0; +} + +static daddr_t +gpt_lookup(daddr_t sector) +{ + char buf[BIOSDISK_DEFAULT_SECSIZE]; + struct mbr_sector *pmbr; + const char gpt_hdr_sig[] = GPT_HDR_SIG; + struct gpt_hdr *hdr; + struct gpt_ent *ent; + uint32_t nents; + uint32_t entsz; + uint32_t entries_per_sector; + uint32_t sectors_per_entry; + uint64_t firstpart_lba = 0; + uint64_t bootable_lba = 0; + uint64_t bootme_lba = 0; + int i, j; + + /* + * Look for a PMBR + */ + if (readsects(, sector, 1, buf, 1) != 0) + return 0; + + pmbr = (struct mbr_sector *)buf; + + if (pmbr->mbr_magic != htole16(MBR_MAGIC)) + return 0; + + if (pmbr->mbr_parts[0].mbrp_type != MBR_PTYPE_PMBR) + return 0; + + sector++; /* skip PMBR */ + + /* + * Look for a GPT header + * Space is scarce, we do not check CRC. + */ + if (readsects(, sector, 1, buf, 1) != 0) + return 0; + + hdr = (struct gpt_hdr *)buf; + + if (memcmp(gpt_hdr_sig, hdr->hdr_sig, sizeof(hdr->hdr_sig)) != 0) + return 0; + + if (hdr->hdr_revision != htole32(GPT_HDR_REVISION)) + return 0; + + if (le32toh(hdr->hdr_size) > BIOSDISK_DEFAULT_SECSIZE) + return 0; + + nents = le32toh(hdr->hdr_entries); + entsz = le32toh(hdr->hdr_entsz); + + sector++; /* skip GPT header */ + + /* + * Read partition table + * + * According to UEFI specification section 5.3.2, entries + * are 128 * (2^n) bytes long. The most common scenario is + * 128 bytes (n = 0) where there are 4 entries per sector. + * If n > 2, then entries spans multiple sectors, but they + * remain sector-aligned. + */ + entries_per_sector = BIOSDISK_DEFAULT_SECSIZE / entsz; + if (entries_per_sector == 0) + entries_per_sector = 1; + + sectors_per_entry = entsz / BIOSDISK_DEFAULT_SECSIZE; + if (sectors_per_entry == 0) + sectors_per_entry = 1; + + for (i = 0; i < nents; i += entries_per_sector) { +
CVS commit: src/sys/arch/i386/stand/bootxx
Module Name:src Committed By: manu Date: Thu Jun 29 14:18:58 UTC 2023 Modified Files: src/sys/arch/i386/stand/bootxx: boot1.c Log Message: Primary bootstrap is now able to read a GPT inside RAIDframe. Previously, primary bootstrap was able to boot on RAID-1 RAIDframe set with the limitation that the FFS filesystem had to start at bloc 0 in the RAID. That allowed inner RAID partitionning with a disklabel, but not with a GPT. When booting on a RAID-1 RAIDframe, primary bootstrap now first try a filesystem at bloc 0 of the RAID as before. On failure, it tries to read a GPT and load secondary bootstrap from, by priority; 1) the first partition with the bootme attribute set 2) the first partition of type FFS, LFS, CCD or CGD 3) the first partition present in the GPT To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/sys/arch/i386/stand/bootxx/boot1.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/sys/arch/i386/stand/bootxx
Module Name:src Committed By: mlelstv Date: Sun Mar 6 18:35:43 UTC 2022 Modified Files: src/sys/arch/i386/stand/bootxx: bootxx.S Log Message: pass errno through switch to protected mode. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/sys/arch/i386/stand/bootxx/bootxx.S Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/i386/stand/bootxx/bootxx.S diff -u src/sys/arch/i386/stand/bootxx/bootxx.S:1.11 src/sys/arch/i386/stand/bootxx/bootxx.S:1.12 --- src/sys/arch/i386/stand/bootxx/bootxx.S:1.11 Thu Jul 11 03:49:51 2019 +++ src/sys/arch/i386/stand/bootxx/bootxx.S Sun Mar 6 18:35:43 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: bootxx.S,v 1.11 2019/07/11 03:49:51 msaitoh Exp $ */ +/* $NetBSD: bootxx.S,v 1.12 2022/03/06 18:35:43 mlelstv Exp $ */ /*- * Copyright (c) 2003 The NetBSD Foundation, Inc. @@ -79,6 +79,7 @@ boot_params:/* space for patchable v push %edx call _C_LABEL(boot1) /* C code to load /boot */ add $8, %esp + movw errno, %dx call prot_to_real .code16 @@ -94,7 +95,7 @@ boot_params:/* space for patchable v boot_fail: push %ax /* error string from boot1 */ - movw errno, %ax + movw %dx, %ax aam/* largest errno is < 100 */ addw $('0' << 8) | '0', %ax /* to ascii */ rorw $8, %ax
CVS commit: src/sys/arch/i386/stand/bootxx
Module Name:src Committed By: mlelstv Date: Sun Mar 6 18:35:43 UTC 2022 Modified Files: src/sys/arch/i386/stand/bootxx: bootxx.S Log Message: pass errno through switch to protected mode. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/sys/arch/i386/stand/bootxx/bootxx.S Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Re: CVS commit: src/sys/arch/i386/stand/bootxx
On Mon, Jan 04, 2016 at 06:33:50PM +1100, matthew green wrote: > "Christos Zoulas" writes: > > Module Name:src > > Committed By: christos > > Date: Sun Jan 3 20:59:47 UTC 2016 > > > > Modified Files: > > src/sys/arch/i386/stand/bootxx: pbr.S > > > > Log Message: > > change 60 to 70 which is the current release. Noticed by Rares Aioanei. > > i don't think so we should do this unless we change the protocol, > as jak mentioned. this can be intepreted by the BIOS and it might > do differnet stuff so unless there's actually a good reason for it > this change could break something that works (poorly.) AFAIR it is just the operating system name in the partition boot record and is purely a comment. The bios certainly should be looking at it, the bios doesn't look at the pbr only the mbr (and shouldn't look at much of that). OTOH, no point changing it. David -- David Laight: da...@l8s.co.uk
CVS commit: src/sys/arch/i386/stand/bootxx
Module Name:src Committed By: christos Date: Fri Jan 1 03:18:27 UTC 2010 Modified Files: src/sys/arch/i386/stand/bootxx: boot1.c Log Message: If the open fails, don't call fstat, because this changes the errno to EINVAL from eg. ENOENT. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/sys/arch/i386/stand/bootxx/boot1.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.