You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/11/28 10:35:31 UTC

[GitHub] [incubator-nuttx] pkarashchenko commented on a change in pull request #4908: add board files to support mcuboot

pkarashchenko commented on a change in pull request #4908:
URL: https://github.com/apache/incubator-nuttx/pull/4908#discussion_r757872070



##########
File path: boards/arm/stm32h7/nucleo-h743zi/Kconfig
##########
@@ -27,4 +27,66 @@ config STM32_ROMFS_IMAGEFILE
         depends on STM32_ROMFS
         default "../../../rom.img"
 
+
+config PROGMEM_OTA_PARTITION
+	bool "Progmem ota partitions"
+	default y
+	select MTD
+	select MTD_BYTE_WRITE
+	select MTD_PARTITION
+	select MTD_PROGMEM
+	select MTD_PROGMEM_ERASESTATE
+
+menuconfig APP_FORMAT_MCUBOOT
+	bool "MCUboot-bootable format"
+	default y
+	select PROGMEM_OTA_PARTITION
+	---help---
+		The MCUboot support of loading the firmware images.
+
+if APP_FORMAT_MCUBOOT
+
+config MCUBOOT_BOOTLOADER
+	bool "MCUboot bootloader application"
+	default y
+	---help---
+		This switch between linker scripts to allow an application be
+		built to another entry point address.

Review comment:
       https://github.com/pkarashchenko/incubator-nuttx-apps/blob/master/boot/mcuboot/Kconfig has same configuration option
   ```
   config MCUBOOT_BOOTLOADER
   	bool "MCUboot bootloader application"
   	default n
   	select BOARDCTL
   	select BOARDCTL_BOOT_IMAGE
   	---help---
   		MCUboot bootloader application
   ```
   I'm not sure if it will work with two configuration options with the same name

##########
File path: boards/arm/stm32h7/nucleo-h743zi/configs/mcuboot-loader/defconfig
##########
@@ -0,0 +1,94 @@
+#
+# 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_SPI_EXCHANGE is not set
+# CONFIG_STM32H7_SYSCFG is not set
+CONFIG_ARCH="arm"
+CONFIG_ARCH_BOARD="nucleo-h743zi"
+CONFIG_ARCH_BOARD_NUCLEO_H743ZI=y
+CONFIG_ARCH_CHIP="stm32h7"
+CONFIG_ARCH_CHIP_STM32H743ZI=y
+CONFIG_ARCH_CHIP_STM32H7=y
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_ARMV7M_BASEPRI_WAR=y
+CONFIG_ARMV7M_DCACHE=y
+CONFIG_ARMV7M_DTCM=y
+CONFIG_ARMV7M_ICACHE=y
+CONFIG_ARMV7M_MEMCPY=y
+CONFIG_ARMV7M_STACKCHECK=y
+CONFIG_ARMV7M_USEBASEPRI=y
+CONFIG_BOARDCTL_RESET=y
+CONFIG_BOARDCTL_ROMDISK=y
+CONFIG_BOARD_CUSTOM_LEDS=y
+CONFIG_BOARD_LATE_INITIALIZE=y
+CONFIG_BOARD_LOOPSPERMSEC=43103
+CONFIG_BOOT_MCUBOOT=y
+CONFIG_BUILTIN=y
+CONFIG_CLOCK_MONOTONIC=y
+CONFIG_DEBUG_FEATURES=y
+CONFIG_DEBUG_IRQ=y
+CONFIG_DEBUG_SYMBOLS=y
+CONFIG_DRVR_READAHEAD=y
+CONFIG_DRVR_WRITEBUFFER=y
+CONFIG_EXPERIMENTAL=y
+CONFIG_FAT_LCNAMES=y
+CONFIG_FAT_LFN=y
+CONFIG_FS_FAT=y
+CONFIG_FS_PROCFS=y
+CONFIG_FTL_WRITEBUFFER=y
+CONFIG_HAVE_CXX=y
+CONFIG_HAVE_CXXINITIALIZE=y
+CONFIG_IOB_NBUFFERS=24
+CONFIG_IOB_NCHAINS=24
+CONFIG_LIBC_LZF=y
+CONFIG_LIBM=y
+CONFIG_MCUBOOT_BOOTLOADER=y
+CONFIG_MCUBOOT_VERSION="ecd34c116873bf187a3d7431151249ec856738d0"

Review comment:
       ```suggestion
   ```

