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 2022/08/28 17:08:12 UTC

[GitHub] [incubator-nuttx] tito97sp opened a new pull request, #6944: boards/stm32h7: add support for mcuboot

tito97sp opened a new pull request, #6944:
URL: https://github.com/apache/incubator-nuttx/pull/6944

   Add support for MCUBoot.
   
   ## Summary
   Two new configurations are added:
   
   - **mcuboot-loader:** mcuboot-loader app used as a bootloader.
   mcuboot_loader_main` is used as entry point
   
   - **mcuboot-app:** used as mcuboot agent app.
   Needs to be signed manually through `"imgtool sign --pad  --align 4 -v 0 -s auto -H 0x200 --pad-header -S 0xc0000 nuttx.hex nuttx_sign.bin"`
   
   Signed-off-by: Andres Sanchez <ti...@hotmail.com>
   
   ## Summary
   
   ## Impact
   
   ## Testing
   
   


-- 
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


[GitHub] [incubator-nuttx] tito97sp commented on a diff in pull request #6944: boards/stm32h7: add support for mcuboot

Posted by GitBox <gi...@apache.org>.
tito97sp commented on code in PR #6944:
URL: https://github.com/apache/incubator-nuttx/pull/6944#discussion_r956783511


##########
boards/arm/stm32h7/nucleo-h743zi/src/stm32_progmem.c:
##########
@@ -0,0 +1,279 @@
+/****************************************************************************
+ * boards/arm/stm32h7/nucleo-h743zi/src/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_STM32_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_STM32_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_STM32_PROGMEM_OTA_PARTITION)
+static const struct ota_partition_s g_ota_partition_table[] =
+{
+  {
+    .offset  = CONFIG_STM32_OTA_PRIMARY_SLOT_OFFSET,
+    .size    = CONFIG_STM32_OTA_SLOT_SIZE,
+    .devpath = CONFIG_STM32_OTA_PRIMARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_STM32_OTA_SECONDARY_SLOT_OFFSET,
+    .size    = CONFIG_STM32_OTA_SLOT_SIZE,
+    .devpath = CONFIG_STM32_OTA_SECONDARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_STM32_OTA_SCRATCH_OFFSET,
+    .size    = CONFIG_STM32_OTA_SCRATCH_SIZE,
+    .devpath = CONFIG_STM32_OTA_SCRATCH_DEVPATH
+  }
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(CONFIG_STM32_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 % 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 /* CONFIG_STM32_PROGMEM_OTA_PARTITION */
+
+/****************************************************************************
+ * 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();
+
+  /* Create an instance of the FLASH program memory device driver */
+
+  g_progmem_mtd = progmem_initialize();
+  if (g_progmem_mtd == NULL)
+    {
+      return -EFAULT;
+    }
+
+#if defined(CONFIG_STM32_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);

Review Comment:
   @xiaoxiang781216 Do you have some reference which I could use as template? (i.e: esp32 drivers or so...)



-- 
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


[GitHub] [incubator-nuttx] tito97sp commented on a diff in pull request #6944: boards/stm32h7: add support for mcuboot

Posted by GitBox <gi...@apache.org>.
tito97sp commented on code in PR #6944:
URL: https://github.com/apache/incubator-nuttx/pull/6944#discussion_r956781742


##########
boards/arm/stm32h7/nucleo-h743zi/scripts/gnu-elf.ld:
##########
@@ -0,0 +1,126 @@
+/****************************************************************************
+ * boards/arm/stm32h7/nucleo-h743zi/scripts/gnu-elf.ld

Review Comment:
   solved



##########
boards/arm/stm32h7/nucleo-h743zi/src/stm32_bringup.c:
##########
@@ -297,7 +297,7 @@ int stm32_bringup(void)
   if (ret < 0)
     {
       syslog(LOG_ERR, "ERROR: Failed to initialize wireless driver: %d\n",
-             ret);
+            ret);

Review Comment:
   solved



-- 
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


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on pull request #6944: boards/stm32h7: add support for mcuboot

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #6944:
URL: https://github.com/apache/incubator-nuttx/pull/6944#issuecomment-1236373540

   @tito97sp it's better to squash the last patch to previous patch.


-- 
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


[GitHub] [incubator-nuttx] tito97sp commented on a diff in pull request #6944: boards/stm32h7: add support for mcuboot

Posted by GitBox <gi...@apache.org>.
tito97sp commented on code in PR #6944:
URL: https://github.com/apache/incubator-nuttx/pull/6944#discussion_r956781727


##########
boards/arm/stm32h7/nucleo-h743zi/Kconfig:
##########
@@ -27,4 +27,6 @@ config STM32_ROMFS_IMAGEFILE
 	depends on STM32_ROMFS
 	default "../../../rom.img"
 
+
+

Review Comment:
   solved



##########
boards/arm/stm32h7/nucleo-h743zi/configs/netnsh/defconfig:
##########
@@ -85,3 +86,4 @@ CONFIG_USART3_SERIAL_CONSOLE=y
 CONFIG_USBHOST=y
 CONFIG_USBHOST_MSC=y
 CONFIG_USBHOST_MSC_NOTIFIER=y
+CONFIG_USER_ENTRYPOINT="nsh_main"

Review Comment:
   solved



##########
boards/arm/stm32h7/nucleo-h743zi/configs/netnsh/defconfig:
##########
@@ -63,6 +63,7 @@ CONFIG_RR_INTERVAL=200
 CONFIG_SCHED_HPWORK=y
 CONFIG_SCHED_LPWORK=y
 CONFIG_SCHED_WAITPID=y
+CONFIG_SDCLONE_DISABLE=y

Review Comment:
   solved



-- 
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


[GitHub] [incubator-nuttx] xiaoxiang781216 merged pull request #6944: boards/stm32h7: add support for mcuboot

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 merged PR #6944:
URL: https://github.com/apache/incubator-nuttx/pull/6944


-- 
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


[GitHub] [incubator-nuttx] tito97sp commented on a diff in pull request #6944: boards/stm32h7: add support for mcuboot

Posted by GitBox <gi...@apache.org>.
tito97sp commented on code in PR #6944:
URL: https://github.com/apache/incubator-nuttx/pull/6944#discussion_r956781351


##########
boards/arm/stm32h7/nucleo-h743zi/src/stm32_progmem.c:
##########
@@ -0,0 +1,279 @@
+/****************************************************************************
+ * boards/arm/stm32h7/nucleo-h743zi/src/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_STM32_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_STM32_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_STM32_PROGMEM_OTA_PARTITION)
+static const struct ota_partition_s g_ota_partition_table[] =
+{
+  {
+    .offset  = CONFIG_STM32_OTA_PRIMARY_SLOT_OFFSET,
+    .size    = CONFIG_STM32_OTA_SLOT_SIZE,
+    .devpath = CONFIG_STM32_OTA_PRIMARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_STM32_OTA_SECONDARY_SLOT_OFFSET,
+    .size    = CONFIG_STM32_OTA_SLOT_SIZE,
+    .devpath = CONFIG_STM32_OTA_SECONDARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_STM32_OTA_SCRATCH_OFFSET,
+    .size    = CONFIG_STM32_OTA_SCRATCH_SIZE,
+    .devpath = CONFIG_STM32_OTA_SCRATCH_DEVPATH
+  }
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(CONFIG_STM32_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 % 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 /* CONFIG_STM32_PROGMEM_OTA_PARTITION */
+
+/****************************************************************************
+ * 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();
+
+  /* Create an instance of the FLASH program memory device driver */
+
+  g_progmem_mtd = progmem_initialize();
+  if (g_progmem_mtd == NULL)
+    {
+      return -EFAULT;
+    }
+
+#if defined(CONFIG_STM32_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);

Review Comment:
   Hi @xiaoxiang781216 . By calling directly `register_mtddriver()` I think I will have to rebuild all the **stm32_progmem** driver. Is this the best way?



-- 
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


[GitHub] [incubator-nuttx] pkarashchenko commented on a diff in pull request #6944: boards/stm32h7: add support for mcuboot

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #6944:
URL: https://github.com/apache/incubator-nuttx/pull/6944#discussion_r957141804


##########
boards/arm/stm32h7/nucleo-h743zi/src/stm32_boot_image.c:
##########
@@ -0,0 +1,186 @@
+/****************************************************************************
+ * boards/arm/stm32h7/nucleo-h743zi/src/stm32_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);
+#ifdef CONFIG_ARMV7M_SYSTICK
+static void systick_disable(void);
+#endif

Review Comment:
   Please see [`boards/arm/samv7/common/src/sam_boot_image.c`](https://github.com/apache/incubator-nuttx/pull/5406/files#r798493720)



##########
boards/arm/stm32h7/nucleo-h743zi/src/stm32_progmem.c:
##########
@@ -0,0 +1,279 @@
+/****************************************************************************
+ * boards/arm/stm32h7/nucleo-h743zi/src/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_STM32_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_STM32_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;

Review Comment:
   ```suggestion
   static struct mtd_dev_s *g_progmem_mtd;
   ```
   Please remove `FAR` for ARM files



##########
boards/arm/stm32h7/nucleo-h743zi/src/stm32_progmem.c:
##########
@@ -0,0 +1,279 @@
+/****************************************************************************
+ * boards/arm/stm32h7/nucleo-h743zi/src/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_STM32_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_STM32_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_STM32_PROGMEM_OTA_PARTITION)
+static const struct ota_partition_s g_ota_partition_table[] =
+{
+  {
+    .offset  = CONFIG_STM32_OTA_PRIMARY_SLOT_OFFSET,
+    .size    = CONFIG_STM32_OTA_SLOT_SIZE,
+    .devpath = CONFIG_STM32_OTA_PRIMARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_STM32_OTA_SECONDARY_SLOT_OFFSET,
+    .size    = CONFIG_STM32_OTA_SLOT_SIZE,
+    .devpath = CONFIG_STM32_OTA_SECONDARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_STM32_OTA_SCRATCH_OFFSET,
+    .size    = CONFIG_STM32_OTA_SCRATCH_SIZE,
+    .devpath = CONFIG_STM32_OTA_SCRATCH_DEVPATH
+  }
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(CONFIG_STM32_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 % 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 /* CONFIG_STM32_PROGMEM_OTA_PARTITION */
+
+/****************************************************************************
+ * 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();
+
+  /* Create an instance of the FLASH program memory device driver */
+
+  g_progmem_mtd = progmem_initialize();
+  if (g_progmem_mtd == NULL)
+    {
+      return -EFAULT;
+    }
+
+#if defined(CONFIG_STM32_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);

Review Comment:
   ```suggestion
     snprintf(blockdev, sizeof(blockdev), "/dev/mtdblock%d", PROGMEM_MTD_MINOR);
     snprintf(chardev, sizeof(chardev), "/dev/mtd%d", PROGMEM_MTD_MINOR);
   ```



##########
boards/arm/stm32h7/nucleo-h743zi/src/stm32_progmem.c:
##########
@@ -0,0 +1,279 @@
+/****************************************************************************
+ * boards/arm/stm32h7/nucleo-h743zi/src/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_STM32_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_STM32_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_STM32_PROGMEM_OTA_PARTITION)
+static const struct ota_partition_s g_ota_partition_table[] =
+{
+  {
+    .offset  = CONFIG_STM32_OTA_PRIMARY_SLOT_OFFSET,
+    .size    = CONFIG_STM32_OTA_SLOT_SIZE,
+    .devpath = CONFIG_STM32_OTA_PRIMARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_STM32_OTA_SECONDARY_SLOT_OFFSET,
+    .size    = CONFIG_STM32_OTA_SLOT_SIZE,
+    .devpath = CONFIG_STM32_OTA_SECONDARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_STM32_OTA_SCRATCH_OFFSET,
+    .size    = CONFIG_STM32_OTA_SCRATCH_SIZE,
+    .devpath = CONFIG_STM32_OTA_SCRATCH_DEVPATH
+  }
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(CONFIG_STM32_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 % 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 /* CONFIG_STM32_PROGMEM_OTA_PARTITION */
+
+/****************************************************************************
+ * 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();
+
+  /* Create an instance of the FLASH program memory device driver */
+
+  g_progmem_mtd = progmem_initialize();
+  if (g_progmem_mtd == NULL)
+    {
+      return -EFAULT;
+    }
+
+#if defined(CONFIG_STM32_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);

Review Comment:
   ```suggestion
         syslog(LOG_ERR, "ERROR: Failed to initialize the FTL layer: %d\n",
                ret);
   ```



##########
boards/arm/stm32h7/nucleo-h743zi/src/stm32_progmem.c:
##########
@@ -0,0 +1,279 @@
+/****************************************************************************
+ * boards/arm/stm32h7/nucleo-h743zi/src/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_STM32_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_STM32_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_STM32_PROGMEM_OTA_PARTITION)
+static const struct ota_partition_s g_ota_partition_table[] =
+{
+  {
+    .offset  = CONFIG_STM32_OTA_PRIMARY_SLOT_OFFSET,
+    .size    = CONFIG_STM32_OTA_SLOT_SIZE,
+    .devpath = CONFIG_STM32_OTA_PRIMARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_STM32_OTA_SECONDARY_SLOT_OFFSET,
+    .size    = CONFIG_STM32_OTA_SLOT_SIZE,
+    .devpath = CONFIG_STM32_OTA_SECONDARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_STM32_OTA_SCRATCH_OFFSET,
+    .size    = CONFIG_STM32_OTA_SCRATCH_SIZE,
+    .devpath = CONFIG_STM32_OTA_SCRATCH_DEVPATH
+  }
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(CONFIG_STM32_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 % 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 /* CONFIG_STM32_PROGMEM_OTA_PARTITION */
+
+/****************************************************************************
+ * 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();
+
+  /* Create an instance of the FLASH program memory device driver */
+
+  g_progmem_mtd = progmem_initialize();
+  if (g_progmem_mtd == NULL)
+    {
+      return -EFAULT;
+    }
+
+#if defined(CONFIG_STM32_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);

Review Comment:
   ```suggestion
         syslog(LOG_ERR, "ERROR: bchdev_register %s failed: %d\n",
                chardev, ret);
   ```



##########
boards/arm/stm32h7/nucleo-h743zi/src/stm32_progmem.c:
##########
@@ -0,0 +1,279 @@
+/****************************************************************************
+ * boards/arm/stm32h7/nucleo-h743zi/src/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_STM32_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_STM32_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_STM32_PROGMEM_OTA_PARTITION)
+static const struct ota_partition_s g_ota_partition_table[] =
+{
+  {
+    .offset  = CONFIG_STM32_OTA_PRIMARY_SLOT_OFFSET,
+    .size    = CONFIG_STM32_OTA_SLOT_SIZE,
+    .devpath = CONFIG_STM32_OTA_PRIMARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_STM32_OTA_SECONDARY_SLOT_OFFSET,
+    .size    = CONFIG_STM32_OTA_SLOT_SIZE,
+    .devpath = CONFIG_STM32_OTA_SECONDARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_STM32_OTA_SCRATCH_OFFSET,
+    .size    = CONFIG_STM32_OTA_SCRATCH_SIZE,
+    .devpath = CONFIG_STM32_OTA_SCRATCH_DEVPATH
+  }
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(CONFIG_STM32_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 % 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 /* CONFIG_STM32_PROGMEM_OTA_PARTITION */
+
+/****************************************************************************
+ * 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();
+
+  /* Create an instance of the FLASH program memory device driver */
+
+  g_progmem_mtd = progmem_initialize();
+  if (g_progmem_mtd == NULL)
+    {
+      return -EFAULT;
+    }
+
+#if defined(CONFIG_STM32_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


[GitHub] [incubator-nuttx] acassis commented on a diff in pull request #6944: boards/stm32h7: add support for mcuboot

Posted by GitBox <gi...@apache.org>.
acassis commented on code in PR #6944:
URL: https://github.com/apache/incubator-nuttx/pull/6944#discussion_r957764831


##########
boards/arm/stm32h7/nucleo-h743zi/configs/netnsh/defconfig:
##########
@@ -63,6 +63,7 @@ CONFIG_RR_INTERVAL=200
 CONFIG_SCHED_HPWORK=y
 CONFIG_SCHED_LPWORK=y
 CONFIG_SCHED_WAITPID=y
+CONFIG_SDCLONE_DISABLE=y

Review Comment:
   It seems you are using old config, this option was removed:
   ```
   $ git grep SDCLONE_DISABLE
   ReleaseNotes:* [#5392](https://github.com/apache/incubator-nuttx/pull/#5392) sched: Remove SDCLONE_DISABLE option and configĀ 
   ```



##########
boards/arm/stm32h7/nucleo-h743zi/Kconfig:
##########
@@ -27,4 +27,6 @@ config STM32_ROMFS_IMAGEFILE
 	depends on STM32_ROMFS
 	default "../../../rom.img"
 
+
+

Review Comment:
   Please remove these extra lines



-- 
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


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #6944: boards/stm32h7: add support for mcuboot

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #6944:
URL: https://github.com/apache/incubator-nuttx/pull/6944#discussion_r956843706


##########
boards/arm/stm32h7/nucleo-h743zi/src/stm32_progmem.c:
##########
@@ -0,0 +1,279 @@
+/****************************************************************************
+ * boards/arm/stm32h7/nucleo-h743zi/src/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_STM32_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_STM32_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_STM32_PROGMEM_OTA_PARTITION)
+static const struct ota_partition_s g_ota_partition_table[] =
+{
+  {
+    .offset  = CONFIG_STM32_OTA_PRIMARY_SLOT_OFFSET,
+    .size    = CONFIG_STM32_OTA_SLOT_SIZE,
+    .devpath = CONFIG_STM32_OTA_PRIMARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_STM32_OTA_SECONDARY_SLOT_OFFSET,
+    .size    = CONFIG_STM32_OTA_SLOT_SIZE,
+    .devpath = CONFIG_STM32_OTA_SECONDARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_STM32_OTA_SCRATCH_OFFSET,
+    .size    = CONFIG_STM32_OTA_SCRATCH_SIZE,
+    .devpath = CONFIG_STM32_OTA_SCRATCH_DEVPATH
+  }
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(CONFIG_STM32_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 % 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 /* CONFIG_STM32_PROGMEM_OTA_PARTITION */
+
+/****************************************************************************
+ * 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();
+
+  /* Create an instance of the FLASH program memory device driver */
+
+  g_progmem_mtd = progmem_initialize();
+  if (g_progmem_mtd == NULL)
+    {
+      return -EFAULT;
+    }
+
+#if defined(CONFIG_STM32_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);

Review Comment:
   > @xiaoxiang781216 Do you have some reference which I could use as template? (i.e: esp32 drivers or so...)
   
   Here is how esp32c3 call `register_mtddriver`:
   https://github.com/apache/incubator-nuttx/blob/master/arch/risc-v/src/esp32c3/esp32c3_partition.c#L651
   
   Basically, you can just call `register_mtddriver` and remove ftl_initialize/bchdev_register since `register_mtddriver` will do that for you behind the scene.
   
   > Hi @xiaoxiang781216 . By calling directly `register_mtddriver()` I think I will have to rebuild all the **stm32_progmem** driver. Is this the best way?
   
   You don't need modify any driver code since `register_mtddriver` use `mtd_dev_s` too.
   
   



-- 
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


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #6944: boards/stm32h7: add support for mcuboot

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #6944:
URL: https://github.com/apache/incubator-nuttx/pull/6944#discussion_r972574028


##########
boards/arm/stm32h7/nucleo-h743zi/src/stm32_progmem.c:
##########
@@ -0,0 +1,279 @@
+/****************************************************************************
+ * boards/arm/stm32h7/nucleo-h743zi/src/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_STM32_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_STM32_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;

Review Comment:
   Fix here: https://github.com/apache/incubator-nuttx/pull/7106



-- 
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


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #6944: boards/stm32h7: add support for mcuboot

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #6944:
URL: https://github.com/apache/incubator-nuttx/pull/6944#discussion_r956758776


##########
boards/arm/stm32h7/nucleo-h743zi/configs/netnsh/defconfig:
##########
@@ -63,6 +63,7 @@ CONFIG_RR_INTERVAL=200
 CONFIG_SCHED_HPWORK=y
 CONFIG_SCHED_LPWORK=y
 CONFIG_SCHED_WAITPID=y
+CONFIG_SDCLONE_DISABLE=y

Review Comment:
   why change netnsh/defconfig



##########
boards/arm/stm32h7/nucleo-h743zi/Kconfig:
##########
@@ -27,4 +27,6 @@ config STM32_ROMFS_IMAGEFILE
 	depends on STM32_ROMFS
 	default "../../../rom.img"
 
+
+

Review Comment:
   revert the change



##########
boards/arm/stm32h7/nucleo-h743zi/src/stm32_bringup.c:
##########
@@ -297,7 +297,7 @@ int stm32_bringup(void)
   if (ret < 0)
     {
       syslog(LOG_ERR, "ERROR: Failed to initialize wireless driver: %d\n",
-             ret);
+            ret);

Review Comment:
   revert the change



##########
boards/arm/stm32h7/nucleo-h743zi/configs/netnsh/defconfig:
##########
@@ -85,3 +86,4 @@ CONFIG_USART3_SERIAL_CONSOLE=y
 CONFIG_USBHOST=y
 CONFIG_USBHOST_MSC=y
 CONFIG_USBHOST_MSC_NOTIFIER=y
+CONFIG_USER_ENTRYPOINT="nsh_main"

Review Comment:
   remove, the option change to CONFIG_INIT_ENTRYPOINT at line 30



##########
boards/arm/stm32h7/nucleo-h743zi/scripts/gnu-elf.ld:
##########
@@ -0,0 +1,126 @@
+/****************************************************************************
+ * boards/arm/stm32h7/nucleo-h743zi/scripts/gnu-elf.ld

Review Comment:
   remove, let's use binfmt/libelf/gnu-elf.ld instead



##########
boards/arm/stm32h7/nucleo-h743zi/src/stm32_progmem.c:
##########
@@ -0,0 +1,279 @@
+/****************************************************************************
+ * boards/arm/stm32h7/nucleo-h743zi/src/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_STM32_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_STM32_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_STM32_PROGMEM_OTA_PARTITION)
+static const struct ota_partition_s g_ota_partition_table[] =
+{
+  {
+    .offset  = CONFIG_STM32_OTA_PRIMARY_SLOT_OFFSET,
+    .size    = CONFIG_STM32_OTA_SLOT_SIZE,
+    .devpath = CONFIG_STM32_OTA_PRIMARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_STM32_OTA_SECONDARY_SLOT_OFFSET,
+    .size    = CONFIG_STM32_OTA_SLOT_SIZE,
+    .devpath = CONFIG_STM32_OTA_SECONDARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_STM32_OTA_SCRATCH_OFFSET,
+    .size    = CONFIG_STM32_OTA_SCRATCH_SIZE,
+    .devpath = CONFIG_STM32_OTA_SCRATCH_DEVPATH
+  }
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(CONFIG_STM32_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 % 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 /* CONFIG_STM32_PROGMEM_OTA_PARTITION */
+
+/****************************************************************************
+ * 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();
+
+  /* Create an instance of the FLASH program memory device driver */
+
+  g_progmem_mtd = progmem_initialize();
+  if (g_progmem_mtd == NULL)
+    {
+      return -EFAULT;
+    }
+
+#if defined(CONFIG_STM32_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);

Review Comment:
   call register_mtddriver directly



-- 
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


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #6944: boards/stm32h7: add support for mcuboot

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #6944:
URL: https://github.com/apache/incubator-nuttx/pull/6944#discussion_r956843706


##########
boards/arm/stm32h7/nucleo-h743zi/src/stm32_progmem.c:
##########
@@ -0,0 +1,279 @@
+/****************************************************************************
+ * boards/arm/stm32h7/nucleo-h743zi/src/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_STM32_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_STM32_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_STM32_PROGMEM_OTA_PARTITION)
+static const struct ota_partition_s g_ota_partition_table[] =
+{
+  {
+    .offset  = CONFIG_STM32_OTA_PRIMARY_SLOT_OFFSET,
+    .size    = CONFIG_STM32_OTA_SLOT_SIZE,
+    .devpath = CONFIG_STM32_OTA_PRIMARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_STM32_OTA_SECONDARY_SLOT_OFFSET,
+    .size    = CONFIG_STM32_OTA_SLOT_SIZE,
+    .devpath = CONFIG_STM32_OTA_SECONDARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_STM32_OTA_SCRATCH_OFFSET,
+    .size    = CONFIG_STM32_OTA_SCRATCH_SIZE,
+    .devpath = CONFIG_STM32_OTA_SCRATCH_DEVPATH
+  }
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(CONFIG_STM32_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 % 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 /* CONFIG_STM32_PROGMEM_OTA_PARTITION */
+
+/****************************************************************************
+ * 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();
+
+  /* Create an instance of the FLASH program memory device driver */
+
+  g_progmem_mtd = progmem_initialize();
+  if (g_progmem_mtd == NULL)
+    {
+      return -EFAULT;
+    }
+
+#if defined(CONFIG_STM32_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);

Review Comment:
   > @xiaoxiang781216 Do you have some reference which I could use as template? (i.e: esp32 drivers or so...)
   
   Here is how esp32c3 call `register_mtddriver`:
   https://github.com/apache/incubator-nuttx/blob/master/arch/risc-v/src/esp32c3/esp32c3_partition.c#L651
   
   > Hi @xiaoxiang781216 . By calling directly `register_mtddriver()` I think I will have to rebuild all the **stm32_progmem** driver. Is this the best way?
   
   You don't need modify any driver code since `register_mtddriver` use `mtd_dev_s` too.
   
   



-- 
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


[GitHub] [incubator-nuttx] pkarashchenko commented on a diff in pull request #6944: boards/stm32h7: add support for mcuboot

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #6944:
URL: https://github.com/apache/incubator-nuttx/pull/6944#discussion_r972363128


##########
boards/arm/stm32h7/nucleo-h743zi/src/stm32_progmem.c:
##########
@@ -0,0 +1,279 @@
+/****************************************************************************
+ * boards/arm/stm32h7/nucleo-h743zi/src/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_STM32_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_STM32_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;

Review Comment:
   @xiaoxiang781216 why this was marked as resolved? And we bring FAR back for ARM.



-- 
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


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #6944: boards/stm32h7: add support for mcuboot

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #6944:
URL: https://github.com/apache/incubator-nuttx/pull/6944#discussion_r956843706


##########
boards/arm/stm32h7/nucleo-h743zi/src/stm32_progmem.c:
##########
@@ -0,0 +1,279 @@
+/****************************************************************************
+ * boards/arm/stm32h7/nucleo-h743zi/src/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_STM32_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_STM32_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_STM32_PROGMEM_OTA_PARTITION)
+static const struct ota_partition_s g_ota_partition_table[] =
+{
+  {
+    .offset  = CONFIG_STM32_OTA_PRIMARY_SLOT_OFFSET,
+    .size    = CONFIG_STM32_OTA_SLOT_SIZE,
+    .devpath = CONFIG_STM32_OTA_PRIMARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_STM32_OTA_SECONDARY_SLOT_OFFSET,
+    .size    = CONFIG_STM32_OTA_SLOT_SIZE,
+    .devpath = CONFIG_STM32_OTA_SECONDARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_STM32_OTA_SCRATCH_OFFSET,
+    .size    = CONFIG_STM32_OTA_SCRATCH_SIZE,
+    .devpath = CONFIG_STM32_OTA_SCRATCH_DEVPATH
+  }
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(CONFIG_STM32_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 % 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 /* CONFIG_STM32_PROGMEM_OTA_PARTITION */
+
+/****************************************************************************
+ * 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();
+
+  /* Create an instance of the FLASH program memory device driver */
+
+  g_progmem_mtd = progmem_initialize();
+  if (g_progmem_mtd == NULL)
+    {
+      return -EFAULT;
+    }
+
+#if defined(CONFIG_STM32_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);

Review Comment:
   > @xiaoxiang781216 Do you have some reference which I could use as template? (i.e: esp32 drivers or so...)
   
   Here is how esp32c3 call `register_mtddriver`:
   https://github.com/apache/incubator-nuttx/blob/master/arch/risc-v/src/esp32c3/esp32c3_partition.c#L651
   
   > Hi @xiaoxiang781216 . By calling directly `register_mtddriver()` I think I will have to rebuild all the **stm32_progmem** driver. Is this the best way?
   
   You don't need modify any driver code since register_mtddriver use `mtd_dev_s` too.
   
   



-- 
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


[GitHub] [incubator-nuttx] pkarashchenko commented on a diff in pull request #6944: boards/stm32h7: add support for mcuboot

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #6944:
URL: https://github.com/apache/incubator-nuttx/pull/6944#discussion_r972361873


##########
boards/arm/stm32h7/nucleo-h743zi/src/stm32_boot_image.c:
##########
@@ -0,0 +1,186 @@
+/****************************************************************************
+ * boards/arm/stm32h7/nucleo-h743zi/src/stm32_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);
+#ifdef CONFIG_ARMV7M_SYSTICK
+static void systick_disable(void);
+#endif

Review Comment:
   @xiaoxiang781216 why this was marked as resolved? It was not answered.



-- 
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


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #6944: boards/stm32h7: add support for mcuboot

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #6944:
URL: https://github.com/apache/incubator-nuttx/pull/6944#discussion_r972575174


##########
boards/arm/stm32h7/nucleo-h743zi/src/stm32_boot_image.c:
##########
@@ -0,0 +1,186 @@
+/****************************************************************************
+ * boards/arm/stm32h7/nucleo-h743zi/src/stm32_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);
+#ifdef CONFIG_ARMV7M_SYSTICK
+static void systick_disable(void);
+#endif

Review Comment:
   Fix here https://github.com/apache/incubator-nuttx/pull/7107



-- 
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


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #6944: boards/stm32h7: add support for mcuboot

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #6944:
URL: https://github.com/apache/incubator-nuttx/pull/6944#discussion_r962419646


##########
boards/arm/stm32h7/nucleo-h743zi/src/stm32_progmem.c:
##########
@@ -0,0 +1,265 @@
+/****************************************************************************
+ * boards/arm/stm32h7/nucleo-h743zi/src/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]))
+
+#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_STM32_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_STM32_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_STM32_PROGMEM_OTA_PARTITION)
+static const struct ota_partition_s g_ota_partition_table[] =
+{
+  {
+    .offset  = CONFIG_STM32_OTA_PRIMARY_SLOT_OFFSET,
+    .size    = CONFIG_STM32_OTA_SLOT_SIZE,
+    .devpath = CONFIG_STM32_OTA_PRIMARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_STM32_OTA_SECONDARY_SLOT_OFFSET,
+    .size    = CONFIG_STM32_OTA_SLOT_SIZE,
+    .devpath = CONFIG_STM32_OTA_SECONDARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_STM32_OTA_SCRATCH_OFFSET,
+    .size    = CONFIG_STM32_OTA_SCRATCH_SIZE,
+    .devpath = CONFIG_STM32_OTA_SCRATCH_DEVPATH
+  }
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if defined(CONFIG_STM32_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 % 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_STM32_PROGMEM_OTA_PARTITION */
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_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 stm32_progmem_init(void)
+{
+  struct mtd_geometry_s geo;
+  int ret = 0;
+
+  g_progmem_mtd = progmem_initialize();
+  if (g_progmem_mtd == NULL)
+    {
+      ferr("ERROR: Failed to get progmem flash MTD\n");
+      ret = -EIO;
+    }
+
+  ret = MTD_IOCTL(g_progmem_mtd, MTDIOC_GEOMETRY, (unsigned long)&geo);

Review Comment:
   remove?



-- 
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