Skip to content

Commit c58ac26

Browse files
committed
Use firmware path from sysfs
Some linux distributions adjust path fro kernel to load firmware from using /sys/module/firmware_class/parameters/path. Kernel supports it, teach tqftpserv to respect it too. Signed-off-by: Alexey Minnekhanov <[email protected]>
1 parent de42697 commit c58ac26

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

translate.c

+34
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@
5353
#define TQFTPSERV_TMP "/data/vendor/tmp/tqftpserv"
5454
#endif
5555

56+
static void read_fw_path_from_sysfs(char *outbuffer, size_t bufsize)
57+
{
58+
size_t pathsize;
59+
FILE *f = fopen("/sys/module/firmware_class/parameters/path", "rt");
60+
if (!f)
61+
return;
62+
pathsize = fread(outbuffer, sizeof(char), bufsize, f);
63+
fclose(f);
64+
if (pathsize <= 0)
65+
return;
66+
/* truncate newline */
67+
outbuffer[pathsize - 1] = '\0';
68+
}
69+
5670
/**
5771
* translate_readonly() - open "file" residing with remoteproc firmware
5872
* @file: file requested, stripped of "/readonly/image/" prefix
@@ -72,13 +86,16 @@ static int translate_readonly(const char *file)
7286
char firmware_value[PATH_MAX];
7387
char firmware_attr[32];
7488
char path[PATH_MAX];
89+
char fw_sysfs_path[PATH_MAX];
7590
struct dirent *de;
7691
int firmware_fd;
7792
DIR *class_dir;
7893
int class_fd;
7994
ssize_t n;
8095
int fd = -1;
8196

97+
read_fw_path_from_sysfs(fw_sysfs_path, sizeof(fw_sysfs_path));
98+
8299
class_fd = open("/sys/class/remoteproc", O_RDONLY | O_DIRECTORY);
83100
if (class_fd < 0) {
84101
warn("failed to open remoteproc class");
@@ -111,6 +128,23 @@ static int translate_readonly(const char *file)
111128
}
112129
firmware_value[n] = '\0';
113130

131+
/* first try path from sysfs */
132+
if ((strlen(fw_sysfs_path) > 0) &&
133+
(strlen(fw_sysfs_path) + 1 +strlen(firmware_value) + 1 + strlen(file) + 1 < sizeof(path))) {
134+
strcpy(path, fw_sysfs_path);
135+
strcat(path, "/");
136+
strcat(path, dirname(firmware_value));
137+
strcat(path, "/");
138+
strcat(path, file);
139+
140+
fd = open(path, O_RDONLY);
141+
if (fd >= 0)
142+
break;
143+
if (errno != ENOENT)
144+
warn("failed to open %s", path);
145+
}
146+
147+
/* now try with base path */
114148
if (strlen(FIRMWARE_BASE) + strlen(firmware_value) + 1 +
115149
strlen(file) + 1 > sizeof(path))
116150
continue;

0 commit comments

Comments
 (0)