boards/arm/samv7/samv71-xult: Add MCUboot support

Refactor to use common sam_progmem implementation and enable MCUboot
support.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
This commit is contained in:
Gerson Fernando Budke 2021-12-04 11:51:51 -03:00 committed by Alan Carvalho de Assis
parent a6fc88740c
commit 24c0e8bc75
4 changed files with 210 additions and 34 deletions

View File

@ -2572,3 +2572,83 @@ Configuration sub-directories
probably means some kind of memory corruption.
2017-01-30: knsh configuration does not yet run correctly.
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_SAMV7_FORMAT_MCUBOOT=y
CONFIG_USER_ENTRYPOINT="mcuboot_loader_main"
Flash bootloader using embedded debugger:
openocd -f interface/cmsis-dap.cfg \
-c 'transport select swd' \
-c 'set CHIPNAME atsamv71q21' \
-f target/atsamv.cfg \
-c 'reset_config srst_only' \
-c init -c targets \
-c 'reset halt' \
-c 'program nuttx.bin 0x400000' \
-c 'reset halt' \
-c 'atsamv gpnvm set 1' \
-c 'reset run' -c shutdown
mcuboot-nsh:
This configuration exercises the MCUboot compatible application slot
example. The application is NuttX nsh with some special commands.
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 mcuboot_nuttx.app.nsh.confirmed-v1.bin
./apps/boot/mcuboot/mcuboot/scripts/imgtool.py sign \
--key apps/boot/mcuboot/mcuboot/root-rsa-2048.pem --align 8 \
--version 2.0.0 --header-size 0x200 --pad-header --slot-size 0xe0000 \
nuttx/nuttx.bin mcuboot_nuttx.app.nsh.confirmed-v2.bin
Flash application version 1.0.0 at MCUboot Slot-0:
openocd -f interface/cmsis-dap.cfg \
-c 'transport select swd' \
-c 'set CHIPNAME atsamv71q21' \
-f target/atsamv.cfg \
-c 'reset_config srst_only' \
-c init -c targets \
-c 'reset halt' \
-c 'program mcuboot_nuttx.app.nsh.confirmed-v1.bin 0x420000' \
-c 'reset halt' \
-c 'atsamv gpnvm set 1' \
-c 'reset run' -c shutdown
Flash version 2.0.0 at MCUboot Slot-1:
openocd -f interface/cmsis-dap.cfg \
-c 'transport select swd' \
-c 'set CHIPNAME atsamv71q21' \
-f target/atsamv.cfg \
-c 'reset_config srst_only' \
-c init -c targets \
-c 'reset halt' \
-c 'program mcuboot_nuttx.app.nsh.confirmed-v2.bin 0x500000' \
-c 'reset halt' \
-c 'atsamv gpnvm set 1' \
-c 'reset run' -c shutdown
Relevant configuration settings:
CONFIG_BOOT_MCUBOOT=y
CONFIG_MCUBOOT_SLOT_CONFIRM_EXAMPLE=y
CONFIG_SAMV7_FORMAT_MCUBOOT=y
CONFIG_USER_ENTRYPOINT="nsh_main"

View File

@ -0,0 +1,62 @@
#
# 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_SAMV7_UART0 is not set
# CONFIG_SAMV7_UART2 is not set
# CONFIG_SAMV7_UART4 is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="samv71-xult"
CONFIG_ARCH_BOARD_SAMV71_XULT=y
CONFIG_ARCH_BUTTONS=y
CONFIG_ARCH_CHIP="samv7"
CONFIG_ARCH_CHIP_SAMV71=y
CONFIG_ARCH_CHIP_SAMV71Q21=y
CONFIG_ARCH_CHIP_SAMV71Q=y
CONFIG_ARCH_CHIP_SAMV7=y
CONFIG_ARCH_CHIP_SAMV7_MEM_FLASH=0x200000
CONFIG_ARCH_CHIP_SAMV7_MEM_RAM=0x60000
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_BOARDCTL_RESET=y
CONFIG_BOARD_LATE_INITIALIZE=y
CONFIG_BOARD_LOOPSPERMSEC=51262
CONFIG_BOOT_MCUBOOT=y
CONFIG_BUILTIN=y
CONFIG_FS_PROCFS=y
CONFIG_MCUBOOT_BOOTLOADER=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_SAMV7_FORMAT_MCUBOOT=y
CONFIG_SAMV7_GPIOA_IRQ=y
CONFIG_SAMV7_GPIOB_IRQ=y
CONFIG_SAMV7_GPIOD_IRQ=y
CONFIG_SAMV7_GPIO_IRQ=y
CONFIG_SAMV7_SYSTEMRESET=y
CONFIG_SAMV7_USART1=y
CONFIG_SAMV7_XDMAC=y
CONFIG_SCHED_HPWORK=y
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_START_DAY=10
CONFIG_START_MONTH=3
CONFIG_START_YEAR=2014
CONFIG_SYSTEM_NSH=y
CONFIG_SYSTEM_RAMTEST=y
CONFIG_USART1_SERIAL_CONSOLE=y
CONFIG_USER_ENTRYPOINT="mcuboot_loader_main"

