From fec43ffc3b8f48a26bf3f541b3fde825bb632708 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 29 Jul 2013 17:54:56 -0600 Subject: [PATCH] Changes to ARMv7-A boot logic to handle the case where we execute out of NOR FLASH --- configs/sama5d3x-ek/Kconfig | 14 +++++++++++++- configs/sama5d3x-ek/README.txt | 14 ++++++++++++++ configs/sama5d3x-ek/ostest/defconfig | 4 ++-- configs/sama5d3x-ek/src/Makefile | 4 ++-- configs/sama5d3x-ek/src/nor_main.c | 26 +++++++++++++++++++++----- 5 files changed, 52 insertions(+), 10 deletions(-) diff --git a/configs/sama5d3x-ek/Kconfig b/configs/sama5d3x-ek/Kconfig index 58f94967ea..5f977fe164 100644 --- a/configs/sama5d3x-ek/Kconfig +++ b/configs/sama5d3x-ek/Kconfig @@ -11,6 +11,18 @@ config SAMA5_NOR_MAIN depends on SAMA5_BOOT_ISRAM ---help--- nor_main is a tiny program that runs in ISRAM. nor_main will enable - NOR flash then jump to the program in NOR flash + NOR flash then either (1) jump to the program in NOR flash or (2) + wait for you to break in with GDB to debug the NOR program. + +config SAMA5_NOR_START + bool "Start NOR program" + default n + depends on SAMA5_NOR_MAIN + ---help--- + The default behavior of the NOR boot program is to initialize the + NOR FLASH at CS0, then patiently wait for you to break into the + program with GDB. An alternative behvior is enabled with this + option: If SAMA5_NOR_START is defined, then it will not wait but + will, instead, immediately start the program in NOR FLASH. endif diff --git a/configs/sama5d3x-ek/README.txt b/configs/sama5d3x-ek/README.txt index e20c0b221f..98c716ae94 100644 --- a/configs/sama5d3x-ek/README.txt +++ b/configs/sama5d3x-ek/README.txt @@ -699,6 +699,20 @@ Configurations STATUS: 2013-7-28: This configuration was verified functional. + norboot: + This is a little program to help debug of code in NOR flash. It + does the following: + + - It enables and configures NOR FLASH, then + - Waits for you to break in with GDB. + + At that point, you can set the PC and begin executing from NOR FLASH + under debug control. + + NOTES: + 1. This program derives from the hello configuration. All of the + notes there apply to this configuration as well. + ostest: This configuration directory, performs a simple OS test using examples/ostest. diff --git a/configs/sama5d3x-ek/ostest/defconfig b/configs/sama5d3x-ek/ostest/defconfig index 9290872214..5d1010ad1c 100644 --- a/configs/sama5d3x-ek/ostest/defconfig +++ b/configs/sama5d3x-ek/ostest/defconfig @@ -228,8 +228,8 @@ CONFIG_BOOT_RUNFROMFLASH=y CONFIG_RAM_START=0x00304000 CONFIG_RAM_VSTART=0x00304000 CONFIG_RAM_SIZE=114688 -CONFIG_FLASH_START=0x1000000 -CONFIG_FLASH_VSTART=0x1000000 +CONFIG_FLASH_START=0x10000000 +CONFIG_FLASH_VSTART=0x10000000 CONFIG_FLASH_SIZE=134217728 # diff --git a/configs/sama5d3x-ek/src/Makefile b/configs/sama5d3x-ek/src/Makefile index 940bdbb5c2..1ae5ae4cf4 100644 --- a/configs/sama5d3x-ek/src/Makefile +++ b/configs/sama5d3x-ek/src/Makefile @@ -73,11 +73,11 @@ ARCH_SRCDIR = $(TOPDIR)/arch/$(CONFIG_ARCH)/src ifeq ($(WINTOOL),y) CFLAGS += -I "${shell cygpath -w $(ARCH_SRCDIR)/chip}" CFLAGS += -I "${shell cygpath -w $(ARCH_SRCDIR)/common}" - CFLAGS += -I "${shell cygpath -w $(ARCH_SRCDIR)/armv7-m}" + CFLAGS += -I "${shell cygpath -w $(ARCH_SRCDIR)/armv7-a}" else CFLAGS += -I$(ARCH_SRCDIR)/chip CFLAGS += -I$(ARCH_SRCDIR)/common - CFLAGS += -I$(ARCH_SRCDIR)/armv7-m + CFLAGS += -I$(ARCH_SRCDIR)/armv7-a endif all: libboard$(LIBEXT) diff --git a/configs/sama5d3x-ek/src/nor_main.c b/configs/sama5d3x-ek/src/nor_main.c index 3c90b8a770..96d881dfb5 100644 --- a/configs/sama5d3x-ek/src/nor_main.c +++ b/configs/sama5d3x-ek/src/nor_main.c @@ -43,6 +43,7 @@ #include #include "up_arch.h" +#include "sctlr.h" #include "sam_periphclks.h" #include "chip/sam_hsmc.h" @@ -114,18 +115,33 @@ int nor_main(int argc, char *argv) HSMC_MODE_TDFCYCLES(1); putreg32(regval, SAM_HSMC_MODE(HSMC_CS0)); + /* Disable the caches and the MMU. Disabling the MMU should be safe here + * because there is a 1-to-1 identity mapping between the physical and + * virtual addressing. + */ + +#if 0 /* Causes a crash */ + printf("Disabling the caches and the MMU\n"); + regval = cp15_rdsctlr(); + regval &= ~(SCTLR_M | SCTLR_C | SCTLR_I); + cp15_wrsctlr(regval); +#endif + +#ifdef SAMA5_NOR_START /* Then jump into NOR flash */ -#if 1 - printf("Waiting for GDB halt\n"); - fflush(stdout); - for (;;); -#else printf("Jumping to NOR flash on CS0\n"); fflush(stdout); usleep(500*1000); NOR_ENTRY(); +#else + /* Or just wait patiently for the user to break in with GDB. */ + + printf("Waiting for GDB halt\n"); + fflush(stdout); + for (;;); #endif + return 0; /* NOR_ENTRY() should not return */ }