Skip to content

Commit 37669ab

Browse files
authored
Merge pull request #12 from minlexx/respect-firmware-sysfs-path
Use firmware path from sysfs
2 parents 289214a + a4c755d commit 37669ab

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");
@@ -112,6 +129,23 @@ static int translate_readonly(const char *file)
112129
}
113130
firmware_value[n] = '\0';
114131

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

0 commit comments

Comments
 (0)