diff --git a/.gitignore b/.gitignore index 95dc6e19b522a..25c517718d094 100644 --- a/.gitignore +++ b/.gitignore @@ -60,3 +60,5 @@ uImage .vscode .DS_Store tools/gdb/__pycache__ +initrd +init.S diff --git a/arch/risc-v/src/qemu-rv/qemu_rv_mm_init.c b/arch/risc-v/src/qemu-rv/qemu_rv_mm_init.c index 4345e79a0a6ca..90b9c21b3d89b 100644 --- a/arch/risc-v/src/qemu-rv/qemu_rv_mm_init.c +++ b/arch/risc-v/src/qemu-rv/qemu_rv_mm_init.c @@ -269,6 +269,22 @@ void qemu_rv_kernel_mappings(void) binfo("map kernel data\n"); map_region(KSRAM_START, KSRAM_START, KSRAM_SIZE, MMU_KDATA_FLAGS); + // Added RAM Disk + //// From nuttx/boards/risc-v/litex/arty_a7/include/board_memorymap.h + /* ramdisk (RW) */ + extern uint8_t __ramdisk_start[]; + extern uint8_t __ramdisk_size[]; + // Copy 0x46100000 to __ramdisk_start (__ramdisk_size bytes) + // TODO: RAM Disk must not exceed __ramdisk_size bytes + memcpy((void *)__ramdisk_start, (void *)0x46100000, (size_t)__ramdisk_size); + +#ifdef NOTUSED + /* Added RAM Disk */ + _info("map RAM Disk\n"); + map_region((uintptr_t)__ramdisk_start, (uintptr_t)__ramdisk_start, (uintptr_t)__ramdisk_size, MMU_KDATA_FLAGS); + _info("map RAM Disk done\n"); +#endif // NOTUSED + #ifdef CONFIG_ARCH_MMU_TYPE_SV39 /* Connect the L1 and L2 page tables for the kernel text and data */ diff --git a/boards/risc-v/qemu-rv/rv-virt/configs/knsh64/defconfig b/boards/risc-v/qemu-rv/rv-virt/configs/knsh64/defconfig index 837793fb48bcf..46fedf0af9056 100644 --- a/boards/risc-v/qemu-rv/rv-virt/configs/knsh64/defconfig +++ b/boards/risc-v/qemu-rv/rv-virt/configs/knsh64/defconfig @@ -42,16 +42,20 @@ CONFIG_ARCH_TEXT_VBASE=0xC0000000 CONFIG_ARCH_USE_MMU=y CONFIG_ARCH_USE_MPU=y CONFIG_ARCH_USE_S_MODE=y +CONFIG_BOARDCTL_ROMDISK=y +CONFIG_BOARD_LATE_INITIALIZE=y CONFIG_BOARD_LOOPSPERMSEC=6366 CONFIG_BUILD_KERNEL=y CONFIG_DEBUG_ASSERTIONS=y CONFIG_DEBUG_ASSERTIONS_EXPRESSION=y CONFIG_DEBUG_BINFMT=y CONFIG_DEBUG_BINFMT_ERROR=y -CONFIG_DEBUG_BINFMT_INFO=y CONFIG_DEBUG_BINFMT_WARN=y CONFIG_DEBUG_ERROR=y CONFIG_DEBUG_FEATURES=y +CONFIG_DEBUG_FS=y +CONFIG_DEBUG_FS_ERROR=y +CONFIG_DEBUG_FS_WARN=y CONFIG_DEBUG_FULLOPT=y CONFIG_DEBUG_INFO=y CONFIG_DEBUG_SCHED=y @@ -63,16 +67,13 @@ CONFIG_DEBUG_WARN=y CONFIG_DEV_ZERO=y CONFIG_ELF=y CONFIG_EXAMPLES_HELLO=m -CONFIG_FS_HOSTFS=y CONFIG_FS_PROCFS=y +CONFIG_FS_ROMFS=y CONFIG_IDLETHREAD_STACKSIZE=3072 CONFIG_INIT_FILEPATH="/system/bin/init" CONFIG_INIT_MOUNT=y -CONFIG_INIT_MOUNT_DATA="fs=../apps" CONFIG_INIT_MOUNT_FLAGS=0x1 -CONFIG_INIT_MOUNT_FSTYPE="hostfs" -CONFIG_INIT_MOUNT_SOURCE="" -CONFIG_INIT_MOUNT_TARGET="/system" +CONFIG_INIT_MOUNT_TARGET="/system/bin" CONFIG_INIT_STACKSIZE=3072 CONFIG_INTELHEX_BINARY=y CONFIG_LIBC_ENVPATH=y @@ -91,7 +92,6 @@ CONFIG_PATH_INITIAL="/system/bin" CONFIG_RAM_SIZE=1048576 CONFIG_RAM_START=0x40200000 CONFIG_READLINE_CMD_HISTORY=y -CONFIG_RISCV_SEMIHOSTING_HOSTFS=y CONFIG_RR_INTERVAL=200 CONFIG_SCHED_LPWORK=y CONFIG_SCHED_WAITPID=y diff --git a/boards/risc-v/qemu-rv/rv-virt/scripts/ld-kernel64.script b/boards/risc-v/qemu-rv/rv-virt/scripts/ld-kernel64.script index d4ec5ef1320db..96ac2abdb3f4d 100644 --- a/boards/risc-v/qemu-rv/rv-virt/scripts/ld-kernel64.script +++ b/boards/risc-v/qemu-rv/rv-virt/scripts/ld-kernel64.script @@ -26,6 +26,8 @@ MEMORY ksram (rwx) : ORIGIN = 0x40400000, LENGTH = 2048K /* w/ cache */ /* Previously 0x80400000 */ pgram (rwx) : ORIGIN = 0x40600000, LENGTH = 4096K /* w/ cache */ + /* Added RAM Disk */ + ramdisk (rwx) : ORIGIN = 0x40A00000, LENGTH = 16M /* w/ cache */ } OUTPUT_ARCH("riscv") @@ -38,10 +40,19 @@ __ksram_start = ORIGIN(ksram); __ksram_size = LENGTH(ksram); __ksram_end = ORIGIN(ksram) + LENGTH(ksram); +/* Added RAM Disk */ /* Page heap */ __pgheap_start = ORIGIN(pgram); -__pgheap_size = LENGTH(pgram); +__pgheap_size = LENGTH(pgram) + LENGTH(ramdisk); +/* Previously: __pgheap_size = LENGTH(pgram); */ + +/* Added RAM Disk */ +/* Application ramdisk */ + +__ramdisk_start = ORIGIN(ramdisk); +__ramdisk_size = LENGTH(ramdisk); +__ramdisk_end = ORIGIN(ramdisk) + LENGTH(ramdisk); SECTIONS { diff --git a/boards/risc-v/qemu-rv/rv-virt/src/qemu_rv_appinit.c b/boards/risc-v/qemu-rv/rv-virt/src/qemu_rv_appinit.c index ffb00398ceb7e..3b3cec28e827f 100644 --- a/boards/risc-v/qemu-rv/rv-virt/src/qemu_rv_appinit.c +++ b/boards/risc-v/qemu-rv/rv-virt/src/qemu_rv_appinit.c @@ -28,6 +28,7 @@ #include #include #include +#include //// #include @@ -78,3 +79,101 @@ int board_app_initialize(uintptr_t arg) return OK; #endif } + +//// Added RAM Disk +//// From nuttx/boards/risc-v/litex/arty_a7/src/litex_appinit.c + +int mount_ramdisk(void); + +/**************************************************************************** + * 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 after up_initialize() and board_early_initialize() and just + * before the initial application is started. This additional + * initialization phase may be used, for example, to initialize board- + * specific device drivers for which board_early_initialize() is not + * suitable. + * + * Waiting for events, use of I2C, SPI, etc are permissible in the context + * of board_late_initialize(). That is because board_late_initialize() + * will run on a temporary, internal kernel thread. + * + ****************************************************************************/ + +void board_late_initialize(void) +{ + _info("\n");//// + + // Mount the RAM Disk + mount_ramdisk(); + + /* Perform board-specific initialization */ + +#ifdef CONFIG_NSH_ARCHINIT + + mount(NULL, "/proc", "procfs", 0, NULL); + +#endif +} + +//// From nuttx/boards/risc-v/litex/arty_a7/include/board_memorymap.h + +/* ramdisk (RW) */ +extern uint8_t __ramdisk_start[]; +extern uint8_t __ramdisk_size[]; + +//// From nuttx/boards/risc-v/litex/arty_a7/src/litex_ramdisk.c + +#include +#include +#include + +#ifndef CONFIG_BUILD_KERNEL +#error "Ramdisk usage is intended to be used with kernel build only" +#endif + +#define SECTORSIZE 512 +#define NSECTORS(b) (((b) + SECTORSIZE - 1) / SECTORSIZE) +#define RAMDISK_DEVICE_MINOR 0 + +/**************************************************************************** + * Name: litex_mount_ramdisk + * + * Description: + * Mount a ramdisk defined in the ld-kernel.script to /dev/ramX. + * The ramdisk is intended to contain a romfs with applications which can + * be spawned at runtime. + * + * Returned Value: + * OK is returned on success. + * -ERRORNO is returned on failure. + * + ****************************************************************************/ + +int mount_ramdisk(void) +{ + int ret; + struct boardioc_romdisk_s desc; + + desc.minor = RAMDISK_DEVICE_MINOR; + desc.nsectors = NSECTORS((ssize_t)__ramdisk_size); + desc.sectsize = SECTORSIZE; + desc.image = __ramdisk_start; + + ret = boardctl(BOARDIOC_ROMDISK, (uintptr_t)&desc); + if (ret < 0) + { + syslog(LOG_ERR, "Ramdisk register failed: %s\n", strerror(errno)); + syslog(LOG_ERR, "Ramdisk mountpoint /dev/ram%d\n", + RAMDISK_DEVICE_MINOR); + syslog(LOG_ERR, "Ramdisk length %lu, origin %lx\n", + (ssize_t)__ramdisk_size, + (uintptr_t)__ramdisk_start); + } + + return ret; +} diff --git a/fs/hostfs/hostfs.c b/fs/hostfs/hostfs.c index 43da3eb4a24b0..aaadbd3705bd8 100644 --- a/fs/hostfs/hostfs.c +++ b/fs/hostfs/hostfs.c @@ -239,6 +239,7 @@ static void hostfs_mkpath(FAR struct hostfs_mountpt_s *fs, static int hostfs_open(FAR struct file *filep, FAR const char *relpath, int oflags, mode_t mode) { + _info("relpath=%s, oflags=0x%x, mode=0x%x\n", relpath, oflags, mode);//// FAR struct inode *inode; FAR struct hostfs_mountpt_s *fs; FAR struct hostfs_ofile_s *hf; @@ -824,6 +825,7 @@ static int hostfs_ftruncate(FAR struct file *filep, off_t length) static int hostfs_opendir(FAR struct inode *mountpt, FAR const char *relpath, FAR struct fs_dirent_s **dir) { + _info("relpath=%s\n", relpath);//// FAR struct hostfs_mountpt_s *fs; FAR struct hostfs_dir_s *hdir; char path[HOSTFS_MAX_PATH]; @@ -1177,6 +1179,7 @@ static int hostfs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf) static int hostfs_unlink(FAR struct inode *mountpt, FAR const char *relpath) { + _info("relpath=%s\n", relpath);//// FAR struct hostfs_mountpt_s *fs; char path[HOSTFS_MAX_PATH]; int ret; @@ -1217,6 +1220,7 @@ static int hostfs_unlink(FAR struct inode *mountpt, FAR const char *relpath) static int hostfs_mkdir(FAR struct inode *mountpt, FAR const char *relpath, mode_t mode) { + _info("relpath=%s, mode=0x%x\n", relpath, mode);//// FAR struct hostfs_mountpt_s *fs; char path[HOSTFS_MAX_PATH]; int ret; @@ -1256,6 +1260,7 @@ static int hostfs_mkdir(FAR struct inode *mountpt, FAR const char *relpath, int hostfs_rmdir(FAR struct inode *mountpt, FAR const char *relpath) { + _info("relpath=%s\n", relpath);//// FAR struct hostfs_mountpt_s *fs; char path[HOSTFS_MAX_PATH]; int ret; @@ -1298,6 +1303,7 @@ int hostfs_rmdir(FAR struct inode *mountpt, FAR const char *relpath) int hostfs_rename(FAR struct inode *mountpt, FAR const char *oldrelpath, FAR const char *newrelpath) { + _info("oldrelpath=%s, newrelpath=%s\n", oldrelpath, newrelpath);//// FAR struct hostfs_mountpt_s *fs; char oldpath[HOSTFS_MAX_PATH]; char newpath[HOSTFS_MAX_PATH]; @@ -1342,6 +1348,7 @@ int hostfs_rename(FAR struct inode *mountpt, FAR const char *oldrelpath, static int hostfs_stat(FAR struct inode *mountpt, FAR const char *relpath, FAR struct stat *buf) { + _info("relpath=%s\n", relpath);//// FAR struct hostfs_mountpt_s *fs; char path[HOSTFS_MAX_PATH]; int ret; @@ -1382,6 +1389,7 @@ static int hostfs_stat(FAR struct inode *mountpt, FAR const char *relpath, static int hostfs_chstat(FAR struct inode *mountpt, FAR const char *relpath, FAR const struct stat *buf, int flags) { + _info("relpath=%s\n", relpath);//// FAR struct hostfs_mountpt_s *fs; char path[HOSTFS_MAX_PATH]; int ret; diff --git a/fs/romfs/fs_romfsutil.c b/fs/romfs/fs_romfsutil.c index 8e6127dbf43e3..e4a12132c08c6 100644 --- a/fs/romfs/fs_romfsutil.c +++ b/fs/romfs/fs_romfsutil.c @@ -76,6 +76,13 @@ struct romfs_entryname_s static uint32_t romfs_devread32(FAR struct romfs_mountpt_s *rm, int ndx) { + //// Stop if RAM Disk Memory is too small + extern uint8_t __ramdisk_start[]; //// + extern uint8_t __ramdisk_size[]; //// + if (&rm->rm_buffer[ndx] > __ramdisk_start + (size_t)__ramdisk_size) + { _err("RAM Disk Memory too smol! Expecting %p, got %p\n", __ramdisk_start + (size_t)__ramdisk_size, &rm->rm_buffer[ndx]); }; + DEBUGASSERT(&rm->rm_buffer[ndx] < __ramdisk_start + (size_t)__ramdisk_size); //// + /* This should not read past the end of the sector since the directory * entries are aligned at 16-byte boundaries. */