53
53
#define TQFTPSERV_TMP "/data/vendor/tmp/tqftpserv"
54
54
#endif
55
55
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
+
56
70
/**
57
71
* translate_readonly() - open "file" residing with remoteproc firmware
58
72
* @file: file requested, stripped of "/readonly/image/" prefix
@@ -72,13 +86,16 @@ static int translate_readonly(const char *file)
72
86
char firmware_value [PATH_MAX ];
73
87
char firmware_attr [32 ];
74
88
char path [PATH_MAX ];
89
+ char fw_sysfs_path [PATH_MAX ];
75
90
struct dirent * de ;
76
91
int firmware_fd ;
77
92
DIR * class_dir ;
78
93
int class_fd ;
79
94
ssize_t n ;
80
95
int fd = -1 ;
81
96
97
+ read_fw_path_from_sysfs (fw_sysfs_path , sizeof (fw_sysfs_path ));
98
+
82
99
class_fd = open ("/sys/class/remoteproc" , O_RDONLY | O_DIRECTORY );
83
100
if (class_fd < 0 ) {
84
101
warn ("failed to open remoteproc class" );
@@ -112,6 +129,23 @@ static int translate_readonly(const char *file)
112
129
}
113
130
firmware_value [n ] = '\0' ;
114
131
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 */
115
149
if (strlen (FIRMWARE_BASE ) + strlen (firmware_value ) + 1 +
116
150
strlen (file ) + 1 > sizeof (path ))
117
151
continue ;
0 commit comments