You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/10/05 16:45:04 UTC

[incubator-nuttx] branch master updated: nucleo-f446re: add romfs support

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 2c722883bc nucleo-f446re: add romfs support
2c722883bc is described below

commit 2c722883bc01d8b10a00c13fd2d13a70817e8eb7
Author: raiden00pl <ra...@railab.me>
AuthorDate: Tue Oct 4 21:04:48 2022 +0200

    nucleo-f446re: add romfs support
---
 boards/arm/stm32/nucleo-f446re/Kconfig             |  22 ++++
 boards/arm/stm32/nucleo-f446re/src/Make.defs       |   4 +
 boards/arm/stm32/nucleo-f446re/src/stm32_bringup.c |  11 +-
 boards/arm/stm32/nucleo-f446re/src/stm32_romfs.h   |  61 +++++++++
 .../nucleo-f446re/src/stm32_romfs_initialize.c     | 139 +++++++++++++++++++++
 5 files changed, 236 insertions(+), 1 deletion(-)

diff --git a/boards/arm/stm32/nucleo-f446re/Kconfig b/boards/arm/stm32/nucleo-f446re/Kconfig
index 35d135fc34..d9e8875f07 100644
--- a/boards/arm/stm32/nucleo-f446re/Kconfig
+++ b/boards/arm/stm32/nucleo-f446re/Kconfig
@@ -31,4 +31,26 @@ config NUCLEO_F446RE_AJOY_MINBUTTONS
 		minimal set:  SELECT (joystick down), FIRE (BUTTON B), and JUMP
 		(BUTTON A).
 
+config STM32_ROMFS
+	bool "Automount baked-in ROMFS image"
+	default n
+	depends on FS_ROMFS
+	---help---
+		Select STM32_ROMFS_IMAGEFILE, STM32_ROMFS_DEV_MINOR, STM32_ROMFS_MOUNTPOINT
+
+config STM32_ROMFS_DEV_MINOR
+	int "Minor for the block device backing the data"
+	depends on STM32_ROMFS
+	default 64
+
+config STM32_ROMFS_MOUNTPOINT
+	string "Mountpoint of the custom romfs image"
+	depends on STM32_ROMFS
+	default "/rom"
+
+config STM32_ROMFS_IMAGEFILE
+	string "ROMFS image file to include into build"
+	depends on STM32_ROMFS
+	default "../../../rom.img"
+
 endif # ARCH_BOARD_NUCLEO_F446RE
diff --git a/boards/arm/stm32/nucleo-f446re/src/Make.defs b/boards/arm/stm32/nucleo-f446re/src/Make.defs
index 24ebb472c6..4e25c7a0d3 100644
--- a/boards/arm/stm32/nucleo-f446re/src/Make.defs
+++ b/boards/arm/stm32/nucleo-f446re/src/Make.defs
@@ -74,6 +74,10 @@ ifeq ($(CONFIG_BOARD_STM32_IHM08M1),y)
 CSRCS += stm32_foc_ihm08m1.c
 endif
 
+ifeq ($(CONFIG_STM32_ROMFS),y)
+CSRCS += stm32_romfs_initialize.c
+endif
+
 DEPPATH += --dep-path board
 VPATH += :board
 CFLAGS += $(shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board)
diff --git a/boards/arm/stm32/nucleo-f446re/src/stm32_bringup.c b/boards/arm/stm32/nucleo-f446re/src/stm32_bringup.c
index ddc42baeda..a576b72995 100644
--- a/boards/arm/stm32/nucleo-f446re/src/stm32_bringup.c
+++ b/boards/arm/stm32/nucleo-f446re/src/stm32_bringup.c
@@ -35,7 +35,7 @@
 #include <nuttx/mmcsd.h>
 
 #include <stm32.h>
-#include <stm32_uart.h>
+#include <stm32_romfs.h>
 
 #include <arch/board/board.h>
 
@@ -90,6 +90,15 @@ int stm32_bringup(void)
     }
 #endif /* CONFIG_FS_PROCFS */
 
+#ifdef CONFIG_STM32_ROMFS
+  ret = stm32_romfs_initialize();
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: Failed to mount romfs at %s: %d\n",
+             CONFIG_STM32_ROMFS_MOUNTPOINT, ret);
+    }
+#endif
+
 #ifdef CONFIG_INPUT_BUTTONS
   /* Register the BUTTON driver */
 
