You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gu...@apache.org on 2021/11/26 17:55:39 UTC

[incubator-nuttx] branch master updated (c1cb429 -> 298c372)

This is an automated email from the ASF dual-hosted git repository.

gustavonihei pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git.


    from c1cb429  libc/hex2bin: Handle the line ending(\r, \n and \r\n) dynamically
     new 134b2e6  arch/arm/include/samv7: fix typo in samv7 irq header files
     new 0d94256  arch/arm/src/samv7: add flash progmem erasestate ioctl support
     new 5101542  boards/same70-xplained: initial support of MCUboot
     new 298c372  tools/nxstyle: fix nxstyle check for pointer to function types

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 arch/arm/include/samv7/same70_irq.h                |   2 +-
 arch/arm/include/samv7/samv71_irq.h                |   2 +-
 arch/arm/src/samv7/Kconfig                         |   7 +
 arch/arm/src/samv7/sam_progmem.c                   |  21 +-
 arch/arm/src/stm32h7/Kconfig                       |   4 +-
 boards/arm/samv7/same70-xplained/Kconfig           |  61 +++++
 boards/arm/samv7/same70-xplained/README.txt        |  37 +++
 .../configs/{nsh => mcuboot-confirm}/defconfig     |  11 +-
 .../configs/{nsh => mcuboot-loader}/defconfig      |  19 +-
 boards/arm/samv7/same70-xplained/scripts/Make.defs |  22 +-
 .../{flash-dtcm.ld => flash-dtcm-mcuboot-app.ld}   |   4 +-
 ...{flash-dtcm.ld => flash-dtcm-mcuboot-loader.ld} |   4 +-
 .../{flash-sram.ld => flash-sram-mcuboot-app.ld}   |   4 +-
 ...{flash-sram.ld => flash-sram-mcuboot-loader.ld} |   4 +-
 boards/arm/samv7/same70-xplained/src/Makefile      |   7 +-
 .../same70-xplained/src/sam_boot_image.c}          | 148 +++++++-----
 boards/arm/samv7/same70-xplained/src/sam_bringup.c |  46 +---
 boards/arm/samv7/same70-xplained/src/sam_progmem.c | 268 +++++++++++++++++++++
 .../samv7/same70-xplained/src/same70-xplained.h    |  11 +
 include/nuttx/progmem.h                            |   2 +-
 tools/nxstyle.c                                    |   2 +-
 21 files changed, 543 insertions(+), 143 deletions(-)
 copy boards/arm/samv7/same70-xplained/configs/{nsh => mcuboot-confirm}/defconfig (89%)
 copy boards/arm/samv7/same70-xplained/configs/{nsh => mcuboot-loader}/defconfig (83%)
 copy boards/arm/samv7/same70-xplained/scripts/{flash-dtcm.ld => flash-dtcm-mcuboot-app.ld} (96%)
 copy boards/arm/samv7/same70-xplained/scripts/{flash-dtcm.ld => flash-dtcm-mcuboot-loader.ld} (96%)
 copy boards/arm/samv7/same70-xplained/scripts/{flash-sram.ld => flash-sram-mcuboot-app.ld} (95%)
 copy boards/arm/samv7/same70-xplained/scripts/{flash-sram.ld => flash-sram-mcuboot-loader.ld} (96%)
 copy boards/arm/{stm32/common/src/stm32_nrf24l01.c => samv7/same70-xplained/src/sam_boot_image.c} (57%)
 create mode 100644 boards/arm/samv7/same70-xplained/src/sam_progmem.c

[incubator-nuttx] 01/04: arch/arm/include/samv7: fix typo in samv7 irq header files

Posted by gu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gustavonihei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 134b2e6ec9bbfb6381b89c910312b28873960e75
Author: Petro Karashchenko <pe...@gmail.com>
AuthorDate: Wed Nov 24 14:25:30 2021 +0200

    arch/arm/include/samv7: fix typo in samv7 irq header files
    
    Signed-off-by: Petro Karashchenko <pe...@gmail.com>
---
 arch/arm/include/samv7/same70_irq.h | 2 +-
 arch/arm/include/samv7/samv71_irq.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/include/samv7/same70_irq.h b/arch/arm/include/samv7/same70_irq.h
index d740225..6f026fd 100644
--- a/arch/arm/include/samv7/same70_irq.h
+++ b/arch/arm/include/samv7/same70_irq.h
@@ -179,7 +179,7 @@
 #define SAM_IRQ_CCF           (SAM_IRQ_EXTINT+SAM_PID_CCF)    /* ARM Cache ECC Fault */
 #define SAM_IRQ_EMACQ1        (SAM_IRQ_EXTINT+SAM_PID_EMACQ1) /* EMAC Queue 1 Interrupt */
 #define SAM_IRQ_EMACQ2        (SAM_IRQ_EXTINT+SAM_PID_EMACQ2) /* EMAC Queue 2 Interrupt */
-#define SAM_IRQ_FPIXC         (SAM_IRQ_EXTINTSAM_PID_FPIXC+)  /* ARM Cache ECC Warning */
+#define SAM_IRQ_FPIXC         (SAM_IRQ_EXTINT+SAM_PID_FPIXC)  /* ARM Cache ECC Warning */
 
 #define SAM_IRQ_NEXTINT       NR_PIDS                         /* Total number of external interrupt numbers */
 #define SAM_IRQ_NIRQS         (SAM_IRQ_EXTINT+NR_PIDS)        /* The number of real IRQs */
diff --git a/arch/arm/include/samv7/samv71_irq.h b/arch/arm/include/samv7/samv71_irq.h
index 3ce9317..42946ec 100644
--- a/arch/arm/include/samv7/samv71_irq.h
+++ b/arch/arm/include/samv7/samv71_irq.h
@@ -179,7 +179,7 @@
 #define SAM_IRQ_CCF           (SAM_IRQ_EXTINT+SAM_PID_CCF)    /* ARM Cache ECC Fault */
 #define SAM_IRQ_EMACQ1        (SAM_IRQ_EXTINT+SAM_PID_EMACQ1) /* EMAC Queue 1 Interrupt */
 #define SAM_IRQ_EMACQ2        (SAM_IRQ_EXTINT+SAM_PID_EMACQ2) /* EMAC Queue 2 Interrupt */
-#define SAM_IRQ_FPIXC         (SAM_IRQ_EXTINTSAM_PID_FPIXC+)  /* ARM Cache ECC Warning */
+#define SAM_IRQ_FPIXC         (SAM_IRQ_EXTINT+SAM_PID_FPIXC)  /* ARM Cache ECC Warning */
 
 #define SAM_IRQ_NEXTINT       NR_PIDS                         /* Total number of external interrupt numbers */
 #define SAM_IRQ_NIRQS         (SAM_IRQ_EXTINT+NR_PIDS)        /* The number of real IRQs */

[incubator-nuttx] 04/04: tools/nxstyle: fix nxstyle check for pointer to function types

Posted by gu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gustavonihei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 298c372afa2bb8d29f66ef6a6606880c5c641733
Author: Petro Karashchenko <pe...@gmail.com>
AuthorDate: Thu Nov 25 07:06:35 2021 +0200

    tools/nxstyle: fix nxstyle check for pointer to function types
    
    Signed-off-by: Petro Karashchenko <pe...@gmail.com>
---
 tools/nxstyle.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/nxstyle.c b/tools/nxstyle.c
