From 0b00788b40eaadeb6427d4517233c4fbb65f8894 Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Thu, 20 Jul 2023 16:39:37 +0800 Subject: [PATCH 01/15] Add HostFS Logging --- arch/risc-v/src/common/riscv_hostfs.c | 3 +++ .../risc-v/qemu-rv/rv-virt/configs/knsh64/defconfig | 12 +++++++++++- fs/hostfs/hostfs.c | 8 ++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/arch/risc-v/src/common/riscv_hostfs.c b/arch/risc-v/src/common/riscv_hostfs.c index 10bc25855750e..47b454a1a77da 100644 --- a/arch/risc-v/src/common/riscv_hostfs.c +++ b/arch/risc-v/src/common/riscv_hostfs.c @@ -31,6 +31,7 @@ #include #include #include +#include //// /**************************************************************************** * Pre-processor Definitions @@ -52,6 +53,8 @@ static long host_call(unsigned int nbr, void *parm, size_t size) { + _info("nbr=0x%x, parm=%p, size=%ld\n", nbr, parm, size);//// + #ifdef CONFIG_RISCV_SEMIHOSTING_HOSTFS_CACHE_COHERENCE up_clean_dcache(parm, parm + size); #endif 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 5500f7d76415c..c054e12d367ad 100644 --- a/boards/risc-v/qemu-rv/rv-virt/configs/knsh64/defconfig +++ b/boards/risc-v/qemu-rv/rv-virt/configs/knsh64/defconfig @@ -44,10 +44,21 @@ CONFIG_ARCH_USE_S_MODE=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_FULLOPT=y +CONFIG_DEBUG_INFO=y +CONFIG_DEBUG_SCHED=y +CONFIG_DEBUG_SCHED_ERROR=y +CONFIG_DEBUG_SCHED_INFO=y +CONFIG_DEBUG_SCHED_WARN=y CONFIG_DEBUG_SYMBOLS=y +CONFIG_DEBUG_WARN=y CONFIG_DEV_ZERO=y CONFIG_ELF=y CONFIG_EXAMPLES_HELLO=m @@ -88,7 +99,6 @@ CONFIG_STACK_COLORATION=y CONFIG_START_MONTH=12 CONFIG_START_YEAR=2021 CONFIG_SYMTAB_ORDEREDBYNAME=y -CONFIG_SYSLOG_TIMESTAMP=y CONFIG_SYSTEM_NSH=y CONFIG_SYSTEM_NSH_PROGNAME="init" CONFIG_TESTING_GETPRIME=y 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; From 7dcc7b28710a210c9b6f9c28eeb13ce698c10020 Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Thu, 20 Jul 2023 17:15:31 +0800 Subject: [PATCH 02/15] Disable logging --- arch/risc-v/src/common/riscv_hostfs.c | 2 +- tools/Unix.mk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/risc-v/src/common/riscv_hostfs.c b/arch/risc-v/src/common/riscv_hostfs.c index 47b454a1a77da..1b48a250498e0 100644 --- a/arch/risc-v/src/common/riscv_hostfs.c +++ b/arch/risc-v/src/common/riscv_hostfs.c @@ -53,7 +53,7 @@ static long host_call(unsigned int nbr, void *parm, size_t size) { - _info("nbr=0x%x, parm=%p, size=%ld\n", nbr, parm, size);//// + //_info("nbr=0x%x, parm=%p, size=%ld\n", nbr, parm, size);//// #ifdef CONFIG_RISCV_SEMIHOSTING_HOSTFS_CACHE_COHERENCE up_clean_dcache(parm, parm + size); diff --git a/tools/Unix.mk b/tools/Unix.mk index 62f74b8c6f870..879ec7b865e6b 100644 --- a/tools/Unix.mk +++ b/tools/Unix.mk @@ -250,7 +250,7 @@ tools/mkconfig$(HOSTEXEEXT): include/nuttx/config.h: $(TOPDIR)/.config tools/mkconfig$(HOSTEXEEXT) $(Q) grep -v "CONFIG_BASE_DEFCONFIG" "$(TOPDIR)/.config" > "$(TOPDIR)/.config.tmp" $(Q) if ! cmp -s "$(TOPDIR)/.config.tmp" "$(TOPDIR)/.config.orig" ; then \ - sed -i.bak "/CONFIG_BASE_DEFCONFIG/ { /-dirty/! s/\"$$/-dirty\"/ }" "$(TOPDIR)/.config"; \ + sed -i.bak "/CONFIG_BASE_DEFCONFIG/s/\"$$/-dirty\"/" "$(TOPDIR)/.config"; \ else \ sed -i.bak "s/-dirty//g" "$(TOPDIR)/.config"; \ fi From 5d1b01fb475e428b7b93c5f45d715854458c811a Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Thu, 20 Jul 2023 18:19:59 +0800 Subject: [PATCH 03/15] Ignore initrd --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 95dc6e19b522a..095ffbeff3399 100644 --- a/.gitignore +++ b/.gitignore @@ -60,3 +60,4 @@ uImage .vscode .DS_Store tools/gdb/__pycache__ +initrd From f9636dcccb651a22980ac81cc474ffcf917d7167 Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Thu, 20 Jul 2023 19:23:59 +0800 Subject: [PATCH 04/15] Enable ROM Disk --- .../qemu-rv/rv-virt/configs/knsh64/defconfig | 12 +-- .../qemu-rv/rv-virt/src/qemu_rv_appinit.c | 99 +++++++++++++++++++ 2 files changed, 102 insertions(+), 9 deletions(-) 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 c054e12d367ad..6156ef5a3fa32 100644 --- a/boards/risc-v/qemu-rv/rv-virt/configs/knsh64/defconfig +++ b/boards/risc-v/qemu-rv/rv-virt/configs/knsh64/defconfig @@ -41,13 +41,14 @@ 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 @@ -62,16 +63,10 @@ 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_STACKSIZE=3072 CONFIG_INTELHEX_BINARY=y CONFIG_LIBC_ENVPATH=y @@ -90,7 +85,6 @@ CONFIG_PATH_INITIAL="/system/bin" CONFIG_RAM_SIZE=1048576 CONFIG_RAM_START=0x80100000 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/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; +} From 0dc5b9891a62e44e4e0fd8e6ee30bb6e857e4f96 Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Thu, 20 Jul 2023 19:42:11 +0800 Subject: [PATCH 05/15] Add RAM Disk to Linker Script --- boards/risc-v/qemu-rv/rv-virt/scripts/ld-kernel64.script | 9 +++++++++ 1 file changed, 9 insertions(+) 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 bfab060ee6845..6151a8b4505f5 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 @@ -23,6 +23,8 @@ MEMORY kflash (rx) : ORIGIN = 0x80000000, LENGTH = 2048K /* w/ cache */ ksram (rwx) : ORIGIN = 0x80200000, LENGTH = 2048K /* w/ cache */ pgram (rwx) : ORIGIN = 0x80400000, LENGTH = 4096K /* w/ cache */ + /* Added RAM Disk */ + ramdisk (rwx) : ORIGIN = 0x84000000, LENGTH = 4096K /* w/ cache */ } OUTPUT_ARCH("riscv") @@ -40,6 +42,13 @@ __ksram_end = ORIGIN(ksram) + LENGTH(ksram); __pgheap_start = ORIGIN(pgram); __pgheap_size = LENGTH(pgram); +/* Added RAM Disk */ +/* Application ramdisk */ + +__ramdisk_start = ORIGIN(ramdisk); +__ramdisk_size = LENGTH(ramdisk); +__ramdisk_end = ORIGIN(ramdisk) + LENGTH(ramdisk); + SECTIONS { . = 0x80000000; From 98e713f621cfe8f435bb6e068babea2e4ed718cc Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Thu, 20 Jul 2023 19:47:42 +0800 Subject: [PATCH 06/15] Mount RAM Disk --- boards/risc-v/qemu-rv/rv-virt/configs/knsh64/defconfig | 3 +++ 1 file changed, 3 insertions(+) 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 6156ef5a3fa32..0feff25fe9db7 100644 --- a/boards/risc-v/qemu-rv/rv-virt/configs/knsh64/defconfig +++ b/boards/risc-v/qemu-rv/rv-virt/configs/knsh64/defconfig @@ -67,6 +67,9 @@ 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_FLAGS=0x1 +CONFIG_INIT_MOUNT_TARGET="/system/bin" CONFIG_INIT_STACKSIZE=3072 CONFIG_INTELHEX_BINARY=y CONFIG_LIBC_ENVPATH=y From 70a7d027936511b9aa5f44c3bb989ba98cdf1219 Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Thu, 20 Jul 2023 20:15:08 +0800 Subject: [PATCH 07/15] Mapping RAM Disk --- arch/risc-v/src/qemu-rv/qemu_rv_mm_init.c | 9 +++++++++ 1 file changed, 9 insertions(+) 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..fc767a66e491a 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,15 @@ 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[]; + _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"); + #ifdef CONFIG_ARCH_MMU_TYPE_SV39 /* Connect the L1 and L2 page tables for the kernel text and data */ From 06e27e2243d1c041783f980533e55366938b62ff Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Thu, 20 Jul 2023 20:19:08 +0800 Subject: [PATCH 08/15] Enable Binary Loader Logging --- boards/risc-v/qemu-rv/rv-virt/configs/knsh64/defconfig | 1 + 1 file changed, 1 insertion(+) 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 0feff25fe9db7..d4a14a277bd3b 100644 --- a/boards/risc-v/qemu-rv/rv-virt/configs/knsh64/defconfig +++ b/boards/risc-v/qemu-rv/rv-virt/configs/knsh64/defconfig @@ -49,6 +49,7 @@ 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 From e8fa26730a293669a8aa152d7ca7b2a66430db30 Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Thu, 20 Jul 2023 20:35:44 +0800 Subject: [PATCH 09/15] Map RAM Disk OK. romfs_bind: ERROR: romfs_fsconfigure failed: -22 --- arch/risc-v/src/qemu-rv/qemu_rv_mm_init.c | 2 ++ boards/risc-v/qemu-rv/rv-virt/configs/knsh64/defconfig | 4 ++++ boards/risc-v/qemu-rv/rv-virt/scripts/ld-kernel64.script | 7 +++++-- 3 files changed, 11 insertions(+), 2 deletions(-) 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 fc767a66e491a..5194a183f2300 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,7 @@ void qemu_rv_kernel_mappings(void) binfo("map kernel data\n"); map_region(KSRAM_START, KSRAM_START, KSRAM_SIZE, MMU_KDATA_FLAGS); +#ifdef NOTUSED /* Added RAM Disk */ //// From nuttx/boards/risc-v/litex/arty_a7/include/board_memorymap.h /* ramdisk (RW) */ @@ -277,6 +278,7 @@ void qemu_rv_kernel_mappings(void) _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 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 d4a14a277bd3b..d5a093fe9f1c6 100644 --- a/boards/risc-v/qemu-rv/rv-virt/configs/knsh64/defconfig +++ b/boards/risc-v/qemu-rv/rv-virt/configs/knsh64/defconfig @@ -53,6 +53,10 @@ 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_INFO=y +CONFIG_DEBUG_FS_WARN=y CONFIG_DEBUG_FULLOPT=y CONFIG_DEBUG_INFO=y CONFIG_DEBUG_SCHED=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 6151a8b4505f5..832a80898903b 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 @@ -24,7 +24,8 @@ MEMORY ksram (rwx) : ORIGIN = 0x80200000, LENGTH = 2048K /* w/ cache */ pgram (rwx) : ORIGIN = 0x80400000, LENGTH = 4096K /* w/ cache */ /* Added RAM Disk */ - ramdisk (rwx) : ORIGIN = 0x84000000, LENGTH = 4096K /* w/ cache */ + ramdisk (rwx) : ORIGIN = 0x80800000, LENGTH = 4096K /* w/ cache */ + /* ramdisk (rwx) : ORIGIN = 0x84000000, LENGTH = 4096K */ /* w/ cache */ } OUTPUT_ARCH("riscv") @@ -37,10 +38,12 @@ __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 */ From c63106e6b4bbf87b9a4cc42f38d2546cea54d298 Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Thu, 20 Jul 2023 20:42:29 +0800 Subject: [PATCH 10/15] Copy RAM Disk. Load page fault. MCAUSE: 000000000000000d, EPC: 0000000080010642, MTVAL: 0000000080f07ee1 --- arch/risc-v/src/qemu-rv/qemu_rv_mm_init.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 5194a183f2300..aac493e7fe71f 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,12 +269,17 @@ void qemu_rv_kernel_mappings(void) binfo("map kernel data\n"); map_region(KSRAM_START, KSRAM_START, KSRAM_SIZE, MMU_KDATA_FLAGS); -#ifdef NOTUSED - /* Added RAM Disk */ + // 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 0x84000000 to __ramdisk_start (__ramdisk_size bytes) + // TODO: RAM Disk must not exceed __ramdisk_size bytes + memcpy((void *)__ramdisk_start, (void *)0x84000000, (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"); From d46a2649cb348a49f06d44e80e7eff50977c425d Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Fri, 21 Jul 2023 13:42:44 +0800 Subject: [PATCH 11/15] Old version of romfs_devread32. Load page fault. MCAUSE: 000000000000000d, EPC: 0000000080010642, MTVAL: 0000000080f07ee0 --- fs/romfs/fs_romfsutil.c | 47 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/fs/romfs/fs_romfsutil.c b/fs/romfs/fs_romfsutil.c index 8e6127dbf43e3..a43e3379b9bb2 100644 --- a/fs/romfs/fs_romfsutil.c +++ b/fs/romfs/fs_romfsutil.c @@ -63,6 +63,52 @@ struct romfs_entryname_s * Private Functions ****************************************************************************/ +#define OLD_DEVREAD //// +#ifdef OLD_DEVREAD //// +// Old version of romfs_devread32 +// https://github.com/lupyuen2/wip-pinephone-nuttx/commit/18e5e75008a73e7bec70c10fd64c6f46d2e0bdb4 +/**************************************************************************** + * Name: romfs_swap32 + * + * Description: + * Convert the 32-bit big endian value to little endian + * + ****************************************************************************/ + +#ifndef CONFIG_ENDIAN_BIG +static inline uint32_t romfs_swap32(uint32_t value) +{ + return ((((value) & 0x000000ff) << 24) | (((value) & 0x0000ff00) << 8) | + (((value) & 0x00ff0000) >> 8) | (((value) & 0xff000000) >> 24)); +} +#endif + +/**************************************************************************** + * Name: romfs_devread32 + * + * Description: + * Read the big-endian 32-bit value from the mount device buffer + * + * Assumption: + * All values are aligned to 32-bit boundaries + * + ****************************************************************************/ + +static uint32_t romfs_devread32(struct romfs_mountpt_s *rm, int ndx) +{ + /* Extract the value */ + + uint32_t value = *(FAR uint32_t *)&rm->rm_buffer[ndx]; + + /* Value is begin endian -- return the native host endian-ness. */ +#ifdef CONFIG_ENDIAN_BIG + return value; +#else + return romfs_swap32(value); +#endif +} +#else +// New version of romfs_devread32 /**************************************************************************** * Name: romfs_devread32 * @@ -85,6 +131,7 @@ static uint32_t romfs_devread32(FAR struct romfs_mountpt_s *rm, int ndx) (((uint32_t)rm->rm_buffer[ndx + 2] & 0xff) << 8) | ((uint32_t)rm->rm_buffer[ndx + 3] & 0xff)); } +#endif // OLD_DEVREAD /**************************************************************************** * Name: romfs_checkentry From b42e7c62f0baab11b49b7951499da3db718f5401 Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Fri, 21 Jul 2023 16:36:27 +0800 Subject: [PATCH 12/15] Increase RAM Disk to 16 MB. Boots OK yay! --- boards/risc-v/qemu-rv/rv-virt/scripts/ld-kernel64.script | 4 ++-- fs/romfs/fs_romfsutil.c | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) 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 832a80898903b..90dabf0a8ef41 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 @@ -24,8 +24,8 @@ MEMORY ksram (rwx) : ORIGIN = 0x80200000, LENGTH = 2048K /* w/ cache */ pgram (rwx) : ORIGIN = 0x80400000, LENGTH = 4096K /* w/ cache */ /* Added RAM Disk */ - ramdisk (rwx) : ORIGIN = 0x80800000, LENGTH = 4096K /* w/ cache */ - /* ramdisk (rwx) : ORIGIN = 0x84000000, LENGTH = 4096K */ /* w/ cache */ + ramdisk (rwx) : ORIGIN = 0x80800000, LENGTH = 16M /* w/ cache */ + /* ramdisk (rwx) : ORIGIN = 0x84000000, LENGTH = 16M */ /* w/ cache */ } OUTPUT_ARCH("riscv") diff --git a/fs/romfs/fs_romfsutil.c b/fs/romfs/fs_romfsutil.c index a43e3379b9bb2..6641abb1fc929 100644 --- a/fs/romfs/fs_romfsutil.c +++ b/fs/romfs/fs_romfsutil.c @@ -96,6 +96,13 @@ static inline uint32_t romfs_swap32(uint32_t value) static uint32_t romfs_devread32(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); //// + /* Extract the value */ uint32_t value = *(FAR uint32_t *)&rm->rm_buffer[ndx]; @@ -109,6 +116,7 @@ static uint32_t romfs_devread32(struct romfs_mountpt_s *rm, int ndx) } #else // New version of romfs_devread32 +// Crashes with Misaligned Address exception /**************************************************************************** * Name: romfs_devread32 * From a1de9453a6e3b7e774a52ad18ee3094095ebbccd Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Fri, 21 Jul 2023 17:13:10 +0800 Subject: [PATCH 13/15] Revert to new version of romfs_devread32. Boots OK yay! --- fs/romfs/fs_romfsutil.c | 50 +---------------------------------------- 1 file changed, 1 insertion(+), 49 deletions(-) diff --git a/fs/romfs/fs_romfsutil.c b/fs/romfs/fs_romfsutil.c index 6641abb1fc929..e4a12132c08c6 100644 --- a/fs/romfs/fs_romfsutil.c +++ b/fs/romfs/fs_romfsutil.c @@ -63,26 +63,6 @@ struct romfs_entryname_s * Private Functions ****************************************************************************/ -#define OLD_DEVREAD //// -#ifdef OLD_DEVREAD //// -// Old version of romfs_devread32 -// https://github.com/lupyuen2/wip-pinephone-nuttx/commit/18e5e75008a73e7bec70c10fd64c6f46d2e0bdb4 -/**************************************************************************** - * Name: romfs_swap32 - * - * Description: - * Convert the 32-bit big endian value to little endian - * - ****************************************************************************/ - -#ifndef CONFIG_ENDIAN_BIG -static inline uint32_t romfs_swap32(uint32_t value) -{ - return ((((value) & 0x000000ff) << 24) | (((value) & 0x0000ff00) << 8) | - (((value) & 0x00ff0000) >> 8) | (((value) & 0xff000000) >> 24)); -} -#endif - /**************************************************************************** * Name: romfs_devread32 * @@ -94,7 +74,7 @@ static inline uint32_t romfs_swap32(uint32_t value) * ****************************************************************************/ -static uint32_t romfs_devread32(struct romfs_mountpt_s *rm, int ndx) +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[]; //// @@ -103,33 +83,6 @@ static uint32_t romfs_devread32(struct romfs_mountpt_s *rm, int ndx) { _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); //// - /* Extract the value */ - - uint32_t value = *(FAR uint32_t *)&rm->rm_buffer[ndx]; - - /* Value is begin endian -- return the native host endian-ness. */ -#ifdef CONFIG_ENDIAN_BIG - return value; -#else - return romfs_swap32(value); -#endif -} -#else -// New version of romfs_devread32 -// Crashes with Misaligned Address exception -/**************************************************************************** - * Name: romfs_devread32 - * - * Description: - * Read the big-endian 32-bit value from the mount device buffer - * - * Assumption: - * All values are aligned to 32-bit boundaries - * - ****************************************************************************/ - -static uint32_t romfs_devread32(FAR struct romfs_mountpt_s *rm, int ndx) -{ /* This should not read past the end of the sector since the directory * entries are aligned at 16-byte boundaries. */ @@ -139,7 +92,6 @@ static uint32_t romfs_devread32(FAR struct romfs_mountpt_s *rm, int ndx) (((uint32_t)rm->rm_buffer[ndx + 2] & 0xff) << 8) | ((uint32_t)rm->rm_buffer[ndx + 3] & 0xff)); } -#endif // OLD_DEVREAD /**************************************************************************** * Name: romfs_checkentry From f72aa9dbd8f074a645cc8e66f3a27f50985a8a48 Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Thu, 27 Jul 2023 06:52:03 +0800 Subject: [PATCH 14/15] Disable info logging --- boards/risc-v/qemu-rv/rv-virt/configs/knsh64/defconfig | 2 -- 1 file changed, 2 deletions(-) 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 d5a093fe9f1c6..b4c2c23ab1e93 100644 --- a/boards/risc-v/qemu-rv/rv-virt/configs/knsh64/defconfig +++ b/boards/risc-v/qemu-rv/rv-virt/configs/knsh64/defconfig @@ -49,13 +49,11 @@ 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_INFO=y CONFIG_DEBUG_FS_WARN=y CONFIG_DEBUG_FULLOPT=y CONFIG_DEBUG_INFO=y From 3c99d2b6607145ed167a2de3e8b411d6632699c2 Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Thu, 27 Jul 2023 06:59:54 +0800 Subject: [PATCH 15/15] Ignore init.S --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 095ffbeff3399..25c517718d094 100644 --- a/.gitignore +++ b/.gitignore @@ -61,3 +61,4 @@ uImage .DS_Store tools/gdb/__pycache__ initrd +init.S