CVS commit: src/sys/stand/efiboot

2021-07-24 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jul 24 10:22:28 UTC 2021

Modified Files:
src/sys/stand/efiboot: boot.c

Log Message:
efiboot: Allow "fs" as alias for "initrd", for compat with x86


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/stand/efiboot/boot.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/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.34 src/sys/stand/efiboot/boot.c:1.35
--- src/sys/stand/efiboot/boot.c:1.34	Wed Jun 23 21:43:38 2021
+++ src/sys/stand/efiboot/boot.c	Sat Jul 24 10:22:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.34 2021/06/23 21:43:38 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.35 2021/07/24 10:22:28 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -110,6 +110,7 @@ const struct boot_command commands[] = {
 	{ "dev",	command_dev,		"dev" },
 	{ "dtb",	command_dtb,		"dtb [dev:][filename]" },
 	{ "initrd",	command_initrd,		"initrd [dev:][filename]" },
+	{ "fs",		command_initrd,		NULL },
 	{ "rndseed",	command_rndseed,	"rndseed [dev:][filename]" },
 	{ "dtoverlay",	command_dtoverlay,	"dtoverlay [dev:][filename]" },
 	{ "dtoverlays",	command_dtoverlays,	"dtoverlays [{on|off|reset}]" },



CVS commit: src/sys/stand/efiboot

2021-07-23 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Jul 23 21:33:00 UTC 2021

Modified Files:
src/sys/stand/efiboot: efiacpi.c smbios.c

Log Message:
efiboot: Add support for SMBIOS 2.x tables.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/stand/efiboot/efiacpi.c
cvs rdiff -u -r1.2 -r1.3 src/sys/stand/efiboot/smbios.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/stand/efiboot/efiacpi.c
diff -u src/sys/stand/efiboot/efiacpi.c:1.9 src/sys/stand/efiboot/efiacpi.c:1.10
--- src/sys/stand/efiboot/efiacpi.c:1.9	Fri May 21 21:53:15 2021
+++ src/sys/stand/efiboot/efiacpi.c	Fri Jul 23 21:33:00 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: efiacpi.c,v 1.9 2021/05/21 21:53:15 jmcneill Exp $ */
+/* $NetBSD: efiacpi.c,v 1.10 2021/07/23 21:33:00 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -52,10 +52,11 @@ struct acpi_rdsp {
 
 static EFI_GUID Acpi20TableGuid = ACPI_20_TABLE_GUID;
 static EFI_GUID Smbios3TableGuid = SMBIOS3_TABLE_GUID;
+static EFI_GUID SmbiosTableGuid = SMBIOS_TABLE_GUID;
 
 static int acpi_enable = 1;
 static void *acpi_root = NULL;
-static void *smbios3_table = NULL;
+static void *smbios_table = NULL;
 
 int
 efi_acpi_probe(void)
@@ -66,9 +67,13 @@ efi_acpi_probe(void)
 	if (EFI_ERROR(status))
 		return EIO;
 
-	status = LibGetSystemConfigurationTable(, _table);
-	if (EFI_ERROR(status))
-		smbios3_table = NULL;
+	status = LibGetSystemConfigurationTable(, _table);
+	if (EFI_ERROR(status)) {
+		status = LibGetSystemConfigurationTable(, _table);
+	}
+	if (EFI_ERROR(status)) {
+		smbios_table = NULL;
+	}
 
 	return 0;
 }
@@ -103,8 +108,8 @@ efi_acpi_get_model(void)
 
 	memset(model_buf, 0, sizeof(model_buf));
 
-	if (smbios3_table != NULL) {
-		smbios_init(smbios3_table);
+	if (smbios_table != NULL) {
+		smbios_init(smbios_table);
 
 		buf = model_buf;
 		smbios.cookie = 0;
@@ -136,7 +141,7 @@ efi_acpi_show(void)
 	rsdp->oemid[0], rsdp->oemid[1], rsdp->oemid[2],
 	rsdp->oemid[3], rsdp->oemid[4], rsdp->oemid[5]);
 
-	if (smbios3_table)
+	if (smbios_table)
 		printf("SMBIOS: %s\n", efi_acpi_get_model());
 }
 
@@ -166,8 +171,8 @@ efi_acpi_create_fdt(void)
 
 	fdt_add_subnode(fdt, fdt_path_offset(fdt, "/"), "chosen");
 	fdt_setprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,acpi-root-table", (uint64_t)(uintptr_t)acpi_root);
-	if (smbios3_table)
-		fdt_setprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,smbios-table", (uint64_t)(uintptr_t)smbios3_table);
+	if (smbios_table)
+		fdt_setprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,smbios-table", (uint64_t)(uintptr_t)smbios_table);
 
 	fdt_add_subnode(fdt, fdt_path_offset(fdt, "/"), "acpi");
 	fdt_setprop_string(fdt, fdt_path_offset(fdt, "/acpi"), "compatible", "netbsd,acpi");

Index: src/sys/stand/efiboot/smbios.c
diff -u src/sys/stand/efiboot/smbios.c:1.2 src/sys/stand/efiboot/smbios.c:1.3
--- src/sys/stand/efiboot/smbios.c:1.2	Fri Dec 27 09:45:27 2019
+++ src/sys/stand/efiboot/smbios.c	Fri Jul 23 21:33:00 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: smbios.c,v 1.2 2019/12/27 09:45:27 msaitoh Exp $	*/
+/*	$NetBSD: smbios.c,v 1.3 2021/07/23 21:33:00 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -82,7 +82,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: smbios.c,v 1.2 2019/12/27 09:45:27 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: smbios.c,v 1.3 2021/07/23 21:33:00 jmcneill Exp $");
 
 #include 
 
@@ -91,8 +91,22 @@ __KERNEL_RCSID(0, "$NetBSD: smbios.c,v 1
 
 struct smbios_entry smbios_entry;
 
-void
-smbios_init(uint8_t *p)
+static void
+smbios2_init(uint8_t *p)
+{
+	const struct smbhdr *sh = (const struct smbhdr *)p;
+
+	smbios_entry.addr = (void *)(uintptr_t)sh->addr;
+	smbios_entry.len = sh->size;
+	smbios_entry.rev = 0;
+	smbios_entry.mjr = sh->majrev;
+	smbios_entry.min = sh->minrev;
+	smbios_entry.doc = 0;
+	smbios_entry.count = sh->count;
+}
+
+static void
+smbios3_init(uint8_t *p)
 {
 	const struct smb3hdr *sh = (const struct smb3hdr *)p;
 
@@ -105,6 +119,16 @@ smbios_init(uint8_t *p)
 	smbios_entry.count = UINT16_MAX;
 }
 
+void
+smbios_init(uint8_t *p)
+{
+	if (memcmp(p, "_SM3_", 5) == 0) {
+		smbios3_init(p);
+	} else if (memcmp(p, "_SM_", 4) == 0) {
+		smbios2_init(p);
+	}
+}
+
 /*
  * smbios_find_table() takes a caller supplied smbios struct type and
  * a pointer to a handle (struct smbtable) returning one if the structure
@@ -121,6 +145,10 @@ smbios_find_table(uint8_t type, struct s
 	struct smbtblhdr *hdr;
 	int ret = 0, tcount = 1;
 
+	if (smbios_entry.addr == 0) {
+		return 0;
+	}
+
 	va = smbios_entry.addr;
 	end = va + smbios_entry.len;
 
@@ -173,6 +201,10 @@ smbios_get_string(struct smbtable *st, u
 	char *ret = NULL;
 	int i;
 
+	if (smbios_entry.addr == 0) {
+		return NULL;
+	}
+
 	va = (uint8_t *)st->hdr + st->hdr->size;
 	end = smbios_entry.addr + smbios_entry.len;
 	for (i = 1; va < end && i < indx && *va; i++)



CVS commit: src/sys/stand/efiboot

2021-06-23 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Jun 23 21:43:38 UTC 2021

Modified Files:
src/sys/stand/efiboot: boot.c

Log Message:
When printing memory size, don't promote to next unit size unless it is at
two digits.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/stand/efiboot/boot.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/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.33 src/sys/stand/efiboot/boot.c:1.34
--- src/sys/stand/efiboot/boot.c:1.33	Wed Jun 23 00:38:12 2021
+++ src/sys/stand/efiboot/boot.c	Wed Jun 23 21:43:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.33 2021/06/23 00:38:12 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.34 2021/06/23 21:43:38 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -479,7 +479,7 @@ format_bytes(uint64_t val, uint64_t *pdi
 	*punit = "bytes";
 	*pdiv = 1;
 
-	for (n = 0; n < __arraycount(units) && val >= 1024; n++) {
+	for (n = 0; n < __arraycount(units) && val >= 1024 * 10; n++) {
 		*punit = units[n];
 		*pdiv *= 1024;
 		val /= 1024;



CVS commit: src/sys/stand/efiboot

2021-06-23 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Jun 23 21:42:43 UTC 2021

Modified Files:
src/sys/stand/efiboot: efiblock.c

Log Message:
fix typo


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/stand/efiboot/efiblock.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/stand/efiboot/efiblock.c
diff -u src/sys/stand/efiboot/efiblock.c:1.16 src/sys/stand/efiboot/efiblock.c:1.17
--- src/sys/stand/efiboot/efiblock.c:1.16	Wed Jun 23 20:55:50 2021
+++ src/sys/stand/efiboot/efiblock.c	Wed Jun 23 21:42:43 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.c,v 1.16 2021/06/23 20:55:50 jmcneill Exp $ */
+/* $NetBSD: efiblock.c,v 1.17 2021/06/23 21:42:43 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -133,7 +133,7 @@ efi_block_do_read_blockio(struct efi_blo
 	blkbuf_offset = off % bdev->bio->Media->BlockSize;
 	blkbuf_size = (lba_end - lba_start) * bdev->bio->Media->BlockSize;
 	if (bdev->bio->Media->IoAlign > 1) {
-		blkbuf_size = (blkbuf_size + bdev->bio-Media->IoAlign - 1) /
+		blkbuf_size = (blkbuf_size + bdev->bio->Media->IoAlign - 1) /
 		bdev->bio->Media->IoAlign *
 		bdev->bio->Media->IoAlign;
 	}



CVS commit: src/sys/stand/efiboot

2021-06-23 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Jun 23 20:55:50 UTC 2021

Modified Files:
src/sys/stand/efiboot: efiblock.c

Log Message:
Fix buffer size for alignment adjusted block I/O reads.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/stand/efiboot/efiblock.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/stand/efiboot/efiblock.c
diff -u src/sys/stand/efiboot/efiblock.c:1.15 src/sys/stand/efiboot/efiblock.c:1.16
--- src/sys/stand/efiboot/efiblock.c:1.15	Tue Jun 22 21:56:51 2021
+++ src/sys/stand/efiboot/efiblock.c	Wed Jun 23 20:55:50 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.c,v 1.15 2021/06/22 21:56:51 jmcneill Exp $ */
+/* $NetBSD: efiblock.c,v 1.16 2021/06/23 20:55:50 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -133,7 +133,9 @@ efi_block_do_read_blockio(struct efi_blo
 	blkbuf_offset = off % bdev->bio->Media->BlockSize;
 	blkbuf_size = (lba_end - lba_start) * bdev->bio->Media->BlockSize;
 	if (bdev->bio->Media->IoAlign > 1) {
-		blkbuf_size += bdev->bio->Media->IoAlign - 1;
+		blkbuf_size = (blkbuf_size + bdev->bio-Media->IoAlign - 1) /
+		bdev->bio->Media->IoAlign *
+		bdev->bio->Media->IoAlign;
 	}
 
 	blkbuf = AllocatePool(blkbuf_size);



CVS commit: src/sys/stand/efiboot

2021-06-22 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Jun 23 00:38:12 UTC 2021

Modified Files:
src/sys/stand/efiboot: boot.c

Log Message:
print_banner: Print memory size like x86 does


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/stand/efiboot/boot.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/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.32 src/sys/stand/efiboot/boot.c:1.33
--- src/sys/stand/efiboot/boot.c:1.32	Mon Jun 21 21:18:47 2021
+++ src/sys/stand/efiboot/boot.c	Wed Jun 23 00:38:12 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.32 2021/06/21 21:18:47 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.33 2021/06/23 00:38:12 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -450,13 +450,56 @@ set_bootargs(const char *arg)
 	return 0;
 }
 
+static void
+get_memory_info(uint64_t *ptotal)
+{
+	EFI_MEMORY_DESCRIPTOR *md, *memmap;
+	UINTN nentries, mapkey, descsize;
+	UINT32 descver;
+	uint64_t totalpg = 0;
+	int n;
+
+	memmap = LibMemoryMap(, , , );
+	for (n = 0, md = memmap; n < nentries; n++, md = NextMemoryDescriptor(md, descsize)) {
+		if ((md->Attribute & EFI_MEMORY_WB) == 0) {
+			continue;
+		}
+		totalpg += md->NumberOfPages;
+	}
+
+	*ptotal = totalpg * EFI_PAGE_SIZE;
+}
+
+static void
+format_bytes(uint64_t val, uint64_t *pdiv, const char **punit)
+{
+	static const char *units[] = { "KB", "MB", "GB" };
+	unsigned n;
+
+	*punit = "bytes";
+	*pdiv = 1;
+
+	for (n = 0; n < __arraycount(units) && val >= 1024; n++) {
+		*punit = units[n];
+		*pdiv *= 1024;
+		val /= 1024;
+	}
+}
+
 void
 print_banner(void)
 {
+	const char *total_unit;
+	uint64_t total, total_div;
+
+	get_memory_info();
+	format_bytes(total, _div, _unit);
+
 	printf("  \\-__,--,___.\n");
 	printf("   \\__,---`  %s\n", bootprog_name);
 	printf("\\   `---,_.  Revision %s\n", bootprog_rev);
-	printf(" \\-,_,.---`\n");
+	printf(" \\-,_,.---`  Memory: %" PRIu64 " %s\n",
+	total / total_div, total_unit);
 	printf("  \\\n");
 	printf("   \\\n");
 	printf("\\\n\n");



CVS commit: src/sys/stand/efiboot

2021-06-22 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Jun 22 21:56:51 UTC 2021

Modified Files:
src/sys/stand/efiboot: efiblock.c

Log Message:
efiboot: Use EFI_BLOCK_IO_PROTOCOL if EFI_DISK_IO_PROTOCOL is missing

UEFI spec says that firmware should automatically add EFI_DISK_IO_PROTOCOL
for all produced EFI_BLOCK_IO_PROTOCOL interfaces. Unfortunately U-Boot
doesn't do this, so fallback to block I/O if disk I/O is not there.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/stand/efiboot/efiblock.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/stand/efiboot/efiblock.c
diff -u src/sys/stand/efiboot/efiblock.c:1.14 src/sys/stand/efiboot/efiblock.c:1.15
--- src/sys/stand/efiboot/efiblock.c:1.14	Mon Jun 21 21:18:47 2021
+++ src/sys/stand/efiboot/efiblock.c	Tue Jun 22 21:56:51 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.c,v 1.14 2021/06/21 21:18:47 jmcneill Exp $ */
+/* $NetBSD: efiblock.c,v 1.15 2021/06/22 21:56:51 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -118,7 +118,74 @@ efi_block_generate_hash_mbr(struct efi_b
 }
 
 static EFI_STATUS
-efi_block_disk_readahead(struct efi_block_dev *bdev, UINT64 off, void *buf,
+efi_block_do_read_blockio(struct efi_block_dev *bdev, UINT64 off, void *buf,
+UINTN bufsize)
+{
+	UINT8 *blkbuf, *blkbuf_start;
+	EFI_STATUS status;
+	EFI_LBA lba_start, lba_end;
+	UINT64 blkbuf_offset;
+	UINT64 blkbuf_size;
+
+	lba_start = off / bdev->bio->Media->BlockSize;
+	lba_end = (off + bufsize + bdev->bio->Media->BlockSize - 1) /
+	bdev->bio->Media->BlockSize;
+	blkbuf_offset = off % bdev->bio->Media->BlockSize;
+	blkbuf_size = (lba_end - lba_start) * bdev->bio->Media->BlockSize;
+	if (bdev->bio->Media->IoAlign > 1) {
+		blkbuf_size += bdev->bio->Media->IoAlign - 1;
+	}
+
+	blkbuf = AllocatePool(blkbuf_size);
+	if (blkbuf == NULL) {
+		return EFI_OUT_OF_RESOURCES;
+	}
+
+	if (bdev->bio->Media->IoAlign > 1) {
+		blkbuf_start = (void *)roundup2((intptr_t)blkbuf,
+		bdev->bio->Media->IoAlign);
+	} else {
+		blkbuf_start = blkbuf;
+	}
+
+	status = uefi_call_wrapper(bdev->bio->ReadBlocks, 5, bdev->bio,
+	bdev->media_id, lba_start, blkbuf_size, blkbuf_start);
+	if (EFI_ERROR(status)) {
+		goto done;
+	}
+
+	memcpy(buf, blkbuf_start + blkbuf_offset, bufsize);
+
+done:
+	FreePool(blkbuf);
+	return status;
+}
+
+static EFI_STATUS
+efi_block_do_read_diskio(struct efi_block_dev *bdev, UINT64 off, void *buf,
+UINTN bufsize)
+{
+	return uefi_call_wrapper(bdev->dio->ReadDisk, 5, bdev->dio,
+	bdev->media_id, off, bufsize, buf);
+}
+
+static EFI_STATUS
+efi_block_do_read(struct efi_block_dev *bdev, UINT64 off, void *buf,
+UINTN bufsize)
+{
+	/*
+	 * Perform read access using EFI_DISK_IO_PROTOCOL if available,
+	 * otherwise use EFI_BLOCK_IO_PROTOCOL.
+	 */
+	if (bdev->dio != NULL) {
+		return efi_block_do_read_diskio(bdev, off, buf, bufsize);
+	} else {
+		return efi_block_do_read_blockio(bdev, off, buf, bufsize);
+	}
+}
+
+static EFI_STATUS
+efi_block_readahead(struct efi_block_dev *bdev, UINT64 off, void *buf,
 UINTN bufsize)
 {
 	EFI_STATUS status;
@@ -140,8 +207,7 @@ efi_block_disk_readahead(struct efi_bloc
 		if (len > mediasize - off) {
 			len = mediasize - off;
 		}
-		status = uefi_call_wrapper(bdev->dio->ReadDisk, 5, bdev->dio,
-		bdev->media_id, off, len, efi_ra_buffer);
+		status = efi_block_do_read(bdev, off, efi_ra_buffer, len);
 		if (EFI_ERROR(status)) {
 			efi_ra_start = efi_ra_length = 0;
 			return status;
@@ -156,15 +222,14 @@ efi_block_disk_readahead(struct efi_bloc
 }
 
 static EFI_STATUS
-efi_block_disk_read(struct efi_block_dev *bdev, UINT64 off, void *buf,
+efi_block_read(struct efi_block_dev *bdev, UINT64 off, void *buf,
 UINTN bufsize)
 {
 	if (efi_ra_enable) {
-		return efi_block_disk_readahead(bdev, off, buf, bufsize);
+		return efi_block_readahead(bdev, off, buf, bufsize);
 	}
 
-	return uefi_call_wrapper(bdev->dio->ReadDisk, 5, bdev->dio,
-	bdev->media_id, off, bufsize, buf);
+	return efi_block_do_read(bdev, off, buf, bufsize);
 }
 
 static int
@@ -176,7 +241,7 @@ efi_block_find_partitions_cd9660(struct 
 	EFI_LBA lba;
 
 	for (lba = 16;; lba++) {
-		status = efi_block_disk_read(bdev,
+		status = efi_block_read(bdev,
 		lba * ISO_DEFAULT_BLOCK_SIZE, , sizeof(vd));
 		if (EFI_ERROR(status)) {
 			goto io_error;
@@ -220,7 +285,7 @@ efi_block_find_partitions_disklabel(stru
 	EFI_STATUS status;
 	int n;
 
-	status = efi_block_disk_read(bdev,
+	status = efi_block_read(bdev,
 	((EFI_LBA)start + LABELSECTOR) * DEV_BSIZE, buf, sizeof(buf));
 	if (EFI_ERROR(status) || getdisklabel(buf, ) != NULL) {
 		FreePool(buf);
@@ -268,7 +333,7 @@ efi_block_find_partitions_mbr(struct efi
 	EFI_STATUS status;
 	int n;
 
-	status = efi_block_disk_read(bdev, 0, , sizeof(mbr));
+	status = efi_block_read(bdev, 0, , sizeof(mbr));
 	if (EFI_ERROR(status))
 		return EIO;
 
@@ -348,7 +413,7 

CVS commit: src/sys/stand/efiboot

2021-06-22 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Jun 22 10:19:35 UTC 2021

Modified Files:
src/sys/stand/efiboot: efirng.c

Log Message:
efirng: fix va_num arg to uefi_call_wrapper for GetRNG calls

As far as I can tell this param isn't actually used, but it is supposed to
be the number of arguments passed to the called method.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/stand/efiboot/efirng.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/stand/efiboot/efirng.c
diff -u src/sys/stand/efiboot/efirng.c:1.2 src/sys/stand/efiboot/efirng.c:1.3
--- src/sys/stand/efiboot/efirng.c:1.2	Thu May 14 23:09:29 2020
+++ src/sys/stand/efiboot/efirng.c	Tue Jun 22 10:19:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: efirng.c,v 1.2 2020/05/14 23:09:29 jmcneill Exp $	*/
+/*	$NetBSD: efirng.c,v 1.3 2021/06/22 10:19:35 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -121,14 +121,14 @@ efi_rng(void *buf, UINTN len)
 	if (!efi_rng_available())
 		return EIO;
 
-	status = uefi_call_wrapper(rng->GetRNG, 3, rng, ,
+	status = uefi_call_wrapper(rng->GetRNG, 4, rng, ,
 	len, buf);
 	if (status == EFI_UNSUPPORTED) {
 		/*
 		 * Fall back to any supported RNG `algorithm' even
 		 * though we would prefer raw samples.
 		 */
-		status = uefi_call_wrapper(rng->GetRNG, 3, rng, NULL, len, buf);
+		status = uefi_call_wrapper(rng->GetRNG, 4, rng, NULL, len, buf);
 	}
 	if (EFI_ERROR(status)) {
 		DPRINT(L"efirng: GetRNG: %r\n", status);



CVS commit: src/sys/stand/efiboot

2021-06-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Jun 21 21:18:47 UTC 2021

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

Log Message:
efiboot: Add readahead support.

Reading data through libsa file-systems ends up breaking block I/O
accesses into very small (512-byte or 2048-byte) accesses. This can be
very inefficient, and causes Ampere eMAG w/ BMC image direction to take
_minutes_ to load the install image and kernel. So slow in fact that
the default watchdog timeout will fire before it finishes.

So, when loading big files, optimistically read ahead up to 64KB of data.
Brings the time to boot the install ISO down to around 40 seconds -- still
not ideal but way better than before.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/stand/efiboot/boot.c
cvs rdiff -u -r1.13 -r1.14 src/sys/stand/efiboot/efiblock.c
cvs rdiff -u -r1.5 -r1.6 src/sys/stand/efiboot/efiblock.h

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/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.31 src/sys/stand/efiboot/boot.c:1.32
--- src/sys/stand/efiboot/boot.c:1.31	Mon Jun 21 19:07:30 2021
+++ src/sys/stand/efiboot/boot.c	Mon Jun 21 21:18:47 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.31 2021/06/21 19:07:30 nia Exp $	*/
+/*	$NetBSD: boot.c,v 1.32 2021/06/21 21:18:47 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -171,7 +171,9 @@ command_boot(char *arg)
 	if (!*bootargs)
 		bootargs = netbsd_args;
 
+	efi_block_set_readahead(true);
 	exec_netbsd(kernel, bootargs);
+	efi_block_set_readahead(false);
 }
 
 void
@@ -498,7 +500,9 @@ boot(void)
 		if (c != '\r' && c != '\n' && c != '\0')
 			bootprompt(); /* does not return */
 
+		efi_block_set_readahead(true);
 		exec_netbsd(netbsd_path, netbsd_args);
+		efi_block_set_readahead(false);
 	}
 
 	bootprompt();	/* does not return */

Index: src/sys/stand/efiboot/efiblock.c
diff -u src/sys/stand/efiboot/efiblock.c:1.13 src/sys/stand/efiboot/efiblock.c:1.14
--- src/sys/stand/efiboot/efiblock.c:1.13	Mon Jun 21 11:11:33 2021
+++ src/sys/stand/efiboot/efiblock.c	Mon Jun 21 21:18:47 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.c,v 1.13 2021/06/21 11:11:33 jmcneill Exp $ */
+/* $NetBSD: efiblock.c,v 1.14 2021/06/21 21:18:47 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -38,6 +38,7 @@
 #include "efiboot.h"
 #include "efiblock.h"
 
+#define	EFI_BLOCK_READAHEAD	(64 * 1024)
 #define	EFI_BLOCK_TIMEOUT	120
 #define	EFI_BLOCK_TIMEOUT_CODE	0x810c
 
@@ -52,6 +53,12 @@ static EFI_HANDLE *efi_block;
 static UINTN efi_nblock;
 static struct efi_block_part *efi_block_booted = NULL;
 
+static bool efi_ra_enable = false;
+static UINT8 *efi_ra_buffer = NULL;
+static UINT32 efi_ra_media_id;
+static UINT64 efi_ra_start = 0;
+static UINT64 efi_ra_length = 0;
+
 static TAILQ_HEAD(, efi_block_dev) efi_block_devs = TAILQ_HEAD_INITIALIZER(efi_block_devs);
 
 static int
@@ -111,9 +118,51 @@ efi_block_generate_hash_mbr(struct efi_b
 }
 
 static EFI_STATUS
+efi_block_disk_readahead(struct efi_block_dev *bdev, UINT64 off, void *buf,
+UINTN bufsize)
+{
+	EFI_STATUS status;
+	UINT64 mediasize, len;
+
+	if (efi_ra_buffer == NULL) {
+		efi_ra_buffer = AllocatePool(EFI_BLOCK_READAHEAD);
+		if (efi_ra_buffer == NULL) {
+			return EFI_OUT_OF_RESOURCES;
+		}
+	}
+
+	if (bdev->media_id != efi_ra_media_id ||
+	off < efi_ra_start ||
+	off + bufsize > efi_ra_start + efi_ra_length) {
+		mediasize = bdev->bio->Media->BlockSize *
+		(bdev->bio->Media->LastBlock + 1);
+		len = EFI_BLOCK_READAHEAD;
+		if (len > mediasize - off) {
+			len = mediasize - off;
+		}
+		status = uefi_call_wrapper(bdev->dio->ReadDisk, 5, bdev->dio,
+		bdev->media_id, off, len, efi_ra_buffer);
+		if (EFI_ERROR(status)) {
+			efi_ra_start = efi_ra_length = 0;
+			return status;
+		}
+		efi_ra_start = off;
+		efi_ra_length = len;
+		efi_ra_media_id = bdev->media_id;
+	}
+
+	memcpy(buf, _ra_buffer[off - efi_ra_start], bufsize);
+	return EFI_SUCCESS;
+}
+
+static EFI_STATUS
 efi_block_disk_read(struct efi_block_dev *bdev, UINT64 off, void *buf,
 UINTN bufsize)
 {
+	if (efi_ra_enable) {
+		return efi_block_disk_readahead(bdev, off, buf, bufsize);
+	}
+
 	return uefi_call_wrapper(bdev->dio->ReadDisk, 5, bdev->dio,
 	bdev->media_id, off, bufsize, buf);
 }
@@ -588,3 +637,9 @@ efi_block_strategy(void *devdata, int rw
 
 	return 0;
 }
+
+void
+efi_block_set_readahead(bool onoff)
+{
+	efi_ra_enable = onoff;
+}

Index: src/sys/stand/efiboot/efiblock.h
diff -u src/sys/stand/efiboot/efiblock.h:1.5 src/sys/stand/efiboot/efiblock.h:1.6
--- src/sys/stand/efiboot/efiblock.h:1.5	Mon Jun 21 11:11:33 2021
+++ src/sys/stand/efiboot/efiblock.h	Mon Jun 21 21:18:47 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.h,v 1.5 2021/06/21 11:11:33 jmcneill Exp $ */
+/* $NetBSD: efiblock.h,v 1.6 2021/06/21 21:18:47 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 

CVS commit: src/sys/stand/efiboot

2021-06-21 Thread Nia Alarie
Module Name:src
Committed By:   nia
Date:   Mon Jun 21 19:07:30 UTC 2021

Modified Files:
src/sys/stand/efiboot: boot.c

Log Message:
efiboot: Add ASCII art.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/stand/efiboot/boot.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/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.30 src/sys/stand/efiboot/boot.c:1.31
--- src/sys/stand/efiboot/boot.c:1.30	Mon May 31 11:12:42 2021
+++ src/sys/stand/efiboot/boot.c	Mon Jun 21 19:07:30 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.30 2021/05/31 11:12:42 rin Exp $	*/
+/*	$NetBSD: boot.c,v 1.31 2021/06/21 19:07:30 nia Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -451,9 +451,13 @@ set_bootargs(const char *arg)
 void
 print_banner(void)
 {
-	printf("\n\n"
-	">> %s, Revision %s\n",
-	bootprog_name, bootprog_rev);
+	printf("  \\-__,--,___.\n");
+	printf("   \\__,---`  %s\n", bootprog_name);
+	printf("\\   `---,_.  Revision %s\n", bootprog_rev);
+	printf(" \\-,_,.---`\n");
+	printf("  \\\n");
+	printf("   \\\n");
+	printf("\\\n\n");
 }
 
 void



CVS commit: src/sys/stand/efiboot

2021-06-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Jun 21 11:11:33 UTC 2021

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

Log Message:
efiboot: Use disk I/O protocol for block device access.

EFI_DISK_IO_PROTOCOL is a simplified interface to block devices. Use this
instead of EFI_BLOCK_IO_PROTOCOL for accessing block devices to simplify
the code -- we no longer need to worry about the underlying media's block
I/O size and alignment requirements.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/stand/efiboot/efiblock.c
cvs rdiff -u -r1.4 -r1.5 src/sys/stand/efiboot/efiblock.h
cvs rdiff -u -r1.26 -r1.27 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/efiblock.c
diff -u src/sys/stand/efiboot/efiblock.c:1.12 src/sys/stand/efiboot/efiblock.c:1.13
--- src/sys/stand/efiboot/efiblock.c:1.12	Sun Jun 20 19:10:47 2021
+++ src/sys/stand/efiboot/efiblock.c	Mon Jun 21 11:11:33 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.c,v 1.12 2021/06/20 19:10:47 jmcneill Exp $ */
+/* $NetBSD: efiblock.c,v 1.13 2021/06/21 11:11:33 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -110,68 +110,41 @@ efi_block_generate_hash_mbr(struct efi_b
 	MD5Final(bpart->hash, );
 }
 
-static void *
-efi_block_allocate_device_buffer(struct efi_block_dev *bdev, UINTN size,
-	void **buf_start)
+static EFI_STATUS
+efi_block_disk_read(struct efi_block_dev *bdev, UINT64 off, void *buf,
+UINTN bufsize)
 {
-	void *buf;
-
-	if (bdev->bio->Media->IoAlign <= 1)
-		*buf_start = buf = AllocatePool(size);
-	else {
-		buf = AllocatePool(size + bdev->bio->Media->IoAlign - 1);
-		*buf_start = (buf == NULL) ? NULL :
-		(void *)roundup2((intptr_t)buf, bdev->bio->Media->IoAlign);
-	}
-
-	return buf;
+	return uefi_call_wrapper(bdev->dio->ReadDisk, 5, bdev->dio,
+	bdev->media_id, off, bufsize, buf);
 }
 
 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;
+	struct iso_primary_descriptor vd;
 	EFI_STATUS status;
 	EFI_LBA lba;
-	UINT32 sz;
-
-	if (bdev->bio->Media->BlockSize != DEV_BSIZE &&
-	bdev->bio->Media->BlockSize != ISO_DEFAULT_BLOCK_SIZE) {
-		return ENXIO;
-	}
-
-	sz = __MAX(sizeof(*vd), bdev->bio->Media->BlockSize);
-	sz = roundup(sz, bdev->bio->Media->BlockSize);
-	if ((buf = efi_block_allocate_device_buffer(bdev, sz, _start)) == NULL) {
-		return ENOMEM;
-	}
 
 	for (lba = 16;; lba++) {
-		status = uefi_call_wrapper(bdev->bio->ReadBlocks, 5,
-		bdev->bio,
-		bdev->media_id,
-		lba * ISO_DEFAULT_BLOCK_SIZE / bdev->bio->Media->BlockSize,
-		sz,
-		buf_start);
+		status = efi_block_disk_read(bdev,
+		lba * ISO_DEFAULT_BLOCK_SIZE, , sizeof(vd));
 		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) {
+		if (memcmp(vd.id, ISO_STANDARD_ID, sizeof vd.id) != 0) {
 			goto io_error;
 		}
-		if (isonum_711(vd->type) == ISO_VD_END) {
+		if (isonum_711(vd.type) == ISO_VD_END) {
 			goto io_error;
 		}
-		if (isonum_711(vd->type) == ISO_VD_PRIMARY) {
+		if (isonum_711(vd.type) == ISO_VD_PRIMARY) {
 			break;
 		}
 	}
 
-	if (isonum_723(vd->logical_block_size) != ISO_DEFAULT_BLOCK_SIZE) {
+	if (isonum_723(vd.logical_block_size) != ISO_DEFAULT_BLOCK_SIZE) {
 		goto io_error;
 	}
 
@@ -181,39 +154,29 @@ efi_block_find_partitions_cd9660(struct 
 	bpart->type = EFI_BLOCK_PART_CD9660;
 	TAILQ_INSERT_TAIL(>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)
+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;
+	char buf[DEV_BSIZE];
 	struct disklabel d;
 	struct partition *p;
 	EFI_STATUS status;
-	EFI_LBA lba;
-	void *buf, *buf_start;
-	UINT32 sz;
 	int n;
 
-	sz = __MAX(sizeof(d), bdev->bio->Media->BlockSize);
-	sz = roundup(sz, bdev->bio->Media->BlockSize);
-	if ((buf = efi_block_allocate_device_buffer(bdev, sz, _start)) == NULL)
-		return ENOMEM;
-
-	lba = (((EFI_LBA)start + LABELSECTOR) * DEV_BSIZE) / bdev->bio->Media->BlockSize;
-	status = uefi_call_wrapper(bdev->bio->ReadBlocks, 5, bdev->bio, bdev->media_id,
-		lba, sz, buf_start);
-	if (EFI_ERROR(status) || getdisklabel(buf_start, ) != NULL) {
+	status = efi_block_disk_read(bdev,
+	((EFI_LBA)start + LABELSECTOR) * DEV_BSIZE, buf, sizeof(buf));
+	if (EFI_ERROR(status) || getdisklabel(buf, ) != NULL) {
 		FreePool(buf);
 		return EIO;
 	}
-	FreePool(buf);
 
 	if (le32toh(d.d_magic) != DISKMAGIC || le32toh(d.d_magic2) != DISKMAGIC)
 		

CVS commit: src/sys/stand/efiboot

2021-06-20 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Jun 20 19:10:47 UTC 2021

Modified Files:
src/sys/stand/efiboot: Makefile.efiboot efiblock.c efiboot.h version
Added Files:
src/sys/stand/efiboot: efiwatchdog.c

Log Message:
Add support for the boot services watchdog and pet it on every block I/O
access. For slow media (like ISO image redirection on Lenovo HR330A BMC)
this is needed because otherwise the default watchdog timeout fires before
we can finish loading the kernel from install media.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/stand/efiboot/Makefile.efiboot
cvs rdiff -u -r1.11 -r1.12 src/sys/stand/efiboot/efiblock.c
cvs rdiff -u -r1.14 -r1.15 src/sys/stand/efiboot/efiboot.h
cvs rdiff -u -r0 -r1.1 src/sys/stand/efiboot/efiwatchdog.c
cvs rdiff -u -r1.25 -r1.26 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.21 src/sys/stand/efiboot/Makefile.efiboot:1.22
--- src/sys/stand/efiboot/Makefile.efiboot:1.21	Thu May 27 06:54:45 2021
+++ src/sys/stand/efiboot/Makefile.efiboot	Sun Jun 20 19:10:47 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.21 2021/05/27 06:54:45 mrg Exp $
+# $NetBSD: Makefile.efiboot,v 1.22 2021/06/20 19:10:47 jmcneill Exp $
 
 S=		${.CURDIR}/../../..
 
@@ -24,7 +24,8 @@ SOURCES=	crt0-efi-${GNUEFIARCH}.S reloc_
 SOURCES+=	boot.c bootmenu.c conf.c console.c dev_net.c devopen.c exec.c \
 		module.c overlay.c panic.c prompt.c
 SOURCES+=	efiboot.c efichar.c efidev.c efigetsecs.c efifdt.c \
-		efifile.c efiblock.c efinet.c efipxe.c efiacpi.c efirng.c smbios.c
+		efifile.c efiblock.c efinet.c efipxe.c efiacpi.c efirng.c efiwatchdog.c \
+	   	smbios.c
 
 .PATH: ${S}/external/bsd/libfdt/dist
 CPPFLAGS+=	-I${S}/external/bsd/libfdt/dist

Index: src/sys/stand/efiboot/efiblock.c
diff -u src/sys/stand/efiboot/efiblock.c:1.11 src/sys/stand/efiboot/efiblock.c:1.12
--- src/sys/stand/efiboot/efiblock.c:1.11	Wed May 26 09:42:36 2021
+++ src/sys/stand/efiboot/efiblock.c	Sun Jun 20 19:10:47 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.c,v 1.11 2021/05/26 09:42:36 mrg Exp $ */
+/* $NetBSD: efiblock.c,v 1.12 2021/06/20 19:10:47 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -38,6 +38,9 @@
 #include "efiboot.h"
 #include "efiblock.h"
 
+#define	EFI_BLOCK_TIMEOUT	120
+#define	EFI_BLOCK_TIMEOUT_CODE	0x810c
+
 /*
  * The raidframe support is basic.  Ideally, it should be expanded to
  * consider raid volumes a first-class citizen like the x86 efiboot does,
@@ -605,6 +608,8 @@ efi_block_strategy(void *devdata, int rw
 	if (rw != F_READ)
 		return EROFS;
 
+	efi_set_watchdog(EFI_BLOCK_TIMEOUT, EFI_BLOCK_TIMEOUT_CODE);
+
 	switch (bpart->type) {
 	case EFI_BLOCK_PART_DISKLABEL:
 		if (bpart->bdev->bio->Media->BlockSize != bpart->disklabel.secsize) {

Index: src/sys/stand/efiboot/efiboot.h
diff -u src/sys/stand/efiboot/efiboot.h:1.14 src/sys/stand/efiboot/efiboot.h:1.15
--- src/sys/stand/efiboot/efiboot.h:1.14	Sun Oct 11 14:03:33 2020
+++ src/sys/stand/efiboot/efiboot.h	Sun Jun 20 19:10:47 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: efiboot.h,v 1.14 2020/10/11 14:03:33 jmcneill Exp $	*/
+/*	$NetBSD: efiboot.h,v 1.15 2021/06/20 19:10:47 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -104,6 +104,9 @@ extern struct netif_driver efinetif;
 void efi_pxe_probe(void);
 bool efi_pxe_match_booted_interface(const EFI_MAC_ADDRESS *, UINT32);
 
+/* efiwatchdog.c */
+void efi_set_watchdog(uint32_t, uint64_t);
+
 /* exec.c */
 int exec_netbsd(const char *, const char *);
 

Index: src/sys/stand/efiboot/version
diff -u src/sys/stand/efiboot/version:1.25 src/sys/stand/efiboot/version:1.26
--- src/sys/stand/efiboot/version:1.25	Thu May 27 06:54:45 2021
+++ src/sys/stand/efiboot/version	Sun Jun 20 19:10:47 2021
@@ -1,4 +1,4 @@
-$NetBSD: version,v 1.25 2021/05/27 06:54:45 mrg Exp $
+$NetBSD: version,v 1.26 2021/06/20 19:10:47 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
@@ -29,3 +29,4 @@ is taken as the current.
 2.6:	Disable ACPI support when booting big endian kernels.
 2.7:	Add basic support for booting from RAID1 volumes.
 2.8:	Add bi-endian disklabel and FFS support.
+2.9:	Watchdog support.

Added files:

Index: src/sys/stand/efiboot/efiwatchdog.c
diff -u /dev/null src/sys/stand/efiboot/efiwatchdog.c:1.1
--- /dev/null	Sun Jun 20 19:10:47 2021
+++ src/sys/stand/efiboot/efiwatchdog.c	Sun Jun 20 19:10:47 2021
@@ -0,0 +1,40 @@
+/* $NetBSD: efiwatchdog.c,v 1.1 2021/06/20 19:10:47 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2021 Jared McNeill 
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ 

CVS commit: src/sys/stand/efiboot

2021-06-20 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Jun 20 19:07:39 UTC 2021

Modified Files:
src/sys/stand/efiboot: exec.c

Log Message:
Enable the twiddle spinner when loading the kernel, ramdisk images, and
modules.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/stand/efiboot/exec.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/stand/efiboot/exec.c
diff -u src/sys/stand/efiboot/exec.c:1.21 src/sys/stand/efiboot/exec.c:1.22
--- src/sys/stand/efiboot/exec.c:1.21	Fri May 21 21:53:15 2021
+++ src/sys/stand/efiboot/exec.c	Sun Jun 20 19:07:39 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.c,v 1.21 2021/05/21 21:53:15 jmcneill Exp $ */
+/* $NetBSD: exec.c,v 1.22 2021/06/20 19:07:39 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -246,6 +246,8 @@ exec_netbsd(const char *fname, const cha
 	EFI_STATUS status;
 	int fd, ohowto;
 
+	twiddle_toggle = 0;
+
 	load_file(get_initrd_path(), 0, false, _addr, _size);
 	load_file(get_dtb_path(), 0, false, _addr, _size);
 	generate_efirng();



CVS commit: src/sys/stand/efiboot

2021-05-31 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon May 31 11:12:42 UTC 2021

Modified Files:
src/sys/stand/efiboot: boot.c

Log Message:
Generalize boot.cfg workaround for ISO9660; fallback to default_device
whenever efi_file_path() fails (due to broken firmware), in addition to
the case of ISO9660 (for which efi_file_path() succeeds but does not
work correctly).


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/stand/efiboot/boot.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/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.29 src/sys/stand/efiboot/boot.c:1.30
--- src/sys/stand/efiboot/boot.c:1.29	Sat Nov 28 14:02:09 2020
+++ src/sys/stand/efiboot/boot.c	Mon May 31 11:12:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.29 2020/11/28 14:02:09 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.30 2021/05/31 11:12:42 rin Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -132,22 +132,18 @@ const struct boot_command commands[] = {
 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
+	 * Fallback to default_device
+	 * - for ISO9660 (efi_file_path() succeeds but does not work correctly)
+	 * - or whenever efi_file_path() fails (due to broken firmware)
 	 */
-	if (efi_bootdp == NULL)
-		return ENXIO;
+	if (default_fstype == FS_ISO9660 || efi_bootdp == NULL ||
+	efi_file_path(efi_bootdp, BOOTCFG_FILENAME, pathbuf, pathbuflen))
+		snprintf(pathbuf, pathbuflen, "%s:%s", default_device,
+		BOOTCFG_FILENAME);
 
-	return efi_file_path(efi_bootdp, BOOTCFG_FILENAME, pathbuf, pathbuflen);
+	return 0;
 }
 
 void



CVS commit: src/sys/stand/efiboot

2021-05-26 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Wed May 26 09:42:36 UTC 2021

Modified Files:
src/sys/stand/efiboot: efiblock.c version

Log Message:
add basic raidframe support to efiboot.

if raid disklabel or gpt is found, add this partition with
the offset/size adjusted by RF_PROTECTED_SECTORS.  note

don't le32toh() the disklabel.  if it was wrong-endian, then
getdisklabel() will have swapped it.

ok jmcneill thorpej.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/stand/efiboot/efiblock.c
cvs rdiff -u -r1.23 -r1.24 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/efiblock.c
diff -u src/sys/stand/efiboot/efiblock.c:1.10 src/sys/stand/efiboot/efiblock.c:1.11
--- src/sys/stand/efiboot/efiblock.c:1.10	Sat Nov 28 15:24:05 2020
+++ src/sys/stand/efiboot/efiblock.c	Wed May 26 09:42:36 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.c,v 1.10 2020/11/28 15:24:05 jmcneill Exp $ */
+/* $NetBSD: efiblock.c,v 1.11 2021/05/26 09:42:36 mrg Exp $ */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -38,6 +38,13 @@
 #include "efiboot.h"
 #include "efiblock.h"
 
+/*
+ * The raidframe support is basic.  Ideally, it should be expanded to
+ * consider raid volumes a first-class citizen like the x86 efiboot does,
+ * but for now, we simply assume each RAID is potentially bootable.
+ */
+#define	RF_PROTECTED_SECTORS	64	/* XXX refer to <.../rf_optnames.h> */
+
 static EFI_HANDLE *efi_block;
 static UINTN efi_nblock;
 static struct efi_block_part *efi_block_booted = NULL;
@@ -217,6 +224,10 @@ efi_block_find_partitions_disklabel(stru
 		case FS_MSDOS:
 		case FS_BSDLFS:
 			break;
+		case FS_RAID:
+			p->p_size -= RF_PROTECTED_SECTORS;
+			p->p_offset += RF_PROTECTED_SECTORS;
+			break;
 		default:
 			continue;
 		}
@@ -225,7 +236,7 @@ efi_block_find_partitions_disklabel(stru
 		bpart->index = n;
 		bpart->bdev = bdev;
 		bpart->type = EFI_BLOCK_PART_DISKLABEL;
-		bpart->disklabel.secsize = le32toh(d.d_secsize);
+		bpart->disklabel.secsize = d.d_secsize;
 		bpart->disklabel.part = *p;
 		efi_block_generate_hash_mbr(bpart, mbr);
 		TAILQ_INSERT_TAIL(>partitions, bpart, entries);
@@ -310,6 +321,10 @@ efi_block_find_partitions_gpt_entry(stru
 	bpart->type = EFI_BLOCK_PART_GPT;
 	bpart->gpt.fstype = fstype;
 	bpart->gpt.ent = *ent;
+	if (fstype == FS_RAID) {
+		bpart->gpt.ent.ent_lba_start += RF_PROTECTED_SECTORS;
+		bpart->gpt.ent.ent_lba_end -= RF_PROTECTED_SECTORS;
+	}
 	memcpy(bpart->hash, ent->ent_guid, sizeof(bpart->hash));
 	TAILQ_INSERT_TAIL(>partitions, bpart, entries);
 
@@ -436,7 +451,7 @@ efi_block_probe(void)
 	fstype = FS_ISO9660;
 	break;
 }
-if (fstype == FS_BSDFFS || fstype == FS_ISO9660) {
+if (fstype == FS_BSDFFS || fstype == FS_ISO9660 || fstype == FS_RAID) {
 	char devname[9];
 	snprintf(devname, sizeof(devname), "hd%u%c", bdev->index, bpart->index + 'a');
 	set_default_device(devname);

Index: src/sys/stand/efiboot/version
diff -u src/sys/stand/efiboot/version:1.23 src/sys/stand/efiboot/version:1.24
--- src/sys/stand/efiboot/version:1.23	Fri May 21 21:53:15 2021
+++ src/sys/stand/efiboot/version	Wed May 26 09:42:36 2021
@@ -1,4 +1,4 @@
-$NetBSD: version,v 1.23 2021/05/21 21:53:15 jmcneill Exp $
+$NetBSD: version,v 1.24 2021/05/26 09:42:36 mrg 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
@@ -27,3 +27,4 @@ is taken as the current.
 2.4:	Add ISO9660 support.
 2.5:	Recognize the EFI system partion as fstype MSDOS.
 2.6:	Disable ACPI support when booting big endian kernels.
+2.7:	Add basic support for booting from RAID1 volumes.



CVS commit: src/sys/stand/efiboot

2021-05-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri May 21 21:53:15 UTC 2021

Modified Files:
src/sys/stand/efiboot: efiacpi.c efiacpi.h efifdt.c exec.c version

Log Message:
Disable ACPI support when booting big endian kernels.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/stand/efiboot/efiacpi.c
cvs rdiff -u -r1.1 -r1.2 src/sys/stand/efiboot/efiacpi.h
cvs rdiff -u -r1.28 -r1.29 src/sys/stand/efiboot/efifdt.c
cvs rdiff -u -r1.20 -r1.21 src/sys/stand/efiboot/exec.c
cvs rdiff -u -r1.22 -r1.23 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/efiacpi.c
diff -u src/sys/stand/efiboot/efiacpi.c:1.8 src/sys/stand/efiboot/efiacpi.c:1.9
--- src/sys/stand/efiboot/efiacpi.c:1.8	Sat Oct 10 19:17:39 2020
+++ src/sys/stand/efiboot/efiacpi.c	Fri May 21 21:53:15 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: efiacpi.c,v 1.8 2020/10/10 19:17:39 jmcneill Exp $ */
+/* $NetBSD: efiacpi.c,v 1.9 2021/05/21 21:53:15 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -53,6 +53,7 @@ struct acpi_rdsp {
 static EFI_GUID Acpi20TableGuid = ACPI_20_TABLE_GUID;
 static EFI_GUID Smbios3TableGuid = SMBIOS3_TABLE_GUID;
 
+static int acpi_enable = 1;
 static void *acpi_root = NULL;
 static void *smbios3_table = NULL;
 
@@ -78,6 +79,18 @@ efi_acpi_available(void)
 	return acpi_root != NULL;
 }
 
+int
+efi_acpi_enabled(void)
+{
+	return acpi_enable;
+}
+
+void
+efi_acpi_enable(int enable)
+{
+	acpi_enable = enable;
+}
+
 static char model_buf[128];
 
 static const char *

Index: src/sys/stand/efiboot/efiacpi.h
diff -u src/sys/stand/efiboot/efiacpi.h:1.1 src/sys/stand/efiboot/efiacpi.h:1.2
--- src/sys/stand/efiboot/efiacpi.h:1.1	Fri Oct 12 22:08:04 2018
+++ src/sys/stand/efiboot/efiacpi.h	Fri May 21 21:53:15 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: efiacpi.h,v 1.1 2018/10/12 22:08:04 jmcneill Exp $ */
+/* $NetBSD: efiacpi.h,v 1.2 2021/05/21 21:53:15 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -32,4 +32,6 @@
 int efi_acpi_probe(void);
 void efi_acpi_show(void);
 int efi_acpi_available(void);
+int efi_acpi_enabled(void);
+void efi_acpi_enable(int);
 int efi_acpi_create_fdt(void);

Index: src/sys/stand/efiboot/efifdt.c
diff -u src/sys/stand/efiboot/efifdt.c:1.28 src/sys/stand/efiboot/efifdt.c:1.29
--- src/sys/stand/efiboot/efifdt.c:1.28	Sat Dec 19 08:09:31 2020
+++ src/sys/stand/efiboot/efifdt.c	Fri May 21 21:53:15 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.c,v 1.28 2020/12/19 08:09:31 skrll Exp $ */
+/* $NetBSD: efifdt.c,v 1.29 2021/05/21 21:53:15 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -370,7 +370,7 @@ efi_fdt_gop(void)
 		/*
 		 * In ACPI mode, use GOP as console.
 		 */
-		if (efi_acpi_available()) {
+		if (efi_acpi_available() && efi_acpi_enabled()) {
 			snprintf(buf, sizeof(buf), "/chosen/framebuffer@%" PRIx64, mode->FrameBufferBase);
 			fdt_setprop_string(fdt_data, chosen, "stdout-path", buf);
 		}

Index: src/sys/stand/efiboot/exec.c
diff -u src/sys/stand/efiboot/exec.c:1.20 src/sys/stand/efiboot/exec.c:1.21
--- src/sys/stand/efiboot/exec.c:1.20	Tue May 11 07:15:10 2021
+++ src/sys/stand/efiboot/exec.c	Fri May 21 21:53:15 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.c,v 1.20 2021/05/11 07:15:10 skrll Exp $ */
+/* $NetBSD: exec.c,v 1.21 2021/05/21 21:53:15 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -289,7 +289,10 @@ exec_netbsd(const char *fname, const cha
 	load_offset = 0;
 
 #ifdef EFIBOOT_ACPI
-	if (efi_acpi_available()) {
+	/* ACPI support only works for little endian kernels */
+	efi_acpi_enable(netbsd_elf_data == ELFDATA2LSB);
+
+	if (efi_acpi_available() && efi_acpi_enabled()) {
 		efi_acpi_create_fdt();
 	} else
 #endif

Index: src/sys/stand/efiboot/version
diff -u src/sys/stand/efiboot/version:1.22 src/sys/stand/efiboot/version:1.23
--- src/sys/stand/efiboot/version:1.22	Sun Oct 18 18:09:32 2020
+++ src/sys/stand/efiboot/version	Fri May 21 21:53:15 2021
@@ -1,4 +1,4 @@
-$NetBSD: version,v 1.22 2020/10/18 18:09:32 tnn Exp $
+$NetBSD: version,v 1.23 2021/05/21 21:53:15 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
@@ -26,3 +26,4 @@ is taken as the current.
 2.3:	EFI RT and GOP support for devicetree mode.
 2.4:	Add ISO9660 support.
 2.5:	Recognize the EFI system partion as fstype MSDOS.
+2.6:	Disable ACPI support when booting big endian kernels.



CVS commit: src/sys/stand/efiboot

2021-05-11 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Tue May 11 07:15:10 UTC 2021

Modified Files:
src/sys/stand/efiboot: exec.c

Log Message:
Consistently have ALIGN sizes as the power of two size, i.e. change
FDT_ALIGN, and use the same math(s) to round.

In the process fix the load_offset for the kernel to use the EFIBOOT_ALIGN
aligned address if that's what we get from AllocatePages.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/stand/efiboot/exec.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/stand/efiboot/exec.c
diff -u src/sys/stand/efiboot/exec.c:1.19 src/sys/stand/efiboot/exec.c:1.20
--- src/sys/stand/efiboot/exec.c:1.19	Sat Oct 10 19:17:39 2020
+++ src/sys/stand/efiboot/exec.c	Tue May 11 07:15:10 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.c,v 1.19 2020/10/10 19:17:39 jmcneill Exp $ */
+/* $NetBSD: exec.c,v 1.20 2021/05/11 07:15:10 skrll Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -42,7 +42,7 @@ extern char twiddle_toggle;
 u_long load_offset = 0;
 
 #define	FDT_SPACE	(4 * 1024 * 1024)
-#define	FDT_ALIGN	((2 * 1024 * 1024) - 1)
+#define	FDT_ALIGN	(2 * 1024 * 1024)
 
 static EFI_PHYSICAL_ADDRESS initrd_addr, dtb_addr, rndseed_addr, efirng_addr;
 static u_long initrd_size = 0, dtb_size = 0, rndseed_size = 0, efirng_size = 0;
@@ -260,7 +260,7 @@ exec_netbsd(const char *fname, const cha
 		return EIO;
 	}
 	close(fd);
-	marks[MARK_END] = (((u_long) marks[MARK_END] + sizeof(int) - 1)) & (-sizeof(int));
+	marks[MARK_END] = (((u_long) marks[MARK_END] + sizeof(int) - 1)) & -sizeof(int);
 	alloc_size = marks[MARK_END] - marks[MARK_START] + FDT_SPACE + EFIBOOT_ALIGN;
 
 #ifdef EFIBOOT_ALLOCATE_MAX_ADDRESS
@@ -279,7 +279,7 @@ exec_netbsd(const char *fname, const cha
 	}
 
 	memset(marks, 0, sizeof(marks));
-	load_offset = (addr + EFIBOOT_ALIGN) & ~(EFIBOOT_ALIGN - 1);
+	load_offset = (addr + EFIBOOT_ALIGN - 1) & -EFIBOOT_ALIGN;
 	fd = loadfile(fname, marks, LOAD_KERNEL);
 	if (fd < 0) {
 		printf("boot: %s: %s\n", fname, strerror(errno));
@@ -308,7 +308,7 @@ exec_netbsd(const char *fname, const cha
 		load_file(get_rndseed_path(), 0, false,
 		_addr, _size);
 
-		efi_fdt_init((marks[MARK_END] + FDT_ALIGN) & ~FDT_ALIGN, FDT_ALIGN + 1);
+		efi_fdt_init((marks[MARK_END] + FDT_ALIGN - 1) & -FDT_ALIGN, FDT_ALIGN);
 		load_modules(fname);
 		load_fdt_overlays();
 		efi_fdt_initrd(initrd_addr, initrd_size);



CVS commit: src/sys/stand/efiboot

2021-05-04 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue May  4 19:07:19 UTC 2021

Modified Files:
src/sys/stand/efiboot: Makefile.efiboot

Log Message:
Set VERSIONMACHINE to ${MACHINE} instead of evbarm (oops)


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/stand/efiboot/Makefile.efiboot

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.19 src/sys/stand/efiboot/Makefile.efiboot:1.20
--- src/sys/stand/efiboot/Makefile.efiboot:1.19	Sun Oct 11 14:03:33 2020
+++ src/sys/stand/efiboot/Makefile.efiboot	Tue May  4 19:07:19 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.19 2020/10/11 14:03:33 jmcneill Exp $
+# $NetBSD: Makefile.efiboot,v 1.20 2021/05/04 19:07:19 jmcneill Exp $
 
 S=		${.CURDIR}/../../..
 
@@ -137,7 +137,7 @@ cleanlibdir:
 
 LIBLIST= ${LIBGNUEFI} ${LIBSA} ${LIBZ} ${LIBKERN} ${LIBSA}
 
-VERSIONMACHINE=evbarm
+VERSIONMACHINE=${MACHINE}
 .include "${S}/conf/newvers_stand.mk"
 
 CLEANFILES+=	${PROG}.so ${PROG}.tmp



CVS commit: src/sys/stand/efiboot/bootriscv64

2021-05-02 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun May  2 15:22:27 UTC 2021

Added Files:
src/sys/stand/efiboot/bootriscv64: Makefile efibootriscv64.c

Log Message:
Add RISC-V 64-bit support.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/stand/efiboot/bootriscv64/Makefile \
src/sys/stand/efiboot/bootriscv64/efibootriscv64.c

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

Added files:

Index: src/sys/stand/efiboot/bootriscv64/Makefile
diff -u /dev/null src/sys/stand/efiboot/bootriscv64/Makefile:1.1
--- /dev/null	Sun May  2 15:22:27 2021
+++ src/sys/stand/efiboot/bootriscv64/Makefile	Sun May  2 15:22:27 2021
@@ -0,0 +1,20 @@
+# $NetBSD: Makefile,v 1.1 2021/05/02 15:22:27 jmcneill Exp $
+
+PROG=		bootriscv64.efi
+OBJFMT=		binary
+NEWVERSWHAT=	"efiboot (riscv64)"
+GNUEFIARCH=	riscv64
+LIBGNUEFI_ARCH=	riscv64
+
+EXTRA_SOURCES=	efibootriscv64.c
+
+COPTS+=		-mcmodel=medany
+AFLAGS+=	-x assembler-with-cpp
+CFLAGS+=	-DEFIBOOT_ALIGN=0x20
+CFLAGS+=	-DEFIBOOT_MODULE_MACHINE=\"riscv\"
+
+.include "${.CURDIR}/../Makefile.efiboot"
+
+release: check_RELEASEDIR
+	${HOST_INSTALL_FILE} -m ${BINMODE} ${PROG} \
+		${RELEASEDIR}/${RELEASEMACHINEDIR}/installation/misc
Index: src/sys/stand/efiboot/bootriscv64/efibootriscv64.c
diff -u /dev/null src/sys/stand/efiboot/bootriscv64/efibootriscv64.c:1.1
--- /dev/null	Sun May  2 15:22:27 2021
+++ src/sys/stand/efiboot/bootriscv64/efibootriscv64.c	Sun May  2 15:22:27 2021
@@ -0,0 +1,78 @@
+/* $NetBSD: efibootriscv64.c,v 1.1 2021/05/02 15:22:27 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2021 Jared McNeill 
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "../efiboot.h"
+#include "../efifdt.h"
+
+#include 
+
+#include 
+#include 
+
+typedef void (*riscv_kernel_entry_t)(register_t, register_t);
+
+static uint32_t
+efi_fdt_get_boot_hartid(void)
+{
+	const int chosen = fdt_path_offset(efi_fdt_data(), "/chosen");
+	const uint32_t *data;
+
+	data = fdt_getprop(efi_fdt_data(), chosen, "boot-hartid", NULL);
+	if (data == NULL) {
+		return 0;	/* XXX */
+	}
+
+	return fdt32_to_cpu(*data);
+}
+
+void
+efi_boot_kernel(u_long marks[MARK_MAX])
+{
+	riscv_kernel_entry_t entry_fn;
+	register_t hart_id; /* a0 */
+	register_t fdt_start; /* a1 */
+
+	entry_fn = (riscv_kernel_entry_t)(uintptr_t)marks[MARK_ENTRY];
+
+	hart_id = efi_fdt_get_boot_hartid();
+	fdt_start = (register_t)efi_fdt_data();
+
+	asm volatile("fence rw,rw; fence.i" ::: "memory");
+
+	entry_fn(hart_id, fdt_start);
+}
+
+void
+efi_md_show(void)
+{
+}
+
+void
+efi_dcache_flush(u_long start, u_long size)
+{
+}



CVS commit: src/sys/stand/efiboot/bootaa64

2021-01-09 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jan  9 13:19:27 UTC 2021

Modified Files:
src/sys/stand/efiboot/bootaa64: efibootaa64.c

Log Message:
Flush from kernel start, not the entry point.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/stand/efiboot/bootaa64/efibootaa64.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/stand/efiboot/bootaa64/efibootaa64.c
diff -u src/sys/stand/efiboot/bootaa64/efibootaa64.c:1.4 src/sys/stand/efiboot/bootaa64/efibootaa64.c:1.5
--- src/sys/stand/efiboot/bootaa64/efibootaa64.c:1.4	Sat Jan  9 13:15:15 2021
+++ src/sys/stand/efiboot/bootaa64/efibootaa64.c	Sat Jan  9 13:19:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: efibootaa64.c,v 1.4 2021/01/09 13:15:15 jmcneill Exp $	*/
+/*	$NetBSD: efibootaa64.c,v 1.5 2021/01/09 13:19:27 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -56,7 +56,7 @@ efi_boot_kernel(u_long marks[MARK_MAX])
 	fdt_start = (u_long)efi_fdt_data();
 	fdt_size = efi_fdt_size();
 
-	aarch64_dcache_wbinv_range(kernel_entry, kernel_size);
+	aarch64_dcache_wbinv_range(kernel_start, kernel_size);
 	if (efi_fdt_size() > 0) {
 		aarch64_dcache_wbinv_range(fdt_start, fdt_size);
 	}



CVS commit: src/sys/stand/efiboot/bootaa64

2021-01-09 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jan  9 13:15:15 UTC 2021

Modified Files:
src/sys/stand/efiboot/bootaa64: efibootaa64.c

Log Message:
Style fixes, NFCI.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/stand/efiboot/bootaa64/efibootaa64.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/stand/efiboot/bootaa64/efibootaa64.c
diff -u src/sys/stand/efiboot/bootaa64/efibootaa64.c:1.3 src/sys/stand/efiboot/bootaa64/efibootaa64.c:1.4
--- src/sys/stand/efiboot/bootaa64/efibootaa64.c:1.3	Sat Nov 28 14:02:09 2020
+++ src/sys/stand/efiboot/bootaa64/efibootaa64.c	Sat Jan  9 13:15:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: efibootaa64.c,v 1.3 2020/11/28 14:02:09 jmcneill Exp $	*/
+/*	$NetBSD: efibootaa64.c,v 1.4 2021/01/09 13:15:15 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -47,18 +47,22 @@ efi_dcache_flush(u_long start, u_long si
 void
 efi_boot_kernel(u_long marks[MARK_MAX])
 {
-	void (*kernel_entry)(register_t, register_t, register_t, register_t);
-	u_long kernel_size;
+	u_long kernel_start, kernel_size, kernel_entry;
+	u_long fdt_start, fdt_size;
 
-	kernel_entry = (void *)marks[MARK_ENTRY];
-	kernel_size = marks[MARK_END] - marks[MARK_START];
-
-	aarch64_dcache_wbinv_range((u_long)kernel_entry, kernel_size);
-	if (efi_fdt_size() > 0)
-		aarch64_dcache_wbinv_range((u_long)efi_fdt_data(), efi_fdt_size());
+	kernel_start = marks[MARK_START];
+	kernel_size = marks[MARK_END] - kernel_start;
+	kernel_entry = marks[MARK_ENTRY];
+	fdt_start = (u_long)efi_fdt_data();
+	fdt_size = efi_fdt_size();
+
+	aarch64_dcache_wbinv_range(kernel_entry, kernel_size);
+	if (efi_fdt_size() > 0) {
+		aarch64_dcache_wbinv_range(fdt_start, fdt_size);
+	}
 	aarch64_icache_inv_all();
 
-	aarch64_exec_kernel((paddr_t)marks[MARK_ENTRY], (paddr_t)efi_fdt_data());
+	aarch64_exec_kernel((paddr_t)kernel_entry, (paddr_t)fdt_start);
 }
 
 /*



CVS commit: src/sys/stand/efiboot

2020-12-19 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Dec 19 08:09:32 UTC 2020

Modified Files:
src/sys/stand/efiboot: efifdt.c

Log Message:
Various clean ups
 - cache node where possible
 - remove a compiler warning
 - improve a comment (the round_page might not be needed)


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/stand/efiboot/efifdt.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/stand/efiboot/efifdt.c
diff -u src/sys/stand/efiboot/efifdt.c:1.27 src/sys/stand/efiboot/efifdt.c:1.28
--- src/sys/stand/efiboot/efifdt.c:1.27	Thu Oct 22 09:28:30 2020
+++ src/sys/stand/efiboot/efifdt.c	Sat Dec 19 08:09:31 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.c,v 1.27 2020/10/22 09:28:30 jmcneill Exp $ */
+/* $NetBSD: efifdt.c,v 1.28 2020/12/19 08:09:31 skrll Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -235,7 +235,7 @@ efi_fdt_memory_map(void)
 	EFI_MEMORY_DESCRIPTOR *md, *memmap;
 	UINT32 descver;
 	UINT64 phys_start, phys_size;
-	int n, memory, chosen;
+	int n, memory;
 
 	memory = fdt_path_offset(fdt_data, FDT_MEMORY_NODE_PATH);
 	if (memory < 0)
@@ -243,8 +243,6 @@ efi_fdt_memory_map(void)
 	if (memory < 0)
 		panic("FDT: Failed to create " FDT_MEMORY_NODE_PATH " node");
 
-	chosen = efi_fdt_chosen();
-
 	fdt_delprop(fdt_data, memory, "reg");
 
 	const int address_cells = fdt_address_cells(fdt_data, fdt_path_offset(fdt_data, "/"));
@@ -252,10 +250,15 @@ efi_fdt_memory_map(void)
 
 	memmap = LibMemoryMap(, , , );
 	for (n = 0, md = memmap; n < nentries; n++, md = NextMemoryDescriptor(md, descsize)) {
-		fdt_appendprop_u32(fdt_data, fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "netbsd,uefi-memmap", md->Type);
-		fdt_appendprop_u64(fdt_data, fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "netbsd,uefi-memmap", md->PhysicalStart);
-		fdt_appendprop_u64(fdt_data, fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "netbsd,uefi-memmap", md->NumberOfPages);
-		fdt_appendprop_u64(fdt_data, fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "netbsd,uefi-memmap", md->Attribute);
+		/*
+		 * create / find the chosen node for each iteration as it might have changed
+		 * when adding to the memory node
+		 */
+		int chosen = efi_fdt_chosen();
+		fdt_appendprop_u32(fdt_data, chosen, "netbsd,uefi-memmap", md->Type);
+		fdt_appendprop_u64(fdt_data, chosen, "netbsd,uefi-memmap", md->PhysicalStart);
+		fdt_appendprop_u64(fdt_data, chosen, "netbsd,uefi-memmap", md->NumberOfPages);
+		fdt_appendprop_u64(fdt_data, chosen, "netbsd,uefi-memmap", md->Attribute);
 
 		if ((md->Attribute & EFI_MEMORY_RUNTIME) != 0)
 			continue;
@@ -273,26 +276,31 @@ efi_fdt_memory_map(void)
 		phys_size = md->NumberOfPages * EFI_PAGE_SIZE;
 
 		if (phys_start & EFI_PAGE_MASK) {
-			/* UEFI spec says these should be 4KB aligned, but U-Boot doesn't always.. */
+			/*
+			 * UEFI spec says these should be 4KB aligned, but
+			 * U-Boot doesn't always, so round up to the next
+			 * page.
+			 */
 			phys_start = (phys_start + EFI_PAGE_SIZE) & ~EFI_PAGE_MASK;
 			phys_size -= (EFI_PAGE_SIZE * 2);
 			if (phys_size == 0)
 continue;
 		}
 
+		memory = fdt_path_offset(fdt_data, FDT_MEMORY_NODE_PATH);
 		if (address_cells == 1)
-			fdt_appendprop_u32(fdt_data, fdt_path_offset(fdt_data, FDT_MEMORY_NODE_PATH),
-			"reg", (uint32_t)phys_start);
+			fdt_appendprop_u32(fdt_data, memory, "reg",
+			(uint32_t)phys_start);
 		else
-			fdt_appendprop_u64(fdt_data, fdt_path_offset(fdt_data, FDT_MEMORY_NODE_PATH),
-			"reg", phys_start);
+			fdt_appendprop_u64(fdt_data, memory, "reg",
+			phys_start);
 
 		if (size_cells == 1)
-			fdt_appendprop_u32(fdt_data, fdt_path_offset(fdt_data, FDT_MEMORY_NODE_PATH),
-			"reg", (uint32_t)phys_size);
+			fdt_appendprop_u32(fdt_data, memory, "reg",
+			(uint32_t)phys_size);
 		else
-			fdt_appendprop_u64(fdt_data, fdt_path_offset(fdt_data, FDT_MEMORY_NODE_PATH),
-			"reg", phys_size);
+			fdt_appendprop_u64(fdt_data, memory, "reg",
+			phys_size);
 	}
 }
 



CVS commit: src/sys/stand/efiboot

2020-11-28 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Nov 28 15:24:05 UTC 2020

Modified Files:
src/sys/stand/efiboot: efiblock.c

Log Message:
Deal with devices that report either 512 or 2048 as logical block size
for CD9660 file-systems.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/stand/efiboot/efiblock.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/stand/efiboot/efiblock.c
diff -u src/sys/stand/efiboot/efiblock.c:1.9 src/sys/stand/efiboot/efiblock.c:1.10
--- src/sys/stand/efiboot/efiblock.c:1.9	Sun Oct 18 18:05:48 2020
+++ src/sys/stand/efiboot/efiblock.c	Sat Nov 28 15:24:05 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.c,v 1.9 2020/10/18 18:05:48 tnn Exp $ */
+/* $NetBSD: efiblock.c,v 1.10 2020/11/28 15:24:05 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -127,28 +127,43 @@ efi_block_find_partitions_cd9660(struct 
 	EFI_LBA lba;
 	UINT32 sz;
 
+	if (bdev->bio->Media->BlockSize != DEV_BSIZE &&
+	bdev->bio->Media->BlockSize != ISO_DEFAULT_BLOCK_SIZE) {
+		return ENXIO;
+	}
+
 	sz = __MAX(sizeof(*vd), bdev->bio->Media->BlockSize);
 	sz = roundup(sz, bdev->bio->Media->BlockSize);
-	if ((buf = efi_block_allocate_device_buffer(bdev, sz, _start)) == NULL)
+	if ((buf = efi_block_allocate_device_buffer(bdev, sz, _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))
+		status = uefi_call_wrapper(bdev->bio->ReadBlocks, 5,
+		bdev->bio,
+		bdev->media_id,
+		lba * ISO_DEFAULT_BLOCK_SIZE / bdev->bio->Media->BlockSize,
+		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)
+		if (memcmp(vd->id, ISO_STANDARD_ID, sizeof vd->id) != 0) {
 			goto io_error;
-		if (isonum_711(vd->type) == ISO_VD_END)
+		}
+		if (isonum_711(vd->type) == ISO_VD_END) {
 			goto io_error;
-		if (isonum_711(vd->type) == ISO_VD_PRIMARY)
+		}
+		if (isonum_711(vd->type) == ISO_VD_PRIMARY) {
 			break;
+		}
 	}
 
-	if (isonum_723(vd->logical_block_size) != ISO_DEFAULT_BLOCK_SIZE)
+	if (isonum_723(vd->logical_block_size) != ISO_DEFAULT_BLOCK_SIZE) {
 		goto io_error;
+	}
 
 	bpart = alloc(sizeof(*bpart));
 	bpart->index = 0;
@@ -593,6 +608,7 @@ efi_block_strategy(void *devdata, int rw
 		dblk += le64toh(bpart->gpt.ent.ent_lba_start);
 		break;
 	case EFI_BLOCK_PART_CD9660:
+		dblk *= ISO_DEFAULT_BLOCK_SIZE / bpart->bdev->bio->Media->BlockSize;
 		break;
 	default:
 		return EINVAL;
@@ -603,8 +619,9 @@ efi_block_strategy(void *devdata, int rw
 		allocated_buf = NULL;
 		aligned_buf = buf;
 	} else if ((allocated_buf = efi_block_allocate_device_buffer(bpart->bdev,
-		size, _buf)) == NULL)
+		size, _buf)) == NULL) {
 		return ENOMEM;
+	}
 
 	status = uefi_call_wrapper(bpart->bdev->bio->ReadBlocks, 5,
 		bpart->bdev->bio, bpart->bdev->media_id, dblk, size, aligned_buf);



CVS commit: src/sys/stand/efiboot

2020-11-28 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Nov 28 14:02:09 UTC 2020

Modified Files:
src/sys/stand/efiboot: boot.c efiboot_machdep.h
src/sys/stand/efiboot/bootaa64: efibootaa64.c
src/sys/stand/efiboot/bootarm: efibootarm.c

Log Message:
Add a hook for MD specific info to print in the "ver" command. Use this
to print the value of the current execution level in bootaa64.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/stand/efiboot/boot.c
cvs rdiff -u -r1.2 -r1.3 src/sys/stand/efiboot/efiboot_machdep.h
cvs rdiff -u -r1.2 -r1.3 src/sys/stand/efiboot/bootaa64/efibootaa64.c
cvs rdiff -u -r1.2 -r1.3 src/sys/stand/efiboot/bootarm/efibootarm.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/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.28 src/sys/stand/efiboot/boot.c:1.29
--- src/sys/stand/efiboot/boot.c:1.28	Sun Oct 11 14:03:33 2020
+++ src/sys/stand/efiboot/boot.c	Sat Nov 28 14:02:09 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.28 2020/10/11 14:03:33 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.29 2020/11/28 14:02:09 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -347,6 +347,7 @@ command_version(char *arg)
 	efi_fdt_show();
 	efi_acpi_show();
 	efi_rng_show();
+	efi_md_show();
 }
 
 void

Index: src/sys/stand/efiboot/efiboot_machdep.h
diff -u src/sys/stand/efiboot/efiboot_machdep.h:1.2 src/sys/stand/efiboot/efiboot_machdep.h:1.3
--- src/sys/stand/efiboot/efiboot_machdep.h:1.2	Fri Sep  7 17:30:32 2018
+++ src/sys/stand/efiboot/efiboot_machdep.h	Sat Nov 28 14:02:09 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efiboot_machdep.h,v 1.2 2018/09/07 17:30:32 jmcneill Exp $ */
+/* $NetBSD: efiboot_machdep.h,v 1.3 2020/11/28 14:02:09 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -32,3 +32,4 @@
 
 void efi_dcache_flush(u_long, u_long);
 void efi_boot_kernel(u_long[]);
+void efi_md_show(void);

Index: src/sys/stand/efiboot/bootaa64/efibootaa64.c
diff -u src/sys/stand/efiboot/bootaa64/efibootaa64.c:1.2 src/sys/stand/efiboot/bootaa64/efibootaa64.c:1.3
--- src/sys/stand/efiboot/bootaa64/efibootaa64.c:1.2	Fri Sep  7 17:30:32 2018
+++ src/sys/stand/efiboot/bootaa64/efibootaa64.c	Sat Nov 28 14:02:09 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: efibootaa64.c,v 1.2 2018/09/07 17:30:32 jmcneill Exp $	*/
+/*	$NetBSD: efibootaa64.c,v 1.3 2020/11/28 14:02:09 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -60,3 +60,20 @@ efi_boot_kernel(u_long marks[MARK_MAX])
 
 	aarch64_exec_kernel((paddr_t)marks[MARK_ENTRY], (paddr_t)efi_fdt_data());
 }
+
+/*
+ * Returns the current exception level.
+ */
+static u_int
+efi_aarch64_current_el(void)
+{
+	uint64_t el;
+	__asm __volatile ("mrs %0, CurrentEL" : "=r" (el));
+	return (el >> 2) & 0x3;
+}
+
+void
+efi_md_show(void)
+{
+	printf("Current Exception Level: EL%u\n", efi_aarch64_current_el());
+}

Index: src/sys/stand/efiboot/bootarm/efibootarm.c
diff -u src/sys/stand/efiboot/bootarm/efibootarm.c:1.2 src/sys/stand/efiboot/bootarm/efibootarm.c:1.3
--- src/sys/stand/efiboot/bootarm/efibootarm.c:1.2	Sat Mar 30 17:41:13 2019
+++ src/sys/stand/efiboot/bootarm/efibootarm.c	Sat Nov 28 14:02:09 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efibootarm.c,v 1.2 2019/03/30 17:41:13 jmcneill Exp $ */
+/* $NetBSD: efibootarm.c,v 1.3 2020/11/28 14:02:09 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared McNeill 
@@ -58,3 +58,8 @@ efi_boot_kernel(u_long marks[MARK_MAX])
 
 	armv7_exec_kernel((register_t)marks[MARK_ENTRY], (register_t)efi_fdt_data());
 }
+
+void
+efi_md_show(void)
+{
+}



CVS commit: src/sys/stand/efiboot

2020-10-22 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Oct 22 09:28:30 UTC 2020

Modified Files:
src/sys/stand/efiboot: efifdt.c

Log Message:
Fix previous.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/stand/efiboot/efifdt.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/stand/efiboot/efifdt.c
diff -u src/sys/stand/efiboot/efifdt.c:1.26 src/sys/stand/efiboot/efifdt.c:1.27
--- src/sys/stand/efiboot/efifdt.c:1.26	Thu Oct 22 09:14:40 2020
+++ src/sys/stand/efiboot/efifdt.c	Thu Oct 22 09:28:30 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.c,v 1.26 2020/10/22 09:14:40 jmcneill Exp $ */
+/* $NetBSD: efifdt.c,v 1.27 2020/10/22 09:28:30 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -338,21 +338,17 @@ efi_fdt_gop(void)
 			continue;
 		}
 
-		snprintf(buf, sizeof(buf), "framebuffer@%" PRIx64, mode->FrameBufferBase);
-		fb = fdt_path_offset(fdt_data, buf);
-		if (fb >= 0) {
-			/* Framebuffer node already exists, no need to create one */
-			return;
-		}
-
 		chosen = efi_fdt_chosen();
 		fdt_setprop_u32(fdt_data, chosen, "#address-cells", 2);
 		fdt_setprop_u32(fdt_data, chosen, "#size-cells", 2);
 		fdt_setprop_empty(fdt_data, chosen, "ranges");
 
+		snprintf(buf, sizeof(buf), "framebuffer@%" PRIx64, mode->FrameBufferBase);
 		fb = fdt_add_subnode(fdt_data, chosen, buf);
-		if (fb < 0)
-			panic("FDT: Failed to create framebuffer node");
+		if (fb < 0) {
+			/* Framebuffer node already exists. No need to create a new one! */
+			return;
+		}
 
 		fdt_appendprop_string(fdt_data, fb, "compatible", "simple-framebuffer");
 		fdt_appendprop_string(fdt_data, fb, "status", "okay");



CVS commit: src/sys/stand/efiboot

2020-10-22 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Oct 22 09:14:41 UTC 2020

Modified Files:
src/sys/stand/efiboot: efifdt.c

Log Message:
If the framebuffer node already exists, we don't need to create one


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/stand/efiboot/efifdt.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/stand/efiboot/efifdt.c
diff -u src/sys/stand/efiboot/efifdt.c:1.25 src/sys/stand/efiboot/efifdt.c:1.26
--- src/sys/stand/efiboot/efifdt.c:1.25	Sat Oct 10 19:17:39 2020
+++ src/sys/stand/efiboot/efifdt.c	Thu Oct 22 09:14:40 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.c,v 1.25 2020/10/10 19:17:39 jmcneill Exp $ */
+/* $NetBSD: efifdt.c,v 1.26 2020/10/22 09:14:40 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -338,12 +338,18 @@ efi_fdt_gop(void)
 			continue;
 		}
 
+		snprintf(buf, sizeof(buf), "framebuffer@%" PRIx64, mode->FrameBufferBase);
+		fb = fdt_path_offset(fdt_data, buf);
+		if (fb >= 0) {
+			/* Framebuffer node already exists, no need to create one */
+			return;
+		}
+
 		chosen = efi_fdt_chosen();
 		fdt_setprop_u32(fdt_data, chosen, "#address-cells", 2);
 		fdt_setprop_u32(fdt_data, chosen, "#size-cells", 2);
 		fdt_setprop_empty(fdt_data, chosen, "ranges");
 
-		snprintf(buf, sizeof(buf), "framebuffer@%" PRIx64, mode->FrameBufferBase);
 		fb = fdt_add_subnode(fdt_data, chosen, buf);
 		if (fb < 0)
 			panic("FDT: Failed to create framebuffer node");



CVS commit: src/sys/stand/efiboot

2020-10-18 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Sun Oct 18 18:09:32 UTC 2020

Modified Files:
src/sys/stand/efiboot: version

Log Message:
efiboot: bump version


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 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/version
diff -u src/sys/stand/efiboot/version:1.21 src/sys/stand/efiboot/version:1.22
--- src/sys/stand/efiboot/version:1.21	Sun Oct 11 14:03:33 2020
+++ src/sys/stand/efiboot/version	Sun Oct 18 18:09:32 2020
@@ -1,4 +1,4 @@
-$NetBSD: version,v 1.21 2020/10/11 14:03:33 jmcneill Exp $
+$NetBSD: version,v 1.22 2020/10/18 18:09:32 tnn 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
@@ -25,3 +25,4 @@ is taken as the current.
 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.
+2.5:	Recognize the EFI system partion as fstype MSDOS.



CVS commit: src/sys/stand/efiboot

2020-10-18 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Sun Oct 18 18:05:48 UTC 2020

Modified Files:
src/sys/stand/efiboot: efiblock.c

Log Message:
efiboot: recognize the EFI system partition as fstype MSDOS


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/stand/efiboot/efiblock.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/stand/efiboot/efiblock.c
diff -u src/sys/stand/efiboot/efiblock.c:1.8 src/sys/stand/efiboot/efiblock.c:1.9
--- src/sys/stand/efiboot/efiblock.c:1.8	Sun Oct 11 14:03:33 2020
+++ src/sys/stand/efiboot/efiblock.c	Sun Oct 18 18:05:48 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.c,v 1.8 2020/10/11 14:03:33 jmcneill Exp $ */
+/* $NetBSD: efiblock.c,v 1.9 2020/10/18 18:05:48 tnn Exp $ */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -269,6 +269,7 @@ static const struct {
 	{ GPT_ENT_TYPE_NETBSD_CCD,		FS_CCD },
 	{ GPT_ENT_TYPE_NETBSD_CGD,		FS_CGD },
 	{ GPT_ENT_TYPE_MS_BASIC_DATA,		FS_MSDOS },	/* or NTFS? ambiguous */
+	{ GPT_ENT_TYPE_EFI,			FS_MSDOS },
 };
 
 static int



CVS commit: src/sys/stand/efiboot

2020-10-11 Thread Jared D. McNeill
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 
@@ -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 
@@ -33,6 +33,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -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 
@@ -33,6 +33,8 @@
 #include 
 #include 
 
+#include 
+
 #include "efiboot.h"
 #include "efiblock.h"
 
@@ -116,6 +118,53 @@ efi_block_allocate_device_buffer(struct 
 }
 
 static int

CVS commit: src/sys/stand/efiboot

2020-10-10 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Oct 10 19:17:39 UTC 2020

Modified Files:
src/sys/stand/efiboot: efiacpi.c efifdt.c efifdt.h exec.c version

Log Message:
Support EFI runtime and GOP FB for devicetree (non-ACPI) setups.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/stand/efiboot/efiacpi.c
cvs rdiff -u -r1.24 -r1.25 src/sys/stand/efiboot/efifdt.c
cvs rdiff -u -r1.9 -r1.10 src/sys/stand/efiboot/efifdt.h
cvs rdiff -u -r1.18 -r1.19 src/sys/stand/efiboot/exec.c
cvs rdiff -u -r1.19 -r1.20 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/efiacpi.c
diff -u src/sys/stand/efiboot/efiacpi.c:1.7 src/sys/stand/efiboot/efiacpi.c:1.8
--- src/sys/stand/efiboot/efiacpi.c:1.7	Thu May 14 19:19:08 2020
+++ src/sys/stand/efiboot/efiacpi.c	Sat Oct 10 19:17:39 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efiacpi.c,v 1.7 2020/05/14 19:19:08 riastradh Exp $ */
+/* $NetBSD: efiacpi.c,v 1.8 2020/10/10 19:17:39 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -155,9 +155,6 @@ efi_acpi_create_fdt(void)
 	fdt_setprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,acpi-root-table", (uint64_t)(uintptr_t)acpi_root);
 	if (smbios3_table)
 		fdt_setprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,smbios-table", (uint64_t)(uintptr_t)smbios3_table);
-#ifdef EFIBOOT_RUNTIME_ADDRESS
-	fdt_setprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,uefi-system-table", (uint64_t)(uintptr_t)ST);
-#endif
 
 	fdt_add_subnode(fdt, fdt_path_offset(fdt, "/"), "acpi");
 	fdt_setprop_string(fdt, fdt_path_offset(fdt, "/acpi"), "compatible", "netbsd,acpi");

Index: src/sys/stand/efiboot/efifdt.c
diff -u src/sys/stand/efiboot/efifdt.c:1.24 src/sys/stand/efiboot/efifdt.c:1.25
--- src/sys/stand/efiboot/efifdt.c:1.24	Sun Jun 21 17:24:26 2020
+++ src/sys/stand/efiboot/efifdt.c	Sat Oct 10 19:17:39 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.c,v 1.24 2020/06/21 17:24:26 jmcneill Exp $ */
+/* $NetBSD: efifdt.c,v 1.25 2020/10/10 19:17:39 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -30,6 +30,7 @@
 #include "efiboot.h"
 #include "efifdt.h"
 #include "efiblock.h"
+#include "efiacpi.h"
 
 #include 
 
@@ -55,6 +56,7 @@ static EFI_GUID FdtTableGuid = FDT_TABLE
 #define PRIxUINTN "x"
 #endif
 static void *fdt_data = NULL;
+static size_t fdt_data_size = 512*1024;
 
 int
 efi_fdt_probe(void)
@@ -76,10 +78,23 @@ efi_fdt_probe(void)
 int
 efi_fdt_set_data(void *data)
 {
+	int err;
+
 	if (fdt_check_header(data) != 0)
 		return EINVAL;
 
-	fdt_data = data;
+	fdt_data = alloc(fdt_data_size);
+	if (fdt_data == NULL)
+		return ENOMEM;
+	memset(fdt_data, 0, fdt_data_size);
+
+	err = fdt_open_into(data, fdt_data, fdt_data_size);
+	if (err != 0) {
+		dealloc(fdt_data, fdt_data_size);
+		fdt_data = NULL;
+		return ENXIO;
+	}
+
 	return 0;
 }
 
@@ -202,6 +217,18 @@ efi_fdt_chosen(void)
 }
 
 void
+efi_fdt_system_table(void)
+{
+#ifdef EFIBOOT_RUNTIME_ADDRESS
+	int chosen;
+
+	chosen = efi_fdt_chosen();
+
+	fdt_setprop_u64(fdt_data, chosen, "netbsd,uefi-system-table", (uint64_t)(uintptr_t)ST);
+#endif
+}
+
+void
 efi_fdt_memory_map(void)
 {
 	UINTN nentries = 0, mapkey, descsize;
@@ -278,7 +305,7 @@ efi_fdt_gop(void)
 	EFI_HANDLE *gop_handle;
 	UINTN ngop_handle, n;
 	char buf[48];
-	int fb;
+	int fb, chosen;
 
 	status = LibLocateHandle(ByProtocol, , NULL, _handle, _handle);
 	if (EFI_ERROR(status) || ngop_handle == 0)
@@ -311,15 +338,13 @@ efi_fdt_gop(void)
 			continue;
 		}
 
-		fdt_setprop_u32(fdt_data,
-		fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "#address-cells", 2);
-		fdt_setprop_u32(fdt_data,
-		fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "#size-cells", 2);
-		fdt_setprop_empty(fdt_data,
-		fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "ranges");
+		chosen = efi_fdt_chosen();
+		fdt_setprop_u32(fdt_data, chosen, "#address-cells", 2);
+		fdt_setprop_u32(fdt_data, chosen, "#size-cells", 2);
+		fdt_setprop_empty(fdt_data, chosen, "ranges");
 
 		snprintf(buf, sizeof(buf), "framebuffer@%" PRIx64, mode->FrameBufferBase);
-		fb = fdt_add_subnode(fdt_data, fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), buf);
+		fb = fdt_add_subnode(fdt_data, chosen, buf);
 		if (fb < 0)
 			panic("FDT: Failed to create framebuffer node");
 
@@ -332,9 +357,13 @@ efi_fdt_gop(void)
 		fdt_appendprop_u32(fdt_data, fb, "stride", mode->Info->PixelsPerScanLine * 4);	/* XXX */
 		fdt_appendprop_string(fdt_data, fb, "format", "a8b8g8r8");
 
-		snprintf(buf, sizeof(buf), "/chosen/framebuffer@%" PRIx64, mode->FrameBufferBase);
-		fdt_setprop_string(fdt_data, fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH),
-		"stdout-path", buf);
+		/*
+		 * In ACPI mode, use GOP as console.
+		 */
+		if (efi_acpi_available()) {
+			snprintf(buf, sizeof(buf), "/chosen/framebuffer@%" PRIx64, mode->FrameBufferBase);
+			fdt_setprop_string(fdt_data, 

CVS commit: src/sys/stand/efiboot/bootaa64

2020-09-10 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Thu Sep 10 14:30:15 UTC 2020

Modified Files:
src/sys/stand/efiboot/bootaa64: Makefile

Log Message:
bootaa64: explicitly set GNUEFIARCH and LIBGNUEFI_ARCH to aarch64


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/stand/efiboot/bootaa64/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/stand/efiboot/bootaa64/Makefile
diff -u src/sys/stand/efiboot/bootaa64/Makefile:1.9 src/sys/stand/efiboot/bootaa64/Makefile:1.10
--- src/sys/stand/efiboot/bootaa64/Makefile:1.9	Tue Sep  8 16:34:43 2020
+++ src/sys/stand/efiboot/bootaa64/Makefile	Thu Sep 10 14:30:14 2020
@@ -1,8 +1,10 @@
-# $NetBSD: Makefile,v 1.9 2020/09/08 16:34:43 jmcneill Exp $
+# $NetBSD: Makefile,v 1.10 2020/09/10 14:30:14 jakllsch Exp $
 
 PROG=		bootaa64.efi
 OBJFMT=		binary
 NEWVERSWHAT=	"efiboot (arm64)"
+GNUEFIARCH=	aarch64
+LIBGNUEFI_ARCH=	aarch64
 
 EXTRA_SOURCES=	efibootaa64.c
 EXTRA_SOURCES+=	cache.S



CVS commit: src/sys/stand/efiboot/bootaa64

2020-09-08 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Sep  8 16:34:43 UTC 2020

Modified Files:
src/sys/stand/efiboot/bootaa64: Makefile

Log Message:
Be explicit about building for little endian. This allows efiboot to be
built with the aarch64eb toolchain.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/stand/efiboot/bootaa64/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/stand/efiboot/bootaa64/Makefile
diff -u src/sys/stand/efiboot/bootaa64/Makefile:1.8 src/sys/stand/efiboot/bootaa64/Makefile:1.9
--- src/sys/stand/efiboot/bootaa64/Makefile:1.8	Sun Jun 21 17:24:26 2020
+++ src/sys/stand/efiboot/bootaa64/Makefile	Tue Sep  8 16:34:43 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.8 2020/06/21 17:24:26 jmcneill Exp $
+# $NetBSD: Makefile,v 1.9 2020/09/08 16:34:43 jmcneill Exp $
 
 PROG=		bootaa64.efi
 OBJFMT=		binary
@@ -7,12 +7,14 @@ NEWVERSWHAT=	"efiboot (arm64)"
 EXTRA_SOURCES=	efibootaa64.c
 EXTRA_SOURCES+=	cache.S
 
-COPTS+=		-mgeneral-regs-only -fno-jump-tables
+COPTS+=		-mgeneral-regs-only -mlittle-endian -fno-jump-tables
+AFLAGS+=	-mlittle-endian
 CFLAGS+=	-DEFIBOOT_ALIGN=0x20
 CFLAGS+=	-DEFIBOOT_RUNTIME_ADDRESS=0x8000L
 CFLAGS+=	-DEFIBOOT_RUNTIME_SIZE=0x4000UL
 CFLAGS+=	-DEFIBOOT_ACPI
 CFLAGS+=	-DEFIBOOT_MODULE_MACHINE=\"evbarm\"
+LDFLAGS+=	-EL
 
 .include "${.CURDIR}/../Makefile.efiboot"
 



CVS commit: src/sys/stand/efiboot/bootarm

2020-09-08 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Sep  8 15:36:37 UTC 2020

Modified Files:
src/sys/stand/efiboot/bootarm: Makefile

Log Message:
Be explicit about building for little endian. This allows efiboot to be
built with the armv7be toolchain.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/stand/efiboot/bootarm/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/stand/efiboot/bootarm/Makefile
diff -u src/sys/stand/efiboot/bootarm/Makefile:1.5 src/sys/stand/efiboot/bootarm/Makefile:1.6
--- src/sys/stand/efiboot/bootarm/Makefile:1.5	Sun Jun 21 17:24:26 2020
+++ src/sys/stand/efiboot/bootarm/Makefile	Tue Sep  8 15:36:37 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.5 2020/06/21 17:24:26 jmcneill Exp $
+# $NetBSD: Makefile,v 1.6 2020/09/08 15:36:37 jmcneill Exp $
 
 PROG=		bootarm.efi
 OBJFMT=		binary
@@ -9,10 +9,12 @@ LIBGNUEFI_ARCH=	arm
 EXTRA_SOURCES=	efibootarm.c
 EXTRA_SOURCES+=	cache.S
 
-COPTS+=		-mfloat-abi=soft -mno-unaligned-access -ffreestanding -fno-unwind-tables
+COPTS+=		-mfloat-abi=soft -mno-unaligned-access -mlittle-endian
+COPTS+=		-ffreestanding -fno-unwind-tables
+AFLAGS+=	-mlittle-endian
 CFLAGS+=	-DEFIBOOT_ALIGN=0x100
 CFLAGS+=	-DEFIBOOT_MODULE_MACHINE=\"evbarm\"
-LDFLAGS+=	-N
+LDFLAGS+=	-N -EL
 
 .include "${.CURDIR}/../Makefile.efiboot"
 



CVS commit: src/sys/stand/efiboot

2020-07-14 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Jul 15 00:51:40 UTC 2020

Modified Files:
src/sys/stand/efiboot: efiboot.h efidev.c efifile.c

Log Message:
Fixup OpenSimpleReadFile usage:
 - The "EFI_DEVICE_PATH **FilePath" parameter can change, so do not free
   the output. This was causing crashes on U-Boot when attempting to load
   boot.cfg, even if it didn't exist.
 - Allocate the SIMPLE_READ_FILE in advance and store a pointer to it in
   struct open_file.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/stand/efiboot/efiboot.h
cvs rdiff -u -r1.1 -r1.2 src/sys/stand/efiboot/efidev.c
cvs rdiff -u -r1.4 -r1.5 src/sys/stand/efiboot/efifile.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/stand/efiboot/efiboot.h
diff -u src/sys/stand/efiboot/efiboot.h:1.12 src/sys/stand/efiboot/efiboot.h:1.13
--- src/sys/stand/efiboot/efiboot.h:1.12	Fri Jun 26 03:23:04 2020
+++ src/sys/stand/efiboot/efiboot.h	Wed Jul 15 00:51:40 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: efiboot.h,v 1.12 2020/06/26 03:23:04 thorpej Exp $	*/
+/*	$NetBSD: efiboot.h,v 1.13 2020/07/15 00:51:40 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -82,7 +82,8 @@ int ucs2_to_utf8(const CHAR16 *, char **
 int utf8_to_ucs2(const char *, CHAR16 **, size_t *);
 
 /* efidev.c */
-int efi_device_path_depth(EFI_DEVICE_PATH *dp, int);
+int efi_device_path_depth(EFI_DEVICE_PATH *, int);
+int efi_device_path_count(EFI_DEVICE_PATH *);
 int efi_device_path_ncmp(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *, int);
 
 /* efinet.c */

Index: src/sys/stand/efiboot/efidev.c
diff -u src/sys/stand/efiboot/efidev.c:1.1 src/sys/stand/efiboot/efidev.c:1.2
--- src/sys/stand/efiboot/efidev.c:1.1	Sun Aug 26 21:28:18 2018
+++ src/sys/stand/efiboot/efidev.c	Wed Jul 15 00:51:40 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: efidev.c,v 1.1 2018/08/26 21:28:18 jmcneill Exp $	*/
+/*	$NetBSD: efidev.c,v 1.2 2020/07/15 00:51:40 jmcneill Exp $	*/
 /*	$OpenBSD: efiboot.c,v 1.28 2017/11/25 19:02:07 patrick Exp $	*/
 
 /*
@@ -37,6 +37,19 @@ efi_device_path_depth(EFI_DEVICE_PATH *d
 }
 
 int
+efi_device_path_count(EFI_DEVICE_PATH *dp)
+{
+	int	count;
+
+	for (count = 0; ; dp = NextDevicePathNode(dp), count++) {
+		if (IsDevicePathEnd(dp))
+			break;
+	}
+
+	return (count);
+}
+
+int
 efi_device_path_ncmp(EFI_DEVICE_PATH *dpa, EFI_DEVICE_PATH *dpb, int deptn)
 {
 	int	 i, cmp;

Index: src/sys/stand/efiboot/efifile.c
diff -u src/sys/stand/efiboot/efifile.c:1.4 src/sys/stand/efiboot/efifile.c:1.5
--- src/sys/stand/efiboot/efifile.c:1.4	Sat Jun 27 17:23:08 2020
+++ src/sys/stand/efiboot/efifile.c	Wed Jul 15 00:51:40 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efifile.c,v 1.4 2020/06/27 17:23:08 jmcneill Exp $ */
+/* $NetBSD: efifile.c,v 1.5 2020/07/15 00:51:40 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -67,9 +67,9 @@ efi_file_system_probe(void)
 int
 efi_file_open(struct open_file *f, ...)
 {
-	EFI_DEVICE_PATH *dp;
-	SIMPLE_READ_FILE srf;
-	EFI_HANDLE device, file;
+	EFI_DEVICE_PATH *file_dp, *dp;
+	SIMPLE_READ_FILE *srf;
+	EFI_HANDLE device;
 	EFI_STATUS status;
 	UINTN vol;
 	const char *fname, *path;
@@ -86,30 +86,37 @@ efi_file_open(struct open_file *f, ...)
 	if (rv != 0)
 		return rv;
 
-	device = efi_vol[vol];
-
 	upath = NULL;
 	rv = utf8_to_ucs2(path, , );
 	if (rv != 0)
 		return rv;
 
-	dp = FileDevicePath(device, upath);
+	file_dp = FileDevicePath(efi_vol[vol], upath);
 	FreePool(upath);
-	if (dp == NULL)
+	if (file_dp == NULL)
 		return EINVAL;
 
-	status = OpenSimpleReadFile(TRUE, NULL, 0, , , );
-	FreePool(dp);
-	if (EFI_ERROR(status))
+	srf = AllocatePool(sizeof(*srf));
+	if (srf == NULL)
+		return ENOMEM;
+
+	dp = file_dp;
+	status = OpenSimpleReadFile(FALSE, NULL, 0, , , srf);
+	FreePool(file_dp);
+	if (EFI_ERROR(status)) {
+		FreePool(srf);
 		return status == EFI_NOT_FOUND ? ENOENT : EIO;
+	}
 
 	for (n = 0; n < ndevs; n++)
 		if (strcmp(DEV_NAME([n]), "efifile") == 0) {
 			f->f_dev = [n];
 			break;
 		}
-	if (n == ndevs)
+	if (n == ndevs) {
+		FreePool(srf);
 		return ENXIO;
+	}
 	f->f_devdata = f;
 	f->f_fsdata = srf;
 	f->f_flags = F_NODEV | F_READ;
@@ -120,9 +127,10 @@ efi_file_open(struct open_file *f, ...)
 int
 efi_file_close(struct open_file *f)
 {
-	SIMPLE_READ_FILE srf = f->f_fsdata;
+	SIMPLE_READ_FILE *srf = f->f_fsdata;
 
-	CloseSimpleReadFile(srf);
+	CloseSimpleReadFile(*srf);
+	FreePool(srf);
 
 	return 0;
 }
@@ -131,7 +139,7 @@ int
 efi_file_strategy(void *devdata, int rw, daddr_t dblk, size_t size, void *buf, size_t *rsize)
 {
 	struct open_file *f = devdata;
-	SIMPLE_READ_FILE srf = f->f_fsdata;
+	SIMPLE_READ_FILE *srf = f->f_fsdata;
 	EFI_STATUS status;
 	UINTN len;
 
@@ -139,7 +147,7 @@ efi_file_strategy(void *devdata, int rw,
 		return EROFS;
 
 	len = size;
-	status = ReadSimpleReadFile(srf, f->f_offset, , buf);
+	status = ReadSimpleReadFile(*srf, f->f_offset, , buf);
 	if (EFI_ERROR(status))
 		return 

CVS commit: src/sys/stand/efiboot

2020-06-28 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Jun 28 11:39:50 UTC 2020

Modified Files:
src/sys/stand/efiboot: Makefile.efiboot boot.c exec.c version
Removed Files:
src/sys/stand/efiboot: efienv.c efienv.h

Log Message:
Remove support for storing settings in EFI environment variables now that
we have boot.cfg support.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/stand/efiboot/Makefile.efiboot
cvs rdiff -u -r1.26 -r1.27 src/sys/stand/efiboot/boot.c
cvs rdiff -u -r1.6 -r0 src/sys/stand/efiboot/efienv.c
cvs rdiff -u -r1.3 -r0 src/sys/stand/efiboot/efienv.h
cvs rdiff -u -r1.17 -r1.18 src/sys/stand/efiboot/exec.c
cvs rdiff -u -r1.18 -r1.19 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.16 src/sys/stand/efiboot/Makefile.efiboot:1.17
--- src/sys/stand/efiboot/Makefile.efiboot:1.16	Fri Jun 26 03:23:04 2020
+++ src/sys/stand/efiboot/Makefile.efiboot	Sun Jun 28 11:39:50 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.16 2020/06/26 03:23:04 thorpej Exp $
+# $NetBSD: Makefile.efiboot,v 1.17 2020/06/28 11:39:50 jmcneill Exp $
 
 S=		${.CURDIR}/../../..
 
@@ -23,7 +23,7 @@ AFLAGS.start.S= ${${ACTIVE_CC} == "clang
 SOURCES=	crt0-efi-${GNUEFIARCH}.S reloc_${GNUEFIARCH}.c
 SOURCES+=	boot.c bootmenu.c conf.c console.c dev_net.c devopen.c exec.c \
 		module.c overlay.c panic.c prompt.c
-SOURCES+=	efiboot.c efichar.c efidev.c efienv.c efigetsecs.c efifdt.c \
+SOURCES+=	efiboot.c efichar.c efidev.c efigetsecs.c efifdt.c \
 		efifile.c efiblock.c efinet.c efipxe.c efiacpi.c efirng.c smbios.c
 
 .PATH: ${S}/external/bsd/libfdt/dist

Index: src/sys/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.26 src/sys/stand/efiboot/boot.c:1.27
--- src/sys/stand/efiboot/boot.c:1.26	Sat Jun 27 18:52:24 2020
+++ src/sys/stand/efiboot/boot.c	Sun Jun 28 11:39:50 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.26 2020/06/27 18:52:24 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.27 2020/06/28 11:39:50 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -32,7 +32,6 @@
 #include "efifile.h"
 #include "efifdt.h"
 #include "efiacpi.h"
-#include "efienv.h"
 #include "efirng.h"
 #include "module.h"
 #include "overlay.h"
@@ -101,10 +100,6 @@ void	command_unload(char *);
 void	command_ls(char *);
 void	command_mem(char *);
 void	command_menu(char *);
-void	command_printenv(char *);
-void	command_setenv(char *);
-void	command_clearenv(char *);
-void	command_resetenv(char *);
 void	command_reset(char *);
 void	command_version(char *);
 void	command_quit(char *);
@@ -123,10 +118,6 @@ const struct boot_command commands[] = {
 	{ "ls",		command_ls,		"ls [hdNn:/path]" },
 	{ "mem",	command_mem,		"mem" },
 	{ "menu",	command_menu,		"menu" },
-	{ "printenv",	command_printenv,	"printenv [key]" },
-	{ "setenv",	command_setenv,		"setenv  " },
-	{ "clearenv",	command_clearenv,	"clearenv " },
-	{ "resetenv",	command_resetenv,	"resetenv" },
 	{ "reboot",	command_reset,		"reboot|reset" },
 	{ "reset",	command_reset,		NULL },
 	{ "version",	command_version,	"version" },
@@ -311,53 +302,6 @@ command_menu(char *arg)
 }
 
 void
-command_printenv(char *arg)
-{
-	char *val;
-
-	if (arg && *arg) {
-		val = efi_env_get(arg);
-		if (val) {
-			printf("\"%s\" = \"%s\"\n", arg, val);
-			FreePool(val);
-		}
-	} else {
-		efi_env_print();
-	}
-}
-
-void
-command_setenv(char *arg)
-{
-	char *spc;
-
-	spc = strchr(arg, ' ');
-	if (spc == NULL || spc[1] == '\0') {
-		command_help("");
-		return;
-	}
-
-	*spc = '\0';
-	efi_env_set(arg, spc + 1);
-}
-
-void
-command_clearenv(char *arg)
-{
-	if (*arg == '\0') {
-		command_help("");
-		return;
-	}
-	efi_env_clear(arg);
-}
-
-void
-command_resetenv(char *arg)
-{
-	efi_env_reset();
-}
-
-void
 command_version(char *arg)
 {
 	char pathbuf[80];
@@ -482,74 +426,12 @@ print_banner(void)
 	bootprog_name, bootprog_rev);
 }
 
-static void
-read_env(void)
-{
-	char *s;
-
-	s = efi_env_get("fdtfile");
-	if (s) {
-#ifdef EFIBOOT_DEBUG
-		printf(">> Setting DTB path to '%s' from environment\n", s);
-#endif
-		set_dtb_path(s);
-		FreePool(s);
-	}
-
-	s = efi_env_get("initrd");
-	if (s) {
-#ifdef EFIBOOT_DEBUG
-		printf(">> Setting initrd path to '%s' from environment\n", s);
-#endif
-		set_initrd_path(s);
-		FreePool(s);
-	}
-
-	s = efi_env_get("bootfile");
-	if (s) {
-#ifdef EFIBOOT_DEBUG
-		printf(">> Setting bootfile path to '%s' from environment\n", s);
-#endif
-		set_bootfile(s);
-		FreePool(s);
-	}
-
-	s = efi_env_get("rootdev");
-	if (s) {
-#ifdef EFIBOOT_DEBUG
-		printf(">> Setting default device to '%s' from environment\n", s);
-#endif
-		set_default_device(s);
-		FreePool(s);
-	}
-
-	s = efi_env_get("bootargs");
-	if (s) {
-#ifdef EFIBOOT_DEBUG
-		printf(">> Setting default boot args to '%s' from environment\n", s);
-#endif
-		set_bootargs(s);
-		

CVS commit: src/sys/stand/efiboot

2020-06-27 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jun 27 18:52:24 UTC 2020

Modified Files:
src/sys/stand/efiboot: boot.c

Log Message:
command_version: print config file path


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/stand/efiboot/boot.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/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.25 src/sys/stand/efiboot/boot.c:1.26
--- src/sys/stand/efiboot/boot.c:1.25	Sat Jun 27 17:23:08 2020
+++ src/sys/stand/efiboot/boot.c	Sat Jun 27 18:52:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.25 2020/06/27 17:23:08 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.26 2020/06/27 18:52:24 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -360,6 +360,7 @@ command_resetenv(char *arg)
 void
 command_version(char *arg)
 {
+	char pathbuf[80];
 	char *ufirmware;
 	int rv;
 
@@ -373,6 +374,10 @@ command_version(char *arg)
 		ST->FirmwareRevision);
 		FreePool(ufirmware);
 	}
+	if (efi_bootdp != NULL &&
+	efi_file_path(efi_bootdp, BOOTCFG_FILENAME, pathbuf, sizeof(pathbuf)) == 0) {
+		printf("Config path: %s\n", pathbuf);
+	}
 
 	efi_fdt_show();
 	efi_acpi_show();



CVS commit: src/sys/stand/efiboot

2020-06-27 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jun 27 17:23:08 UTC 2020

Modified Files:
src/sys/stand/efiboot: boot.c efifile.c efifile.h

Log Message:
Load boot.cfg from the EFI system partition instead of the first FFS
partition on that device.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/stand/efiboot/boot.c
cvs rdiff -u -r1.3 -r1.4 src/sys/stand/efiboot/efifile.c
cvs rdiff -u -r1.1 -r1.2 src/sys/stand/efiboot/efifile.h

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/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.24 src/sys/stand/efiboot/boot.c:1.25
--- src/sys/stand/efiboot/boot.c:1.24	Fri Jun 26 03:23:04 2020
+++ src/sys/stand/efiboot/boot.c	Sat Jun 27 17:23:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.24 2020/06/26 03:23:04 thorpej Exp $	*/
+/*	$NetBSD: boot.c,v 1.25 2020/06/27 17:23:08 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -29,6 +29,7 @@
 
 #include "efiboot.h"
 #include "efiblock.h"
+#include "efifile.h"
 #include "efifdt.h"
 #include "efiacpi.h"
 #include "efienv.h"
@@ -539,11 +540,15 @@ read_env(void)
 void
 boot(void)
 {
+	char pathbuf[80];
 	int currname, c;
 
 	read_env();
 
-	parsebootconf(BOOTCFG_FILENAME);
+	if (efi_bootdp != NULL && efi_file_path(efi_bootdp, BOOTCFG_FILENAME, pathbuf, sizeof(pathbuf)) == 0) {
+		twiddle_toggle = 1;
+		parsebootconf(pathbuf);
+	}
 
 	if (bootcfg_info.clear)
 		uefi_call_wrapper(ST->ConOut->ClearScreen, 1, ST->ConOut);
@@ -551,7 +556,6 @@ boot(void)
 	print_banner();
 
 	/* Display menu if configured */
-	twiddle_toggle = 1;
 	if (bootcfg_info.nummenu > 0) {
 		doboottypemenu();	/* No return */
 	}

Index: src/sys/stand/efiboot/efifile.c
diff -u src/sys/stand/efiboot/efifile.c:1.3 src/sys/stand/efiboot/efifile.c:1.4
--- src/sys/stand/efiboot/efifile.c:1.3	Sun Aug 26 21:28:18 2018
+++ src/sys/stand/efiboot/efifile.c	Sat Jun 27 17:23:08 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efifile.c,v 1.3 2018/08/26 21:28:18 jmcneill Exp $ */
+/* $NetBSD: efifile.c,v 1.4 2020/06/27 17:23:08 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -146,3 +146,22 @@ efi_file_strategy(void *devdata, int rw,
 
 	return 0;
 }
+
+int
+efi_file_path(EFI_DEVICE_PATH *dp, const char *fname, char *buf, size_t buflen)
+{
+	UINTN vol;
+	int depth;
+
+	depth = efi_device_path_depth(dp, END_DEVICE_PATH_TYPE);
+
+	for (vol = 0; vol < efi_nvol; vol++) {
+		if (efi_device_path_ncmp(dp, DevicePathFromHandle(efi_vol[vol]), depth) == 0)
+			break;
+	}
+	if (vol == efi_nvol)
+		return ENOENT;
+
+	snprintf(buf, buflen, "fs%u:%s", (u_int)vol, fname);
+	return 0;
+}

Index: src/sys/stand/efiboot/efifile.h
diff -u src/sys/stand/efiboot/efifile.h:1.1 src/sys/stand/efiboot/efifile.h:1.2
--- src/sys/stand/efiboot/efifile.h:1.1	Fri Aug 24 02:01:06 2018
+++ src/sys/stand/efiboot/efifile.h	Sat Jun 27 17:23:08 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efifile.h,v 1.1 2018/08/24 02:01:06 jmcneill Exp $ */
+/* $NetBSD: efifile.h,v 1.2 2020/06/27 17:23:08 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -31,3 +31,5 @@ void efi_file_system_probe(void);
 int efi_file_open(struct open_file *, ...);
 int efi_file_close(struct open_file *);
 int efi_file_strategy(void *, int, daddr_t, size_t, void *, size_t *);
+int efi_file_path(EFI_DEVICE_PATH *, const char *, char *, size_t);
+



CVS commit: src/sys/stand/efiboot

2020-06-25 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Jun 26 03:23:04 UTC 2020

Modified Files:
src/sys/stand/efiboot: Makefile.efiboot boot.c bootmenu.c efiboot.c
efiboot.h efienv.c efienv.h exec.c version
Added Files:
src/sys/stand/efiboot: overlay.c overlay.h

Log Message:
Add dtoverlay command to specify device tree overlays from the boot
loader command line.  Add support for specifying device tree overlays
in boot.cfg, with the syntax:

dtoverlay=/path/to/overlay.dtbo
dtoverlay=hd0e:/overlays/example.dtbo

Multiple overlays can be specified, and they are loaded in the order
they appear in boot.cfg.

Remove support for efiboot.plist.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/stand/efiboot/Makefile.efiboot
cvs rdiff -u -r1.23 -r1.24 src/sys/stand/efiboot/boot.c
cvs rdiff -u -r1.1 -r1.2 src/sys/stand/efiboot/bootmenu.c
cvs rdiff -u -r1.19 -r1.20 src/sys/stand/efiboot/efiboot.c
cvs rdiff -u -r1.11 -r1.12 src/sys/stand/efiboot/efiboot.h
cvs rdiff -u -r1.5 -r1.6 src/sys/stand/efiboot/efienv.c
cvs rdiff -u -r1.2 -r1.3 src/sys/stand/efiboot/efienv.h
cvs rdiff -u -r1.16 -r1.17 src/sys/stand/efiboot/exec.c
cvs rdiff -u -r0 -r1.1 src/sys/stand/efiboot/overlay.c \
src/sys/stand/efiboot/overlay.h
cvs rdiff -u -r1.17 -r1.18 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.15 src/sys/stand/efiboot/Makefile.efiboot:1.16
--- src/sys/stand/efiboot/Makefile.efiboot:1.15	Sun Jun 21 23:53:26 2020
+++ src/sys/stand/efiboot/Makefile.efiboot	Fri Jun 26 03:23:04 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.15 2020/06/21 23:53:26 jmcneill Exp $
+# $NetBSD: Makefile.efiboot,v 1.16 2020/06/26 03:23:04 thorpej Exp $
 
 S=		${.CURDIR}/../../..
 
@@ -22,7 +22,7 @@ AFLAGS.start.S= ${${ACTIVE_CC} == "clang
 .PATH: ${EFIDIR}/gnuefi
 SOURCES=	crt0-efi-${GNUEFIARCH}.S reloc_${GNUEFIARCH}.c
 SOURCES+=	boot.c bootmenu.c conf.c console.c dev_net.c devopen.c exec.c \
-		module.c panic.c prompt.c
+		module.c overlay.c panic.c prompt.c
 SOURCES+=	efiboot.c efichar.c efidev.c efienv.c efigetsecs.c efifdt.c \
 		efifile.c efiblock.c efinet.c efipxe.c efiacpi.c efirng.c smbios.c
 

Index: src/sys/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.23 src/sys/stand/efiboot/boot.c:1.24
--- src/sys/stand/efiboot/boot.c:1.23	Sun Jun 21 23:53:26 2020
+++ src/sys/stand/efiboot/boot.c	Fri Jun 26 03:23:04 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.23 2020/06/21 23:53:26 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.24 2020/06/26 03:23:04 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -34,6 +34,7 @@
 #include "efienv.h"
 #include "efirng.h"
 #include "module.h"
+#include "overlay.h"
 #include "bootmenu.h"
 
 #include 
@@ -76,7 +77,6 @@ static const char *efi_memory_type[] = {
 static char default_device[32];
 static char initrd_path[255];
 static char dtb_path[255];
-static char efibootplist_path[255];
 static char netbsd_path[255];
 static char netbsd_args[255];
 static char rndseed_path[255];
@@ -90,9 +90,10 @@ int	set_bootargs(const char *);
 void	command_boot(char *);
 void	command_dev(char *);
 void	command_dtb(char *);
-void	command_plist(char *);
 void	command_initrd(char *);
 void	command_rndseed(char *);
+void	command_dtoverlay(char *);
+void	command_dtoverlays(char *);
 void	command_modules(char *);
 void	command_load(char *);
 void	command_unload(char *);
@@ -111,9 +112,10 @@ const struct boot_command commands[] = {
 	{ "boot",	command_boot,		"boot [dev:][filename] [args]\n (ex. \"hd0a:\\netbsd.old -s\"" },
 	{ "dev",	command_dev,		"dev" },
 	{ "dtb",	command_dtb,		"dtb [dev:][filename]" },
-	{ "plist",	command_plist,		"plist [dev:][filename]" },
 	{ "initrd",	command_initrd,		"initrd [dev:][filename]" },
 	{ "rndseed",	command_rndseed,	"rndseed [dev:][filename]" },
+	{ "dtoverlay",	command_dtoverlay,	"dtoverlay [dev:][filename]" },
+	{ "dtoverlays",	command_dtoverlays,	"dtoverlays [{on|off|reset}]" },
 	{ "modules",	command_modules,	"modules [{on|off|reset}]" },
 	{ "load",	command_load,		"load " },
 	{ "unload",	command_unload,		"unload " },
@@ -185,13 +187,6 @@ command_dtb(char *arg)
 }
 
 void
-command_plist(char *arg)
-{
-	if (set_efibootplist_path(arg) == 0)
-		load_efibootplist(false);
-}
-
-void
 command_initrd(char *arg)
 {
 	set_initrd_path(arg);
@@ -204,6 +199,37 @@ command_rndseed(char *arg)
 }
 
 void
+command_dtoverlays(char *arg)
+{
+	if (arg && *arg) {
+		if (strcmp(arg, "on") == 0)
+			dtoverlay_enable(1);
+		else if (strcmp(arg, "off") == 0)
+			dtoverlay_enable(0);
+		else if (strcmp(arg, "reset") == 0)
+			dtoverlay_remove_all();
+		else {
+			command_help("");
+			return;
+		}
+	} else {
+		printf("Device Tree overlays are %sabled\n",
+		dtoverlay_enabled ? "en" : "dis");
+	}
+}
+
+void

CVS commit: src/sys/stand/efiboot

2020-06-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Jun 21 23:53:26 UTC 2020

Modified Files:
src/sys/stand/efiboot: Makefile.efiboot boot.c efiboot.c version
Added Files:
src/sys/stand/efiboot: bootmenu.c bootmenu.h

Log Message:
Add boot.cfg support.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/stand/efiboot/Makefile.efiboot
cvs rdiff -u -r1.22 -r1.23 src/sys/stand/efiboot/boot.c
cvs rdiff -u -r0 -r1.1 src/sys/stand/efiboot/bootmenu.c \
src/sys/stand/efiboot/bootmenu.h
cvs rdiff -u -r1.18 -r1.19 src/sys/stand/efiboot/efiboot.c
cvs rdiff -u -r1.16 -r1.17 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.14 src/sys/stand/efiboot/Makefile.efiboot:1.15
--- src/sys/stand/efiboot/Makefile.efiboot:1.14	Sun Jun 21 17:24:26 2020
+++ src/sys/stand/efiboot/Makefile.efiboot	Sun Jun 21 23:53:26 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.14 2020/06/21 17:24:26 jmcneill Exp $
+# $NetBSD: Makefile.efiboot,v 1.15 2020/06/21 23:53:26 jmcneill Exp $
 
 S=		${.CURDIR}/../../..
 
@@ -21,8 +21,8 @@ AFLAGS.start.S= ${${ACTIVE_CC} == "clang
 
 .PATH: ${EFIDIR}/gnuefi
 SOURCES=	crt0-efi-${GNUEFIARCH}.S reloc_${GNUEFIARCH}.c
-SOURCES+=	boot.c conf.c console.c dev_net.c devopen.c exec.c module.c \
-		panic.c prompt.c
+SOURCES+=	boot.c bootmenu.c conf.c console.c dev_net.c devopen.c exec.c \
+		module.c panic.c prompt.c
 SOURCES+=	efiboot.c efichar.c efidev.c efienv.c efigetsecs.c efifdt.c \
 		efifile.c efiblock.c efinet.c efipxe.c efiacpi.c efirng.c smbios.c
 

Index: src/sys/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.22 src/sys/stand/efiboot/boot.c:1.23
--- src/sys/stand/efiboot/boot.c:1.22	Sun Jun 21 17:24:26 2020
+++ src/sys/stand/efiboot/boot.c	Sun Jun 21 23:53:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.22 2020/06/21 17:24:26 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.23 2020/06/21 23:53:26 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -34,12 +34,14 @@
 #include "efienv.h"
 #include "efirng.h"
 #include "module.h"
+#include "bootmenu.h"
 
 #include 
 #include 
 #include 
 
 #include 
+#include 
 
 extern const char bootprog_name[], bootprog_rev[], bootprog_kernrev[];
 
@@ -96,6 +98,7 @@ void	command_load(char *);
 void	command_unload(char *);
 void	command_ls(char *);
 void	command_mem(char *);
+void	command_menu(char *);
 void	command_printenv(char *);
 void	command_setenv(char *);
 void	command_clearenv(char *);
@@ -116,6 +119,7 @@ const struct boot_command commands[] = {
 	{ "unload",	command_unload,		"unload " },
 	{ "ls",		command_ls,		"ls [hdNn:/path]" },
 	{ "mem",	command_mem,		"mem" },
+	{ "menu",	command_menu,		"menu" },
 	{ "printenv",	command_printenv,	"printenv [key]" },
 	{ "setenv",	command_setenv,		"setenv  " },
 	{ "clearenv",	command_clearenv,	"clearenv " },
@@ -269,6 +273,17 @@ command_mem(char *arg)
 }
 
 void
+command_menu(char *arg)
+{
+	if (bootcfg_info.nummenu == 0) {
+		printf("No menu defined in boot.cfg\n");
+		return;
+	}
+
+	doboottypemenu();	/* Does not return */
+}
+
+void
 command_printenv(char *arg)
 {
 	char *val;
@@ -530,7 +545,20 @@ boot(void)
 	int currname, c;
 
 	read_env();
+
+	parsebootconf(BOOTCFG_FILENAME);
+
+	if (bootcfg_info.clear)
+		uefi_call_wrapper(ST->ConOut->ClearScreen, 1, ST->ConOut);
+
 	print_banner();
+
+	/* Display menu if configured */
+	twiddle_toggle = 1;
+	if (bootcfg_info.nummenu > 0) {
+		doboottypemenu();	/* No return */
+	}
+
 	printf("Press return to boot now, any other key for boot prompt\n");
 
 	if (netbsd_path[0] != '\0')

Index: src/sys/stand/efiboot/efiboot.c
diff -u src/sys/stand/efiboot/efiboot.c:1.18 src/sys/stand/efiboot/efiboot.c:1.19
--- src/sys/stand/efiboot/efiboot.c:1.18	Thu May 14 19:20:08 2020
+++ src/sys/stand/efiboot/efiboot.c	Sun Jun 21 23:53:26 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efiboot.c,v 1.18 2020/05/14 19:20:08 riastradh Exp $ */
+/* $NetBSD: efiboot.c,v 1.19 2020/06/21 23:53:26 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -72,7 +72,6 @@ efi_main(EFI_HANDLE imageHandle, EFI_SYS
 	uefi_call_wrapper(ST->ConOut->Reset, 2, ST->ConOut, TRUE);
 	uefi_call_wrapper(ST->ConOut->SetMode, 2, ST->ConOut, 0);
 	uefi_call_wrapper(ST->ConOut->EnableCursor, 2, ST->ConOut, TRUE);
-	uefi_call_wrapper(ST->ConOut->ClearScreen, 1, ST->ConOut);
 
 	status = uefi_call_wrapper(BS->AllocatePages, 4, AllocateAnyPages, EfiLoaderData, sz, _start);
 	if (EFI_ERROR(status))

Index: src/sys/stand/efiboot/version
diff -u src/sys/stand/efiboot/version:1.16 src/sys/stand/efiboot/version:1.17
--- src/sys/stand/efiboot/version:1.16	Sun Jun 21 17:24:26 2020
+++ src/sys/stand/efiboot/version	Sun Jun 21 23:53:26 2020
@@ -1,4 +1,4 @@
-$NetBSD: version,v 1.16 2020/06/21 17:24:26 jmcneill Exp $
+$NetBSD: version,v 1.17 2020/06/21 23:53:26 

CVS commit: src/sys/stand/efiboot

2020-06-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Jun 21 17:24:26 UTC 2020

Modified Files:
src/sys/stand/efiboot: Makefile.efiboot boot.c efifdt.c efifdt.h exec.c
version
src/sys/stand/efiboot/bootaa64: Makefile
src/sys/stand/efiboot/bootarm: Makefile
Added Files:
src/sys/stand/efiboot: module.c module.h

Log Message:
Add module support.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/stand/efiboot/Makefile.efiboot
cvs rdiff -u -r1.21 -r1.22 src/sys/stand/efiboot/boot.c
cvs rdiff -u -r1.23 -r1.24 src/sys/stand/efiboot/efifdt.c
cvs rdiff -u -r1.8 -r1.9 src/sys/stand/efiboot/efifdt.h
cvs rdiff -u -r1.15 -r1.16 src/sys/stand/efiboot/exec.c \
src/sys/stand/efiboot/version
cvs rdiff -u -r0 -r1.1 src/sys/stand/efiboot/module.c \
src/sys/stand/efiboot/module.h
cvs rdiff -u -r1.7 -r1.8 src/sys/stand/efiboot/bootaa64/Makefile
cvs rdiff -u -r1.4 -r1.5 src/sys/stand/efiboot/bootarm/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/stand/efiboot/Makefile.efiboot
diff -u src/sys/stand/efiboot/Makefile.efiboot:1.13 src/sys/stand/efiboot/Makefile.efiboot:1.14
--- src/sys/stand/efiboot/Makefile.efiboot:1.13	Thu May 14 19:19:08 2020
+++ src/sys/stand/efiboot/Makefile.efiboot	Sun Jun 21 17:24:26 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.13 2020/05/14 19:19:08 riastradh Exp $
+# $NetBSD: Makefile.efiboot,v 1.14 2020/06/21 17:24:26 jmcneill Exp $
 
 S=		${.CURDIR}/../../..
 
@@ -21,8 +21,10 @@ AFLAGS.start.S= ${${ACTIVE_CC} == "clang
 
 .PATH: ${EFIDIR}/gnuefi
 SOURCES=	crt0-efi-${GNUEFIARCH}.S reloc_${GNUEFIARCH}.c
-SOURCES+=	boot.c conf.c console.c dev_net.c devopen.c exec.c panic.c prompt.c
-SOURCES+=	efiboot.c efichar.c efidev.c efienv.c efigetsecs.c efifdt.c efifile.c efiblock.c efinet.c efipxe.c efiacpi.c efirng.c smbios.c
+SOURCES+=	boot.c conf.c console.c dev_net.c devopen.c exec.c module.c \
+		panic.c prompt.c
+SOURCES+=	efiboot.c efichar.c efidev.c efienv.c efigetsecs.c efifdt.c \
+		efifile.c efiblock.c efinet.c efipxe.c efiacpi.c efirng.c smbios.c
 
 .PATH: ${S}/external/bsd/libfdt/dist
 CPPFLAGS+=	-I${S}/external/bsd/libfdt/dist

Index: src/sys/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.21 src/sys/stand/efiboot/boot.c:1.22
--- src/sys/stand/efiboot/boot.c:1.21	Thu May 14 19:19:08 2020
+++ src/sys/stand/efiboot/boot.c	Sun Jun 21 17:24:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.21 2020/05/14 19:19:08 riastradh Exp $	*/
+/*	$NetBSD: boot.c,v 1.22 2020/06/21 17:24:26 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -33,6 +33,7 @@
 #include "efiacpi.h"
 #include "efienv.h"
 #include "efirng.h"
+#include "module.h"
 
 #include 
 #include 
@@ -90,6 +91,9 @@ void	command_dtb(char *);
 void	command_plist(char *);
 void	command_initrd(char *);
 void	command_rndseed(char *);
+void	command_modules(char *);
+void	command_load(char *);
+void	command_unload(char *);
 void	command_ls(char *);
 void	command_mem(char *);
 void	command_printenv(char *);
@@ -107,6 +111,9 @@ const struct boot_command commands[] = {
 	{ "plist",	command_plist,		"plist [dev:][filename]" },
 	{ "initrd",	command_initrd,		"initrd [dev:][filename]" },
 	{ "rndseed",	command_rndseed,	"rndseed [dev:][filename]" },
+	{ "modules",	command_modules,	"modules [{on|off|reset}]" },
+	{ "load",	command_load,		"load " },
+	{ "unload",	command_unload,		"unload " },
 	{ "ls",		command_ls,		"ls [hdNn:/path]" },
 	{ "mem",	command_mem,		"mem" },
 	{ "printenv",	command_printenv,	"printenv [key]" },
@@ -193,6 +200,47 @@ command_rndseed(char *arg)
 }
 
 void
+command_modules(char *arg)
+{
+	if (arg && *arg) {
+		if (strcmp(arg, "on") == 0)
+			module_enable(1);
+		else if (strcmp(arg, "off") == 0)
+			module_enable(0);
+		else if (strcmp(arg, "reset") == 0)
+			module_remove_all();
+		else {
+			command_help("");
+			return;
+		}
+	} else {
+		printf("modules are %sabled\n", module_enabled ? "en" : "dis");
+	}
+}
+
+void
+command_load(char *arg)
+{
+	if (!arg || !*arg) {
+		command_help("");
+		return;
+	}
+
+	module_add(arg);
+}
+
+void
+command_unload(char *arg)
+{
+	if (!arg || !*arg) {
+		command_help("");
+		return;
+	}
+
+	module_remove(arg);
+}
+
+void
 command_ls(char *arg)
 {
 	ls(arg);

Index: src/sys/stand/efiboot/efifdt.c
diff -u src/sys/stand/efiboot/efifdt.c:1.23 src/sys/stand/efiboot/efifdt.c:1.24
--- src/sys/stand/efiboot/efifdt.c:1.23	Thu May 14 19:21:53 2020
+++ src/sys/stand/efiboot/efifdt.c	Sun Jun 21 17:24:26 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.c,v 1.23 2020/05/14 19:21:53 riastradh Exp $ */
+/* $NetBSD: efifdt.c,v 1.24 2020/06/21 17:24:26 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -425,3 +425,18 @@ efi_fdt_efirng(u_long efirng_addr, u_lon
 	fdt_setprop_u64(fdt_data, chosen, "netbsd,efirng-end",
 	efirng_addr + efirng_size);
 }
+
+/* pass in module information */
+void

CVS commit: src/sys/stand/efiboot

2020-05-23 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat May 23 16:40:42 UTC 2020

Modified Files:
src/sys/stand/efiboot: exec.c

Log Message:
If a device tree overlay does not have a "compatible" match, don't
load it.  (Oops, missing return statement.)


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/stand/efiboot/exec.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/stand/efiboot/exec.c
diff -u src/sys/stand/efiboot/exec.c:1.14 src/sys/stand/efiboot/exec.c:1.15
--- src/sys/stand/efiboot/exec.c:1.14	Thu May 14 19:20:08 2020
+++ src/sys/stand/efiboot/exec.c	Sat May 23 16:40:41 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.c,v 1.14 2020/05/14 19:20:08 riastradh Exp $ */
+/* $NetBSD: exec.c,v 1.15 2020/05/23 16:40:41 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -199,6 +199,7 @@ apply_overlay(void *dtbo)
 
 	if (!efi_fdt_overlay_is_compatible(dtbo)) {
 		printf("boot: incompatible overlay\n");
+		return;
 	}
 
 	int fdterr;



CVS commit: src/sys/stand/efiboot

2020-05-14 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu May 14 23:09:29 UTC 2020

Modified Files:
src/sys/stand/efiboot: efirng.c

Log Message:
Make efi_rng_show return early if RNG protocol is not available. While
here, use efi_rng_available() consistently, prefix all show messages with
"RNG: ", and use sizeof(foo) instead of sizeof foo.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/stand/efiboot/efirng.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/stand/efiboot/efirng.c
diff -u src/sys/stand/efiboot/efirng.c:1.1 src/sys/stand/efiboot/efirng.c:1.2
--- src/sys/stand/efiboot/efirng.c:1.1	Thu May 14 19:19:08 2020
+++ src/sys/stand/efiboot/efirng.c	Thu May 14 23:09:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: efirng.c,v 1.1 2020/05/14 19:19:08 riastradh Exp $	*/
+/*	$NetBSD: efirng.c,v 1.2 2020/05/14 23:09:29 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -79,13 +79,16 @@ void
 efi_rng_show(void)
 {
 	EFI_RNG_ALGORITHM alglist[10];
-	UINTN i, j, alglistsz = sizeof alglist;
+	UINTN i, j, alglistsz = sizeof(alglist);
 	EFI_STATUS status;
 
+	if (!efi_rng_available())
+		return;
+
 	/* Query the list of supported algorithms.  */
 	status = uefi_call_wrapper(rng->GetInfo, 3, rng, , alglist);
 	if (EFI_ERROR(status)) {
-		Print(L"efirng: GetInfo: %r\n", status);
+		Print(L"RNG: GetInfo: %r\n", status);
 		return;
 	}
 
@@ -115,7 +118,7 @@ efi_rng(void *buf, UINTN len)
 {
 	EFI_STATUS status;
 
-	if (rng == NULL)
+	if (!efi_rng_available())
 		return EIO;
 
 	status = uefi_call_wrapper(rng->GetRNG, 3, rng, ,



CVS commit: src/sys/stand/efiboot

2020-05-14 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu May 14 19:25:16 UTC 2020

Modified Files:
src/sys/stand/efiboot: version

Log Message:
Bump efiboot version to note EFI RNG support.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 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/version
diff -u src/sys/stand/efiboot/version:1.14 src/sys/stand/efiboot/version:1.15
--- src/sys/stand/efiboot/version:1.14	Wed Dec 18 21:46:03 2019
+++ src/sys/stand/efiboot/version	Thu May 14 19:25:16 2020
@@ -1,4 +1,4 @@
-$NetBSD: version,v 1.14 2019/12/18 21:46:03 riastradh Exp $
+$NetBSD: version,v 1.15 2020/05/14 19:25:16 riastradh 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
@@ -18,3 +18,4 @@ is taken as the current.
 1.11:	Add full UEFI memory map to /chosen node.
 1.12:	Derive ACPI model string from SMBIOS.
 1.13:	Add rndseed support.
+1.14:	Add EFI RNG support.



CVS commit: src/sys/stand/efiboot

2020-05-14 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu May 14 19:21:53 UTC 2020

Modified Files:
src/sys/stand/efiboot: efifdt.c

Log Message:
Deduplicate lazy /chosen node creation logic.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/stand/efiboot/efifdt.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/stand/efiboot/efifdt.c
diff -u src/sys/stand/efiboot/efifdt.c:1.22 src/sys/stand/efiboot/efifdt.c:1.23
--- src/sys/stand/efiboot/efifdt.c:1.22	Thu May 14 19:20:08 2020
+++ src/sys/stand/efiboot/efifdt.c	Thu May 14 19:21:53 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.c,v 1.22 2020/05/14 19:20:08 riastradh Exp $ */
+/* $NetBSD: efifdt.c,v 1.23 2020/05/14 19:21:53 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -185,6 +185,22 @@ efi_fdt_show(void)
 	printf("]\n");
 }
 
+static int
+efi_fdt_chosen(void)
+{
+	int chosen;
+
+	chosen = fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH);
+	if (chosen < 0)
+		chosen = fdt_add_subnode(fdt_data,
+		fdt_path_offset(fdt_data, "/"),
+		FDT_CHOSEN_NODE_NAME);
+	if (chosen < 0)
+		panic("FDT: Failed to create " FDT_CHOSEN_NODE_PATH " node");
+
+	return chosen;
+}
+
 void
 efi_fdt_memory_map(void)
 {
@@ -200,11 +216,7 @@ efi_fdt_memory_map(void)
 	if (memory < 0)
 		panic("FDT: Failed to create " FDT_MEMORY_NODE_PATH " node");
 
-	chosen = fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH);
-	if (chosen < 0)
-		chosen = fdt_add_subnode(fdt_data, fdt_path_offset(fdt_data, "/"), FDT_CHOSEN_NODE_NAME);
-	if (chosen < 0)
-		panic("FDT: Failed to create " FDT_CHOSEN_NODE_PATH " node");
+	chosen = efi_fdt_chosen();
 
 	fdt_delprop(fdt_data, memory, "reg");
 
@@ -335,11 +347,7 @@ efi_fdt_bootargs(const char *bootargs)
 	uint8_t macaddr[6];
 	int chosen;
 
-	chosen = fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH);
-	if (chosen < 0)
-		chosen = fdt_add_subnode(fdt_data, fdt_path_offset(fdt_data, "/"), FDT_CHOSEN_NODE_NAME);
-	if (chosen < 0)
-		panic("FDT: Failed to create " FDT_CHOSEN_NODE_PATH " node");
+	chosen = efi_fdt_chosen();
 
 	if (*bootargs)
 		fdt_setprop_string(fdt_data, chosen, "bootargs", bootargs);
@@ -381,12 +389,7 @@ efi_fdt_initrd(u_long initrd_addr, u_lon
 	if (initrd_size == 0)
 		return;
 
-	chosen = fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH);
-	if (chosen < 0)
-		chosen = fdt_add_subnode(fdt_data, fdt_path_offset(fdt_data, "/"), FDT_CHOSEN_NODE_NAME);
-	if (chosen < 0)
-		panic("FDT: Failed to create " FDT_CHOSEN_NODE_PATH " node");
-
+	chosen = efi_fdt_chosen();
 	fdt_setprop_u64(fdt_data, chosen, "linux,initrd-start", initrd_addr);
 	fdt_setprop_u64(fdt_data, chosen, "linux,initrd-end", initrd_addr + initrd_size);
 }
@@ -400,14 +403,7 @@ efi_fdt_rndseed(u_long rndseed_addr, u_l
 	if (rndseed_size == 0)
 		return;
 
-	chosen = fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH);
-	if (chosen < 0)
-		chosen = fdt_add_subnode(fdt_data,
-		fdt_path_offset(fdt_data, "/"),
-		FDT_CHOSEN_NODE_NAME);
-	if (chosen < 0)
-		panic("FDT: Failed to create " FDT_CHOSEN_NODE_PATH " node");
-
+	chosen = efi_fdt_chosen();
 	fdt_setprop_u64(fdt_data, chosen, "netbsd,rndseed-start",
 	rndseed_addr);
 	fdt_setprop_u64(fdt_data, chosen, "netbsd,rndseed-end",
@@ -423,14 +419,7 @@ efi_fdt_efirng(u_long efirng_addr, u_lon
 	if (efirng_size == 0)
 		return;
 
-	chosen = fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH);
-	if (chosen < 0)
-		chosen = fdt_add_subnode(fdt_data,
-		fdt_path_offset(fdt_data, "/"),
-		FDT_CHOSEN_NODE_NAME);
-	if (chosen < 0)
-		panic("FDT: Failed to create " FDT_CHOSEN_NODE_PATH " node");
-
+	chosen = efi_fdt_chosen();
 	fdt_setprop_u64(fdt_data, chosen, "netbsd,efirng-start",
 	efirng_addr);
 	fdt_setprop_u64(fdt_data, chosen, "netbsd,efirng-end",



CVS commit: src/sys/stand/efiboot

2020-05-14 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu May 14 19:20:08 UTC 2020

Modified Files:
src/sys/stand/efiboot: efiboot.c efifdt.c efifdt.h exec.c

Log Message:
Pass EFI RNG output via /chosen/netbsd,efirng-{start,end}.

This is separate from /chosen/netbsd,rndseed-{start,end}, which
specifies NetBSD's persistent on-disk seed; efirng is the firmware's
RNG device.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/stand/efiboot/efiboot.c
cvs rdiff -u -r1.21 -r1.22 src/sys/stand/efiboot/efifdt.c
cvs rdiff -u -r1.7 -r1.8 src/sys/stand/efiboot/efifdt.h
cvs rdiff -u -r1.13 -r1.14 src/sys/stand/efiboot/exec.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/stand/efiboot/efiboot.c
diff -u src/sys/stand/efiboot/efiboot.c:1.17 src/sys/stand/efiboot/efiboot.c:1.18
--- src/sys/stand/efiboot/efiboot.c:1.17	Thu Sep 26 14:28:14 2019
+++ src/sys/stand/efiboot/efiboot.c	Thu May 14 19:20:08 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efiboot.c,v 1.17 2019/09/26 14:28:14 jmcneill Exp $ */
+/* $NetBSD: efiboot.c,v 1.18 2020/05/14 19:20:08 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -31,6 +31,7 @@
 #include "efiblock.h"
 #include "efifdt.h"
 #include "efiacpi.h"
+#include "efirng.h"
 
 #include 
 
@@ -99,6 +100,7 @@ efi_main(EFI_HANDLE imageHandle, EFI_SYS
 	efi_net_probe();
 	efi_file_system_probe();
 	efi_block_probe();
+	efi_rng_probe();
 
 	boot();
 

Index: src/sys/stand/efiboot/efifdt.c
diff -u src/sys/stand/efiboot/efifdt.c:1.21 src/sys/stand/efiboot/efifdt.c:1.22
--- src/sys/stand/efiboot/efifdt.c:1.21	Fri Jan  3 14:14:56 2020
+++ src/sys/stand/efiboot/efifdt.c	Thu May 14 19:20:08 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.c,v 1.21 2020/01/03 14:14:56 skrll Exp $ */
+/* $NetBSD: efifdt.c,v 1.22 2020/05/14 19:20:08 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -391,6 +391,7 @@ efi_fdt_initrd(u_long initrd_addr, u_lon
 	fdt_setprop_u64(fdt_data, chosen, "linux,initrd-end", initrd_addr + initrd_size);
 }
 
+/* pass in the NetBSD on-disk random seed */
 void
 efi_fdt_rndseed(u_long rndseed_addr, u_long rndseed_size)
 {
@@ -412,3 +413,26 @@ efi_fdt_rndseed(u_long rndseed_addr, u_l
 	fdt_setprop_u64(fdt_data, chosen, "netbsd,rndseed-end",
 	rndseed_addr + rndseed_size);
 }
+
+/* pass in output from the EFI firmware's RNG from some unknown source */
+void
+efi_fdt_efirng(u_long efirng_addr, u_long efirng_size)
+{
+	int chosen;
+
+	if (efirng_size == 0)
+		return;
+
+	chosen = fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH);
+	if (chosen < 0)
+		chosen = fdt_add_subnode(fdt_data,
+		fdt_path_offset(fdt_data, "/"),
+		FDT_CHOSEN_NODE_NAME);
+	if (chosen < 0)
+		panic("FDT: Failed to create " FDT_CHOSEN_NODE_PATH " node");
+
+	fdt_setprop_u64(fdt_data, chosen, "netbsd,efirng-start",
+	efirng_addr);
+	fdt_setprop_u64(fdt_data, chosen, "netbsd,efirng-end",
+	efirng_addr + efirng_size);
+}

Index: src/sys/stand/efiboot/efifdt.h
diff -u src/sys/stand/efiboot/efifdt.h:1.7 src/sys/stand/efiboot/efifdt.h:1.8
--- src/sys/stand/efiboot/efifdt.h:1.7	Wed Dec 18 21:46:03 2019
+++ src/sys/stand/efiboot/efifdt.h	Thu May 14 19:20:08 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.h,v 1.7 2019/12/18 21:46:03 riastradh Exp $ */
+/* $NetBSD: efifdt.h,v 1.8 2020/05/14 19:20:08 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -38,5 +38,6 @@ void efi_fdt_show(void);
 void efi_fdt_bootargs(const char *);
 void efi_fdt_initrd(u_long, u_long);
 void efi_fdt_rndseed(u_long, u_long);
+void efi_fdt_efirng(u_long, u_long);
 void efi_fdt_init(u_long, u_long);
 void efi_fdt_fini(void);

Index: src/sys/stand/efiboot/exec.c
diff -u src/sys/stand/efiboot/exec.c:1.13 src/sys/stand/efiboot/exec.c:1.14
--- src/sys/stand/efiboot/exec.c:1.13	Sat Jan 25 10:53:13 2020
+++ src/sys/stand/efiboot/exec.c	Thu May 14 19:20:08 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.c,v 1.13 2020/01/25 10:53:13 jmcneill Exp $ */
+/* $NetBSD: exec.c,v 1.14 2020/05/14 19:20:08 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -31,6 +31,7 @@
 #include "efienv.h"
 #include "efifdt.h"
 #include "efiacpi.h"
+#include "efirng.h"
 
 #include 
 
@@ -41,8 +42,8 @@ u_long load_offset = 0;
 #define	FDT_SPACE	(4 * 1024 * 1024)
 #define	FDT_ALIGN	((2 * 1024 * 1024) - 1)
 
-static EFI_PHYSICAL_ADDRESS initrd_addr, dtb_addr, rndseed_addr;
-static u_long initrd_size = 0, dtb_size = 0, rndseed_size = 0;
+static EFI_PHYSICAL_ADDRESS initrd_addr, dtb_addr, rndseed_addr, efirng_addr;
+static u_long initrd_size = 0, dtb_size = 0, rndseed_size = 0, efirng_size = 0;
 
 static int
 load_file(const char *path, u_long extra, bool quiet_errors,
@@ -273,6 +274,47 @@ load_fdt_overlays(void)
 	prop_object_iterator_release(iter);
 }
 
+static void
+generate_efirng(void)
+{
+	EFI_PHYSICAL_ADDRESS addr;
+	u_long size = EFI_PAGE_SIZE;
+	EFI_STATUS status;
+
+	/* Check whether the RNG is available 

CVS commit: src/sys/stand/efiboot

2020-05-14 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu May 14 19:19:08 UTC 2020

Modified Files:
src/sys/stand/efiboot: Makefile.efiboot boot.c efiacpi.c
Added Files:
src/sys/stand/efiboot: efirng.c efirng.h

Log Message:
Draft logic to get at EFI RNG.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/stand/efiboot/Makefile.efiboot
cvs rdiff -u -r1.20 -r1.21 src/sys/stand/efiboot/boot.c
cvs rdiff -u -r1.6 -r1.7 src/sys/stand/efiboot/efiacpi.c
cvs rdiff -u -r0 -r1.1 src/sys/stand/efiboot/efirng.c \
src/sys/stand/efiboot/efirng.h

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.12 src/sys/stand/efiboot/Makefile.efiboot:1.13
--- src/sys/stand/efiboot/Makefile.efiboot:1.12	Sun Apr 26 06:51:35 2020
+++ src/sys/stand/efiboot/Makefile.efiboot	Thu May 14 19:19:08 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.12 2020/04/26 06:51:35 rin Exp $
+# $NetBSD: Makefile.efiboot,v 1.13 2020/05/14 19:19:08 riastradh Exp $
 
 S=		${.CURDIR}/../../..
 
@@ -22,7 +22,7 @@ AFLAGS.start.S= ${${ACTIVE_CC} == "clang
 .PATH: ${EFIDIR}/gnuefi
 SOURCES=	crt0-efi-${GNUEFIARCH}.S reloc_${GNUEFIARCH}.c
 SOURCES+=	boot.c conf.c console.c dev_net.c devopen.c exec.c panic.c prompt.c
-SOURCES+=	efiboot.c efichar.c efidev.c efienv.c efigetsecs.c efifdt.c efifile.c efiblock.c efinet.c efipxe.c efiacpi.c smbios.c
+SOURCES+=	efiboot.c efichar.c efidev.c efienv.c efigetsecs.c efifdt.c efifile.c efiblock.c efinet.c efipxe.c efiacpi.c efirng.c smbios.c
 
 .PATH: ${S}/external/bsd/libfdt/dist
 CPPFLAGS+=	-I${S}/external/bsd/libfdt/dist

Index: src/sys/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.20 src/sys/stand/efiboot/boot.c:1.21
--- src/sys/stand/efiboot/boot.c:1.20	Sat Jan 25 11:24:20 2020
+++ src/sys/stand/efiboot/boot.c	Thu May 14 19:19:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.20 2020/01/25 11:24:20 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.21 2020/05/14 19:19:08 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -32,6 +32,7 @@
 #include "efifdt.h"
 #include "efiacpi.h"
 #include "efienv.h"
+#include "efirng.h"
 
 #include 
 #include 
@@ -285,6 +286,7 @@ command_version(char *arg)
 
 	efi_fdt_show();
 	efi_acpi_show();
+	efi_rng_show();
 }
 
 void

Index: src/sys/stand/efiboot/efiacpi.c
diff -u src/sys/stand/efiboot/efiacpi.c:1.6 src/sys/stand/efiboot/efiacpi.c:1.7
--- src/sys/stand/efiboot/efiacpi.c:1.6	Sat Jan 25 11:24:20 2020
+++ src/sys/stand/efiboot/efiacpi.c	Thu May 14 19:19:08 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efiacpi.c,v 1.6 2020/01/25 11:24:20 jmcneill Exp $ */
+/* $NetBSD: efiacpi.c,v 1.7 2020/05/14 19:19:08 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -124,7 +124,7 @@ efi_acpi_show(void)
 	rsdp->oemid[3], rsdp->oemid[4], rsdp->oemid[5]);
 
 	if (smbios3_table)
-		printf("SMBIOS: %s", efi_acpi_get_model());
+		printf("SMBIOS: %s\n", efi_acpi_get_model());
 }
 
 int

Added files:

Index: src/sys/stand/efiboot/efirng.c
diff -u /dev/null src/sys/stand/efiboot/efirng.c:1.1
--- /dev/null	Thu May 14 19:19:08 2020
+++ src/sys/stand/efiboot/efirng.c	Thu May 14 19:19:08 2020
@@ -0,0 +1,136 @@
+/*	$NetBSD: efirng.c,v 1.1 2020/05/14 19:19:08 riastradh Exp $	*/
+
+/*-
+ * Copyright (c) 2020 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * UEFI Forum, Inc.: UEFI Specification, Version 2.8 Errata A, February
+ * 2020, Sec. 37.5 EFI Random Number Generator Protocol, pp. 2158--2162
+ * 

CVS commit: src/sys/stand/efiboot

2020-04-26 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sun Apr 26 06:51:35 UTC 2020

Modified Files:
src/sys/stand/efiboot: Makefile.efiboot

Log Message:
Adjust for binutils 2.34 in the same manner as efiboot/x86:
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/arch/i386/stand/efiboot/Makefile.efiboot#rev1.17


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/stand/efiboot/Makefile.efiboot

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.11 src/sys/stand/efiboot/Makefile.efiboot:1.12
--- src/sys/stand/efiboot/Makefile.efiboot:1.11	Wed Apr  1 10:45:44 2020
+++ src/sys/stand/efiboot/Makefile.efiboot	Sun Apr 26 06:51:35 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.11 2020/04/01 10:45:44 tnn Exp $
+# $NetBSD: Makefile.efiboot,v 1.12 2020/04/26 06:51:35 rin Exp $
 
 S=		${.CURDIR}/../../..
 
@@ -47,6 +47,7 @@ BINMODE=444
 .PATH:	${.CURDIR} ${.CURDIR}/..
 .PATH:	${.CURDIR}/../../lib
 
+LDFLAGS+= --no-dynamic-linker --noinhibit-exec
 LDFLAGS+= -nostdlib -T${LDSCRIPT} -Bsymbolic -shared
 CPPFLAGS+= -I$S -I${.CURDIR} -I${.CURDIR}/../common -I$S/lib/libsa
 CPPFLAGS+= -I${.OBJDIR}



CVS commit: src/sys/stand/efiboot

2020-04-01 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Wed Apr  1 10:45:44 UTC 2020

Modified Files:
src/sys/stand/efiboot: Makefile.efiboot

Log Message:
efiboot: add clang fix from i386/stand/efiboot/bootx64/Makefile here too


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/stand/efiboot/Makefile.efiboot

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.10 src/sys/stand/efiboot/Makefile.efiboot:1.11
--- src/sys/stand/efiboot/Makefile.efiboot:1.10	Sat Jan 25 11:24:20 2020
+++ src/sys/stand/efiboot/Makefile.efiboot	Wed Apr  1 10:45:44 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.10 2020/01/25 11:24:20 jmcneill Exp $
+# $NetBSD: Makefile.efiboot,v 1.11 2020/04/01 10:45:44 tnn Exp $
 
 S=		${.CURDIR}/../../..
 
@@ -87,6 +87,11 @@ CPPFLAGS+= -DLIBSA_ENABLE_LS_OP
 #CPPFLAGS+= -DRARP_DEBUG
 #CPPFLAGS+= -DRPC_DEBUG
 
+# Follow the suit of Makefile.kern.inc; needed for the lfs64 union
+# accessors -- they don't actually dereference the resulting pointer,
+# just use it for type-checking.
+CWARNFLAGS.clang+=	-Wno-error=address-of-packed-member
+
 SAMISCCPPFLAGS+= -DLIBSA_PRINTF_LONGLONG_SUPPORT
 SAMISCCPPFLAGS+= -DLIBSA_PRINTF_WIDTH_SUPPORT
 SAMISCCPPFLAGS+= -D"cdb2devb(bno)=(bno)"



CVS commit: src/sys/stand/efiboot

2020-01-25 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jan 25 11:24:20 UTC 2020

Modified Files:
src/sys/stand/efiboot: Makefile.efiboot boot.c efiacpi.c
src/sys/stand/efiboot/bootaa64: Makefile
src/sys/stand/efiboot/bootarm: Makefile

Log Message:
Clean up the banner so it fits in 80 columns and add some extra details
to the "version" command output.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/stand/efiboot/Makefile.efiboot
cvs rdiff -u -r1.19 -r1.20 src/sys/stand/efiboot/boot.c
cvs rdiff -u -r1.5 -r1.6 src/sys/stand/efiboot/efiacpi.c
cvs rdiff -u -r1.6 -r1.7 src/sys/stand/efiboot/bootaa64/Makefile
cvs rdiff -u -r1.3 -r1.4 src/sys/stand/efiboot/bootarm/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/stand/efiboot/Makefile.efiboot
diff -u src/sys/stand/efiboot/Makefile.efiboot:1.9 src/sys/stand/efiboot/Makefile.efiboot:1.10
--- src/sys/stand/efiboot/Makefile.efiboot:1.9	Sat Nov 30 13:02:18 2019
+++ src/sys/stand/efiboot/Makefile.efiboot	Sat Jan 25 11:24:20 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.9 2019/11/30 13:02:18 jmcneill Exp $
+# $NetBSD: Makefile.efiboot,v 1.10 2020/01/25 11:24:20 jmcneill Exp $
 
 S=		${.CURDIR}/../../..
 
@@ -8,7 +8,7 @@ NOLIBCSANITIZER=# defined
 NOSANITIZER=	# defined
 NORELRO=	# defined
 PROG?=		boot.efi
-NEWVERSWHAT?=	"EFI Boot"
+NEWVERSWHAT?=	"efiboot"
 
 EFIDIR= ${S}/external/bsd/gnu-efi/dist
 GNUEFIARCH?= ${MACHINE_CPU}

Index: src/sys/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.19 src/sys/stand/efiboot/boot.c:1.20
--- src/sys/stand/efiboot/boot.c:1.19	Wed Dec 18 21:46:03 2019
+++ src/sys/stand/efiboot/boot.c	Sat Jan 25 11:24:20 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.19 2019/12/18 21:46:03 riastradh Exp $	*/
+/*	$NetBSD: boot.c,v 1.20 2020/01/25 11:24:20 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -115,6 +115,7 @@ const struct boot_command commands[] = {
 	{ "reboot",	command_reset,		"reboot|reset" },
 	{ "reset",	command_reset,		NULL },
 	{ "version",	command_version,	"version" },
+	{ "ver",	command_version,	NULL },
 	{ "help",	command_help,		"help|?" },
 	{ "?",		command_help,		NULL },
 	{ "quit",	command_quit,		"quit" },
@@ -271,12 +272,13 @@ command_version(char *arg)
 	char *ufirmware;
 	int rv;
 
-	printf("EFI version: %d.%02d\n",
+	printf("Version: %s (%s)\n", bootprog_rev, bootprog_kernrev);
+	printf("EFI: %d.%02d\n",
 	ST->Hdr.Revision >> 16, ST->Hdr.Revision & 0x);
 	ufirmware = NULL;
 	rv = ucs2_to_utf8(ST->FirmwareVendor, );
 	if (rv == 0) {
-		printf("EFI Firmware: %s (rev 0x%x)\n", ufirmware,
+		printf("Firmware: %s (rev 0x%x)\n", ufirmware,
 		ST->FirmwareRevision);
 		FreePool(ufirmware);
 	}
@@ -393,8 +395,8 @@ void
 print_banner(void)
 {
 	printf("\n\n"
-	">> %s, Revision %s (from NetBSD %s)\n",
-	bootprog_name, bootprog_rev, bootprog_kernrev);
+	">> %s, Revision %s\n",
+	bootprog_name, bootprog_rev);
 }
 
 static void

Index: src/sys/stand/efiboot/efiacpi.c
diff -u src/sys/stand/efiboot/efiacpi.c:1.5 src/sys/stand/efiboot/efiacpi.c:1.6
--- src/sys/stand/efiboot/efiacpi.c:1.5	Sat Nov 30 13:02:18 2019
+++ src/sys/stand/efiboot/efiacpi.c	Sat Jan 25 11:24:20 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efiacpi.c,v 1.5 2019/11/30 13:02:18 jmcneill Exp $ */
+/* $NetBSD: efiacpi.c,v 1.6 2020/01/25 11:24:20 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -34,6 +34,18 @@
 #include "efifdt.h"
 #include "smbios.h"
 
+struct acpi_rdsp {
+	char signature[8];
+	uint8_t checksum;
+	char oemid[6];
+	uint8_t revision;
+	uint32_t rsdtphys;
+	uint32_t length;
+	uint64_t xsdtphys;
+	uint8_t extcsum;
+	uint8_t reserved[3];
+};
+
 #include 
 
 #define	ACPI_FDT_SIZE	(128 * 1024)
@@ -66,18 +78,6 @@ efi_acpi_available(void)
 	return acpi_root != NULL;
 }
 
-void
-efi_acpi_show(void)
-{
-	if (!efi_acpi_available())
-		return;
-
-	printf("ACPI: RSDP %p", acpi_root);
-	if (smbios3_table)
-		printf(", SMBIOS %p", smbios3_table);
-	printf("\n");
-}
-
 static char model_buf[128];
 
 static const char *
@@ -111,6 +111,22 @@ efi_acpi_get_model(void)
 	return model_buf;
 }
 
+void
+efi_acpi_show(void)
+{
+	struct acpi_rdsp *rsdp = acpi_root;
+
+	if (!efi_acpi_available())
+		return;
+
+	printf("ACPI: v%02d %c%c%c%c%c%c\n", rsdp->revision,
+	rsdp->oemid[0], rsdp->oemid[1], rsdp->oemid[2],
+	rsdp->oemid[3], rsdp->oemid[4], rsdp->oemid[5]);
+
+	if (smbios3_table)
+		printf("SMBIOS: %s", efi_acpi_get_model());
+}
+
 int
 efi_acpi_create_fdt(void)
 {

Index: src/sys/stand/efiboot/bootaa64/Makefile
diff -u src/sys/stand/efiboot/bootaa64/Makefile:1.6 src/sys/stand/efiboot/bootaa64/Makefile:1.7
--- src/sys/stand/efiboot/bootaa64/Makefile:1.6	Mon Sep 23 13:42:37 2019
+++ src/sys/stand/efiboot/bootaa64/Makefile	Sat Jan 25 11:24:20 2020
@@ -1,8 +1,8 @@
-# $NetBSD: Makefile,v 1.6 2019/09/23 13:42:37 christos Exp $
+# 

CVS commit: src/sys/stand/efiboot

2020-01-25 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jan 25 10:53:13 UTC 2020

Modified Files:
src/sys/stand/efiboot: exec.c

Log Message:
Hide the twiddle while loading efiboot plist


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/stand/efiboot/exec.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/stand/efiboot/exec.c
diff -u src/sys/stand/efiboot/exec.c:1.12 src/sys/stand/efiboot/exec.c:1.13
--- src/sys/stand/efiboot/exec.c:1.12	Wed Dec 18 21:46:03 2019
+++ src/sys/stand/efiboot/exec.c	Sat Jan 25 10:53:13 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.c,v 1.12 2019/12/18 21:46:03 riastradh Exp $ */
+/* $NetBSD: exec.c,v 1.13 2020/01/25 10:53:13 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -34,6 +34,8 @@
 
 #include 
 
+extern char twiddle_toggle;
+
 u_long load_offset = 0;
 
 #define	FDT_SPACE	(4 * 1024 * 1024)
@@ -127,6 +129,7 @@ load_efibootplist(bool default_fallback)
 	u_long plist_size = 0;
 	prop_dictionary_t plist = NULL, oplist = NULL;
 	bool load_quietly = false;
+	bool old_twiddle_toggle = twiddle_toggle;
 
 	const char *path = get_efibootplist_path();
 	if (path == NULL || strlen(path) == 0) {
@@ -136,6 +139,8 @@ load_efibootplist(bool default_fallback)
 		load_quietly = true;
 	}
 
+	twiddle_toggle = load_quietly;
+
 	/*
 	 * Fudge the size so we can ensure the resulting buffer
 	 * is NUL-terminated for convenience.
@@ -157,6 +162,8 @@ load_efibootplist(bool default_fallback)
 out:
 	oplist = efibootplist;
 
+	twiddle_toggle = old_twiddle_toggle;
+
 	/*
 	 * If we had a failure, create an empty one for
 	 * convenience.  But a failure should not clobber



CVS commit: src/sys/stand/efiboot

2020-01-25 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jan 25 10:09:46 UTC 2020

Modified Files:
src/sys/stand/efiboot: prompt.c

Log Message:
Fix for disappearing counters on graphics consoles


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/stand/efiboot/prompt.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/stand/efiboot/prompt.c
diff -u src/sys/stand/efiboot/prompt.c:1.5 src/sys/stand/efiboot/prompt.c:1.6
--- src/sys/stand/efiboot/prompt.c:1.5	Sun Sep 29 00:52:26 2019
+++ src/sys/stand/efiboot/prompt.c	Sat Jan 25 10:09:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: prompt.c,v 1.5 2019/09/29 00:52:26 jakllsch Exp $	*/
+/*	$NetBSD: prompt.c,v 1.6 2020/01/25 10:09:46 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997
@@ -75,23 +75,27 @@ awaitkey(int timeout, int tell)
 {
 	int i = timeout * POLL_FREQ;
 	int last_secs = -1, secs;
+	int last_len = -1, n;
+	char buf[32];
 	char c = 0;
 
 	for (;;) {
 		if (tell) {
-			char buf[32];
 			int len;
 
 			secs = (i + POLL_FREQ - 1) / POLL_FREQ;
 			if (secs != last_secs) {
-len = snprintf(buf, sizeof(buf), "%d seconds. ", (i + POLL_FREQ - 1) / POLL_FREQ);
-if (len > 0 && len < sizeof(buf)) {
+if (last_len != -1) {
 	char *p = buf;
-	printf("%s", buf);
-	while (*p)
+	for (n = 0; n < last_len; n++)
 		*p++ = '\b';
+	*p = '\0';
 	printf("%s", buf);
 }
+len = snprintf(buf, sizeof(buf), "%d seconds. ", (i + POLL_FREQ - 1) / POLL_FREQ);
+if (len > 0 && len < sizeof(buf))
+	printf("%s", buf);
+last_len = len;
 last_secs = secs;
 			}
 		}
@@ -109,8 +113,16 @@ awaitkey(int timeout, int tell)
 	}
 
 out:
-	if (tell)
+	if (tell) {
+		if (last_len != -1) {
+			char *p = buf;
+			for (n = 0; n < last_len; n++)
+*p++ = '\b';
+			*p = '\0';
+			printf("%s", buf);
+		}
 		printf("0 seconds. \n");
+	}
 
 	return c;
 }



CVS commit: src/sys/stand/efiboot

2020-01-03 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Jan  3 14:14:56 UTC 2020

Modified Files:
src/sys/stand/efiboot: efifdt.c

Log Message:
Fix EFIBOOT_DEBUG build on arm


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/stand/efiboot/efifdt.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/stand/efiboot/efifdt.c
diff -u src/sys/stand/efiboot/efifdt.c:1.20 src/sys/stand/efiboot/efifdt.c:1.21
--- src/sys/stand/efiboot/efifdt.c:1.20	Wed Dec 18 21:46:03 2019
+++ src/sys/stand/efiboot/efifdt.c	Fri Jan  3 14:14:56 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.c,v 1.20 2019/12/18 21:46:03 riastradh Exp $ */
+/* $NetBSD: efifdt.c,v 1.21 2020/01/03 14:14:56 skrll Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -47,6 +47,13 @@ static EFI_GUID FdtTableGuid = FDT_TABLE
 	 (_md)->Type == EfiBootServicesCode || (_md)->Type == EfiBootServicesData || \
 	 (_md)->Type == EfiConventionalMemory)
 
+#ifdef _LP64
+#define PRIdUINTN "ld"
+#define PRIxUINTN "lx"
+#else
+#define PRIdUINTN "d"
+#define PRIxUINTN "x"
+#endif
 static void *fdt_data = NULL;
 
 int
@@ -275,7 +282,7 @@ efi_fdt_gop(void)
 			continue;
 
 #ifdef EFIBOOT_DEBUG
-		printf("GOP: FB @ 0x%lx size 0x%lx\n", mode->FrameBufferBase, mode->FrameBufferSize);
+		printf("GOP: FB @ 0x%" PRIx64 " size 0x%" PRIxUINTN "\n", mode->FrameBufferBase, mode->FrameBufferSize);
 		printf("GOP: Version %d\n", mode->Info->Version);
 		printf("GOP: HRes %d VRes %d\n", mode->Info->HorizontalResolution, mode->Info->VerticalResolution);
 		printf("GOP: PixelFormat %d\n", mode->Info->PixelFormat);



CVS commit: src/sys/stand/efiboot/bootarm

2020-01-03 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Jan  3 11:44:33 UTC 2020

Modified Files:
src/sys/stand/efiboot/bootarm: Makefile

Log Message:
Add -mfloat-abi=soft so that gcc 8 doesn't emit FP instructions.  This
fixes bootarm.efi compiled by gcc 8.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/stand/efiboot/bootarm/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/stand/efiboot/bootarm/Makefile
diff -u src/sys/stand/efiboot/bootarm/Makefile:1.2 src/sys/stand/efiboot/bootarm/Makefile:1.3
--- src/sys/stand/efiboot/bootarm/Makefile:1.2	Mon Sep 23 13:42:37 2019
+++ src/sys/stand/efiboot/bootarm/Makefile	Fri Jan  3 11:44:33 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.2 2019/09/23 13:42:37 christos Exp $
+# $NetBSD: Makefile,v 1.3 2020/01/03 11:44:33 skrll Exp $
 
 PROG=		bootarm.efi
 OBJFMT=		binary
@@ -9,7 +9,7 @@ LIBGNUEFI_ARCH=	arm
 EXTRA_SOURCES=	efibootarm.c
 EXTRA_SOURCES+=	cache.S
 
-COPTS+=		-mno-unaligned-access -ffreestanding -fno-unwind-tables
+COPTS+=		-mfloat-abi=soft -mno-unaligned-access -ffreestanding -fno-unwind-tables
 CFLAGS+=	-DEFIBOOT_ALIGN=0x100
 LDFLAGS+=	-N
 



CVS commit: src/sys/stand/efiboot

2019-04-21 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Apr 21 22:30:41 UTC 2019

Modified Files:
src/sys/stand/efiboot: Makefile.efiboot boot.c efiboot.c efiboot.h
efienv.c efienv.h efifdt.c efifdt.h exec.c version

Log Message:
- Add support for a boot configuration file, defaulting to /etc/efiboot.plist.
- Add support for pre-loading EFI environment variables from efiboot.plist.
- Add support for device tree overlays specified in efiboot.plist.

(Man page for efiboot forthcoming.)


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/stand/efiboot/Makefile.efiboot
cvs rdiff -u -r1.17 -r1.18 src/sys/stand/efiboot/boot.c
cvs rdiff -u -r1.15 -r1.16 src/sys/stand/efiboot/efiboot.c
cvs rdiff -u -r1.9 -r1.10 src/sys/stand/efiboot/efiboot.h \
src/sys/stand/efiboot/exec.c src/sys/stand/efiboot/version
cvs rdiff -u -r1.3 -r1.4 src/sys/stand/efiboot/efienv.c
cvs rdiff -u -r1.1 -r1.2 src/sys/stand/efiboot/efienv.h
cvs rdiff -u -r1.14 -r1.15 src/sys/stand/efiboot/efifdt.c
cvs rdiff -u -r1.4 -r1.5 src/sys/stand/efiboot/efifdt.h

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.6 src/sys/stand/efiboot/Makefile.efiboot:1.7
--- src/sys/stand/efiboot/Makefile.efiboot:1.6	Fri Oct 12 22:08:04 2018
+++ src/sys/stand/efiboot/Makefile.efiboot	Sun Apr 21 22:30:41 2019
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.6 2018/10/12 22:08:04 jmcneill Exp $
+# $NetBSD: Makefile.efiboot,v 1.7 2019/04/21 22:30:41 thorpej Exp $
 
 S=		${.CURDIR}/../../..
 
@@ -26,7 +26,7 @@ SOURCES+=	efiboot.c efichar.c efidev.c e
 
 .PATH: ${S}/external/bsd/libfdt/dist
 CPPFLAGS+=	-I${S}/external/bsd/libfdt/dist
-SOURCES+=	fdt.c fdt_addresses.c fdt_empty_tree.c
+SOURCES+=	fdt.c fdt_addresses.c fdt_empty_tree.c fdt_overlay.c
 SOURCES+=	fdt_ro.c fdt_rw.c fdt_strerror.c fdt_sw.c fdt_wip.c
 
 SRCS= ${SOURCES} ${EXTRA_SOURCES}
@@ -51,6 +51,7 @@ LDFLAGS+= -nostdlib -T${LDSCRIPT} -Bsymb
 CPPFLAGS+= -I$S -I${.CURDIR} -I${.CURDIR}/../common -I$S/lib/libsa
 CPPFLAGS+= -I${.OBJDIR}
 CPPFLAGS+= -I${.CURDIR}/../../lib
+CPPFLAGS+= -I${S}/../common/include
 
 COPTS+=	-fpic -g -O2
 COPTS+=	-fshort-wchar -fno-strict-aliasing
@@ -77,6 +78,7 @@ CPPFLAGS+= -DSUPPORT_DHCP
 CPPFLAGS+= -DSUPPORT_TFTP
 CPPFLAGS+= -DLIBSA_ENABLE_LS_OP
 
+#CPPFLAGS+= -DEFIBOOT_DEBUG
 #CPPFLAGS+= -DARP_DEBUG
 #CPPFLAGS+= -DBOOTP_DEBUG
 #CPPFLAGS+= -DNET_DEBUG

Index: src/sys/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.17 src/sys/stand/efiboot/boot.c:1.18
--- src/sys/stand/efiboot/boot.c:1.17	Sat Apr 20 11:28:53 2019
+++ src/sys/stand/efiboot/boot.c	Sun Apr 21 22:30:41 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.17 2019/04/20 11:28:53 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.18 2019/04/21 22:30:41 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -72,6 +72,7 @@ static const char *efi_memory_type[] = {
 static char default_device[32];
 static char initrd_path[255];
 static char dtb_path[255];
+static char efibootplist_path[255];
 static char netbsd_path[255];
 static char netbsd_args[255];
 
@@ -84,6 +85,7 @@ int	set_bootargs(const char *);
 void	command_boot(char *);
 void	command_dev(char *);
 void	command_dtb(char *);
+void	command_plist(char *);
 void	command_initrd(char *);
 void	command_ls(char *);
 void	command_mem(char *);
@@ -99,6 +101,7 @@ const struct boot_command commands[] = {
 	{ "boot",	command_boot,		"boot [dev:][filename] [args]\n (ex. \"hd0a:\\netbsd.old -s\"" },
 	{ "dev",	command_dev,		"dev" },
 	{ "dtb",	command_dtb,		"dtb [dev:][filename]" },
+	{ "plist",	command_plist,		"plist [dev:][filename]" },
 	{ "initrd",	command_initrd,		"initrd [dev:][filename]" },
 	{ "ls",		command_ls,		"ls [hdNn:/path]" },
 	{ "mem",	command_mem,		"mem" },
@@ -166,6 +169,13 @@ command_dtb(char *arg)
 }
 
 void
+command_plist(char *arg)
+{
+	if (set_efibootplist_path(arg) == 0)
+		load_efibootplist(false);
+}
+
+void
 command_initrd(char *arg)
 {
 	set_initrd_path(arg);
@@ -324,6 +334,20 @@ get_dtb_path(void)
 }
 
 int
+set_efibootplist_path(const char *arg)
+{
+	if (strlen(arg) + 1 > sizeof(efibootplist_path))
+		return ERANGE;
+	strcpy(efibootplist_path, arg);
+	return 0;
+}
+
+char *get_efibootplist_path(void)
+{
+	return efibootplist_path;
+}
+
+int
 set_bootfile(const char *arg)
 {
 	if (strlen(arg) + 1 > sizeof(netbsd_path))
@@ -354,6 +378,21 @@ read_env(void)
 {
 	char *s;
 
+	s = efi_env_get("efibootplist");
+	if (s) {
+#ifdef EFIBOOT_DEBUG
+		printf(">> Setting efiboot.plist path to '%s' from environment\n", s);
+#endif
+		set_efibootplist_path(s);
+		FreePool(s);
+	}
+
+	/*
+	 * Read the efiboot.plist now as it may contain additional
+	 * environment variables.
+	 */
+	load_efibootplist(true);
+
 	s = efi_env_get("fdtfile");
 	if (s) {
 #ifdef EFIBOOT_DEBUG

Index: src/sys/stand/efiboot/efiboot.c
diff -u 

CVS commit: src/sys/stand/efiboot

2019-04-20 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Apr 20 11:28:53 UTC 2019

Modified Files:
src/sys/stand/efiboot: boot.c

Log Message:
ST FirmwareRevision field is in a vendor defined format, so just print the raw 
value


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/stand/efiboot/boot.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/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.16 src/sys/stand/efiboot/boot.c:1.17
--- src/sys/stand/efiboot/boot.c:1.16	Wed Apr 10 19:36:04 2019
+++ src/sys/stand/efiboot/boot.c	Sat Apr 20 11:28:53 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.16 2019/04/10 19:36:04 skrll Exp $	*/
+/*	$NetBSD: boot.c,v 1.17 2019/04/20 11:28:53 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -257,9 +257,8 @@ command_version(char *arg)
 	ufirmware = NULL;
 	rv = ucs2_to_utf8(ST->FirmwareVendor, );
 	if (rv == 0) {
-		printf("EFI Firmware: %s (rev %d.%02d)\n", ufirmware,
-		ST->FirmwareRevision >> 16,
-		ST->FirmwareRevision & 0x);
+		printf("EFI Firmware: %s (rev 0x%x)\n", ufirmware,
+		ST->FirmwareRevision);
 		FreePool(ufirmware);
 	}
 



CVS commit: src/sys/stand/efiboot

2019-04-20 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Apr 20 11:23:16 UTC 2019

Modified Files:
src/sys/stand/efiboot: efiboot.c

Log Message:
Skip clearing the screen when efiboot starts, it may end up hiding useful 
information


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/stand/efiboot/efiboot.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/stand/efiboot/efiboot.c
diff -u src/sys/stand/efiboot/efiboot.c:1.14 src/sys/stand/efiboot/efiboot.c:1.15
--- src/sys/stand/efiboot/efiboot.c:1.14	Wed Apr 10 19:11:42 2019
+++ src/sys/stand/efiboot/efiboot.c	Sat Apr 20 11:23:16 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: efiboot.c,v 1.14 2019/04/10 19:11:42 skrll Exp $ */
+/* $NetBSD: efiboot.c,v 1.15 2019/04/20 11:23:16 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -67,8 +67,6 @@ efi_main(EFI_HANDLE imageHandle, EFI_SYS
 	InitializeLib(imageHandle, systemTable);
 
 	(void)uefi_call_wrapper(ST->ConOut->Reset, 2, ST->ConOut, FALSE);
-	if (ST->ConOut->ClearScreen)
-		(void)uefi_call_wrapper(ST->ConOut->ClearScreen, 1, ST->ConOut);
 
 	status = uefi_call_wrapper(BS->AllocatePages, 4, AllocateAnyPages, EfiLoaderData, sz, _start);
 	if (EFI_ERROR(status))



CVS commit: src/sys/stand/efiboot

2019-04-10 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Apr 10 19:36:04 UTC 2019

Modified Files:
src/sys/stand/efiboot: boot.c

Log Message:
Print bootargs from the environment

Pass the enironment boot args if none are provided by the boot command


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/stand/efiboot/boot.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/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.15 src/sys/stand/efiboot/boot.c:1.16
--- src/sys/stand/efiboot/boot.c:1.15	Fri Jan 18 19:41:03 2019
+++ src/sys/stand/efiboot/boot.c	Wed Apr 10 19:36:04 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.15 2019/01/18 19:41:03 skrll Exp $	*/
+/*	$NetBSD: boot.c,v 1.16 2019/04/10 19:36:04 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -137,6 +137,9 @@ command_boot(char *arg)
 	if (!kernel || !*kernel)
 		kernel = DEFFILENAME;
 
+	if (!*bootargs)
+		bootargs = netbsd_args;
+
 	exec_netbsd(kernel, bootargs);
 }
 
@@ -415,7 +418,8 @@ boot(void)
 	for (; currname < (int)NUMNAMES; currname++) {
 		if (currname >= 0)
 			set_bootfile(names[currname]);
-		printf("booting %s - starting in ", netbsd_path);
+		printf("booting %s%s%s - starting in ", netbsd_path,
+		netbsd_args[0] != '\0' ? " " : "", netbsd_args);
 
 		c = awaitkey(DEFTIMEOUT, 1);
 		if (c != '\r' && c != '\n' && c != '\0')



CVS commit: src/sys/stand/efiboot

2019-04-10 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Apr 10 19:11:42 UTC 2019

Modified Files:
src/sys/stand/efiboot: efiboot.c

Log Message:
Fixup EFIBOT_DEBUG output for non-_LP64 case


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/stand/efiboot/efiboot.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/stand/efiboot/efiboot.c
diff -u src/sys/stand/efiboot/efiboot.c:1.13 src/sys/stand/efiboot/efiboot.c:1.14
--- src/sys/stand/efiboot/efiboot.c:1.13	Sat Mar 30 12:47:53 2019
+++ src/sys/stand/efiboot/efiboot.c	Wed Apr 10 19:11:42 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: efiboot.c,v 1.13 2019/03/30 12:47:53 jmcneill Exp $ */
+/* $NetBSD: efiboot.c,v 1.14 2019/04/10 19:11:42 skrll Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -42,6 +42,14 @@ EFI_LOADED_IMAGE *efi_li;
 
 int howto = 0;
 
+#ifdef _LP64
+#define PRIxEFIPTR "lX"
+#define PRIxEFISIZE "lX"
+#else
+#define PRIxEFIPTR "X"
+#define PRIxEFISIZE "X"
+#endif
+
 static EFI_PHYSICAL_ADDRESS heap_start;
 static UINTN heap_size = 8 * 1024 * 1024;
 static EFI_EVENT delay_ev = 0;
@@ -75,10 +83,10 @@ efi_main(EFI_HANDLE imageHandle, EFI_SYS
 		efi_bootdp = NULL;
 
 #ifdef EFIBOOT_DEBUG
-	Print(L"Loaded image  : 0x%lX\n", efi_li);
-	Print(L"FilePath  : 0x%lX\n", efi_li->FilePath);
-	Print(L"ImageBase : 0x%lX\n", efi_li->ImageBase);
-	Print(L"ImageSize : 0x%lX\n", efi_li->ImageSize);
+	Print(L"Loaded image  : 0x%" PRIxEFIPTR "\n", efi_li);
+	Print(L"FilePath  : 0x%" PRIxEFIPTR "\n", efi_li->FilePath);
+	Print(L"ImageBase : 0x%" PRIxEFIPTR "\n", efi_li->ImageBase);
+	Print(L"ImageSize : 0x%" PRIxEFISIZE "\n", efi_li->ImageSize);
 	Print(L"Image file: %s\n", DevicePathToStr(efi_li->FilePath));
 #endif
 



CVS commit: src/sys/stand/efiboot

2019-03-31 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Mar 31 22:24:41 UTC 2019

Modified Files:
src/sys/stand/efiboot: efinet.c

Log Message:
Add support for netbooting with non-PCI network devices.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/stand/efiboot/efinet.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/stand/efiboot/efinet.c
diff -u src/sys/stand/efiboot/efinet.c:1.5 src/sys/stand/efiboot/efinet.c:1.6
--- src/sys/stand/efiboot/efinet.c:1.5	Tue Mar  5 08:25:03 2019
+++ src/sys/stand/efiboot/efinet.c	Sun Mar 31 22:24:41 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: efinet.c,v 1.5 2019/03/05 08:25:03 msaitoh Exp $	*/
+/*	$NetBSD: efinet.c,v 1.6 2019/03/31 22:24:41 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2001 Doug Rabson
@@ -117,6 +117,33 @@ dump_mode(EFI_SIMPLE_NETWORK_MODE *mode)
 }
 #endif
 
+static const EFI_MAC_ADDRESS *
+efinet_hwaddr(const EFI_SIMPLE_NETWORK_MODE *mode)
+{
+	int valid, n;
+
+	for (valid = 0, n = 0; n < mode->HwAddressSize; n++)
+		if (mode->CurrentAddress.Addr[n] != 0x00) {
+			valid = true;
+			break;
+		}
+	if (!valid)
+		goto use_permanent;
+
+	for (valid = 0, n = 0; n < mode->HwAddressSize; n++)
+		if (mode->CurrentAddress.Addr[n] != 0xff) {
+			valid = true;
+			break;
+		}
+	if (!valid)
+		goto use_permanent;
+
+	return >CurrentAddress;
+
+use_permanent:
+	return >PermanentAddress;
+}
+
 static int
 efinet_match(struct netif *nif, void *machdep_hint)
 {
@@ -143,12 +170,16 @@ efinet_put(struct iodesc *desc, void *pk
 	EFI_SIMPLE_NETWORK *net;
 	EFI_STATUS status;
 	void *buf;
+	char *ptr;
 
 	if (eni == NULL)
 		return -1;
 	net = eni->net;
 
-	status = uefi_call_wrapper(net->Transmit, 7, net, 0, (UINTN)len, pkt, NULL,
+	ptr = eni->pktbuf;
+
+	memcpy(ptr, pkt, len);
+	status = uefi_call_wrapper(net->Transmit, 7, net, 0, (UINTN)len, ptr, NULL,
 	NULL, NULL);
 	if (EFI_ERROR(status))
 		return -1;
@@ -202,6 +233,7 @@ efinet_get(struct iodesc *desc, void *pk
 		if (!EFI_ERROR(status)) {
 			rsz = uimin(rsz, len);
 			memcpy(pkt, ptr, rsz);
+
 			ret = (int)rsz;
 			break;
 		}
@@ -252,7 +284,7 @@ efinet_init(struct iodesc *desc, void *m
 
 	status = uefi_call_wrapper(net->ReceiveFilters, 6, net, mask, 0, FALSE,
 	0, NULL);
-	if (EFI_ERROR(status) && status != EFI_INVALID_PARAMETER) {
+	if (EFI_ERROR(status) && status != EFI_INVALID_PARAMETER && status != EFI_UNSUPPORTED) {
 		printf("net%d: cannot set rx. filters (status=%" PRIxMAX ")\n",
 		nif->nif_unit, (uintmax_t)status);
 		return;
@@ -272,7 +304,7 @@ efinet_init(struct iodesc *desc, void *m
 	dump_mode(net->Mode);
 #endif
 
-	memcpy(desc->myea, net->Mode->PermanentAddress.Addr, 6);
+	memcpy(desc->myea, efinet_hwaddr(net->Mode)->Addr, 6);
 	desc->xid = 1;
 }
 
@@ -289,44 +321,13 @@ efinet_end(struct netif *nif)
 	uefi_call_wrapper(net->Shutdown, 1, net);
 }
 
-static bool
-efi_net_pci_probe(struct efinetinfo *eni, EFI_DEVICE_PATH *dp, EFI_DEVICE_PATH *pdp)
-{
-#if notyet
-	PCI_DEVICE_PATH *pci = (PCI_DEVICE_PATH *)dp;
-#endif
-	int bus = -1;
-
-	if (pdp != NULL &&
-	DevicePathType(pdp) == ACPI_DEVICE_PATH &&
-	(DevicePathSubType(pdp) == ACPI_DP ||
-	 DevicePathSubType(pdp) == EXPANDED_ACPI_DP)) {
-		ACPI_HID_DEVICE_PATH *acpi = (ACPI_HID_DEVICE_PATH *)pdp;
-		/* PCI root bus */
-		if (acpi->HID == EISA_PNP_ID(0x0A08) ||
-		acpi->HID == EISA_PNP_ID(0x0A03)) {
-			bus = acpi->UID;
-		}
-	}
-	if (bus < 0)
-		return false;
-
-#if notyet
-	eni->bus.type = BI_BUS_PCI;
-	eni->bus.tag = (bus & 0xff) << 8;
-	eni->bus.tag |= (pci->Device & 0x1f) << 3;
-	eni->bus.tag |= pci->Function & 0x7;
-#endif
-	return true;
-}
-
 void
 efi_net_probe(void)
 {
 	struct efinetinfo *enis;
 	struct netif_dif *dif;
 	struct netif_stats *stats;
-	EFI_DEVICE_PATH *dp0, *dp, *pdp;
+	EFI_DEVICE_PATH *dp0, *dp;
 	EFI_SIMPLE_NETWORK *net;
 	EFI_HANDLE *handles;
 	EFI_STATUS status;
@@ -375,45 +376,33 @@ efi_net_probe(void)
 			printf("Unable to open network interface %" PRIuMAX
 			" for exclusive access: %" PRIxMAX "\n",
 			(uintmax_t)i, (uintmax_t)status);
+			continue;
 		}
 
-		found = false;
-		for (pdp = NULL, dp = dp0;
-		!IsDevicePathEnd(dp);
-		pdp = dp, dp = NextDevicePathNode(dp)) {
-			if (DevicePathType(dp) == HARDWARE_DEVICE_PATH) {
-if (DevicePathSubType(dp) == HW_PCI_DP)
-	found = efi_net_pci_probe([nifs],
-	dp, pdp);
-break;
+		enis[nifs].net = net;
+		enis[nifs].bootdev = efi_pxe_match_booted_interface(
+		efinet_hwaddr(net->Mode), net->Mode->HwAddressSize);
+		enis[nifs].pktbufsz = net->Mode->MaxPacketSize +
+		ETHER_EXT_LEN;
+		enis[nifs].pktbuf = alloc(enis[nifs].pktbufsz);
+		if (enis[nifs].pktbuf == NULL) {
+			while (i-- > 0) {
+dealloc(enis[i].pktbuf, enis[i].pktbufsz);
+if (i == 0)
+	break;
 			}
+			dealloc(enis, nhandles * sizeof(*enis));
+			FreePool(handles);
+			return;
 		}
-		if (found) {
-			

CVS commit: src/sys/stand/efiboot/bootarm

2019-03-30 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Mar 30 17:41:13 UTC 2019

Modified Files:
src/sys/stand/efiboot/bootarm: efibootarm.c

Log Message:
Jump to MARK_ENTRY instead of MARK_START


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/stand/efiboot/bootarm/efibootarm.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/stand/efiboot/bootarm/efibootarm.c
diff -u src/sys/stand/efiboot/bootarm/efibootarm.c:1.1 src/sys/stand/efiboot/bootarm/efibootarm.c:1.2
--- src/sys/stand/efiboot/bootarm/efibootarm.c:1.1	Sat Mar 30 12:48:50 2019
+++ src/sys/stand/efiboot/bootarm/efibootarm.c	Sat Mar 30 17:41:13 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: efibootarm.c,v 1.1 2019/03/30 12:48:50 jmcneill Exp $ */
+/* $NetBSD: efibootarm.c,v 1.2 2019/03/30 17:41:13 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared McNeill 
@@ -47,16 +47,14 @@ efi_dcache_flush(u_long start, u_long si
 void
 efi_boot_kernel(u_long marks[MARK_MAX])
 {
-	void (*kernel_entry)(register_t, register_t, register_t, register_t);
 	u_long kernel_size;
 
-	kernel_entry = (void *)marks[MARK_START];
 	kernel_size = marks[MARK_END] - marks[MARK_START];
 
-	armv7_dcache_wbinv_range((u_long)kernel_entry, kernel_size);
+	armv7_dcache_wbinv_range(marks[MARK_START], kernel_size);
 	if (efi_fdt_size() > 0)
 		armv7_dcache_wbinv_range((u_long)efi_fdt_data(), efi_fdt_size());
 	armv7_icache_inv_all();
 
-	armv7_exec_kernel((register_t)marks[MARK_START], (register_t)efi_fdt_data());
+	armv7_exec_kernel((register_t)marks[MARK_ENTRY], (register_t)efi_fdt_data());
 }



CVS commit: src/sys/stand/efiboot/bootarm

2019-03-30 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Mar 30 12:48:50 UTC 2019

Added Files:
src/sys/stand/efiboot/bootarm: Makefile cache.S efibootarm.c

Log Message:
Add efiboot support for 32-bit ARM targets.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/stand/efiboot/bootarm/Makefile \
src/sys/stand/efiboot/bootarm/cache.S \
src/sys/stand/efiboot/bootarm/efibootarm.c

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

Added files:

Index: src/sys/stand/efiboot/bootarm/Makefile
diff -u /dev/null src/sys/stand/efiboot/bootarm/Makefile:1.1
--- /dev/null	Sat Mar 30 12:48:50 2019
+++ src/sys/stand/efiboot/bootarm/Makefile	Sat Mar 30 12:48:50 2019
@@ -0,0 +1,20 @@
+# $NetBSD: Makefile,v 1.1 2019/03/30 12:48:50 jmcneill Exp $
+
+PROG=		bootarm.efi
+OBJFMT=		binary
+NEWVERSWHAT=	"EFI Boot (arm)"
+GNUEFIARCH=	arm
+LIBGNUEFI_ARCH=	arm
+
+EXTRA_SOURCES=	efibootarm.c
+EXTRA_SOURCES+=	cache.S
+
+COPTS+=		-mno-unaligned-access -ffreestanding -fno-unwind-tables
+CFLAGS+=	-DEFIBOOT_ALIGN=0x100
+LDFLAGS+=	-N
+
+.include "${.CURDIR}/../Makefile.efiboot"
+
+release: check_RELEASEDIR
+	${HOST_INSTALL_FILE} -m ${BINMODE} ${PROG} \
+		${RELEASEDIR}/${MACHINE}/installation/misc
Index: src/sys/stand/efiboot/bootarm/cache.S
diff -u /dev/null src/sys/stand/efiboot/bootarm/cache.S:1.1
--- /dev/null	Sat Mar 30 12:48:50 2019
+++ src/sys/stand/efiboot/bootarm/cache.S	Sat Mar 30 12:48:50 2019
@@ -0,0 +1,118 @@
+/*-
+ * Copyright (c) 2010 Per Odlund 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* ARMv7 assembly functions for manipulating caches and other core functions.
+ * Based on cpufuncs for v6 and xscale.
+ */
+
+#include 
+
+	.arch	armv7a
+
+/* LINTSTUB: void armv7_dcache_wbinv_range(vaddr_t, vsize_t); */
+ENTRY(armv7_dcache_wbinv_range)
+	mov	ip, #0
+	mcr	p15, 2, ip, c0, c0, 0	@ set cache level to L1
+	mrc	p15, 1, r2, c0, c0, 0	@ read CCSIDR
+	and	r2, r2, #7		@ get line size (log2(size)-4, 0=16)
+	mov	ip, #16			@ make a bit mask
+	lsl	r2, ip, r2		@ and shift into position
+	sub	ip, r2, #1		@ make into a mask
+	and	r3, r0, ip		@ get offset into cache line
+	add	r1, r1, r3		@ add to length
+	bic	r0, r0, ip		@ clear offset from start.
+	dsb
+1:
+	mcr	p15, 0, r0, c7, c14, 1	@ wb and inv the D-Cache line to PoC
+	add	r0, r0, r2
+	subs	r1, r1, r2
+	bhi	1b
+	dsb@ data synchronization barrier
+	bx	lr
+END(armv7_dcache_wbinv_range)
+
+/* * LINTSTUB: void armv7_icache_inv_all(void); */
+ENTRY_NP(armv7_icache_inv_all)
+	mov	r0, #0
+	mcr	p15, 2, r0, c0, c0, 0	@ set cache level to L1
+	mrc	p15, 1, r0, c0, c0, 0	@ read CCSIDR
+
+	ubfx	r2, r0, #13, #15	@ get num sets - 1 from CCSIDR
+	ubfx	r3, r0, #3, #10		@ get numways - 1 from CCSIDR
+	clz	r1, r3			@ number of bits to MSB of way
+	lsl	r3, r3, r1		@ shift into position
+	mov	ip, #1			@
+	lsl	ip, ip, r1		@ ip now contains the way decr
+
+	ubfx	r0, r0, #0, #3		@ get linesize from CCSIDR
+	add	r0, r0, #4		@ apply bias
+	lsl	r2, r2, r0		@ shift sets by log2(linesize)
+	add	r3, r3, r2		@ merge numsets - 1 with numways - 1
+	sub	ip, ip, r2		@ subtract numsets - 1 from way decr
+	mov	r1, #1
+	lsl	r1, r1, r0		@ r1 now contains the set decr
+	mov	r2, ip			@ r2 now contains set way decr
+
+	/* r3 = ways/sets, r2 = way decr, r1 = set decr, r0 and ip are free */
+1:	mcr	p15, 0, r3, c7, c6, 2	@ DCISW (data cache invalidate by set/way)
+	movs	r0, r3			@ get current way/set
+	beq	2f			@ at 0 means we are done.
+	lsls	r0, r0, #10		@ clear way bits leaving only set bits
+	subne	r3, r3, r1		@ non-zero?, decrement set #
+	subeq	r3, r3, r2		@ zero?, decrement way # and restore set count
+	b	1b
+
+2:	dsb@ wait for stores 

CVS commit: src/sys/stand/efiboot

2019-03-30 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Mar 30 12:47:53 UTC 2019

Modified Files:
src/sys/stand/efiboot: efiboot.c efienv.c efigetsecs.c exec.c

Log Message:
Build fixes for 32-bit targets.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/stand/efiboot/efiboot.c
cvs rdiff -u -r1.2 -r1.3 src/sys/stand/efiboot/efienv.c
cvs rdiff -u -r1.3 -r1.4 src/sys/stand/efiboot/efigetsecs.c
cvs rdiff -u -r1.8 -r1.9 src/sys/stand/efiboot/exec.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/stand/efiboot/efiboot.c
diff -u src/sys/stand/efiboot/efiboot.c:1.12 src/sys/stand/efiboot/efiboot.c:1.13
--- src/sys/stand/efiboot/efiboot.c:1.12	Thu Nov  1 00:43:38 2018
+++ src/sys/stand/efiboot/efiboot.c	Sat Mar 30 12:47:53 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: efiboot.c,v 1.12 2018/11/01 00:43:38 jmcneill Exp $ */
+/* $NetBSD: efiboot.c,v 1.13 2019/03/30 12:47:53 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -65,7 +65,7 @@ efi_main(EFI_HANDLE imageHandle, EFI_SYS
 	status = uefi_call_wrapper(BS->AllocatePages, 4, AllocateAnyPages, EfiLoaderData, sz, _start);
 	if (EFI_ERROR(status))
 		return status;
-	setheap((void *)heap_start, (void *)(heap_start + heap_size));
+	setheap((void *)(uintptr_t)heap_start, (void *)(uintptr_t)(heap_start + heap_size));
 
 	status = uefi_call_wrapper(BS->HandleProtocol, 3, imageHandle, , (void **)_li);
 	if (EFI_ERROR(status))

Index: src/sys/stand/efiboot/efienv.c
diff -u src/sys/stand/efiboot/efienv.c:1.2 src/sys/stand/efiboot/efienv.c:1.3
--- src/sys/stand/efiboot/efienv.c:1.2	Tue Sep 18 19:19:45 2018
+++ src/sys/stand/efiboot/efienv.c	Sat Mar 30 12:47:53 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: efienv.c,v 1.2 2018/09/18 19:19:45 jmcneill Exp $ */
+/* $NetBSD: efienv.c,v 1.3 2019/03/30 12:47:53 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -47,7 +47,7 @@ efi_env_set(const char *key, char *val)
 	FreePool(ukey);
 
 	if (EFI_ERROR(status))
-		printf("env: failed to set variable '%s': %#lx\n", key, status);
+		printf("env: failed to set variable '%s': %#lx\n", key, (u_long)status);
 }
 
 char *

Index: src/sys/stand/efiboot/efigetsecs.c
diff -u src/sys/stand/efiboot/efigetsecs.c:1.3 src/sys/stand/efiboot/efigetsecs.c:1.4
--- src/sys/stand/efiboot/efigetsecs.c:1.3	Mon Sep  3 00:04:02 2018
+++ src/sys/stand/efiboot/efigetsecs.c	Sat Mar 30 12:47:53 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: efigetsecs.c,v 1.3 2018/09/03 00:04:02 jmcneill Exp $	*/
+/*	$NetBSD: efigetsecs.c,v 1.4 2019/03/30 12:47:53 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 2015 YASUOKA Masahiko 
@@ -70,10 +70,10 @@ getsecs(void)
 		status = uefi_call_wrapper(BS->CreateEvent, 5, EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_CALLBACK,
 		getsecs_notify_func, 0, _ev);
 		if (EFI_ERROR(status))
-			panic("%s: couldn't create event timer: 0x%lx", __func__, status);
+			panic("%s: couldn't create event timer: 0x%lx", __func__, (u_long)status);
 		status = uefi_call_wrapper(BS->SetTimer, 3, getsecs_ev, TimerPeriodic, 1000);	/* 1s in "100ns" units */
 		if (EFI_ERROR(status))
-			panic("%s: couldn't start event timer: 0x%lx", __func__, status);
+			panic("%s: couldn't start event timer: 0x%lx", __func__, (u_long)status);
 		getsecs_val = getsecs_rtc();
 	}
 

Index: src/sys/stand/efiboot/exec.c
diff -u src/sys/stand/efiboot/exec.c:1.8 src/sys/stand/efiboot/exec.c:1.9
--- src/sys/stand/efiboot/exec.c:1.8	Sun Oct 28 10:17:47 2018
+++ src/sys/stand/efiboot/exec.c	Sat Mar 30 12:47:53 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.c,v 1.8 2018/10/28 10:17:47 jmcneill Exp $ */
+/* $NetBSD: exec.c,v 1.9 2019/03/30 12:47:53 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -80,13 +80,13 @@ load_file(char *path, EFI_PHYSICAL_ADDRE
 #endif
 	if (EFI_ERROR(status)) {
 		printf("Failed to allocate %lu bytes for %s (error %lu)\n",
-		*psize, path, status);
+		*psize, path, (u_long)status);
 		close(fd);
 		return ENOMEM;
 	}
 
 	printf("boot: loading %s ", path);
-	len = read(fd, (void *)*paddr, *psize);
+	len = read(fd, (void *)(uintptr_t)*paddr, *psize);
 	close(fd);
 
 	if (len != *psize) {
@@ -139,7 +139,7 @@ exec_netbsd(const char *fname, const cha
 #endif
 	if (EFI_ERROR(status)) {
 		printf("Failed to allocate %lu bytes for kernel image (error %lu)\n",
-		alloc_size, status);
+		alloc_size, (u_long)status);
 		return ENOMEM;
 	}
 
@@ -158,7 +158,7 @@ exec_netbsd(const char *fname, const cha
 		efi_acpi_create_fdt();
 	} else
 #endif
-	if (dtb_addr && efi_fdt_set_data((void *)dtb_addr) != 0) {
+	if (dtb_addr && efi_fdt_set_data((void *)(uintptr_t)dtb_addr) != 0) {
 		printf("boot: invalid DTB data\n");
 		goto cleanup;
 	}



CVS commit: src/sys/stand/efiboot

2019-03-09 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Mar  9 13:16:42 UTC 2019

Modified Files:
src/sys/stand/efiboot: efiblock.c

Log Message:
Workaround a bug with ROCKPro64's U-Boot EFI implementation. The booted
device path when booting from SD card sometimes does not include a
MEDIA_DEVICE_PATH component, so in this case fallback to doing an exact
match on the booted device path with the block device path to detect the
default boot device.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/stand/efiboot/efiblock.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/stand/efiboot/efiblock.c
diff -u src/sys/stand/efiboot/efiblock.c:1.4 src/sys/stand/efiboot/efiblock.c:1.5
--- src/sys/stand/efiboot/efiblock.c:1.4	Thu Nov  1 00:43:38 2018
+++ src/sys/stand/efiboot/efiblock.c	Sat Mar  9 13:16:42 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.c,v 1.4 2018/11/01 00:43:38 jmcneill Exp $ */
+/* $NetBSD: efiblock.c,v 1.5 2019/03/09 13:16:42 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -315,6 +315,8 @@ efi_block_probe(void)
 		depth = efi_device_path_depth(efi_bootdp, MEDIA_DEVICE_PATH);
 		if (depth == 0)
 			depth = 1;
+		else if (depth == -1)
+			depth = 2;
 	}
 
 	for (n = 0; n < efi_nblock; n++) {



CVS commit: src/sys/stand/efiboot

2019-01-18 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Jan 18 19:41:03 UTC 2019

Modified Files:
src/sys/stand/efiboot: boot.c version

Log Message:
Add support for "bootargs" environment variable from jmcneill@

Doesn't work with some (all?) u-boots.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/stand/efiboot/boot.c
cvs rdiff -u -r1.8 -r1.9 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/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.14 src/sys/stand/efiboot/boot.c:1.15
--- src/sys/stand/efiboot/boot.c:1.14	Thu Nov 15 23:52:33 2018
+++ src/sys/stand/efiboot/boot.c	Fri Jan 18 19:41:03 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.14 2018/11/15 23:52:33 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.15 2019/01/18 19:41:03 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -73,11 +73,13 @@ static char default_device[32];
 static char initrd_path[255];
 static char dtb_path[255];
 static char netbsd_path[255];
+static char netbsd_args[255];
 
 #define	DEFTIMEOUT	5
 #define DEFFILENAME	names[0]
 
 int	set_bootfile(const char *);
+int	set_bootargs(const char *);
 
 void	command_boot(char *);
 void	command_dev(char *);
@@ -328,6 +330,15 @@ set_bootfile(const char *arg)
 	return 0;
 }
 
+int
+set_bootargs(const char *arg)
+{
+	if (strlen(arg) + 1 > sizeof(netbsd_args))
+		return ERANGE;
+	strcpy(netbsd_args, arg);
+	return 0;
+}
+
 void
 print_banner(void)
 {
@@ -376,6 +387,15 @@ read_env(void)
 		set_default_device(s);
 		FreePool(s);
 	}
+
+	s = efi_env_get("bootargs");
+	if (s) {
+#ifdef EFIBOOT_DEBUG
+		printf(">> Setting default boot args to '%s' from environment\n", s);
+#endif
+		set_bootargs(s);
+		FreePool(s);
+	}
 }
 
 void
@@ -401,7 +421,7 @@ boot(void)
 		if (c != '\r' && c != '\n' && c != '\0')
 			bootprompt(); /* does not return */
 
-		exec_netbsd(netbsd_path, "");
+		exec_netbsd(netbsd_path, netbsd_args);
 	}
 
 	bootprompt();	/* does not return */

Index: src/sys/stand/efiboot/version
diff -u src/sys/stand/efiboot/version:1.8 src/sys/stand/efiboot/version:1.9
--- src/sys/stand/efiboot/version:1.8	Thu Nov 15 23:52:33 2018
+++ src/sys/stand/efiboot/version	Fri Jan 18 19:41:03 2019
@@ -1,4 +1,4 @@
-$NetBSD: version,v 1.8 2018/11/15 23:52:33 jmcneill Exp $
+$NetBSD: version,v 1.9 2019/01/18 19:41:03 skrll 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
@@ -12,3 +12,4 @@ is taken as the current.
 1.5:	EFI runtime support.
 1.6:	Add GPT support.
 1.7:	Add NFS support.
+1.8:	Add support for "bootargs" environment variable.



CVS commit: src/sys/stand/efiboot

2018-11-15 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Nov 15 23:52:33 UTC 2018

Modified Files:
src/sys/stand/efiboot: boot.c conf.c dev_net.c devopen.c efiboot.h
efifdt.c efinet.c efipxe.c version

Log Message:
Add support for loading kernels over NFS.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/stand/efiboot/boot.c \
src/sys/stand/efiboot/efifdt.c
cvs rdiff -u -r1.3 -r1.4 src/sys/stand/efiboot/conf.c \
src/sys/stand/efiboot/devopen.c src/sys/stand/efiboot/efinet.c
cvs rdiff -u -r1.1 -r1.2 src/sys/stand/efiboot/dev_net.c \
src/sys/stand/efiboot/efipxe.c
cvs rdiff -u -r1.8 -r1.9 src/sys/stand/efiboot/efiboot.h
cvs rdiff -u -r1.7 -r1.8 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/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.13 src/sys/stand/efiboot/boot.c:1.14
--- src/sys/stand/efiboot/boot.c:1.13	Fri Nov  2 01:22:39 2018
+++ src/sys/stand/efiboot/boot.c	Thu Nov 15 23:52:33 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.13 2018/11/02 01:22:39 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.14 2018/11/15 23:52:33 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -72,7 +72,7 @@ static const char *efi_memory_type[] = {
 static char default_device[32];
 static char initrd_path[255];
 static char dtb_path[255];
-static char bootfile[255];
+static char netbsd_path[255];
 
 #define	DEFTIMEOUT	5
 #define DEFFILENAME	names[0]
@@ -146,7 +146,6 @@ command_dev(char *arg)
 	} else {
 		efi_block_show();
 		efi_net_show();
-		efi_pxe_show();
 	}
 
 	if (strlen(default_device) > 0) {
@@ -323,9 +322,9 @@ get_dtb_path(void)
 int
 set_bootfile(const char *arg)
 {
-	if (strlen(arg) + 1 > sizeof(bootfile))
+	if (strlen(arg) + 1 > sizeof(netbsd_path))
 		return ERANGE;
-	strcpy(bootfile, arg);
+	strcpy(netbsd_path, arg);
 	return 0;
 }
 
@@ -388,7 +387,7 @@ boot(void)
 	print_banner();
 	printf("Press return to boot now, any other key for boot prompt\n");
 
-	if (bootfile[0] != '\0')
+	if (netbsd_path[0] != '\0')
 		currname = -1;
 	else
 		currname = 0;
@@ -396,13 +395,13 @@ boot(void)
 	for (; currname < (int)NUMNAMES; currname++) {
 		if (currname >= 0)
 			set_bootfile(names[currname]);
-		printf("booting %s - starting in ", bootfile);
+		printf("booting %s - starting in ", netbsd_path);
 
 		c = awaitkey(DEFTIMEOUT, 1);
 		if (c != '\r' && c != '\n' && c != '\0')
 			bootprompt(); /* does not return */
 
-		exec_netbsd(bootfile, "");
+		exec_netbsd(netbsd_path, "");
 	}
 
 	bootprompt();	/* does not return */
Index: src/sys/stand/efiboot/efifdt.c
diff -u src/sys/stand/efiboot/efifdt.c:1.13 src/sys/stand/efiboot/efifdt.c:1.14
--- src/sys/stand/efiboot/efifdt.c:1.13	Fri Nov  2 01:22:39 2018
+++ src/sys/stand/efiboot/efifdt.c	Thu Nov 15 23:52:33 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.c,v 1.13 2018/11/02 01:22:39 jmcneill Exp $ */
+/* $NetBSD: efifdt.c,v 1.14 2018/11/15 23:52:33 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -194,6 +194,7 @@ void
 efi_fdt_bootargs(const char *bootargs)
 {
 	struct efi_block_part *bpart = efi_block_boot_part();
+	uint8_t macaddr[6];
 	int chosen;
 
 	chosen = fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH);
@@ -229,6 +230,8 @@ efi_fdt_bootargs(const char *bootargs)
 		default:
 			break;
 		}
+	} else if (efi_net_get_booted_macaddr(macaddr) == 0) {
+		fdt_setprop(fdt_data, chosen, "netbsd,booted-mac-address", macaddr, sizeof(macaddr));
 	}
 }
 

Index: src/sys/stand/efiboot/conf.c
diff -u src/sys/stand/efiboot/conf.c:1.3 src/sys/stand/efiboot/conf.c:1.4
--- src/sys/stand/efiboot/conf.c:1.3	Mon Sep  3 00:04:02 2018
+++ src/sys/stand/efiboot/conf.c	Thu Nov 15 23:52:33 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: conf.c,v 1.3 2018/09/03 00:04:02 jmcneill Exp $ */
+/* $NetBSD: conf.c,v 1.4 2018/11/15 23:52:33 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -34,6 +34,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -59,3 +60,4 @@ int nfsys = __arraycount(file_system);
 
 struct fs_ops null_fs_ops = FS_OPS(null);
 struct fs_ops tftp_fs_ops = FS_OPS(tftp);
+struct fs_ops nfs_fs_ops = FS_OPS(nfs);
Index: src/sys/stand/efiboot/devopen.c
diff -u src/sys/stand/efiboot/devopen.c:1.3 src/sys/stand/efiboot/devopen.c:1.4
--- src/sys/stand/efiboot/devopen.c:1.3	Mon Sep  3 00:04:02 2018
+++ src/sys/stand/efiboot/devopen.c	Thu Nov 15 23:52:33 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: devopen.c,v 1.3 2018/09/03 00:04:02 jmcneill Exp $ */
+/* $NetBSD: devopen.c,v 1.4 2018/11/15 23:52:33 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -36,7 +36,12 @@ devopen(struct open_file *f, const char 
 	int error;
 
 	error = efi_net_open(f, fname, file);
-	file_system[0] = error ? null_fs_ops : tftp_fs_ops;
+	if (error)
+		file_system[0] = null_fs_ops;
+	else if (rootpath[0] != '\0')
+		file_system[0] = nfs_fs_ops;
+	else
+		

CVS commit: src/sys/stand/efiboot

2018-11-01 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Nov  2 01:22:39 UTC 2018

Modified Files:
src/sys/stand/efiboot: boot.c efifdt.c

Log Message:
Add a "mem" command to print the EFI memory map.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/stand/efiboot/boot.c \
src/sys/stand/efiboot/efifdt.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/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.12 src/sys/stand/efiboot/boot.c:1.13
--- src/sys/stand/efiboot/boot.c:1.12	Mon Oct 29 05:15:21 2018
+++ src/sys/stand/efiboot/boot.c	Fri Nov  2 01:22:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.12 2018/10/29 05:15:21 mrg Exp $	*/
+/*	$NetBSD: boot.c,v 1.13 2018/11/02 01:22:39 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -51,6 +51,24 @@ static const char * const names[] = {
 
 #define NUMNAMES	__arraycount(names)
 
+static const char *efi_memory_type[] = {
+[EfiReservedMemoryType] = "Reserved Memory Type",
+[EfiLoaderCode] = "Loader Code",
+[EfiLoaderData] = "Loader Data",
+[EfiBootServicesCode]   = "Boot Services Code",
+[EfiBootServicesData]   = "Boot Services Data",
+[EfiRuntimeServicesCode]= "Runtime Services Code",
+[EfiRuntimeServicesData]= "Runtime Services Data",
+[EfiConventionalMemory] = "Conventional Memory",
+[EfiUnusableMemory] = "Unusable Memory",
+[EfiACPIReclaimMemory]  = "ACPI Reclaim Memory",
+[EfiACPIMemoryNVS]  = "ACPI Memory NVS",
+[EfiMemoryMappedIO] = "MMIO",
+[EfiMemoryMappedIOPortSpace]= "MMIO (Port Space)",
+[EfiPalCode]= "Pal Code",
+[EfiPersistentMemory]   = "Persistent Memory",
+};
+
 static char default_device[32];
 static char initrd_path[255];
 static char dtb_path[255];
@@ -66,6 +84,7 @@ void	command_dev(char *);
 void	command_dtb(char *);
 void	command_initrd(char *);
 void	command_ls(char *);
+void	command_mem(char *);
 void	command_printenv(char *);
 void	command_setenv(char *);
 void	command_clearenv(char *);
@@ -80,6 +99,7 @@ const struct boot_command commands[] = {
 	{ "dtb",	command_dtb,		"dtb [dev:][filename]" },
 	{ "initrd",	command_initrd,		"initrd [dev:][filename]" },
 	{ "ls",		command_ls,		"ls [hdNn:/path]" },
+	{ "mem",	command_mem,		"mem" },
 	{ "printenv",	command_printenv,	"printenv [key]" },
 	{ "setenv",	command_setenv,		"setenv  " },
 	{ "clearenv",	command_clearenv,	"clearenv " },
@@ -154,6 +174,28 @@ command_ls(char *arg)
 }
 
 void
+command_mem(char *arg)
+{
+	EFI_MEMORY_DESCRIPTOR *md, *memmap;
+	UINTN nentries, mapkey, descsize;
+	UINT32 descver;
+	int n;
+
+	printf("TypeStart End   Attributes\n");
+	printf("--      \n");
+	memmap = LibMemoryMap(, , , );
+	for (n = 0, md = memmap; n < nentries; n++, md = NextMemoryDescriptor(md, descsize)) {
+		const char *mem_type = "";
+		if (md->Type < __arraycount(efi_memory_type))
+			mem_type = efi_memory_type[md->Type];
+
+		printf("%-22s  %016" PRIx64 "  %016" PRIx64 "  %016" PRIx64 "\n",
+		mem_type, md->PhysicalStart, md->PhysicalStart + (md->NumberOfPages * EFI_PAGE_SIZE) - 1,
+		md->Attribute);
+	}
+}
+
+void
 command_printenv(char *arg)
 {
 	char *val;
Index: src/sys/stand/efiboot/efifdt.c
diff -u src/sys/stand/efiboot/efifdt.c:1.12 src/sys/stand/efiboot/efifdt.c:1.13
--- src/sys/stand/efiboot/efifdt.c:1.12	Thu Nov  1 00:43:38 2018
+++ src/sys/stand/efiboot/efifdt.c	Fri Nov  2 01:22:39 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.c,v 1.12 2018/11/01 00:43:38 jmcneill Exp $ */
+/* $NetBSD: efifdt.c,v 1.13 2018/11/02 01:22:39 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -152,12 +152,6 @@ efi_fdt_memory_map(void)
 
 	memmap = LibMemoryMap(, , , );
 	for (n = 0, md = memmap; n < nentries; n++, md = NextMemoryDescriptor(md, descsize)) {
-#ifdef EFI_MEMORY_DEBUG
-		printf("MEM: %u: Type 0x%x Attr 0x%lx Phys 0x%lx Virt 0x%lx Size 0x%lx\n",
-		n, md->Type, md->Attribute,
-		md->PhysicalStart, md->VirtualStart,
-		(u_long)md->NumberOfPages * EFI_PAGE_SIZE);
-#endif
 		if ((md->Attribute & EFI_MEMORY_RUNTIME) != 0)
 			continue;
 		if ((md->Attribute & EFI_MEMORY_WB) == 0)



CVS commit: src/sys/stand/efiboot

2018-10-31 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Nov  1 00:43:38 UTC 2018

Modified Files:
src/sys/stand/efiboot: efiblock.c efiblock.h efiboot.c efifdt.c version

Log Message:
Add GPT support.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/stand/efiboot/efiblock.c
cvs rdiff -u -r1.2 -r1.3 src/sys/stand/efiboot/efiblock.h
cvs rdiff -u -r1.11 -r1.12 src/sys/stand/efiboot/efiboot.c \
src/sys/stand/efiboot/efifdt.c
cvs rdiff -u -r1.6 -r1.7 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/efiblock.c
diff -u src/sys/stand/efiboot/efiblock.c:1.3 src/sys/stand/efiboot/efiblock.c:1.4
--- src/sys/stand/efiboot/efiblock.c:1.3	Fri Sep 14 21:37:03 2018
+++ src/sys/stand/efiboot/efiblock.c	Thu Nov  1 00:43:38 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.c,v 1.3 2018/09/14 21:37:03 jakllsch Exp $ */
+/* $NetBSD: efiblock.c,v 1.4 2018/11/01 00:43:38 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -31,6 +31,7 @@
 
 #include 
 #include 
+#include 
 
 #include "efiboot.h"
 #include "efiblock.h"
@@ -192,16 +193,114 @@ efi_block_find_partitions_mbr(struct efi
 	return 0;
 }
 
+static const struct {
+	struct uuid guid;
+	uint8_t fstype;
+} gpt_guid_to_str[] = {
+	{ GPT_ENT_TYPE_NETBSD_FFS,		FS_BSDFFS },
+	{ GPT_ENT_TYPE_NETBSD_LFS,		FS_BSDLFS },
+	{ GPT_ENT_TYPE_NETBSD_RAIDFRAME,	FS_RAID },
+	{ GPT_ENT_TYPE_NETBSD_CCD,		FS_CCD },
+	{ GPT_ENT_TYPE_NETBSD_CGD,		FS_CGD },
+	{ GPT_ENT_TYPE_MS_BASIC_DATA,		FS_MSDOS },	/* or NTFS? ambiguous */
+};
+
+static int
+efi_block_find_partitions_gpt_entry(struct efi_block_dev *bdev, struct gpt_hdr *hdr, struct gpt_ent *ent, UINT32 index)
+{
+	struct efi_block_part *bpart;
+	uint8_t fstype = FS_UNUSED;
+	struct uuid uuid;
+	int n;
+
+	memcpy(, ent->ent_type, sizeof(uuid));
+	for (n = 0; n < __arraycount(gpt_guid_to_str); n++)
+		if (memcmp(ent->ent_type, _guid_to_str[n].guid, sizeof(ent->ent_type)) == 0) {
+			fstype = gpt_guid_to_str[n].fstype;
+			break;
+		}
+	if (fstype == FS_UNUSED)
+		return 0;
+
+	bpart = alloc(sizeof(*bpart));
+	bpart->index = index;
+	bpart->bdev = bdev;
+	bpart->type = EFI_BLOCK_PART_GPT;
+	bpart->gpt.fstype = fstype;
+	bpart->gpt.ent = *ent;
+	memcpy(bpart->hash, ent->ent_guid, sizeof(bpart->hash));
+	TAILQ_INSERT_TAIL(>partitions, bpart, entries);
+
+	return 0;
+}
+
+static int
+efi_block_find_partitions_gpt(struct efi_block_dev *bdev)
+{
+	struct gpt_hdr hdr;
+	struct gpt_ent ent;
+	EFI_STATUS status;
+	UINT32 sz, entry;
+	uint8_t *buf;
+
+	sz = __MAX(sizeof(hdr), bdev->bio->Media->BlockSize);
+	sz = roundup(sz, bdev->bio->Media->BlockSize);
+	buf = AllocatePool(sz);
+	if (!buf)
+		return ENOMEM;
+
+	status = uefi_call_wrapper(bdev->bio->ReadBlocks, 5, bdev->bio, bdev->media_id, GPT_HDR_BLKNO, sz, buf);
+	if (EFI_ERROR(status)) {
+		FreePool(buf);
+		return EIO;
+	}
+	memcpy(, buf, sizeof(hdr));
+	FreePool(buf);
+
+	if (memcmp(hdr.hdr_sig, GPT_HDR_SIG, sizeof(hdr.hdr_sig)) != 0)
+		return ENOENT;
+	if (le32toh(hdr.hdr_entsz) < sizeof(ent))
+		return EINVAL;
+
+	sz = __MAX(le32toh(hdr.hdr_entsz) * le32toh(hdr.hdr_entries), bdev->bio->Media->BlockSize);
+	sz = roundup(sz, bdev->bio->Media->BlockSize);
+	buf = AllocatePool(sz);
+	if (!buf)
+		return ENOMEM;
+
+	status = uefi_call_wrapper(bdev->bio->ReadBlocks, 5, bdev->bio, bdev->media_id, le64toh(hdr.hdr_lba_table), sz, buf);
+	if (EFI_ERROR(status)) {
+		FreePool(buf);
+		return EIO;
+	}
+
+	for (entry = 0; entry < le32toh(hdr.hdr_entries); entry++) {
+		memcpy(, buf + (entry * le32toh(hdr.hdr_entsz)), sizeof(ent));
+		efi_block_find_partitions_gpt_entry(bdev, , , entry);
+	}
+
+	FreePool(buf);
+
+	return 0;
+}
+
 static int
 efi_block_find_partitions(struct efi_block_dev *bdev)
 {
-	return efi_block_find_partitions_mbr(bdev);
+	int error;
+
+	error = efi_block_find_partitions_gpt(bdev);
+	if (error)
+		error = efi_block_find_partitions_mbr(bdev);
+
+	return error;
 }
 
 void
 efi_block_probe(void)
 {
 	struct efi_block_dev *bdev;
+	struct efi_block_part *bpart;
 	EFI_BLOCK_IO *bio;
 	EFI_STATUS status;
 	uint16_t devindex = 0;
@@ -234,13 +333,40 @@ efi_block_probe(void)
 		TAILQ_INIT(>partitions);
 		TAILQ_INSERT_TAIL(_block_devs, bdev, entries);
 
+		efi_block_find_partitions(bdev);
+
 		if (depth > 0 && efi_device_path_ncmp(efi_bootdp, DevicePathFromHandle(efi_block[n]), depth) == 0) {
-			char devname[9];
-			snprintf(devname, sizeof(devname), "hd%ua", bdev->index);
-			set_default_device(devname);
+			TAILQ_FOREACH(bpart, >partitions, entries) {
+uint8_t fstype = FS_UNUSED;
+switch (bpart->type) {
+case EFI_BLOCK_PART_DISKLABEL:
+	fstype = bpart->disklabel.part.p_fstype;
+	break;
+case EFI_BLOCK_PART_GPT:
+	fstype = bpart->gpt.fstype;
+	break;
+}
+if (fstype == FS_BSDFFS) {
+	char devname[9];
+	snprintf(devname, sizeof(devname), "hd%u%c", bdev->index, 

CVS commit: src/sys/stand/efiboot

2018-10-31 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Oct 31 23:49:34 UTC 2018

Modified Files:
src/sys/stand/efiboot: prompt.c

Log Message:
No need to re-print the countdown timer if the number of seconds hasn't changed.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/stand/efiboot/prompt.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/stand/efiboot/prompt.c
diff -u src/sys/stand/efiboot/prompt.c:1.3 src/sys/stand/efiboot/prompt.c:1.4
--- src/sys/stand/efiboot/prompt.c:1.3	Sat Sep 15 16:41:37 2018
+++ src/sys/stand/efiboot/prompt.c	Wed Oct 31 23:49:34 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: prompt.c,v 1.3 2018/09/15 16:41:37 jmcneill Exp $	*/
+/*	$NetBSD: prompt.c,v 1.4 2018/10/31 23:49:34 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997
@@ -73,6 +73,7 @@ char
 awaitkey(int timeout, int tell)
 {
 	int i = timeout * POLL_FREQ;
+	int last_secs = -1, secs;
 	char c = 0;
 
 	for (;;) {
@@ -80,13 +81,17 @@ awaitkey(int timeout, int tell)
 			char buf[32];
 			int len;
 
-			len = snprintf(buf, sizeof(buf), "%d seconds. ", (i + POLL_FREQ - 1) / POLL_FREQ);
-			if (len > 0 && len < sizeof(buf)) {
-char *p = buf;
-printf("%s", buf);
-while (*p)
-	*p++ = '\b';
-printf("%s", buf);
+			secs = (i + POLL_FREQ - 1) / POLL_FREQ;
+			if (secs != last_secs) {
+len = snprintf(buf, sizeof(buf), "%d seconds. ", (i + POLL_FREQ - 1) / POLL_FREQ);
+if (len > 0 && len < sizeof(buf)) {
+	char *p = buf;
+	printf("%s", buf);
+	while (*p)
+		*p++ = '\b';
+	printf("%s", buf);
+}
+last_secs = secs;
 			}
 		}
 		if (ischar()) {



CVS commit: src/sys/stand/efiboot

2018-10-31 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Oct 31 13:00:35 UTC 2018

Modified Files:
src/sys/stand/efiboot: efiboot.c

Log Message:
Assign VAs for EFI runtime mmio ranges


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/stand/efiboot/efiboot.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/stand/efiboot/efiboot.c
diff -u src/sys/stand/efiboot/efiboot.c:1.10 src/sys/stand/efiboot/efiboot.c:1.11
--- src/sys/stand/efiboot/efiboot.c:1.10	Sun Oct 28 10:17:47 2018
+++ src/sys/stand/efiboot/efiboot.c	Wed Oct 31 13:00:35 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efiboot.c,v 1.10 2018/10/28 10:17:47 jmcneill Exp $ */
+/* $NetBSD: efiboot.c,v 1.11 2018/10/31 13:00:35 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -144,6 +144,11 @@ efi_set_virtual_address_map(EFI_MEMORY_D
 			fdt_appendprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,uefi-runtime-data", md->VirtualStart);
 			fdt_appendprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,uefi-runtime-data", md->NumberOfPages * EFI_PAGE_SIZE);
 			break;
+		case EfiMemoryMappedIO:
+			fdt_appendprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,uefi-runtime-mmio", md->PhysicalStart);
+			fdt_appendprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,uefi-runtime-mmio", md->VirtualStart);
+			fdt_appendprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,uefi-runtime-mmio", md->NumberOfPages * EFI_PAGE_SIZE);
+			break;
 		default:
 			break;
 		}



CVS commit: src/sys/stand/efiboot

2018-10-31 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Oct 31 12:59:43 UTC 2018

Modified Files:
src/sys/stand/efiboot: efifdt.c

Log Message:
When building /memory, skip EFI runtime memory ranges


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/stand/efiboot/efifdt.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/stand/efiboot/efifdt.c
diff -u src/sys/stand/efiboot/efifdt.c:1.10 src/sys/stand/efiboot/efifdt.c:1.11
--- src/sys/stand/efiboot/efifdt.c:1.10	Wed Oct 31 09:13:32 2018
+++ src/sys/stand/efiboot/efifdt.c	Wed Oct 31 12:59:43 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.c,v 1.10 2018/10/31 09:13:32 jmcneill Exp $ */
+/* $NetBSD: efifdt.c,v 1.11 2018/10/31 12:59:43 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -158,6 +158,8 @@ efi_fdt_memory_map(void)
 		md->PhysicalStart, md->VirtualStart,
 		(u_long)md->NumberOfPages * EFI_PAGE_SIZE);
 #endif
+		if ((md->Attribute & EFI_MEMORY_RUNTIME) != 0)
+			continue;
 		if ((md->Attribute & EFI_MEMORY_WB) == 0)
 			continue;
 		if (!FDT_MEMORY_USABLE(md))



CVS commit: src/sys/stand/efiboot

2018-10-31 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Oct 31 09:13:32 UTC 2018

Modified Files:
src/sys/stand/efiboot: efifdt.c

Log Message:
No longer need to delete reserved memory ranges.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/stand/efiboot/efifdt.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/stand/efiboot/efifdt.c
diff -u src/sys/stand/efiboot/efifdt.c:1.9 src/sys/stand/efiboot/efifdt.c:1.10
--- src/sys/stand/efiboot/efifdt.c:1.9	Sun Sep  9 13:37:54 2018
+++ src/sys/stand/efiboot/efifdt.c	Wed Oct 31 09:13:32 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.c,v 1.9 2018/09/09 13:37:54 jmcneill Exp $ */
+/* $NetBSD: efifdt.c,v 1.10 2018/10/31 09:13:32 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -146,10 +146,6 @@ efi_fdt_memory_map(void)
 		panic("FDT: Failed to create " FDT_MEMORY_NODE_PATH " node");
 
 	fdt_delprop(fdt_data, memory, "reg");
-	while (fdt_num_mem_rsv(fdt_data) > 0) {
-		if (fdt_del_mem_rsv(fdt_data, 0) < 0)
-			panic("FDT: Failed to remove reserved memory map entry");
-	}
 
 	const int address_cells = fdt_address_cells(fdt_data, fdt_path_offset(fdt_data, "/"));
 	const int size_cells = fdt_size_cells(fdt_data, fdt_path_offset(fdt_data, "/"));



CVS commit: src/sys/stand/efiboot

2018-10-28 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Oct 29 05:15:21 UTC 2018

Modified Files:
src/sys/stand/efiboot: boot.c

Log Message:
avoid sign/unsigned issue and for NUMNAMES to an integer when it is
compared against a value that may be -1.

fixes autoboot when boot-file is set.  (serves me right for removing
code that looked odd when it was tested :-)


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/stand/efiboot/boot.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/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.11 src/sys/stand/efiboot/boot.c:1.12
--- src/sys/stand/efiboot/boot.c:1.11	Fri Oct 26 20:56:35 2018
+++ src/sys/stand/efiboot/boot.c	Mon Oct 29 05:15:21 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.11 2018/10/26 20:56:35 mrg Exp $	*/
+/*	$NetBSD: boot.c,v 1.12 2018/10/29 05:15:21 mrg Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -351,7 +351,7 @@ boot(void)
 	else
 		currname = 0;
 
-	for (; currname < NUMNAMES; currname++) {
+	for (; currname < (int)NUMNAMES; currname++) {
 		if (currname >= 0)
 			set_bootfile(names[currname]);
 		printf("booting %s - starting in ", bootfile);



CVS commit: src/sys/stand/efiboot

2018-10-28 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Oct 28 10:17:47 UTC 2018

Modified Files:
src/sys/stand/efiboot: efiacpi.c efiboot.c exec.c version
src/sys/stand/efiboot/bootaa64: Makefile

Log Message:
Make EFI runtime services available to the kernel. Bump version to 1.5.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/stand/efiboot/efiacpi.c
cvs rdiff -u -r1.9 -r1.10 src/sys/stand/efiboot/efiboot.c
cvs rdiff -u -r1.7 -r1.8 src/sys/stand/efiboot/exec.c
cvs rdiff -u -r1.5 -r1.6 src/sys/stand/efiboot/version
cvs rdiff -u -r1.4 -r1.5 src/sys/stand/efiboot/bootaa64/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/stand/efiboot/efiacpi.c
diff -u src/sys/stand/efiboot/efiacpi.c:1.2 src/sys/stand/efiboot/efiacpi.c:1.3
--- src/sys/stand/efiboot/efiacpi.c:1.2	Tue Oct 23 10:12:59 2018
+++ src/sys/stand/efiboot/efiacpi.c	Sun Oct 28 10:17:47 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efiacpi.c,v 1.2 2018/10/23 10:12:59 jmcneill Exp $ */
+/* $NetBSD: efiacpi.c,v 1.3 2018/10/28 10:17:47 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -103,6 +103,9 @@ efi_acpi_create_fdt(void)
 	fdt_setprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,acpi-root-table", (uint64_t)(uintptr_t)acpi_root);
 	if (smbios3_table)
 		fdt_setprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,smbios-table", (uint64_t)(uintptr_t)smbios3_table);
+#ifdef EFIBOOT_RUNTIME_ADDRESS
+	fdt_setprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,uefi-system-table", (uint64_t)(uintptr_t)ST);
+#endif
 
 	fdt_add_subnode(fdt, fdt_path_offset(fdt, "/"), "acpi");
 	fdt_setprop_string(fdt, fdt_path_offset(fdt, "/acpi"), "compatible", "netbsd,acpi");

Index: src/sys/stand/efiboot/efiboot.c
diff -u src/sys/stand/efiboot/efiboot.c:1.9 src/sys/stand/efiboot/efiboot.c:1.10
--- src/sys/stand/efiboot/efiboot.c:1.9	Fri Oct 12 22:08:04 2018
+++ src/sys/stand/efiboot/efiboot.c	Sun Oct 28 10:17:47 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efiboot.c,v 1.9 2018/10/12 22:08:04 jmcneill Exp $ */
+/* $NetBSD: efiboot.c,v 1.10 2018/10/28 10:17:47 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -34,6 +34,8 @@
 
 #include 
 
+#include 
+
 EFI_HANDLE IH;
 EFI_DEVICE_PATH *efi_bootdp;
 EFI_LOADED_IMAGE *efi_li;
@@ -41,7 +43,7 @@ EFI_LOADED_IMAGE *efi_li;
 int howto = 0;
 
 static EFI_PHYSICAL_ADDRESS heap_start;
-static UINTN heap_size = 1 * 1024 * 1024;
+static UINTN heap_size = 8 * 1024 * 1024;
 static EFI_EVENT delay_ev = 0;
 
 EFI_STATUS EFIAPI efi_main(EFI_HANDLE, EFI_SYSTEM_TABLE *);
@@ -92,18 +94,92 @@ efi_main(EFI_HANDLE imageHandle, EFI_SYS
 	return EFI_SUCCESS;
 }
 
+#ifdef EFIBOOT_RUNTIME_ADDRESS
+static uint64_t
+efi_runtime_alloc_va(uint64_t npages)
+{
+	static uint64_t va = EFIBOOT_RUNTIME_ADDRESS;
+	static uint64_t sz = EFIBOOT_RUNTIME_SIZE;
+	uint64_t nva;
+
+	if (sz < (npages * EFI_PAGE_SIZE))
+		panic("efi_acpi_alloc_va: couldn't allocate %" PRIu64 " pages", npages);
+
+	nva = va;
+	va += (npages * EFI_PAGE_SIZE);
+	sz -= (npages * EFI_PAGE_SIZE);
+
+	return nva;
+}
+#endif
+
+#ifdef EFIBOOT_RUNTIME_ADDRESS
+static void
+efi_set_virtual_address_map(EFI_MEMORY_DESCRIPTOR *memmap, UINTN nentries, UINTN mapkey, UINTN descsize, UINT32 descver)
+{
+	EFI_MEMORY_DESCRIPTOR *md, *vmd, *vmemmap;
+	EFI_STATUS status;
+	int n, nrt;
+	void *fdt;
+
+	fdt = efi_fdt_data();
+
+	vmemmap = alloc(nentries * descsize);
+	if (vmemmap == NULL)
+		panic("FATAL: couldn't allocate virtual memory map");
+
+	for (n = 0, nrt = 0, vmd = vmemmap, md = memmap; n < nentries; n++, md = NextMemoryDescriptor(md, descsize)) {
+		if ((md->Attribute & EFI_MEMORY_RUNTIME) == 0)
+			continue;
+		md->VirtualStart = efi_runtime_alloc_va(md->NumberOfPages);
+
+		switch (md->Type) {
+		case EfiRuntimeServicesCode:
+			fdt_appendprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,uefi-runtime-code", md->PhysicalStart);
+			fdt_appendprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,uefi-runtime-code", md->VirtualStart);
+			fdt_appendprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,uefi-runtime-code", md->NumberOfPages * EFI_PAGE_SIZE);
+			break;
+		case EfiRuntimeServicesData:
+			fdt_appendprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,uefi-runtime-data", md->PhysicalStart);
+			fdt_appendprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,uefi-runtime-data", md->VirtualStart);
+			fdt_appendprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,uefi-runtime-data", md->NumberOfPages * EFI_PAGE_SIZE);
+			break;
+		default:
+			break;
+		}
+
+		*vmd = *md;
+		vmd = NextMemoryDescriptor(vmd, descsize);
+		++nrt;
+	}
+
+	status = uefi_call_wrapper(RT->SetVirtualAddressMap, 4, nrt * descsize, descsize, descver, vmemmap);
+	if (EFI_ERROR(status)) {
+		printf("WARNING: SetVirtualAddressMap failed\n");
+		return;
+	}
+}
+#endif
+
 void
 efi_cleanup(void)
 {
 	EFI_STATUS status;
+	

CVS commit: src/sys/stand/efiboot

2018-10-26 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Fri Oct 26 20:56:35 UTC 2018

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

Log Message:
add "boot-file" support.  now one can automatically boot a
non-default kernel with "setenv boot-file host/netbsd".

this is particularly useful with the current net / tftp
kernel boot, so the tftproot does not need a "/netbsd"
visible to all hosts, but some host-specific path.

some minor clean up.

version 1.4.

ok jmcneill@.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/stand/efiboot/boot.c
cvs rdiff -u -r1.7 -r1.8 src/sys/stand/efiboot/efiboot.h
cvs rdiff -u -r1.4 -r1.5 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/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.10 src/sys/stand/efiboot/boot.c:1.11
--- src/sys/stand/efiboot/boot.c:1.10	Fri Oct 12 22:08:04 2018
+++ src/sys/stand/efiboot/boot.c	Fri Oct 26 20:56:35 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.10 2018/10/12 22:08:04 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.11 2018/10/26 20:56:35 mrg Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -43,20 +43,23 @@ extern const char bootprog_name[], bootp
 
 extern char twiddle_toggle;
 
-static const char * const names[][2] = {
-	{ "netbsd", "netbsd.gz" },
-	{ "onetbsd", "onetbsd.gz" },
-	{ "netbsd.old", "netbsd.old.gz" },
+static const char * const names[] = {
+	"netbsd", "netbsd.gz",
+	"onetbsd", "onetbsd.gz",
+	"netbsd.old", "netbsd.old.gz",
 };
 
 #define NUMNAMES	__arraycount(names)
-#define DEFFILENAME	names[0][0]
-
-#define	DEFTIMEOUT	5
 
 static char default_device[32];
 static char initrd_path[255];
 static char dtb_path[255];
+static char bootfile[255];
+
+#define	DEFTIMEOUT	5
+#define DEFFILENAME	names[0]
+
+int	set_bootfile(const char *);
 
 void	command_boot(char *);
 void	command_dev(char *);
@@ -106,9 +109,13 @@ void
 command_boot(char *arg)
 {
 	char *fname = arg;
+	const char *kernel = *fname ? fname : bootfile;
 	char *bootargs = gettrailer(arg);
 
-	exec_netbsd(*fname ? fname : DEFFILENAME, bootargs);
+	if (!kernel || !*kernel)
+		kernel = DEFFILENAME;
+
+	exec_netbsd(kernel, bootargs);
 }
 
 void
@@ -227,7 +234,7 @@ command_reset(char *arg)
 }
 
 int
-set_default_device(char *arg)
+set_default_device(const char *arg)
 {
 	if (strlen(arg) + 1 > sizeof(default_device))
 		return ERANGE;
@@ -242,7 +249,7 @@ get_default_device(void)
 }
 
 int
-set_initrd_path(char *arg)
+set_initrd_path(const char *arg)
 {
 	if (strlen(arg) + 1 > sizeof(initrd_path))
 		return ERANGE;
@@ -257,7 +264,7 @@ get_initrd_path(void)
 }
 
 int
-set_dtb_path(char *arg)
+set_dtb_path(const char *arg)
 {
 	if (strlen(arg) + 1 > sizeof(dtb_path))
 		return ERANGE;
@@ -271,6 +278,15 @@ get_dtb_path(void)
 	return dtb_path;
 }
 
+int
+set_bootfile(const char *arg)
+{
+	if (strlen(arg) + 1 > sizeof(bootfile))
+		return ERANGE;
+	strcpy(bootfile, arg);
+	return 0;
+}
+
 void
 print_banner(void)
 {
@@ -302,6 +318,15 @@ read_env(void)
 		FreePool(s);
 	}
 
+	s = efi_env_get("bootfile");
+	if (s) {
+#ifdef EFIBOOT_DEBUG
+		printf(">> Setting bootfile path to '%s' from environment\n", s);
+#endif
+		set_bootfile(s);
+		FreePool(s);
+	}
+
 	s = efi_env_get("rootdev");
 	if (s) {
 #ifdef EFIBOOT_DEBUG
@@ -318,23 +343,24 @@ boot(void)
 	int currname, c;
 
 	read_env();
-
 	print_banner();
-
 	printf("Press return to boot now, any other key for boot prompt\n");
-	for (currname = 0; currname < NUMNAMES; currname++) {
-		printf("booting %s - starting in ", names[currname][0]);
+
+	if (bootfile[0] != '\0')
+		currname = -1;
+	else
+		currname = 0;
+
+	for (; currname < NUMNAMES; currname++) {
+		if (currname >= 0)
+			set_bootfile(names[currname]);
+		printf("booting %s - starting in ", bootfile);
 
 		c = awaitkey(DEFTIMEOUT, 1);
-		if ((c != '\r') && (c != '\n') && (c != '\0')) {
+		if (c != '\r' && c != '\n' && c != '\0')
 			bootprompt(); /* does not return */
-		}
 
-		/*
-		 * try pairs of names[] entries, foo and foo.gz
-		 */
-		exec_netbsd(names[currname][0], "");
-		exec_netbsd(names[currname][1], "");
+		exec_netbsd(bootfile, "");
 	}
 
 	bootprompt();	/* does not return */

Index: src/sys/stand/efiboot/efiboot.h
diff -u src/sys/stand/efiboot/efiboot.h:1.7 src/sys/stand/efiboot/efiboot.h:1.8
--- src/sys/stand/efiboot/efiboot.h:1.7	Sat Sep 15 17:06:32 2018
+++ src/sys/stand/efiboot/efiboot.h	Fri Oct 26 20:56:35 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: efiboot.h,v 1.7 2018/09/15 17:06:32 jmcneill Exp $	*/
+/*	$NetBSD: efiboot.h,v 1.8 2018/10/26 20:56:35 mrg Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -52,13 +52,12 @@ void clearit(void);
 void print_banner(void);
 extern const struct boot_command commands[];
 void command_help(char *);
-int set_default_device(char *);
+int set_default_device(const char *);
 char *get_default_device(void);
-int set_initrd_path(char *);
+int 

CVS commit: src/sys/stand/efiboot

2018-10-23 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Oct 23 10:13:00 UTC 2018

Modified Files:
src/sys/stand/efiboot: efiacpi.c

Log Message:
If an SMBIOS3 table is found, pass the address to the kernel via /chosen
"netbsd,smbios-table" property.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/stand/efiboot/efiacpi.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/stand/efiboot/efiacpi.c
diff -u src/sys/stand/efiboot/efiacpi.c:1.1 src/sys/stand/efiboot/efiacpi.c:1.2
--- src/sys/stand/efiboot/efiacpi.c:1.1	Fri Oct 12 22:08:04 2018
+++ src/sys/stand/efiboot/efiacpi.c	Tue Oct 23 10:12:59 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efiacpi.c,v 1.1 2018/10/12 22:08:04 jmcneill Exp $ */
+/* $NetBSD: efiacpi.c,v 1.2 2018/10/23 10:12:59 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -38,8 +38,10 @@
 #define	ACPI_FDT_SIZE	(64 * 1024)
 
 static EFI_GUID Acpi20TableGuid = ACPI_20_TABLE_GUID;
+static EFI_GUID Smbios3TableGuid = SMBIOS3_TABLE_GUID;
 
 static void *acpi_root = NULL;
+static void *smbios3_table = NULL;
 
 int
 efi_acpi_probe(void)
@@ -50,6 +52,10 @@ efi_acpi_probe(void)
 	if (EFI_ERROR(status))
 		return EIO;
 
+	status = LibGetSystemConfigurationTable(, _table);
+	if (EFI_ERROR(status))
+		smbios3_table = NULL;
+
 	return 0;
 }
 
@@ -65,7 +71,10 @@ efi_acpi_show(void)
 	if (!efi_acpi_available())
 		return;
 
-	printf("ACPI: RSDP %p\n", acpi_root);
+	printf("ACPI: RSDP %p", acpi_root);
+	if (smbios3_table)
+		printf(", SMBIOS %p", smbios3_table);
+	printf("\n");
 }
 
 int
@@ -92,6 +101,8 @@ efi_acpi_create_fdt(void)
 
 	fdt_add_subnode(fdt, fdt_path_offset(fdt, "/"), "chosen");
 	fdt_setprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,acpi-root-table", (uint64_t)(uintptr_t)acpi_root);
+	if (smbios3_table)
+		fdt_setprop_u64(fdt, fdt_path_offset(fdt, "/chosen"), "netbsd,smbios-table", (uint64_t)(uintptr_t)smbios3_table);
 
 	fdt_add_subnode(fdt, fdt_path_offset(fdt, "/"), "acpi");
 	fdt_setprop_string(fdt, fdt_path_offset(fdt, "/acpi"), "compatible", "netbsd,acpi");



CVS commit: src/sys/stand/efiboot

2018-10-20 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Oct 21 00:57:38 UTC 2018

Modified Files:
src/sys/stand/efiboot: version
src/sys/stand/efiboot/bootaa64: Makefile

Log Message:
Enable ACPI support.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/stand/efiboot/version
cvs rdiff -u -r1.3 -r1.4 src/sys/stand/efiboot/bootaa64/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/stand/efiboot/version
diff -u src/sys/stand/efiboot/version:1.3 src/sys/stand/efiboot/version:1.4
--- src/sys/stand/efiboot/version:1.3	Sun Sep  9 17:55:22 2018
+++ src/sys/stand/efiboot/version	Sun Oct 21 00:57:38 2018
@@ -1,4 +1,4 @@
-$NetBSD: version,v 1.3 2018/09/09 17:55:22 jmcneill Exp $
+$NetBSD: version,v 1.4 2018/10/21 00:57:38 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
@@ -7,3 +7,4 @@ is taken as the current.
 1.0:	Initial version.
 1.1:	Add PXE booting support.
 1.2:	Add environment variable support.
+1.3:	Add ACPI support.

Index: src/sys/stand/efiboot/bootaa64/Makefile
diff -u src/sys/stand/efiboot/bootaa64/Makefile:1.3 src/sys/stand/efiboot/bootaa64/Makefile:1.4
--- src/sys/stand/efiboot/bootaa64/Makefile:1.3	Fri Oct 12 22:08:04 2018
+++ src/sys/stand/efiboot/bootaa64/Makefile	Sun Oct 21 00:57:38 2018
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.3 2018/10/12 22:08:04 jmcneill Exp $
+# $NetBSD: Makefile,v 1.4 2018/10/21 00:57:38 jmcneill Exp $
 
 PROG=		bootaa64.efi
 OBJFMT=		binary
@@ -9,7 +9,7 @@ EXTRA_SOURCES+=	cache.S
 
 COPTS+=		-mgeneral-regs-only -fno-jump-tables
 CFLAGS+=	-DEFIBOOT_ALIGN=0x20
-#CFLAGS+=	-DEFIBOOT_ACPI
+CFLAGS+=	-DEFIBOOT_ACPI
 
 .include "${.CURDIR}/../Makefile.efiboot"
 



CVS commit: src/sys/stand/efiboot

2018-10-12 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Oct 12 22:08:04 UTC 2018

Modified Files:
src/sys/stand/efiboot: Makefile.efiboot boot.c efiboot.c exec.c
src/sys/stand/efiboot/bootaa64: Makefile
Added Files:
src/sys/stand/efiboot: efiacpi.c efiacpi.h

Log Message:
Add ACPI support (enable with -DEFIBOOT_ACPI, currently disabled).

When UEFI reports that ACPI tables are available, generate a DTB with
compatible string "netbsd,generic-acpi" and pass this to the booted
kernel.

The DTB contains a /chosen property "netbsd,acpi-root-table" that contains
the physical address of the ACPI RSDP, along with a special /acpi node
with compatible string "netbsd,acpi" for the kernel to attach an acpi(4)
device driver.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/stand/efiboot/Makefile.efiboot
cvs rdiff -u -r1.9 -r1.10 src/sys/stand/efiboot/boot.c
cvs rdiff -u -r0 -r1.1 src/sys/stand/efiboot/efiacpi.c \
src/sys/stand/efiboot/efiacpi.h
cvs rdiff -u -r1.8 -r1.9 src/sys/stand/efiboot/efiboot.c
cvs rdiff -u -r1.6 -r1.7 src/sys/stand/efiboot/exec.c
cvs rdiff -u -r1.2 -r1.3 src/sys/stand/efiboot/bootaa64/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/stand/efiboot/Makefile.efiboot
diff -u src/sys/stand/efiboot/Makefile.efiboot:1.5 src/sys/stand/efiboot/Makefile.efiboot:1.6
--- src/sys/stand/efiboot/Makefile.efiboot:1.5	Sat Sep 15 17:06:32 2018
+++ src/sys/stand/efiboot/Makefile.efiboot	Fri Oct 12 22:08:04 2018
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.5 2018/09/15 17:06:32 jmcneill Exp $
+# $NetBSD: Makefile.efiboot,v 1.6 2018/10/12 22:08:04 jmcneill Exp $
 
 S=		${.CURDIR}/../../..
 
@@ -22,7 +22,7 @@ AFLAGS.start.S= ${${ACTIVE_CC} == "clang
 .PATH: ${EFIDIR}/gnuefi
 SOURCES=	crt0-efi-${GNUEFIARCH}.S reloc_${GNUEFIARCH}.c
 SOURCES+=	boot.c conf.c console.c dev_net.c devopen.c exec.c panic.c prompt.c
-SOURCES+=	efiboot.c efichar.c efidev.c efienv.c efigetsecs.c efifdt.c efifile.c efiblock.c efinet.c efipxe.c
+SOURCES+=	efiboot.c efichar.c efidev.c efienv.c efigetsecs.c efifdt.c efifile.c efiblock.c efinet.c efipxe.c efiacpi.c
 
 .PATH: ${S}/external/bsd/libfdt/dist
 CPPFLAGS+=	-I${S}/external/bsd/libfdt/dist

Index: src/sys/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.9 src/sys/stand/efiboot/boot.c:1.10
--- src/sys/stand/efiboot/boot.c:1.9	Sun Sep  9 18:00:20 2018
+++ src/sys/stand/efiboot/boot.c	Fri Oct 12 22:08:04 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.9 2018/09/09 18:00:20 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.10 2018/10/12 22:08:04 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -30,6 +30,7 @@
 #include "efiboot.h"
 #include "efiblock.h"
 #include "efifdt.h"
+#include "efiacpi.h"
 #include "efienv.h"
 
 #include 
@@ -210,6 +211,7 @@ command_version(char *arg)
 	}
 
 	efi_fdt_show();
+	efi_acpi_show();
 }
 
 void

Index: src/sys/stand/efiboot/efiboot.c
diff -u src/sys/stand/efiboot/efiboot.c:1.8 src/sys/stand/efiboot/efiboot.c:1.9
--- src/sys/stand/efiboot/efiboot.c:1.8	Sat Sep 15 17:06:32 2018
+++ src/sys/stand/efiboot/efiboot.c	Fri Oct 12 22:08:04 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efiboot.c,v 1.8 2018/09/15 17:06:32 jmcneill Exp $ */
+/* $NetBSD: efiboot.c,v 1.9 2018/10/12 22:08:04 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -30,6 +30,7 @@
 #include "efifile.h"
 #include "efiblock.h"
 #include "efifdt.h"
+#include "efiacpi.h"
 
 #include 
 
@@ -79,6 +80,7 @@ efi_main(EFI_HANDLE imageHandle, EFI_SYS
 	Print(L"Image file: %s\n", DevicePathToStr(efi_li->FilePath));
 #endif
 
+	efi_acpi_probe();
 	efi_fdt_probe();
 	efi_file_system_probe();
 	efi_block_probe();

Index: src/sys/stand/efiboot/exec.c
diff -u src/sys/stand/efiboot/exec.c:1.6 src/sys/stand/efiboot/exec.c:1.7
--- src/sys/stand/efiboot/exec.c:1.6	Sat Sep 15 17:06:32 2018
+++ src/sys/stand/efiboot/exec.c	Fri Oct 12 22:08:04 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.c,v 1.6 2018/09/15 17:06:32 jmcneill Exp $ */
+/* $NetBSD: exec.c,v 1.7 2018/10/12 22:08:04 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -28,6 +28,7 @@
 
 #include "efiboot.h"
 #include "efifdt.h"
+#include "efiacpi.h"
 
 #include 
 
@@ -152,6 +153,11 @@ exec_netbsd(const char *fname, const cha
 	close(fd);
 	load_offset = 0;
 
+#ifdef EFIBOOT_ACPI
+	if (efi_acpi_available()) {
+		efi_acpi_create_fdt();
+	} else
+#endif
 	if (dtb_addr && efi_fdt_set_data((void *)dtb_addr) != 0) {
 		printf("boot: invalid DTB data\n");
 		goto cleanup;

Index: src/sys/stand/efiboot/bootaa64/Makefile
diff -u src/sys/stand/efiboot/bootaa64/Makefile:1.2 src/sys/stand/efiboot/bootaa64/Makefile:1.3
--- src/sys/stand/efiboot/bootaa64/Makefile:1.2	Mon Aug 27 22:40:51 2018
+++ src/sys/stand/efiboot/bootaa64/Makefile	Fri Oct 12 22:08:04 2018
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.2 2018/08/27 22:40:51 jmcneill Exp $
+# $NetBSD: Makefile,v 1.3 2018/10/12 

CVS commit: src/sys/stand/efiboot

2018-09-18 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Sep 18 19:19:45 UTC 2018

Modified Files:
src/sys/stand/efiboot: efienv.c

Log Message:
utf8_to_ucs2 second param (nmp) needs to be initialized before calling this 
function


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/stand/efiboot/efienv.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/stand/efiboot/efienv.c
diff -u src/sys/stand/efiboot/efienv.c:1.1 src/sys/stand/efiboot/efienv.c:1.2
--- src/sys/stand/efiboot/efienv.c:1.1	Sun Sep  9 17:55:22 2018
+++ src/sys/stand/efiboot/efienv.c	Tue Sep 18 19:19:45 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efienv.c,v 1.1 2018/09/09 17:55:22 jmcneill Exp $ */
+/* $NetBSD: efienv.c,v 1.2 2018/09/18 19:19:45 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -39,16 +39,12 @@ efi_env_set(const char *key, char *val)
 {
 	EFI_STATUS status;
 	CHAR16 *ukey;
-	char *data;
 	size_t len;
 
-	data = AllocatePool(strlen(val) + 1);
-	strcpy(data, val);
-
+	ukey = NULL;
 	utf8_to_ucs2(key, , );
-	status = LibSetNVVariable(ukey, , strlen(data) + 1, data);
+	status = LibSetNVVariable(ukey, , strlen(val) + 1, val);
 	FreePool(ukey);
-	FreePool(data);
 
 	if (EFI_ERROR(status))
 		printf("env: failed to set variable '%s': %#lx\n", key, status);
@@ -61,6 +57,7 @@ efi_env_get(const char *key)
 	size_t len;
 	char *ret;
 
+	ukey = NULL;
 	utf8_to_ucs2(key, , );
 	ret = LibGetVariable(ukey, );
 	FreePool(ukey);
@@ -74,6 +71,7 @@ efi_env_clear(const char *key)
 	CHAR16 *ukey;
 	size_t len;
 
+	ukey = NULL;
 	utf8_to_ucs2(key, , );
 	LibDeleteVariable(ukey, );
 	FreePool(ukey);



CVS commit: src/sys/stand/efiboot

2018-09-15 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Sep 15 17:06:32 UTC 2018

Modified Files:
src/sys/stand/efiboot: Makefile.efiboot efiboot.c efiboot.h exec.c

Log Message:
Suppress printing size info when calling loadfile with COUNT_KERNEL


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/stand/efiboot/Makefile.efiboot
cvs rdiff -u -r1.7 -r1.8 src/sys/stand/efiboot/efiboot.c
cvs rdiff -u -r1.6 -r1.7 src/sys/stand/efiboot/efiboot.h
cvs rdiff -u -r1.5 -r1.6 src/sys/stand/efiboot/exec.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/stand/efiboot/Makefile.efiboot
diff -u src/sys/stand/efiboot/Makefile.efiboot:1.4 src/sys/stand/efiboot/Makefile.efiboot:1.5
--- src/sys/stand/efiboot/Makefile.efiboot:1.4	Sun Sep  9 17:55:22 2018
+++ src/sys/stand/efiboot/Makefile.efiboot	Sat Sep 15 17:06:32 2018
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.4 2018/09/09 17:55:22 jmcneill Exp $
+# $NetBSD: Makefile.efiboot,v 1.5 2018/09/15 17:06:32 jmcneill Exp $
 
 S=		${.CURDIR}/../../..
 
@@ -61,6 +61,7 @@ LDFLAGS+= --defsym=EFI_SUBSYSTEM=0xa
 COPTS+= ${${ACTIVE_CC} == "gcc":? -Wno-error=unused-but-set-variable :}
 CPPFLAGS+= -nostdinc -D_STANDALONE
 CPPFLAGS+= -DEFIBOOT
+CPPFLAGS+= -DPROGRESS_FN=efi_progress
 
 CPPFLAGS+= -Wall -Wmissing-prototypes
 CPPFLAGS+= -Wno-pointer-sign

Index: src/sys/stand/efiboot/efiboot.c
diff -u src/sys/stand/efiboot/efiboot.c:1.7 src/sys/stand/efiboot/efiboot.c:1.8
--- src/sys/stand/efiboot/efiboot.c:1.7	Sat Sep 15 16:41:57 2018
+++ src/sys/stand/efiboot/efiboot.c	Sat Sep 15 17:06:32 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efiboot.c,v 1.7 2018/09/15 16:41:57 jmcneill Exp $ */
+/* $NetBSD: efiboot.c,v 1.8 2018/09/15 17:06:32 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -31,10 +31,14 @@
 #include "efiblock.h"
 #include "efifdt.h"
 
+#include 
+
 EFI_HANDLE IH;
 EFI_DEVICE_PATH *efi_bootdp;
 EFI_LOADED_IMAGE *efi_li;
 
+int howto = 0;
+
 static EFI_PHYSICAL_ADDRESS heap_start;
 static UINTN heap_size = 1 * 1024 * 1024;
 static EFI_EVENT delay_ev = 0;
@@ -133,3 +137,16 @@ efi_delay(int us)
 	uefi_call_wrapper(BS->SetTimer, 3, delay_ev, TimerRelative, us * 10);
 	uefi_call_wrapper(BS->WaitForEvent, 3, 1, _ev, );
 }
+
+void
+efi_progress(const char *fmt, ...)
+{
+	va_list ap;
+
+	if ((howto & AB_SILENT) != 0)
+		return;
+
+	va_start(ap, fmt);
+	vprintf(fmt, ap);
+	va_end(ap);
+}

Index: src/sys/stand/efiboot/efiboot.h
diff -u src/sys/stand/efiboot/efiboot.h:1.6 src/sys/stand/efiboot/efiboot.h:1.7
--- src/sys/stand/efiboot/efiboot.h:1.6	Sun Sep  9 18:00:20 2018
+++ src/sys/stand/efiboot/efiboot.h	Sat Sep 15 17:06:32 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: efiboot.h,v 1.6 2018/09/09 18:00:20 jmcneill Exp $	*/
+/*	$NetBSD: efiboot.h,v 1.7 2018/09/15 17:06:32 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -32,6 +32,8 @@
 #include 
 #include 
 
+#include 
+
 #include "efiboot_machdep.h"
 
 struct boot_command {
@@ -56,6 +58,7 @@ int set_initrd_path(char *);
 char *get_initrd_path(void);
 int set_dtb_path(char *);
 char *get_dtb_path(void);
+extern int howto;
 
 /* console.c */
 int ischar(void);

Index: src/sys/stand/efiboot/exec.c
diff -u src/sys/stand/efiboot/exec.c:1.5 src/sys/stand/efiboot/exec.c:1.6
--- src/sys/stand/efiboot/exec.c:1.5	Sun Sep  9 13:37:54 2018
+++ src/sys/stand/efiboot/exec.c	Sat Sep 15 17:06:32 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.c,v 1.5 2018/09/09 13:37:54 jmcneill Exp $ */
+/* $NetBSD: exec.c,v 1.6 2018/09/15 17:06:32 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -29,7 +29,7 @@
 #include "efiboot.h"
 #include "efifdt.h"
 
-#include 
+#include 
 
 u_long load_offset = 0;
 
@@ -109,13 +109,16 @@ exec_netbsd(const char *fname, const cha
 	EFI_PHYSICAL_ADDRESS addr;
 	u_long marks[MARK_MAX], alloc_size;
 	EFI_STATUS status;
-	int fd;
+	int fd, ohowto;
 
 	load_file(get_initrd_path(), _addr, _size);
 	load_file(get_dtb_path(), _addr, _size);
 
 	memset(marks, 0, sizeof(marks));
+	ohowto = howto;
+	howto |= AB_SILENT;
 	fd = loadfile(fname, marks, COUNT_KERNEL | LOAD_NOTE);
+	howto = ohowto;
 	if (fd < 0) {
 		printf("boot: %s: %s\n", fname, strerror(errno));
 		return EIO;



CVS commit: src/sys/stand/efiboot

2018-09-15 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Sep 15 16:44:15 UTC 2018

Modified Files:
src/sys/stand/efiboot: console.c

Log Message:
Some U-Boot implementations (notably U-Boot) do not implement WaitForKey. Do 
the same as FreeBSD EFI loader here (I wrote the original patch there as well).


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/stand/efiboot/console.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/stand/efiboot/console.c
diff -u src/sys/stand/efiboot/console.c:1.1 src/sys/stand/efiboot/console.c:1.2
--- src/sys/stand/efiboot/console.c:1.1	Fri Aug 24 02:01:06 2018
+++ src/sys/stand/efiboot/console.c	Sat Sep 15 16:44:15 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: console.c,v 1.1 2018/08/24 02:01:06 jmcneill Exp $ */
+/* $NetBSD: console.c,v 1.2 2018/09/15 16:44:15 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -28,16 +28,25 @@
 
 #include "efiboot.h"
 
+static EFI_INPUT_KEY key_cur;
+static int key_pending;
+
 int
 getchar(void)
 {
 	EFI_STATUS status;
 	EFI_INPUT_KEY key;
 
-	status = uefi_call_wrapper(ST->ConIn->ReadKeyStroke, 2, ST->ConIn, );
-	while (status == EFI_NOT_READY) {
-		WaitForSingleEvent(ST->ConIn->WaitForKey, 0);
+	if (key_pending) {
+		key = key_cur;
+		key_pending = 0;
+	} else {
 		status = uefi_call_wrapper(ST->ConIn->ReadKeyStroke, 2, ST->ConIn, );
+		while (status == EFI_NOT_READY) {
+			if (ST->ConIn->WaitForKey != NULL)
+WaitForSingleEvent(ST->ConIn->WaitForKey, 0);
+			status = uefi_call_wrapper(ST->ConIn->ReadKeyStroke, 2, ST->ConIn, );
+		}
 	}
 
 	return key.UnicodeChar;
@@ -55,9 +64,20 @@ putchar(int c)
 int
 ischar(void)
 {
+	EFI_INPUT_KEY key;
 	EFI_STATUS status;
 
-	status = uefi_call_wrapper(BS->CheckEvent, 1, ST->ConIn->WaitForKey);
-
-	return status == EFI_SUCCESS;
+	if (ST->ConIn->WaitForKey == NULL) {
+		if (key_pending)
+			return 1;
+		status = uefi_call_wrapper(ST->ConIn->ReadKeyStroke, 2, ST->ConIn, );
+		if (status == EFI_SUCCESS) {
+			key_cur = key;
+			key_pending = 1;
+		}
+		return key_pending;
+	} else {
+		status = uefi_call_wrapper(BS->CheckEvent, 1, ST->ConIn->WaitForKey);
+		return status == EFI_SUCCESS;
+	}
 }



CVS commit: src/sys/stand/efiboot

2018-09-15 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Sep 15 16:41:57 UTC 2018

Modified Files:
src/sys/stand/efiboot: efiboot.c

Log Message:
Claer the screen at startup


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/stand/efiboot/efiboot.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/stand/efiboot/efiboot.c
diff -u src/sys/stand/efiboot/efiboot.c:1.6 src/sys/stand/efiboot/efiboot.c:1.7
--- src/sys/stand/efiboot/efiboot.c:1.6	Sun Sep  9 18:00:20 2018
+++ src/sys/stand/efiboot/efiboot.c	Sat Sep 15 16:41:57 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efiboot.c,v 1.6 2018/09/09 18:00:20 jmcneill Exp $ */
+/* $NetBSD: efiboot.c,v 1.7 2018/09/15 16:41:57 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -52,6 +52,8 @@ efi_main(EFI_HANDLE imageHandle, EFI_SYS
 	InitializeLib(imageHandle, systemTable);
 
 	(void)uefi_call_wrapper(ST->ConOut->Reset, 2, ST->ConOut, FALSE);
+	if (ST->ConOut->ClearScreen)
+		(void)uefi_call_wrapper(ST->ConOut->ClearScreen, 1, ST->ConOut);
 
 	status = uefi_call_wrapper(BS->AllocatePages, 4, AllocateAnyPages, EfiLoaderData, sz, _start);
 	if (EFI_ERROR(status))



CVS commit: src/sys/stand/efiboot

2018-09-15 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Sep 15 16:41:37 UTC 2018

Modified Files:
src/sys/stand/efiboot: prompt.c

Log Message:
Only need to ischar() once when polling for input


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/stand/efiboot/prompt.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/stand/efiboot/prompt.c
diff -u src/sys/stand/efiboot/prompt.c:1.2 src/sys/stand/efiboot/prompt.c:1.3
--- src/sys/stand/efiboot/prompt.c:1.2	Fri Aug 24 20:55:20 2018
+++ src/sys/stand/efiboot/prompt.c	Sat Sep 15 16:41:37 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: prompt.c,v 1.2 2018/08/24 20:55:20 jmcneill Exp $	*/
+/*	$NetBSD: prompt.c,v 1.3 2018/09/15 16:41:37 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997
@@ -90,8 +90,7 @@ awaitkey(int timeout, int tell)
 			}
 		}
 		if (ischar()) {
-			while (ischar())
-c = getchar();
+			c = getchar();
 			if (c == 0)
 c = -1;
 			goto out;



CVS commit: src/sys/stand/efiboot

2018-09-14 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Fri Sep 14 21:37:03 UTC 2018

Modified Files:
src/sys/stand/efiboot: efiblock.c

Log Message:
MI efiboot: avoid LBA overflow in efi_block_find_partitions_disklabel()


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/stand/efiboot/efiblock.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/stand/efiboot/efiblock.c
diff -u src/sys/stand/efiboot/efiblock.c:1.2 src/sys/stand/efiboot/efiblock.c:1.3
--- src/sys/stand/efiboot/efiblock.c:1.2	Mon Aug 27 09:51:32 2018
+++ src/sys/stand/efiboot/efiblock.c	Fri Sep 14 21:37:03 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.c,v 1.2 2018/08/27 09:51:32 jmcneill Exp $ */
+/* $NetBSD: efiblock.c,v 1.3 2018/09/14 21:37:03 jakllsch Exp $ */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -115,7 +115,7 @@ efi_block_find_partitions_disklabel(stru
 	if (!buf)
 		return ENOMEM;
 
-	lba = ((start + LABELSECTOR) * DEV_BSIZE) / bdev->bio->Media->BlockSize;
+	lba = (((EFI_LBA)start + LABELSECTOR) * DEV_BSIZE) / bdev->bio->Media->BlockSize;
 	status = uefi_call_wrapper(bdev->bio->ReadBlocks, 5, bdev->bio, bdev->media_id, lba, sz, buf);
 	if (EFI_ERROR(status) || getdisklabel(buf, ) != NULL) {
 		FreePool(buf);



CVS commit: src/sys/stand/efiboot

2018-09-09 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Sep  9 18:00:20 UTC 2018

Modified Files:
src/sys/stand/efiboot: boot.c efiboot.c efiboot.h

Log Message:
Add a reboot command to the bootloader


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/stand/efiboot/boot.c
cvs rdiff -u -r1.5 -r1.6 src/sys/stand/efiboot/efiboot.c \
src/sys/stand/efiboot/efiboot.h

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/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.8 src/sys/stand/efiboot/boot.c:1.9
--- src/sys/stand/efiboot/boot.c:1.8	Sun Sep  9 17:55:22 2018
+++ src/sys/stand/efiboot/boot.c	Sun Sep  9 18:00:20 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.8 2018/09/09 17:55:22 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.9 2018/09/09 18:00:20 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -80,6 +80,8 @@ const struct boot_command commands[] = {
 	{ "setenv",	command_setenv,		"setenv  " },
 	{ "clearenv",	command_clearenv,	"clearenv " },
 	{ "resetenv",	command_resetenv,	"resetenv" },
+	{ "reboot",	command_reset,		"reboot|reset" },
+	{ "reset",	command_reset,		NULL },
 	{ "version",	command_version,	"version" },
 	{ "help",	command_help,		"help|?" },
 	{ "?",		command_help,		NULL },
@@ -216,6 +218,12 @@ command_quit(char *arg)
 	efi_exit();
 }
 
+void
+command_reset(char *arg)
+{
+	efi_reboot();
+}
+
 int
 set_default_device(char *arg)
 {

Index: src/sys/stand/efiboot/efiboot.c
diff -u src/sys/stand/efiboot/efiboot.c:1.5 src/sys/stand/efiboot/efiboot.c:1.6
--- src/sys/stand/efiboot/efiboot.c:1.5	Mon Sep  3 00:04:02 2018
+++ src/sys/stand/efiboot/efiboot.c	Sun Sep  9 18:00:20 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efiboot.c,v 1.5 2018/09/03 00:04:02 jmcneill Exp $ */
+/* $NetBSD: efiboot.c,v 1.6 2018/09/09 18:00:20 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -109,6 +109,14 @@ efi_exit(void)
 }
 
 void
+efi_reboot(void)
+{
+	uefi_call_wrapper(RT->ResetSystem, 4, EfiResetCold, EFI_SUCCESS, 0, NULL);
+
+	printf("WARNING: Reset failed\n");
+}
+
+void
 efi_delay(int us)
 {
 	EFI_STATUS status;
Index: src/sys/stand/efiboot/efiboot.h
diff -u src/sys/stand/efiboot/efiboot.h:1.5 src/sys/stand/efiboot/efiboot.h:1.6
--- src/sys/stand/efiboot/efiboot.h:1.5	Sun Sep  9 13:37:54 2018
+++ src/sys/stand/efiboot/efiboot.h	Sun Sep  9 18:00:20 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: efiboot.h,v 1.5 2018/09/09 13:37:54 jmcneill Exp $	*/
+/*	$NetBSD: efiboot.h,v 1.6 2018/09/09 18:00:20 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -67,6 +67,7 @@ extern EFI_LOADED_IMAGE *efi_li;
 void efi_cleanup(void);
 void efi_exit(void);
 void efi_delay(int);
+void efi_reboot(void);
 
 /* efichar.c */
 size_t ucs2len(const CHAR16 *);



CVS commit: src/sys/stand/efiboot

2018-09-09 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Sep  9 17:55:22 UTC 2018

Modified Files:
src/sys/stand/efiboot: Makefile.efiboot boot.c version
Added Files:
src/sys/stand/efiboot: efienv.c efienv.h

Log Message:
Add support for setting environment variables. Currently the following env
vars are supported: "fdtfile", "initrd", and "rootdev".


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/stand/efiboot/Makefile.efiboot
cvs rdiff -u -r1.7 -r1.8 src/sys/stand/efiboot/boot.c
cvs rdiff -u -r0 -r1.1 src/sys/stand/efiboot/efienv.c \
src/sys/stand/efiboot/efienv.h
cvs rdiff -u -r1.2 -r1.3 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.3 src/sys/stand/efiboot/Makefile.efiboot:1.4
--- src/sys/stand/efiboot/Makefile.efiboot:1.3	Mon Sep  3 00:04:02 2018
+++ src/sys/stand/efiboot/Makefile.efiboot	Sun Sep  9 17:55:22 2018
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.3 2018/09/03 00:04:02 jmcneill Exp $
+# $NetBSD: Makefile.efiboot,v 1.4 2018/09/09 17:55:22 jmcneill Exp $
 
 S=		${.CURDIR}/../../..
 
@@ -22,7 +22,7 @@ AFLAGS.start.S= ${${ACTIVE_CC} == "clang
 .PATH: ${EFIDIR}/gnuefi
 SOURCES=	crt0-efi-${GNUEFIARCH}.S reloc_${GNUEFIARCH}.c
 SOURCES+=	boot.c conf.c console.c dev_net.c devopen.c exec.c panic.c prompt.c
-SOURCES+=	efiboot.c efichar.c efidev.c efigetsecs.c efifdt.c efifile.c efiblock.c efinet.c efipxe.c
+SOURCES+=	efiboot.c efichar.c efidev.c efienv.c efigetsecs.c efifdt.c efifile.c efiblock.c efinet.c efipxe.c
 
 .PATH: ${S}/external/bsd/libfdt/dist
 CPPFLAGS+=	-I${S}/external/bsd/libfdt/dist

Index: src/sys/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.7 src/sys/stand/efiboot/boot.c:1.8
--- src/sys/stand/efiboot/boot.c:1.7	Sun Sep  9 13:37:54 2018
+++ src/sys/stand/efiboot/boot.c	Sun Sep  9 17:55:22 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.7 2018/09/09 13:37:54 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.8 2018/09/09 17:55:22 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -30,6 +30,7 @@
 #include "efiboot.h"
 #include "efiblock.h"
 #include "efifdt.h"
+#include "efienv.h"
 
 #include 
 #include 
@@ -61,6 +62,10 @@ void	command_dev(char *);
 void	command_dtb(char *);
 void	command_initrd(char *);
 void	command_ls(char *);
+void	command_printenv(char *);
+void	command_setenv(char *);
+void	command_clearenv(char *);
+void	command_resetenv(char *);
 void	command_reset(char *);
 void	command_version(char *);
 void	command_quit(char *);
@@ -71,6 +76,10 @@ const struct boot_command commands[] = {
 	{ "dtb",	command_dtb,		"dtb [dev:][filename]" },
 	{ "initrd",	command_initrd,		"initrd [dev:][filename]" },
 	{ "ls",		command_ls,		"ls [hdNn:/path]" },
+	{ "printenv",	command_printenv,	"printenv [key]" },
+	{ "setenv",	command_setenv,		"setenv  " },
+	{ "clearenv",	command_clearenv,	"clearenv " },
+	{ "resetenv",	command_resetenv,	"resetenv" },
 	{ "version",	command_version,	"version" },
 	{ "help",	command_help,		"help|?" },
 	{ "?",		command_help,		NULL },
@@ -135,6 +144,53 @@ command_ls(char *arg)
 }
 
 void
+command_printenv(char *arg)
+{
+	char *val;
+
+	if (arg && *arg) {
+		val = efi_env_get(arg);
+		if (val) {
+			printf("\"%s\" = \"%s\"\n", arg, val);
+			FreePool(val);
+		}
+	} else {
+		efi_env_print();
+	}
+}
+
+void
+command_setenv(char *arg)
+{
+	char *spc;
+
+	spc = strchr(arg, ' ');
+	if (spc == NULL || spc[1] == '\0') {
+		command_help("");
+		return;
+	}
+
+	*spc = '\0';
+	efi_env_set(arg, spc + 1);
+}
+
+void
+command_clearenv(char *arg)
+{
+	if (*arg == '\0') {
+		command_help("");
+		return;
+	}
+	efi_env_clear(arg);
+}
+
+void
+command_resetenv(char *arg)
+{
+	efi_env_reset();
+}
+
+void
 command_version(char *arg)
 {
 	char *ufirmware;
@@ -213,11 +269,46 @@ print_banner(void)
 	bootprog_name, bootprog_rev, bootprog_kernrev);
 }
 
+static void
+read_env(void)
+{
+	char *s;
+
+	s = efi_env_get("fdtfile");
+	if (s) {
+#ifdef EFIBOOT_DEBUG
+		printf(">> Setting DTB path to '%s' from environment\n", s);
+#endif
+		set_dtb_path(s);
+		FreePool(s);
+	}
+
+	s = efi_env_get("initrd");
+	if (s) {
+#ifdef EFIBOOT_DEBUG
+		printf(">> Setting initrd path to '%s' from environment\n", s);
+#endif
+		set_initrd_path(s);
+		FreePool(s);
+	}
+
+	s = efi_env_get("rootdev");
+	if (s) {
+#ifdef EFIBOOT_DEBUG
+		printf(">> Setting default device to '%s' from environment\n", s);
+#endif
+		set_default_device(s);
+		FreePool(s);
+	}
+}
+
 void
 boot(void)
 {
 	int currname, c;
 
+	read_env();
+
 	print_banner();
 
 	printf("Press return to boot now, any other key for boot prompt\n");

Index: src/sys/stand/efiboot/version
diff -u src/sys/stand/efiboot/version:1.2 src/sys/stand/efiboot/version:1.3
--- src/sys/stand/efiboot/version:1.2	Mon Sep  3 00:04:02 2018
+++ src/sys/stand/efiboot/version	Sun Sep  9 

CVS commit: src/sys/stand/efiboot

2018-09-09 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Sep  9 13:37:54 UTC 2018

Modified Files:
src/sys/stand/efiboot: boot.c efiboot.h efifdt.c efifdt.h exec.c

Log Message:
Add "dtb" command for loading a custom .dtb file.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/stand/efiboot/boot.c
cvs rdiff -u -r1.4 -r1.5 src/sys/stand/efiboot/efiboot.h \
src/sys/stand/efiboot/exec.c
cvs rdiff -u -r1.8 -r1.9 src/sys/stand/efiboot/efifdt.c
cvs rdiff -u -r1.3 -r1.4 src/sys/stand/efiboot/efifdt.h

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/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.6 src/sys/stand/efiboot/boot.c:1.7
--- src/sys/stand/efiboot/boot.c:1.6	Fri Sep  7 17:30:58 2018
+++ src/sys/stand/efiboot/boot.c	Sun Sep  9 13:37:54 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.6 2018/09/07 17:30:58 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.7 2018/09/09 13:37:54 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -54,9 +54,11 @@ static const char * const names[][2] = {
 
 static char default_device[32];
 static char initrd_path[255];
+static char dtb_path[255];
 
 void	command_boot(char *);
 void	command_dev(char *);
+void	command_dtb(char *);
 void	command_initrd(char *);
 void	command_ls(char *);
 void	command_reset(char *);
@@ -66,6 +68,7 @@ void	command_quit(char *);
 const struct boot_command commands[] = {
 	{ "boot",	command_boot,		"boot [dev:][filename] [args]\n (ex. \"hd0a:\\netbsd.old -s\"" },
 	{ "dev",	command_dev,		"dev" },
+	{ "dtb",	command_dtb,		"dtb [dev:][filename]" },
 	{ "initrd",	command_initrd,		"initrd [dev:][filename]" },
 	{ "ls",		command_ls,		"ls [hdNn:/path]" },
 	{ "version",	command_version,	"version" },
@@ -114,6 +117,12 @@ command_dev(char *arg)
 }
 
 void
+command_dtb(char *arg)
+{
+	set_dtb_path(arg);
+}
+
+void
 command_initrd(char *arg)
 {
 	set_initrd_path(arg);
@@ -181,6 +190,21 @@ get_initrd_path(void)
 	return initrd_path;
 }
 
+int
+set_dtb_path(char *arg)
+{
+	if (strlen(arg) + 1 > sizeof(dtb_path))
+		return ERANGE;
+	strcpy(dtb_path, arg);
+	return 0;
+}
+
+char *
+get_dtb_path(void)
+{
+	return dtb_path;
+}
+
 void
 print_banner(void)
 {

Index: src/sys/stand/efiboot/efiboot.h
diff -u src/sys/stand/efiboot/efiboot.h:1.4 src/sys/stand/efiboot/efiboot.h:1.5
--- src/sys/stand/efiboot/efiboot.h:1.4	Fri Sep  7 17:30:58 2018
+++ src/sys/stand/efiboot/efiboot.h	Sun Sep  9 13:37:54 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: efiboot.h,v 1.4 2018/09/07 17:30:58 jmcneill Exp $	*/
+/*	$NetBSD: efiboot.h,v 1.5 2018/09/09 13:37:54 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -54,6 +54,8 @@ int set_default_device(char *);
 char *get_default_device(void);
 int set_initrd_path(char *);
 char *get_initrd_path(void);
+int set_dtb_path(char *);
+char *get_dtb_path(void);
 
 /* console.c */
 int ischar(void);
Index: src/sys/stand/efiboot/exec.c
diff -u src/sys/stand/efiboot/exec.c:1.4 src/sys/stand/efiboot/exec.c:1.5
--- src/sys/stand/efiboot/exec.c:1.4	Fri Sep  7 17:30:58 2018
+++ src/sys/stand/efiboot/exec.c	Sun Sep  9 13:37:54 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.c,v 1.4 2018/09/07 17:30:58 jmcneill Exp $ */
+/* $NetBSD: exec.c,v 1.5 2018/09/09 13:37:54 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -36,19 +36,17 @@ u_long load_offset = 0;
 #define	FDT_SPACE	(4 * 1024 * 1024)
 #define	FDT_ALIGN	((2 * 1024 * 1024) - 1)
 
-static EFI_PHYSICAL_ADDRESS initrd_addr;
-static u_long initrd_size = 0;
+static EFI_PHYSICAL_ADDRESS initrd_addr, dtb_addr;
+static u_long initrd_size = 0, dtb_size = 0;
 
 static int
-load_initrd(void)
+load_file(char *path, EFI_PHYSICAL_ADDRESS *paddr, u_long *psize)
 {
 	EFI_STATUS status;
 	struct stat st;
 	ssize_t len;
-	char *path;
 	int fd;
 
-	path = get_initrd_path();
 	if (strlen(path) == 0)
 		return 0;
 
@@ -63,44 +61,44 @@ load_initrd(void)
 		return errno;
 	}
 	if (st.st_size == 0) {
-		printf("boot: empty initrd %s\n", path);
+		printf("boot: empty file %s\n", path);
 		close(fd);
 		return EINVAL;
 	}
 
-	initrd_size = st.st_size;
+	*psize = st.st_size;
 
 #ifdef EFIBOOT_ALLOCATE_MAX_ADDRESS
-	initrd_addr = EFIBOOT_ALLOCATE_MAX_ADDRESS;
+	*paddr = EFIBOOT_ALLOCATE_MAX_ADDRESS;
 	status = uefi_call_wrapper(BS->AllocatePages, 4, AllocateMaxAddress, EfiLoaderData,
-	EFI_SIZE_TO_PAGES(initrd_size), _addr);
+	EFI_SIZE_TO_PAGES(*psize), paddr);
 #else
-	initrd_addr = 0;
+	*paddr = 0;
 	status = uefi_call_wrapper(BS->AllocatePages, 4, AllocateAnyPages, EfiLoaderData,
-	EFI_SIZE_TO_PAGES(initrd_size), _addr);
+	EFI_SIZE_TO_PAGES(*psize), paddr);
 #endif
 	if (EFI_ERROR(status)) {
-		printf("Failed to allocate %lu bytes for initrd image (error %lu)\n",
-		initrd_size, status);
+		printf("Failed to allocate %lu bytes for %s (error %lu)\n",
+		*psize, path, status);
 		close(fd);
 		return ENOMEM;
 	}
 
 	printf("boot: loading %s 

CVS commit: src/sys/stand/efiboot

2018-09-07 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Sep  7 17:30:59 UTC 2018

Modified Files:
src/sys/stand/efiboot: boot.c efiboot.h efifdt.c efifdt.h exec.c

Log Message:
Add initrd support.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/stand/efiboot/boot.c
cvs rdiff -u -r1.3 -r1.4 src/sys/stand/efiboot/efiboot.h \
src/sys/stand/efiboot/exec.c
cvs rdiff -u -r1.7 -r1.8 src/sys/stand/efiboot/efifdt.c
cvs rdiff -u -r1.2 -r1.3 src/sys/stand/efiboot/efifdt.h

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/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.5 src/sys/stand/efiboot/boot.c:1.6
--- src/sys/stand/efiboot/boot.c:1.5	Mon Sep  3 00:17:00 2018
+++ src/sys/stand/efiboot/boot.c	Fri Sep  7 17:30:58 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.5 2018/09/03 00:17:00 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.6 2018/09/07 17:30:58 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -53,17 +53,20 @@ static const char * const names[][2] = {
 #define	DEFTIMEOUT	5
 
 static char default_device[32];
+static char initrd_path[255];
 
 void	command_boot(char *);
 void	command_dev(char *);
+void	command_initrd(char *);
 void	command_ls(char *);
 void	command_reset(char *);
 void	command_version(char *);
 void	command_quit(char *);
 
 const struct boot_command commands[] = {
-	{ "boot",	command_boot,		"boot [fsN:][filename] [args]\n (ex. \"fs0:\\netbsd.old -s\"" },
+	{ "boot",	command_boot,		"boot [dev:][filename] [args]\n (ex. \"hd0a:\\netbsd.old -s\"" },
 	{ "dev",	command_dev,		"dev" },
+	{ "initrd",	command_initrd,		"initrd [dev:][filename]" },
 	{ "ls",		command_ls,		"ls [hdNn:/path]" },
 	{ "version",	command_version,	"version" },
 	{ "help",	command_help,		"help|?" },
@@ -111,6 +114,12 @@ command_dev(char *arg)
 }
 
 void
+command_initrd(char *arg)
+{
+	set_initrd_path(arg);
+}
+
+void
 command_ls(char *arg)
 {
 	ls(arg);
@@ -157,6 +166,21 @@ get_default_device(void)
 	return default_device;
 }
 
+int
+set_initrd_path(char *arg)
+{
+	if (strlen(arg) + 1 > sizeof(initrd_path))
+		return ERANGE;
+	strcpy(initrd_path, arg);
+	return 0;
+}
+
+char *
+get_initrd_path(void)
+{
+	return initrd_path;
+}
+
 void
 print_banner(void)
 {

Index: src/sys/stand/efiboot/efiboot.h
diff -u src/sys/stand/efiboot/efiboot.h:1.3 src/sys/stand/efiboot/efiboot.h:1.4
--- src/sys/stand/efiboot/efiboot.h:1.3	Mon Sep  3 00:04:02 2018
+++ src/sys/stand/efiboot/efiboot.h	Fri Sep  7 17:30:58 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: efiboot.h,v 1.3 2018/09/03 00:04:02 jmcneill Exp $	*/
+/*	$NetBSD: efiboot.h,v 1.4 2018/09/07 17:30:58 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -52,6 +52,8 @@ extern const struct boot_command command
 void command_help(char *);
 int set_default_device(char *);
 char *get_default_device(void);
+int set_initrd_path(char *);
+char *get_initrd_path(void);
 
 /* console.c */
 int ischar(void);
Index: src/sys/stand/efiboot/exec.c
diff -u src/sys/stand/efiboot/exec.c:1.3 src/sys/stand/efiboot/exec.c:1.4
--- src/sys/stand/efiboot/exec.c:1.3	Sun Sep  2 23:50:23 2018
+++ src/sys/stand/efiboot/exec.c	Fri Sep  7 17:30:58 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.c,v 1.3 2018/09/02 23:50:23 jmcneill Exp $ */
+/* $NetBSD: exec.c,v 1.4 2018/09/07 17:30:58 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -33,6 +33,78 @@
 
 u_long load_offset = 0;
 
+#define	FDT_SPACE	(4 * 1024 * 1024)
+#define	FDT_ALIGN	((2 * 1024 * 1024) - 1)
+
+static EFI_PHYSICAL_ADDRESS initrd_addr;
+static u_long initrd_size = 0;
+
+static int
+load_initrd(void)
+{
+	EFI_STATUS status;
+	struct stat st;
+	ssize_t len;
+	char *path;
+	int fd;
+
+	path = get_initrd_path();
+	if (strlen(path) == 0)
+		return 0;
+
+	fd = open(path, 0);
+	if (fd < 0) {
+		printf("boot: failed to open %s: %s\n", path, strerror(errno));
+		return errno;
+	}
+	if (fstat(fd, ) < 0) {
+		printf("boot: failed to fstat %s: %s\n", path, strerror(errno));
+		close(fd);
+		return errno;
+	}
+	if (st.st_size == 0) {
+		printf("boot: empty initrd %s\n", path);
+		close(fd);
+		return EINVAL;
+	}
+
+	initrd_size = st.st_size;
+
+#ifdef EFIBOOT_ALLOCATE_MAX_ADDRESS
+	initrd_addr = EFIBOOT_ALLOCATE_MAX_ADDRESS;
+	status = uefi_call_wrapper(BS->AllocatePages, 4, AllocateMaxAddress, EfiLoaderData,
+	EFI_SIZE_TO_PAGES(initrd_size), _addr);
+#else
+	initrd_addr = 0;
+	status = uefi_call_wrapper(BS->AllocatePages, 4, AllocateAnyPages, EfiLoaderData,
+	EFI_SIZE_TO_PAGES(initrd_size), _addr);
+#endif
+	if (EFI_ERROR(status)) {
+		printf("Failed to allocate %lu bytes for initrd image (error %lu)\n",
+		initrd_size, status);
+		close(fd);
+		return ENOMEM;
+	}
+
+	printf("boot: loading %s ", path);
+	len = read(fd, (void *)initrd_addr, initrd_size);
+	close(fd);
+
+	if (len != initrd_size) {
+		if (len < 0)
+			printf(": %s\n", strerror(errno));
+		else
+			printf(": returned %ld 

CVS commit: src/sys/stand/efiboot

2018-09-07 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Sep  7 17:30:32 UTC 2018

Modified Files:
src/sys/stand/efiboot: efiboot_machdep.h
src/sys/stand/efiboot/bootaa64: cache.S efibootaa64.c

Log Message:
Disable MMU and dcache before jumping to the kernel.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/stand/efiboot/efiboot_machdep.h
cvs rdiff -u -r1.1 -r1.2 src/sys/stand/efiboot/bootaa64/cache.S \
src/sys/stand/efiboot/bootaa64/efibootaa64.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/stand/efiboot/efiboot_machdep.h
diff -u src/sys/stand/efiboot/efiboot_machdep.h:1.1 src/sys/stand/efiboot/efiboot_machdep.h:1.2
--- src/sys/stand/efiboot/efiboot_machdep.h:1.1	Fri Aug 24 02:01:06 2018
+++ src/sys/stand/efiboot/efiboot_machdep.h	Fri Sep  7 17:30:32 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efiboot_machdep.h,v 1.1 2018/08/24 02:01:06 jmcneill Exp $ */
+/* $NetBSD: efiboot_machdep.h,v 1.2 2018/09/07 17:30:32 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -30,4 +30,5 @@
 #define	EFIBOOT_ALIGN 0
 #endif
 
+void efi_dcache_flush(u_long, u_long);
 void efi_boot_kernel(u_long[]);

Index: src/sys/stand/efiboot/bootaa64/cache.S
diff -u src/sys/stand/efiboot/bootaa64/cache.S:1.1 src/sys/stand/efiboot/bootaa64/cache.S:1.2
--- src/sys/stand/efiboot/bootaa64/cache.S:1.1	Fri Aug 24 02:01:06 2018
+++ src/sys/stand/efiboot/bootaa64/cache.S	Fri Sep  7 17:30:32 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: cache.S,v 1.1 2018/08/24 02:01:06 jmcneill Exp $	*/
+/*	$NetBSD: cache.S,v 1.2 2018/09/07 17:30:32 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2014 Robin Randhawa
@@ -34,6 +34,9 @@
 
 #include 
 
+#define	SCTLR_M	(1<<0)
+#define	SCTLR_C	(1<<2)
+
 	.text
 	.align	2
 
@@ -96,3 +99,40 @@ ENTRY(aarch64_icache_inv_all)
 	isb
 	ret
 END(aarch64_icache_inv_all)
+
+/*
+ * void aarch64_exec_kernel(paddr_t entry, paddr_t dtb)
+ */
+ENTRY(aarch64_exec_kernel)
+	mov	x20, x0	/* kernel entry point */
+	mov	x21, x1	/* dtb address */
+
+	mrs	x0, CurrentEL
+	lsr	x0, x0, #2
+	cmp	x0, #0x2
+	b.eq	1f
+
+	/* Disable MMU and dcache, CurrentEL = EL1 */
+	mrs	x0, sctlr_el1
+	bic	x0, x0, #SCTLR_M
+	bic	x0, x0, #SCTLR_C
+	msr	sctlr_el1, x0
+	isb
+	b	2f
+1:
+	/* Disable MMU and dcache, CurrentEL = EL2 */
+	mrs	x0, sctlr_el2
+	bic	x0, x0, #SCTLR_M
+	bic	x0, x0, #SCTLR_C
+	msr	sctlr_el2, x0
+	isb
+2:
+
+	/* Jump to kernel */
+	mov	x0, x21
+	mov	x1, xzr
+	mov	x2, xzr
+	mov	x3, xzr
+	br	x20
+
+END(aarch64_exec_kernel)
Index: src/sys/stand/efiboot/bootaa64/efibootaa64.c
diff -u src/sys/stand/efiboot/bootaa64/efibootaa64.c:1.1 src/sys/stand/efiboot/bootaa64/efibootaa64.c:1.2
--- src/sys/stand/efiboot/bootaa64/efibootaa64.c:1.1	Fri Aug 24 02:01:06 2018
+++ src/sys/stand/efiboot/bootaa64/efibootaa64.c	Fri Sep  7 17:30:32 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: efibootaa64.c,v 1.1 2018/08/24 02:01:06 jmcneill Exp $	*/
+/*	$NetBSD: efibootaa64.c,v 1.2 2018/09/07 17:30:32 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -36,6 +36,13 @@
 /* cache.S */
 void aarch64_dcache_wbinv_range(vaddr_t, vsize_t);
 void aarch64_icache_inv_all(void);
+void aarch64_exec_kernel(paddr_t, paddr_t);
+
+void
+efi_dcache_flush(u_long start, u_long size)
+{
+	aarch64_dcache_wbinv_range(start, size);
+}
 
 void
 efi_boot_kernel(u_long marks[MARK_MAX])
@@ -51,5 +58,5 @@ efi_boot_kernel(u_long marks[MARK_MAX])
 		aarch64_dcache_wbinv_range((u_long)efi_fdt_data(), efi_fdt_size());
 	aarch64_icache_inv_all();
 
-	kernel_entry((register_t)efi_fdt_data(), 0, 0, 0);
+	aarch64_exec_kernel((paddr_t)marks[MARK_ENTRY], (paddr_t)efi_fdt_data());
 }



CVS commit: src/sys/stand/efiboot

2018-09-04 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Sep  4 21:29:54 UTC 2018

Modified Files:
src/sys/stand/efiboot: efinet.c

Log Message:
If the loader is loaded from the network, try to load the kernel from the
same network device.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/stand/efiboot/efinet.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/stand/efiboot/efinet.c
diff -u src/sys/stand/efiboot/efinet.c:1.2 src/sys/stand/efiboot/efinet.c:1.3
--- src/sys/stand/efiboot/efinet.c:1.2	Tue Sep  4 15:08:30 2018
+++ src/sys/stand/efiboot/efinet.c	Tue Sep  4 21:29:54 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: efinet.c,v 1.2 2018/09/04 15:08:30 riastradh Exp $	*/
+/*	$NetBSD: efinet.c,v 1.3 2018/09/04 21:29:54 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2001 Doug Rabson
@@ -28,6 +28,7 @@
  */
 
 #include 
+#include 
 
 #include "efiboot.h"
 
@@ -334,7 +335,7 @@ efi_net_probe(void)
 	EFI_HANDLE *handles;
 	EFI_STATUS status;
 	UINTN i, nhandles;
-	int nifs;
+	int nifs, depth = -1;
 	bool found;
 
 	status = LibLocateHandle(ByProtocol, , NULL,
@@ -347,6 +348,12 @@ efi_net_probe(void)
 		return;
 	memset(enis, 0, nhandles * sizeof(*enis));
 
+	if (efi_bootdp) {
+		depth = efi_device_path_depth(efi_bootdp, HARDWARE_DEVICE_PATH);
+		if (depth == 0)
+			depth = 1;
+	}
+
 	nifs = 0;
 	for (i = 0; i < nhandles; i++) {
 		status = uefi_call_wrapper(BS->HandleProtocol, 3, handles[i],
@@ -402,6 +409,13 @@ efi_net_probe(void)
 FreePool(handles);
 return;
 			}
+
+			if (depth > 0 && efi_device_path_ncmp(efi_bootdp, dp0, depth) == 0) {
+char devname[9];
+snprintf(devname, sizeof(devname), "net%u", nifs);
+set_default_device(devname);
+			}
+
 			nifs++;
 		}
 	}
@@ -489,9 +503,9 @@ efi_net_get_booted_interface_unit(void)
 int
 efi_net_open(struct open_file *f, ...)
 {
+	char **file, pathbuf[PATH_MAX], *default_device, *path, *ep;
+	const char *fname, *full_path;
 	struct devdesc desc;
-	const char *fname;
-	char **file, *ep;
 	intmax_t dev;
 	va_list ap;
 	int n;
@@ -501,13 +515,25 @@ efi_net_open(struct open_file *f, ...)
 	file = va_arg(ap, char **);
 	va_end(ap);
 
-	if (strncmp(fname, "net", 3) != 0)
+	default_device = get_default_device();
+	if (strchr(fname, ':') == NULL) {
+		if (strlen(default_device) > 0) {
+			snprintf(pathbuf, sizeof(pathbuf), "%s:%s", default_device, fname);
+			full_path = pathbuf;
+			path = __UNCONST(fname);
+		} else {
+			return EINVAL;
+		}
+	} else {
+		full_path = fname;
+		path = strchr(fname, ':') + 1;
+	}
+
+	if (strncmp(full_path, "net", 3) != 0)
 		return EINVAL;
-dev = strtoimax(fname + 3, , 10);
+dev = strtoimax(full_path + 3, , 10);
 if (dev < 0 || dev >= efinetif.netif_nifs)
 return ENXIO;
-	if (*ep != ':')
-		return ENXIO;
 
 for (n = 0; n < ndevs; n++)
 if (strcmp(DEV_NAME([n]), "net") == 0) {
@@ -517,7 +543,7 @@ efi_net_open(struct open_file *f, ...)
 if (n == ndevs)
 return ENXIO;
 
-	*file = ep + 1;
+	*file = path;
 
 	//try_bootp = 1;
 



CVS commit: src/sys/stand/efiboot

2018-09-02 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Sep  3 00:17:00 UTC 2018

Modified Files:
src/sys/stand/efiboot: boot.c efifdt.c efifdt.h

Log Message:
Print FDT model and compatible strings with "version" command


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/stand/efiboot/boot.c
cvs rdiff -u -r1.6 -r1.7 src/sys/stand/efiboot/efifdt.c
cvs rdiff -u -r1.1 -r1.2 src/sys/stand/efiboot/efifdt.h

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/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.4 src/sys/stand/efiboot/boot.c:1.5
--- src/sys/stand/efiboot/boot.c:1.4	Mon Sep  3 00:04:02 2018
+++ src/sys/stand/efiboot/boot.c	Mon Sep  3 00:17:00 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.4 2018/09/03 00:04:02 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.5 2018/09/03 00:17:00 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -29,6 +29,7 @@
 
 #include "efiboot.h"
 #include "efiblock.h"
+#include "efifdt.h"
 
 #include 
 #include 
@@ -131,6 +132,8 @@ command_version(char *arg)
 		ST->FirmwareRevision & 0x);
 		FreePool(ufirmware);
 	}
+
+	efi_fdt_show();
 }
 
 void

Index: src/sys/stand/efiboot/efifdt.c
diff -u src/sys/stand/efiboot/efifdt.c:1.6 src/sys/stand/efiboot/efifdt.c:1.7
--- src/sys/stand/efiboot/efifdt.c:1.6	Sun Sep  2 23:54:25 2018
+++ src/sys/stand/efiboot/efifdt.c	Mon Sep  3 00:17:00 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.c,v 1.6 2018/09/02 23:54:25 jmcneill Exp $ */
+/* $NetBSD: efifdt.c,v 1.7 2018/09/03 00:17:00 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -78,6 +78,27 @@ efi_fdt_size(void)
 }
 
 void
+efi_fdt_show(void)
+{
+	const char *model, *compat;
+	int n, ncompat;
+
+	if (fdt_data == NULL)
+		return;
+
+	model = fdt_getprop(fdt_data, fdt_path_offset(fdt_data, "/"), "model", NULL);
+	if (model)
+		printf("FDT: %s [", model);
+	ncompat = fdt_stringlist_count(fdt_data, fdt_path_offset(fdt_data, "/"), "compatible");
+	for (n = 0; n < ncompat; n++) {
+		compat = fdt_stringlist_get(fdt_data, fdt_path_offset(fdt_data, "/"),
+		"compatible", n, NULL);
+		printf("%s%s", n == 0 ? "" : ", ", compat);
+	}
+	printf("]\n");
+}
+
+void
 efi_fdt_memory_map(void)
 {
 	UINTN nentries = 0, mapkey, descsize;

Index: src/sys/stand/efiboot/efifdt.h
diff -u src/sys/stand/efiboot/efifdt.h:1.1 src/sys/stand/efiboot/efifdt.h:1.2
--- src/sys/stand/efiboot/efifdt.h:1.1	Fri Aug 24 02:01:06 2018
+++ src/sys/stand/efiboot/efifdt.h	Mon Sep  3 00:17:00 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.h,v 1.1 2018/08/24 02:01:06 jmcneill Exp $ */
+/* $NetBSD: efifdt.h,v 1.2 2018/09/03 00:17:00 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -30,4 +30,5 @@ int efi_fdt_probe(void);
 void efi_fdt_memory_map(void);
 void *efi_fdt_data(void);
 int efi_fdt_size(void);
+void efi_fdt_show(void);
 void efi_fdt_bootargs(const char *);



CVS commit: src/sys/stand/efiboot

2018-09-02 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Sep  3 00:04:02 UTC 2018

Modified Files:
src/sys/stand/efiboot: Makefile.efiboot boot.c conf.c devopen.c
efiboot.c efiboot.h version
Added Files:
src/sys/stand/efiboot: dev_net.c efigetsecs.c efinet.c efinet.h
efipxe.c

Log Message:
Add PXE support.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/stand/efiboot/Makefile.efiboot \
src/sys/stand/efiboot/conf.c src/sys/stand/efiboot/devopen.c \
src/sys/stand/efiboot/efiboot.h
cvs rdiff -u -r1.3 -r1.4 src/sys/stand/efiboot/boot.c
cvs rdiff -u -r0 -r1.1 src/sys/stand/efiboot/dev_net.c \
src/sys/stand/efiboot/efinet.c src/sys/stand/efiboot/efinet.h \
src/sys/stand/efiboot/efipxe.c
cvs rdiff -u -r1.4 -r1.5 src/sys/stand/efiboot/efiboot.c
cvs rdiff -u -r0 -r1.3 src/sys/stand/efiboot/efigetsecs.c
cvs rdiff -u -r1.1 -r1.2 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.2 src/sys/stand/efiboot/Makefile.efiboot:1.3
--- src/sys/stand/efiboot/Makefile.efiboot:1.2	Sun Aug 26 21:28:18 2018
+++ src/sys/stand/efiboot/Makefile.efiboot	Mon Sep  3 00:04:02 2018
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.2 2018/08/26 21:28:18 jmcneill Exp $
+# $NetBSD: Makefile.efiboot,v 1.3 2018/09/03 00:04:02 jmcneill Exp $
 
 S=		${.CURDIR}/../../..
 
@@ -21,8 +21,8 @@ AFLAGS.start.S= ${${ACTIVE_CC} == "clang
 
 .PATH: ${EFIDIR}/gnuefi
 SOURCES=	crt0-efi-${GNUEFIARCH}.S reloc_${GNUEFIARCH}.c
-SOURCES+=	boot.c conf.c console.c devopen.c exec.c panic.c prompt.c
-SOURCES+=	efiboot.c efichar.c efidev.c efifdt.c efifile.c efiblock.c
+SOURCES+=	boot.c conf.c console.c dev_net.c devopen.c exec.c panic.c prompt.c
+SOURCES+=	efiboot.c efichar.c efidev.c efigetsecs.c efifdt.c efifile.c efiblock.c efinet.c efipxe.c
 
 .PATH: ${S}/external/bsd/libfdt/dist
 CPPFLAGS+=	-I${S}/external/bsd/libfdt/dist
@@ -68,12 +68,12 @@ CPPFLAGS+= -Wno-pointer-sign
 CPPFLAGS+= -DHEAP_VARIABLE
 #CPPFLAGS+= -DSUPPORT_CD9660
 CPPFLAGS+= -D"devb2cdb(bno)=(bno)"
-#CPPFLAGS+= -DSUPPORT_DOSFS
+CPPFLAGS+= -DSUPPORT_DOSFS
 #CPPFLAGS+= -DSUPPORT_EXT2FS
-#CPPFLAGS+= -DSUPPORT_BOOTP
-#CPPFLAGS+= -DSUPPORT_DHCP
+CPPFLAGS+= -DSUPPORT_BOOTP
+CPPFLAGS+= -DSUPPORT_DHCP
 #CPPFLAGS+= -DSUPPORT_NFS
-#CPPFLAGS+= -DSUPPORT_TFTP
+CPPFLAGS+= -DSUPPORT_TFTP
 CPPFLAGS+= -DLIBSA_ENABLE_LS_OP
 
 #CPPFLAGS+= -DARP_DEBUG
@@ -92,7 +92,7 @@ SAMISCCPPFLAGS+= -D"cdb2devb(bno)=(bno)"
 SA_AS= library
 SAMISCMAKEFLAGS+="SA_USE_LOADFILE=yes"
 SAMISCMAKEFLAGS+="SA_USE_CREAD=yes"
-#SAMISCMAKEFLAGS+="SA_INCLUDE_NET=yes"
+SAMISCMAKEFLAGS+="SA_INCLUDE_NET=yes"
 SAMISCMAKEFLAGS+="SA_ENABLE_LS_OP=yes"
 .include "${S}/lib/libsa/Makefile.inc"
 LIBSA= ${SALIB}
Index: src/sys/stand/efiboot/conf.c
diff -u src/sys/stand/efiboot/conf.c:1.2 src/sys/stand/efiboot/conf.c:1.3
--- src/sys/stand/efiboot/conf.c:1.2	Sun Aug 26 21:28:18 2018
+++ src/sys/stand/efiboot/conf.c	Mon Sep  3 00:04:02 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: conf.c,v 1.2 2018/08/26 21:28:18 jmcneill Exp $ */
+/* $NetBSD: conf.c,v 1.3 2018/09/03 00:04:02 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -33,20 +33,29 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 struct devsw devsw[] = {
 	{ "efifile", efi_file_strategy, efi_file_open, efi_file_close, noioctl },
 	{ "efiblock", efi_block_strategy, efi_block_open, efi_block_close, noioctl },
+	{ "net", net_strategy, net_open, net_close, noioctl },
 };
 int ndevs = __arraycount(devsw);
 
 struct netif_driver *netif_drivers[] = {
+	,
 };
 int n_netif_drivers = __arraycount(netif_drivers);
 
 struct fs_ops file_system[] = {
+	FS_OPS(null),
 	FS_OPS(ffsv1),
 	FS_OPS(ffsv2),
 	FS_OPS(dosfs),
 };
 int nfsys = __arraycount(file_system);
+
+struct fs_ops null_fs_ops = FS_OPS(null);
+struct fs_ops tftp_fs_ops = FS_OPS(tftp);
Index: src/sys/stand/efiboot/devopen.c
diff -u src/sys/stand/efiboot/devopen.c:1.2 src/sys/stand/efiboot/devopen.c:1.3
--- src/sys/stand/efiboot/devopen.c:1.2	Sun Aug 26 21:28:18 2018
+++ src/sys/stand/efiboot/devopen.c	Mon Sep  3 00:04:02 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: devopen.c,v 1.2 2018/08/26 21:28:18 jmcneill Exp $ */
+/* $NetBSD: devopen.c,v 1.3 2018/09/03 00:04:02 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -35,7 +35,11 @@ devopen(struct open_file *f, const char 
 {
 	int error;
 
-	error = efi_block_open(f, fname, file);
+	error = efi_net_open(f, fname, file);
+	file_system[0] = error ? null_fs_ops : tftp_fs_ops;
+
+	if (error)
+		error = efi_block_open(f, fname, file);
 	if (error)
 		error = efi_file_open(f, fname);
 
Index: src/sys/stand/efiboot/efiboot.h
diff -u src/sys/stand/efiboot/efiboot.h:1.2 src/sys/stand/efiboot/efiboot.h:1.3
--- src/sys/stand/efiboot/efiboot.h:1.2	Sun Aug 26 21:28:18 2018
+++ 

CVS commit: src/sys/stand/efiboot

2018-09-02 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Sep  2 23:54:25 UTC 2018

Modified Files:
src/sys/stand/efiboot: efifdt.c

Log Message:
Dump memory map if EFI_MEMORY_DEBUG is defined


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/stand/efiboot/efifdt.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/stand/efiboot/efifdt.c
diff -u src/sys/stand/efiboot/efifdt.c:1.5 src/sys/stand/efiboot/efifdt.c:1.6
--- src/sys/stand/efiboot/efifdt.c:1.5	Tue Aug 28 01:24:39 2018
+++ src/sys/stand/efiboot/efifdt.c	Sun Sep  2 23:54:25 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.c,v 1.5 2018/08/28 01:24:39 jmcneill Exp $ */
+/* $NetBSD: efifdt.c,v 1.6 2018/09/02 23:54:25 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -103,6 +103,12 @@ efi_fdt_memory_map(void)
 
 	memmap = LibMemoryMap(, , , );
 	for (n = 0, md = memmap; n < nentries; n++, md = NextMemoryDescriptor(md, descsize)) {
+#ifdef EFI_MEMORY_DEBUG
+		printf("MEM: %u: Type 0x%x Attr 0x%lx Phys 0x%lx Virt 0x%lx Size 0x%lx\n",
+		n, md->Type, md->Attribute,
+		md->PhysicalStart, md->VirtualStart,
+		(u_long)md->NumberOfPages * EFI_PAGE_SIZE);
+#endif
 		if ((md->Attribute & EFI_MEMORY_WB) == 0)
 			continue;
 		if (!FDT_MEMORY_USABLE(md))



CVS commit: src/sys/stand/efiboot

2018-08-27 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Aug 28 01:24:39 UTC 2018

Modified Files:
src/sys/stand/efiboot: efifdt.c

Log Message:
Remove call to fdt_pack, it is causing problems with memory detection


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/stand/efiboot/efifdt.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/stand/efiboot/efifdt.c
diff -u src/sys/stand/efiboot/efifdt.c:1.4 src/sys/stand/efiboot/efifdt.c:1.5
--- src/sys/stand/efiboot/efifdt.c:1.4	Mon Aug 27 22:51:55 2018
+++ src/sys/stand/efiboot/efifdt.c	Tue Aug 28 01:24:39 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.c,v 1.4 2018/08/27 22:51:55 alnsn Exp $ */
+/* $NetBSD: efifdt.c,v 1.5 2018/08/28 01:24:39 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -166,6 +166,4 @@ efi_fdt_bootargs(const char *bootargs)
 			break;
 		}
 	}
-
-	fdt_pack(fdt_data);
 }



CVS commit: src/sys/stand/efiboot

2018-08-27 Thread Alexander Nasonov
Module Name:src
Committed By:   alnsn
Date:   Mon Aug 27 22:51:55 UTC 2018

Modified Files:
src/sys/stand/efiboot: efifdt.c

Log Message:
Fix typo in a panic string.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/stand/efiboot/efifdt.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/stand/efiboot/efifdt.c
diff -u src/sys/stand/efiboot/efifdt.c:1.3 src/sys/stand/efiboot/efifdt.c:1.4
--- src/sys/stand/efiboot/efifdt.c:1.3	Mon Aug 27 09:51:32 2018
+++ src/sys/stand/efiboot/efifdt.c	Mon Aug 27 22:51:55 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.c,v 1.3 2018/08/27 09:51:32 jmcneill Exp $ */
+/* $NetBSD: efifdt.c,v 1.4 2018/08/27 22:51:55 alnsn Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -149,7 +149,7 @@ efi_fdt_bootargs(const char *bootargs)
 	if (chosen < 0)
 		chosen = fdt_add_subnode(fdt_data, fdt_path_offset(fdt_data, "/"), FDT_CHOSEN_NODE_NAME);
 	if (chosen < 0)
-		panic("FDT: Failed to craete " FDT_CHOSEN_NODE_PATH " node");
+		panic("FDT: Failed to create " FDT_CHOSEN_NODE_PATH " node");
 
 	if (*bootargs)
 		fdt_setprop_string(fdt_data, chosen, "bootargs", bootargs);



CVS commit: src/sys/stand/efiboot/bootaa64

2018-08-27 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Aug 27 22:40:51 UTC 2018

Modified Files:
src/sys/stand/efiboot/bootaa64: Makefile

Log Message:
Add release target


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/stand/efiboot/bootaa64/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/stand/efiboot/bootaa64/Makefile
diff -u src/sys/stand/efiboot/bootaa64/Makefile:1.1 src/sys/stand/efiboot/bootaa64/Makefile:1.2
--- src/sys/stand/efiboot/bootaa64/Makefile:1.1	Fri Aug 24 02:01:06 2018
+++ src/sys/stand/efiboot/bootaa64/Makefile	Mon Aug 27 22:40:51 2018
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1 2018/08/24 02:01:06 jmcneill Exp $
+# $NetBSD: Makefile,v 1.2 2018/08/27 22:40:51 jmcneill Exp $
 
 PROG=		bootaa64.efi
 OBJFMT=		binary
@@ -12,3 +12,6 @@ CFLAGS+=	-DEFIBOOT_ALIGN=0x20
 
 .include "${.CURDIR}/../Makefile.efiboot"
 
+release: check_RELEASEDIR
+	${HOST_INSTALL_FILE} -m ${BINMODE} ${PROG} \
+		${RELEASEDIR}/${MACHINE}/installation/misc



CVS commit: src/sys/stand/efiboot

2018-08-27 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Aug 27 09:51:32 UTC 2018

Modified Files:
src/sys/stand/efiboot: efiblock.c efiblock.h efifdt.c exec.c

Log Message:
Pass a hash of the MBR and the booted partition to the kernel.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/stand/efiboot/efiblock.c \
src/sys/stand/efiboot/efiblock.h src/sys/stand/efiboot/exec.c
cvs rdiff -u -r1.2 -r1.3 src/sys/stand/efiboot/efifdt.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/stand/efiboot/efiblock.c
diff -u src/sys/stand/efiboot/efiblock.c:1.1 src/sys/stand/efiboot/efiblock.c:1.2
--- src/sys/stand/efiboot/efiblock.c:1.1	Sun Aug 26 21:28:18 2018
+++ src/sys/stand/efiboot/efiblock.c	Mon Aug 27 09:51:32 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.c,v 1.1 2018/08/26 21:28:18 jmcneill Exp $ */
+/* $NetBSD: efiblock.c,v 1.2 2018/08/27 09:51:32 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -30,12 +30,14 @@
 #define FSTYPENAMES
 
 #include 
+#include 
 
 #include "efiboot.h"
 #include "efiblock.h"
 
 static EFI_HANDLE *efi_block;
 static UINTN efi_nblock;
+static struct efi_block_part *efi_block_booted = NULL;
 
 static TAILQ_HEAD(, efi_block_dev) efi_block_devs = TAILQ_HEAD_INITIALIZER(efi_block_devs);
 
@@ -85,8 +87,18 @@ efi_block_parse(const char *fname, struc
 	return ENOENT;
 }
 
+static void
+efi_block_generate_hash_mbr(struct efi_block_part *bpart, struct mbr_sector *mbr)
+{
+	MD5_CTX md5ctx;
+
+	MD5Init();
+	MD5Update(, (void *)mbr, sizeof(*mbr));
+	MD5Final(bpart->hash, );
+}
+
 static int
-efi_block_find_partitions_disklabel(struct efi_block_dev *bdev, uint32_t start, uint32_t size)
+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;
 	struct disklabel d;
@@ -133,6 +145,7 @@ efi_block_find_partitions_disklabel(stru
 		bpart->type = EFI_BLOCK_PART_DISKLABEL;
 		bpart->disklabel.secsize = le32toh(d.d_secsize);
 		bpart->disklabel.part = *p;
+		efi_block_generate_hash_mbr(bpart, mbr);
 		TAILQ_INSERT_TAIL(>partitions, bpart, entries);
 	}
 
@@ -171,7 +184,7 @@ efi_block_find_partitions_mbr(struct efi
 		if (le32toh(mbr_part->mbrp_size) == 0)
 			continue;
 		if (mbr_part->mbrp_type == MBR_PTYPE_NETBSD) {
-			efi_block_find_partitions_disklabel(bdev, le32toh(mbr_part->mbrp_start), le32toh(mbr_part->mbrp_size));
+			efi_block_find_partitions_disklabel(bdev, , le32toh(mbr_part->mbrp_start), le32toh(mbr_part->mbrp_size));
 			break;
 		}
 	}
@@ -278,6 +291,12 @@ efi_block_show(void)
 	}
 }
 
+struct efi_block_part *
+efi_block_boot_part(void)
+{
+	return efi_block_booted;
+}
+
 int
 efi_block_open(struct open_file *f, ...)
 {
@@ -309,6 +328,8 @@ efi_block_open(struct open_file *f, ...)
 
 	*file = path;
 
+	efi_block_booted = bpart;
+
 	return 0;
 }
 
Index: src/sys/stand/efiboot/efiblock.h
diff -u src/sys/stand/efiboot/efiblock.h:1.1 src/sys/stand/efiboot/efiblock.h:1.2
--- src/sys/stand/efiboot/efiblock.h:1.1	Sun Aug 26 21:28:18 2018
+++ src/sys/stand/efiboot/efiblock.h	Mon Aug 27 09:51:32 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efiblock.h,v 1.1 2018/08/26 21:28:18 jmcneill Exp $ */
+/* $NetBSD: efiblock.h,v 1.2 2018/08/27 09:51:32 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -59,12 +59,14 @@ struct efi_block_part {
 	union {
 		struct efi_block_part_disklabel disklabel;
 	};
+	uint8_t hash[16];
 
 	TAILQ_ENTRY(efi_block_part) entries;
 };
 
 void efi_block_probe(void);
 void efi_block_show(void);
+struct efi_block_part *efi_block_boot_part(void);
 
 int efi_block_open(struct open_file *, ...);
 int efi_block_close(struct open_file *);
Index: src/sys/stand/efiboot/exec.c
diff -u src/sys/stand/efiboot/exec.c:1.1 src/sys/stand/efiboot/exec.c:1.2
--- src/sys/stand/efiboot/exec.c:1.1	Fri Aug 24 02:01:06 2018
+++ src/sys/stand/efiboot/exec.c	Mon Aug 27 09:51:32 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.c,v 1.1 2018/08/24 02:01:06 jmcneill Exp $ */
+/* $NetBSD: exec.c,v 1.2 2018/08/27 09:51:32 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -74,8 +74,7 @@ exec_netbsd(const char *fname, const cha
 	close(fd);
 
 	if (efi_fdt_size() > 0) {
-		if (args && *args)
-			efi_fdt_bootargs(args);
+		efi_fdt_bootargs(args);
 		efi_fdt_memory_map();	
 	}
 

Index: src/sys/stand/efiboot/efifdt.c
diff -u src/sys/stand/efiboot/efifdt.c:1.2 src/sys/stand/efiboot/efifdt.c:1.3
--- src/sys/stand/efiboot/efifdt.c:1.2	Fri Aug 24 23:20:41 2018
+++ src/sys/stand/efiboot/efifdt.c	Mon Aug 27 09:51:32 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.c,v 1.2 2018/08/24 23:20:41 jmcneill Exp $ */
+/* $NetBSD: efifdt.c,v 1.3 2018/08/27 09:51:32 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -28,6 +28,7 @@
 
 #include "efiboot.h"
 #include "efifdt.h"
+#include "efiblock.h"
 
 #include 
 
@@ -38,6 +39,7 @@ static EFI_GUID FdtTableGuid = FDT_TABLE
 

CVS commit: src/sys/stand/efiboot

2018-08-26 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Aug 26 21:28:18 UTC 2018

Modified Files:
src/sys/stand/efiboot: Makefile.efiboot boot.c conf.c devopen.c
efiboot.c efiboot.h efifile.c
Added Files:
src/sys/stand/efiboot: efiblock.c efiblock.h efidev.c

Log Message:
Add support for booting kernels from FFS partitions.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/stand/efiboot/Makefile.efiboot \
src/sys/stand/efiboot/conf.c src/sys/stand/efiboot/devopen.c \
src/sys/stand/efiboot/efiboot.h
cvs rdiff -u -r1.2 -r1.3 src/sys/stand/efiboot/boot.c \
src/sys/stand/efiboot/efifile.c
cvs rdiff -u -r0 -r1.1 src/sys/stand/efiboot/efiblock.c \
src/sys/stand/efiboot/efiblock.h src/sys/stand/efiboot/efidev.c
cvs rdiff -u -r1.3 -r1.4 src/sys/stand/efiboot/efiboot.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/stand/efiboot/Makefile.efiboot
diff -u src/sys/stand/efiboot/Makefile.efiboot:1.1 src/sys/stand/efiboot/Makefile.efiboot:1.2
--- src/sys/stand/efiboot/Makefile.efiboot:1.1	Fri Aug 24 02:01:06 2018
+++ src/sys/stand/efiboot/Makefile.efiboot	Sun Aug 26 21:28:18 2018
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.1 2018/08/24 02:01:06 jmcneill Exp $
+# $NetBSD: Makefile.efiboot,v 1.2 2018/08/26 21:28:18 jmcneill Exp $
 
 S=		${.CURDIR}/../../..
 
@@ -22,7 +22,7 @@ AFLAGS.start.S= ${${ACTIVE_CC} == "clang
 .PATH: ${EFIDIR}/gnuefi
 SOURCES=	crt0-efi-${GNUEFIARCH}.S reloc_${GNUEFIARCH}.c
 SOURCES+=	boot.c conf.c console.c devopen.c exec.c panic.c prompt.c
-SOURCES+=	efiboot.c efichar.c efifdt.c efifile.c
+SOURCES+=	efiboot.c efichar.c efidev.c efifdt.c efifile.c efiblock.c
 
 .PATH: ${S}/external/bsd/libfdt/dist
 CPPFLAGS+=	-I${S}/external/bsd/libfdt/dist
@@ -74,7 +74,7 @@ CPPFLAGS+= -D"devb2cdb(bno)=(bno)"
 #CPPFLAGS+= -DSUPPORT_DHCP
 #CPPFLAGS+= -DSUPPORT_NFS
 #CPPFLAGS+= -DSUPPORT_TFTP
-#CPPFLAGS+= -DLIBSA_ENABLE_LS_OP
+CPPFLAGS+= -DLIBSA_ENABLE_LS_OP
 
 #CPPFLAGS+= -DARP_DEBUG
 #CPPFLAGS+= -DBOOTP_DEBUG
@@ -93,7 +93,7 @@ SA_AS= library
 SAMISCMAKEFLAGS+="SA_USE_LOADFILE=yes"
 SAMISCMAKEFLAGS+="SA_USE_CREAD=yes"
 #SAMISCMAKEFLAGS+="SA_INCLUDE_NET=yes"
-#SAMISCMAKEFLAGS+="SA_ENABLE_LS_OP=yes"
+SAMISCMAKEFLAGS+="SA_ENABLE_LS_OP=yes"
 .include "${S}/lib/libsa/Makefile.inc"
 LIBSA= ${SALIB}
 
Index: src/sys/stand/efiboot/conf.c
diff -u src/sys/stand/efiboot/conf.c:1.1 src/sys/stand/efiboot/conf.c:1.2
--- src/sys/stand/efiboot/conf.c:1.1	Fri Aug 24 02:01:06 2018
+++ src/sys/stand/efiboot/conf.c	Sun Aug 26 21:28:18 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: conf.c,v 1.1 2018/08/24 02:01:06 jmcneill Exp $ */
+/* $NetBSD: conf.c,v 1.2 2018/08/26 21:28:18 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -28,9 +28,15 @@
 
 #include "efiboot.h"
 #include "efifile.h"
+#include "efiblock.h"
+
+#include 
+#include 
+#include 
 
 struct devsw devsw[] = {
 	{ "efifile", efi_file_strategy, efi_file_open, efi_file_close, noioctl },
+	{ "efiblock", efi_block_strategy, efi_block_open, efi_block_close, noioctl },
 };
 int ndevs = __arraycount(devsw);
 
@@ -39,5 +45,8 @@ struct netif_driver *netif_drivers[] = {
 int n_netif_drivers = __arraycount(netif_drivers);
 
 struct fs_ops file_system[] = {
+	FS_OPS(ffsv1),
+	FS_OPS(ffsv2),
+	FS_OPS(dosfs),
 };
 int nfsys = __arraycount(file_system);
Index: src/sys/stand/efiboot/devopen.c
diff -u src/sys/stand/efiboot/devopen.c:1.1 src/sys/stand/efiboot/devopen.c:1.2
--- src/sys/stand/efiboot/devopen.c:1.1	Fri Aug 24 02:01:06 2018
+++ src/sys/stand/efiboot/devopen.c	Sun Aug 26 21:28:18 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: devopen.c,v 1.1 2018/08/24 02:01:06 jmcneill Exp $ */
+/* $NetBSD: devopen.c,v 1.2 2018/08/26 21:28:18 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -28,13 +28,16 @@
 
 #include "efiboot.h"
 #include "efifile.h"
+#include "efiblock.h"
 
 int
 devopen(struct open_file *f, const char *fname, char **file)
 {
 	int error;
 
-	error = efi_file_open(f, fname);
+	error = efi_block_open(f, fname, file);
+	if (error)
+		error = efi_file_open(f, fname);
 
 	return error;
 }
Index: src/sys/stand/efiboot/efiboot.h
diff -u src/sys/stand/efiboot/efiboot.h:1.1 src/sys/stand/efiboot/efiboot.h:1.2
--- src/sys/stand/efiboot/efiboot.h:1.1	Fri Aug 24 02:01:06 2018
+++ src/sys/stand/efiboot/efiboot.h	Sun Aug 26 21:28:18 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: efiboot.h,v 1.1 2018/08/24 02:01:06 jmcneill Exp $	*/
+/*	$NetBSD: efiboot.h,v 1.2 2018/08/26 21:28:18 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -46,6 +46,8 @@ void clearit(void);
 void print_banner(void);
 extern const struct boot_command commands[];
 void command_help(char *);
+int set_default_device(char *);
+char *get_default_device(void);
 
 /* console.c */
 int ischar(void);
@@ -63,6 +65,10 @@ size_t ucs2len(const CHAR16 *);
 int ucs2_to_utf8(const CHAR16 *, char **);
 int utf8_to_ucs2(const char *, CHAR16 **, size_t 

CVS commit: src/sys/stand/efiboot

2018-08-24 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Aug 24 23:21:56 UTC 2018

Modified Files:
src/sys/stand/efiboot: efiboot.c

Log Message:
If we could not query the DevicePathProtocol handle, just select no default 
boot device instead of exiting.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/stand/efiboot/efiboot.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/stand/efiboot/efiboot.c
diff -u src/sys/stand/efiboot/efiboot.c:1.2 src/sys/stand/efiboot/efiboot.c:1.3
--- src/sys/stand/efiboot/efiboot.c:1.2	Fri Aug 24 20:51:15 2018
+++ src/sys/stand/efiboot/efiboot.c	Fri Aug 24 23:21:56 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efiboot.c,v 1.2 2018/08/24 20:51:15 jmcneill Exp $ */
+/* $NetBSD: efiboot.c,v 1.3 2018/08/24 23:21:56 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -62,7 +62,7 @@ efi_main(EFI_HANDLE imageHandle, EFI_SYS
 		return status;
 	status = uefi_call_wrapper(BS->HandleProtocol, 3, efi_li->DeviceHandle, , (void **)_bootdp);
 	if (EFI_ERROR(status))
-		return status;
+		efi_bootdp = NULL;
 
 #ifdef EFIBOOT_DEBUG
 	Print(L"Loaded image  : 0x%lX\n", efi_li);



CVS commit: src/sys/stand/efiboot

2018-08-24 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Aug 24 23:22:10 UTC 2018

Modified Files:
src/sys/stand/efiboot: boot.c

Log Message:
Use absolute paths for default kernel filenames


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/stand/efiboot/boot.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/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.1 src/sys/stand/efiboot/boot.c:1.2
--- src/sys/stand/efiboot/boot.c:1.1	Fri Aug 24 02:01:06 2018
+++ src/sys/stand/efiboot/boot.c	Fri Aug 24 23:22:10 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.1 2018/08/24 02:01:06 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.2 2018/08/24 23:22:10 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -40,9 +40,9 @@ extern const char bootprog_name[], bootp
 extern char twiddle_toggle;
 
 static const char * const names[][2] = {
-	{ "netbsd", "netbsd.gz" },
-	{ "onetbsd", "onetbsd.gz" },
-	{ "netbsd.old", "netbsd.old.gz" },
+	{ "\\netbsd", "\\netbsd.gz" },
+	{ "\\onetbsd", "\\onetbsd.gz" },
+	{ "\\netbsd.old", "\\netbsd.old.gz" },
 };
 
 #define NUMNAMES	__arraycount(names)



CVS commit: src/sys/stand/efiboot

2018-08-24 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Aug 24 23:20:41 UTC 2018

Modified Files:
src/sys/stand/efiboot: efifdt.c

Log Message:
Sanitize the memory map passed to the kernel.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/stand/efiboot/efifdt.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/stand/efiboot/efifdt.c
diff -u src/sys/stand/efiboot/efifdt.c:1.1 src/sys/stand/efiboot/efifdt.c:1.2
--- src/sys/stand/efiboot/efifdt.c:1.1	Fri Aug 24 02:01:06 2018
+++ src/sys/stand/efiboot/efifdt.c	Fri Aug 24 23:20:41 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.c,v 1.1 2018/08/24 02:01:06 jmcneill Exp $ */
+/* $NetBSD: efifdt.c,v 1.2 2018/08/24 23:20:41 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill 
@@ -79,8 +79,9 @@ void
 efi_fdt_memory_map(void)
 {
 	UINTN nentries = 0, mapkey, descsize;
-	EFI_MEMORY_DESCRIPTOR *md;
+	EFI_MEMORY_DESCRIPTOR *md, *memmap;
 	UINT32 descver;
+	UINT64 phys_start, phys_size;
 	int n, memory;
 
 	memory = fdt_path_offset(fdt_data, FDT_MEMORY_NODE_PATH);
@@ -90,30 +91,49 @@ efi_fdt_memory_map(void)
 		panic("FDT: Failed to create " FDT_MEMORY_NODE_PATH " node");
 
 	fdt_delprop(fdt_data, memory, "reg");
+	while (fdt_num_mem_rsv(fdt_data) > 0) {
+		if (fdt_del_mem_rsv(fdt_data, 0) < 0)
+			panic("FDT: Failed to remove reserved memory map entry");
+	}
 
 	const int address_cells = fdt_address_cells(fdt_data, fdt_path_offset(fdt_data, "/"));
 	const int size_cells = fdt_size_cells(fdt_data, fdt_path_offset(fdt_data, "/"));
 
-	md = LibMemoryMap(, , , );
-	for (n = 0; n < nentries; n++, md = NextMemoryDescriptor(md, descsize)) {
+	memmap = LibMemoryMap(, , , );
+	for (n = 0, md = memmap; n < nentries; n++, md = NextMemoryDescriptor(md, descsize)) {
 		if ((md->Attribute & EFI_MEMORY_WB) == 0)
 			continue;
 		if (!FDT_MEMORY_USABLE(md))
 			continue;
+		if ((address_cells == 1 || size_cells == 1) && md->PhysicalStart + (md->NumberOfPages * EFI_PAGE_SIZE) > 0x)
+			continue;
+		if (md->NumberOfPages <= 1)
+			continue;
+
+		phys_start = md->PhysicalStart;
+		phys_size = md->NumberOfPages * EFI_PAGE_SIZE;
+
+		if (phys_start & EFI_PAGE_MASK) {
+			/* UEFI spec says these should be 4KB aligned, but U-Boot doesn't always.. */
+			phys_start = (phys_start + EFI_PAGE_SIZE) & ~EFI_PAGE_MASK;
+			phys_size -= (EFI_PAGE_SIZE * 2);
+			if (phys_size == 0)
+continue;
+		}
 
 		if (address_cells == 1)
 			fdt_appendprop_u32(fdt_data, fdt_path_offset(fdt_data, FDT_MEMORY_NODE_PATH),
-			"reg", (uint32_t)md->PhysicalStart);
+			"reg", (uint32_t)phys_start);
 		else
 			fdt_appendprop_u64(fdt_data, fdt_path_offset(fdt_data, FDT_MEMORY_NODE_PATH),
-			"reg", md->PhysicalStart);
+			"reg", phys_start);
 
 		if (size_cells == 1)
 			fdt_appendprop_u32(fdt_data, fdt_path_offset(fdt_data, FDT_MEMORY_NODE_PATH),
-			"reg", (uint32_t)md->NumberOfPages * EFI_PAGE_SIZE);
+			"reg", (uint32_t)phys_size);
 		else
 			fdt_appendprop_u64(fdt_data, fdt_path_offset(fdt_data, FDT_MEMORY_NODE_PATH),
-			"reg", (uint64_t)md->NumberOfPages * EFI_PAGE_SIZE);
+			"reg", phys_size);
 	}
 }
 



  1   2   >