Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TODO: Add Initial RAM Disk to Star64 JH7110 RISC-V SBC #34

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ uImage
.vscode
.DS_Store
tools/gdb/__pycache__
initrd
init.S
16 changes: 16 additions & 0 deletions arch/risc-v/src/qemu-rv/qemu_rv_mm_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
14 changes: 7 additions & 7 deletions boards/risc-v/qemu-rv/rv-virt/configs/knsh64/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
13 changes: 12 additions & 1 deletion boards/risc-v/qemu-rv/rv-virt/scripts/ld-kernel64.script
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
{
Expand Down
99 changes: 99 additions & 0 deletions boards/risc-v/qemu-rv/rv-virt/src/qemu_rv_appinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <stdio.h>
#include <syslog.h>
#include <errno.h>
#include <debug.h> ////

#include <nuttx/board.h>

Expand Down Expand Up @@ -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 <arch/board/board_memorymap.h>
#include <nuttx/drivers/ramdisk.h>
#include <sys/boardctl.h>

#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;
}
8 changes: 8 additions & 0 deletions fs/hostfs/hostfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions fs/romfs/fs_romfsutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Loading