module/sotest: Try devminor of romdisk

For case that /dev/ram${EXAMPLES_SOTEST_DEVMINOR}(e.g. /dev/ram0) already exists, and users may not care which device to use.

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
This commit is contained in:
wangjianyu3 2024-06-21 20:12:27 +08:00 committed by Xiang Xiao
parent 758ed55722
commit dae4d7572f
2 changed files with 26 additions and 18 deletions

View File

@ -35,13 +35,14 @@ config EXAMPLES_SOTEST_BUILTINFS
if EXAMPLES_SOTEST_BUILTINFS
config EXAMPLES_SOTEST_DEVMINOR
int "ROMFS Minor Device Number"
default 0
config EXAMPLES_SOTEST_DEVMINOR_MAX
int "ROMFS Max Minor Device Number"
default 5
---help---
The minor device number of the ROMFS block. For example, the N in /dev/ramN.
The max minor device number of the ROMFS block will be tried.
For example, from /dev/ram0 to /dev/ramN.
Used for registering the RAM block driver that will hold the ROMFS file system
containing the SOTEST executables to be tested. Default: 0
containing the SOTEST executables to be tested. Default: 5
endif # EXAMPLES_SOTEST_BUILTINFS

View File

@ -71,8 +71,8 @@
# define NSECTORS(b) (((b)+SECTORSIZE-1)/SECTORSIZE)
# define BINDIR "/mnt/romfs"
# ifndef CONFIG_EXAMPLES_SOTEST_DEVMINOR
# define CONFIG_EXAMPLES_SOTEST_DEVMINOR 0
# ifndef CONFIG_EXAMPLES_SOTEST_DEVMINOR_MAX
# define CONFIG_EXAMPLES_SOTEST_DEVMINOR_MAX 5
# endif
#else
# define BINDIR CONFIG_EXAMPLES_SOTEST_BINDIR
@ -127,26 +127,33 @@ int main(int argc, FAR char *argv[])
#ifdef CONFIG_EXAMPLES_SOTEST_BUILTINFS
/* Create a ROM disk for the ROMFS filesystem */
desc.minor = CONFIG_EXAMPLES_SOTEST_DEVMINOR; /* Minor device number of the ROM disk. */
desc.minor = 0; /* Minor device number of the ROM disk. */
desc.nsectors = NSECTORS(romfs_img_len); /* The number of sectors in the ROM disk */
desc.sectsize = SECTORSIZE; /* The size of one sector in bytes */
desc.image = (FAR uint8_t *)romfs_img; /* File system image */
printf("main: Registering romdisk at /dev/ram%d\n",
CONFIG_EXAMPLES_SOTEST_DEVMINOR);
ret = boardctl(BOARDIOC_ROMDISK, (uintptr_t)&desc);
if (ret < 0)
for (; desc.minor <= CONFIG_EXAMPLES_SOTEST_DEVMINOR_MAX; desc.minor++)
{
fprintf(stderr, "ERROR: romdisk_register failed: %s\n",
strerror(errno));
exit(EXIT_FAILURE);
printf("main: Registering romdisk at /dev/ram%d\n", desc.minor);
ret = boardctl(BOARDIOC_ROMDISK, (uintptr_t)&desc);
if (ret >= 0)
{
break;
}
if (errno != EEXIST ||
desc.minor == CONFIG_EXAMPLES_SOTEST_DEVMINOR_MAX)
{
fprintf(stderr, "ERROR: romdisk_register failed: %s\n",
strerror(errno));
exit(EXIT_FAILURE);
}
}
/* Mount the file system */
sprintf(devname, SOTEST_DEVPATH_FMT, CONFIG_EXAMPLES_SOTEST_DEVMINOR);
sprintf(devname, SOTEST_DEVPATH_FMT, desc.minor);
printf("main: Mounting ROMFS filesystem at target=%s with source=%s\n",
BINDIR, devname);