SAMA5D4-EK: Add bootloader that runs from ISRAM and loads an Intel HEX file into DRAM

This commit is contained in:
Gregory Nutt
2014-06-26 16:42:06 -06:00
parent 3a1a8da19c
commit 3fb8023bdf
8 changed files with 1421 additions and 5 deletions
+1 -1
View File
@@ -64,7 +64,7 @@ config SAMA5D3xEK_NOR_START
---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
program with GDB. An alternative behavior is enabled with this
option: If SAMA5D3xEK_NOR_START is defined, then it will not wait but
will, instead, immediately start the program in NOR FLASH.
+36
View File
@@ -37,6 +37,42 @@ config SAMA5D4EK_MT47H64M16HR
endchoice # SAMA4D4-EK DRAM Type
config SAMA5D4EK_DRAM_MAIN
bool "Build dram_main"
default n
depends on SAMA5_BOOT_ISRAM
---help---
dram_main is a tiny program that runs in ISRAM. dram_main will
enable SDRAM and load an Intel HEX program into SDRAM over the
serial console. Then it will either (1) jump to the program in
DRAM at address 0x2000:0000 (2) wait for you to break in with GDB to
debug the SDRAM program. These different behaviors are controlled
by SAMA5D4EK_DRAM_START.
NOTE: If you use this boot loader, then your program must be built at
origin 0x2000:0000, not at 0x2100:0000 as is customary with U-Boot.
config SAMA5D4EK_DRAM_START
bool "Start DRAM program"
default n
depends on SAMA5D4EK_DRAM_MAIN
---help---
The default behavior of the DRAM boot program is to initialize the
DRAM, then patiently wait for you to break into the program with GDB.
An alternative behavior is enabled with this option: If
SAMA5D4EK_DRAM_START is defined, then it will not wait but will,
instead, immediately start the program in DRAM.
config SAMA5D4EK_DRAM_BOOT
bool "Using DRAM boot loader"
default y
depends on SAMA5_BOOT_SDRAM && !SAMA5D4EK_DRAM_MAIN
---help---
Select this option if you are going to boot using the sdram_main
bootloader (created with SAMA5D4EK_DRAM_MAIN=y). This selection
will simply origin your program at 0x2000:0000 as required by the
sdram_main bootloader (vs. 0x2100:0000 as required by U-Boot).
config SAMA5D4EK_NAND_AUTOMOUNT
bool "NAND FLASH auto-mount"
default n
+188 -4
View File
@@ -62,6 +62,7 @@ Contents
- NXFLAT Toolchain
- Loading Code into SRAM with J-Link
- Writing to FLASH using SAM-BA
- Creating and Using DRAMBOOT
- Running NuttX from SDRAM
- PIO Usage
- Buttons and LEDs
@@ -328,14 +329,108 @@ Writing to FLASH using SAM-BA
re-open the terminal emulator program.
10. Power cycle the board.
Creating and Using DRAMBOOT
===========================
In order to have more control of debugging code that runs out of DARM,
I created the sama5d4-ek/dramboot configuration. That configuration is
described below under "Configurations."
Here are some general instructions on how to build an use dramboot:
Building:
1. Remove any old configurations (if applicable).
cd <nuttx>
make distclean
2. Install and build the dramboot configuration. This steps will establish
the dramboot configuration and setup the PATH variable in order to do
the build:
cd tools
./configure.sh sama5d4-ek/dramboot
cd -
. ./setenv.sh
Before sourcing the setenv.sh file above, you should examine it and
perform edits as necessary so that TOOLCHAIN_BIN is the correct path
to the directory than holds your toolchain binaries.
NOTE: Be aware that the default dramboot also disables the watchdog.
Since you will not be able to re-enable the watchdog later, you may
need to set CONFIG_SAMA5_WDT=y in the NuttX configuration file.
Then make dramboot:
make
This will result in an ELF binary called 'nuttx' and also HEX and
binary versions called 'nuttx.hex' and 'nuttx.bin'.
3. Rename the binaries. Since you will need two versions of NuttX: this
dramboot version that runs in internal SRAM and another under test in
NOR FLASH, I rename the resulting binary files so that they can be
distinguished:
mv nuttx dramboot
mv nuttx.hex dramboot.hex
mv nuttx.bin dramboot.bin
4. Build the "real" DRAM configuration. This will create the nuttx.hex
that you will load using dramboot.
5. Restart the system holding DIS_BOOT. You should see the RamBOOT
prompt on the 115200 8N1 serial console (and nothing) more. Hit
the ENTER key with the focus on your terminal window a few time.
This will enable JTAG.
6. Then start the J-Link GDB server and GDB. In GDB, I do the following:
(gdb) mon heal # Halt the CPU
(gdb) load dramboot # Load dramboot into internal SRAM
(gdb) mon go # Start dramboot
You should see this message:
Send Intel HEX file now
Load your program by sending the nuttx.hex via the terminal program.
Then:
(gdb) mon halt # Break in
(gdb) mon reg pc = 0x20000040 # Set the PC to DRAM entry point
(gdb) mon go # And jump into DRAM
The dramboot program can also be configured to jump directly into
DRAM without requiring the final halt and go by setting
CONFIG_SAMA5D4EK_DRAM_START=y in the NuttX configuration. However,
since I have been debugging the early boot sequence, the above
sequence has been most convenient for me since it allows me to
step into the program in SDRAM.
7. An option is to use the SAM-BA tool to write the DRAMBOOT image into
Serial FLASH. Then, the system will boot from Serial FLASH by
copying the DRAMBOOT image in SRAM which will run, download the nuttx.hex
file, and then start the image loaded into DRAM automatically. This is
a very convenient usage!
NOTES: (1) There is that must be closed to enable use of the AT25
Serial Flash. (2) If using SAM-BA, make sure that you load the DRAM
boot program into the boot area via the pull-down menu.
Running NuttX from SDRAM
========================
NuttX may be executed from SDRAM. But this case means that the NuttX
binary must reside on some other media (typically NAND FLASH, Serial
FLASH, or, perhaps even a TFTP server). In these cases, an intermediate
bootloader such as U-Boot or Barebox must be used to configure the
SAMA5D4 clocks and SDRAM and then to copy the NuttX binary into SDRAM.
FLASH) or transferred over some interface (perhaps a UARt or even a
TFTP server). In these cases, an intermediate bootloader such as U-Boot
or Barebox must be used to configure the SAMA5D4 clocks and SDRAM and
then to copy the NuttX binary into SDRAM.
The SRAMBOOT program is another option (see above). But this section
will focus on U-Boot.
- NuttX Configuration
- Boot sequence
@@ -2420,6 +2515,10 @@ Watchdog Timer
the WDT, we cannot disable the watchdog time if CONFIG_SAMA5_WDT=y. So,
be forewarned: You have only 16 seconds to run your watchdog timer test!
NOTE: If you are using the dramboot program to run from DRAM as I did,
beware that the default version also disables the watchdog. You will
need a special version of dramboot with CONFIG_SAMA5_WDT=y.
TRNG and /dev/random
====================
@@ -2809,6 +2908,9 @@ Configurations
Summary: Some of the descriptions below are long and wordy. Here is the
concise summary of the available SAMA4D4-EK configurations:
dramboot: This is a little program to help debug of code in DRAM. See
the description below and the section above entitled "Creating and
Using DRAMBOOT" for more information
nsh: This is another NSH configuration, not too different from the
demo configuration. The nsh configuration is, however, bare bones.
It is the simplest possible NSH configuration and is useful as a
@@ -2823,6 +2925,86 @@ Configurations
Now for the gory details:
dramboot:
This is a little program to help debug of code in DRAM. It does the
following:
- It configures DRAM,
- It loads and Intel HEX file into DRAM over the terminal port,
- Waits for you to break in with GDB.
At that point, you can set the PC and begin executing from SDRAM under
debug control. See the section entitled "Creating and Using
DRAMBOOT" above.
NOTES:
1. This configuration uses the the USART3 for the serial console
which is available at the "DBGU" RS-232 connector (J24). That
is easily changed by reconfiguring to (1) enable a different
serial peripheral, and (2) selecting that serial peripheral as
the console device.
2. By default, this configuration is set up to build on Windows
under either a Cygwin or MSYS environment using a recent, Windows-
native, generic ARM EABI GCC toolchain (such as the CodeSourcery
toolchain). Both the build environment and the toolchain
selection can easily be changed by reconfiguring:
CONFIG_HOST_WINDOWS=y : Windows operating system
CONFIG_WINDOWS_CYGWIN=y : POSIX environment under windows
CONFIG_ARMV7A_TOOLCHAIN_CODESOURCERYW=y : CodeSourcery for Windows
If you are running on Linux, make *certain* that you have
CONFIG_HOST_LINUX=y *before* the first make or you will create a
corrupt configuration that may not be easy to recover from. See
the warning in the section "Information Common to All Configurations"
for further information.
3. This configuration executes out of internal SRAM flash and is
loaded into SRAM by the boot RomBoot from NAND, Serial
DataFlash, SD card or from a TFTPC sever via the Boot ROM.
Data also is positioned in SRAM.
2. The default dramboot program initializes the DRAM memory,
displays a message, loads an Intel HEX program into DRAM over the
serial console and halts. The dramboot program can also be
configured to jump directly into DRAM without requiring the
final halt and go by setting CONFIG_SAMA5D4EK_DRAM_START=y in the
NuttX configuration.
3. Be aware that the default dramboot also disables the watchdog.
Since you will not be able to re-enable the watchdog later, you may
need to set CONFIG_SAMA5_WDT=y in the NuttX configuration file.
4. If you put dramboot on the Serial FLASH, you can automatically
boot to SDRAM on reset. See the section "Creating and Using DRAMBOOT"
above.
5. Here are the steps that I use to execute this program in SRAM
using only the ROM Bootloader:
a) Hold the DIS_BOOT button and
b) With the DIS_BOOT button pressed, power cycle the board. A
reset does not seem to be sufficient.
c) The serial should show RomBOOT in a terminal window (at 115200
8N1) and nothing more.
d) Press ENTER in the terminal window a few times to enable JTAG.
e) Start the Segger GDB server. It should successfully connect to
the board via JTAG (if JTAG was correctly enabled in step d)).
f) Start GDB, connect, to the GDB server, load NuttX, and debug.
gdb> target remote localhost:2331
gdb> mon halt (don't do mon reset)
gdb> load nuttx
gdb> mon reg pc (make sure that the PC is 0x200040
gdb> ... and debug ...
nsh:
This configuration directory provide the NuttShell (NSH). This is a
@@ -2830,6 +3012,7 @@ Configurations
functionality.
NOTES:
1. This configuration uses the the USART3 for the serial console
which is available at the "DBGU" RS-232 connector (J24). That
is easily changed by reconfiguring to (1) enable a different
@@ -2917,6 +3100,7 @@ Configurations
bringing up SDRAM.
NOTES:
1. This configuration uses the the USART3 for the serial console
which is available at the "DBGU" RS-232 connector (J24). That
is easily changed by reconfiguring to (1) enable a different
@@ -2942,7 +3126,7 @@ Configurations
3. This configuration executes out of internal SRAM flash and is
loaded into SRAM by the boot ROM SDRAM from NAND, Serial
DataFlash, SD card or from a TFTPC sever via the Boot ROM.
Data also is positioned in SDRAM.
Data also is positioned in SRAM.
Here are the steps that I use to execute this program in SRAM
using only the ROM Bootloader:
+126
View File
@@ -0,0 +1,126 @@
############################################################################
# configs/sama5d4-ek/dramboot/Make.defs
#
# Copyright (C) 2014 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
include ${TOPDIR}/.config
include ${TOPDIR}/tools/Config.mk
include ${TOPDIR}$(DELIM)arch$(DELIM)arm$(DELIM)src$(DELIM)armv7-a$(DELIM)Toolchain.defs
ifeq ($(CONFIG_SAMA5_BOOT_ISRAM),y)
LDSCRIPT = isram.ld
endif
ifeq ($(CONFIG_SAMA5_BOOT_SDRAM),y)
LDSCRIPT = ddram.ld
endif
ifeq ($(WINTOOL),y)
# Windows-native toolchains
ARCHINCLUDES = -I. -isystem "${shell cygpath -w $(TOPDIR)$(DELIM)include}"
ARCHXXINCLUDES = -I. -isystem "${shell cygpath -w $(TOPDIR)$(DELIM)include}" -isystem "${shell cygpath -w $(TOPDIR)$(DELIM)include$(DELIM)cxx}"
ARCHSCRIPT = -T "${shell cygpath -w $(TOPDIR)$(DELIM)configs$(DELIM)$(CONFIG_ARCH_BOARD)$(DELIM)scripts$(DELIM)$(LDSCRIPT)}"
else
# Linux/Cygwin-native toolchain
ARCHINCLUDES = -I. -isystem $(TOPDIR)$(DELIM)include
ARCHXXINCLUDES = -I. -isystem $(TOPDIR)$(DELIM)include -isystem $(TOPDIR)$(DELIM)include$(DELIM)cxx
ARCHSCRIPT = -T$(TOPDIR)$(DELIM)configs$(DELIM)$(CONFIG_ARCH_BOARD)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
endif
CC = $(CROSSDEV)gcc
CXX = $(CROSSDEV)g++
CPP = $(CROSSDEV)gcc -E
LD = $(CROSSDEV)ld
AR = $(ARCROSSDEV)ar rcs
NM = $(ARCROSSDEV)nm
OBJCOPY = $(CROSSDEV)objcopy
OBJDUMP = $(CROSSDEV)objdump
ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
ARCHOPTIMIZATION = -g
endif
ifneq ($(CONFIG_DEBUG_NOOPT),y)
ARCHOPTIMIZATION += $(MAXOPTIMIZATION) -fno-strict-aliasing -fno-strength-reduce -fomit-frame-pointer
endif
ARCHCPUFLAGS = -mcpu=cortex-a5 -mfpu=vfpv4-d16
ARCHCFLAGS = -fno-builtin
ARCHCXXFLAGS = -fno-builtin -fno-exceptions -fno-rtti
ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow
ARCHWARNINGSXX = -Wall -Wshadow
ARCHDEFINES =
ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
CFLAGS = $(ARCHCFLAGS) $(ARCHWARNINGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -pipe
CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
CXXFLAGS = $(ARCHCXXFLAGS) $(ARCHWARNINGSXX) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -pipe
CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS)
CPPFLAGS = $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES)
AFLAGS = $(CFLAGS) -D__ASSEMBLY__
NXFLATLDFLAGS1 = -r -d -warn-common
NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)$(DELIM)binfmt$(DELIM)libnxflat$(DELIM)gnu-nxflat-pcrel.ld -no-check-sections
LDNXFLATFLAGS = -e main -s 2048
OBJEXT = .o
LIBEXT = .a
EXEEXT =
ifneq ($(CROSSDEV),arm-nuttx-elf-)
LDFLAGS += -nostartfiles -nodefaultlibs
endif
ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
LDFLAGS += -g
endif
HOSTCC = gcc
HOSTINCLUDES = -I.
HOSTCFLAGS = -Wall -Wstrict-prototypes -Wshadow -g -pipe
HOSTLDFLAGS =
ifeq ($(CONFIG_HOST_WINDOWS),y)
HOSTEXEEXT = .exe
else
HOSTEXEEXT =
endif
ifeq ($(WINTOOL),y)
# Windows-native host tools
DIRLINK = $(TOPDIR)$(DELIM)tools$(DELIM)copydir.sh
DIRUNLINK = $(TOPDIR)$(DELIM)tools$(DELIM)unlink.sh
MKDEP = $(TOPDIR)$(DELIM)tools$(DELIM)mknulldeps.sh
else
# Linux/Cygwin-native host tools
MKDEP = $(TOPDIR)$(DELIM)tools$(DELIM)mkdeps$(HOSTEXEEXT)
endif
File diff suppressed because it is too large Load Diff
+76
View File
@@ -0,0 +1,76 @@
#!/bin/bash
# configs/sama5d4-ek/dramboot/setenv.sh
#
# Copyright (C) 2014 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
if [ "$_" = "$0" ] ; then
echo "You must source this script, not run it!" 1>&2
exit 1
fi
WD=`pwd`
if [ ! -x "setenv.sh" ]; then
echo "This script must be executed from the top-level NuttX build directory"
exit 1
fi
if [ -z "${PATH_ORIG}" ]; then
export PATH_ORIG="${PATH}"
fi
# This is the Cygwin path to the location where I installed the Atmel GCC
# toolchain under Windows. You will also have to edit this if you install
# this toolchain in any other location
#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/Atmel/Atmel Toolchain/ARM GCC/Native/4.7.3.99/arm-gnu-toolchain/bin"
# This is the Cygwin path to the location where I installed the CodeSourcery
# toolchain under windows. You will also have to edit this if you install
# the CodeSourcery toolchain in any other location
#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/CodeSourcery/Sourcery G++ Lite/bin"
export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_EABI/bin"
# These are the Cygwin paths to the locations where I installed the Atollic
# toolchain under windows. You will also have to edit this if you install
# the Atollic toolchain in any other location. /usr/bin is added before
# the Atollic bin path because there is are binaries named gcc.exe and g++.exe
# at those locations as well.
#export TOOLCHAIN_BIN="/usr/bin:/cygdrive/c/Program Files (x86)/Atollic/TrueSTUDIO for ARM Pro 2.3.0/ARMTools/bin"
#export TOOLCHAIN_BIN="/usr/bin:/cygdrive/c/Program Files (x86)/Atollic/TrueSTUDIO for STMicroelectronics STM32 Lite 2.3.0/ARMTools/bin"
# This is the Cygwin path to the location where I build the buildroot
# toolchain.
#export TOOLCHAIN_BIN="${WD}/../misc/buildroot/build_arm/staging_dir/bin"
# Add the path to the toolchain to the PATH varialble
export PATH="${TOOLCHAIN_BIN}:/sbin:/usr/sbin:${PATH_ORIG}"
echo "PATH : ${PATH}"
+4
View File
@@ -62,6 +62,10 @@ ifeq ($(CONFIG_SAMA5_EBICS3_NAND),y)
CSRCS += sam_nandflash.c
endif
ifeq ($(CONFIG_SAMA5D4EK_DRAM_MAIN),y)
CSRCS += dram_main.c
endif
ifeq ($(CONFIG_MTD_AT25),y)
ifeq ($(CONFIG_SAMA5_SPI0),y)
CSRCS += sam_at25.c
+155
View File
@@ -0,0 +1,155 @@
/*****************************************************************************
* configs/sama5d4-ek/src/dram_main.c
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <debug.h>
#include <arch/irq.h>
#include <apps/hex2bin.h>
#include "up_arch.h"
#include "mmu.h"
#include "cache.h"
#include "sama5d4-ek.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define DRAM_ENTRY ((dram_entry_t)SAM_DDRCS_VSECTION)
#define DRAM_WAIT 1
#define DRAM_NOWAIT 0
#ifdef CONFIG_SAMA5D4EK_DRAM_START
# define DRAM_BOOT_MODE DRAM_NOWAIT
#else
# define DRAM_BOOT_MODE DRAM_WAIT
#endif
/****************************************************************************
* Private Types
****************************************************************************/
typedef void (*dram_entry_t)(void);
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: dram_main
*
* Description:
* dram_main is a tiny program that runs in ISRAM. dram_main will
* configure DRAM, present a prompt, load and Intel HEX file into DRAM,
* and either start that program or wait for you to break in with the
* debugger.
*
****************************************************************************/
int dram_main(int argc, char *argv)
{
int ret;
/* Here we have a in memory value we can change in the debugger
* to begin booting in NOR Flash
*/
static volatile uint32_t wait = DRAM_BOOT_MODE;
/* DRAM was already initialized at boot time, so we are ready to load the
* Intel HEX stream into DRAM.
*/
printf("Send Intel HEX file now\n");
fflush(stdout);
ret = hex2mem(0, /* Accept Intel HEX on stdin */
(uint32_t)SAM_DDRCS_VSECTION,
(uint32_t)(SAM_DDRCS_VSECTION + CONFIG_SAMA5_DDRCS_SIZE),
0);
if (ret < 0)
{
/* We failed the load */
printf("ERROR: Intel HEX file load failed: %d\n", ret);
fflush(stdout);
for(;;);
}
/* Interrupts must be disabled through the following. In this configuration,
* there should only be timer interrupts. Your NuttX configuration must use
* CONFIG_SERIAL_LOWCONSOLE=y or printf() will hang when the interrupts
* are disabled!
*/
(void)irqsave();
/* 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.
*/
cp15_disable_mmu();
cp15_disable_caches();
/* Invalidate caches and TLBs */
cp15_invalidate_icache();
cp15_invalidate_dcache_all();
cp15_invalidate_tlbs();
/* Then jump into NOR flash */
while (wait)
{
}
DRAM_ENTRY();
return 0; /* We should not get here in either case */
}