diff --git a/boards/arm/stm32/nucleo-f446re/src/stm32_romfs.h b/boards/arm/stm32/nucleo-f446re/src/stm32_romfs.h
new file mode 100644
index 0000000000..1d4a23c5f0
--- /dev/null
+++ b/boards/arm/stm32/nucleo-f446re/src/stm32_romfs.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+ * boards/arm/stm32/nucleo-f446re/src/stm32_romfs.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __BOARDS_ARM_STM32_NUCLEO_F446RE_SRC_STM32_ROMFS_H
+#define __BOARDS_ARM_STM32_NUCLEO_F446RE_SRC_STM32_ROMFS_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#ifdef CONFIG_STM32_ROMFS
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ROMFS_SECTOR_SIZE 64
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_romfs_initialize
+ *
+ * Description:
+ *   Registers built-in ROMFS image as block device and mounts it.
+ *
+ * Returned Value:
+ *   Zero (OK) on success, a negated errno value on error.
+ *
+ * Assumptions/Limitations:
+ *   Memory addresses [romfs_data_begin .. romfs_data_begin) should contain
+ *   ROMFS volume data, as included in the assembly snippet above (l. 84).
+ *
+ ****************************************************************************/
+
+int stm32_romfs_initialize(void);
+
+#endif /* CONFIG_STM32_ROMFS */
+
+#endif /* __BOARDS_ARM_STM32_NUCLEO_F446RE_SRC_STM32_ROMFS_H */
diff --git a/boards/arm/stm32/nucleo-f446re/src/stm32_romfs_initialize.c b/boards/arm/stm32/nucleo-f446re/src/stm32_romfs_initialize.c
new file mode 100644
index 0000000000..d60b9f7266
--- /dev/null
+++ b/boards/arm/stm32/nucleo-f446re/src/stm32_romfs_initialize.c
@@ -0,0 +1,139 @@
+/****************************************************************************
+ * boards/arm/stm32/nucleo-f446re/src/stm32_romfs_initialize.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.
+ *
+ ****************************************************************************/
+
+/* This file provides contents of an optional ROMFS volume, mounted at boot */
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/mount.h>
+#include <sys/types.h>
+#include <stdint.h>
+#include <debug.h>
+#include <errno.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/drivers/ramdisk.h>
+#include "stm32_romfs.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifndef CONFIG_STM32_ROMFS
+#  error "CONFIG_STM32_ROMFS must be defined"
+#else
+
+#ifndef CONFIG_STM32_ROMFS_IMAGEFILE
+#  error "CONFIG_STM32_ROMFS_IMAGEFILE must be defined"
+#endif
+
+#ifndef CONFIG_STM32_ROMFS_DEV_MINOR
+#  error "CONFIG_STM32_ROMFS_DEV_MINOR must be defined"
+#endif
+
+#ifndef CONFIG_STM32_ROMFS_MOUNTPOINT
+#  error "CONFIG_STM32_ROMFS_MOUNTPOINT must be defined"
+#endif
+
+#define NSECTORS(size) (((size) + ROMFS_SECTOR_SIZE - 1)/ROMFS_SECTOR_SIZE)
+
+#define STR2(m)  #m
+#define STR(m) STR2(m)
+
+#define MKMOUNT_DEVNAME(m) "/dev/ram" STR(m)
+#define MOUNT_DEVNAME      MKMOUNT_DEVNAME(CONFIG_STM32_ROMFS_DEV_MINOR)
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+__asm__ (
+  "   .section .rodata                            \n"
+  "   .balign  16                                 \n"
+  "   .globl   romfs_data_begin                   \n"
+  "romfs_data_begin:                              \n"
+  "   .incbin " STR(CONFIG_STM32_ROMFS_IMAGEFILE)"\n"
+  "   .balign " STR(ROMFS_SECTOR_SIZE)           "\n"
+  "   .globl   romfs_data_end                     \n"
+  "romfs_data_end:                                \n"
+  );
+
+extern const uint8_t romfs_data_begin[];
+extern const uint8_t romfs_data_end[];
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_romfs_initialize
+ *
+ * Description:
+ *   Registers the aboveincluded binary file as block device.
+ *   Then mounts the block device as ROMFS filesystems.
+ *
+ * Returned Value:
+ *   Zero (OK) on success, a negated errno value on error.
+ *
+ * Assumptions/Limitations:
+ *   Memory addresses [&romfs_data_begin .. &romfs_data_begin) should contain
+ *   ROMFS volume data, as included in the assembly snippet above (l. 84).
+ *
+ ****************************************************************************/
+
+int stm32_romfs_initialize(void)
+{
+  uintptr_t romfs_data_len;
+  int  ret;
+
+  /* Create a ROM disk for the /etc filesystem */
+
+  romfs_data_len = (uintptr_t)romfs_data_end - (uintptr_t)romfs_data_begin;
+
+  ret = romdisk_register(CONFIG_STM32_ROMFS_DEV_MINOR, romfs_data_begin,
+                         NSECTORS(romfs_data_len), ROMFS_SECTOR_SIZE);
+  if (ret < 0)
+    {
+      ferr("ERROR: romdisk_register failed: %d\n", -ret);
+      return ret;
+    }
+
+  /* Mount the file system */
+
+  finfo("Mounting ROMFS filesystem at target=%s with source=%s\n",
+        CONFIG_STM32_ROMFS_MOUNTPOINT, MOUNT_DEVNAME);
+
+  ret = nx_mount(MOUNT_DEVNAME, CONFIG_STM32_ROMFS_MOUNTPOINT,
+                 "romfs", MS_RDONLY, NULL);
+  if (ret < 0)
+    {
+      ferr("ERROR: nx_mount(%s,%s,romfs) failed: %d\n",
+           MOUNT_DEVNAME, CONFIG_STM32_ROMFS_MOUNTPOINT, ret);
+      return ret;
+    }
+
+  return OK;
+}
+
+#endif /* CONFIG_STM32_ROMFS */