Skip to content

Commit dae4d75

Browse files
JianyuWang0623xiaoxiang781216
authored andcommitted
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 <[email protected]>
1 parent 758ed55 commit dae4d75

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

examples/sotest/Kconfig

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ config EXAMPLES_SOTEST_BUILTINFS
3535

3636
if EXAMPLES_SOTEST_BUILTINFS
3737

38-
config EXAMPLES_SOTEST_DEVMINOR
39-
int "ROMFS Minor Device Number"
40-
default 0
38+
config EXAMPLES_SOTEST_DEVMINOR_MAX
39+
int "ROMFS Max Minor Device Number"
40+
default 5
4141
---help---
42-
The minor device number of the ROMFS block. For example, the N in /dev/ramN.
42+
The max minor device number of the ROMFS block will be tried.
43+
For example, from /dev/ram0 to /dev/ramN.
4344
Used for registering the RAM block driver that will hold the ROMFS file system
44-
containing the SOTEST executables to be tested. Default: 0
45+
containing the SOTEST executables to be tested. Default: 5
4546

4647
endif # EXAMPLES_SOTEST_BUILTINFS
4748

examples/sotest/sotest_main.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@
7171
# define NSECTORS(b) (((b)+SECTORSIZE-1)/SECTORSIZE)
7272
# define BINDIR "/mnt/romfs"
7373

74-
# ifndef CONFIG_EXAMPLES_SOTEST_DEVMINOR
75-
# define CONFIG_EXAMPLES_SOTEST_DEVMINOR 0
74+
# ifndef CONFIG_EXAMPLES_SOTEST_DEVMINOR_MAX
75+
# define CONFIG_EXAMPLES_SOTEST_DEVMINOR_MAX 5
7676
# endif
7777
#else
7878
# define BINDIR CONFIG_EXAMPLES_SOTEST_BINDIR
@@ -127,26 +127,33 @@ int main(int argc, FAR char *argv[])
127127
#ifdef CONFIG_EXAMPLES_SOTEST_BUILTINFS
128128
/* Create a ROM disk for the ROMFS filesystem */
129129

130-
desc.minor = CONFIG_EXAMPLES_SOTEST_DEVMINOR; /* Minor device number of the ROM disk. */
130+
desc.minor = 0; /* Minor device number of the ROM disk. */
131131
desc.nsectors = NSECTORS(romfs_img_len); /* The number of sectors in the ROM disk */
132132
desc.sectsize = SECTORSIZE; /* The size of one sector in bytes */
133133
desc.image = (FAR uint8_t *)romfs_img; /* File system image */
134134

135-
printf("main: Registering romdisk at /dev/ram%d\n",
136-
CONFIG_EXAMPLES_SOTEST_DEVMINOR);
137-
138-
ret = boardctl(BOARDIOC_ROMDISK, (uintptr_t)&desc);
139-
140-
if (ret < 0)
135+
for (; desc.minor <= CONFIG_EXAMPLES_SOTEST_DEVMINOR_MAX; desc.minor++)
141136
{
142-
fprintf(stderr, "ERROR: romdisk_register failed: %s\n",
143-
strerror(errno));
144-
exit(EXIT_FAILURE);
137+
printf("main: Registering romdisk at /dev/ram%d\n", desc.minor);
138+
139+
ret = boardctl(BOARDIOC_ROMDISK, (uintptr_t)&desc);
140+
if (ret >= 0)
141+
{
142+
break;
143+
}
144+
145+
if (errno != EEXIST ||
146+
desc.minor == CONFIG_EXAMPLES_SOTEST_DEVMINOR_MAX)
147+
{
148+
fprintf(stderr, "ERROR: romdisk_register failed: %s\n",
149+
strerror(errno));
150+
exit(EXIT_FAILURE);
151+
}
145152
}
146153

147154
/* Mount the file system */
148155

149-
sprintf(devname, SOTEST_DEVPATH_FMT, CONFIG_EXAMPLES_SOTEST_DEVMINOR);
156+
sprintf(devname, SOTEST_DEVPATH_FMT, desc.minor);
150157
printf("main: Mounting ROMFS filesystem at target=%s with source=%s\n",
151158
BINDIR, devname);
152159

0 commit comments

Comments
 (0)