index f2b44fb..c63328a 100644
--- a/tools/nxstyle.c
+++ b/tools/nxstyle.c
@@ -2469,7 +2469,7 @@ int main(int argc, char **argv, char **envp)
                     {
                       /* REVISIT: This gives false alarms on syntax like *--ptr */
 
-                      if (line[n - 1] != ' ')
+                      if (line[n - 1] != ' ' && line[n - 1] != '(')
                         {
                            ERROR("Operator/assignment must be preceded "
                                   "with whitespace", lineno, n);

[incubator-nuttx] 03/04: boards/same70-xplained: initial support of MCUboot

Posted by gu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gustavonihei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 510154299b38700fd4202fb0992e65fc23d0a19f
Author: Petro Karashchenko <pe...@gmail.com>
AuthorDate: Wed Nov 24 14:46:24 2021 +0200

    boards/same70-xplained: initial support of MCUboot
    
    Signed-off-by: Petro Karashchenko <pe...@gmail.com>
    
    Co-authored-by: Gerson Fernando Budke <na...@gmail.com>
---
 boards/arm/samv7/same70-xplained/Kconfig           |  61 +++++
 boards/arm/samv7/same70-xplained/README.txt        |  37 +++
 .../configs/mcuboot-confirm/defconfig              |  81 +++++++
 .../configs/mcuboot-loader/defconfig               |  83 +++++++
 boards/arm/samv7/same70-xplained/scripts/Make.defs |  22 +-
 .../scripts/flash-dtcm-mcuboot-app.ld              | 117 +++++++++
 .../scripts/flash-dtcm-mcuboot-loader.ld           | 117 +++++++++
 .../scripts/flash-sram-mcuboot-app.ld              | 114 +++++++++
 .../scripts/flash-sram-mcuboot-loader.ld           | 114 +++++++++
 boards/arm/samv7/same70-xplained/src/Makefile      |   7 +-
 .../arm/samv7/same70-xplained/src/sam_boot_image.c | 156 ++++++++++++
 boards/arm/samv7/same70-xplained/src/sam_bringup.c |  46 +---
 boards/arm/samv7/same70-xplained/src/sam_progmem.c | 268 +++++++++++++++++++++
 .../samv7/same70-xplained/src/same70-xplained.h    |  11 +
 14 files changed, 1185 insertions(+), 49 deletions(-)

diff --git a/boards/arm/samv7/same70-xplained/Kconfig b/boards/arm/samv7/same70-xplained/Kconfig
index dd3d2f0b..740e844 100644
--- a/boards/arm/samv7/same70-xplained/Kconfig
+++ b/boards/arm/samv7/same70-xplained/Kconfig
@@ -90,4 +90,65 @@ config SAME70XPLAINED_HSMCI0_AUTOMOUNT_UDELAY
 
 endif # SAME70XPLAINED_HSMCI0_AUTOMOUNT
 
+config SAME70XPLAINED_PROGMEM_OTA_PARTITION
+	bool
+	default n
+	select MTD
+	select MTD_BYTE_WRITE
+	select MTD_PARTITION
+	select MTD_PROGMEM
+	select MTD_PROGMEM_ERASESTATE
+
+menuconfig SAME70XPLAINED_APP_FORMAT_MCUBOOT
+	bool "MCUboot-bootable format"
+	default n
+	select SAME70XPLAINED_PROGMEM_OTA_PARTITION
+	---help---
+		The MCUboot support of loading the firmware images.
+
+if SAME70XPLAINED_APP_FORMAT_MCUBOOT
+
+config SAME70XPLAINED_MCUBOOT_BOOTLOADER
+	bool "MCUboot bootloader application"
+	default n
+	---help---
+		This switch between linker scripts to allow an application be
+		built to another entry point address.
+
+comment "MCUboot Application Image OTA Update support"
+
+config SAME70XPLAINED_OTA_PRIMARY_SLOT_OFFSET
+	hex "MCUboot application image primary slot offset"
+	default "0x20000"
+
+config SAME70XPLAINED_OTA_PRIMARY_SLOT_DEVPATH
+	string "Application image primary slot device path"
+	default "/dev/ota0"
+
+config SAME70XPLAINED_OTA_SECONDARY_SLOT_OFFSET
+	hex "MCUboot application image secondary slot offset"
+	default "0x100000"
+
+config SAME70XPLAINED_OTA_SECONDARY_SLOT_DEVPATH
+	string "Application image secondary slot device path"
+	default "/dev/ota1"
+
+config SAME70XPLAINED_OTA_SLOT_SIZE
+	hex "MCUboot application image slot size (in bytes)"
+	default "0xe0000"
+
+config SAME70XPLAINED_OTA_SCRATCH_OFFSET
+	hex "MCUboot scratch partition offset"
+	default "0x1e0000"
+
+config SAME70XPLAINED_OTA_SCRATCH_DEVPATH
+	string "Scratch partition device path"
+	default "/dev/otascratch"
+
+config SAME70XPLAINED_OTA_SCRATCH_SIZE
+	hex "MCUboot scratch partition size (in bytes)"
+	default "0x20000"
+
+endif # SAME70XPLAINED_APP_FORMAT_MCUBOOT
+
 endif # ARCH_BOARD_SAME70_XPLAINED
diff --git a/boards/arm/samv7/same70-xplained/README.txt b/boards/arm/samv7/same70-xplained/README.txt
index 5f5262f..57c78b7 100644
--- a/boards/arm/samv7/same70-xplained/README.txt
+++ b/boards/arm/samv7/same70-xplained/README.txt
@@ -1698,3 +1698,40 @@ Configuration sub-directories
          most of the issues.  Things look good on real, local hardware
          (see boards/lpcxpresso-lpc54628/twm4nx).  VNC is just not mature
          enough for this kind of usage at this time.
+
+  mcuboot-loader:
+    This configuration exercises the port of MCUboot loader to NuttX.
+
+    In this configuration both primary, secondary and scratch partitions are
+    mapped into the internal flash.
+    Relevant configuration settings:
+
+      CONFIG_BOARD_LATE_INITIALIZE=y
+
+      CONFIG_BOOT_MCUBOOT=y
+      CONFIG_MCUBOOT_BOOTLOADER=y
+      CONFIG_MCUBOOT_ENABLE_LOGGING=y
+
+      CONFIG_SAME70XPLAINED_APP_FORMAT_MCUBOOT=y
+      CONFIG_SAME70XPLAINED_MCUBOOT_BOOTLOADER=y
+      CONFIG_USER_ENTRYPOINT="mcuboot_loader_main"
+
+  mcuboot-confirm:
+    This configuration exercises the MCUboot compatible application slot
+    confirm example.
+
+    Generate signed binaries for MCUboot compatible application:
+      ./apps/boot/mcuboot/mcuboot/scripts/imgtool.py sign \
+        --key apps/boot/mcuboot/mcuboot/root-rsa-2048.pem --align 8 \
+        --version 1.0.0 --header-size 0x200 --pad-header --slot-size 0xe0000 \
+        nuttx/nuttx.bin signed_app_1_0_0.bin
+
+    Relevant configuration settings:
+
+      CONFIG_BOARD_LATE_INITIALIZE=y
+
+      CONFIG_BOOT_MCUBOOT=y
+      CONFIG_MCUBOOT_SLOT_CONFIRM_EXAMPLE=y
+
+      CONFIG_SAME70XPLAINED_APP_FORMAT_MCUBOOT=y
+      CONFIG_USER_ENTRYPOINT="mcuboot_confirm_main"
diff --git a/boards/arm/samv7/same70-xplained/configs/mcuboot-confirm/defconfig b/boards/arm/samv7/same70-xplained/configs/mcuboot-confirm/defconfig
new file mode 100644
index 0000000..a8314ae
--- /dev/null
+++ b/boards/arm/samv7/same70-xplained/configs/mcuboot-confirm/defconfig
@@ -0,0 +1,81 @@
+#
+# This file is autogenerated: PLEASE DO NOT EDIT IT.
+#
+# You can use "make menuconfig" to make any modifications to the installed .config file.
+# You can then do "make savedefconfig" to generate a new defconfig file that includes your
+# modifications.
+#
+# CONFIG_MMCSD_MMCSUPPORT is not set
+# CONFIG_MMCSD_SPI is not set
+# CONFIG_SAMV7_SDRAMHEAP is not set
+# CONFIG_SAMV7_UART0 is not set
+# CONFIG_SAMV7_UART2 is not set
+# CONFIG_SAMV7_UART4 is not set
+CONFIG_ARCH="arm"
+CONFIG_ARCH_BOARD="same70-xplained"
+CONFIG_ARCH_BOARD_SAME70_XPLAINED=y
+CONFIG_ARCH_BUTTONS=y
+CONFIG_ARCH_CHIP="samv7"
+CONFIG_ARCH_CHIP_SAME70=y
+CONFIG_ARCH_CHIP_SAME70Q21=y
+CONFIG_ARCH_CHIP_SAME70Q=y
+CONFIG_ARCH_CHIP_SAMV7=y
+CONFIG_ARCH_INTERRUPTSTACK=2048
+CONFIG_ARCH_IRQBUTTONS=y
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_ARMV7M_DCACHE=y
+CONFIG_ARMV7M_ICACHE=y
+CONFIG_ARMV7M_LAZYFPU=y
+CONFIG_AT24XX_ADDR=0x57
+CONFIG_AT24XX_EXTENDED=y
+CONFIG_AT24XX_EXTSIZE=160
+CONFIG_AT24XX_SIZE=2
+CONFIG_BOARD_LATE_INITIALIZE=y
+CONFIG_BOARD_LOOPSPERMSEC=51262
+CONFIG_BOOT_MCUBOOT=y
+CONFIG_BUILTIN=y
+CONFIG_FAT_LCNAMES=y
+CONFIG_FAT_LFN=y
+CONFIG_FS_FAT=y
+CONFIG_FS_PROCFS=y
+CONFIG_I2CTOOL_MAXBUS=0
+CONFIG_MCUBOOT_SLOT_CONFIRM_EXAMPLE=y
+CONFIG_MMCSD_MULTIBLOCK_DISABLE=y
+CONFIG_MMCSD_SDIO=y
+CONFIG_MTD_AT24XX=y
+CONFIG_MTD_AT25=y
+CONFIG_MTD_CONFIG=y
+CONFIG_NSH_ARCHINIT=y
+CONFIG_NSH_BUILTIN_APPS=y
+CONFIG_NSH_FILEIOSIZE=512
+CONFIG_NSH_LINELEN=64
+CONFIG_NSH_READLINE=y
+CONFIG_PREALLOC_TIMERS=4
+CONFIG_RAM_SIZE=393216
+CONFIG_RAM_START=0x20400000
+CONFIG_RAW_BINARY=y
+CONFIG_RR_INTERVAL=200
+CONFIG_SAME70XPLAINED_APP_FORMAT_MCUBOOT=y
+CONFIG_SAMV7_GPIOA_IRQ=y
+CONFIG_SAMV7_GPIOC_IRQ=y
+CONFIG_SAMV7_GPIO_IRQ=y
+CONFIG_SAMV7_HSMCI0=y
+CONFIG_SAMV7_PROGMEM=y
+CONFIG_SAMV7_PROGMEM_NSECTORS=16
+CONFIG_SAMV7_SDRAMC=y
+CONFIG_SAMV7_SDRAMSIZE=2097152
+CONFIG_SAMV7_TWIHS0=y
+CONFIG_SAMV7_USART1=y
+CONFIG_SAMV7_XDMAC=y
+CONFIG_SCHED_HPWORK=y
+CONFIG_SCHED_WAITPID=y
+CONFIG_SDCLONE_DISABLE=y
+CONFIG_SDIO_BLOCKSETUP=y
+CONFIG_START_DAY=10
+CONFIG_START_MONTH=3
+CONFIG_START_YEAR=2014
+CONFIG_SYSTEM_I2CTOOL=y
+CONFIG_SYSTEM_NSH=y
+CONFIG_SYSTEM_RAMTEST=y
+CONFIG_USART1_SERIAL_CONSOLE=y
+CONFIG_USER_ENTRYPOINT="mcuboot_confirm_main"
diff --git a/boards/arm/samv7/same70-xplained/configs/mcuboot-loader/defconfig b/boards/arm/samv7/same70-xplained/configs/mcuboot-loader/defconfig
new file mode 100644
index 0000000..369b25d
--- /dev/null
+++ b/boards/arm/samv7/same70-xplained/configs/mcuboot-loader/defconfig
@@ -0,0 +1,83 @@
+#
+# This file is autogenerated: PLEASE DO NOT EDIT IT.
+#
+# You can use "make menuconfig" to make any modifications to the installed .config file.
+# You can then do "make savedefconfig" to generate a new defconfig file that includes your
+# modifications.
+#
+# CONFIG_MMCSD_MMCSUPPORT is not set
+# CONFIG_MMCSD_SPI is not set
+# CONFIG_SAMV7_SDRAMHEAP is not set
+# CONFIG_SAMV7_UART0 is not set
+# CONFIG_SAMV7_UART2 is not set
+# CONFIG_SAMV7_UART4 is not set
+CONFIG_ARCH="arm"
+CONFIG_ARCH_BOARD="same70-xplained"
+CONFIG_ARCH_BOARD_SAME70_XPLAINED=y
+CONFIG_ARCH_BUTTONS=y
+CONFIG_ARCH_CHIP="samv7"
+CONFIG_ARCH_CHIP_SAME70=y
+CONFIG_ARCH_CHIP_SAME70Q21=y
+CONFIG_ARCH_CHIP_SAME70Q=y
+CONFIG_ARCH_CHIP_SAMV7=y
+CONFIG_ARCH_INTERRUPTSTACK=2048
+CONFIG_ARCH_IRQBUTTONS=y
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_ARMV7M_DCACHE=y
+CONFIG_ARMV7M_ICACHE=y
+CONFIG_ARMV7M_LAZYFPU=y
+CONFIG_AT24XX_ADDR=0x57
+CONFIG_AT24XX_EXTENDED=y
+CONFIG_AT24XX_EXTSIZE=160
+CONFIG_AT24XX_SIZE=2
+CONFIG_BOARD_LATE_INITIALIZE=y
+CONFIG_BOARD_LOOPSPERMSEC=51262
+CONFIG_BOOT_MCUBOOT=y
+CONFIG_BUILTIN=y
+CONFIG_FAT_LCNAMES=y
+CONFIG_FAT_LFN=y
+CONFIG_FS_FAT=y
+CONFIG_FS_PROCFS=y
+CONFIG_I2CTOOL_MAXBUS=0
+CONFIG_MCUBOOT_BOOTLOADER=y
+CONFIG_MCUBOOT_ENABLE_LOGGING=y
+CONFIG_MMCSD_MULTIBLOCK_DISABLE=y
+CONFIG_MMCSD_SDIO=y
+CONFIG_MTD_AT24XX=y
+CONFIG_MTD_AT25=y
+CONFIG_MTD_CONFIG=y
+CONFIG_NSH_ARCHINIT=y
+CONFIG_NSH_BUILTIN_APPS=y
+CONFIG_NSH_FILEIOSIZE=512
+CONFIG_NSH_LINELEN=64
+CONFIG_NSH_READLINE=y
+CONFIG_PREALLOC_TIMERS=4
+CONFIG_RAM_SIZE=393216
+CONFIG_RAM_START=0x20400000
+CONFIG_RAW_BINARY=y
+CONFIG_RR_INTERVAL=200
+CONFIG_SAME70XPLAINED_APP_FORMAT_MCUBOOT=y
+CONFIG_SAME70XPLAINED_MCUBOOT_BOOTLOADER=y
+CONFIG_SAMV7_GPIOA_IRQ=y
+CONFIG_SAMV7_GPIOC_IRQ=y
+CONFIG_SAMV7_GPIO_IRQ=y
+CONFIG_SAMV7_HSMCI0=y
+CONFIG_SAMV7_PROGMEM=y
+CONFIG_SAMV7_PROGMEM_NSECTORS=16
+CONFIG_SAMV7_SDRAMC=y
+CONFIG_SAMV7_SDRAMSIZE=2097152
+CONFIG_SAMV7_TWIHS0=y
+CONFIG_SAMV7_USART1=y
+CONFIG_SAMV7_XDMAC=y
+CONFIG_SCHED_HPWORK=y
+CONFIG_SCHED_WAITPID=y
+CONFIG_SDCLONE_DISABLE=y
+CONFIG_SDIO_BLOCKSETUP=y
+CONFIG_START_DAY=24
+CONFIG_START_MONTH=11
+CONFIG_START_YEAR=2021
+CONFIG_SYSTEM_I2CTOOL=y
+CONFIG_SYSTEM_NSH=y
+CONFIG_SYSTEM_RAMTEST=y
+CONFIG_USART1_SERIAL_CONSOLE=y
+CONFIG_USER_ENTRYPOINT="mcuboot_loader_main"
diff --git a/boards/arm/samv7/same70-xplained/scripts/Make.defs b/boards/arm/samv7/same70-xplained/scripts/Make.defs
index cf6d86e..0d508f4 100644
--- a/boards/arm/samv7/same70-xplained/scripts/Make.defs
+++ b/boards/arm/samv7/same70-xplained/scripts/Make.defs
@@ -22,10 +22,26 @@ include $(TOPDIR)/.config
 include $(TOPDIR)/tools/Config.mk
 include $(TOPDIR)/arch/arm/src/armv7-m/Toolchain.defs
 
-ifeq ($(CONFIG_ARMV7M_DTCM),y)
-  LDSCRIPT = flash-dtcm.ld
+ifeq ($(CONFIG_SAME70XPLAINED_APP_FORMAT_MCUBOOT),y)
+ifeq ($(CONFIG_SAME70XPLAINED_MCUBOOT_BOOTLOADER),y)
+  ifeq ($(CONFIG_ARMV7M_DTCM),y)
+    LDSCRIPT = flash-dtcm-mcuboot-loader.ld
+  else
+    LDSCRIPT = flash-sram-mcuboot-loader.ld
+  endif
 else
-  LDSCRIPT = flash-sram.ld
+  ifeq ($(CONFIG_ARMV7M_DTCM),y)
+    LDSCRIPT = flash-dtcm-mcuboot-app.ld
+  else
+    LDSCRIPT = flash-sram-mcuboot-app.ld
+  endif
+endif
+else
+  ifeq ($(CONFIG_ARMV7M_DTCM),y)
+    LDSCRIPT = flash-dtcm.ld
+  else
+    LDSCRIPT = flash-sram.ld
+  endif
 endif
 
 ifeq ($(CONFIG_CYGWIN_WINTOOL),y)
diff --git a/boards/arm/samv7/same70-xplained/scripts/flash-dtcm-mcuboot-app.ld b/boards/arm/samv7/same70-xplained/scripts/flash-dtcm-mcuboot-app.ld
new file mode 100644
index 0000000..5eae10d
--- /dev/null
+++ b/boards/arm/samv7/same70-xplained/scripts/flash-dtcm-mcuboot-app.ld
@@ -0,0 +1,117 @@
+/****************************************************************************
+ * boards/arm/samv7/same70-xplained/scripts/flash-dtcm-mcuboot-app.ld
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/* The SAME70Q21 has 2048Kb of FLASH beginning at address 0x0040:0000 and
+ * 384Kb of SRAM beginining at 0x2040:0000
+ *
+ * When booting from FLASH, FLASH memory is aliased to address 0x0000:0000
+ * where the code expects to begin execution by jumping to the entry point in
+ * the 0x0400:0000 address range (Assuming that ITCM is not enable).
+ *
+ * NOTE: that the DTCM address of 0x2000:0000 is used for SRAM.  If DTCM is
+ * disabled, then the accesses will actually occur on the AHB bus.
+ */
+
+MEMORY
+{
+  flash (rx) : ORIGIN = 0x00420200, LENGTH = 2048K - 128K - 0x200
+  sram (rwx) : ORIGIN = 0x20000000, LENGTH = 384K
+}
+
+OUTPUT_ARCH(arm)
+EXTERN(_vectors)
+ENTRY(_stext)
+
+SECTIONS
+{
+    .text : {
+        _stext = ABSOLUTE(.);
+        *(.vectors)
+        *(.text .text.*)
+        *(.fixup)
+        *(.gnu.warning)
+        *(.rodata .rodata.*)
+        *(.gnu.linkonce.t.*)
+        *(.glue_7)
+        *(.glue_7t)
+        *(.got)
+        *(.gcc_except_table)
+        *(.gnu.linkonce.r.*)
+        _etext = ABSOLUTE(.);
+    } > flash
+
+    .init_section : {
+        _sinit = ABSOLUTE(.);
+        *(.init_array .init_array.*)
+        _einit = ABSOLUTE(.);
+    } > flash
+
+    .ARM.extab : {
+        *(.ARM.extab*)
+    } > flash
+
+    __exidx_start = ABSOLUTE(.);
+    .ARM.exidx : {
+        *(.ARM.exidx*)
+    } > flash
+    __exidx_end = ABSOLUTE(.);
+
+    _eronly = ABSOLUTE(.);
+
+    .data : {
+        _sdata = ABSOLUTE(.);
+        *(.data .data.*)
+        *(.gnu.linkonce.d.*)
+        CONSTRUCTORS
+        . = ALIGN(4);
+        _edata = ABSOLUTE(.);
+    } > sram AT > flash
+
+    .ramfunc ALIGN(4): {
+        _sramfuncs = ABSOLUTE(.);
+        *(.ramfunc  .ramfunc.*)
+        _eramfuncs = ABSOLUTE(.);
+    } > sram AT > flash
+
+    _framfuncs = LOADADDR(.ramfunc);
+
+    .bss : {
+        _sbss = ABSOLUTE(.);
+        *(.bss .bss.*)
+        *(.gnu.linkonce.b.*)
+        *(COMMON)
+        . = ALIGN(4);
+        _ebss = ABSOLUTE(.);
+    } > sram
+
+    /* Stabs debugging sections. */
+    .stab 0 : { *(.stab) }
+    .stabstr 0 : { *(.stabstr) }
+    .stab.excl 0 : { *(.stab.excl) }
+    .stab.exclstr 0 : { *(.stab.exclstr) }
+    .stab.index 0 : { *(.stab.index) }
+    .stab.indexstr 0 : { *(.stab.indexstr) }
+    .comment 0 : { *(.comment) }
+    .debug_abbrev 0 : { *(.debug_abbrev) }
+    .debug_info 0 : { *(.debug_info) }
+    .debug_line 0 : { *(.debug_line) }
+    .debug_pubnames 0 : { *(.debug_pubnames) }
+    .debug_aranges 0 : { *(.debug_aranges) }
+}
diff --git a/boards/arm/samv7/same70-xplained/scripts/flash-dtcm-mcuboot-loader.ld b/boards/arm/samv7/same70-xplained/scripts/flash-dtcm-mcuboot-loader.ld
new file mode 100644
index 0000000..15c29ce
--- /dev/null
+++ b/boards/arm/samv7/same70-xplained/scripts/flash-dtcm-mcuboot-loader.ld
@@ -0,0 +1,117 @@
+/****************************************************************************
+ * boards/arm/samv7/same70-xplained/scripts/flash-dtcm-mcuboot-loader.ld
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/* The SAME70Q21 has 2048Kb of FLASH beginning at address 0x0040:0000 and
+ * 384Kb of SRAM beginining at 0x2040:0000
+ *
+ * When booting from FLASH, FLASH memory is aliased to address 0x0000:0000
+ * where the code expects to begin execution by jumping to the entry point in
+ * the 0x0400:0000 address range (Assuming that ITCM is not enable).
+ *
+ * NOTE: that the DTCM address of 0x2000:0000 is used for SRAM.  If DTCM is
+ * disabled, then the accesses will actually occur on the AHB bus.
+ */
+
+MEMORY
+{
+  flash (rx) : ORIGIN = 0x00400000, LENGTH = 128K
+  sram (rwx) : ORIGIN = 0x20000000, LENGTH = 384K
+}
+
+OUTPUT_ARCH(arm)
+EXTERN(_vectors)
+ENTRY(_stext)
+
+SECTIONS
+{
+    .text : {
+        _stext = ABSOLUTE(.);
+        *(.vectors)
+        *(.text .text.*)
+        *(.fixup)
+        *(.gnu.warning)
+        *(.rodata .rodata.*)
+        *(.gnu.linkonce.t.*)
+        *(.glue_7)
+        *(.glue_7t)
+        *(.got)
+        *(.gcc_except_table)
+        *(.gnu.linkonce.r.*)
+        _etext = ABSOLUTE(.);
+    } > flash
+
+    .init_section : {
+        _sinit = ABSOLUTE(.);
+        *(.init_array .init_array.*)
+        _einit = ABSOLUTE(.);
+    } > flash
+
+    .ARM.extab : {
+        *(.ARM.extab*)
+    } > flash
+
+    __exidx_start = ABSOLUTE(.);
+    .ARM.exidx : {
+        *(.ARM.exidx*)
+    } > flash
+    __exidx_end = ABSOLUTE(.);
+
+    _eronly = ABSOLUTE(.);
+
+    .data : {
+        _sdata = ABSOLUTE(.);
+        *(.data .data.*)
+        *(.gnu.linkonce.d.*)
+        CONSTRUCTORS
+        . = ALIGN(4);
+        _edata = ABSOLUTE(.);
+    } > sram AT > flash
+
+    .ramfunc ALIGN(4): {
+        _sramfuncs = ABSOLUTE(.);
+        *(.ramfunc  .ramfunc.*)
+        _eramfuncs = ABSOLUTE(.);
+    } > sram AT > flash
+
+    _framfuncs = LOADADDR(.ramfunc);
+
+    .bss : {
+        _sbss = ABSOLUTE(.);
+        *(.bss .bss.*)
+        *(.gnu.linkonce.b.*)
+        *(COMMON)
+        . = ALIGN(4);
+        _ebss = ABSOLUTE(.);
+    } > sram
+
+    /* Stabs debugging sections. */
+    .stab 0 : { *(.stab) }
+    .stabstr 0 : { *(.stabstr) }
+    .stab.excl 0 : { *(.stab.excl) }
+    .stab.exclstr 0 : { *(.stab.exclstr) }
+    .stab.index 0 : { *(.stab.index) }
+    .stab.indexstr 0 : { *(.stab.indexstr) }
+    .comment 0 : { *(.comment) }
+    .debug_abbrev 0 : { *(.debug_abbrev) }
+    .debug_info 0 : { *(.debug_info) }
+    .debug_line 0 : { *(.debug_line) }
+    .debug_pubnames 0 : { *(.debug_pubnames) }
+    .debug_aranges 0 : { *(.debug_aranges) }
+}
diff --git a/boards/arm/samv7/same70-xplained/scripts/flash-sram-mcuboot-app.ld b/boards/arm/samv7/same70-xplained/scripts/flash-sram-mcuboot-app.ld
new file mode 100644
index 0000000..8af295c
--- /dev/null
+++ b/boards/arm/samv7/same70-xplained/scripts/flash-sram-mcuboot-app.ld
@@ -0,0 +1,114 @@
+/****************************************************************************
+ * boards/arm/samv7/same70-xplained/scripts/flash-sram-mcuboot-app.ld
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/* The SAME70Q21 has 2048Kb of FLASH beginning at address 0x0040:0000 and
+ * 384Kb of SRAM beginining at 0x2040:0000
+ *
+ * When booting from FLASH, FLASH memory is aliased to address 0x0000:0000
+ * where the code expects to begin execution by jumping to the entry point in
+ * the 0x0400:0000 address range (Assuming that ITCM is not enable).
+ */
+
+MEMORY
+{
+  flash (rx) : ORIGIN = 0x00420200, LENGTH = 2048K - 128K - 0x200
+  sram (rwx) : ORIGIN = 0x20400000, LENGTH = 384K
+}
+
+OUTPUT_ARCH(arm)
+EXTERN(_vectors)
+ENTRY(_stext)
+
+SECTIONS
+{
+    .text : {
+        _stext = ABSOLUTE(.);
+        *(.vectors)
+        *(.text .text.*)
+        *(.fixup)
+        *(.gnu.warning)
+        *(.rodata .rodata.*)
+        *(.gnu.linkonce.t.*)
+        *(.glue_7)
+        *(.glue_7t)
+        *(.got)
+        *(.gcc_except_table)
+        *(.gnu.linkonce.r.*)
+        _etext = ABSOLUTE(.);
+    } > flash
+
+    .init_section : {
+        _sinit = ABSOLUTE(.);
+        *(.init_array .init_array.*)
+        _einit = ABSOLUTE(.);
+    } > flash
+
+    .ARM.extab : {
+        *(.ARM.extab*)
+    } > flash
+
+    __exidx_start = ABSOLUTE(.);
+    .ARM.exidx : {
+        *(.ARM.exidx*)
+    } > flash
+    __exidx_end = ABSOLUTE(.);
+
+    _eronly = ABSOLUTE(.);
+
+    .data : {
+        _sdata = ABSOLUTE(.);
+        *(.data .data.*)
+        *(.gnu.linkonce.d.*)
+        CONSTRUCTORS
+        . = ALIGN(4);
+        _edata = ABSOLUTE(.);
+    } > sram AT > flash
+
+    .ramfunc ALIGN(4): {
+        _sramfuncs = ABSOLUTE(.);
+        *(.ramfunc  .ramfunc.*)
+        _eramfuncs = ABSOLUTE(.);
+    } > sram AT > flash
+
+    _framfuncs = LOADADDR(.ramfunc);
+
+    .bss : {
+        _sbss = ABSOLUTE(.);
+        *(.bss .bss.*)
+        *(.gnu.linkonce.b.*)
+        *(COMMON)
+        . = ALIGN(4);
+        _ebss = ABSOLUTE(.);
+    } > sram
+
+    /* Stabs debugging sections. */
+    .stab 0 : { *(.stab) }
+    .stabstr 0 : { *(.stabstr) }
+    .stab.excl 0 : { *(.stab.excl) }
+    .stab.exclstr 0 : { *(.stab.exclstr) }
+    .stab.index 0 : { *(.stab.index) }
+    .stab.indexstr 0 : { *(.stab.indexstr) }
+    .comment 0 : { *(.comment) }
+    .debug_abbrev 0 : { *(.debug_abbrev) }
+    .debug_info 0 : { *(.debug_info) }
+    .debug_line 0 : { *(.debug_line) }
+    .debug_pubnames 0 : { *(.debug_pubnames) }
+    .debug_aranges 0 : { *(.debug_aranges) }
+}
diff --git a/boards/arm/samv7/same70-xplained/scripts/flash-sram-mcuboot-loader.ld b/boards/arm/samv7/same70-xplained/scripts/flash-sram-mcuboot-loader.ld
new file mode 100644
index 0000000..d9b6ee8
--- /dev/null
+++ b/boards/arm/samv7/same70-xplained/scripts/flash-sram-mcuboot-loader.ld
@@ -0,0 +1,114 @@
+/****************************************************************************
+ * boards/arm/samv7/same70-xplained/scripts/flash-sram-mcuboot-loader.ld
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/* The SAME70Q21 has 2048Kb of FLASH beginning at address 0x0040:0000 and
+ * 384Kb of SRAM beginining at 0x2040:0000
+ *
+ * When booting from FLASH, FLASH memory is aliased to address 0x0000:0000
+ * where the code expects to begin execution by jumping to the entry point in
+ * the 0x0400:0000 address range (Assuming that ITCM is not enable).
+ */
+
+MEMORY
+{
+  flash (rx) : ORIGIN = 0x00400000, LENGTH = 128K
+  sram (rwx) : ORIGIN = 0x20400000, LENGTH = 384K
+}
+
+OUTPUT_ARCH(arm)
+EXTERN(_vectors)
+ENTRY(_stext)
+
+SECTIONS
+{
+    .text : {
+        _stext = ABSOLUTE(.);
+        *(.vectors)
+        *(.text .text.*)
+        *(.fixup)
+        *(.gnu.warning)
+        *(.rodata .rodata.*)
+        *(.gnu.linkonce.t.*)
+        *(.glue_7)
+        *(.glue_7t)
+        *(.got)
+        *(.gcc_except_table)
+        *(.gnu.linkonce.r.*)
+        _etext = ABSOLUTE(.);
+    } > flash
+
+    .init_section : {
+        _sinit = ABSOLUTE(.);
+        *(.init_array .init_array.*)
+        _einit = ABSOLUTE(.);
+    } > flash
+
+    .ARM.extab : {
+        *(.ARM.extab*)
+    } > flash
+
+    __exidx_start = ABSOLUTE(.);
+    .ARM.exidx : {
+        *(.ARM.exidx*)
+    } > flash
+    __exidx_end = ABSOLUTE(.);
+
+    _eronly = ABSOLUTE(.);
+
+    .data : {
+        _sdata = ABSOLUTE(.);
+        *(.data .data.*)
+        *(.gnu.linkonce.d.*)
+        CONSTRUCTORS
+        . = ALIGN(4);
+        _edata = ABSOLUTE(.);
+    } > sram AT > flash
+
+    .ramfunc ALIGN(4): {
+        _sramfuncs = ABSOLUTE(.);
+        *(.ramfunc  .ramfunc.*)
+        _eramfuncs = ABSOLUTE(.);
+    } > sram AT > flash
+
+    _framfuncs = LOADADDR(.ramfunc);
+
+    .bss : {
+        _sbss = ABSOLUTE(.);
+        *(.bss .bss.*)
+        *(.gnu.linkonce.b.*)
+        *(COMMON)
+        . = ALIGN(4);
+        _ebss = ABSOLUTE(.);
+    } > sram
+
+    /* Stabs debugging sections. */
+    .stab 0 : { *(.stab) }
+    .stabstr 0 : { *(.stabstr) }
+    .stab.excl 0 : { *(.stab.excl) }
+    .stab.exclstr 0 : { *(.stab.exclstr) }
+    .stab.index 0 : { *(.stab.index) }
+    .stab.indexstr 0 : { *(.stab.indexstr) }
+    .comment 0 : { *(.comment) }
+    .debug_abbrev 0 : { *(.debug_abbrev) }
+    .debug_info 0 : { *(.debug_info) }
+    .debug_line 0 : { *(.debug_line) }
+    .debug_pubnames 0 : { *(.debug_pubnames) }
+    .debug_aranges 0 : { *(.debug_aranges) }
+}
diff --git a/boards/arm/samv7/same70-xplained/src/Makefile b/boards/arm/samv7/same70-xplained/src/Makefile
index c0e6a12..b78b8b0 100644
--- a/boards/arm/samv7/same70-xplained/src/Makefile
+++ b/boards/arm/samv7/same70-xplained/src/Makefile
@@ -27,12 +27,15 @@ CSRCS += sam_sdram.c
 endif
 
 ifeq ($(CONFIG_BOARDCTL),y)
-CSRCS += sam_appinit.c sam_bringup.c
+CSRCS += sam_appinit.c sam_bringup.c sam_progmem.c
 ifeq ($(CONFIG_BOARDCTL_RESET),y)
 CSRCS += sam_reset.c
 endif
+ifeq ($(CONFIG_BOARDCTL_BOOT_IMAGE),y)
+CSRCS += sam_boot_image.c
+endif
 else ifeq ($(CONFIG_BOARD_LATE_INITIALIZE),y)
-CSRCS += sam_bringup.c
+CSRCS += sam_bringup.c sam_progmem.c
 endif
 
 ifeq ($(CONFIG_ARCH_LEDS),y)
diff --git a/boards/arm/samv7/same70-xplained/src/sam_boot_image.c b/boards/arm/samv7/same70-xplained/src/sam_boot_image.c
new file mode 100644
index 0000000..4bc2e3c
--- /dev/null
+++ b/boards/arm/samv7/same70-xplained/src/sam_boot_image.c
@@ -0,0 +1,156 @@
+/****************************************************************************
+ * boards/arm/samv7/same70-xplained/src/sam_boot_image.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <debug.h>
+#include <stdio.h>
+#include <fcntl.h>
+
+#include <sys/boardctl.h>
+#include <nuttx/irq.h>
+#include <nuttx/cache.h>
+
+#include "nvic.h"
+#include "arm_arch.h"
+#include "barriers.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* This structure represents the first two entries on NVIC vector table */
+
+struct arm_vector_table
+{
+  uint32_t spr;   /* Stack pointer on reset */
+  uint32_t reset; /* Pointer to reset exception handler */
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static void cleanup_arm_nvic(void);
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name:  cleanup_arm_nvic
+ *
+ * Description:
+ *   Acknowledge and disable all interrupts in NVIC
+ *
+ * Input Parameters:
+ *   None
+ *
+ *  Returned Value:
+ *    None
+ *
+ ****************************************************************************/
+
+static void cleanup_arm_nvic(void)
+{
+  int i;
+
+  /* Allow any pending interrupts to be recognized */
+
+  ARM_ISB();
+  cpsid();
+
+  /* Disable all interrupts */
+
+  for (i = 0; i < SAM_IRQ_NIRQS; i += 32)
+    {
+      putreg32(0xffffffff, NVIC_IRQ_CLEAR(i));
+    }
+
+  /* Clear all pending interrupts */
+
+  for (i = 0; i < SAM_IRQ_NIRQS; i += 32)
+    {
+      putreg32(0xffffffff, NVIC_IRQ_CLRPEND(i));
+    }
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_boot_image
+ *
+ * Description:
+ *   This entry point is called by bootloader to jump to application image.
+ *
+ ****************************************************************************/
+
+int board_boot_image(FAR const char *path, uint32_t hdr_size)
+{
+  static struct arm_vector_table vt;
+  int fd;
+  ssize_t bytes;
+
+  fd = open(path, O_RDONLY | O_CLOEXEC);
+  if (fd < 0)
+    {
+      syslog(LOG_ERR, "Failed to open %s with: %d", path, fd);
+      return fd;
+    }
+
+  bytes = pread(fd, &vt, sizeof(vt), hdr_size);
+  if (bytes != sizeof(vt))
+    {
+      syslog(LOG_ERR, "Failed to read ARM vector table: %d", bytes);
+      return bytes < 0 ? bytes : -1;
+    }
+
+  cleanup_arm_nvic();
+
+#ifdef CONFIG_ARMV7M_DCACHE
+  up_disable_dcache();
+#endif
+#ifdef CONFIG_ARMV7M_ICACHE
+  up_disable_icache();
+#endif
+
+#ifdef CONFIG_ARM_MPU
+  mpu_control(false, false, false);
+#endif
+
+  /* Set main and process stack pointers */
+
+  __asm__ __volatile__("\tmsr msp, %0\n" : : "r" (vt.spr));
+  setcontrol(0x00);
+  ARM_ISB();
+  ((void (*)(void))vt.reset)();
+
+  return 0;
+}
diff --git a/boards/arm/samv7/same70-xplained/src/sam_bringup.c b/boards/arm/samv7/same70-xplained/src/sam_bringup.c
index 5d0265e..51d15fb 100644
--- a/boards/arm/samv7/same70-xplained/src/sam_bringup.c
+++ b/boards/arm/samv7/same70-xplained/src/sam_bringup.c
@@ -45,11 +45,6 @@
 #include "sam_twihs.h"
 #include "same70-xplained.h"
 
-#ifdef HAVE_PROGMEM_CHARDEV
-#  include <nuttx/mtd/mtd.h>
-#  include "sam_progmem.h"
-#endif
-
 #ifdef HAVE_ROMFS
 #  include <arch/board/boot_romfsimg.h>
 #endif
@@ -137,13 +132,6 @@ static void sam_i2ctool(void)
 
 int sam_bringup(void)
 {
-#ifdef HAVE_PROGMEM_CHARDEV
-  FAR struct mtd_dev_s *mtd;
-#if defined(CONFIG_BCH)
-  char blockdev[18];
-  char chardev[12];
-#endif /* defined(CONFIG_BCH) */
-#endif
   int ret;
 
   /* Register I2C drivers on behalf of the I2C tool */
@@ -252,42 +240,12 @@ int sam_bringup(void)
 #ifdef HAVE_PROGMEM_CHARDEV
   /* Initialize the SAME70 FLASH programming memory library */
 
-  sam_progmem_initialize();
-
-  /* Create an instance of the SAME70 FLASH program memory device driver */
-
-  mtd = progmem_initialize();
-  if (!mtd)
-    {
-      syslog(LOG_ERR, "ERROR: progmem_initialize failed\n");
-    }
-
-  /* Use the FTL layer to wrap the MTD driver as a block driver */
-
-  ret = ftl_initialize(PROGMEM_MTD_MINOR, mtd);
-  if (ret < 0)
-    {
-      syslog(LOG_ERR, "ERROR: Failed to initialize the FTL layer: %d\n",
-             ret);
-      return ret;
-    }
-
-#if defined(CONFIG_BCH)
-  /* Use the minor number to create device paths */
-
-  snprintf(blockdev, 18, "/dev/mtdblock%d", PROGMEM_MTD_MINOR);
-  snprintf(chardev, 12, "/dev/mtd%d", PROGMEM_MTD_MINOR);
-
-  /* Now create a character device on the block device */
-
-  ret = bchdev_register(blockdev, chardev, false);
+  ret = sam_progmem_init();
   if (ret < 0)
     {
-      syslog(LOG_ERR, "ERROR: bchdev_register %s failed: %d\n",
-             chardev, ret);
+      syslog(LOG_ERR, "ERROR: Failed to initialize progmem: %d\n", ret);
       return ret;
     }
-#endif /* defined(CONFIG_BCH) */
 #endif
 
 #ifdef HAVE_USBHOST
diff --git a/boards/arm/samv7/same70-xplained/src/sam_progmem.c b/boards/arm/samv7/same70-xplained/src/sam_progmem.c
new file mode 100644
index 0000000..3232c2f
--- /dev/null
+++ b/boards/arm/samv7/same70-xplained/src/sam_progmem.c
@@ -0,0 +1,268 @@
+/****************************************************************************
+ * boards/arm/samv7/same70-xplained/src/sam_progmem.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/mount.h>
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/kmalloc.h>
+#include <nuttx/mtd/mtd.h>
+#ifdef CONFIG_BCH
+#include <nuttx/drivers/drivers.h>
+#endif
+
+#include "sam_progmem.h"
+#include "same70-xplained.h"
+
+#ifdef HAVE_PROGMEM_CHARDEV
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ARRAYSIZE(x)                (sizeof((x)) / sizeof((x)[0]))
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+#if defined(SAME70XPLAINED_PROGMEM_OTA_PARTITION)
+
+struct ota_partition_s
+{
+  uint32_t    offset;          /* Partition offset from the beginning of MTD */
+  uint32_t    size;            /* Partition size in bytes */
+  const char *devpath;         /* Partition device path */
+};
+
+#endif
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+#if defined(SAME70XPLAINED_PROGMEM_OTA_PARTITION)
+static struct mtd_dev_s *sam_progmem_alloc_mtdpart(uint32_t mtd_offset,
+                                                   uint32_t mtd_size);
+static int init_ota_partitions(void);
+#endif
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static FAR struct mtd_dev_s *g_samv7_progmem_mtd;
+
+#if defined(SAME70XPLAINED_PROGMEM_OTA_PARTITION)
+static const struct ota_partition_s g_ota_partition_table[] =
+{
+  {
+    .offset  = CONFIG_SAME70XPLAINED_OTA_PRIMARY_SLOT_OFFSET,
+    .size    = CONFIG_SAME70XPLAINED_OTA_SLOT_SIZE,
+    .devpath = CONFIG_SAME70XPLAINED_OTA_PRIMARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_SAME70XPLAINED_OTA_SECONDARY_SLOT_OFFSET,
+    .size    = CONFIG_SAME70XPLAINED_OTA_SLOT_SIZE,
+    .devpath = CONFIG_SAME70XPLAINED_OTA_SECONDARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_SAME70XPLAINED_OTA_SCRATCH_OFFSET,
+    .size    = CONFIG_SAME70XPLAINED_OTA_SCRATCH_SIZE,
+    .devpath = CONFIG_SAME70XPLAINED_OTA_SCRATCH_DEVPATH
+  }
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(SAME70XPLAINED_PROGMEM_OTA_PARTITION)
+
+/****************************************************************************
+ * Name: sam_progmem_alloc_mtdpart
+ *
+ * Description:
+ *   Allocate an MTD partition from FLASH.
+ *
+ * Input Parameters:
+ *   mtd_offset - MTD Partition offset from the base address in FLASH.
+ *   mtd_size   - Size for the MTD partition.
+ *
+ * Returned Value:
+ *   MTD partition data pointer on success, NULL on failure.
+ *
+ ****************************************************************************/
+
+static struct mtd_dev_s *sam_progmem_alloc_mtdpart(uint32_t mtd_offset,
+                                                   uint32_t mtd_size)
+{
+  uint32_t blocks;
+  uint32_t startblock;
+
+  ASSERT((mtd_offset + mtd_size) <= up_progmem_neraseblocks() *
+          up_progmem_pagesize(0));
+  ASSERT((mtd_offset % up_progmem_pagesize(0)) == 0);
+  ASSERT((mtd_size % up_progmem_pagesize(0)) == 0);
+
+  finfo("\tMTD offset = 0x%"PRIx32"\n", mtd_offset);
+  finfo("\tMTD size = 0x%"PRIx32"\n", mtd_size);
+
+  startblock = up_progmem_getpage(mtd_offset);
+  if (startblock < 0)
+    {
+      return NULL;
+    }
+
+  blocks = mtd_size / up_progmem_pagesize(0);
+
+  return mtd_partition(g_samv7_progmem_mtd, startblock, blocks);
+}
+
+/****************************************************************************
+ * Name: init_ota_partitions
+ *
+ * Description:
+ *   Initialize partitions that are dedicated to firmware OTA update.
+ *
+ * Input Parameters:
+ *   None.
+ *
+ * Returned Value:
+ *   Zero on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+static int init_ota_partitions(void)
+{
+  FAR struct mtd_dev_s *mtd;
+#ifdef CONFIG_BCH
+  char blockdev[18];
+#endif
+  int ret = OK;
+
+  for (int i = 0; i < ARRAYSIZE(g_ota_partition_table); ++i)
+    {
+      const struct ota_partition_s *part = &g_ota_partition_table[i];
+      mtd = sam_progmem_alloc_mtdpart(part->offset, part->size);
+
+      ret = ftl_initialize(i, mtd);
+      if (ret < 0)
+        {
+          ferr("ERROR: Failed to initialize the FTL layer: %d\n", ret);
+          return ret;
+        }
+
+#ifdef CONFIG_BCH
+      snprintf(blockdev, 18, "/dev/mtdblock%d", i);
+
+      ret = bchdev_register(blockdev, part->devpath, false);
+      if (ret < 0)
+        {
+          ferr("ERROR: bchdev_register %s failed: %d\n", part->devpath, ret);
+          return ret;
+        }
+#endif
+    }
+
+  return ret;
+}
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sam_progmem_init
+ *
+ * Description:
+ *   Initialize the FLASH and register the MTD device.
+ ****************************************************************************/
+
+int sam_progmem_init(void)
+{
+  int ret = OK;
+
+  /* Initialize the SAME70 FLASH programming memory library */
+
+  sam_progmem_initialize();
+
+  /* Create an instance of the SAME70 FLASH program memory device driver */
+
+  g_samv7_progmem_mtd = progmem_initialize();
+  if (g_samv7_progmem_mtd == NULL)
+    {
+      return -EFAULT;
+    }
+
+#if defined(SAME70XPLAINED_PROGMEM_OTA_PARTITION)
+  ret = init_ota_partitions();
+  if (ret < 0)
+    {
+      return ret;
+    }
+#else
+  /* Use the FTL layer to wrap the MTD driver as a block driver */
+
+  ret = ftl_initialize(PROGMEM_MTD_MINOR, g_samv7_progmem_mtd);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: Failed to initialize the FTL layer: %d\n",
+             ret);
+      return ret;
+    }
+
+#ifdef CONFIG_BCH
+  char blockdev[18];
+  char chardev[12];
+
+  /* Use the minor number to create device paths */
+
+  snprintf(blockdev, 18, "/dev/mtdblock%d", PROGMEM_MTD_MINOR);
+  snprintf(chardev, 12, "/dev/mtd%d", PROGMEM_MTD_MINOR);
+
+  /* Now create a character device on the block device */
+
+  ret = bchdev_register(blockdev, chardev, false);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: bchdev_register %s failed: %d\n",
+             chardev, ret);
+      return ret;
+    }
+#endif /* CONFIG_BCH */
+#endif
+
+  return ret;
+}
+#endif /* HAVE_PROGMEM_CHARDEV */
diff --git a/boards/arm/samv7/same70-xplained/src/same70-xplained.h b/boards/arm/samv7/same70-xplained/src/same70-xplained.h
index ea7229e..37429ed 100644
--- a/boards/arm/samv7/same70-xplained/src/same70-xplained.h
+++ b/boards/arm/samv7/same70-xplained/src/same70-xplained.h
@@ -501,6 +501,17 @@ int sam_hsmci_initialize(int slot, int minor);
 #endif
 
 /****************************************************************************
+ * Name: sam_progmem_init
+ *
+ * Description:
+ *   Initialize the FLASH and register the MTD device.
+ ****************************************************************************/
+
+#ifdef HAVE_PROGMEM_CHARDEV
+int sam_progmem_init(void);
+#endif
+
+/****************************************************************************
  * Name:  sam_usbinitialize
  *
  * Description:

[incubator-nuttx] 02/04: arch/arm/src/samv7: add flash progmem erasestate ioctl support

Posted by gu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gustavonihei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 0d9425676dac5413860208a3f7e2591ce49d54cd
Author: Petro Karashchenko <pe...@gmail.com>
AuthorDate: Wed Nov 24 14:28:59 2021 +0200

    arch/arm/src/samv7: add flash progmem erasestate ioctl support
    
    Signed-off-by: Petro Karashchenko <pe...@gmail.com>
---
 arch/arm/src/samv7/Kconfig       |  7 +++++++
 arch/arm/src/samv7/sam_progmem.c | 21 ++++++++++++++++++---
 arch/arm/src/stm32h7/Kconfig     |  4 ++--
 include/nuttx/progmem.h          |  2 +-
 4 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/arch/arm/src/samv7/Kconfig b/arch/arm/src/samv7/Kconfig
index 78dab74..bbac6b3 100644
--- a/arch/arm/src/samv7/Kconfig
+++ b/arch/arm/src/samv7/Kconfig
@@ -816,6 +816,13 @@ config SAMV7_PROGMEM_NSECTORS
 		flash memory that will be reserved for use with by the interfaces
 		prototyped in include/nuttx/progmem.h
 
+config SAMV7_PROGMEM_ERASESTATE
+	bool "Flash progmem erasestate ioctl support"
+	default y
+	select ARCH_HAVE_PROGMEM_ERASESTATE
+	---help---
+		Add progmem erasestate ioctl command.
+
 endif # SAMV7_PROGMEM
 
 menu "SDRAM Configuration"
diff --git a/arch/arm/src/samv7/sam_progmem.c b/arch/arm/src/samv7/sam_progmem.c
index 0f64a70..5d0d818 100644
--- a/arch/arm/src/samv7/sam_progmem.c
+++ b/arch/arm/src/samv7/sam_progmem.c
@@ -137,6 +137,8 @@
 #define SAMV7_PROGMEM_ENDSEC     (SAMV7_TOTAL_NSECTORS)
 #define SAMV7_PROGMEM_STARTSEC   (SAMV7_PROGMEM_ENDSEC - CONFIG_SAMV7_PROGMEM_NSECTORS)
 
+#define SAMV7_PROGMEM_ERASEDVAL  (0xff)
+
 /* Misc stuff */
 
 #ifndef MIN
@@ -445,13 +447,13 @@ ssize_t up_progmem_ispageerased(size_t cluster)
   address = (cluster << SAMV7_CLUSTER_SHIFT) + SAMV7_PROGMEM_START;
   up_flush_dcache(address, address + SAMV7_CLUSTER_SIZE);
 
-  /* Verify that the cluster is erased (i.e., all 0xff) */
+  /* Verify that the cluster is erased (i.e., all SAMV7_PROGMEM_ERASEDVAL) */
 
   for (nleft = SAMV7_CLUSTER_SIZE, nwritten = 0;
        nleft > 0;
        nleft--, address++)
     {
-      if (getreg8(address) != 0xff)
+      if (getreg8(address) != SAMV7_PROGMEM_ERASEDVAL)
         {
           nwritten++;
         }
@@ -469,7 +471,7 @@ ssize_t up_progmem_ispageerased(size_t cluster)
  * Input Parameters:
  *   address - Address with or without flash offset
  *   buffer  - Pointer to buffer
- *   buflen   - Number of bytes to write
+ *   buflen  - Number of bytes to write
  *
  * Returned Value:
  *   Bytes written or negative value on error.  The following errors are
@@ -608,3 +610,16 @@ ssize_t up_progmem_write(size_t address, const void *buffer, size_t buflen)
   page_buffer_unlock();
   return written;
 }
+
+/****************************************************************************
+ * Name: up_progmem_erasestate
+ *
+ * Description:
+ *   Return a byte that represents flash erased value state
+ *
+ ****************************************************************************/
+
+ssize_t up_progmem_erasestate(void)
+{
+  return SAMV7_PROGMEM_ERASEDVAL;
+}
diff --git a/arch/arm/src/stm32h7/Kconfig b/arch/arm/src/stm32h7/Kconfig
index 51a9e77..610ff41 100644
--- a/arch/arm/src/stm32h7/Kconfig
+++ b/arch/arm/src/stm32h7/Kconfig
@@ -334,12 +334,12 @@ config STM32H7_PROGMEM
 		obtain an uniform flash memory mapping.
 
 config STM32H7_PROGMEM_ERASESTATE
-	bool "Flash progmem erasestate ictl support"
+	bool "Flash progmem erasestate ioctl support"
 	depends on STM32H7_PROGMEM
 	default y
 	select ARCH_HAVE_PROGMEM_ERASESTATE
 	---help---
-		Add progmem erasestate ictl command.
+		Add progmem erasestate ioctl command.
 
 menu "STM32H7 Peripheral Selection"
 
diff --git a/include/nuttx/progmem.h b/include/nuttx/progmem.h
index e671a9a..933d303 100644
--- a/include/nuttx/progmem.h
+++ b/include/nuttx/progmem.h
@@ -238,7 +238,7 @@ ssize_t up_progmem_read(size_t addr, FAR void *buf, size_t count);
  * Name: up_progmem_erasestate
  *
  * Description:
- *   Return value of erease state.
+ *   Return value of erase state.
  *
  ****************************************************************************/