Module Name:    src
Committed By:   jmcneill
Date:           Sun Oct 11 14:03:33 UTC 2020

Modified Files:
        src/sys/stand/efiboot: Makefile.efiboot boot.c conf.c efiblock.c
            efiblock.h efiboot.h version

Log Message:
Add ISO9660 support.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/stand/efiboot/Makefile.efiboot
cvs rdiff -u -r1.27 -r1.28 src/sys/stand/efiboot/boot.c
cvs rdiff -u -r1.4 -r1.5 src/sys/stand/efiboot/conf.c
cvs rdiff -u -r1.7 -r1.8 src/sys/stand/efiboot/efiblock.c
cvs rdiff -u -r1.3 -r1.4 src/sys/stand/efiboot/efiblock.h
cvs rdiff -u -r1.13 -r1.14 src/sys/stand/efiboot/efiboot.h
cvs rdiff -u -r1.20 -r1.21 src/sys/stand/efiboot/version

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/stand/efiboot/Makefile.efiboot
diff -u src/sys/stand/efiboot/Makefile.efiboot:1.18 src/sys/stand/efiboot/Makefile.efiboot:1.19
--- src/sys/stand/efiboot/Makefile.efiboot:1.18	Sun Sep  6 07:20:31 2020
+++ src/sys/stand/efiboot/Makefile.efiboot	Sun Oct 11 14:03:33 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.18 2020/09/06 07:20:31 mrg Exp $
+# $NetBSD: Makefile.efiboot,v 1.19 2020/10/11 14:03:33 jmcneill Exp $
 
 S=		${.CURDIR}/../../..
 
@@ -71,7 +71,7 @@ CPPFLAGS+= -Wall -Wmissing-prototypes
 CPPFLAGS+= -Wno-pointer-sign
 
 CPPFLAGS+= -DHEAP_VARIABLE
-#CPPFLAGS+= -DSUPPORT_CD9660
+CPPFLAGS+= -DSUPPORT_CD9660
 CPPFLAGS+= -D"devb2cdb(bno)=(bno)"
 CPPFLAGS+= -DSUPPORT_DOSFS
 #CPPFLAGS+= -DSUPPORT_EXT2FS

Index: src/sys/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.27 src/sys/stand/efiboot/boot.c:1.28
--- src/sys/stand/efiboot/boot.c:1.27	Sun Jun 28 11:39:50 2020
+++ src/sys/stand/efiboot/boot.c	Sun Oct 11 14:03:33 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.27 2020/06/28 11:39:50 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.28 2020/10/11 14:03:33 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <[email protected]>
@@ -75,6 +75,7 @@ static const char *efi_memory_type[] = {
 };
 
 static char default_device[32];
+static int default_fstype = FS_UNUSED;
 static char initrd_path[255];
 static char dtb_path[255];
 static char netbsd_path[255];
@@ -128,6 +129,27 @@ const struct boot_command commands[] = {
 	{ NULL,		NULL },
 };
 
+static int
+bootcfg_path(char *pathbuf, size_t pathbuflen)
+{
+	/*
+	 * Special handling of boot.cfg on ISO9660 because fs protocol doesn't
+	 * seem to work.
+	 */
+	if (default_fstype == FS_ISO9660) {
+		snprintf(pathbuf, pathbuflen, "%s:%s", default_device, BOOTCFG_FILENAME);
+		return 0;
+	}
+
+	/*
+	 * Fall back to fs protocol for loading boot.cfg
+	 */
+	if (efi_bootdp == NULL)
+		return ENXIO;
+
+	return efi_file_path(efi_bootdp, BOOTCFG_FILENAME, pathbuf, pathbuflen);
+}
+
 void
 command_help(char *arg)
 {
@@ -318,8 +340,7 @@ command_version(char *arg)
 		    ST->FirmwareRevision);
 		FreePool(ufirmware);
 	}
-	if (efi_bootdp != NULL &&
-	    efi_file_path(efi_bootdp, BOOTCFG_FILENAME, pathbuf, sizeof(pathbuf)) == 0) {
+	if (bootcfg_path(pathbuf, sizeof(pathbuf)) == 0) {
 		printf("Config path: %s\n", pathbuf);
 	}
 
@@ -355,6 +376,18 @@ get_default_device(void)
 	return default_device;
 }
 
