mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 08:36:24 +08:00
sched: move etc romfs mount from nsh to sched/init
Usually the startup script is placed under /etc. The contents of the etc directory are compiled and linked with Nuttx binary in the form of romfs. After startup, it will be mounted by Nsh. etc is generated by the different boards, that use genromfs and xxd tools to generate and compile it into the Nuttx, for example: boards/arm/at32/at32f437-mini/tool/mkromfs.sh The more common method is etc image generated from the content in the corresponding board/arch/board/board/src/etc directory, and added by Makefile for example: boards/sim/sim/sim/src/etc. But in kernel/protected mode, Nuttx kernel and apps are run in different privileged/ non-privileged mode or the isolated binarys, so as that nsh should use syscall to access Nuttx kernel by exported API. In this scenario, nsh can not mount the etc image content, because that is generated in board and as a part of Nuttx kernel. changes: - move etc romfs mount from nsh to Nuttx, but keep the script to parse and execute. - move and rename the related CONFIG, move customized nsh_romfsimg.h to etc_romfs.c in boards, and no need declaration for romfs_img/romfs_img_len. This commit changes and updates all configurations in Nuttx arch/board as much as possible, but if any missing, please refer to the following simple guide: - rename CONFIG_NSH_ROMFSETC to CONFIG_ETC_ROMFS, and delete CONFIG_NSH_ARCHROMFS in defconfig - rename the etc romfs mount configs, for example CONFIG_NSH_FATDEVNO to CONFIG_ETC_FATDEVNO - move customized nsh_romfsimg.h to etc_romfs.c in board/arch/board/board/src and no need declaration for romfs_img/romfs_img_len. - delete default nsh_romfsimg.h, if ROMFSETC is enabled, should generate and compile etc_romfs.c in board/arch/board/board/src. Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
This commit is contained in:
committed by
Alan Carvalho de Assis
parent
62698051c7
commit
c479ccb8aa
@@ -528,6 +528,86 @@ config INIT_MOUNT_DATA
|
||||
endif # INIT_MOUNT
|
||||
endif # INIT_FILE
|
||||
|
||||
menuconfig ETC_ROMFS
|
||||
bool "Auto-mount etc baked-in ROMFS image"
|
||||
default n
|
||||
depends on !DISABLE_MOUNTPOINT && FS_ROMFS
|
||||
---help---
|
||||
Mount a ROMFS filesystem at /etc and provide a system init
|
||||
script at /etc/init.d/rc.sysinit and a startup script
|
||||
at /etc/init.d/rcS. The default system init script will mount
|
||||
a FAT FS RAMDISK at /tmp but the logic is easily extensible.
|
||||
|
||||
if ETC_ROMFS
|
||||
|
||||
config ETC_CROMFS
|
||||
bool "Support CROMFS (compressed) start-up script"
|
||||
default n
|
||||
depends on FS_CROMFS
|
||||
---help---
|
||||
Mount a CROMFS filesystem at /etc and provide a compressed system
|
||||
init script at /etc/init.d/rc.sysinit and a startup script
|
||||
at /etc/init.d/rcS.
|
||||
|
||||
config ETC_ROMFSMOUNTPT
|
||||
string "Mountpoint of the etc romfs image"
|
||||
default "/etc"
|
||||
|
||||
config ETC_ROMFSDEVNO
|
||||
int "ROMFS block device minor number"
|
||||
default 0
|
||||
---help---
|
||||
This is the minor number of the ROMFS block device. The default is
|
||||
'0' corresponding to /dev/ram0.
|
||||
|
||||
config ETC_ROMFSSECTSIZE
|
||||
int "ROMFS sector size"
|
||||
default 64
|
||||
---help---
|
||||
This is the sector size to use with the ROMFS volume. Since the
|
||||
default volume is very small, this defaults to 64 but should be
|
||||
increased if the ROMFS volume were to be become large. Any value
|
||||
selected must be a power of 2.
|
||||
|
||||
config ETC_FATDEVNO
|
||||
int "FAT block device minor number"
|
||||
default 1
|
||||
depends on FS_FAT
|
||||
---help---
|
||||
When the default rcS file used when ETC_ROMFS is selected, it
|
||||
will mount a FAT FS under /tmp. This is the minor number of the FAT
|
||||
FS block device. The default is '1' corresponding to /dev/ram1.
|
||||
|
||||
config ETC_FATSECTSIZE
|
||||
int "FAT sector size"
|
||||
default 512
|
||||
depends on FS_FAT
|
||||
---help---
|
||||
When the default rcS file used when ETC_ROMFS is selected, it
|
||||
will mount a FAT FS under /tmp. This is the sector size use with the
|
||||
FAT FS. Default is 512.
|
||||
|
||||
config ETC_FATNSECTORS
|
||||
int "FAT number of sectors"
|
||||
default 1024
|
||||
depends on FS_FAT
|
||||
---help---
|
||||
When the default rcS file used when ETC_ROMFS is selected, it
|
||||
will mount a FAT FS under /tmp. This is the number of sectors to use
|
||||
with the FAT FS. Default is 1024. The amount of memory used by the
|
||||
FAT FS will be ETC_FATSECTSIZE * ETC_FATNSECTORS bytes.
|
||||
|
||||
config ETC_FATMOUNTPT
|
||||
string "FAT mount point"
|
||||
default "/tmp"
|
||||
depends on FS_FAT
|
||||
---help---
|
||||
When the default rcS file used when ETC_ROMFS is selected, it
|
||||
will mount a FAT FS under /tmp. This is the location where the FAT
|
||||
FS will be mounted. Default is "/tmp".
|
||||
|
||||
endif # ETC_ROMFS
|
||||
|
||||
config RR_INTERVAL
|
||||
int "Round robin timeslice (MSEC)"
|
||||
default 0
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <nuttx/board.h>
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/init.h>
|
||||
#include <nuttx/nuttx.h>
|
||||
#include <nuttx/symtab.h>
|
||||
#include <nuttx/trace.h>
|
||||
#include <nuttx/wqueue.h>
|
||||
@@ -50,6 +51,11 @@
|
||||
#include "init/init.h"
|
||||
#include "misc/coredump.h"
|
||||
|
||||
#ifdef CONFIG_ETC_ROMFS
|
||||
# include <nuttx/drivers/ramdisk.h>
|
||||
# include <sys/mount.h>
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
@@ -116,6 +122,15 @@ extern const int CONFIG_INIT_NEXPORTS;
|
||||
# define CONFIG_INIT_PRIORITY SCHED_PRIORITY_DEFAULT
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ETC_ROMFS
|
||||
# define NSECTORS(b) (((b)+CONFIG_ETC_ROMFSSECTSIZE-1)/CONFIG_ETC_ROMFSSECTSIZE)
|
||||
# define MKMOUNT_DEVNAME(m) "/dev/ram" STRINGIFY(m)
|
||||
# define MOUNT_DEVNAME MKMOUNT_DEVNAME(CONFIG_ETC_ROMFSDEVNO)
|
||||
|
||||
extern const unsigned char romfs_img[];
|
||||
extern const unsigned int romfs_img_len;
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
@@ -211,6 +226,58 @@ static inline void nx_workqueues(void)
|
||||
|
||||
#endif /* CONFIG_SCHED_WORKQUEUE */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nx_romfsetc
|
||||
*
|
||||
* Description: mount baked-in ROMFS image to /etc.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ETC_ROMFS
|
||||
static inline void nx_romfsetc(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
#ifndef CONFIG_ETC_CROMFS
|
||||
/* Create a ROM disk for the /etc filesystem */
|
||||
|
||||
ret = romdisk_register(CONFIG_ETC_ROMFSDEVNO, romfs_img,
|
||||
NSECTORS(romfs_img_len),
|
||||
CONFIG_ETC_ROMFSSECTSIZE);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: romdisk_register failed: %d\n", -ret);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Mount the file system */
|
||||
|
||||
finfo("Mounting ROMFS filesystem at target=%s with source=%s\n",
|
||||
CONFIG_ETC_ROMFSMOUNTPT, MOUNT_DEVNAME);
|
||||
|
||||
#if defined(CONFIG_ETC_CROMFS)
|
||||
ret = nx_mount(MOUNT_DEVNAME, CONFIG_ETC_ROMFSMOUNTPT,
|
||||
"cromfs", MS_RDONLY, NULL);
|
||||
#else
|
||||
ret = nx_mount(MOUNT_DEVNAME, CONFIG_ETC_ROMFSMOUNTPT,
|
||||
"romfs", MS_RDONLY, NULL);
|
||||
#endif
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: nx_mount(%s,%s,romfs) failed: %d\n",
|
||||
MOUNT_DEVNAME, CONFIG_ETC_ROMFSMOUNTPT, ret);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CONFIG_ETC_ROMFS */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nx_start_application
|
||||
*
|
||||
@@ -241,6 +308,10 @@ static inline void nx_start_application(void)
|
||||
#endif
|
||||
int ret;
|
||||
|
||||
#ifdef CONFIG_ETC_ROMFS
|
||||
nx_romfsetc();
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BOARD_LATE_INITIALIZE
|
||||
/* Perform any last-minute, board-specific initialization, if so
|
||||
* configured.
|
||||
|
||||
Reference in New Issue
Block a user