View File

@ -0,0 +1,63 @@
#
# 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_SAMV7_UART0 is not set
# CONFIG_SAMV7_UART2 is not set
# CONFIG_SAMV7_UART4 is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="samv71-xult"
CONFIG_ARCH_BOARD_SAMV71_XULT=y
CONFIG_ARCH_BUTTONS=y
CONFIG_ARCH_CHIP="samv7"
CONFIG_ARCH_CHIP_SAMV71=y
CONFIG_ARCH_CHIP_SAMV71Q21=y
CONFIG_ARCH_CHIP_SAMV71Q=y
CONFIG_ARCH_CHIP_SAMV7=y
CONFIG_ARCH_CHIP_SAMV7_MEM_FLASH=0x200000
CONFIG_ARCH_CHIP_SAMV7_MEM_RAM=0x60000
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_BOARDCTL_RESET=y
CONFIG_BOARD_LATE_INITIALIZE=y
CONFIG_BOARD_LOOPSPERMSEC=51262
CONFIG_BOOT_MCUBOOT=y
CONFIG_BUILTIN=y
CONFIG_FS_PROCFS=y
CONFIG_MCUBOOT_SLOT_CONFIRM_EXAMPLE=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_PTABLE_PARTITION=y
CONFIG_RAM_SIZE=393216
CONFIG_RAM_START=0x20400000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SAMV7_FORMAT_MCUBOOT=y
CONFIG_SAMV7_GPIOA_IRQ=y
CONFIG_SAMV7_GPIOB_IRQ=y
CONFIG_SAMV7_GPIOD_IRQ=y
CONFIG_SAMV7_GPIO_IRQ=y
CONFIG_SAMV7_SYSTEMRESET=y
CONFIG_SAMV7_USART1=y
CONFIG_SAMV7_XDMAC=y
CONFIG_SCHED_HPWORK=y
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_START_DAY=10
CONFIG_START_MONTH=3
CONFIG_START_YEAR=2014
CONFIG_SYSTEM_NSH=y
CONFIG_SYSTEM_RAMTEST=y
CONFIG_USART1_SERIAL_CONSOLE=y
CONFIG_USER_ENTRYPOINT="nsh_main"

View File

@ -62,6 +62,7 @@
#ifdef HAVE_PROGMEM_CHARDEV
# include "sam_progmem.h"
# include "sam_progmem_common.h"
#endif
#if defined(HAVE_RTC_DSXXXX) || defined(HAVE_RTC_PCF85263)
@ -165,13 +166,13 @@ int sam_bringup(void)
#ifdef HAVE_S25FL1
FAR struct qspi_dev_s *qspi;
#endif
#if defined(HAVE_S25FL1) || defined(HAVE_PROGMEM_CHARDEV)
#if defined(HAVE_S25FL1)
FAR struct mtd_dev_s *mtd;
#endif
#if defined(HAVE_RTC_DSXXXX) || defined(HAVE_RTC_PCF85263)
FAR struct i2c_master_s *i2c;
#endif
#if defined(HAVE_S25FL1_CHARDEV) || defined(HAVE_PROGMEM_CHARDEV)
#if defined(HAVE_S25FL1_CHARDEV)
#if defined(CONFIG_BCH)
char blockdev[18];
char chardev[12];
@ -440,42 +441,12 @@ int sam_bringup(void)
#ifdef HAVE_PROGMEM_CHARDEV
/* Initialize the SAMV71 FLASH programming memory library */
sam_progmem_initialize();
/* Create an instance of the SAMV71 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_common_initialize();
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