@@ -11,6 +11,7 @@
#include <cpu_func.h>
#include <asm/system.h>
#include <asm/armv8/mmu.h>
+#include <asm/sections.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -361,6 +362,24 @@ __weak u64 get_page_table_size(void)
return size;
}
+__weak void add_text_map(void)
+{
+ if (!(gd->flags & GD_FLG_RELOC))
+ return;
+
+ /* Text is always XN=0, read-only region. */
+ struct mm_region text = {
+ .virt = (unsigned long)__image_copy_start,
+ .phys = (unsigned long)__image_copy_start,
+ .size = (unsigned long)__text_end - (unsigned long)__image_copy_start,
+ .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
+ PTE_BLOCK_INNER_SHARE |
+ PTE_BLOCK_AP_RO
+ };
+
+ add_map(&text);
+}
+
void setup_pgtables(void)
{
int i;
@@ -378,6 +397,8 @@ void setup_pgtables(void)
/* Now add all MMU table entries one after another to the table */
for (i = 0; mem_map[i].size || mem_map[i].attrs; i++)
add_map(&mem_map[i]);
+
+ add_text_map();
}
static void setup_all_pgtables(void)
@@ -20,8 +20,8 @@ SECTIONS
#endif
. = 0x00000000;
- . = ALIGN(8);
- .text :
+ /* Align .text to the page size */
+ .text ALIGN(0x1000):
{
*(.__image_copy_start)
CPUDIR/start.o (.text*)
@@ -39,6 +39,8 @@ SECTIONS
.text_rest :
{
*(.text*)
+ . = NEXT(0x1000);
+ KEEP(*(.__text_end))
}
#ifdef CONFIG_ARMV8_PSCI
@@ -58,6 +58,12 @@
*/
#define PTE_BLOCK_MEMTYPE(x) ((x) << 2)
#define PTE_BLOCK_NS (1 << 5)
+/*
+ * AP[1] bit is ignored by hardware and is
+ * treated as if it was One in EL2/EL3
+ */
+#define PTE_BLOCK_AP_RO (1 << 7)
+#define PTE_BLOCK_AP_RW (0 << 7)
#define PTE_BLOCK_NON_SHARE (0 << 8)
#define PTE_BLOCK_OUTER_SHARE (2 << 8)
#define PTE_BLOCK_INNER_SHARE (3 << 8)
@@ -18,6 +18,7 @@
* aliasing warnings.
*/
+char __text_end[0] __attribute__((section(".__text_end")));
char __bss_start[0] __attribute__((section(".__bss_start")));
char __bss_end[0] __attribute__((section(".__bss_end")));
char __image_copy_start[0] __attribute__((section(".__image_copy_start")));
@@ -70,6 +70,7 @@ extern void _start(void);
*/
#ifdef CONFIG_ARM
+extern char __text_end[];
extern char __bss_start[];
extern char __bss_end[];
extern char __image_copy_start[];