diff mbox series

[13/13] gard: Add OpenBMC vPNOR support

Message ID 20171108085918.12590-14-oohall@gmail.com
State Accepted
Headers show
Series [01/13] gard: show: Remove "Res Recovery" field | expand

Commit Message

Oliver O'Halloran Nov. 8, 2017, 8:59 a.m. UTC
A big-ol-hack to add some checking for OpenBMC's vPNOR GUARD files under
/media/pnor-prsv. This isn't ideal since it doesn't handle the create
case well, but it's better than nothing.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
---
 external/gard/gard.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
diff mbox series

Patch

diff --git a/external/gard/gard.c b/external/gard/gard.c
index 815243457cf5..a49151653aa0 100644
--- a/external/gard/gard.c
+++ b/external/gard/gard.c
@@ -50,6 +50,9 @@ 
 #define SYSFS_MTD_PATH "/sys/class/mtd/"
 #define FLASH_GARD_PART "GUARD"
 
+#define VPNOR_GARD_DIR "/media/pnor-prsv"
+#define VPNOR_GARD_FILE VPNOR_GARD_DIR"/GUARD"
+
 /* Full gard version number (possibly includes gitid). */
 extern const char version[];
 
@@ -879,6 +882,34 @@  int main(int argc, char **argv)
 #endif
 	}
 
+#ifdef __arm__
+	/*
+	 * HACK: Look for a vPNOR GUARD file if we haven't been given anything
+	 * explitly. If it exists then we can safely assume that:
+	 * a) The host is a P9
+	 * b) The file is ECC protected
+	 * c) The file is a bare partition.
+	 *
+	 * This is a stupid hack, but there's not other sane place for it.
+	 * arch_init_flash() always looks for a FFS formatted PNOR when
+	 * filename is NULL
+	 */
+	if (!filename) {
+		struct stat buf;
+
+		if (!stat(VPNOR_GARD_FILE, &buf)) {
+			filename = strdup(VPNOR_GARD_FILE);
+			/* BUG: This ignores the command line settings */
+			part = true;
+			ecc = true;
+			set_chip_gen(p9_chip_units);
+		} else if (!stat(VPNOR_GARD_DIR, &buf)) {
+			printf(VPNOR_GARD_FILE" is missing. Nothing to do\n");
+			return 0;
+		}
+	}
+#endif
+
 	/*
 	 * Force libflash to do flash accesses via the MTD. Direct mode is
 	 * generally unsafe since it fiddles with the flash controller state