PERFORCE change 222057 for review

Bjoern A. Zeeb bz at FreeBSD.org
Fri Feb 15 13:42:32 UTC 2013


http://p4web.freebsd.org/@@222057?ac=10

Change 222057 by bz at bz_zenith on 2013/02/15 13:41:41

	Read the kenv variable from either isf or cfi.
	Try to open either isf or cfi for read/write.
	Only issue the erase ioctl in case of isf.

Affected files ...

.. //depot/projects/ctsrd/beribsd/src/ctsrd/atsectl/atsectl.c#3 edit

Differences ...

==== //depot/projects/ctsrd/beribsd/src/ctsrd/atsectl/atsectl.c#3 (text+ko) ====

@@ -42,6 +42,7 @@
 #include <sys/errno.h>
 #include <sys/socket.h>
 
+#include <assert.h>
 #include <err.h>
 #include <fcntl.h>
 #include <inttypes.h>
@@ -61,19 +62,22 @@
 	off_t	ir_off;		/* Offset of range to delete (set to 0xFF) */
 	size_t	ir_size;	/* Size of range */
 };
-
 #define ISF_ERASE	_IOW('I', 1, struct isf_range)
-
 #define ISF_ERASE_BLOCK (128 * 1024)
-
-#if 0
-static enum {UNSET, ERASE} action = UNSET;
-#endif
-
 #define	DEV_ISF0_PATH	"/dev/isf0"
+#define	DEV_CFI0_PATH	"/dev/cfi0"
 
 static u_char block[ISF_ERASE_BLOCK];
 
+#define	UNKNOWN	0
+#define	ISF	1
+#define	CFI	2
+static int fdev	= UNKNOWN;
+static const char *fdevs[] = {
+	"UNKNOWN",
+	"ISF",
+	"CFI"
+};
 static int gflag;
 
 /* XXX-BZ should include if_atsereg.h. */
@@ -96,10 +100,16 @@
 
 	fd = open(DEV_ISF0_PATH, O_RDONLY, 0);
 	if (fd == -1)
+		fd = open(DEV_ISF0_PATH, O_RDONLY, 0);
+	else
+		fdev = ISF;
+	if (fd == -1)
 		errx(1, "Failed to open " DEV_ISF0_PATH);
+	else
+		fdev = CFI;
 
 	if (read(fd, block, sizeof(block)) != ISF_ERASE_BLOCK)
-		errx(1, "Short read from " DEV_ISF0_PATH);
+		errx(1, "Short read from %s", fdevs[fdev]);
 
 	close(fd);
 }
@@ -110,6 +120,9 @@
 	struct isf_range ir;
 	int fd;
 
+	if (fdev != ISF)
+		return;
+
 	fd = open(DEV_ISF0_PATH, O_RDONLY, 0);
 	if (fd == -1)
 		errx(1, "Failed to open " DEV_ISF0_PATH);
@@ -129,12 +142,16 @@
 {
 	int fd;
 
+	assert(fdev == ISF || fdev == CFI);
+
 	fd = open(DEV_ISF0_PATH, O_WRONLY, 0);
 	if (fd == -1)
+		fd = open(DEV_CFI0_PATH, O_WRONLY, 0);
+	if (fd == -1)
 		errx(1, "Failed to open " DEV_ISF0_PATH);
 
 	if (write(fd, block, sizeof(block)) != ISF_ERASE_BLOCK)
-		errx(1, "Short write on " DEV_ISF0_PATH);
+		errx(1, "Short write on %s", fdevs[fdev]);
 
 	close(fd);
 }
@@ -191,15 +208,20 @@
 {
 	uint8_t buf[32];
 	MD5_CTX ctx;
+	int rc;
 
 	printf("Original:\n");
 	read_block();
 	print_eaddr();
 
 	if (eaddr == NULL) {
-		/* isf0.factory_ppr="0x0123456789abcdef" */
-		if (kenv(KENV_GET, "isf0.factory_ppr", buf, sizeof(buf)) == -1)
-			err(1, "Could not find isf PPR serial\n");
+		/* (isf|cfi)0.factory_ppr="0x0123456789abcdef" */
+		rc = kenv(KENV_GET, "isf0.factory_ppr", buf, sizeof(buf));
+		if (rc == -1)
+			rc = kenv(KENV_GET, "cfi0.factory_ppr", buf,
+			    sizeof(buf));
+		if (rc == -1)
+			err(1, "Could not find Intel flash PPR serial\n");
 
 		MD5Init(&ctx);
 		MD5Update(&ctx, buf+2, 16);


More information about the p4-projects mailing list