mem_safe: prevent writing to .text in XIP systems

The sys_mem_safe_write_to_text_section() now always fails in XIP
systems, since their .text section is in ROM.

Change-Id: Ie47a5dbf5f75a4bfe8e9fc9852d0037a3546aae8
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
diff --git a/misc/debug/mem_safe_check_boundaries.c b/misc/debug/mem_safe_check_boundaries.c
index 64b3674..0bc5ea4 100644
--- a/misc/debug/mem_safe_check_boundaries.c
+++ b/misc/debug/mem_safe_check_boundaries.c
@@ -216,6 +216,17 @@
 			mem_access(dest, buf, width, num_bytes, SYS_MEM_SAFE_WRITE);
 }
 
+#if defined(CONFIG_XIP)
+int _mem_safe_write_to_text_section(void *dest, char *buf, size_t num_bytes)
+{
+	ARG_UNUSED(dest);
+	ARG_UNUSED(buf);
+	ARG_UNUSED(num_bytes);
+
+	/* cannot write to text section when it's in ROM */
+	return -EFAULT;
+}
+#else
 int _mem_safe_write_to_text_section(void *dest, char *buf, size_t num_bytes)
 {
 	vaddr_t v = (vaddr_t)dest;
@@ -229,6 +240,7 @@
 	memcpy(dest, buf, num_bytes);
 	return 0;
 }
+#endif /* CONFIG_XIP */
 
 int _mem_safe_region_add(void *addr, size_t num_bytes, int perm)
 {