Tue Mar 13 14:54:52 2018 UTC ()
Pull up following revision(s) (requested by nonaka in ticket #625):
	sys/arch/i386/stand/efiboot/efidisk.c: revision 1.2
	sys/arch/i386/stand/efiboot/devopen.c: revision 1.2
	sys/arch/i386/stand/efiboot/efidisk.h: revision 1.2
	sys/arch/i386/stand/efiboot/boot.c: revision 1.6
	sys/arch/i386/stand/efiboot/efidisk_ll.c: revision 1.2
	sys/arch/i386/stand/efiboot/efidev.c: revision 1.1
	sys/arch/i386/stand/lib/biosdisk_ll.h: revision 1.16
	sys/arch/i386/stand/lib/biosdisk.h: revision 1.9
	sys/lib/libsa/cd9660.c: revision 1.31
	sys/arch/i386/stand/efiboot/efiboot.c: revision 1.5
	sys/arch/i386/stand/efiboot/efiboot.h: revision 1.6
	sys/arch/i386/stand/lib/biosdisk.c: revision 1.47
	sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.10
	sys/arch/i386/stand/efiboot/TODO.efiboot: revision 1.4
efiboot: system can boot from CD/DVD-ROM media.

Add missed file in previous commit.


(martin)
diff -r1.9 -r1.9.2.1 src/sys/arch/i386/stand/efiboot/Makefile.efiboot
diff -r1.3 -r1.3.10.1 src/sys/arch/i386/stand/efiboot/TODO.efiboot
diff -r1.5 -r1.5.2.1 src/sys/arch/i386/stand/efiboot/boot.c
diff -r1.5 -r1.5.2.1 src/sys/arch/i386/stand/efiboot/efiboot.h
diff -r1.1 -r1.1.12.1 src/sys/arch/i386/stand/efiboot/devopen.c
diff -r1.1 -r1.1.12.1 src/sys/arch/i386/stand/efiboot/efidisk.c
diff -r1.1 -r1.1.12.1 src/sys/arch/i386/stand/efiboot/efidisk.h
diff -r1.1 -r1.1.12.1 src/sys/arch/i386/stand/efiboot/efidisk_ll.c
diff -r1.4 -r1.4.10.1 src/sys/arch/i386/stand/efiboot/efiboot.c
diff -r0 -r1.1.2.2 src/sys/arch/i386/stand/efiboot/efidev.c
diff -r1.46 -r1.46.6.1 src/sys/arch/i386/stand/lib/biosdisk.c
diff -r1.8 -r1.8.52.1 src/sys/arch/i386/stand/lib/biosdisk.h
diff -r1.15 -r1.15.90.1 src/sys/arch/i386/stand/lib/biosdisk_ll.h
diff -r1.30 -r1.30.22.1 src/sys/lib/libsa/cd9660.c

cvs diff -r1.9 -r1.9.2.1 src/sys/arch/i386/stand/efiboot/Makefile.efiboot (expand / switch to unified diff)

--- src/sys/arch/i386/stand/efiboot/Makefile.efiboot 2017/04/29 00:05:35 1.9
+++ src/sys/arch/i386/stand/efiboot/Makefile.efiboot 2018/03/13 14:54:52 1.9.2.1
@@ -1,29 +1,29 @@ @@ -1,29 +1,29 @@
1# $NetBSD: Makefile.efiboot,v 1.9 2017/04/29 00:05:35 nonaka Exp $ 1# $NetBSD: Makefile.efiboot,v 1.9.2.1 2018/03/13 14:54:52 martin Exp $
2 2
3S= ${.CURDIR}/../../../../.. 3S= ${.CURDIR}/../../../../..
4 4
5NOMAN= # defined 5NOMAN= # defined
6PROG?= boot.efi 6PROG?= boot.efi
7NEWVERSWHAT?= "EFI Boot" 7NEWVERSWHAT?= "EFI Boot"
8 8
9AFLAGS.start.S= ${${ACTIVE_CC} == "clang":?-no-integrated-as:} 9AFLAGS.start.S= ${${ACTIVE_CC} == "clang":?-no-integrated-as:}
10 10
11SOURCES?= start.S conf.c devopen.c efiboot.c self_reloc.c 11SOURCES?= start.S conf.c devopen.c efiboot.c self_reloc.c
12LIBI386SRCS= boot.c biosdisk.c bootinfo.c bootinfo_biosgeom.c 12LIBI386SRCS= boot.c biosdisk.c bootinfo.c bootinfo_biosgeom.c
13LIBI386SRCS+= bootmenu.c diskbuf.c exec.c menuutils.c 13LIBI386SRCS+= bootmenu.c diskbuf.c exec.c menuutils.c
14LIBI386SRCS+= panic.c parseutils.c pread.c 14LIBI386SRCS+= panic.c parseutils.c pread.c
15LIBI386SRCS+= eficons.c efidelay.c efidisk.c efidisk_ll.c efigetsecs.c 15LIBI386SRCS+= eficons.c efidelay.c efidev.c efidisk.c efidisk_ll.c
16LIBI386SRCS+= efimemory.c 16LIBI386SRCS+= efigetsecs.c efimemory.c
17SRCS= ${SOURCES} ${EXTRA_SOURCES} ${LIBI386SRCS} 17SRCS= ${SOURCES} ${EXTRA_SOURCES} ${LIBI386SRCS}
18 18
19PIE_CFLAGS= 19PIE_CFLAGS=
20PIE_LDFLAGS= 20PIE_LDFLAGS=
21PIE_AFLAGS= 21PIE_AFLAGS=
22 22
23.include <bsd.own.mk> 23.include <bsd.own.mk>
24 24
25STRIPFLAG= # nothing 25STRIPFLAG= # nothing
26 26
27LIBCRT0= # nothing 27LIBCRT0= # nothing
28LIBCRTI= # nothing 28LIBCRTI= # nothing
29LIBCRTBEGIN= # nothing 29LIBCRTBEGIN= # nothing
@@ -44,38 +44,41 @@ CPPFLAGS+= -I${.CURDIR}/../../lib @@ -44,38 +44,41 @@ CPPFLAGS+= -I${.CURDIR}/../../lib
44 44
45COPTS+= -ffreestanding -fPIC -fshort-wchar -fno-strict-aliasing -fno-builtin 45COPTS+= -ffreestanding -fPIC -fshort-wchar -fno-strict-aliasing -fno-builtin
46COPTS+= -fno-stack-protector 46COPTS+= -fno-stack-protector
47COPTS+= ${${ACTIVE_CC} == "gcc":? -Wno-error=unused-but-set-variable :} 47COPTS+= ${${ACTIVE_CC} == "gcc":? -Wno-error=unused-but-set-variable :}
48CPPFLAGS+= -nostdinc -D_STANDALONE 48CPPFLAGS+= -nostdinc -D_STANDALONE
49CPPFLAGS+= -DEFIBOOT 49CPPFLAGS+= -DEFIBOOT
50 50
51CPPFLAGS+= -Wall -Wmissing-prototypes 51CPPFLAGS+= -Wall -Wmissing-prototypes
52CPPFLAGS+= -Wno-pointer-sign 52CPPFLAGS+= -Wno-pointer-sign
53 53
54CPPFLAGS+= -DEFI_ALLOCATE_MAX_ADDRESS=0x100000000ULL 54CPPFLAGS+= -DEFI_ALLOCATE_MAX_ADDRESS=0x100000000ULL
55CPPFLAGS+= -DHEAP_VARIABLE 55CPPFLAGS+= -DHEAP_VARIABLE
56CPPFLAGS+= -DSUPPORT_CD9660 56CPPFLAGS+= -DSUPPORT_CD9660
 57CPPFLAGS+= -D"devb2cdb(bno)=(bno)"
57CPPFLAGS+= -DSUPPORT_DOSFS 58CPPFLAGS+= -DSUPPORT_DOSFS
58CPPFLAGS+= -DSUPPORT_EXT2FS 59CPPFLAGS+= -DSUPPORT_EXT2FS
59CPPFLAGS+= -DPASS_BIOSGEOM 60CPPFLAGS+= -DPASS_BIOSGEOM
 61CPPFLAGS+= -DBIOSDISK_DEFAULT_SECSIZE=2048 # for bootinfo_biosgeom.c
60CPPFLAGS+= -DLIBSA_ENABLE_LS_OP 62CPPFLAGS+= -DLIBSA_ENABLE_LS_OP
61 63
62EFIDIR= ${S}/external/bsd/gnu-efi/dist 64EFIDIR= ${S}/external/bsd/gnu-efi/dist
63GNUEFIARCH?= ${MACHINE_CPU} 65GNUEFIARCH?= ${MACHINE_CPU}
64CPPFLAGS+= -I${EFIDIR}/inc -I${EFIDIR}/inc/${GNUEFIARCH} 66CPPFLAGS+= -I${EFIDIR}/inc -I${EFIDIR}/inc/${GNUEFIARCH}
65CPPFLAGS+= -I${EFIDIR}/inc/protocol 67CPPFLAGS+= -I${EFIDIR}/inc/protocol
66 68
67SAMISCCPPFLAGS+= -DLIBSA_PRINTF_LONGLONG_SUPPORT 69SAMISCCPPFLAGS+= -DLIBSA_PRINTF_LONGLONG_SUPPORT
68SAMISCCPPFLAGS+= -DLIBSA_PRINTF_WIDTH_SUPPORT 70SAMISCCPPFLAGS+= -DLIBSA_PRINTF_WIDTH_SUPPORT
 71SAMISCCPPFLAGS+= -D"cdb2devb(bno)=(bno)"
69SAMISCMAKEFLAGS+= SA_USE_CREAD=yes # Read compressed kernels 72SAMISCMAKEFLAGS+= SA_USE_CREAD=yes # Read compressed kernels
70SAMISCMAKEFLAGS+= SA_INCLUDE_NET=no # Netboot via TFTP, NFS 73SAMISCMAKEFLAGS+= SA_INCLUDE_NET=no # Netboot via TFTP, NFS
71 74
72### find out what to use for libsa 75### find out what to use for libsa
73SA_AS= library 76SA_AS= library
74SAMISCMAKEFLAGS+="SA_USE_LOADFILE=yes" 77SAMISCMAKEFLAGS+="SA_USE_LOADFILE=yes"
75SAMISCMAKEFLAGS+="SA_ENABLE_LS_OP=yes" 78SAMISCMAKEFLAGS+="SA_ENABLE_LS_OP=yes"
76.include "${S}/lib/libsa/Makefile.inc" 79.include "${S}/lib/libsa/Makefile.inc"
77LIBSA= ${SALIB} 80LIBSA= ${SALIB}
78 81
79### find out what to use for libkern 82### find out what to use for libkern
80KERN_AS= library 83KERN_AS= library
81LIBKERN_ARCH?= ${MACHINE_ARCH} 84LIBKERN_ARCH?= ${MACHINE_ARCH}

cvs diff -r1.3 -r1.3.10.1 src/sys/arch/i386/stand/efiboot/TODO.efiboot (expand / switch to unified diff)

--- src/sys/arch/i386/stand/efiboot/TODO.efiboot 2017/03/12 06:37:41 1.3
+++ src/sys/arch/i386/stand/efiboot/TODO.efiboot 2018/03/13 14:54:52 1.3.10.1
@@ -1,16 +1,15 @@ @@ -1,16 +1,15 @@
1- efiboot 1- efiboot
2 * handle UEFI variables 2 * handle UEFI variables
3 * boot from CD/DVD (bootable from CD/DVD, but root fs not found.) 
4 * load boot.cfg from EFI system partition (FAT32) 3 * load boot.cfg from EFI system partition (FAT32)
5 4
6- kernel 5- kernel
7 * handle UEFI variables (/dev/efivar) 6 * handle UEFI variables (/dev/efivar)
8 * accelerated console 7 * accelerated console
9 8
10- userland 9- userland
11 * efibootmgr like utility 10 * efibootmgr like utility
12 * merge distrib/amd64/uefi-installimage to distrib/amd64/install-image 11 * merge distrib/amd64/uefi-installimage to distrib/amd64/install-image
13 * merge distrib/amd64/uefi-installimage/Makefile.* to distrib/common/Makefile.* 12 * merge distrib/amd64/uefi-installimage/Makefile.* to distrib/common/Makefile.*
14 13
15- installer 14- installer
16 * sysinst(8): handle dk(4) for install disk 15 * sysinst(8): handle dk(4) for install disk

cvs diff -r1.5 -r1.5.2.1 src/sys/arch/i386/stand/efiboot/boot.c (expand / switch to unified diff)

--- src/sys/arch/i386/stand/efiboot/boot.c 2017/05/01 13:03:01 1.5
+++ src/sys/arch/i386/stand/efiboot/boot.c 2018/03/13 14:54:52 1.5.2.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: boot.c,v 1.5 2017/05/01 13:03:01 nonaka Exp $ */ 1/* $NetBSD: boot.c,v 1.5.2.1 2018/03/13 14:54:52 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org> 4 * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -409,27 +409,27 @@ command_boot(char *arg) @@ -409,27 +409,27 @@ command_boot(char *arg)
409 bootit(names[i][1], howto); 409 bootit(names[i][1], howto);
410 } 410 }
411 } 411 }
412} 412}
413 413
414void 414void
415command_dev(char *arg) 415command_dev(char *arg)
416{ 416{
417 static char savedevname[MAXDEVNAME + 1]; 417 static char savedevname[MAXDEVNAME + 1];
418 char *fsname, *devname; 418 char *fsname, *devname;
419 const char *file; /* dummy */ 419 const char *file; /* dummy */
420 420
421 if (*arg == '\0') { 421 if (*arg == '\0') {
422 biosdisk_probe(); 422 efi_disk_show();
423 printf("default %s%d%c\n", default_devname, default_unit, 423 printf("default %s%d%c\n", default_devname, default_unit,
424 'a' + default_partition); 424 'a' + default_partition);
425 return; 425 return;
426 } 426 }
427 427
428 if (strchr(arg, ':') == NULL || 428 if (strchr(arg, ':') == NULL ||
429 parsebootfile(arg, &fsname, &devname, &default_unit, 429 parsebootfile(arg, &fsname, &devname, &default_unit,
430 &default_partition, &file)) { 430 &default_partition, &file)) {
431 command_help(NULL); 431 command_help(NULL);
432 return; 432 return;
433 } 433 }
434 434
435 /* put to own static storage */ 435 /* put to own static storage */
@@ -544,35 +544,40 @@ command_multiboot(char *arg) @@ -544,35 +544,40 @@ command_multiboot(char *arg)
544 char *filename; 544 char *filename;
545 545
546 filename = arg; 546 filename = arg;
547 if (exec_multiboot(filename, gettrailer(arg)) < 0) 547 if (exec_multiboot(filename, gettrailer(arg)) < 0)
548 printf("multiboot: %s: %s\n", sprint_bootsel(filename), 548 printf("multiboot: %s: %s\n", sprint_bootsel(filename),
549 strerror(errno)); 549 strerror(errno));
550 else 550 else
551 printf("boot returned\n"); 551 printf("boot returned\n");
552} 552}
553 553
554void 554void
555command_version(char *arg) 555command_version(char *arg)
556{ 556{
 557 CHAR16 *path;
557 558
558 if (strcmp(arg, "full") == 0) { 559 if (strcmp(arg, "full") == 0) {
559 printf("ImageBase: 0x%" PRIxPTR "\n", 560 printf("ImageBase: 0x%" PRIxPTR "\n",
560 (uintptr_t)efi_li->ImageBase); 561 (uintptr_t)efi_li->ImageBase);
561 printf("Stack: 0x%" PRIxPTR "\n", efi_main_sp); 562 printf("Stack: 0x%" PRIxPTR "\n", efi_main_sp);
562 printf("EFI version: %d.%02d\n", 563 printf("EFI version: %d.%02d\n",
563 ST->Hdr.Revision >> 16, ST->Hdr.Revision & 0xffff); 564 ST->Hdr.Revision >> 16, ST->Hdr.Revision & 0xffff);
564 Print(L"EFI Firmware: %s (rev %d.%02d)\n", ST->FirmwareVendor, 565 Print(L"EFI Firmware: %s (rev %d.%02d)\n", ST->FirmwareVendor,
565 ST->FirmwareRevision >> 16, ST->FirmwareRevision & 0xffff); 566 ST->FirmwareRevision >> 16, ST->FirmwareRevision & 0xffff);
 567 path = DevicePathToStr(efi_bootdp);
 568 Print(L"Boot DevicePath: %d:%d:%s\n", DevicePathType(efi_bootdp),
 569 DevicePathSubType(efi_bootdp), path);
 570 FreePool(path);
566 } 571 }
567 572
568 printf("\n" 573 printf("\n"
569 ">> %s, Revision %s (from NetBSD %s)\n" 574 ">> %s, Revision %s (from NetBSD %s)\n"
570 ">> Memory: %d/%d k\n", 575 ">> Memory: %d/%d k\n",
571 bootprog_name, bootprog_rev, bootprog_kernrev, 576 bootprog_name, bootprog_rev, bootprog_kernrev,
572 getbasemem(), getextmem()); 577 getbasemem(), getextmem());
573} 578}
574 579
575void 580void
576command_memmap(char *arg) 581command_memmap(char *arg)
577{ 582{
578 bool sorted = true; 583 bool sorted = true;

cvs diff -r1.5 -r1.5.2.1 src/sys/arch/i386/stand/efiboot/efiboot.h (expand / switch to unified diff)

--- src/sys/arch/i386/stand/efiboot/efiboot.h 2017/05/01 13:03:01 1.5
+++ src/sys/arch/i386/stand/efiboot/efiboot.h 2018/03/13 14:54:52 1.5.2.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: efiboot.h,v 1.5 2017/05/01 13:03:01 nonaka Exp $ */ 1/* $NetBSD: efiboot.h,v 1.5.2.1 2018/03/13 14:54:52 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org> 4 * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -36,37 +36,43 @@ @@ -36,37 +36,43 @@
36 36
37#include "efiboot_machdep.h" 37#include "efiboot_machdep.h"
38 38
39extern EFI_GUID GraphicsOutputProtocol; 39extern EFI_GUID GraphicsOutputProtocol;
40 40
41/* boot.c */ 41/* boot.c */
42void boot(void); 42void boot(void);
43void clearit(void); 43void clearit(void);
44void print_banner(void); 44void print_banner(void);
45 45
46/* efiboot.c */ 46/* efiboot.c */
47extern EFI_HANDLE IH; 47extern EFI_HANDLE IH;
48extern EFI_DEVICE_PATH *efi_bootdp; 48extern EFI_DEVICE_PATH *efi_bootdp;
 49extern int efi_bootdp_type;
49extern EFI_LOADED_IMAGE *efi_li; 50extern EFI_LOADED_IMAGE *efi_li;
50extern uintptr_t efi_main_sp; 51extern uintptr_t efi_main_sp;
51extern physaddr_t efi_loadaddr, efi_kernel_start; 52extern physaddr_t efi_loadaddr, efi_kernel_start;
52extern u_long efi_kernel_size; 53extern u_long efi_kernel_size;
53extern bool efi_cleanuped; 54extern bool efi_cleanuped;
54void efi_cleanup(void); 55void efi_cleanup(void);
55 56
56/* eficons.c */ 57/* eficons.c */
57int cninit(void); 58int cninit(void);
58void consinit(int, int, int); 59void consinit(int, int, int);
59void command_text(char *); 60void command_text(char *);
60void command_gop(char *); 61void command_gop(char *);
61 62
 63/* efidev.c */
 64int efi_device_path_depth(EFI_DEVICE_PATH *dp, int);
 65int efi_device_path_ncmp(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *, int);
 66
62/* efidisk.c */ 67/* efidisk.c */
63void efi_disk_probe(void); 68void efi_disk_probe(void);
 69void efi_disk_show(void);
64 70
65/* efimemory.c */ 71/* efimemory.c */
66void efi_memory_probe(void); 72void efi_memory_probe(void);
67void efi_memory_show_map(bool); 73void efi_memory_show_map(bool);
68EFI_MEMORY_DESCRIPTOR *efi_memory_get_map(UINTN *, UINTN *, UINTN *, UINT32 *, 74EFI_MEMORY_DESCRIPTOR *efi_memory_get_map(UINTN *, UINTN *, UINTN *, UINT32 *,
69 bool); 75 bool);
70 76
71/* panic.c */ 77/* panic.c */
72__dead VOID Panic(IN CHAR16 *, ...); 78__dead VOID Panic(IN CHAR16 *, ...);

cvs diff -r1.1 -r1.1.12.1 src/sys/arch/i386/stand/efiboot/devopen.c (expand / switch to unified diff)

--- src/sys/arch/i386/stand/efiboot/devopen.c 2017/01/24 11:09:14 1.1
+++ src/sys/arch/i386/stand/efiboot/devopen.c 2018/03/13 14:54:52 1.1.12.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: devopen.c,v 1.1 2017/01/24 11:09:14 nonaka Exp $ */ 1/* $NetBSD: devopen.c,v 1.1.12.1 2018/03/13 14:54:52 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2005 The NetBSD Foundation, Inc. 4 * Copyright (c) 2005 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Bang Jun-Young. 8 * by Bang Jun-Young.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -56,37 +56,46 @@ @@ -56,37 +56,46 @@
56 56
57#include "efiboot.h" 57#include "efiboot.h"
58 58
59#include <biosdisk.h> 59#include <biosdisk.h>
60#include "devopen.h" 60#include "devopen.h"
61#include <bootinfo.h> 61#include <bootinfo.h>
62 62
63static int 63static int
64dev2bios(char *devname, int unit, int *biosdev) 64dev2bios(char *devname, int unit, int *biosdev)
65{ 65{
66 66
67 if (strcmp(devname, "hd") == 0) 67 if (strcmp(devname, "hd") == 0)
68 *biosdev = 0x80 + unit; 68 *biosdev = 0x80 + unit;
 69 if (strcmp(devname, "cd") == 0)
 70 *biosdev = 0x80 + get_harddrives() + unit;
69 else 71 else
70 return ENXIO; 72 return ENXIO;
 73
71 return 0; 74 return 0;
72} 75}
73 76
74void 77void
75bios2dev(int biosdev, daddr_t sector, char **devname, int *unit, int *partition) 78bios2dev(int biosdev, daddr_t sector, char **devname, int *unit, int *partition)
76{ 79{
77 80
78 *unit = biosdev & 0x7f; 81 *unit = biosdev & 0x7f;
79 *devname = "hd"; 82
 83 if (biosdev >= 0x80 + get_harddrives()) {
 84 *devname = "cd";
 85 *unit -= get_harddrives();
 86 } else
 87 *devname = "hd";
 88
80 *partition = biosdisk_findpartition(biosdev, sector); 89 *partition = biosdisk_findpartition(biosdev, sector);
81} 90}
82 91
83struct btinfo_bootpath bibp; 92struct btinfo_bootpath bibp;
84extern bool kernel_loaded; 93extern bool kernel_loaded;
85 94
86/* 95/*
87 * Open the EFI disk device 96 * Open the EFI disk device
88 */ 97 */
89int 98int
90devopen(struct open_file *f, const char *fname, char **file) 99devopen(struct open_file *f, const char *fname, char **file)
91{ 100{
92 char *fsname, *devname; 101 char *fsname, *devname;

cvs diff -r1.1 -r1.1.12.1 src/sys/arch/i386/stand/efiboot/efidisk.c (expand / switch to unified diff)

--- src/sys/arch/i386/stand/efiboot/efidisk.c 2017/01/24 11:09:14 1.1
+++ src/sys/arch/i386/stand/efiboot/efidisk.c 2018/03/13 14:54:52 1.1.12.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: efidisk.c,v 1.1 2017/01/24 11:09:14 nonaka Exp $ */ 1/* $NetBSD: efidisk.c,v 1.1.12.1 2018/03/13 14:54:52 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org> 4 * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -16,102 +16,191 @@ @@ -16,102 +16,191 @@
16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
 29#define FSTYPENAMES /* for sys/disklabel.h */
 30
29#include "efiboot.h" 31#include "efiboot.h"
30 32
 33#include <sys/disklabel.h>
 34
 35#include "biosdisk.h"
 36#include "biosdisk_ll.h"
 37#include "devopen.h"
31#include "efidisk.h" 38#include "efidisk.h"
32 39
33static struct efidiskinfo_lh efi_disklist; 40static struct efidiskinfo_lh efi_disklist;
34static int nefidisks; 41static int nefidisks;
35 42
36void 43void
37efi_disk_probe(void) 44efi_disk_probe(void)
38{ 45{
39 EFI_STATUS status; 46 EFI_STATUS status;
40 UINTN i, nhandles; 47 UINTN i, nhandles;
41 EFI_HANDLE *handles; 48 EFI_HANDLE *handles;
42 EFI_BLOCK_IO *bio; 49 EFI_BLOCK_IO *bio;
43 EFI_BLOCK_IO_MEDIA *media; 50 EFI_BLOCK_IO_MEDIA *media;
 51 EFI_DEVICE_PATH *dp;
44 struct efidiskinfo *edi; 52 struct efidiskinfo *edi;
45 EFI_DEVICE_PATH *dp, *bdp; 53 int dev, depth = -1;
46 bool bootdev; 
47 int dev; 
48 54
49 TAILQ_INIT(&efi_disklist); 55 TAILQ_INIT(&efi_disklist);
50 56
51 status = LibLocateHandle(ByProtocol, &BlockIoProtocol, NULL, 57 status = LibLocateHandle(ByProtocol, &BlockIoProtocol, NULL,
52 &nhandles, &handles); 58 &nhandles, &handles);
53 if (EFI_ERROR(status)) 59 if (EFI_ERROR(status))
54 Panic(L"LocateHandle(BlockIoProtocol): %r", status); 60 Panic(L"LocateHandle(BlockIoProtocol): %r", status);
55 61
 62 if (efi_bootdp != NULL)
 63 depth = efi_device_path_depth(efi_bootdp, MEDIA_DEVICE_PATH);
 64
 65 /*
 66 * U-Boot incorrectly represents devices with a single
 67 * MEDIA_DEVICE_PATH component. In that case include that
 68 * component into the matching, otherwise we'll blindly select
 69 * the first device.
 70 */
 71 if (depth == 0)
 72 depth = 1;
 73
56 for (i = 0; i < nhandles; i++) { 74 for (i = 0; i < nhandles; i++) {
57 status = uefi_call_wrapper(BS->HandleProtocol, 3, handles[i], 75 status = uefi_call_wrapper(BS->HandleProtocol, 3, handles[i],
58 &BlockIoProtocol, (void **)&bio); 76 &BlockIoProtocol, (void **)&bio);
59 if (EFI_ERROR(status)) 77 if (EFI_ERROR(status))
60 Panic(L"HandleProtocol(BlockIoProtocol): %r", status); 78 Panic(L"HandleProtocol(BlockIoProtocol): %r", status);
61 79
62 media = bio->Media; 80 media = bio->Media;
63 if (media->LogicalPartition || !media->MediaPresent) 81 if (media->LogicalPartition || !media->MediaPresent)
64 continue; 82 continue;
65 83
66 edi = alloc(sizeof(struct efidiskinfo)); 84 edi = alloc(sizeof(struct efidiskinfo));
67 memset(edi, 0, sizeof(*edi)); 85 memset(edi, 0, sizeof(*edi));
 86 edi->type = BIOSDISK_TYPE_HD;
68 edi->bio = bio; 87 edi->bio = bio;
69 edi->media_id = media->MediaId; 88 edi->media_id = media->MediaId;
70 89
71 bootdev = false; 90 if (efi_bootdp != NULL && depth > 0) {
72 if (efi_bootdp == NULL) 91 status = uefi_call_wrapper(BS->HandleProtocol, 3,
73 goto next; 92 handles[i], &DevicePathProtocol, (void **)&dp);
74 93 if (EFI_ERROR(status))
75 status = uefi_call_wrapper(BS->HandleProtocol, 3, handles[i], 94 goto next;
76 &DevicePathProtocol, (void **)&dp); 95 if (efi_device_path_ncmp(efi_bootdp, dp, depth) == 0) {
77 if (EFI_ERROR(status)) 96 edi->bootdev = true;
78 goto next; 97 TAILQ_INSERT_HEAD(&efi_disklist, edi,
79 98 list);
80 bdp = efi_bootdp; 99 continue;
81 for (;;) { 
82 if (IsDevicePathEnd(dp)) { 
83 bootdev = true; 
84 break; 
85 } 100 }
86 if (memcmp(dp, bdp, sizeof(EFI_DEVICE_PATH)) != 0 || 
87 memcmp(dp, bdp, DevicePathNodeLength(dp)) != 0) 
88 break; 
89 dp = NextDevicePathNode(dp); 
90 bdp = NextDevicePathNode(bdp); 
91 } 101 }
92next: 102next:
93 if (bootdev) 103 TAILQ_INSERT_TAIL(&efi_disklist, edi, list);
94 TAILQ_INSERT_HEAD(&efi_disklist, edi, list); 
95 else 
96 TAILQ_INSERT_TAIL(&efi_disklist, edi, list); 
97 } 104 }
98 105
99 FreePool(handles); 106 FreePool(handles);
100 107
 108 if (efi_bootdp_type == BIOSDISK_TYPE_CD) {
 109 TAILQ_FOREACH(edi, &efi_disklist, list) {
 110 if (edi->bootdev) {
 111 edi = TAILQ_FIRST(&efi_disklist);
 112 edi->type = BIOSDISK_TYPE_CD;
 113 TAILQ_REMOVE(&efi_disklist, edi, list);
 114 TAILQ_INSERT_TAIL(&efi_disklist, edi, list);
 115 break;
 116 }
 117 }
 118 }
 119
101 dev = 0x80; 120 dev = 0x80;
102 TAILQ_FOREACH(edi, &efi_disklist, list) { 121 TAILQ_FOREACH(edi, &efi_disklist, list) {
103 edi->dev = dev++; 122 edi->dev = dev++;
104 nefidisks++; 123 if (edi->type == BIOSDISK_TYPE_HD)
 124 nefidisks++;
 125 if (edi->bootdev)
 126 boot_biosdev = edi->dev;
 127 }
 128}
 129
 130void
 131efi_disk_show(void)
 132{
 133 const struct efidiskinfo *edi;
 134 EFI_BLOCK_IO_MEDIA *media;
 135 struct biosdisk_partition *part;
 136 uint64_t size;
 137 int i, nparts;
 138 bool first;
 139
 140 TAILQ_FOREACH(edi, &efi_disklist, list) {
 141 media = edi->bio->Media;
 142 first = true;
 143 printf("disk ");
 144 switch (edi->type) {
 145 case BIOSDISK_TYPE_CD:
 146 printf("cd0");
 147 printf(" mediaId %u", media->MediaId);
 148 if (edi->media_id != media->MediaId)
 149 printf("(%u)", edi->media_id);
 150 printf("\n");
 151 printf(" cd0a\n");
 152 break;
 153 case BIOSDISK_TYPE_HD:
 154 printf("hd%d", edi->dev & 0x7f);
 155 printf(" mediaId %u", media->MediaId);
 156 if (edi->media_id != media->MediaId)
 157 printf("(%u)", edi->media_id);
 158 printf(" size ");
 159 size = (media->LastBlock + 1) * media->BlockSize;
 160 if (size >= (10ULL * 1024 * 1024 * 1024))
 161 printf("%"PRIu64" GB", size / (1024 * 1024 * 1024));
 162 else
 163 printf("%"PRIu64" MB", size / (1024 * 1024));
 164 printf("\n");
 165 break;
 166 }
 167 if (edi->type != BIOSDISK_TYPE_HD)
 168 continue;
 169
 170 if (biosdisk_readpartition(edi->dev, &part, &nparts))
 171 continue;
 172
 173 for (i = 0; i < nparts; i++) {
 174 if (part[i].size == 0)
 175 continue;
 176 if (part[i].fstype == FS_UNUSED)
 177 continue;
 178 if (first) {
 179 printf(" ");
 180 first = false;
 181 }
 182 printf(" hd%d%c(", edi->dev & 0x7f, i + 'a');
 183 if (part[i].guid != NULL)
 184 printf("%s", part[i].guid->name);
 185 else if (part[i].fstype < FSMAXTYPES)
 186 printf("%s", fstypenames[part[i].fstype]);
 187 else
 188 printf("%d", part[i].fstype);
 189 printf(")");
 190 }
 191 if (!first)
 192 printf("\n");
 193 dealloc(part, sizeof(*part) * nparts);
105 } 194 }
106} 195}
107 196
108const struct efidiskinfo * 197const struct efidiskinfo *
109efidisk_getinfo(int dev) 198efidisk_getinfo(int dev)
110{ 199{
111 const struct efidiskinfo *edi; 200 const struct efidiskinfo *edi;
112 201
113 TAILQ_FOREACH(edi, &efi_disklist, list) { 202 TAILQ_FOREACH(edi, &efi_disklist, list) {
114 if (dev == edi->dev) 203 if (dev == edi->dev)
115 return edi; 204 return edi;
116 } 205 }
117 return NULL; 206 return NULL;

cvs diff -r1.1 -r1.1.12.1 src/sys/arch/i386/stand/efiboot/efidisk.h (expand / switch to unified diff)

--- src/sys/arch/i386/stand/efiboot/efidisk.h 2017/01/24 11:09:14 1.1
+++ src/sys/arch/i386/stand/efiboot/efidisk.h 2018/03/13 14:54:52 1.1.12.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: efidisk.h,v 1.1 2017/01/24 11:09:14 nonaka Exp $ */ 1/* $NetBSD: efidisk.h,v 1.1.12.1 2018/03/13 14:54:52 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org> 4 * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -22,19 +22,21 @@ @@ -22,19 +22,21 @@
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/queue.h> 29#include <sys/queue.h>
30 30
31struct efidiskinfo { 31struct efidiskinfo {
32 TAILQ_ENTRY(efidiskinfo) list; 32 TAILQ_ENTRY(efidiskinfo) list;
33 33
34 int dev; 34 int dev;
 35 int type;
35 EFI_BLOCK_IO *bio; 36 EFI_BLOCK_IO *bio;
36 UINT32 media_id; 37 UINT32 media_id;
 38 bool bootdev;
37}; 39};
38TAILQ_HEAD(efidiskinfo_lh, efidiskinfo); 40TAILQ_HEAD(efidiskinfo_lh, efidiskinfo);
39 41
40const struct efidiskinfo *efidisk_getinfo(int); 42const struct efidiskinfo *efidisk_getinfo(int);

cvs diff -r1.1 -r1.1.12.1 src/sys/arch/i386/stand/efiboot/efidisk_ll.c (expand / switch to unified diff)

--- src/sys/arch/i386/stand/efiboot/efidisk_ll.c 2017/01/24 11:09:14 1.1
+++ src/sys/arch/i386/stand/efiboot/efidisk_ll.c 2018/03/13 14:54:52 1.1.12.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: efidisk_ll.c,v 1.1 2017/01/24 11:09:14 nonaka Exp $ */ 1/* $NetBSD: efidisk_ll.c,v 1.1.12.1 2018/03/13 14:54:52 martin Exp $ */
2/* NetBSD: biosdisk_ll.c,v 1.31 2011/02/21 02:58:02 jakllsch Exp */ 2/* NetBSD: biosdisk_ll.c,v 1.31 2011/02/21 02:58:02 jakllsch Exp */
3 3
4/*- 4/*-
5 * Copyright (c) 2005 The NetBSD Foundation, Inc. 5 * Copyright (c) 2005 The NetBSD Foundation, Inc.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * This code is derived from software contributed to The NetBSD Foundation 8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Bang Jun-Young. 9 * by Bang Jun-Young.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -85,34 +85,36 @@ static int do_read(struct biosdisk_ll *, @@ -85,34 +85,36 @@ static int do_read(struct biosdisk_ll *,
85int 85int
86set_geometry(struct biosdisk_ll *d, struct biosdisk_extinfo *ed) 86set_geometry(struct biosdisk_ll *d, struct biosdisk_extinfo *ed)
87{ 87{
88 const struct efidiskinfo *edi; 88 const struct efidiskinfo *edi;
89 EFI_BLOCK_IO_MEDIA *media; 89 EFI_BLOCK_IO_MEDIA *media;
90 90
91 edi = efidisk_getinfo(d->dev); 91 edi = efidisk_getinfo(d->dev);
92 if (edi == NULL) 92 if (edi == NULL)
93 return 1; 93 return 1;
94 94
95 media = edi->bio->Media; 95 media = edi->bio->Media;
96 96
97 d->secsize = media->BlockSize; 97 d->secsize = media->BlockSize;
98 d->type = BIOSDISK_TYPE_HD; 98 d->type = edi->type;
99 d->flags = BIOSDISK_INT13EXT; 99 d->flags = BIOSDISK_INT13EXT;
100 100
101 ed->totsec = media->LastBlock + 1; 101 if (ed != NULL) {
102 ed->sbytes = media->BlockSize; 102 ed->totsec = media->LastBlock + 1;
103 ed->flags = 0; 103 ed->sbytes = media->BlockSize;
104 if (media->RemovableMedia) 104 ed->flags = 0;
105 ed->flags |= EXTINFO_REMOVABLE; 105 if (media->RemovableMedia)
 106 ed->flags |= EXTINFO_REMOVABLE;
 107 }
106 108
107 return 0; 109 return 0;
108} 110}
109 111
110/* 112/*
111 * Global shared "diskbuf" is used as read ahead buffer. For reading from 113 * Global shared "diskbuf" is used as read ahead buffer. For reading from
112 * floppies, the bootstrap has to be loaded on a 64K boundary to ensure that 114 * floppies, the bootstrap has to be loaded on a 64K boundary to ensure that
113 * this buffer doesn't cross a 64K DMA boundary. 115 * this buffer doesn't cross a 64K DMA boundary.
114 */ 116 */
115static int ra_dev; 117static int ra_dev;
116static daddr_t ra_end; 118static daddr_t ra_end;
117static daddr_t ra_first; 119static daddr_t ra_first;
118 120

cvs diff -r1.4 -r1.4.10.1 src/sys/arch/i386/stand/efiboot/efiboot.c (expand / switch to unified diff)

--- src/sys/arch/i386/stand/efiboot/efiboot.c 2017/02/11 10:23:39 1.4
+++ src/sys/arch/i386/stand/efiboot/efiboot.c 2018/03/13 14:54:52 1.4.10.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: efiboot.c,v 1.4 2017/02/11 10:23:39 nonaka Exp $ */ 1/* $NetBSD: efiboot.c,v 1.4.10.1 2018/03/13 14:54:52 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org> 4 * Copyright (c) 2016 Kimihiro Nonaka <nonaka@netbsd.org>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -18,31 +18,33 @@ @@ -18,31 +18,33 @@
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include "efiboot.h" 29#include "efiboot.h"
30 30
 31#include "biosdisk_ll.h"
31#include "bootinfo.h" 32#include "bootinfo.h"
32#include "devopen.h" 33#include "devopen.h"
33 34
34EFI_HANDLE IH; 35EFI_HANDLE IH;
35EFI_DEVICE_PATH *efi_bootdp; 36EFI_DEVICE_PATH *efi_bootdp;
 37int efi_bootdp_type = BIOSDISK_TYPE_HD;
36EFI_LOADED_IMAGE *efi_li; 38EFI_LOADED_IMAGE *efi_li;
37uintptr_t efi_main_sp; 39uintptr_t efi_main_sp;
38physaddr_t efi_loadaddr, efi_kernel_start; 40physaddr_t efi_loadaddr, efi_kernel_start;
39u_long efi_kernel_size; 41u_long efi_kernel_size;
40bool efi_cleanuped; 42bool efi_cleanuped;
41 43
42static EFI_PHYSICAL_ADDRESS heap_start = EFI_ALLOCATE_MAX_ADDRESS; 44static EFI_PHYSICAL_ADDRESS heap_start = EFI_ALLOCATE_MAX_ADDRESS;
43static UINTN heap_size = 1 * 1024 * 1024; /* 1MB */ 45static UINTN heap_size = 1 * 1024 * 1024; /* 1MB */
44static struct btinfo_efi btinfo_efi; 46static struct btinfo_efi btinfo_efi;
45 47
46static void efi_heap_init(void); 48static void efi_heap_init(void);
47 49
48EFI_STATUS EFIAPI efi_main(EFI_HANDLE, EFI_SYSTEM_TABLE *); 50EFI_STATUS EFIAPI efi_main(EFI_HANDLE, EFI_SYSTEM_TABLE *);
@@ -61,35 +63,33 @@ efi_main(EFI_HANDLE imageHandle, EFI_SYS @@ -61,35 +63,33 @@ efi_main(EFI_HANDLE imageHandle, EFI_SYS
61 63
62 cninit(); 64 cninit();
63 efi_heap_init(); 65 efi_heap_init();
64 efi_md_init(); 66 efi_md_init();
65 67
66 status = uefi_call_wrapper(BS->HandleProtocol, 3, IH, 68 status = uefi_call_wrapper(BS->HandleProtocol, 3, IH,
67 &LoadedImageProtocol, (void **)&efi_li); 69 &LoadedImageProtocol, (void **)&efi_li);
68 if (EFI_ERROR(status)) 70 if (EFI_ERROR(status))
69 Panic(L"HandleProtocol(LoadedImageProtocol): %r", status); 71 Panic(L"HandleProtocol(LoadedImageProtocol): %r", status);
70 status = uefi_call_wrapper(BS->HandleProtocol, 3, efi_li->DeviceHandle, 72 status = uefi_call_wrapper(BS->HandleProtocol, 3, efi_li->DeviceHandle,
71 &DevicePathProtocol, (void **)&dp0); 73 &DevicePathProtocol, (void **)&dp0);
72 if (EFI_ERROR(status)) 74 if (EFI_ERROR(status))
73 Panic(L"HandleProtocol(DevicePathProtocol): %r", status); 75 Panic(L"HandleProtocol(DevicePathProtocol): %r", status);
 76 efi_bootdp = dp0;
74 for (dp = dp0; !IsDevicePathEnd(dp); dp = NextDevicePathNode(dp)) { 77 for (dp = dp0; !IsDevicePathEnd(dp); dp = NextDevicePathNode(dp)) {
75 if (DevicePathType(dp) == MEDIA_DEVICE_PATH) 78 if (DevicePathType(dp) == MEDIA_DEVICE_PATH &&
76 continue; 79 DevicePathSubType(dp) == MEDIA_CDROM_DP) {
77 if (DevicePathSubType(dp) == MEDIA_HARDDRIVE_DP) { 80 efi_bootdp_type = BIOSDISK_TYPE_CD;
78 boot_biosdev = 0x80; 
79 efi_bootdp = dp; 
80 break; 81 break;
81 } 82 }
82 break; 
83 } 83 }
84 84
85 efi_disk_probe(); 85 efi_disk_probe();
86 86
87 status = uefi_call_wrapper(BS->SetWatchdogTimer, 4, 0, 0, 0, NULL); 87 status = uefi_call_wrapper(BS->SetWatchdogTimer, 4, 0, 0, 0, NULL);
88 if (EFI_ERROR(status)) 88 if (EFI_ERROR(status))
89 Panic(L"SetWatchdogTimer: %r", status); 89 Panic(L"SetWatchdogTimer: %r", status);
90 90
91 boot(); 91 boot();
92 92
93 return EFI_SUCCESS; 93 return EFI_SUCCESS;
94} 94}
95 95

File Added: src/sys/arch/i386/stand/efiboot/efidev.c
/*	$NetBSD: efidev.c,v 1.1.2.2 2018/03/13 14:54:52 martin Exp $	*/
/*	$OpenBSD: efiboot.c,v 1.28 2017/11/25 19:02:07 patrick Exp $	*/

/*
 * Copyright (c) 2015 YASUOKA Masahiko <yasuoka@yasuoka.net>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include "efiboot.h"

/*
 * Determine the number of nodes up to, but not including, the first
 * node of the specified type.
 */
int
efi_device_path_depth(EFI_DEVICE_PATH *dp, int dptype)
{
	int	i;

	for (i = 0; !IsDevicePathEnd(dp); dp = NextDevicePathNode(dp), i++) {
		if (DevicePathType(dp) == dptype)
			return (i);
	}

	return (-1);
}

int
efi_device_path_ncmp(EFI_DEVICE_PATH *dpa, EFI_DEVICE_PATH *dpb, int deptn)
{
	int	 i, cmp;

	for (i = 0; i < deptn; i++) {
		if (IsDevicePathEnd(dpa) || IsDevicePathEnd(dpb))
			return ((IsDevicePathEnd(dpa) && IsDevicePathEnd(dpb))
			    ? 0 : (IsDevicePathEnd(dpa))? -1 : 1);
		cmp = DevicePathNodeLength(dpa) - DevicePathNodeLength(dpb);
		if (cmp)
			return (cmp);
		cmp = memcmp(dpa, dpb, DevicePathNodeLength(dpa));
		if (cmp)
			return (cmp);
		dpa = NextDevicePathNode(dpa);
		dpb = NextDevicePathNode(dpb);
	}

	return (0);
}

cvs diff -r1.46 -r1.46.6.1 src/sys/arch/i386/stand/lib/biosdisk.c (expand / switch to unified diff)

--- src/sys/arch/i386/stand/lib/biosdisk.c 2017/01/24 11:09:14 1.46
+++ src/sys/arch/i386/stand/lib/biosdisk.c 2018/03/13 14:54:52 1.46.6.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: biosdisk.c,v 1.46 2017/01/24 11:09:14 nonaka Exp $ */ 1/* $NetBSD: biosdisk.c,v 1.46.6.1 2018/03/13 14:54:52 martin Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, 1998 4 * Copyright (c) 1996, 1998
5 * Matthias Drochner. All rights reserved. 5 * Matthias Drochner. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -79,47 +79,38 @@ @@ -79,47 +79,38 @@
79 79
80#include <fs/cd9660/iso.h> 80#include <fs/cd9660/iso.h>
81 81
82#include <lib/libsa/saerrno.h> 82#include <lib/libsa/saerrno.h>
83#include <machine/cpu.h> 83#include <machine/cpu.h>
84 84
85#include "libi386.h" 85#include "libi386.h"
86#include "biosdisk_ll.h" 86#include "biosdisk_ll.h"
87#include "biosdisk.h" 87#include "biosdisk.h"
88#ifdef _STANDALONE 88#ifdef _STANDALONE
89#include "bootinfo.h" 89#include "bootinfo.h"
90#endif 90#endif
91 91
92#define BUFSIZE 2048 /* must be large enough for a CD sector */ 92#ifndef BIOSDISK_BUFSIZE
 93#define BIOSDISK_BUFSIZE 2048 /* must be large enough for a CD sector */
 94#endif
93 95
94#define BIOSDISKNPART 26 96#define BIOSDISKNPART 26
95 97
96struct biosdisk { 98struct biosdisk {
97 struct biosdisk_ll ll; 99 struct biosdisk_ll ll;
98 daddr_t boff; 100 daddr_t boff;
99 char buf[BUFSIZE]; 101 char buf[BIOSDISK_BUFSIZE];
100#if !defined(NO_DISKLABEL) || !defined(NO_GPT) 102#if !defined(NO_DISKLABEL) || !defined(NO_GPT)
101 struct { 103 struct biosdisk_partition part[BIOSDISKNPART];
102 daddr_t offset; 
103 daddr_t size; 
104 int fstype; 
105#ifdef EFIBOOT 
106 const struct gpt_part { 
107 const struct uuid *guid; 
108 const char *name; 
109 } *guid; 
110 uint64_t attr; 
111#endif 
112 } part[BIOSDISKNPART]; 
113#endif 104#endif
114}; 105};
115 106
116#ifndef NO_GPT 107#ifndef NO_GPT
117const struct uuid GET_nbsd_raid = GPT_ENT_TYPE_NETBSD_RAIDFRAME; 108const struct uuid GET_nbsd_raid = GPT_ENT_TYPE_NETBSD_RAIDFRAME;
118const struct uuid GET_nbsd_ffs = GPT_ENT_TYPE_NETBSD_FFS; 109const struct uuid GET_nbsd_ffs = GPT_ENT_TYPE_NETBSD_FFS;
119const struct uuid GET_nbsd_lfs = GPT_ENT_TYPE_NETBSD_LFS; 110const struct uuid GET_nbsd_lfs = GPT_ENT_TYPE_NETBSD_LFS;
120const struct uuid GET_nbsd_swap = GPT_ENT_TYPE_NETBSD_SWAP; 111const struct uuid GET_nbsd_swap = GPT_ENT_TYPE_NETBSD_SWAP;
121const struct uuid GET_nbsd_ccd = GPT_ENT_TYPE_NETBSD_CCD; 112const struct uuid GET_nbsd_ccd = GPT_ENT_TYPE_NETBSD_CCD;
122const struct uuid GET_nbsd_cgd = GPT_ENT_TYPE_NETBSD_CGD; 113const struct uuid GET_nbsd_cgd = GPT_ENT_TYPE_NETBSD_CGD;
123#ifdef EFIBOOT 114#ifdef EFIBOOT
124const struct uuid GET_efi = GPT_ENT_TYPE_EFI; 115const struct uuid GET_efi = GPT_ENT_TYPE_EFI;
125const struct uuid GET_mbr = GPT_ENT_TYPE_MBR; 116const struct uuid GET_mbr = GPT_ENT_TYPE_MBR;
@@ -168,40 +159,44 @@ const struct gpt_part gpt_parts[] = { @@ -168,40 +159,44 @@ const struct gpt_part gpt_parts[] = {
168}; 159};
169#endif 160#endif
170#endif /* NO_GPT */ 161#endif /* NO_GPT */
171 162
172#ifdef _STANDALONE 163#ifdef _STANDALONE
173static struct btinfo_bootdisk bi_disk; 164static struct btinfo_bootdisk bi_disk;
174static struct btinfo_bootwedge bi_wedge; 165static struct btinfo_bootwedge bi_wedge;
175#endif 166#endif
176 167
177#define MBR_PARTS(buf) ((char *)(buf) + offsetof(struct mbr_sector, mbr_parts)) 168#define MBR_PARTS(buf) ((char *)(buf) + offsetof(struct mbr_sector, mbr_parts))
178 169
179#define RF_PROTECTED_SECTORS 64 /* XXX refer to <.../rf_optnames.h> */ 170#define RF_PROTECTED_SECTORS 64 /* XXX refer to <.../rf_optnames.h> */
180 171
 172#ifndef devb2cdb
 173#define devb2cdb(bno) (((bno) * DEV_BSIZE) / ISO_DEFAULT_BLOCK_SIZE)
 174#endif
 175
181int 176int
182biosdisk_strategy(void *devdata, int flag, daddr_t dblk, size_t size, 177biosdisk_strategy(void *devdata, int flag, daddr_t dblk, size_t size,
183 void *buf, size_t *rsize) 178 void *buf, size_t *rsize)
184{ 179{
185 struct biosdisk *d; 180 struct biosdisk *d;
186 int blks, frag; 181 int blks, frag;
187 182
188 if (flag != F_READ) 183 if (flag != F_READ)
189 return EROFS; 184 return EROFS;
190 185
191 d = (struct biosdisk *) devdata; 186 d = (struct biosdisk *) devdata;
192 187
193 if (d->ll.type == BIOSDISK_TYPE_CD) 188 if (d->ll.type == BIOSDISK_TYPE_CD)
194 dblk = dblk * DEV_BSIZE / ISO_DEFAULT_BLOCK_SIZE; 189 dblk = devb2cdb(dblk);
195 190
196 dblk += d->boff; 191 dblk += d->boff;
197 192
198 blks = size / d->ll.secsize; 193 blks = size / d->ll.secsize;
199 if (blks && readsects(&d->ll, dblk, blks, buf, 0)) { 194 if (blks && readsects(&d->ll, dblk, blks, buf, 0)) {
200 if (rsize) 195 if (rsize)
201 *rsize = 0; 196 *rsize = 0;
202 return EIO; 197 return EIO;
203 } 198 }
204 199
205 /* needed for CD */ 200 /* needed for CD */
206 frag = size % d->ll.secsize; 201 frag = size % d->ll.secsize;
207 if (frag) { 202 if (frag) {
@@ -507,26 +502,59 @@ read_minix_subp(struct biosdisk *d, stru @@ -507,26 +502,59 @@ read_minix_subp(struct biosdisk *d, stru
507 if (typ == 0) 502 if (typ == 0)
508 continue; 503 continue;
509 sector = this_ext + mbr[i].mbrp_start; 504 sector = this_ext + mbr[i].mbrp_start;
510 if (dflt_lbl->d_npartitions >= MAXPARTITIONS) 505 if (dflt_lbl->d_npartitions >= MAXPARTITIONS)
511 continue; 506 continue;
512 p = &dflt_lbl->d_partitions[dflt_lbl->d_npartitions++]; 507 p = &dflt_lbl->d_partitions[dflt_lbl->d_npartitions++];
513 p->p_offset = sector; 508 p->p_offset = sector;
514 p->p_size = mbr[i].mbrp_size; 509 p->p_size = mbr[i].mbrp_size;
515 p->p_fstype = xlat_mbr_fstype(typ); 510 p->p_fstype = xlat_mbr_fstype(typ);
516 } 511 }
517 return 0; 512 return 0;
518} 513}
519 514
 515#if defined(EFIBOOT) && defined(SUPPORT_CD9660)
 516static int
 517check_cd9660(struct biosdisk *d)
 518{
 519 struct biosdisk_extinfo ed;
 520 struct iso_primary_descriptor *vd;
 521 daddr_t bno;
 522
 523 for (bno = 16;; bno++) {
 524 if (readsects(&d->ll, bno, 1, d->buf, 0))
 525 return -1;
 526 vd = (struct iso_primary_descriptor *)d->buf;
 527 if (memcmp(vd->id, ISO_STANDARD_ID, sizeof vd->id) != 0)
 528 return -1;
 529 if (isonum_711(vd->type) == ISO_VD_END)
 530 return -1;
 531 if (isonum_711(vd->type) == ISO_VD_PRIMARY)
 532 break;
 533 }
 534 if (isonum_723(vd->logical_block_size) != ISO_DEFAULT_BLOCK_SIZE)
 535 return -1;
 536
 537 if (set_geometry(&d->ll, &ed))
 538 return -1;
 539
 540 memset(d->part, 0, sizeof(d->part));
 541 d->part[0].fstype = FS_ISO9660;
 542 d->part[0].offset = 0;
 543 d->part[0].size = ed.totsec;
 544 return 0;
 545}
 546#endif
 547
520static int 548static int
521read_label(struct biosdisk *d) 549read_label(struct biosdisk *d)
522{ 550{
523 struct disklabel dflt_lbl; 551 struct disklabel dflt_lbl;
524 struct mbr_partition mbr[MBR_PART_COUNT]; 552 struct mbr_partition mbr[MBR_PART_COUNT];
525 struct partition *p; 553 struct partition *p;
526 uint32_t sector; 554 uint32_t sector;
527 int i; 555 int i;
528 int error; 556 int error;
529 int typ; 557 int typ;
530 uint32_t ext_base, this_ext, next_ext; 558 uint32_t ext_base, this_ext, next_ext;
531#ifdef COMPAT_386BSD_MBRPART 559#ifdef COMPAT_386BSD_MBRPART
532 int sector_386bsd = -1; 560 int sector_386bsd = -1;
@@ -614,26 +642,33 @@ read_label(struct biosdisk *d) @@ -614,26 +642,33 @@ read_label(struct biosdisk *d)
614 642
615 /* 643 /*
616 * One of two things: 644 * One of two things:
617 * 1. no MBR 645 * 1. no MBR
618 * 2. no NetBSD partition in MBR 646 * 2. no NetBSD partition in MBR
619 * 647 *
620 * We simply default to "start of disk" in this case and 648 * We simply default to "start of disk" in this case and
621 * press on. 649 * press on.
622 */ 650 */
623 error = check_label(d, sector); 651 error = check_label(d, sector);
624 if (error >= 0) 652 if (error >= 0)
625 return error; 653 return error;
626 654
 655#if defined(EFIBOOT) && defined(SUPPORT_CD9660)
 656 /* Check CD/DVD */
 657 error = check_cd9660(d);
 658 if (error >= 0)
 659 return error;
 660#endif
 661
627 /* 662 /*
628 * Nothing at start of disk, return info from mbr partitions. 663 * Nothing at start of disk, return info from mbr partitions.
629 */ 664 */
630 /* XXX fill it to make checksum match kernel one */ 665 /* XXX fill it to make checksum match kernel one */
631 dflt_lbl.d_checksum = dkcksum(&dflt_lbl); 666 dflt_lbl.d_checksum = dkcksum(&dflt_lbl);
632 ingest_label(d, &dflt_lbl); 667 ingest_label(d, &dflt_lbl);
633 return 0; 668 return 0;
634} 669}
635#endif /* NO_DISKLABEL */ 670#endif /* NO_DISKLABEL */
636 671
637#if !defined(NO_DISKLABEL) || !defined(NO_GPT) 672#if !defined(NO_DISKLABEL) || !defined(NO_GPT)
638static int 673static int
639read_partitions(struct biosdisk *d) 674read_partitions(struct biosdisk *d)
@@ -764,50 +799,88 @@ biosdisk_findpartition(int biosdev, dadd @@ -764,50 +799,88 @@ biosdisk_findpartition(int biosdev, dadd
764 799
765 if (read_partitions(d) == 0) { 800 if (read_partitions(d) == 0) {
766 for (partition = (BIOSDISKNPART-1); --partition;) { 801 for (partition = (BIOSDISKNPART-1); --partition;) {
767 if (d->part[partition].fstype == FS_UNUSED) 802 if (d->part[partition].fstype == FS_UNUSED)
768 continue; 803 continue;
769#ifdef EFIBOOT 804#ifdef EFIBOOT
770 if (d->part[partition].attr & GPT_ENT_ATTR_BOOTME) { 805 if (d->part[partition].attr & GPT_ENT_ATTR_BOOTME) {
771 switch (d->part[partition].fstype) { 806 switch (d->part[partition].fstype) {
772 case FS_BSDFFS: 807 case FS_BSDFFS:
773 case FS_BSDLFS: 808 case FS_BSDLFS:
774 case FS_RAID: 809 case FS_RAID:
775 case FS_CCD: 810 case FS_CCD:
776 case FS_CGD: 811 case FS_CGD:
 812 case FS_ISO9660:
777 break; 813 break;
778 814
779 default: 815 default:
780 candidate = partition; 816 candidate = partition;
781 continue; 817 continue;
782 } 818 }
783 break; 819 break;
784 } 820 }
785#else 821#else
786 if (d->part[partition].offset == sector) 822 if (d->part[partition].offset == sector)
787 break; 823 break;
788#endif 824#endif
789 } 825 }
790#ifdef EFIBOOT 826#ifdef EFIBOOT
791 if (partition == 0 && candidate != 0) 827 if (partition == 0 && candidate != 0)
792 partition = candidate; 828 partition = candidate;
793#endif 829#endif
794 } 830 }
795 831
796 dealloc(d, sizeof(*d)); 832 dealloc(d, sizeof(*d));
797 return partition; 833 return partition;
798#endif /* NO_DISKLABEL && NO_GPT */ 834#endif /* NO_DISKLABEL && NO_GPT */
799} 835}
800 836
 837int
 838biosdisk_readpartition(int biosdev, struct biosdisk_partition **partpp,
 839 int *rnum)
 840{
 841#if defined(NO_DISKLABEL) && defined(NO_GPT)
 842 return ENOTSUP;
 843#else
 844 struct biosdisk *d;
 845 struct biosdisk_partition *part;
 846 int rv;
 847
 848 /* Look for netbsd partition that is the dos boot one */
 849 d = alloc_biosdisk(biosdev);
 850 if (d == NULL)
 851 return ENOMEM;
 852
 853 if (read_partitions(d)) {
 854 rv = EINVAL;
 855 goto out;
 856 }
 857
 858 part = alloc(sizeof(d->part));
 859 if (part == NULL) {
 860 rv = ENOMEM;
 861 goto out;
 862 }
 863
 864 memcpy(part, d->part, sizeof(d->part));
 865 *partpp = part;
 866 *rnum = (int)__arraycount(d->part);
 867 rv = 0;
 868out:
 869 dealloc(d, sizeof(*d));
 870 return rv;
 871#endif /* NO_DISKLABEL && NO_GPT */
 872}
 873
801#ifdef _STANDALONE 874#ifdef _STANDALONE
802static void 875static void
803add_biosdisk_bootinfo(void) 876add_biosdisk_bootinfo(void)
804{ 877{
805 if (bootinfo == NULL) { 878 if (bootinfo == NULL) {
806 return; 879 return;
807 } 880 }
808 BI_ADD(&bi_disk, BTINFO_BOOTDISK, sizeof(bi_disk)); 881 BI_ADD(&bi_disk, BTINFO_BOOTDISK, sizeof(bi_disk));
809 BI_ADD(&bi_wedge, BTINFO_BOOTWEDGE, sizeof(bi_wedge)); 882 BI_ADD(&bi_wedge, BTINFO_BOOTWEDGE, sizeof(bi_wedge));
810 return; 883 return;
811} 884}
812#endif 885#endif
813 886

cvs diff -r1.8 -r1.8.52.1 src/sys/arch/i386/stand/lib/biosdisk.h (expand / switch to unified diff)

--- src/sys/arch/i386/stand/lib/biosdisk.h 2010/12/24 20:36:51 1.8
+++ src/sys/arch/i386/stand/lib/biosdisk.h 2018/03/13 14:54:52 1.8.52.1
@@ -1,32 +1,46 @@ @@ -1,32 +1,46 @@
1/* $NetBSD: biosdisk.h,v 1.8 2010/12/24 20:36:51 jakllsch Exp $ */ 1/* $NetBSD: biosdisk.h,v 1.8.52.1 2018/03/13 14:54:52 martin Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996 4 * Copyright (c) 1996
5 * Matthias Drochner. All rights reserved. 5 * Matthias Drochner. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
 28struct biosdisk_partition {
 29 daddr_t offset;
 30 daddr_t size;
 31 int fstype;
 32#ifdef EFIBOOT
 33 const struct gpt_part {
 34 const struct uuid *guid;
 35 const char *name;
 36 } *guid;
 37 uint64_t attr;
 38#endif
 39};
 40
28int biosdisk_strategy(void *, int, daddr_t, size_t, void *, size_t *); 41int biosdisk_strategy(void *, int, daddr_t, size_t, void *, size_t *);
29int biosdisk_open(struct open_file *, ...); 42int biosdisk_open(struct open_file *, ...);
30int biosdisk_close(struct open_file *); 43int biosdisk_close(struct open_file *);
31int biosdisk_ioctl(struct open_file *, u_long, void *); 44int biosdisk_ioctl(struct open_file *, u_long, void *);
32int biosdisk_findpartition(int, daddr_t); 45int biosdisk_findpartition(int, daddr_t);
 46int biosdisk_readpartition(int, struct biosdisk_partition **, int *);

cvs diff -r1.15 -r1.15.90.1 src/sys/arch/i386/stand/lib/biosdisk_ll.h (expand / switch to unified diff)

--- src/sys/arch/i386/stand/lib/biosdisk_ll.h 2007/12/25 18:33:34 1.15
+++ src/sys/arch/i386/stand/lib/biosdisk_ll.h 2018/03/13 14:54:52 1.15.90.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: biosdisk_ll.h,v 1.15 2007/12/25 18:33:34 perry Exp $ */ 1/* $NetBSD: biosdisk_ll.h,v 1.15.90.1 2018/03/13 14:54:52 martin Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996 4 * Copyright (c) 1996
5 * Matthias Drochner. All rights reserved. 5 * Matthias Drochner. All rights reserved.
6 * Copyright (c) 1996 6 * Copyright (c) 1996
7 * Perry E. Metzger. All rights reserved. 7 * Perry E. Metzger. All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -110,17 +110,19 @@ struct biosdisk_extinfo { @@ -110,17 +110,19 @@ struct biosdisk_extinfo {
110 uint8_t checksum; /* byte sum from dev_path_sig is 0 */ 110 uint8_t checksum; /* byte sum from dev_path_sig is 0 */
111#endif /* BIOSDISK_EXTINFO_V3 */ 111#endif /* BIOSDISK_EXTINFO_V3 */
112#endif /* BIOSDISK_EXTINFO_V2 */ 112#endif /* BIOSDISK_EXTINFO_V2 */
113} __packed; 113} __packed;
114 114
115#define EXTINFO_DMA_TRANS 0x0001 /* transparent DMA boundary errors */ 115#define EXTINFO_DMA_TRANS 0x0001 /* transparent DMA boundary errors */
116#define EXTINFO_GEOM_VALID 0x0002 /* geometry in c/h/s in struct valid */ 116#define EXTINFO_GEOM_VALID 0x0002 /* geometry in c/h/s in struct valid */
117#define EXTINFO_REMOVABLE 0x0004 /* removable device */ 117#define EXTINFO_REMOVABLE 0x0004 /* removable device */
118#define EXTINFO_WRITEVERF 0x0008 /* supports write with verify */ 118#define EXTINFO_WRITEVERF 0x0008 /* supports write with verify */
119#define EXTINFO_CHANGELINE 0x0010 /* changeline support */ 119#define EXTINFO_CHANGELINE 0x0010 /* changeline support */
120#define EXTINFO_LOCKABLE 0x0020 /* device is lockable */ 120#define EXTINFO_LOCKABLE 0x0020 /* device is lockable */
121#define EXTINFO_MAXGEOM 0x0040 /* geometry set to max; no media */ 121#define EXTINFO_MAXGEOM 0x0040 /* geometry set to max; no media */
122 122
 123#ifndef BIOSDISK_DEFAULT_SECSIZE
123#define BIOSDISK_DEFAULT_SECSIZE 512 124#define BIOSDISK_DEFAULT_SECSIZE 512
 125#endif
124 126
125int set_geometry(struct biosdisk_ll *, struct biosdisk_extinfo *); 127int set_geometry(struct biosdisk_ll *, struct biosdisk_extinfo *);
126int readsects(struct biosdisk_ll *, daddr_t, int, char *, int); 128int readsects(struct biosdisk_ll *, daddr_t, int, char *, int);

cvs diff -r1.30 -r1.30.22.1 src/sys/lib/libsa/cd9660.c (expand / switch to unified diff)

--- src/sys/lib/libsa/cd9660.c 2014/03/20 03:13:18 1.30
+++ src/sys/lib/libsa/cd9660.c 2018/03/13 14:54:52 1.30.22.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: cd9660.c,v 1.30 2014/03/20 03:13:18 christos Exp $ */ 1/* $NetBSD: cd9660.c,v 1.30.22.1 2018/03/13 14:54:52 martin Exp $ */
2 2
3/* 3/*
4 * Copyright (C) 1996 Wolfgang Solfrank. 4 * Copyright (C) 1996 Wolfgang Solfrank.
5 * Copyright (C) 1996 TooLs GmbH. 5 * Copyright (C) 1996 TooLs GmbH.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -61,27 +61,29 @@ struct file { @@ -61,27 +61,29 @@ struct file {
61 off_t size; /* Size of file */ 61 off_t size; /* Size of file */
62}; 62};
63 63
64struct ptable_ent { 64struct ptable_ent {
65 char namlen [ISODCL( 1, 1)]; /* 711 */ 65 char namlen [ISODCL( 1, 1)]; /* 711 */
66 char extlen [ISODCL( 2, 2)]; /* 711 */ 66 char extlen [ISODCL( 2, 2)]; /* 711 */
67 char block [ISODCL( 3, 6)]; /* 732 */ 67 char block [ISODCL( 3, 6)]; /* 732 */
68 char parent [ISODCL( 7, 8)]; /* 722 */ 68 char parent [ISODCL( 7, 8)]; /* 722 */
69 char name [1]; 69 char name [1];
70}; 70};
71#define PTFIXSZ 8 71#define PTFIXSZ 8
72#define PTSIZE(pp) roundup(PTFIXSZ + isonum_711((pp)->namlen), 2) 72#define PTSIZE(pp) roundup(PTFIXSZ + isonum_711((pp)->namlen), 2)
73 73
 74#ifndef cdb2devb
74#define cdb2devb(bno) ((bno) * ISO_DEFAULT_BLOCK_SIZE / DEV_BSIZE) 75#define cdb2devb(bno) ((bno) * ISO_DEFAULT_BLOCK_SIZE / DEV_BSIZE)
 76#endif
75 77
76static int pnmatch(const char *, struct ptable_ent *); 78static int pnmatch(const char *, struct ptable_ent *);
77static int dirmatch(const char *, struct iso_directory_record *); 79static int dirmatch(const char *, struct iso_directory_record *);
78 80
79static int 81static int
80pnmatch(const char *path, struct ptable_ent *pp) 82pnmatch(const char *path, struct ptable_ent *pp)
81{ 83{
82 char *cp; 84 char *cp;
83 int i; 85 int i;
84 86
85 cp = pp->name; 87 cp = pp->name;
86 for (i = isonum_711(pp->namlen); --i >= 0; path++, cp++) { 88 for (i = isonum_711(pp->namlen); --i >= 0; path++, cp++) {
87 if (toupper(*path) == *cp) 89 if (toupper(*path) == *cp)