Module Name:    src
Committed By:   martin
Date:           Thu Jan  9 17:06:46 UTC 2020

Modified Files:
        src/usr.sbin/sysinst/arch/evbarm: md.c md.h

Log Message:
Instead of a (bogus) attempt to query the model via ofctl, use the (now
fixed) sysctl hw.model instead.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/sysinst/arch/evbarm/md.c
cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/sysinst/arch/evbarm/md.h

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

Modified files:

Index: src/usr.sbin/sysinst/arch/evbarm/md.c
diff -u src/usr.sbin/sysinst/arch/evbarm/md.c:1.11 src/usr.sbin/sysinst/arch/evbarm/md.c:1.12
--- src/usr.sbin/sysinst/arch/evbarm/md.c:1.11	Thu Jan  9 13:22:31 2020
+++ src/usr.sbin/sysinst/arch/evbarm/md.c	Thu Jan  9 17:06:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: md.c,v 1.11 2020/01/09 13:22:31 martin Exp $ */
+/*	$NetBSD: md.c,v 1.12 2020/01/09 17:06:46 martin Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -42,6 +42,7 @@
 #include <sys/types.h>
 #include <sys/ioctl.h>
 #include <sys/param.h>
+#include <sys/sysctl.h>
 
 #include "defs.h"
 #include "md.h"
@@ -50,18 +51,31 @@
 
 int boardtype = BOARD_TYPE_NORMAL;
 
+#define	SBSA_MODEL_STR	"netbsd,generic-acpi"
+#define	RPI_MODEL_STR	"raspberrypi,"
+
 void
 md_init(void)
 {
-	int rv;
-
-	rv =run_program(RUN_SILENT|RUN_ERROR_OK, "sh -c 'ofctl -p / model | "
-	    "fgrep \"Raspberry Pi\"'");
-	if (rv != 0)
-		return;
+	static const int mib[2] = {CTL_HW, HW_MODEL};
+	size_t len;
+	char *cpu_model;
+
+	sysctl(mib, 2, NULL, &len, NULL, 0);
+	cpu_model = malloc(len);
+	sysctl(mib, 2, cpu_model, &len, NULL, 0);
+
+	if (strstr(cpu_model, RPI_MODEL_STR) != NULL)
+		/* this is some kind of Raspberry Pi */
+		boardtype = BOARD_TYPE_RPI;
+	else if (strstr(cpu_model, SBSA_MODEL_STR) != NULL)
+		/* some SBSA compatible machine */
+		boardtype = BOARD_TYPE_ACPI;
+	else
+		/* unknown, assume u-boot + dtb */
+		boardtype = BOARD_TYPE_NORMAL;
 
-	/* this is some kind of Raspberry Pi */
-	boardtype = BOARD_TYPE_RPI;
+	free(cpu_model);
 }
 
 void

Index: src/usr.sbin/sysinst/arch/evbarm/md.h
diff -u src/usr.sbin/sysinst/arch/evbarm/md.h:1.3 src/usr.sbin/sysinst/arch/evbarm/md.h:1.4
--- src/usr.sbin/sysinst/arch/evbarm/md.h:1.3	Wed Oct  2 11:16:02 2019
+++ src/usr.sbin/sysinst/arch/evbarm/md.h	Thu Jan  9 17:06:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: md.h,v 1.3 2019/10/02 11:16:02 maya Exp $	*/
+/*	$NetBSD: md.h,v 1.4 2020/01/09 17:06:46 martin Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -76,8 +76,9 @@
 #define DISKLABEL_CMD "disklabel -w -r"
 
 /* Special board type routines need a switch */
-#define BOARD_TYPE_NORMAL	0
-#define BOARD_TYPE_RPI		1
+#define BOARD_TYPE_NORMAL	0	/* assume u-boot */
+#define BOARD_TYPE_RPI		1	/* RPi firmware booted us */
+#define	BOARD_TYPE_ACPI		2	/* generic SBSA machine */
 int boardtype;
 
 /*

Reply via email to