From 7c116efe05f9a297762f76ae2afcff5010caeacc Mon Sep 17 00:00:00 2001 From: Ville Juven Date: Tue, 28 Dec 2021 13:00:15 +0200 Subject: [PATCH] Add support for a ROMFS image for MPFS The image must be placed into: boards/risc-v/mpfs/icicle/include/boot_romfsimg.h The image is mounted by mpfs_bringup, which is run by the application itself, or by board_late_initialize() in the case when CONFIG_BOARD_LATE_INITIALIZE is defined, e.g. with CONFIG_BUILD_KERNEL --- arch/risc-v/src/mpfs/Kconfig | 8 +++++ boards/risc-v/mpfs/common/src/mpfs_boot.c | 24 ++++++++++++++ boards/risc-v/mpfs/icicle/src/mpfs_bringup.c | 33 ++++++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/arch/risc-v/src/mpfs/Kconfig b/arch/risc-v/src/mpfs/Kconfig index 3c03635a09..a4cd8a6c3a 100755 --- a/arch/risc-v/src/mpfs/Kconfig +++ b/arch/risc-v/src/mpfs/Kconfig @@ -137,6 +137,14 @@ config MPFS_EMMCSD_MUX_GPIO ---help--- External mux GPIO between e.MMC and SD-card +config MPFS_ROMFS_MOUNT + bool "Mount the ROMFS file system" + depends on FS_ROMFS + default n + ---help--- + Mount a ROMFS image to /bin mount point. The image must be placed into + + menu "MPFS Peripheral Support" # These "hidden" settings determine whether a peripheral option is available diff --git a/boards/risc-v/mpfs/common/src/mpfs_boot.c b/boards/risc-v/mpfs/common/src/mpfs_boot.c index 19ccaa4b91..2a8ab7e3ac 100755 --- a/boards/risc-v/mpfs/common/src/mpfs_boot.c +++ b/boards/risc-v/mpfs/common/src/mpfs_boot.c @@ -29,6 +29,8 @@ #include #include +#include "board_config.h" + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -56,3 +58,25 @@ void mpfs_boardinitialize(void) { board_autoled_initialize(); } + +/**************************************************************************** + * Name: board_late_initialize + * + * Description: + * If CONFIG_BOARD_LATE_INITIALIZE is selected, then an additional + * initialization call will be performed in the boot-up sequence to a + * function called board_late_initialize(). board_late_initialize() will be + * called immediately after up_initialize() is called and just before the + * initial application is started. This additional initialization phase + * may be used, for example, to initialize board-specific device drivers. + * + ****************************************************************************/ + +#ifdef CONFIG_BOARD_LATE_INITIALIZE +void board_late_initialize(void) +{ + /* Perform board initialization */ + + mpfs_bringup(); +} +#endif /* CONFIG_BOARD_LATE_INITIALIZE */ diff --git a/boards/risc-v/mpfs/icicle/src/mpfs_bringup.c b/boards/risc-v/mpfs/icicle/src/mpfs_bringup.c index 292e584848..940fa72500 100755 --- a/boards/risc-v/mpfs/icicle/src/mpfs_bringup.c +++ b/boards/risc-v/mpfs/icicle/src/mpfs_bringup.c @@ -33,10 +33,23 @@ #include #include +#ifdef CONFIG_MPFS_ROMFS_MOUNT +# include +#endif + #include "board_config.h" #include "mpfs_corepwm.h" #include "mpfs.h" +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifdef CONFIG_MPFS_ROMFS_MOUNT +# define SECTORSIZE 512 +# define NSECTORS(b) (((b) + SECTORSIZE - 1) / SECTORSIZE) +#endif /* CONFIG_MPFS_ROMFS_MOUNT */ + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -70,6 +83,26 @@ int mpfs_bringup(void) } #endif +#ifdef CONFIG_MPFS_ROMFS_MOUNT + /* Create a ROM disk for the /bin filesystem */ + + ret = romdisk_register(0, romfs_img, NSECTORS(romfs_img_len), SECTORSIZE); + if (ret < 0) + { + serr("ERROR: Failed to register romdisk: %d\n", -ret); + } + else + { + /* Mount the file system */ + + ret = mount("/dev/ram0", "/bin", "romfs", MS_RDONLY, NULL); + if (ret < 0) + { + serr("ERROR: Failed to mount romfs: %d\n", -ret); + } + } +#endif /* CONFIG_MPFS_ROMFS_MOUNT */ + #if defined(CONFIG_MPFS_SPI0) || defined(CONFIG_MPFS_SPI1) /* Configure SPI peripheral interfaces */