iMXRT MCUboot support

This commit is contained in:
jturnsek
2023-02-24 07:12:28 +01:00
committed by Xiang Xiao
parent aeddec2ec5
commit 081b04f05e
15 changed files with 1891 additions and 4 deletions
+116
View File
@@ -151,6 +151,47 @@ config ARCH_FAMILY_IMXRT106x
select ARMV7M_HAVE_DTCM
select IMXRT_HIGHSPEED_GPIO
config IMXRT_HAVE_OTA_PARTITION
bool
default n
config IMXRT_PROGMEM
bool "Flash progmem support"
default n
select ARCH_HAVE_PROGMEM
---help---
Add progmem support, start block and end block options are provided to
obtain an uniform flash memory mapping.
menu "Application Image Configuration"
choice
prompt "Application Image Format"
default IMXRT_APP_FORMAT_LEGACY
---help---
Depending on the chosen 2nd stage bootloader, the application may
be required to be perform a specific startup routine. Furthermore,
the image binary must be formatted according to the definition from
the 2nd stage bootloader.
config IMXRT_APP_FORMAT_LEGACY
bool "Legacy format"
---help---
This is the legacy application image format.
config IMXRT_APP_FORMAT_MCUBOOT
bool "MCUboot-bootable format"
select IMXRT_HAVE_OTA_PARTITION
depends on EXPERIMENTAL
---help---
The MCUboot support of loading the firmware images.
comment "MCUboot support depends on CONFIG_EXPERIMENTAL"
depends on !EXPERIMENTAL
endchoice # Application Image Format
endmenu # Application Image Configuration
# Peripheral support
config IMXRT_USDHC
@@ -2781,4 +2822,79 @@ config IMXRT_USBDEV_REGDEBUG
endmenu # USB device controller driver (DCD) options
endif # IMXRT_USBDEV
menu "Progmem MTD configuration"
if IMXRT_PROGMEM
comment "Progmem instance support"
config IMXRT_PROGMEM_FLEXSPI_INSTANCE
int "FlexSPI instance number (0 or 1)"
default 1
---help---
FlexSPI instance number. Base address 0x60000000 is used for instance 0
and 0x70000000 for instance 1. Other values are not supported.
endif #IMXRT_PROGMEM
if IMXRT_HAVE_OTA_PARTITION
comment "Application Image OTA Update support"
config IMXRT_PROGMEM_OTA_PARTITION
bool "MTD driver"
default n
select BCH
select MTD
select MTD_BYTE_WRITE
select MTD_PARTITION
select MTD_PROGMEM
select IMXRT_PROGMEM
---help---
Initialize an MTD driver for the Flash, which will
add an entry at /dev for application access from userspace.
if IMXRT_PROGMEM_OTA_PARTITION
config IMXRT_MCUBOOT_HEADER_SIZE
hex
default 0x200
depends on IMXRT_APP_FORMAT_MCUBOOT
config IMXRT_OTA_PRIMARY_SLOT_DEVPATH
string "Application image primary slot device path"
default "/dev/ota0"
config IMXRT_OTA_SECONDARY_SLOT_DEVPATH
string "Application image secondary slot device path"
default "/dev/ota1"
config IMXRT_OTA_SCRATCH_DEVPATH
string "Scratch partition device path"
default "/dev/otascratch"
config IMXRT_OTA_PRIMARY_SLOT_OFFSET
hex "MCUboot application image primary slot offset"
default "0x40000"
config IMXRT_OTA_SECONDARY_SLOT_OFFSET
hex "MCUboot application image secondary slot offset"
default "0x200000"
config IMXRT_OTA_SCRATCH_OFFSET
hex "MCUboot scratch partition offset"
default "0x3c0000"
config IMXRT_OTA_SLOT_SIZE
hex "MCUboot application image slot size (in bytes)"
default "0x1c0000"
config IMXRT_OTA_SCRATCH_SIZE
hex "MCUboot scratch partition size (in bytes)"
default "0x40000"
endif #IMXRT_PROGMEM_OTA_PARTITION
endif #IMXRT_HAVE_OTA_PARTITION
endmenu # Progmem configuration
endif # ARCH_CHIP_IMXRT
+3
View File
@@ -25,6 +25,9 @@ include armv7-m/Make.defs
# Required i.MX RT files
CHIP_CSRCS = imxrt_allocateheap.c imxrt_start.c imxrt_clockconfig.c
ifeq ($(CONFIG_IMXRT_PROGMEM),y)
CHIP_CSRCS += imxrt_flash.c
endif
CHIP_CSRCS += imxrt_periphclks.c imxrt_irq.c imxrt_clrpend.c imxrt_gpio.c
CHIP_CSRCS += imxrt_daisy.c imxrt_wdog.c imxrt_iomuxc.c imxrt_serial.c
CHIP_CSRCS += imxrt_xbar.c imxrt_ocotp.c imxrt_lowputc.c
File diff suppressed because it is too large Load Diff
+35
View File
@@ -0,0 +1,35 @@
/****************************************************************************
* arch/arm/src/imxrt/imxrt_flash.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>
#if defined(CONFIG_ARCH_FAMILY_IMXRT106x)
# include "imxrt106x_flash.c"
#else
# error "Unsupported IMXRT chip"
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
@@ -0,0 +1,85 @@
#
# 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_ARCH_LEDS is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="imxrt1064-evk"
CONFIG_ARCH_BOARD_IMXRT1064_EVK=y
CONFIG_ARCH_CHIP="imxrt"
CONFIG_ARCH_CHIP_IMXRT=y
CONFIG_ARCH_CHIP_MIMXRT1064DVL6A=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_ARMV7M_DCACHE=y
CONFIG_ARMV7M_DCACHE_WRITETHROUGH=y
CONFIG_ARMV7M_ICACHE=y
CONFIG_ARMV7M_USEBASEPRI=y
CONFIG_BOARDCTL_RESET=y
CONFIG_BOARD_LOOPSPERMSEC=104926
CONFIG_BUILTIN=y
CONFIG_DEBUG_SYMBOLS=y
CONFIG_ETH0_PHY_KSZ8081=y
CONFIG_EXAMPLES_MCUBOOT_SLOT_CONFIRM=y
CONFIG_EXAMPLES_MCUBOOT_SWAP_TEST=y
CONFIG_EXAMPLES_MCUBOOT_UPDATE_AGENT=y
CONFIG_EXAMPLES_MCUBOOT_UPDATE_AGENT_DL_BUFFER_SIZE=4096
CONFIG_EXPERIMENTAL=y
CONFIG_FAT_LCNAMES=y
CONFIG_FS_FAT=y
CONFIG_FS_PROCFS=y
CONFIG_FS_PROCFS_REGISTER=y
CONFIG_IDLETHREAD_STACKSIZE=2048
CONFIG_IMXRT_APP_FORMAT_MCUBOOT=y
CONFIG_IMXRT_ENET=y
CONFIG_IMXRT_LPUART1=y
CONFIG_IMXRT_PROGMEM_OTA_PARTITION=y
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INIT_STACKSIZE=4096
CONFIG_IOB_NBUFFERS=128
CONFIG_LIBC_HOSTNAME="i.MXRT1064 EVK"
CONFIG_LPUART1_BAUD=9600
CONFIG_LPUART1_SERIAL_CONSOLE=y
CONFIG_NET=y
CONFIG_NETDB_DNSCLIENT=y
CONFIG_NETDEV_STATISTICS=y
CONFIG_NETINIT_NOMAC=y
CONFIG_NETUTILS_DISCOVER=y
CONFIG_NETUTILS_WEBCLIENT=y
CONFIG_NET_ARP_SEND=y
CONFIG_NET_BROADCAST=y
CONFIG_NET_ETH_PKTSIZE=1514
CONFIG_NET_GUARDSIZE=4
CONFIG_NET_ICMP=y
CONFIG_NET_ICMP_SOCKET=y
CONFIG_NET_ICMPv6=y
CONFIG_NET_ICMPv6_NEIGHBOR=y
CONFIG_NET_ICMPv6_SOCKET=y
CONFIG_NET_IPv6=y
CONFIG_NET_STATISTICS=y
CONFIG_NET_TCP=y
CONFIG_NET_TCPBACKLOG=y
CONFIG_NET_TCP_WRITE_BUFFERS=y
CONFIG_NET_UDP=y
CONFIG_NET_UDP_WRITE_BUFFERS=y
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_LINELEN=64
CONFIG_NSH_MOTD=y
CONFIG_NSH_MOTD_STRING="Welcome to Nuttx from MCUboot, this is the FIRST firmware."
CONFIG_NSH_READLINE=y
CONFIG_RAM_SIZE=1048576
CONFIG_RAM_START=0x20200000
CONFIG_RAW_BINARY=y
CONFIG_READLINE_CMD_HISTORY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_WAITPID=y
CONFIG_START_DAY=14
CONFIG_START_MONTH=3
CONFIG_SYSTEM_DHCPC_RENEW=y
CONFIG_SYSTEM_NSH=y
CONFIG_SYSTEM_PING=y
@@ -0,0 +1,59 @@
#
# 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_ARCH="arm"
CONFIG_ARCH_BOARD="imxrt1064-evk"
CONFIG_ARCH_BOARD_IMXRT1064_EVK=y
CONFIG_ARCH_CHIP="imxrt"
CONFIG_ARCH_CHIP_IMXRT=y
CONFIG_ARCH_CHIP_MIMXRT1064DVL6A=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_ARMV7M_DCACHE=y
CONFIG_ARMV7M_DCACHE_WRITETHROUGH=y
CONFIG_ARMV7M_ICACHE=y
CONFIG_ARMV7M_USEBASEPRI=y
CONFIG_BOARDCTL_RESET=y
CONFIG_BOARD_LOOPSPERMSEC=104926
CONFIG_BOOT_MCUBOOT=y
CONFIG_BUILTIN=y
CONFIG_DEBUG_SYMBOLS=y
CONFIG_EXPERIMENTAL=y
CONFIG_FAT_LCNAMES=y
CONFIG_FS_FAT=y
CONFIG_FS_PROCFS=y
CONFIG_FS_PROCFS_REGISTER=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_IDLETHREAD_STACKSIZE=2048
CONFIG_IMXRT_APP_FORMAT_MCUBOOT=y
CONFIG_IMXRT_LPUART1=y
CONFIG_IMXRT_PROGMEM_OTA_PARTITION=y
CONFIG_INIT_ENTRYPOINT="mcuboot_loader_main"
CONFIG_INIT_STACKSIZE=4096
CONFIG_LIBM=y
CONFIG_LPUART1_BAUD=9600
CONFIG_LPUART1_SERIAL_CONSOLE=y
CONFIG_MCUBOOT_BOOTLOADER=y
CONFIG_MCUBOOT_VERSION="414ac87cfd8d9cedeb781f812ad6f5072e6d8a39"
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_DISABLE_IFUPDOWN=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_LIBRARY=y
CONFIG_NSH_LINELEN=64
CONFIG_NSH_MOTD=y
CONFIG_NSH_MOTD_STRING="Welcome to Nuttx MCUboot-Loader!"
CONFIG_NSH_READLINE=y
CONFIG_RAM_SIZE=1048576
CONFIG_RAM_START=0x20200000
CONFIG_RAW_BINARY=y
CONFIG_SCHED_HPWORK=y
CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_WAITPID=y
CONFIG_START_DAY=14
CONFIG_START_MONTH=3
CONFIG_TASK_NAME_SIZE=0
CONFIG_WQUEUE_NOTIFIER=y
@@ -22,10 +22,18 @@ include $(TOPDIR)/.config
include $(TOPDIR)/tools/Config.mk
include $(TOPDIR)/arch/arm/src/armv7-m/Toolchain.defs
ifeq ($(CONFIG_BOOT_RUNFROMFLASH),y)
LDSCRIPT = flash.ld
else ifeq ($(CONFIG_BOOT_RUNFROMISRAM),y)
LDSCRIPT = flash-ocram.ld
ifeq ($(CONFIG_IMXRT_APP_FORMAT_MCUBOOT),y)
ifeq ($(CONFIG_MCUBOOT_BOOTLOADER),y)
LDSCRIPT = flash-mcuboot-loader.ld
else
LDSCRIPT = flash-mcuboot-app.ld
endif
else
ifeq ($(CONFIG_BOOT_RUNFROMFLASH),y)
LDSCRIPT = flash.ld
else ifeq ($(CONFIG_BOOT_RUNFROMISRAM),y)
LDSCRIPT = flash-ocram.ld
endif
endif
ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
@@ -0,0 +1,119 @@
/****************************************************************************
* boards/arm/imxrt/imxrt1064-evk/scripts/flash.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.
*
****************************************************************************/
/* Specify the memory areas */
MEMORY
{
flash (rx) : ORIGIN = 0x70040200, LENGTH = 1792K - 512
sram (rwx) : ORIGIN = 0x20200000, LENGTH = 512M
itcm (rwx) : ORIGIN = 0x00000000, LENGTH = 128K
dtcm (rwx) : ORIGIN = 0x20000000, LENGTH = 128K
}
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
.ARM.exidx :
{
__exidx_start = ABSOLUTE(.);
*(.ARM.exidx*)
__exidx_end = ABSOLUTE(.);
} > flash
_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,139 @@
/****************************************************************************
* boards/arm/imxrt/imxrt1064-evk/scripts/flash.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.
*
****************************************************************************/
/* Specify the memory areas */
MEMORY
{
flash (rx) : ORIGIN = 0x70000000, LENGTH = 256K
sram (rwx) : ORIGIN = 0x20200000, LENGTH = 512M
itcm (rwx) : ORIGIN = 0x00000000, LENGTH = 128K
dtcm (rwx) : ORIGIN = 0x20000000, LENGTH = 128K
}
OUTPUT_ARCH(arm)
EXTERN(_vectors)
EXTERN(g_flash_config)
EXTERN(g_image_vector_table)
EXTERN(g_boot_data)
ENTRY(_stext)
SECTIONS
{
/* Image Vector Table and Boot Data for booting from external flash */
.boot_hdr : ALIGN(4)
{
FILL(0xff)
__boot_hdr_start__ = ABSOLUTE(.) ;
KEEP(*(.boot_hdr.conf))
. = 0x1000 ;
KEEP(*(.boot_hdr.ivt))
. = 0x1020 ;
KEEP(*(.boot_hdr.boot_data))
. = 0x1030 ;
KEEP(*(.boot_hdr.dcd_data))
__boot_hdr_end__ = ABSOLUTE(.) ;
. = 0x2000 ;
} >flash
.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
.ARM.exidx :
{
__exidx_start = ABSOLUTE(.);
*(.ARM.exidx*)
__exidx_end = ABSOLUTE(.);
} > flash
_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) }
}
@@ -86,4 +86,16 @@ ifeq ($(CONFIG_IMXRT_FLEXSPI),y)
CSRCS += imxrt_flexspi_nor.c
endif
ifeq ($(CONFIG_IMXRT_PROGMEM),y)
CSRCS += imxrt_progmem.c
endif
ifeq ($(CONFIG_BOARDCTL_RESET),y)
CSRCS += imxrt_reset.c
endif
ifeq ($(CONFIG_BOARDCTL_BOOT_IMAGE),y)
CSRCS += imxrt_boot_image.c
endif
include $(TOPDIR)/boards/Board.mk
@@ -40,6 +40,14 @@
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
#define HAVE_PROGMEM_CHARDEV 1
#if !defined(CONFIG_IMXRT_PROGMEM) || !defined(CONFIG_MTD_PROGMEM)
# undef HAVE_PROGMEM_CHARDEV
#endif
/* Touchscreen definitions **************************************************/
/* The IMXRT 1050/1060 have connectors for the LCD model RK043FN02H-CT.
@@ -317,5 +325,12 @@ int imxrt_usbhost_initialize(void);
int imxrt_flexspi_nor_initialize(void);
#endif
#ifdef CONFIG_MTD
#ifdef HAVE_PROGMEM_CHARDEV
int imxrt_progmem_init(void);
#endif /* HAVE_PROGMEM_CHARDEV */
#endif
#endif /* __ASSEMBLY__ */
#endif /* __BOARDS_ARM_IMXRT_IMXRT1064_EVK_SRC_IMXRT1064_EVK_H */
@@ -0,0 +1,180 @@
/****************************************************************************
* boards/arm/imxrt/imxrt1064-evk/src/imxrt_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_internal.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);
static void systick_disable(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 < NR_IRQS; i += 32)
{
putreg32(0xffffffff, NVIC_IRQ_CLEAR(i));
}
/* Clear all pending interrupts */
for (i = 0; i < NR_IRQS; i += 32)
{
putreg32(0xffffffff, NVIC_IRQ_CLRPEND(i));
}
}
/****************************************************************************
* Name: systick_disable
*
* Description:
* Disable the SysTick system timer
*
* Input Parameters:
* None
*
* Returned Value:
* None
*
****************************************************************************/
static void systick_disable(void)
{
putreg32(0, NVIC_SYSTICK_CTRL);
putreg32(NVIC_SYSTICK_RELOAD_MASK, NVIC_SYSTICK_RELOAD);
putreg32(0, NVIC_SYSTICK_CURRENT);
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_boot_image
*
* Description:
* This entry point is called by bootloader to jump to application image.
*
****************************************************************************/
int board_boot_image(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;
}
systick_disable();
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;
}
@@ -287,6 +287,16 @@ int imxrt_bringup(void)
}
#endif /* CONFIG_IMXRT_FLEXSPI */
#ifdef CONFIG_MTD
#ifdef HAVE_PROGMEM_CHARDEV
ret = imxrt_progmem_init();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: Failed to initialize MTD progmem: %d\n", ret);
}
#endif /* HAVE_PROGMEM_CHARDEV */
#endif /* CONFIG_MTD */
UNUSED(ret);
return OK;
}
@@ -0,0 +1,255 @@
/****************************************************************************
* boards/arm/imxrt/imxrt1064-evk/src/imxrt_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/progmem.h>
#include <nuttx/drivers/drivers.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/kmalloc.h>
#include <nuttx/mtd/mtd.h>
#ifdef CONFIG_BCH
#include <nuttx/drivers/drivers.h>
#endif
#include "imxrt1064-evk.h"
#ifdef HAVE_PROGMEM_CHARDEV
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
#define PARTITION_LABEL_LEN 16
/* Configuration ************************************************************/
/* Make sure that support for MTD partitions is enabled */
#ifdef CONFIG_MTD
#ifndef CONFIG_MTD_PARTITION
# error "CONFIG_MTD_PARTITION is required"
#endif
#endif
/****************************************************************************
* Private Types
****************************************************************************/
#if defined(CONFIG_IMXRT_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(CONFIG_IMXRT_PROGMEM_OTA_PARTITION)
static struct mtd_dev_s *progmem_alloc_mtdpart(uint32_t mtd_offset,
uint32_t mtd_size);
static int init_ota_partitions(void);
#endif
/****************************************************************************
* Private Data
****************************************************************************/
static struct mtd_dev_s *g_progmem_mtd;
#if defined(CONFIG_IMXRT_PROGMEM_OTA_PARTITION)
static const struct ota_partition_s g_ota_partition_table[] =
{
{
.offset = CONFIG_IMXRT_OTA_PRIMARY_SLOT_OFFSET,
.size = CONFIG_IMXRT_OTA_SLOT_SIZE,
.devpath = CONFIG_IMXRT_OTA_PRIMARY_SLOT_DEVPATH
},
{
.offset = CONFIG_IMXRT_OTA_SECONDARY_SLOT_OFFSET,
.size = CONFIG_IMXRT_OTA_SLOT_SIZE,
.devpath = CONFIG_IMXRT_OTA_SECONDARY_SLOT_DEVPATH
},
{
.offset = CONFIG_IMXRT_OTA_SCRATCH_OFFSET,
.size = CONFIG_IMXRT_OTA_SCRATCH_SIZE,
.devpath = CONFIG_IMXRT_OTA_SCRATCH_DEVPATH
}
};
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
#if defined(CONFIG_IMXRT_PROGMEM_OTA_PARTITION)
/****************************************************************************
* Name: 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 *progmem_alloc_mtdpart(uint32_t mtd_offset,
uint32_t mtd_size)
{
uint32_t blocks;
ssize_t startblock;
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 + up_progmem_getaddress(0));
if (startblock < 0)
{
return NULL;
}
blocks = mtd_size / up_progmem_pagesize(0);
return mtd_partition(g_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)
{
int i;
struct mtd_dev_s *mtd;
int ret = 0;
char path[PARTITION_LABEL_LEN + 1];
for (i = 0; i < ARRAYSIZE(g_ota_partition_table); ++i)
{
const struct ota_partition_s *part = &g_ota_partition_table[i];
mtd = progmem_alloc_mtdpart(part->offset, part->size);
strncpy(path, (char *)part->devpath, PARTITION_LABEL_LEN);
path[PARTITION_LABEL_LEN] = '\0';
finfo("INFO: [label]: %s\n", path);
finfo("INFO: [offset]: 0x%08" PRIx32 "\n", part->offset);
finfo("INFO: [size]: 0x%08" PRIx32 "\n", part->size);
if (!mtd)
{
ferr("ERROR: Failed to create MTD partition\n");
ret = -1;
}
ret = register_mtddriver(path, mtd, 0777, NULL);
if (ret < 0)
{
ferr("ERROR: Failed to register MTD @ %s\n", path);
ret = -1;
}
}
return ret;
}
#endif /* CONFIG_IMXRT_PROGMEM_OTA_PARTITION */
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: imxrt_progmem_init
*
* Initialize Progmem partition. Read partition information, and use
* these data for creating MTD.
*
* Input Parameters:
* None
*
* Returned Value:
* 0 if success or a negative value if fail.
*
****************************************************************************/
int imxrt_progmem_init(void)
{
int ret = 0;
g_progmem_mtd = progmem_initialize();
if (g_progmem_mtd == NULL)
{
ferr("ERROR: Failed to get progmem flash MTD\n");
ret = -EIO;
}
#ifdef CONFIG_IMXRT_PROGMEM_OTA_PARTITION
ret = init_ota_partitions();
if (ret < 0)
{
ferr("ERROR: Failed to create OTA partition from MTD\n");
ret = -EIO;
}
#endif
return ret;
}
#endif /* HAVE_PROGMEM_CHARDEV */
@@ -0,0 +1,62 @@
/****************************************************************************
* boards/arm/imxrt/imxrt1064-evk/src/imxrt_reset.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 <nuttx/arch.h>
#include <nuttx/board.h>
#ifdef CONFIG_BOARDCTL_RESET
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_reset
*
* Description:
* Reset board. Support for this function is required by board-level
* logic if CONFIG_BOARDCTL_RESET is selected.
*
* Input Parameters:
* status - Status information provided with the reset event. This
* meaning of this status information is board-specific. If not
* used by a board, the value zero may be provided in calls to
* board_reset().
*
* Returned Value:
* If this function returns, then it was not possible to power-off the
* board due to some constraints. The return value int this case is a
* board-specific reason for the failure to shutdown.
*
****************************************************************************/
int board_reset(int status)
{
up_systemreset();
return 0;
}
#endif /* CONFIG_BOARDCTL_RESET */