##########
File path: boards/arm/stm32h7/nucleo-h743zi/src/stm32_progmem.c
##########
@@ -0,0 +1,284 @@
+/****************************************************************************
+ * apps/examples/mtdpart/stm32_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 <stm32.h>
+#include <nucleo-h743zi.h>
+#include <stm32_flash.h>
+
+#ifdef HAVE_PROGMEM_CHARDEV
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ARRAYSIZE(x)                (sizeof((x)) / sizeof((x)[0]))
+
+/* 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_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_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 FAR struct mtd_dev_s *g_progmem_mtd;
+
+#if defined(CONFIG_PROGMEM_OTA_PARTITION)
+static const struct ota_partition_s g_ota_partition_table[] =
+{
+  {
+    .offset  = CONFIG_OTA_PRIMARY_SLOT_OFFSET,
+    .size    = CONFIG_OTA_SLOT_SIZE,
+    .devpath = CONFIG_OTA_PRIMARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_OTA_SECONDARY_SLOT_OFFSET,
+    .size    = CONFIG_OTA_SLOT_SIZE,
+    .devpath = CONFIG_OTA_SECONDARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_OTA_SCRATCH_OFFSET,
+    .size    = CONFIG_OTA_SCRATCH_SIZE,
+    .devpath = CONFIG_OTA_SCRATCH_DEVPATH
+  }
+};
+#endif
+
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(CONFIG_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 *progmem_alloc_mtdpart(uint32_t mtd_offset,
+                                                   uint32_t mtd_size)
+{
+  uint32_t blocks;
+  ssize_t startblock;
+
+  //ASSERT((mtd_offset + mtd_size) <= up_progmem_neraseblocks() *
+  //        up_progmem_pagesize(0));

Review comment:
       Why this is commented out?

##########
File path: boards/arm/stm32h7/nucleo-h743zi/scripts/Make.defs
##########
@@ -22,7 +22,15 @@ include $(TOPDIR)/.config
 include $(TOPDIR)/tools/Config.mk
 include $(TOPDIR)/arch/arm/src/armv7-m/Toolchain.defs
 
-LDSCRIPT = flash.ld
+ifeq ($(CONFIG_APP_FORMAT_MCUBOOT),y)
+ifeq ($(CONFIG_MCUBOOT_BOOTLOADER),y)
+    LDSCRIPT = flash-mcuboot-loader.ld
+else
+    LDSCRIPT = flash-mcuboot-app.ld

Review comment:
       Either correct this name to `flash-mcu-app.ld` or rename a linker script

##########
File path: boards/arm/stm32h7/nucleo-h743zi/configs/mcuboot-loader/defconfig
##########
@@ -0,0 +1,94 @@
+#
+# 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_SPI_EXCHANGE is not set
+# CONFIG_STM32H7_SYSCFG is not set
+CONFIG_ARCH="arm"
+CONFIG_ARCH_BOARD="nucleo-h743zi"
+CONFIG_ARCH_BOARD_NUCLEO_H743ZI=y
+CONFIG_ARCH_CHIP="stm32h7"
+CONFIG_ARCH_CHIP_STM32H743ZI=y
+CONFIG_ARCH_CHIP_STM32H7=y
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_ARMV7M_BASEPRI_WAR=y
+CONFIG_ARMV7M_DCACHE=y
+CONFIG_ARMV7M_DTCM=y
+CONFIG_ARMV7M_ICACHE=y
+CONFIG_ARMV7M_MEMCPY=y
+CONFIG_ARMV7M_STACKCHECK=y
+CONFIG_ARMV7M_USEBASEPRI=y
+CONFIG_BOARDCTL_RESET=y
+CONFIG_BOARDCTL_ROMDISK=y
+CONFIG_BOARD_CUSTOM_LEDS=y
+CONFIG_BOARD_LATE_INITIALIZE=y
+CONFIG_BOARD_LOOPSPERMSEC=43103
+CONFIG_BOOT_MCUBOOT=y
+CONFIG_BUILTIN=y
+CONFIG_CLOCK_MONOTONIC=y
+CONFIG_DEBUG_FEATURES=y
+CONFIG_DEBUG_IRQ=y
+CONFIG_DEBUG_SYMBOLS=y
+CONFIG_DRVR_READAHEAD=y
+CONFIG_DRVR_WRITEBUFFER=y
+CONFIG_EXPERIMENTAL=y
+CONFIG_FAT_LCNAMES=y
+CONFIG_FAT_LFN=y
+CONFIG_FS_FAT=y
+CONFIG_FS_PROCFS=y
+CONFIG_FTL_WRITEBUFFER=y
+CONFIG_HAVE_CXX=y
+CONFIG_HAVE_CXXINITIALIZE=y
+CONFIG_IOB_NBUFFERS=24
+CONFIG_IOB_NCHAINS=24
+CONFIG_LIBC_LZF=y
+CONFIG_LIBM=y
+CONFIG_MCUBOOT_BOOTLOADER=y
+CONFIG_MCUBOOT_VERSION="ecd34c116873bf187a3d7431151249ec856738d0"
+CONFIG_MM_CIRCBUF=y
+CONFIG_MM_IOB=y
+CONFIG_MM_REGIONS=4
+CONFIG_MTD=y
+CONFIG_MTD_BYTE_WRITE=y
+CONFIG_MTD_PARTITION=y
+CONFIG_MTD_PROGMEM=y
+CONFIG_MTD_PROGMEM_ERASESTATE=y
+CONFIG_MTD_WRBUFFER=y
+CONFIG_NSH_ARCHINIT=y
+CONFIG_NSH_BUILTIN_APPS=y
+CONFIG_NSH_DISABLE_IFCONFIG=y
+CONFIG_NSH_DISABLE_IFUPDOWN=y
+CONFIG_NSH_DISABLE_PS=y
+CONFIG_NSH_FILEIOSIZE=512
+CONFIG_NSH_LINELEN=64
+CONFIG_NSH_MOTD=y
+CONFIG_NSH_MOTD_STRING="Wellcome to Nuttx MCUboot-Loader!"
+CONFIG_NSH_READLINE=y
+CONFIG_PREALLOC_TIMERS=4
+CONFIG_RAM_SIZE=245760
+CONFIG_RAM_START=0x20010000
+CONFIG_RAW_BINARY=y
+CONFIG_RR_INTERVAL=200
+CONFIG_SCHED_LPNTHREADS=4
+CONFIG_SCHED_LPWORK=y
+CONFIG_SCHED_WAITPID=y
+CONFIG_SDCLONE_DISABLE=y
+CONFIG_SIG_DEFAULT=y
+CONFIG_SIG_PREALLOC_IRQ_ACTIONS=10
+CONFIG_SPI=y
+CONFIG_START_DAY=6
+CONFIG_START_MONTH=12
+CONFIG_START_YEAR=2011

Review comment:
       maybe we can move to 2021 :)

##########
File path: boards/arm/stm32h7/nucleo-h743zi/scripts/Make.defs
##########
@@ -22,7 +22,15 @@ include $(TOPDIR)/.config
 include $(TOPDIR)/tools/Config.mk
 include $(TOPDIR)/arch/arm/src/armv7-m/Toolchain.defs
 
-LDSCRIPT = flash.ld
+ifeq ($(CONFIG_APP_FORMAT_MCUBOOT),y)
+ifeq ($(CONFIG_MCUBOOT_BOOTLOADER),y)
+    LDSCRIPT = flash-mcuboot-loader.ld

Review comment:
       Either correct this name to `flash-mcu-loader.ld` or rename a linker script

##########
File path: boards/arm/stm32h7/nucleo-h743zi/configs/mcuboot-app/defconfig
##########
@@ -0,0 +1,141 @@
+#
+# 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_SPI_EXCHANGE is not set
+# CONFIG_STM32H7_SYSCFG is not set
+CONFIG_ARCH="arm"
+CONFIG_ARCH_BOARD="nucleo-h743zi"
+CONFIG_ARCH_BOARD_NUCLEO_H743ZI=y
+CONFIG_ARCH_CHIP="stm32h7"
+CONFIG_ARCH_CHIP_STM32H743ZI=y
+CONFIG_ARCH_CHIP_STM32H7=y
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_ARMV7M_BASEPRI_WAR=y
+CONFIG_ARMV7M_DCACHE=y
+CONFIG_ARMV7M_DTCM=y
+CONFIG_ARMV7M_ICACHE=y
+CONFIG_ARMV7M_MEMCPY=y
+CONFIG_ARMV7M_STACKCHECK=y
+CONFIG_ARMV7M_USEBASEPRI=y
+CONFIG_ARM_MPU_EARLY_RESET=y
+CONFIG_BOARDCTL_RESET=y
+CONFIG_BOARD_CUSTOM_LEDS=y
+CONFIG_BOARD_LOOPSPERMSEC=43103
+CONFIG_BOOT_MCUBOOT=y
+CONFIG_BUILTIN=y
+CONFIG_CLOCK_MONOTONIC=y
+CONFIG_DEBUG_FEATURES=y
+CONFIG_DEBUG_IRQ=y
+CONFIG_DEBUG_NET=y
+CONFIG_DEBUG_SYMBOLS=y
+CONFIG_DRVR_READAHEAD=y
+CONFIG_DRVR_WRITEBUFFER=y
+CONFIG_ETH0_PHY_LAN8742A=y
+CONFIG_EXAMPLES_LEDS=y
+CONFIG_EXAMPLES_LEDS_LEDSET=0x03
+CONFIG_EXAMPLES_TCPECHO=y
+CONFIG_EXPERIMENTAL=y
+CONFIG_FAT_LCNAMES=y
+CONFIG_FAT_LFN=y
+CONFIG_FS_FAT=y
+CONFIG_FS_PROCFS=y
+CONFIG_FS_ROMFS=y
+CONFIG_FTL_WRITEBUFFER=y
+CONFIG_HAVE_CXX=y
+CONFIG_HAVE_CXXINITIALIZE=y
+CONFIG_I2C=y
+CONFIG_IOB_NBUFFERS=24
+CONFIG_IOB_THROTTLE=0
+CONFIG_LIBC_LZF=y
+CONFIG_LIBM=y
+CONFIG_MCUBOOT_SLOT_CONFIRM_EXAMPLE=y
+CONFIG_MCUBOOT_VERSION="ecd34c116873bf187a3d7431151249ec856738d0"
+CONFIG_MMCSD=y
+CONFIG_MM_CIRCBUF=y
+CONFIG_MM_REGIONS=4
+CONFIG_MTD=y
+CONFIG_MTD_PARTITION=y
+CONFIG_MTD_PROGMEM=y

Review comment:
       This options are auto-enabled by `PROGMEM_OTA_PARTITION` that is enabled by `APP_FORMAT_MCUBOOT` and I do not see it enabled. Probably it is missing?

##########
File path: boards/arm/stm32h7/nucleo-h743zi/configs/mcuboot-app/defconfig
##########
@@ -0,0 +1,141 @@
+#
+# 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_SPI_EXCHANGE is not set
+# CONFIG_STM32H7_SYSCFG is not set
+CONFIG_ARCH="arm"
+CONFIG_ARCH_BOARD="nucleo-h743zi"
+CONFIG_ARCH_BOARD_NUCLEO_H743ZI=y
+CONFIG_ARCH_CHIP="stm32h7"
+CONFIG_ARCH_CHIP_STM32H743ZI=y
+CONFIG_ARCH_CHIP_STM32H7=y
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_ARMV7M_BASEPRI_WAR=y
+CONFIG_ARMV7M_DCACHE=y
+CONFIG_ARMV7M_DTCM=y
+CONFIG_ARMV7M_ICACHE=y
+CONFIG_ARMV7M_MEMCPY=y
+CONFIG_ARMV7M_STACKCHECK=y
+CONFIG_ARMV7M_USEBASEPRI=y
+CONFIG_ARM_MPU_EARLY_RESET=y
+CONFIG_BOARDCTL_RESET=y
+CONFIG_BOARD_CUSTOM_LEDS=y
+CONFIG_BOARD_LOOPSPERMSEC=43103
+CONFIG_BOOT_MCUBOOT=y
+CONFIG_BUILTIN=y
+CONFIG_CLOCK_MONOTONIC=y
+CONFIG_DEBUG_FEATURES=y
+CONFIG_DEBUG_IRQ=y
+CONFIG_DEBUG_NET=y
+CONFIG_DEBUG_SYMBOLS=y
+CONFIG_DRVR_READAHEAD=y
+CONFIG_DRVR_WRITEBUFFER=y
+CONFIG_ETH0_PHY_LAN8742A=y
+CONFIG_EXAMPLES_LEDS=y
+CONFIG_EXAMPLES_LEDS_LEDSET=0x03
+CONFIG_EXAMPLES_TCPECHO=y
+CONFIG_EXPERIMENTAL=y
+CONFIG_FAT_LCNAMES=y
+CONFIG_FAT_LFN=y
+CONFIG_FS_FAT=y
+CONFIG_FS_PROCFS=y
+CONFIG_FS_ROMFS=y
+CONFIG_FTL_WRITEBUFFER=y
+CONFIG_HAVE_CXX=y
+CONFIG_HAVE_CXXINITIALIZE=y
+CONFIG_I2C=y
+CONFIG_IOB_NBUFFERS=24
+CONFIG_IOB_THROTTLE=0
+CONFIG_LIBC_LZF=y
+CONFIG_LIBM=y
+CONFIG_MCUBOOT_SLOT_CONFIRM_EXAMPLE=y
+CONFIG_MCUBOOT_VERSION="ecd34c116873bf187a3d7431151249ec856738d0"
+CONFIG_MMCSD=y
+CONFIG_MM_CIRCBUF=y
+CONFIG_MM_REGIONS=4
+CONFIG_MTD=y
+CONFIG_MTD_PARTITION=y
+CONFIG_MTD_PROGMEM=y
+CONFIG_MTD_SECT512=y
+CONFIG_MTD_WRBUFFER=y
+CONFIG_NET=y
+CONFIG_NETDB_DNSCLIENT=y
+CONFIG_NETDB_DNSSERVER_IPv4ADDR=0x08080808
+CONFIG_NETDEV_PHY_IOCTL=y
+CONFIG_NETINIT_DRIPADDR=0xc0a80101
+CONFIG_NETINIT_IPADDR=0xc0a801e3
+CONFIG_NETINIT_NOMAC=y
+CONFIG_NETINIT_THREAD=y
+CONFIG_NETUTILS_DISCOVER=y
+CONFIG_NETUTILS_TELNETD=y
+CONFIG_NETUTILS_WEBCLIENT=y
+CONFIG_NETUTILS_WEBSERVER=y
+CONFIG_NET_BROADCAST=y
+CONFIG_NET_ETH_PKTSIZE=1500
+CONFIG_NET_ICMP=y
+CONFIG_NET_ICMP_SOCKET=y
+CONFIG_NET_IGMP=y
+CONFIG_NET_PKT=y
+CONFIG_NET_RECV_BUFSIZE=1500
+CONFIG_NET_ROUTE=y
+CONFIG_NET_SEND_BUFSIZE=1500
+CONFIG_NET_SOLINGER=y
+CONFIG_NET_STATISTICS=y
+CONFIG_NET_TCP=y
+CONFIG_NET_TCPBACKLOG=y
+CONFIG_NET_TCP_NPOLLWAITERS=4
+CONFIG_NET_TCP_WRITE_BUFFERS=y
+CONFIG_NET_UDP=y
+CONFIG_NET_UDP_CHECKSUMS=y
+CONFIG_NSH_ARCHINIT=y
+CONFIG_NSH_ARCHROMFS=y
+CONFIG_NSH_BUILTIN_APPS=y
+CONFIG_NSH_FILEIOSIZE=512
+CONFIG_NSH_LINELEN=64
+CONFIG_NSH_MMCSDSPIPORTNO=1
+CONFIG_NSH_MOTD=y
+CONFIG_NSH_MOTD_STRING="Wellcome to Nuttx MCUboot-Confirm from MCUboot-Loader!"

Review comment:
       ```suggestion
   CONFIG_NSH_MOTD_STRING="Wellcome to Nuttx MCUboot-Confirm from MCUboot-App!"
   ```

##########
File path: boards/arm/stm32h7/nucleo-h743zi/configs/mcuboot-loader/defconfig
##########
@@ -0,0 +1,94 @@
+#
+# 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_SPI_EXCHANGE is not set
+# CONFIG_STM32H7_SYSCFG is not set
+CONFIG_ARCH="arm"
+CONFIG_ARCH_BOARD="nucleo-h743zi"
+CONFIG_ARCH_BOARD_NUCLEO_H743ZI=y
+CONFIG_ARCH_CHIP="stm32h7"
+CONFIG_ARCH_CHIP_STM32H743ZI=y
+CONFIG_ARCH_CHIP_STM32H7=y
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_ARMV7M_BASEPRI_WAR=y
+CONFIG_ARMV7M_DCACHE=y
+CONFIG_ARMV7M_DTCM=y
+CONFIG_ARMV7M_ICACHE=y
+CONFIG_ARMV7M_MEMCPY=y
+CONFIG_ARMV7M_STACKCHECK=y
+CONFIG_ARMV7M_USEBASEPRI=y
+CONFIG_BOARDCTL_RESET=y
+CONFIG_BOARDCTL_ROMDISK=y
+CONFIG_BOARD_CUSTOM_LEDS=y
+CONFIG_BOARD_LATE_INITIALIZE=y
+CONFIG_BOARD_LOOPSPERMSEC=43103
+CONFIG_BOOT_MCUBOOT=y
+CONFIG_BUILTIN=y
+CONFIG_CLOCK_MONOTONIC=y
+CONFIG_DEBUG_FEATURES=y
+CONFIG_DEBUG_IRQ=y
+CONFIG_DEBUG_SYMBOLS=y
+CONFIG_DRVR_READAHEAD=y
+CONFIG_DRVR_WRITEBUFFER=y
+CONFIG_EXPERIMENTAL=y
+CONFIG_FAT_LCNAMES=y
+CONFIG_FAT_LFN=y
+CONFIG_FS_FAT=y
+CONFIG_FS_PROCFS=y
+CONFIG_FTL_WRITEBUFFER=y
+CONFIG_HAVE_CXX=y
+CONFIG_HAVE_CXXINITIALIZE=y
+CONFIG_IOB_NBUFFERS=24
+CONFIG_IOB_NCHAINS=24
+CONFIG_LIBC_LZF=y
+CONFIG_LIBM=y
+CONFIG_MCUBOOT_BOOTLOADER=y
+CONFIG_MCUBOOT_VERSION="ecd34c116873bf187a3d7431151249ec856738d0"
+CONFIG_MM_CIRCBUF=y
+CONFIG_MM_IOB=y
+CONFIG_MM_REGIONS=4
+CONFIG_MTD=y
+CONFIG_MTD_BYTE_WRITE=y
+CONFIG_MTD_PARTITION=y
+CONFIG_MTD_PROGMEM=y
+CONFIG_MTD_PROGMEM_ERASESTATE=y

Review comment:
       I do not see `APP_FORMAT_MCUBOOT` enabled. Is it missing?

##########
File path: boards/arm/stm32h7/nucleo-h743zi/src/stm32_boot_image.c
##########
@@ -0,0 +1,168 @@
+/****************************************************************************
+ * boards/arm/stm32h7/nucleo-h743zi/src/stm32_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 <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);
+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));
+    }
+}
+
+static void systick_disable(void)
+{
+  // interrupt disable
+  modifyreg32(NVIC_SYSTICK_CTRL, NVIC_SYSTICK_CTRL_TICKINT, 0);
+  modifyreg32(NVIC_SYSTICK_CTRL, NVIC_SYSTICK_CTRL_ENABLE, 0);
+
+  // counter disable
+	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(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
+
+  systick_disable();
+
+  /* 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;
+}

Review comment:
       ```suggestion
   }
   
   ```

##########
File path: boards/arm/stm32h7/nucleo-h743zi/scripts/flash-mcu-app.ld
##########
@@ -0,0 +1,200 @@
+/****************************************************************************
+ * boards/arm/stm32h7/nucleo-h743zi/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.
+ *
+ ****************************************************************************/
+
+/* The STM32H743ZI has 2048Kb of main FLASH memory. The flash memory is
+ * partitioned into a User Flash memory and a System Flash memory. Each
+ * of these memories has two banks:
+ *
+ *   1) User Flash memory:
+ *
+ *      Bank 1: Start address 0x0800:0000 to 0x080F:FFFF with 8 sectors, 128Kb each
+ *      Bank 2: Start address 0x0810:0000 to 0x081F:FFFF with 8 sectors, 128Kb each
+ *
+ *   2) System Flash memory:
+ *
+ *      Bank 1: Start address 0x1FF0:0000 to 0x1FF1:FFFF with 1 x 128Kb sector
+ *      Bank 1: Start address 0x1FF4:0000 to 0x1FF5:FFFF with 1 x 128Kb sector
+ *
+ *   3) User option bytes for user configuration, only in Bank 1.
+ *
+ * In the STM32H743ZI, two different boot spaces can be selected through
+ * the BOOT pin and the boot base address programmed in the BOOT_ADD0 and
+ * BOOT_ADD1 option bytes:
+ *
+ *   1) BOOT=0: Boot address defined by user option byte BOOT_ADD0[15:0].
+ *      ST programmed value: Flash memory at 0x0800:0000
+ *   2) BOOT=1: Boot address defined by user option byte BOOT_ADD1[15:0].
+ *      ST programmed value: System bootloader at 0x1FF0:0000
+ *
+ * TODO: Check next paragraph with nucleo schematics
+ *
+ * NuttX does not modify these option bytes. On the unmodified NUCLEO-H743ZI
+ * board, the BOOT0 pin is at ground so by default, the STM32 will boot
+ * to address 0x0800:0000 in FLASH.
+ *
+ * The STM32H743ZI also has 1024Kb of data SRAM.
+ * SRAM is split up into several blocks and into three power domains:
+ *
+ *   1) TCM SRAMs are dedicated to the Cortex-M7 and are accessible with
+ *      0 wait states by the Cortex-M7 and by MDMA through AHBS slave bus
+ *
+ *      1.1) 128Kb of DTCM-RAM beginning at address 0x2000:0000
+ *
+ *           The DTCM-RAM is organized as 2 x 64Kb DTCM-RAMs on 2 x 32 bit
+ *           DTCM ports. The DTCM-RAM could be used for critical real-time
+ *           data, such as interrupt service routines or stack / heap memory.
+ *           Both DTCM-RAMs can be used in parallel (for load/store operations)
+ *           thanks to the Cortex-M7 dual issue capability.
+ *
+ *      1.2)  64Kb of ITCM-RAM beginning at address 0x0000:0000
+ *
+ *           This RAM is connected to ITCM 64-bit interface designed for
+ *           execution of critical real-times routines by the CPU.
+ *
+ *   2) AXI SRAM (D1 domain) accessible by all system masters except BDMA
+ *      through D1 domain AXI bus matrix
+ *
+ *      2.1) 512Kb of SRAM beginning at address 0x2400:0000
+ *
+ *   3) AHB SRAM (D2 domain) accessible by all system masters except BDMA
+ *      through D2 domain AHB bus matrix
+ *
+ *      3.1) 128Kb of SRAM1 beginning at address 0x3000:0000
+ *      3.2) 128Kb of SRAM2 beginning at address 0x3002:0000
+ *      3.3)  32Kb of SRAM3 beginning at address 0x3004:0000
+ *
+ *      SRAM1 - SRAM3 are one contiguous block: 288Kb at address 0x3000:0000
+ *
+ *   4) AHB SRAM (D3 domain) accessible by most of system masters
+ *      through D3 domain AHB bus matrix
+ *
+ *      4.1)  64Kb of SRAM4 beginning at address 0x3800:0000
+ *      4.1)   4Kb of backup RAM beginning at address 0x3880: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 0x0800:0000 address range.
+ */
+
+MEMORY
+{
+  itcm  (rwx) : ORIGIN = 0x00000000, LENGTH =   64K
+  flash (rx)  : ORIGIN = 0x08020000, LENGTH = 1920K

Review comment:
       Please see https://github.com/apache/incubator-nuttx/blob/5da9dbe57af2d9b0b22c6cf1b92e76dfe6dcb67b/boards/arm/samv7/same70-xplained/scripts/flash-dtcm-mcuboot-app.ld#L34 as a reference.
   The MCUboot compatible image requires a header to be prepended to image. The default header size is 32 bytes, but taking into account that NVIC start address should be aligned according to arch requirements the alignment might be bigger than 32.
   Also please align `LENGTH` with `config OTA_SLOT_SIZE` value
   

##########
File path: boards/arm/stm32h7/nucleo-h743zi/configs/mcuboot-app/defconfig
##########
@@ -0,0 +1,141 @@
+#
+# 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_SPI_EXCHANGE is not set
+# CONFIG_STM32H7_SYSCFG is not set
+CONFIG_ARCH="arm"
+CONFIG_ARCH_BOARD="nucleo-h743zi"
+CONFIG_ARCH_BOARD_NUCLEO_H743ZI=y
+CONFIG_ARCH_CHIP="stm32h7"
+CONFIG_ARCH_CHIP_STM32H743ZI=y
+CONFIG_ARCH_CHIP_STM32H7=y
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_ARMV7M_BASEPRI_WAR=y
+CONFIG_ARMV7M_DCACHE=y
+CONFIG_ARMV7M_DTCM=y
+CONFIG_ARMV7M_ICACHE=y
+CONFIG_ARMV7M_MEMCPY=y
+CONFIG_ARMV7M_STACKCHECK=y
+CONFIG_ARMV7M_USEBASEPRI=y
+CONFIG_ARM_MPU_EARLY_RESET=y
+CONFIG_BOARDCTL_RESET=y
+CONFIG_BOARD_CUSTOM_LEDS=y
+CONFIG_BOARD_LOOPSPERMSEC=43103
+CONFIG_BOOT_MCUBOOT=y
+CONFIG_BUILTIN=y
+CONFIG_CLOCK_MONOTONIC=y
+CONFIG_DEBUG_FEATURES=y
+CONFIG_DEBUG_IRQ=y
+CONFIG_DEBUG_NET=y
+CONFIG_DEBUG_SYMBOLS=y
+CONFIG_DRVR_READAHEAD=y
+CONFIG_DRVR_WRITEBUFFER=y
+CONFIG_ETH0_PHY_LAN8742A=y
+CONFIG_EXAMPLES_LEDS=y
+CONFIG_EXAMPLES_LEDS_LEDSET=0x03
+CONFIG_EXAMPLES_TCPECHO=y
+CONFIG_EXPERIMENTAL=y
+CONFIG_FAT_LCNAMES=y
+CONFIG_FAT_LFN=y
+CONFIG_FS_FAT=y
+CONFIG_FS_PROCFS=y
+CONFIG_FS_ROMFS=y
+CONFIG_FTL_WRITEBUFFER=y
+CONFIG_HAVE_CXX=y
+CONFIG_HAVE_CXXINITIALIZE=y
+CONFIG_I2C=y
+CONFIG_IOB_NBUFFERS=24
+CONFIG_IOB_THROTTLE=0
+CONFIG_LIBC_LZF=y
+CONFIG_LIBM=y
+CONFIG_MCUBOOT_SLOT_CONFIRM_EXAMPLE=y
+CONFIG_MCUBOOT_VERSION="ecd34c116873bf187a3d7431151249ec856738d0"

Review comment:
       ```suggestion
   ```

##########
File path: boards/arm/stm32h7/nucleo-h743zi/scripts/flash-mcu-loader.ld
##########
@@ -0,0 +1,200 @@
+/****************************************************************************
+ * boards/arm/stm32h7/nucleo-h743zi/scripts/flash.ld

Review comment:
       ```suggestion
    * boards/arm/stm32h7/nucleo-h743zi/scripts/flash-mcu-loader.ld
   ```

##########
File path: boards/arm/stm32h7/nucleo-h743zi/scripts/flash-mcu-app.ld
##########
@@ -0,0 +1,200 @@
+/****************************************************************************
+ * boards/arm/stm32h7/nucleo-h743zi/scripts/flash.ld

Review comment:
       ```suggestion
    * boards/arm/stm32h7/nucleo-h743zi/scripts/flash-mcu-app.ld
   ```

##########
File path: boards/arm/stm32h7/nucleo-h743zi/src/nucleo-h743zi.h
##########
@@ -36,10 +36,12 @@
 
 /* Configuration ************************************************************/
 
-#define HAVE_PROC       1
-#define HAVE_USBDEV     1
-#define HAVE_USBHOST    1
-#define HAVE_USBMONITOR 1
+#define HAVE_PROC            1
+#define HAVE_USBDEV          1
+#define HAVE_USBHOST         1
+#define HAVE_USBMONITOR      1
+#define HAVE_MTDCONFIG       1

Review comment:
       Please add below in this file
   ```
   #if !defined(CONFIG_MTD_CONFIG)
   #  undef HAVE_MTDCONFIG
   #endif
   
   /* On-chip Programming Memory */
   
   #if !defined(CONFIG_STM32H7_PROGMEM) || !defined(CONFIG_MTD_PROGMEM)
   #  undef HAVE_PROGMEM_CHARDEV
   #endif
   ```

##########
File path: boards/arm/stm32h7/nucleo-h743zi/src/stm32_progmem.c
##########
@@ -0,0 +1,284 @@
+/****************************************************************************
+ * apps/examples/mtdpart/stm32_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 <stm32.h>
+#include <nucleo-h743zi.h>
+#include <stm32_flash.h>
+
+#ifdef HAVE_PROGMEM_CHARDEV
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ARRAYSIZE(x)                (sizeof((x)) / sizeof((x)[0]))
+
+/* 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_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_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 FAR struct mtd_dev_s *g_progmem_mtd;
+
+#if defined(CONFIG_PROGMEM_OTA_PARTITION)
+static const struct ota_partition_s g_ota_partition_table[] =
+{
+  {
+    .offset  = CONFIG_OTA_PRIMARY_SLOT_OFFSET,
+    .size    = CONFIG_OTA_SLOT_SIZE,
+    .devpath = CONFIG_OTA_PRIMARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_OTA_SECONDARY_SLOT_OFFSET,
+    .size    = CONFIG_OTA_SLOT_SIZE,
+    .devpath = CONFIG_OTA_SECONDARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_OTA_SCRATCH_OFFSET,
+    .size    = CONFIG_OTA_SCRATCH_SIZE,
+    .devpath = CONFIG_OTA_SCRATCH_DEVPATH
+  }
+};
+#endif
+
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(CONFIG_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 *progmem_alloc_mtdpart(uint32_t mtd_offset,
+                                                   uint32_t mtd_size)
+{
+  uint32_t blocks;
+  ssize_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 + 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)
+{
+  FAR struct mtd_dev_s *mtd;
+#ifdef CONFIG_BCH
+  char blockdev[18];
+#endif
+  int ret = OK;
+
+  for (uint 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);
+
+      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: stm32_progmem_init
+ *
+ * Description:
+ *   Initialize the FLASH and register the MTD device.
+ ****************************************************************************/
+
+int stm32_progmem_init(void)
+{
+  int ret = OK;
+
+
+  stm32h7_flash_unlock();  //TODO: Remove. Is only because cant link if removed.
+
+  /* Create an instance of the SAME70 FLASH program memory device driver */
+
+  g_progmem_mtd = progmem_initialize();
+  if (g_progmem_mtd == NULL)
+  {
+    return -EFAULT;
+  }
+
+#if defined(CONFIG_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_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 */

Review comment:
       ```suggestion
   #endif /* HAVE_PROGMEM_CHARDEV */
   
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org