+void
+set_default_fstype(int fstype)
+{
+	default_fstype = fstype;
+}
+
+int
+get_default_fstype(void)
+{
+	return default_fstype;
+}
+
 int
 set_initrd_path(const char *arg)
 {
@@ -432,7 +465,7 @@ boot(void)
 	char pathbuf[80];
 	int currname, c;
 
-	if (efi_bootdp != NULL && efi_file_path(efi_bootdp, BOOTCFG_FILENAME, pathbuf, sizeof(pathbuf)) == 0) {
+	if (bootcfg_path(pathbuf, sizeof(pathbuf)) == 0) {
 		twiddle_toggle = 1;
 		parsebootconf(pathbuf);
 	}

Index: src/sys/stand/efiboot/conf.c
diff -u src/sys/stand/efiboot/conf.c:1.4 src/sys/stand/efiboot/conf.c:1.5
--- src/sys/stand/efiboot/conf.c:1.4	Thu Nov 15 23:52:33 2018
+++ src/sys/stand/efiboot/conf.c	Sun Oct 11 14:03:33 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: conf.c,v 1.4 2018/11/15 23:52:33 jmcneill Exp $ */
+/* $NetBSD: conf.c,v 1.5 2020/10/11 14:03:33 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <[email protected]>
@@ -33,6 +33,7 @@
 #include <lib/libsa/stand.h>
 #include <lib/libsa/ufs.h>
 #include <lib/libsa/dosfs.h>
+#include <lib/libsa/cd9660.h>
 #include <lib/libsa/tftp.h>
 #include <lib/libsa/nfs.h>
 #include <lib/libsa/net.h>
@@ -55,6 +56,7 @@ struct fs_ops file_system[] = {
 	FS_OPS(ffsv1),
 	FS_OPS(ffsv2),
 	FS_OPS(dosfs),
+	FS_OPS(cd9660),
 };
 int nfsys = __arraycount(file_system);
 

Index: src/sys/stand/efiboot/efiblock.c
diff -u src/sys/stand/efiboot/efiblock.c:1.7 src/sys/stand/efiboot/efiblock.c:1.8
--- src/sys/stand/efiboot/efiblock.c:1.7	Fri Sep 27 20:10:42 2019
+++ src/sys/stand/efiboot/efiblock.c	Sun Oct 11 14:03:33 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.c,v 1.7 2019/09/27 20:10:42 jakllsch Exp $ */
+/* $NetBSD: efiblock.c,v 1.8 2020/10/11 14:03:33 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <[email protected]>
@@ -33,6 +33,8 @@
 #include <sys/md5.h>
 #include <sys/uuid.h>
 
+#include <fs/cd9660/iso.h>
+
 #include "efiboot.h"
 #include "efiblock.h"
 
@@ -116,6 +118,53 @@ efi_block_allocate_device_buffer(struct 
 }
 
 static int
+efi_block_find_partitions_cd9660(struct efi_block_dev *bdev)
+{
+	struct efi_block_part *bpart;
+	struct iso_primary_descriptor *vd;
+	void *buf, *buf_start;
+	EFI_STATUS status;
+	EFI_LBA lba;
+	UINT32 sz;
+
+	sz = __MAX(sizeof(*vd), bdev->bio->Media->BlockSize);
+	sz = roundup(sz, bdev->bio->Media->BlockSize);
+	if ((buf = efi_block_allocate_device_buffer(bdev, sz, &buf_start)) == NULL)
+		return ENOMEM;
+
+	for (lba = 16;; lba++) {
+		status = uefi_call_wrapper(bdev->bio->ReadBlocks, 5, bdev->bio, bdev->media_id,
+		    lba, sz, buf_start);
+		if (EFI_ERROR(status))
+			goto io_error;
+
+		vd = (struct iso_primary_descriptor *)buf_start;
+		if (memcmp(vd->id, ISO_STANDARD_ID, sizeof vd->id) != 0)
+			goto io_error;
+		if (isonum_711(vd->type) == ISO_VD_END)
+			goto io_error;
+		if (isonum_711(vd->type) == ISO_VD_PRIMARY)
+			break;
+	}
+
+	if (isonum_723(vd->logical_block_size) != ISO_DEFAULT_BLOCK_SIZE)
+		goto io_error;
+
+	bpart = alloc(sizeof(*bpart));
+	bpart->index = 0;
+	bpart->bdev = bdev;
+	bpart->type = EFI_BLOCK_PART_CD9660;
+	TAILQ_INSERT_TAIL(&bdev->partitions, bpart, entries);
+
+	FreePool(buf);
+	return 0;
+
+io_error:
+	FreePool(buf);
+	return EIO;
+}
+
+static int
 efi_block_find_partitions_disklabel(struct efi_block_dev *bdev, struct mbr_sector *mbr, uint32_t start, uint32_t size)
 {
 	struct efi_block_part *bpart;
@@ -310,6 +359,8 @@ efi_block_find_partitions(struct efi_blo
 	error = efi_block_find_partitions_gpt(bdev);
 	if (error)
 		error = efi_block_find_partitions_mbr(bdev);
+	if (error)
+		error = efi_block_find_partitions_cd9660(bdev);
 
 	return error;
 }
@@ -365,11 +416,15 @@ efi_block_probe(void)
 				case EFI_BLOCK_PART_GPT:
 					fstype = bpart->gpt.fstype;
 					break;
+				case EFI_BLOCK_PART_CD9660:
+					fstype = FS_ISO9660;
+					break;
 				}
-				if (fstype == FS_BSDFFS) {
+				if (fstype == FS_BSDFFS || fstype == FS_ISO9660) {
 					char devname[9];
 					snprintf(devname, sizeof(devname), "hd%u%c", bdev->index, bpart->index + 'a');
 					set_default_device(devname);
+					set_default_fstype(fstype);
 					break;
 				}
 			}
@@ -451,6 +506,9 @@ efi_block_show(void)
 
 				printf("%s\n", fstypenames[bpart->gpt.fstype]);
 				break;
+			case EFI_BLOCK_PART_CD9660:
+				printf("  hd%u%c %s\n", bdev->index, bpart->index + 'a', fstypenames[FS_ISO9660]);
+				break;
 			default:
 				break;
 			}
@@ -533,6 +591,8 @@ efi_block_strategy(void *devdata, int rw
 		}
 		dblk += le64toh(bpart->gpt.ent.ent_lba_start);
 		break;
+	case EFI_BLOCK_PART_CD9660:
+		break;
 	default:
 		return EINVAL;
 	}

Index: src/sys/stand/efiboot/efiblock.h
diff -u src/sys/stand/efiboot/efiblock.h:1.3 src/sys/stand/efiboot/efiblock.h:1.4
--- src/sys/stand/efiboot/efiblock.h:1.3	Thu Nov  1 00:43:38 2018
+++ src/sys/stand/efiboot/efiblock.h	Sun Oct 11 14:03:33 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.h,v 1.3 2018/11/01 00:43:38 jmcneill Exp $ */
+/* $NetBSD: efiblock.h,v 1.4 2020/10/11 14:03:33 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <[email protected]>
@@ -33,7 +33,8 @@
 
 enum efi_block_part_type {
 	EFI_BLOCK_PART_DISKLABEL,
-	EFI_BLOCK_PART_GPT
+	EFI_BLOCK_PART_GPT,
+	EFI_BLOCK_PART_CD9660
 };
 
 struct efi_block_part;

Index: src/sys/stand/efiboot/efiboot.h
diff -u src/sys/stand/efiboot/efiboot.h:1.13 src/sys/stand/efiboot/efiboot.h:1.14
--- src/sys/stand/efiboot/efiboot.h:1.13	Wed Jul 15 00:51:40 2020
+++ src/sys/stand/efiboot/efiboot.h	Sun Oct 11 14:03:33 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: efiboot.h,v 1.13 2020/07/15 00:51:40 jmcneill Exp $	*/
+/*	$NetBSD: efiboot.h,v 1.14 2020/10/11 14:03:33 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <[email protected]>
@@ -56,6 +56,8 @@ extern const struct boot_command command
 void command_help(char *);
 int set_default_device(const char *);
 char *get_default_device(void);
+void set_default_fstype(int);
+int get_default_fstype(void);
 int set_initrd_path(const char *);
 char *get_initrd_path(void);
 int set_dtb_path(const char *);

Index: src/sys/stand/efiboot/version
diff -u src/sys/stand/efiboot/version:1.20 src/sys/stand/efiboot/version:1.21
--- src/sys/stand/efiboot/version:1.20	Sat Oct 10 19:17:39 2020
+++ src/sys/stand/efiboot/version	Sun Oct 11 14:03:33 2020
@@ -1,4 +1,4 @@
-$NetBSD: version,v 1.20 2020/10/10 19:17:39 jmcneill Exp $
+$NetBSD: version,v 1.21 2020/10/11 14:03:33 jmcneill Exp $
 
 NOTE ANY CHANGES YOU MAKE TO THE EFI BOOTLOADER HERE.  The format of this
 file is important - make sure the entries are appended on end, last item
@@ -24,3 +24,4 @@ is taken as the current.
 2.1:	Remove efiboot.plist support; support dtoverlay in boot.cfg.
 2.2:	Remove support for storing settings in EFI env vars.
 2.3:	EFI RT and GOP support for devicetree mode.
+2.4:	Add ISO9660 support.

Reply via email to