[PATCH 11/11] ARM: mmuinfo: add options for enabling/disabling zero page trapping

Ahmad Fatoum a.fatoum at pengutronix.de
Sun May 21 22:28:35 PDT 2023


mmuinfo 0 will most likely trigger a translation fault. To allow
decoding the zero page or to allow reading BootROM code at address 0,
teach mmuinfo -z to disable trapping of the zero page and mmuinfo -Z to
reinstate the faulting zero page.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/arm/cpu/mmuinfo.c | 47 ++++++++++++++++++++++++++++++++++++++++--
 include/zero_page.h    | 12 +++++++++++
 2 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/arch/arm/cpu/mmuinfo.c b/arch/arm/cpu/mmuinfo.c
index 413f2f337e95..44d6980a7569 100644
--- a/arch/arm/cpu/mmuinfo.c
+++ b/arch/arm/cpu/mmuinfo.c
@@ -6,8 +6,10 @@
 
 #include <common.h>
 #include <command.h>
+#include <getopt.h>
 #include <asm/mmuinfo.h>
 #include <asm/system_info.h>
+#include <zero_page.h>
 #include <mmu.h>
 
 int mmuinfo(void *addr)
@@ -23,8 +25,40 @@ int mmuinfo(void *addr)
 static __maybe_unused int do_mmuinfo(int argc, char *argv[])
 {
 	unsigned long addr;
+	int access_zero_page = -1;
+	int opt;
 
-	if (argc < 2)
+	while ((opt = getopt(argc, argv, "zZ")) > 0) {
+		switch (opt) {
+		case 'z':
+			access_zero_page = true;
+			break;
+		case 'Z':
+			access_zero_page = false;
+			break;
+		default:
+			return COMMAND_ERROR_USAGE;
+		}
+	}
+
+	if (access_zero_page >= 0) {
+		if (argc - optind != 0)
+			return COMMAND_ERROR_USAGE;
+
+		if (!zero_page_remappable()) {
+			pr_warn("No architecture support for zero page remap\n");
+			return -ENOSYS;
+		}
+
+		if (access_zero_page)
+			zero_page_access();
+		else
+			zero_page_faulting();
+
+		return 0;
+	}
+
+	if (argc - optind != 1)
 		return COMMAND_ERROR_USAGE;
 
 	addr = strtoul_suffix(argv[1], NULL, 0);
@@ -32,11 +66,20 @@ static __maybe_unused int do_mmuinfo(int argc, char *argv[])
 	return mmuinfo((void *)addr);
 }
 
+BAREBOX_CMD_HELP_START(mmuinfo)
+BAREBOX_CMD_HELP_TEXT("Show MMU/cache information using the cp15/model-specific registers.")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT ("-z",  "enable access to zero page")
+BAREBOX_CMD_HELP_OPT ("-Z",  "disable access to zero page")
+BAREBOX_CMD_HELP_END
+
 #ifdef CONFIG_COMMAND_SUPPORT
 BAREBOX_CMD_START(mmuinfo)
 	.cmd            = do_mmuinfo,
 	BAREBOX_CMD_DESC("show MMU/cache information of an address")
-	BAREBOX_CMD_OPTS("ADDRESS")
+	BAREBOX_CMD_OPTS("[-zZ | ADDRESS]")
 	BAREBOX_CMD_GROUP(CMD_GRP_INFO)
+	BAREBOX_CMD_HELP(cmd_mmuinfo_help)
 BAREBOX_CMD_END
 #endif
diff --git a/include/zero_page.h b/include/zero_page.h
index a71c0e0b8733..79e0f22c7b5b 100644
--- a/include/zero_page.h
+++ b/include/zero_page.h
@@ -20,6 +20,13 @@ void zero_page_faulting(void);
  */
 void zero_page_access(void);
 
+void zero_page_access(void);
+
+static inline bool zero_page_remappable(void)
+{
+	return true;
+}
+
 #else
 
 static inline void zero_page_faulting(void)
@@ -30,6 +37,11 @@ static inline void zero_page_access(void)
 {
 }
 
+static inline bool zero_page_remappable(void)
+{
+	return false;
+}
+
 #endif
 
 static inline bool zero_page_contains(unsigned long addr)
-- 
2.39.2




More information about the barebox mailing list