From 7d55679684f7847fb61af25a243af7ca0b166e2c Mon Sep 17 00:00:00 2001 From: anjiahao Date: Wed, 24 Apr 2024 12:07:48 +0800 Subject: [PATCH] fs/ioctl:add FIOC_XIPBASE to get file xip address in tmpfs/romfs, we can get file real xip address to execute program Signed-off-by: anjiahao --- fs/romfs/fs_romfs.c | 15 +++++++++++++++ fs/tmpfs/fs_tmpfs.c | 7 +++++++ include/nuttx/fs/ioctl.h | 3 +++ 3 files changed, 25 insertions(+) diff --git a/fs/romfs/fs_romfs.c b/fs/romfs/fs_romfs.c index e5af8c988b602..7c34925fffb85 100644 --- a/fs/romfs/fs_romfs.c +++ b/fs/romfs/fs_romfs.c @@ -604,6 +604,21 @@ static int romfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg) strlcat(ptr, rf->rf_path, PATH_MAX); return OK; } + else if (cmd == FIOC_XIPBASE) + { + FAR struct romfs_mountpt_s *rm = filep->f_inode->i_private; + FAR uintptr_t *ptr = (FAR uintptr_t *)arg; + + if (rm->rm_xipbase != 0) + { + *ptr = (uintptr_t)rm->rm_xipbase + rf->rf_startoffset; + return OK; + } + else + { + return -ENXIO; + } + } return -ENOTTY; } diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c index 2e4dc5a91dd7c..ce635d1efb975 100644 --- a/fs/tmpfs/fs_tmpfs.c +++ b/fs/tmpfs/fs_tmpfs.c @@ -1825,6 +1825,13 @@ static int tmpfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg) return ret; } } + else if (cmd == FIOC_XIPBASE) + { + FAR uintptr_t *ptr = (FAR uintptr_t *)arg; + + *ptr = (uintptr_t)tfo->tfo_data; + return OK; + } return ret; } diff --git a/include/nuttx/fs/ioctl.h b/include/nuttx/fs/ioctl.h index 17cb8d5c4f5e5..8ed1e1b926a47 100644 --- a/include/nuttx/fs/ioctl.h +++ b/include/nuttx/fs/ioctl.h @@ -226,6 +226,9 @@ #define FIOC_SETLKW _FIOC(0x0014) /* IN: Pointer to flock * OUT: None */ +#define FIOC_XIPBASE _FIOC(0x0015) /* IN: uinptr_t * + * OUT: Current file xip base address + */ /* NuttX file system ioctl definitions **************************************/