boards/same70-xplained: initial support of MCUboot
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com> Co-authored-by: Gerson Fernando Budke <nandojve@gmail.com>
This commit is contained in:
parent
0d9425676d
commit
510154299b
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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"
|
@ -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"
|
@ -22,11 +22,27 @@ include $(TOPDIR)/.config
|
||||
include $(TOPDIR)/tools/Config.mk
|
||||
include $(TOPDIR)/arch/arm/src/armv7-m/Toolchain.defs
|
||||
|
||||
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
|
||||
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)
|
||||
ARCHSCRIPT = -T "${shell cygpath -w $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)}"
|
||||
|
@ -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) }
|
||||
}
|
@ -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) }
|
||||
}
|
@ -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) }
|
||||
}
|
@ -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) }
|
||||
}
|
@ -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)
|
||||
|
156
boards/arm/samv7/same70-xplained/src/sam_boot_image.c
Normal file
156
boards/arm/samv7/same70-xplained/src/sam_boot_image.c
Normal file
@ -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;
|
||||
}
|
@ -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);
|
||||
ret = sam_progmem_init();
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: Failed to initialize the FTL layer: %d\n",
|
||||
ret);
|
||||
syslog(LOG_ERR, "ERROR: Failed to initialize progmem: %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);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: bchdev_register %s failed: %d\n",
|
||||
chardev, ret);
|
||||
return ret;
|
||||
}
|
||||
#endif /* defined(CONFIG_BCH) */
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_USBHOST
|
||||
|
268
boards/arm/samv7/same70-xplained/src/sam_progmem.c
Normal file
268
boards/arm/samv7/same70-xplained/src/sam_progmem.c
Normal file
@ -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 */
|
@ -500,6 +500,17 @@ int sam_hsmci_initialize(int slot, int minor);
|
||||
# define sam_hsmci_initialize(s,m) (-ENOSYS)
|
||||
#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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user